Search in sources :

Example 26 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class ExtendedModeIT method test2_ExtendedModeDelete.

@Test
public void test2_ExtendedModeDelete() throws SQLException {
    ((CloudSpannerConnection) getConnection()).setAllowExtendedMode(true);
    try (ResultSet rs = getConnection().createStatement().executeQuery("select count(*) from test where id<10")) {
        while (rs.next()) {
            assertEquals(10L, rs.getLong(1));
        }
    }
    PreparedStatement ps = getConnection().prepareStatement("delete from test where id<?");
    ps.setLong(1, 10L);
    ps.executeUpdate();
    getConnection().commit();
    try (ResultSet rs = getConnection().createStatement().executeQuery("select count(*) from test where id<10")) {
        while (rs.next()) {
            assertEquals(0L, rs.getLong(1));
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) PreparedStatement(java.sql.PreparedStatement) IntegrationTest(nl.topicus.jdbc.test.category.IntegrationTest) Test(org.junit.Test)

Example 27 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class LoggerIT method testLogLongTransaction.

private void testLogLongTransaction(int logLevel) throws SQLException, InterruptedException {
    StringWriter writer = new StringWriter();
    DriverManager.setLogWriter(new PrintWriter(writer));
    CloudSpannerDriver.setLongTransactionTrigger(1000L);
    CloudSpannerConnection connection = (CloudSpannerConnection) getConnection();
    connection.setAutoCommit(false);
    connection.getLogger().setLogLevel(logLevel);
    try (ResultSet rs = connection.createStatement().executeQuery("SELECT 1")) {
        while (rs.next()) {
        }
    }
    // Wait for 7 seconds to ensure the keep-alive query is triggered
    Thread.sleep(7000L);
    connection.commit();
    assertTrue(writer.toString().contains("Transaction has been inactive for more than 5 seconds and will do a keep-alive query"));
    assertEquals(logLevel >= CloudSpannerDriver.DEBUG, writer.toString().contains("Transaction was started by: "));
}
Also used : StringWriter(java.io.StringWriter) ResultSet(java.sql.ResultSet) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) PrintWriter(java.io.PrintWriter)

Example 28 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerStatementTest method testBatchDMLThenDDL.

@Test
public void testBatchDMLThenDDL() throws SQLException {
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    thrown.expect(SQLFeatureNotSupportedException.class);
    thrown.expectMessage("DDL statements may not be batched together with DML statements");
    statement.addBatch(BATCH_DML);
    statement.addBatch(BATCH_DDL);
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 29 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerStatementTest method testShowDdlOperations.

@Test
public void testShowDdlOperations() throws SQLException {
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    Assert.assertTrue(statement.execute("SHOW_DDL_OPERATIONS"));
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 30 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerStatementTest method testBatchSelect.

@Test
public void testBatchSelect() throws SQLException {
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    thrown.expect(SQLFeatureNotSupportedException.class);
    thrown.expectMessage("SELECT statements may not be batched");
    statement.addBatch("SELECT * FROM FOO");
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Aggregations

CloudSpannerConnection (nl.topicus.jdbc.CloudSpannerConnection)37 Test (org.junit.Test)22 UnitTest (nl.topicus.jdbc.test.category.UnitTest)17 ResultSet (java.sql.ResultSet)11 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 IntegrationTest (nl.topicus.jdbc.test.category.IntegrationTest)5 SQLException (java.sql.SQLException)4 Returns (org.mockito.internal.stubbing.answers.Returns)4 TableKeyMetaData (nl.topicus.jdbc.MetaDataStore.TableKeyMetaData)3 CloudSpannerResultSet (nl.topicus.jdbc.resultset.CloudSpannerResultSet)3 Select (net.sf.jsqlparser.statement.select.Select)2 CloudSpannerDataSourceTest (nl.topicus.jdbc.CloudSpannerDataSourceTest)2 CloudSpannerDatabaseMetaData (nl.topicus.jdbc.CloudSpannerDatabaseMetaData)2 CloudSpannerXADataSource (nl.topicus.jdbc.CloudSpannerXADataSource)2 CloudSpannerSQLException (nl.topicus.jdbc.exception.CloudSpannerSQLException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Code (com.google.rpc.Code)1 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 PropertyVetoException (java.beans.PropertyVetoException)1