use of com.google.cloud.spanner.jdbc.CloudSpannerJdbcConnection in project java-spanner-jdbc by googleapis.
the class ITJdbcReadWriteAutocommitTest method test02_WriteMutation.
@Test
public void test02_WriteMutation() throws Exception {
try (CloudSpannerJdbcConnection connection = createConnection(env, database)) {
connection.write(Mutation.newInsertBuilder("TEST").set("ID").to(9999L).set("NAME").to("FOO").build());
java.sql.Statement statement = connection.createStatement();
statement.execute(String.format("SHOW VARIABLE %sCOMMIT_TIMESTAMP", getDialect() == Dialect.POSTGRESQL ? "SPANNER." : ""));
try (java.sql.ResultSet rs = statement.getResultSet()) {
assertThat(rs.next(), is(true));
assertThat(rs.getTimestamp(1), is(notNullValue()));
}
}
}
use of com.google.cloud.spanner.jdbc.CloudSpannerJdbcConnection in project java-spanner-jdbc by googleapis.
the class ITJdbcConnectTest method testNonDefaultConnection.
private void testNonDefaultConnection(Connection connection) throws SQLException {
assertThat(connection.isWrapperFor(CloudSpannerJdbcConnection.class)).isTrue();
CloudSpannerJdbcConnection cs = connection.unwrap(CloudSpannerJdbcConnection.class);
assertThat(cs.getAutoCommit()).isFalse();
assertThat(cs.isReadOnly()).isTrue();
try (ResultSet rs = connection.createStatement().executeQuery("SELECT 1")) {
assertThat(rs.next()).isTrue();
assertThat(rs.getInt(1)).isEqualTo(1);
}
connection.commit();
cs.setReadOnly(false);
assertThat(cs.isRetryAbortsInternally()).isFalse();
}
use of com.google.cloud.spanner.jdbc.CloudSpannerJdbcConnection in project liquibase-spanner by cloudspannerecosystem.
the class CloudSpanner method setConnection.
@Override
public void setConnection(final DatabaseConnection conn) {
DatabaseConnection connectionToUse = conn;
// moment.
if (!(conn instanceof CloudSpannerConnection) && conn instanceof JdbcConnection && ((JdbcConnection) conn).getUnderlyingConnection() instanceof CloudSpannerJdbcConnection) {
// user-agent string.
if (!conn.getURL().contains("userAgent=")) {
// connection that will be used by Liquibase with the correct user-agent.
try {
connectionToUse = new CloudSpannerConnection(DriverManager.getConnection(conn.getURL() + ";userAgent=sp-liq"), conn);
} catch (SQLException e) {
// Ignore and use the original connection. This could for example happen if the user is
// using an older version of the Spanner JDBC driver that does not support this user-agent
// string.
}
}
}
super.setConnection(connectionToUse);
}
Aggregations