use of com.google.cloud.spanner.ReadContext in project spanner-jdbc by olavloite.
the class CloudSpannerStatement method executeQuery.
@Override
public ResultSet executeQuery(String sql) throws SQLException {
String[] sqlTokens = getTokens(sql);
CustomDriverStatement custom = getCustomDriverStatement(sqlTokens);
if (custom != null && custom.isQuery()) {
return custom.executeQuery(sqlTokens);
}
try (ReadContext context = getReadContext()) {
com.google.cloud.spanner.ResultSet rs = context.executeQuery(com.google.cloud.spanner.Statement.of(sql));
return new CloudSpannerResultSet(this, rs);
}
}
use of com.google.cloud.spanner.ReadContext in project spanner-jdbc by olavloite.
the class CloudSpannerPreparedStatement method executeQuery.
@Override
public ResultSet executeQuery() throws SQLException {
CustomDriverStatement custom = getCustomDriverStatement(sqlTokens);
if (custom != null && custom.isQuery()) {
return custom.executeQuery(sqlTokens);
}
Statement statement;
try {
statement = CCJSqlParserUtil.parse(sanitizeSQL(sql));
} catch (JSQLParserException | TokenMgrError e) {
throw new CloudSpannerSQLException(PARSE_ERROR + sql + ": " + e.getLocalizedMessage(), Code.INVALID_ARGUMENT, e);
}
if (statement instanceof Select) {
determineForceSingleUseReadContext((Select) statement);
com.google.cloud.spanner.Statement.Builder builder = createSelectBuilder(statement, sql);
try (ReadContext context = getReadContext()) {
com.google.cloud.spanner.ResultSet rs = context.executeQuery(builder.build());
return new CloudSpannerResultSet(this, rs);
}
}
throw new CloudSpannerSQLException("SQL statement not suitable for executeQuery. Expected SELECT-statement.", Code.INVALID_ARGUMENT);
}
Aggregations