in src/main/java/software/amazon/qldb/QldbSession.java [56:123]
<T> T execute(Executor<T> executor) {
Transaction txn = null;
String txnId = "None";
try {
txn = this.startTransaction();
txnId = txn.getTransactionId();
T returnedValue = executor.execute(new TransactionExecutor(txn));
if (returnedValue instanceof StreamResult) {
// If someone accidentally returned a StreamResult object which would become invalidated by the
// commit, automatically buffer it to allow them to use the result anyway.
returnedValue = (T) new BufferedResult((Result) returnedValue);
}
txn.commit();
return returnedValue;
} catch (InvalidSessionException ise) {
boolean isAborted = false;
boolean transactionExpired = ise.getMessage().matches("Transaction.*has expired.*");
if (transactionExpired) {
isAborted = this.tryAbort(txn);
}
throw new ExecuteException(
ise,
!transactionExpired,
isAborted,
true,
txnId
);
} catch (OccConflictException oce) {
throw new ExecuteException(
oce,
true,
true,
false,
txnId
);
} catch (QldbSessionException qse) {
boolean retryable = (qse.statusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR)
|| (qse.statusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE);
throw new ExecuteException(
qse,
retryable,
this.tryAbort(txn),
false,
txnId
);
} catch (SdkClientException sce) {
// SdkClientException means that client couldn't reach out QLDB so transaction should be retried.
throw new ExecuteException(
sce,
true,
this.tryAbort(txn),
false,
txnId
);
} catch (RuntimeException re) {
throw new ExecuteException(
re,
false,
this.tryAbort(txn),
false,
txnId
);
} finally {
if (txn != null) {
txn.internalClose();
}
}
}