use of com.google.rpc.Code in project spanner-jdbc by olavloite.
the class TransactionThread method stopTransaction.
private void stopTransaction(TransactionStopStatement statement) throws SQLException {
if (status == TransactionStatus.FAIL || status == TransactionStatus.SUCCESS)
return;
while (status == TransactionStatus.NOT_STARTED) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new CloudSpannerSQLException(getFailedMessage(statement, e), Code.ABORTED, e);
}
}
this.stopStatement = statement;
stop = true;
// Add a statement object in order to get the transaction thread to
// proceed
statements.add(Statement.of(statement.name()));
synchronized (monitor) {
while (!stopped || status == TransactionStatus.NOT_STARTED || status == TransactionStatus.RUNNING) {
try {
monitor.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new CloudSpannerSQLException(getFailedMessage(statement, e), Code.ABORTED, e);
}
}
}
if (status == TransactionStatus.FAIL && exception != null) {
Code code = Code.UNKNOWN;
if (exception instanceof CloudSpannerSQLException)
code = ((CloudSpannerSQLException) exception).getCode();
if (exception instanceof SpannerException)
code = Code.forNumber(((SpannerException) exception).getCode());
throw new CloudSpannerSQLException(getFailedMessage(statement, exception), code, exception);
}
}
use of com.google.rpc.Code in project spanner-jdbc by olavloite.
the class CloudSpannerPooledConnection method fireConnectionError.
/**
* Fires a connection error event, but only if we think the exception is fatal.
*
* @param e the SQLException to consider
*/
private void fireConnectionError(SQLException e) {
Code code = Code.UNKNOWN;
if (e instanceof CloudSpannerSQLException) {
code = ((CloudSpannerSQLException) e).getCode();
}
if (!isFatalState(code)) {
return;
}
fireConnectionFatalError(e);
}
Aggregations