Search in sources :

Example 6 with ReadyResponse

use of com.google.cloud.spanner.pgadapter.wireoutput.ReadyResponse in project pgadapter by GoogleCloudPlatform.

the class FlushMessage method sendPayload.

@Override
protected void sendPayload() throws Exception {
    boolean inTransaction = connection.getSpannerConnection().isInTransaction();
    new ReadyResponse(this.outputStream, inTransaction ? Status.TRANSACTION : ReadyResponse.Status.IDLE).send();
}
Also used : ReadyResponse(com.google.cloud.spanner.pgadapter.wireoutput.ReadyResponse)

Example 7 with ReadyResponse

use of com.google.cloud.spanner.pgadapter.wireoutput.ReadyResponse in project pgadapter by GoogleCloudPlatform.

the class QueryMessage method handleQuery.

/**
 * Simple Query handler, which examined the state of the statement and processes accordingly (if
 * error, handle error, otherwise sends the result and if contains result set, send row
 * description)
 *
 * @throws Exception if handling the query fails
 */
public void handleQuery() throws Exception {
    // Skip unexecuted statements, as no response needs be returned
    for (int index = 0; index < statement.getExecutedCount(); index++) {
        if (this.statement.hasException(index)) {
            new ErrorResponse(this.outputStream, this.statement.getException(index), State.InternalError).send();
        } else if (this.statement.getCommand(index).equalsIgnoreCase(COPY)) {
            CopyStatement copyStatement = (CopyStatement) this.statement;
            new CopyInResponse(this.outputStream, copyStatement.getTableColumns().size(), copyStatement.getFormatCode()).send();
            this.connection.setStatus(ConnectionStatus.COPY_IN);
            // Return early as we do not respond with CommandComplete after a COPY command.
            return;
        } else if ("".equals(this.statement.getCommandTag(index))) {
            new EmptyQueryResponse(outputStream).send();
        } else {
            if (this.statement.containsResultSet(index)) {
                new RowDescriptionResponse(this.outputStream, this.statement, this.statement.getStatementResult(index), this.connection.getServer().getOptions(), QueryMode.SIMPLE).send(false);
            }
            this.sendSpannerResult(index, this.statement, QueryMode.SIMPLE, 0L);
        }
    }
    if (connection.getSpannerConnection().isInTransaction() && connection.getStatus() == ConnectionStatus.TRANSACTION_ABORTED) {
        // Actively rollback the aborted transaction but still block clients
        // Clear any statement tags, as these are not allowed for rollbacks.
        connection.getSpannerConnection().setStatementTag(null);
        connection.getSpannerConnection().rollback();
    }
    new ReadyResponse(this.outputStream, connection.getStatus().getReadyResponseStatus()).send();
    this.connection.cleanUp(this.statement);
}
Also used : RowDescriptionResponse(com.google.cloud.spanner.pgadapter.wireoutput.RowDescriptionResponse) ReadyResponse(com.google.cloud.spanner.pgadapter.wireoutput.ReadyResponse) CopyStatement(com.google.cloud.spanner.pgadapter.statements.CopyStatement) EmptyQueryResponse(com.google.cloud.spanner.pgadapter.wireoutput.EmptyQueryResponse) CopyInResponse(com.google.cloud.spanner.pgadapter.wireoutput.CopyInResponse) ErrorResponse(com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse)

Aggregations

ReadyResponse (com.google.cloud.spanner.pgadapter.wireoutput.ReadyResponse)7 ErrorResponse (com.google.cloud.spanner.pgadapter.wireoutput.ErrorResponse)3 MutationWriter (com.google.cloud.spanner.pgadapter.utils.MutationWriter)2 CopyStatement (com.google.cloud.spanner.pgadapter.statements.CopyStatement)1 AuthenticationOkResponse (com.google.cloud.spanner.pgadapter.wireoutput.AuthenticationOkResponse)1 CopyInResponse (com.google.cloud.spanner.pgadapter.wireoutput.CopyInResponse)1 EmptyQueryResponse (com.google.cloud.spanner.pgadapter.wireoutput.EmptyQueryResponse)1 KeyDataResponse (com.google.cloud.spanner.pgadapter.wireoutput.KeyDataResponse)1 ParameterStatusResponse (com.google.cloud.spanner.pgadapter.wireoutput.ParameterStatusResponse)1 RowDescriptionResponse (com.google.cloud.spanner.pgadapter.wireoutput.RowDescriptionResponse)1 TerminateResponse (com.google.cloud.spanner.pgadapter.wireoutput.TerminateResponse)1