use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project pgadapter by GoogleCloudPlatform.
the class StatementParser method parseCommands.
public static ImmutableList<String> parseCommands(ImmutableList<ParsedStatement> statements) {
Preconditions.checkNotNull(statements);
ImmutableList.Builder<String> builder = ImmutableList.builder();
for (ParsedStatement stat : statements) {
builder.add(parseCommand(stat.getSqlWithoutComments()));
}
return builder.build();
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionImpl method executeUpdateAsync.
public ApiFuture<Long> executeUpdateAsync(Statement update) {
Preconditions.checkNotNull(update);
ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG);
ParsedStatement parsedStatement = getStatementParser().parse(update);
if (parsedStatement.isUpdate()) {
switch(parsedStatement.getType()) {
case UPDATE:
return internalExecuteUpdateAsync(parsedStatement);
case CLIENT_SIDE:
case QUERY:
case DDL:
case UNKNOWN:
default:
}
}
throw SpannerExceptionFactory.newSpannerException(ErrorCode.INVALID_ARGUMENT, "Statement is not an update statement: " + parsedStatement.getSqlWithoutComments());
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionImpl method executeBatchUpdate.
@Override
public long[] executeBatchUpdate(Iterable<Statement> updates) {
Preconditions.checkNotNull(updates);
ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG);
// Check that there are only DML statements in the input.
List<ParsedStatement> parsedStatements = new LinkedList<>();
for (Statement update : updates) {
ParsedStatement parsedStatement = getStatementParser().parse(update);
switch(parsedStatement.getType()) {
case UPDATE:
parsedStatements.add(parsedStatement);
break;
case CLIENT_SIDE:
case QUERY:
case DDL:
case UNKNOWN:
default:
throw SpannerExceptionFactory.newSpannerException(ErrorCode.INVALID_ARGUMENT, "The batch update list contains a statement that is not an update statement: " + parsedStatement.getSqlWithoutComments());
}
}
return get(internalExecuteBatchUpdateAsync(parsedStatements));
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionImpl method executeAsync.
@Override
public AsyncStatementResult executeAsync(Statement statement) {
Preconditions.checkNotNull(statement);
ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG);
ParsedStatement parsedStatement = getStatementParser().parse(statement, this.queryOptions);
switch(parsedStatement.getType()) {
case CLIENT_SIDE:
return AsyncStatementResultImpl.of(parsedStatement.getClientSideStatement().execute(connectionStatementExecutor, parsedStatement.getSqlWithoutComments()), spanner.getAsyncExecutorProvider());
case QUERY:
return AsyncStatementResultImpl.of(internalExecuteQueryAsync(parsedStatement, AnalyzeMode.NONE));
case UPDATE:
return AsyncStatementResultImpl.of(internalExecuteUpdateAsync(parsedStatement));
case DDL:
return AsyncStatementResultImpl.noResult(executeDdlAsync(parsedStatement));
case UNKNOWN:
default:
}
throw SpannerExceptionFactory.newSpannerException(ErrorCode.INVALID_ARGUMENT, "Unknown statement: " + parsedStatement.getSqlWithoutComments());
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionImpl method parseAndExecuteQuery.
/**
* Parses the given statement as a query and executes it. Throws a {@link SpannerException} if the
* statement is not a query.
*/
private ResultSet parseAndExecuteQuery(Statement query, AnalyzeMode analyzeMode, QueryOption... options) {
Preconditions.checkNotNull(query);
Preconditions.checkNotNull(analyzeMode);
ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG);
ParsedStatement parsedStatement = getStatementParser().parse(query, this.queryOptions);
if (parsedStatement.isQuery()) {
switch(parsedStatement.getType()) {
case CLIENT_SIDE:
return parsedStatement.getClientSideStatement().execute(connectionStatementExecutor, parsedStatement.getSqlWithoutComments()).getResultSet();
case QUERY:
return internalExecuteQuery(parsedStatement, analyzeMode, options);
case UPDATE:
case DDL:
case UNKNOWN:
default:
}
}
throw SpannerExceptionFactory.newSpannerException(ErrorCode.INVALID_ARGUMENT, "Statement is not a query: " + parsedStatement.getSqlWithoutComments());
}
Aggregations