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"));
}
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");
}
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());
}
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);
}
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));
}
}
}
Aggregations