Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,39 +230,49 @@ public long executeUpdate(Statement statement) {
beforeReadOrQuery();
final ExecuteSqlRequest.Builder builder =
getExecuteSqlRequestBuilder(statement, QueryMode.NORMAL);
com.google.spanner.v1.ResultSet resultSet =
rpc.executeQuery(builder.build(), session.getOptions());
if (!resultSet.hasStats()) {
throw new IllegalArgumentException(
"DML response missing stats possibly due to non-DML statement as input");
try {
com.google.spanner.v1.ResultSet resultSet =
rpc.executeQuery(builder.build(), session.getOptions());
if (!resultSet.hasStats()) {
throw new IllegalArgumentException(
"DML response missing stats possibly due to non-DML statement as input");
}
// For standard DML, using the exact row count.
return resultSet.getStats().getRowCountExact();
} catch (SpannerException e) {
onError(e);
throw e;
}
// For standard DML, using the exact row count.
return resultSet.getStats().getRowCountExact();
}

@Override
public long[] batchUpdate(Iterable<Statement> statements) {
beforeReadOrQuery();
final ExecuteBatchDmlRequest.Builder builder = getExecuteBatchDmlRequestBuilder(statements);
com.google.spanner.v1.ExecuteBatchDmlResponse response =
rpc.executeBatchDml(builder.build(), session.getOptions());
long[] results = new long[response.getResultSetsCount()];
for (int i = 0; i < response.getResultSetsCount(); ++i) {
results[i] = response.getResultSets(i).getStats().getRowCountExact();
}
try {
com.google.spanner.v1.ExecuteBatchDmlResponse response =
rpc.executeBatchDml(builder.build(), session.getOptions());
long[] results = new long[response.getResultSetsCount()];
for (int i = 0; i < response.getResultSetsCount(); ++i) {
results[i] = response.getResultSets(i).getStats().getRowCountExact();
}

// If one of the DML statements was aborted, we should throw an aborted exception.
// In all other cases, we should throw a BatchUpdateException.
if (response.getStatus().getCode() == Code.ABORTED_VALUE) {
throw newSpannerException(
ErrorCode.fromRpcStatus(response.getStatus()), response.getStatus().getMessage());
} else if (response.getStatus().getCode() != 0) {
throw newSpannerBatchUpdateException(
ErrorCode.fromRpcStatus(response.getStatus()),
response.getStatus().getMessage(),
results);
// If one of the DML statements was aborted, we should throw an aborted exception.
// In all other cases, we should throw a BatchUpdateException.
if (response.getStatus().getCode() == Code.ABORTED_VALUE) {
throw newSpannerException(
ErrorCode.fromRpcStatus(response.getStatus()), response.getStatus().getMessage());
} else if (response.getStatus().getCode() != 0) {
throw newSpannerBatchUpdateException(
ErrorCode.fromRpcStatus(response.getStatus()),
response.getStatus().getMessage(),
results);
}
return results;
} catch (SpannerException e) {
onError(e);
throw e;
}
return results;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ public void abortNextTransaction() {
abortNextTransaction.set(true);
}

/** Instruct the mock server to abort all transactions currently active on the server. */
public void abortAllTransactions() {
for (ByteString id : transactions.keySet()) {
markAbortedTransaction(id);
}
}

@Override
public void createSession(
CreateSessionRequest request, StreamObserver<Session> responseObserver) {
Expand Down Expand Up @@ -735,6 +742,7 @@ public void executeBatchDml(
List<StatementResult> results = new ArrayList<>();
com.google.rpc.Status status =
com.google.rpc.Status.newBuilder().setCode(Code.OK_VALUE).build();
resultLoop:
for (com.google.spanner.v1.ExecuteBatchDmlRequest.Statement statement :
request.getStatementsList()) {
try {
Expand All @@ -744,7 +752,11 @@ public void executeBatchDml(
StatementResult res = getResult(spannerStatement);
switch (res.getType()) {
case EXCEPTION:
throw res.getException();
status =
com.google.rpc.Status.newBuilder()
.setCode(res.getException().getStatus().getCode().value())
.build();
break resultLoop;
case RESULT_SET:
throw Status.INVALID_ARGUMENT
.withDescription("Not a DML statement: " + statement.getSql())
Expand Down
Loading