use of com.google.cloud.spanner.connection.AbstractStatementParser.StatementType in project java-spanner by googleapis.
the class AbstractConnectionImplTest method testAnalyzeQuery.
private void testAnalyzeQuery(final StatementType type) {
// TODO: add log statements when ANALYZE ... sql statements are supported
try (Connection connection = getConnection()) {
for (QueryAnalyzeMode mode : QueryAnalyzeMode.values()) {
final QueryAnalyzeMode currentMode = mode;
if (type == StatementType.QUERY && isExecuteAllowed(StatementType.QUERY)) {
ResultSet rs = connection.analyzeQuery(getTestStatement(type), currentMode);
assertThat(rs, is(notNullValue()));
while (rs.next()) {
}
assertThat(rs.getStats(), is(notNullValue()));
} else if (type == StatementType.QUERY) {
// it is a query, but queries are not allowed for this connection state
expectSpannerException(type + " should not be allowed", t -> t.analyzeQuery(getTestStatement(type), currentMode), connection, ErrorCode.FAILED_PRECONDITION);
} else {
expectSpannerException(type + " should be an invalid argument", t -> t.analyzeQuery(getTestStatement(type), currentMode), connection, ErrorCode.INVALID_ARGUMENT);
}
}
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.StatementType in project java-spanner by googleapis.
the class AbstractConnectionImplTest method testExecuteQuery.
private void testExecuteQuery(final StatementType type) {
try (Connection connection = getConnection()) {
if (type == StatementType.QUERY && isExecuteAllowed(StatementType.QUERY)) {
log("@EXPECT RESULT_SET 'TEST',1");
log(getTestStatement(type).getSql() + ";");
ResultSet rs = connection.executeQuery(getTestStatement(type));
assertThat(rs, is(notNullValue()));
assertThat(rs.getStats(), is(nullValue()));
} else if (type == StatementType.QUERY) {
// it is a query, but queries are not allowed for this connection state
expectSpannerException(type + " should not be allowed", t -> {
log("@EXPECT EXCEPTION FAILED_PRECONDITION");
log(getTestStatement(type).getSql() + ";");
t.executeQuery(getTestStatement(type));
}, connection, ErrorCode.FAILED_PRECONDITION);
} else {
expectSpannerException(type + " should be an invalid argument", t -> t.executeQuery(getTestStatement(type)), connection, ErrorCode.INVALID_ARGUMENT);
}
}
}
Aggregations