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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ these can also be supplied in a Properties instance that is passed to the
- maxSessions (int): Sets the maximum number of sessions in the backing session pool. Defaults to 400.
- numChannels (int): Sets the number of gRPC channels to use. Defaults to 4.
- retryAbortsInternally (boolean): The JDBC driver will by default automatically retry aborted transactions internally. This is done by keeping track of all statements and the results of these during a transaction, and if the transaction is aborted by Cloud Spanner, it will replay the statements on a new transaction and compare the results with the initial attempt. Disable this option if you want to handle aborted transactions in your own application.
- auto_batch_dml (boolean): Automatically buffer DML statements and execute them as one batch,
instead of executing them on Spanner directly. The buffered DML statements are executed on Spanner
in one batch when a query is executed, or when the transaction is committed. This option can for
example be used in combination with Hibernate to automatically group more (small) DML statements
into one batch.
- oauthToken (string): A valid pre-existing OAuth token to use for authentication for this connection. Setting this property will take precedence over any value set for a credentials file.
- lenient (boolean): Enable this to force the JDBC driver to ignore unknown properties in the connection URL. Some applications automatically add additional properties to the URL that are not recognized by the JDBC driver. Normally, the JDBC driver will reject this, unless `lenient` mode is enabled.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.google.protobuf.Value;
import com.google.rpc.Code;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.v1.CommitRequest;
import com.google.spanner.v1.ExecuteBatchDmlRequest;
import com.google.spanner.v1.ResultSetMetadata;
import com.google.spanner.v1.ResultSetStats;
import com.google.spanner.v1.StructType;
Expand Down Expand Up @@ -844,4 +846,28 @@ public void testInvalidExecuteUpdate_shouldNotLeakSession() throws SQLException
}
}
}

private String getExtension() {
return dialect == Dialect.POSTGRESQL ? "spanner." : "";
}

@Test
public void testExecuteAutoBatchDml() throws SQLException {
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
connection.setAutoCommit(false);

assertFalse(statement.execute(String.format("set %sauto_batch_dml = true", getExtension())));
for (int i = 0; i < 3; i++) {
assertFalse(statement.execute(dml));
assertEquals(1, statement.getUpdateCount());
}
connection.commit();
}
assertEquals(1, mockSpanner.countRequestsOfType(ExecuteBatchDmlRequest.class));
ExecuteBatchDmlRequest request =
mockSpanner.getRequestsOfType(ExecuteBatchDmlRequest.class).get(0);
assertEquals(3, request.getStatementsCount());
assertEquals(1, mockSpanner.countRequestsOfType(CommitRequest.class));
}
}
Loading