Search in sources :

Example 1 with ReadContext

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);
    }
}
Also used : ReadContext(com.google.cloud.spanner.ReadContext) CloudSpannerResultSet(nl.topicus.jdbc.resultset.CloudSpannerResultSet)

Example 2 with ReadContext

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);
}
Also used : Statement(net.sf.jsqlparser.statement.Statement) JSQLParserException(net.sf.jsqlparser.JSQLParserException) TokenMgrError(net.sf.jsqlparser.parser.TokenMgrError) CloudSpannerSQLException(nl.topicus.jdbc.exception.CloudSpannerSQLException) ReadContext(com.google.cloud.spanner.ReadContext) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) SubSelect(net.sf.jsqlparser.statement.select.SubSelect) Select(net.sf.jsqlparser.statement.select.Select) CloudSpannerResultSet(nl.topicus.jdbc.resultset.CloudSpannerResultSet)

Aggregations

ReadContext (com.google.cloud.spanner.ReadContext)2 CloudSpannerResultSet (nl.topicus.jdbc.resultset.CloudSpannerResultSet)2 JSQLParserException (net.sf.jsqlparser.JSQLParserException)1 TokenMgrError (net.sf.jsqlparser.parser.TokenMgrError)1 Statement (net.sf.jsqlparser.statement.Statement)1 PlainSelect (net.sf.jsqlparser.statement.select.PlainSelect)1 Select (net.sf.jsqlparser.statement.select.Select)1 SubSelect (net.sf.jsqlparser.statement.select.SubSelect)1 CloudSpannerSQLException (nl.topicus.jdbc.exception.CloudSpannerSQLException)1