Search in sources :

Example 31 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testSelect.

@Test
public void testSelect() throws SQLException {
    String[] queries = new String[] { "SELECT * FROM FOO", "/* SELECT STATEMENT FOR TABLE FOO*/\nSELECT * FROM FOO", "--SINGLE LINE COMMENT \nSELECT * FROM FOO" };
    for (String sql : queries) {
        CloudSpannerConnection connection = createConnection();
        CloudSpannerStatement statement = connection.createStatement();
        boolean isResultSet = statement.execute(sql);
        Assert.assertTrue(isResultSet);
        ResultSet rs = statement.getResultSet();
        Assert.assertNotNull(rs);
        boolean moreResults = statement.getMoreResults();
        Assert.assertFalse(moreResults);
        Assert.assertTrue(rs.isClosed());
        Assert.assertEquals(-1, statement.getUpdateCount());
        ResultSet rs2 = statement.executeQuery(sql);
        Assert.assertNotNull(rs2);
        Assert.assertFalse(statement.getMoreResults(Statement.KEEP_CURRENT_RESULT));
        Assert.assertFalse(rs2.isClosed());
    }
}
Also used : ResultSet(java.sql.ResultSet) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 32 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testBatch.

private void testBatch(String sql, BatchMode expectedMode) throws SQLException {
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    assertEquals(BatchMode.NONE, statement.getCurrentBatchMode());
    assertEquals(0, statement.getBatch().size());
    statement.addBatch(sql);
    assertEquals(expectedMode, statement.getCurrentBatchMode());
    assertEquals(1, statement.getBatch().size());
    int[] res = statement.executeBatch();
    assertEquals(1, res.length);
    assertEquals(0, statement.getBatch().size());
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection)

Example 33 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testBatchDDLThenDML.

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

Example 34 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method createConnection.

private CloudSpannerConnection createConnection() throws SQLException {
    CloudSpannerConnection connection = CloudSpannerTestObjects.createConnection();
    Mockito.when(connection.createStatement()).thenCallRealMethod();
    Mockito.when(connection.prepareStatement(Mockito.anyString())).thenCallRealMethod();
    return connection;
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection)

Example 35 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testGetTokens.

@Test
public void testGetTokens() throws SQLException {
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    Assert.assertArrayEquals(new String[] { "CREATE", "TABLE", "FOO", "(ID", "INT64)" }, statement.getTokens("   CREATE  TABLE FOO (ID INT64)"));
    Assert.assertArrayEquals(new String[] { "CREATE", "TABLE", "FOO", "(ID", "INT64)" }, statement.getTokens("CREATE TABLE FOO (ID INT64)"));
    Assert.assertArrayEquals(new String[] { "CREATE", "TABLE", "FOO", "(ID", "INT64)" }, statement.getTokens("\t\nCREATE TABLE\n\tFOO (ID INT64)   "));
    Assert.assertArrayEquals(new String[] { "SET_CONNECTION_PROPERTY", "AsyncDdlOperations", "=", "true" }, statement.getTokens("SET_CONNECTION_PROPERTY AsyncDdlOperations=true"));
    Assert.assertArrayEquals(new String[] { "SET_CONNECTION_PROPERTY", "AsyncDdlOperations", "=", "true" }, statement.getTokens("\t\tSET_CONNECTION_PROPERTY     AsyncDdlOperations\t=\ttrue"));
    Assert.assertArrayEquals(new String[] { "SET_CONNECTION_PROPERTY", "AsyncDdlOperations", "=", "true", "AND AllowExtendedMode=true" }, statement.getTokens("SET_CONNECTION_PROPERTY AsyncDdlOperations=true AND AllowExtendedMode=true"));
}
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