Interface ClientSession

All Superinterfaces:
AutoCloseable, com.mongodb.session.ClientSession, Closeable

public interface ClientSession extends com.mongodb.session.ClientSession
A client session that supports transactions.
Since:
1.9
  • Method Summary

    Modifier and Type
    Method
    Description
    Abort a transaction in the context of this session.
    Commit a transaction in the context of this session.
    com.mongodb.TransactionOptions
    Gets the transaction options.
    com.mongodb.internal.observability.micrometer.TransactionSpan
    Get the transaction span (if started).
    boolean
    Returns true if there is an active transaction on this session, and false otherwise
    boolean
    Notify that a message is about to be sent.
    void
    Notify the client session that command execution is being initiated.
    void
    Start a transaction in the context of this session with default transaction options.
    void
    startTransaction(com.mongodb.TransactionOptions transactionOptions)
    Start a transaction in the context of this session with the given transaction options.

    Methods inherited from interface com.mongodb.session.ClientSession

    advanceClusterTime, advanceOperationTime, clearTransactionContext, close, getClusterTime, getOperationTime, getOptions, getOriginator, getOverloadRetryPolicyState, getPinnedServerAddress, getRecoveryToken, getServerSession, getSnapshotTimestamp, getTimeoutContext, getTransactionContext, isCausallyConsistent, setRecoveryToken, setSnapshotTimestamp, setTransactionContext
  • Method Details

    • hasActiveTransaction

      boolean hasActiveTransaction()
      Returns true if there is an active transaction on this session, and false otherwise
      Returns:
      true if there is an active transaction on this session
      Since server release
      4.0
    • notifyMessageSent

      @Internal boolean notifyMessageSent()
      Notify that a message is about to be sent.

      For internal use only

      Returns:
      true Iff the message must bear startTransaction: true.
    • notifyOperationInitiated

      @Internal void notifyOperationInitiated(Object operation)
      Notify the client session that command execution is being initiated. This should be called before server selection occurs.

      For internal use only

      Parameters:
      operation - the operation
    • getTransactionOptions

      com.mongodb.TransactionOptions getTransactionOptions()
      Gets the transaction options. Only call this method of the session has an active transaction
      Returns:
      the transaction options
    • startTransaction

      void startTransaction()
      Start a transaction in the context of this session with default transaction options. A transaction can not be started if there is already an active transaction on this session.
      See Also:
      • MongoException.TRANSIENT_TRANSACTION_ERROR_LABEL
      Since server release
      4.0
    • startTransaction

      void startTransaction(com.mongodb.TransactionOptions transactionOptions)
      Start a transaction in the context of this session with the given transaction options. A transaction can not be started if there is already an active transaction on this session.
      Parameters:
      transactionOptions - the options to apply to the transaction
      See Also:
      • MongoException.TRANSIENT_TRANSACTION_ERROR_LABEL
      Since server release
      4.0
    • commitTransaction

      Publisher<Void> commitTransaction()
      Commit a transaction in the context of this session. A transaction can only be committed if one has first been started.
      Returns:
      an empty publisher that indicates when the operation has completed
      See Also:
      • MongoException.UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL
      Since server release
      4.0
    • abortTransaction

      Publisher<Void> abortTransaction()
      Abort a transaction in the context of this session. A transaction can only be aborted if one has first been started.
      Returns:
      an empty publisher that indicates when the operation has completed
      Since server release
      4.0
    • getTransactionSpan

      @Nullable com.mongodb.internal.observability.micrometer.TransactionSpan getTransactionSpan()
      Get the transaction span (if started).
      Returns:
      the transaction span
      Since:
      5.7