in google-cloud-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/schema/SpannerSchemaManagementTool.java [95:121]
public Connection getIsolatedConnection(boolean autocommit) {
Connection delegateConnection = this.delegate.getIsolatedConnection(autocommit);
// Create a proxy for the connection that will override the call to
// Connection#createStatement().
return (Connection)
Proxy.newProxyInstance(
delegateConnection.getClass().getClassLoader(),
new Class[] {Connection.class},
(proxy, method, args) -> {
// Only handle the Connection#createStatement() differently.
// All other methods are just passed through.
if (method.equals(createStatementMethod)) {
// Create a proxy for the returned Statement that will override the behavior of
// Statement#execute(String).
return createProxyStatement(delegateConnection);
} else if (method.equals(connectionCloseMethod)) {
// Ignore as the connection is released when this DdlTransactionIsolator is
// released.
return null;
}
try {
return method.invoke(delegateConnection, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
});
}