@Override public long advanceTransactionNumber() { return clientSession.getServerSession().advanceTransactionNumber(); }
private static String debugString(@Nullable ClientSession session) { if (session == null) { return "null"; } String debugString = String.format("[%s@%s ", ClassUtils.getShortName(session.getClass()), Integer.toHexString(session.hashCode())); try { if (session.getServerSession() != null) { debugString += String.format("id = %s, ", session.getServerSession().getIdentifier()); debugString += String.format("causallyConsistent = %s, ", session.isCausallyConsistent()); debugString += String.format("txActive = %s, ", session.hasActiveTransaction()); debugString += String.format("txNumber = %d, ", session.getServerSession().getTransactionNumber()); debugString += String.format("closed = %d, ", session.getServerSession().isClosed()); debugString += String.format("clusterTime = %s", session.getClusterTime()); } else { debugString += "id = n/a"; debugString += String.format("causallyConsistent = %s, ", session.isCausallyConsistent()); debugString += String.format("txActive = %s, ", session.hasActiveTransaction()); debugString += String.format("clusterTime = %s", session.getClusterTime()); } } catch (RuntimeException e) { debugString += String.format("error = %s", e.getMessage()); } debugString += "]"; return debugString; }
@Override public long getTransactionNumber() { return clientSession.getServerSession().getTransactionNumber(); }
@Override public BsonDocument getSessionId() { return clientSession.getServerSession().getIdentifier(); }
/** * Close a {@link ClientSession} without regard to its transactional state. */ void closeSession() { ClientSession session = getRequiredSession(); if (session.getServerSession() != null && !session.getServerSession().isClosed()) { session.close(); } }
@Override public long getTransactionNumber() { return clientSession.getServerSession().getTransactionNumber(); }
@Override public BsonDocument getSessionId() { return clientSession.getServerSession().getIdentifier(); }
/** * @return {@literal true} if the session is active and has not been closed. */ boolean hasActiveSession() { if (!hasSession()) { return false; } return hasServerSession() && !getRequiredSession().getServerSession().isClosed(); }
private static String debugString(@Nullable ClientSession session) { if (session == null) { return "null"; } String debugString = String.format("[%s@%s ", ClassUtils.getShortName(session.getClass()), Integer.toHexString(session.hashCode())); try { if (session.getServerSession() != null) { debugString += String.format("id = %s, ", session.getServerSession().getIdentifier()); debugString += String.format("causallyConsistent = %s, ", session.isCausallyConsistent()); debugString += String.format("txActive = %s, ", session.hasActiveTransaction()); debugString += String.format("txNumber = %d, ", session.getServerSession().getTransactionNumber()); debugString += String.format("closed = %d, ", session.getServerSession().isClosed()); debugString += String.format("clusterTime = %s", session.getClusterTime()); } else { debugString += "id = n/a"; debugString += String.format("causallyConsistent = %s, ", session.isCausallyConsistent()); debugString += String.format("txActive = %s, ", session.hasActiveTransaction()); debugString += String.format("clusterTime = %s", session.getClusterTime()); } } catch (RuntimeException e) { debugString += String.format("error = %s", e.getMessage()); } debugString += "]"; return debugString; }
@Override public void startTransaction(final TransactionOptions transactionOptions) { notNull("transactionOptions", transactionOptions); if (transactionState == TransactionState.IN) { throw new IllegalStateException("Transaction already in progress"); } if (transactionState == TransactionState.COMMITTED) { cleanupTransaction(TransactionState.IN); } else { transactionState = TransactionState.IN; } getServerSession().advanceTransactionNumber(); this.transactionOptions = TransactionOptions.merge(transactionOptions, getOptions().getDefaultTransactionOptions()); WriteConcern writeConcern = this.transactionOptions.getWriteConcern(); if (writeConcern == null) { throw new MongoInternalException("Invariant violated. Transaction options write concern can not be null"); } if (!writeConcern.isAcknowledged()) { throw new MongoClientException("Transactions do not support unacknowledged write concern"); } }
/** * Close a {@link ClientSession} without regard to its transactional state. */ void closeSession() { ClientSession session = getRequiredSession(); if (session.getServerSession() != null && !session.getServerSession().isClosed()) { session.close(); } }
@Override public long advanceTransactionNumber() { return clientSession.getServerSession().advanceTransactionNumber(); }
/** * @return {@literal true} if the session is active and has not been closed. */ boolean hasActiveSession() { if (!hasSession()) { return false; } return hasServerSession() && !getRequiredSession().getServerSession().isClosed(); }
@Override public void startTransaction(final TransactionOptions transactionOptions) { notNull("transactionOptions", transactionOptions); if (transactionState == TransactionState.IN) { throw new IllegalStateException("Transaction already in progress"); } if (transactionState == TransactionState.COMMITTED) { cleanupTransaction(TransactionState.IN); } else { transactionState = TransactionState.IN; } getServerSession().advanceTransactionNumber(); this.transactionOptions = TransactionOptions.merge(transactionOptions, getOptions().getDefaultTransactionOptions()); WriteConcern writeConcern = this.transactionOptions.getWriteConcern(); if (writeConcern == null) { throw new MongoInternalException("Invariant violated. Transaction options write concern can not be null"); } if (!writeConcern.isAcknowledged()) { throw new MongoClientException("Transactions do not support unacknowledged write concern"); } }
@Override public void startTransaction(final TransactionOptions transactionOptions) { notNull("transactionOptions", transactionOptions); if (transactionState == TransactionState.IN) { throw new IllegalStateException("Transaction already in progress"); } if (transactionState == TransactionState.COMMITTED) { cleanupTransaction(TransactionState.IN); } else { transactionState = TransactionState.IN; } getServerSession().advanceTransactionNumber(); this.transactionOptions = TransactionOptions.merge(transactionOptions, getOptions().getDefaultTransactionOptions()); WriteConcern writeConcern = this.transactionOptions.getWriteConcern(); if (writeConcern == null) { throw new MongoInternalException("Invariant violated. Transaction options write concern can not be null"); } if (!writeConcern.isAcknowledged()) { throw new MongoClientException("Transactions do not support unacknowledged write concern"); } }