use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteGetAutocommit.
@Test
public void testExecuteGetAutocommit() {
ParsedStatement statement = parser.parse(Statement.of("show variable autocommit"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementShowAutocommit()).thenCallRealMethod();
statement.getClientSideStatement().execute(executor, "show variable autocommit");
verify(connection, times(1)).isAutocommit();
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteGetReadTimestamp.
@Test
public void testExecuteGetReadTimestamp() {
ParsedStatement statement = parser.parse(Statement.of("show variable read_timestamp"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementShowReadTimestamp()).thenCallRealMethod();
when(connection.getReadTimestampOrNull()).thenReturn(Timestamp.now());
statement.getClientSideStatement().execute(executor, "show variable read_timestamp");
verify(connection, times(1)).getReadTimestampOrNull();
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithOneParameterTest method testExecuteSetReadOnly.
@Test
public void testExecuteSetReadOnly() {
ParsedStatement subject = parser.parse(Statement.of("set readonly = true"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementSetReadOnly(any(Boolean.class))).thenCallRealMethod();
for (Boolean mode : new Boolean[] { Boolean.FALSE, Boolean.TRUE }) {
subject.getClientSideStatement().execute(executor, String.format("set readonly = %s", mode));
verify(connection, times(1)).setReadOnly(mode);
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class StatementParserTest method testStatementWithCommentContainingSlash.
@Test
public void testStatementWithCommentContainingSlash() {
String sql = "/*\n" + " * Script for testing invalid/unrecognized statements\n" + " */\n" + "\n" + "-- MERGE into test comment MERGE -- \n" + "@EXPECT EXCEPTION INVALID_ARGUMENT 'INVALID_ARGUMENT: Unknown statement'\n" + "MERGE INTO Singers s\n" + "/*** test ****/" + "USING (VALUES (1, 'John', 'Doe')) v\n" + "ON v.column1 = s.SingerId\n" + "WHEN NOT MATCHED \n" + " INSERT VALUES (v.column1, v.column2, v.column3)\n" + "WHEN MATCHED\n" + " UPDATE SET FirstName = v.column2,\n" + " LastName = v.column3;";
String sqlWithoutComments = "@EXPECT EXCEPTION INVALID_ARGUMENT 'INVALID_ARGUMENT: Unknown statement'\n" + "MERGE INTO Singers s\n" + "USING (VALUES (1, 'John', 'Doe')) v\n" + "ON v.column1 = s.SingerId\n" + "WHEN NOT MATCHED \n" + " INSERT VALUES (v.column1, v.column2, v.column3)\n" + "WHEN MATCHED\n" + " UPDATE SET FirstName = v.column2,\n" + " LastName = v.column3";
ParsedStatement statement = parser.parse(Statement.of(sql));
assertThat(statement.getSqlWithoutComments()).isEqualTo(sqlWithoutComments);
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class StatementParserTest method testStatementWithCommentContainingSlashAndNoAsteriskOnNewLine.
@Test
public void testStatementWithCommentContainingSlashAndNoAsteriskOnNewLine() {
String sql = "/*\n" + " * Script for testing invalid/unrecognized statements\n" + " foo bar baz" + " */\n" + "\n" + "-- MERGE INTO test comment MERGE\n" + "@EXPECT EXCEPTION INVALID_ARGUMENT 'INVALID_ARGUMENT: Unknown statement'\n" + "MERGE INTO Singers s\n" + "USING (VALUES (1, 'John', 'Doe')) v\n" + "ON v.column1 = s.SingerId\n" + "-- test again --\n" + "WHEN NOT MATCHED \n" + " INSERT VALUES (v.column1, v.column2, v.column3)\n" + "WHEN MATCHED\n" + " UPDATE SET FirstName = v.column2,\n" + " LastName = v.column3;";
String sqlWithoutComments = "@EXPECT EXCEPTION INVALID_ARGUMENT 'INVALID_ARGUMENT: Unknown statement'\n" + "MERGE INTO Singers s\n" + "USING (VALUES (1, 'John', 'Doe')) v\n" + "ON v.column1 = s.SingerId\n" + "\nWHEN NOT MATCHED \n" + " INSERT VALUES (v.column1, v.column2, v.column3)\n" + "WHEN MATCHED\n" + " UPDATE SET FirstName = v.column2,\n" + " LastName = v.column3";
ParsedStatement statement = parser.parse(Statement.of(sql));
assertThat(statement.getSqlWithoutComments()).isEqualTo(sqlWithoutComments);
}
Aggregations