use of com.mongodb.internal.operation.AbortTransactionOperation in project mongo-java-driver by mongodb.
the class ClientSessionImpl method abortTransaction.
@Override
public void abortTransaction() {
if (transactionState == TransactionState.ABORTED) {
throw new IllegalStateException("Cannot call abortTransaction twice");
}
if (transactionState == TransactionState.COMMITTED) {
throw new IllegalStateException("Cannot call abortTransaction after calling commitTransaction");
}
if (transactionState == TransactionState.NONE) {
throw new IllegalStateException("There is no transaction started");
}
try {
if (messageSentInCurrentTransaction) {
ReadConcern readConcern = transactionOptions.getReadConcern();
if (readConcern == null) {
throw new MongoInternalException("Invariant violated. Transaction options read concern can not be null");
}
delegate.getOperationExecutor().execute(new AbortTransactionOperation(transactionOptions.getWriteConcern()).recoveryToken(getRecoveryToken()), readConcern, this);
}
} catch (Exception e) {
// ignore exceptions from abort
} finally {
clearTransactionContext();
cleanupTransaction(TransactionState.ABORTED);
}
}
use of com.mongodb.internal.operation.AbortTransactionOperation in project mongo-java-driver by mongodb.
the class ClientSessionPublisherImpl method abortTransaction.
@Override
public Publisher<Void> abortTransaction() {
if (transactionState == TransactionState.ABORTED) {
throw new IllegalStateException("Cannot call abortTransaction twice");
}
if (transactionState == TransactionState.COMMITTED) {
throw new IllegalStateException("Cannot call abortTransaction after calling commitTransaction");
}
if (transactionState == TransactionState.NONE) {
throw new IllegalStateException("There is no transaction started");
}
if (!messageSentInCurrentTransaction) {
cleanupTransaction(TransactionState.ABORTED);
return Mono.create(MonoSink::success);
} else {
ReadConcern readConcern = transactionOptions.getReadConcern();
if (readConcern == null) {
throw new MongoInternalException("Invariant violated. Transaction options read concern can not be null");
}
return executor.execute(new AbortTransactionOperation(transactionOptions.getWriteConcern()).recoveryToken(getRecoveryToken()), readConcern, this).onErrorResume(Throwable.class, (e) -> Mono.empty()).doOnTerminate(() -> {
clearTransactionContext();
cleanupTransaction(TransactionState.ABORTED);
});
}
}
Aggregations