in google-cloud-spanner-hibernate-samples/spring-data-jpa-full-sample/src/main/java/com/google/cloud/spanner/sample/service/BatchService.java [76:99]
private void runWithAutoBatchDml(Runnable runnable) {
// Enable auto_batch_dml on the JDBC connection and run the runnable.
// Then flush the Hibernate session and reset the JDBC connection.
Session session = entityManager.unwrap(Session.class);
try {
session.doWork(
connection -> {
try (Statement statement = connection.createStatement()) {
statement.execute("set auto_batch_dml=true");
statement.execute("set max_commit_delay='50ms'");
}
});
runnable.run();
session.flush();
} finally {
session.doWork(
connection -> {
try (Statement statement = connection.createStatement()) {
statement.execute("set auto_batch_dml=false");
statement.execute("set max_commit_delay=null");
}
});
}
}