Skip to content

Commit ae408ef

Browse files
committed
chore: cleanup and add comments
1 parent 23b7acf commit ae408ef

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DmlBatchUpdateCountVerificationFailedException.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
public class DmlBatchUpdateCountVerificationFailedException extends AbortedException {
2929
private static final long serialVersionUID = 1L;
3030

31+
private final long[] expected;
32+
33+
private final long[] actual;
34+
3135
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
3236
DmlBatchUpdateCountVerificationFailedException(
3337
DoNotConstructDirectly token, long[] expected, long[] actual) {
@@ -41,5 +45,24 @@ public class DmlBatchUpdateCountVerificationFailedException extends AbortedExcep
4145
Arrays.stream(expected).mapToObj(Long::toString).collect(Collectors.joining()),
4246
Arrays.stream(actual).mapToObj(Long::toString).collect(Collectors.joining())),
4347
/* cause = */ null);
48+
this.expected = expected;
49+
this.actual = actual;
50+
}
51+
52+
/**
53+
* The expected update counts. These were returned to the client application when the DML
54+
* statements were buffered.
55+
*/
56+
public long[] getExpected() {
57+
return Arrays.copyOf(this.expected, this.expected.length);
58+
}
59+
60+
/**
61+
* The actual update counts. These were returned by Spanner to the client when the DML statements
62+
* were actually executed, and are the update counts that the client application would have
63+
* received if auto-batching had not been enabled.
64+
*/
65+
public long[] getActual() {
66+
return Arrays.copyOf(this.actual, this.actual.length);
4467
}
4568
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerExceptionFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public static SpannerBatchUpdateException newSpannerBatchUpdateException(
116116
return new SpannerBatchUpdateException(token, code, message, updateCounts);
117117
}
118118

119+
/** Constructs a specific error that */
119120
public static DmlBatchUpdateCountVerificationFailedException
120121
newDmlBatchUpdateCountVerificationFailedException(long[] expected, long[] actual) {
121122
return new DmlBatchUpdateCountVerificationFailedException(

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,16 +1165,43 @@ default StatementResult execute(Statement statement, Set<ResultType> allowedResu
11651165
*/
11661166
ResultSet analyzeQuery(Statement query, QueryAnalyzeMode queryMode);
11671167

1168+
/**
1169+
* Enables or disables automatic batching of DML statements. When enabled, DML statements that are
1170+
* executed on this connection will be buffered in memory instead of actually being executed. The
1171+
* buffered DML statements are flushed to Spanner when a statement that cannot be part of a DML
1172+
* batch is executed on the connection. This can be a query, a DDL statement with a THEN RETURN
1173+
* clause, or a Commit call. The update count that is returned for DML statements that are
1174+
* buffered is determined by the value that has been set with {@link
1175+
* #setAutoBatchDmlUpdateCount(long)}. The default is 1. The connection verifies that the update
1176+
* counts that were returned while buffering DML statements match the actual update counts that
1177+
* are returned by Spanner when the batch is executed. This verification can be disabled by
1178+
* calling {@link #setAutoBatchDmlUpdateCountVerification(boolean)}.
1179+
*/
11681180
void setAutoBatchDml(boolean autoBatchDml);
11691181

1182+
/** Returns whether automatic DML batching is enabled on this connection. */
11701183
boolean isAutoBatchDml();
11711184

1185+
/**
1186+
* Sets the update count that is returned for DML statements that are buffered during an automatic
1187+
* DML batch. This value is only used if {@link #isAutoBatchDml()} is enabled.
1188+
*/
11721189
void setAutoBatchDmlUpdateCount(long updateCount);
11731190

1191+
/**
1192+
* Returns the update count that is returned for DML statements that are buffered during an
1193+
* automatic DML batch.
1194+
*/
11741195
long getAutoBatchDmlUpdateCount();
11751196

1197+
/**
1198+
* Sets whether the update count that is returned by Spanner after executing an automatic DML
1199+
* batch should be verified against the update counts that were returned during the buffering of
1200+
* those statements.
1201+
*/
11761202
void setAutoBatchDmlUpdateCountVerification(boolean verification);
11771203

1204+
/** Indicates whether the update counts of automatic DML batches should be verified. */
11781205
boolean isAutoBatchDmlUpdateCountVerification();
11791206

11801207
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ConnectionImpl implements Connection {
118118
.parse(Statement.of("START BATCH DDL"));
119119
private static final ParsedStatement START_BATCH_DML_STATEMENT =
120120
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
121-
.parse(Statement.of("START BATCH DDL"));
121+
.parse(Statement.of("START BATCH DML"));
122122
private static final ParsedStatement RUN_BATCH_STATEMENT =
123123
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
124124
.parse(Statement.of("RUN BATCH"));

0 commit comments

Comments
 (0)