use of com.mongodb.internal.operation.CommitTransactionOperation in project mongo-java-driver by mongodb.
the class ClientSessionPublisherImpl method commitTransaction.
@Override
public Publisher<Void> commitTransaction() {
if (transactionState == TransactionState.ABORTED) {
throw new IllegalStateException("Cannot call commitTransaction after calling abortTransaction");
}
if (transactionState == TransactionState.NONE) {
throw new IllegalStateException("There is no transaction started");
}
if (!messageSentInCurrentTransaction) {
cleanupTransaction(TransactionState.COMMITTED);
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");
}
boolean alreadyCommitted = commitInProgress || transactionState == TransactionState.COMMITTED;
commitInProgress = true;
return executor.execute(new CommitTransactionOperation(transactionOptions.getWriteConcern(), alreadyCommitted).recoveryToken(getRecoveryToken()).maxCommitTime(transactionOptions.getMaxCommitTime(MILLISECONDS), MILLISECONDS), readConcern, this).doOnTerminate(() -> {
commitInProgress = false;
transactionState = TransactionState.COMMITTED;
}).doOnError(MongoException.class, this::clearTransactionContextOnError);
}
}
use of com.mongodb.internal.operation.CommitTransactionOperation in project mongo-java-driver by mongodb.
the class ClientSessionImpl method commitTransaction.
@Override
public void commitTransaction() {
if (transactionState == TransactionState.ABORTED) {
throw new IllegalStateException("Cannot call commitTransaction after calling abortTransaction");
}
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");
}
commitInProgress = true;
delegate.getOperationExecutor().execute(new CommitTransactionOperation(transactionOptions.getWriteConcern(), transactionState == TransactionState.COMMITTED).recoveryToken(getRecoveryToken()).maxCommitTime(transactionOptions.getMaxCommitTime(MILLISECONDS), MILLISECONDS), readConcern, this);
}
} catch (MongoException e) {
clearTransactionContextOnError(e);
throw e;
} finally {
transactionState = TransactionState.COMMITTED;
commitInProgress = false;
}
}
Aggregations