Search in sources :

Example 11 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testCleanDdlOperations.

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

Example 12 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testBatchCustom.

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

Example 13 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testAutoBatch.

@Test
public void testAutoBatch() throws SQLException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    CloudSpannerConnection connection = createConnection();
    Mockito.doCallRealMethod().when(connection).addAutoBatchedDdlOperation(Mockito.anyString());
    Mockito.doCallRealMethod().when(connection).clearAutoBatchedDdlOperations();
    Mockito.doCallRealMethod().when(connection).getAutoBatchedDdlOperations();
    Mockito.when(connection.isAutoBatchDdlOperations()).then(new Returns(true));
    Field field = CloudSpannerConnection.class.getDeclaredField("autoBatchedDdlOperations");
    field.setAccessible(true);
    field.set(connection, new ArrayList<String>());
    CloudSpannerStatement statement = connection.createStatement();
    assertEquals(0, connection.getAutoBatchedDdlOperations().size());
    statement.execute(BATCH_DDL);
    assertEquals(1, connection.getAutoBatchedDdlOperations().size());
    statement.execute(BATCH_DML);
    assertEquals(1, connection.getAutoBatchedDdlOperations().size());
    statement.execute("EXECUTE_DDL_BATCH");
    assertEquals(0, connection.getAutoBatchedDdlOperations().size());
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) Field(java.lang.reflect.Field) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 14 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testExecuteBatchReadOnlyMode.

private void testExecuteBatchReadOnlyMode(boolean keepCurrent) throws SQLException {
    CloudSpannerConnection connection = createConnection();
    connection.setAutoCommit(false);
    connection.setBatchReadOnly(true);
    CloudSpannerStatement statement = connection.createStatement();
    boolean res = statement.execute("SELECT * FROM FOO");
    int count = 0;
    ResultSet prev = null;
    assertTrue(res);
    do {
        if (prev != null)
            assertEquals(keepCurrent, !prev.isClosed());
        ResultSet rs = statement.getResultSet();
        assertNotNull(rs);
        assertFalse(rs.isClosed());
        prev = rs;
        count++;
    } while (keepCurrent ? statement.getMoreResults(Statement.KEEP_CURRENT_RESULT) : statement.getMoreResults());
    assertFalse(statement.getMoreResults());
    assertNull(statement.getResultSet());
    assertEquals(3, count);
}
Also used : ResultSet(java.sql.ResultSet) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection)

Example 15 with CloudSpannerConnection

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

the class ExtendedModeIT method test4_ExtendedModeUpdateWithNull.

@Test
public void test4_ExtendedModeUpdateWithNull() throws SQLException {
    ((CloudSpannerConnection) getConnection()).setAllowExtendedMode(true);
    try (ResultSet rs = getConnection().createStatement().executeQuery("select count(*) from test where id=40 and name like '4%'")) {
        while (rs.next()) {
            assertEquals(1L, rs.getLong(1));
        }
    }
    PreparedStatement ps = getConnection().prepareStatement("delete from test where id=? and name like coalesce(?, '5%')");
    ps.setLong(1, 40L);
    ps.setNull(2, Types.NVARCHAR);
    ps.executeUpdate();
    getConnection().commit();
    try (ResultSet rs = getConnection().createStatement().executeQuery("select count(*) from test where id=40 and name like '4%'")) {
        while (rs.next()) {
            assertEquals(1L, 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)

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