Search in sources :

Example 6 with CloudSpannerConnection

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

the class CloudSpannerParameterMetaDataTest method createStatement.

private CloudSpannerPreparedStatement createStatement(String sql) throws SQLException {
    CloudSpannerConnection connection = mock(CloudSpannerConnection.class);
    CloudSpannerDatabaseMetaData metadata = mock(CloudSpannerDatabaseMetaData.class);
    CloudSpannerResultSet columns = mock(CloudSpannerResultSet.class);
    TableKeyMetaData table = mock(TableKeyMetaData.class);
    when(table.getKeyColumns()).thenReturn(Arrays.asList("COL1"));
    when(connection.getTable("FOO")).thenReturn(table);
    when(connection.getMetaData()).thenAnswer(new Returns(metadata));
    when(metadata.getColumns(null, null, "FOO", null)).thenReturn(columns);
    final ColumnsNextAnswer next = new ColumnsNextAnswer();
    when(columns.next()).thenAnswer(next);
    when(columns.getString("COLUMN_NAME")).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return Arrays.asList("COL1", "COL2", "COL3").get(next.nextCalled - 1);
        }
    });
    when(columns.getInt("COLUMN_SIZE")).thenAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            return Arrays.asList(8, 50, 100).get(next.nextCalled - 1);
        }
    });
    when(columns.getInt("DATA_TYPE")).thenAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            return Arrays.asList(Types.BIGINT, Types.NVARCHAR, Types.NVARCHAR).get(next.nextCalled - 1);
        }
    });
    when(columns.getInt("NULLABLE")).thenAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            return Arrays.asList(ParameterMetaData.parameterNoNulls, ParameterMetaData.parameterNoNulls, ParameterMetaData.parameterNullable).get(next.nextCalled - 1);
        }
    });
    return new CloudSpannerPreparedStatement(sql, connection, null);
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) TableKeyMetaData(nl.topicus.jdbc.MetaDataStore.TableKeyMetaData) CloudSpannerDatabaseMetaData(nl.topicus.jdbc.CloudSpannerDatabaseMetaData) Returns(org.mockito.internal.stubbing.answers.Returns) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CloudSpannerResultSet(nl.topicus.jdbc.resultset.CloudSpannerResultSet)

Example 7 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testGetGeneratedKeys.

@Test
public void testGetGeneratedKeys() throws SQLException {
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    try (ResultSet rs = statement.getGeneratedKeys()) {
        assertFalse(rs.next());
    }
}
Also used : ResultSet(java.sql.ResultSet) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 8 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testInsertWithGetTimestamp.

@Test
public void testInsertWithGetTimestamp() throws SQLException {
    thrown.expect(CloudSpannerSQLException.class);
    thrown.expectMessage("Function calls such as for example GET_TIMESTAMP() are not allowed in client side insert/update statements");
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    String sql = "INSERT INTO providers\n" + "(provider_id, created, device_id, document_number, document_type_id, name, notification, phone, updated, last_access, deleted, token_fcm)\n" + "VALUES('000000', CURRENT_DATE(), 'not-device-id', null, null, 'provider-promocion', false, null, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), false, 'not-token')";
    statement.execute(sql);
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 9 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testExecuteNormalMode.

@Test
public void testExecuteNormalMode() throws SQLException {
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    boolean res = statement.execute("SELECT * FROM FOO");
    assertTrue(res);
    ResultSet rs = statement.getResultSet();
    assertNotNull(rs);
    assertFalse(rs.isClosed());
    assertFalse(statement.getMoreResults());
    assertNull(statement.getResultSet());
}
Also used : ResultSet(java.sql.ResultSet) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 10 with CloudSpannerConnection

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

the class CloudSpannerStatementTest method testIsDDLStatement.

@Test
public void testIsDDLStatement() throws SQLException {
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    Assert.assertTrue(statement.isDDLStatement(statement.getTokens("CREATE TABLE FOO (ID INT64 NOT NULL, COL1 STRING(100) NOT NULL) PRIMARY KEY (ID)")));
    Assert.assertTrue(statement.isDDLStatement(statement.getTokens("ALTER TABLE FOO ADD COLUMN COL2 STRING(100) NOT NULL")));
    Assert.assertTrue(statement.isDDLStatement(statement.getTokens("DROP TABLE FOO")));
    Assert.assertTrue(statement.isDDLStatement(statement.getTokens("CREATE INDEX IDX_FOO ON FOO (COL1)")));
    Assert.assertTrue(statement.isDDLStatement(statement.getTokens("DROP INDEX IDX_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