Skip to content

Commit 1f850e9

Browse files
chore: deduplicate code for batch updates (#2591)
* chore: deduplicate code for batch updates De-duplicate code that is equal for both the sync and async version of the executeBatchUpdate methods. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 78470cb commit 1f850e9

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,32 +1324,15 @@ public ResultSet analyzeUpdateStatement(
13241324

13251325
@Override
13261326
public long[] executeBatchUpdate(Iterable<Statement> updates) {
1327-
Preconditions.checkNotNull(updates);
1328-
ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG);
1329-
// Check that there are only DML statements in the input.
1330-
List<ParsedStatement> parsedStatements = new LinkedList<>();
1331-
for (Statement update : updates) {
1332-
ParsedStatement parsedStatement = getStatementParser().parse(update);
1333-
switch (parsedStatement.getType()) {
1334-
case UPDATE:
1335-
parsedStatements.add(parsedStatement);
1336-
break;
1337-
case CLIENT_SIDE:
1338-
case QUERY:
1339-
case DDL:
1340-
case UNKNOWN:
1341-
default:
1342-
throw SpannerExceptionFactory.newSpannerException(
1343-
ErrorCode.INVALID_ARGUMENT,
1344-
"The batch update list contains a statement that is not an update statement: "
1345-
+ parsedStatement.getSqlWithoutComments());
1346-
}
1347-
}
1348-
return get(internalExecuteBatchUpdateAsync(CallType.SYNC, parsedStatements));
1327+
return get(internalExecuteBatchUpdateAsync(CallType.SYNC, parseUpdateStatements(updates)));
13491328
}
13501329

13511330
@Override
13521331
public ApiFuture<long[]> executeBatchUpdateAsync(Iterable<Statement> updates) {
1332+
return internalExecuteBatchUpdateAsync(CallType.ASYNC, parseUpdateStatements(updates));
1333+
}
1334+
1335+
private List<ParsedStatement> parseUpdateStatements(Iterable<Statement> updates) {
13531336
Preconditions.checkNotNull(updates);
13541337
ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG);
13551338
// Check that there are only DML statements in the input.
@@ -1371,7 +1354,7 @@ public ApiFuture<long[]> executeBatchUpdateAsync(Iterable<Statement> updates) {
13711354
+ parsedStatement.getSqlWithoutComments());
13721355
}
13731356
}
1374-
return internalExecuteBatchUpdateAsync(CallType.ASYNC, parsedStatements);
1357+
return parsedStatements;
13751358
}
13761359

13771360
private QueryOption[] mergeDataBoost(QueryOption... options) {

0 commit comments

Comments
 (0)