Class Session

java.lang.Object
net.pincette.mongo.Session

public class Session extends Object
A CompletionStage wrapper around client sessions.
Since:
1.1
Author:
Werner Donné
  • Method Details

    • abortTransaction

      public static CompletionStage<Void> abortTransaction(ClientSession session)
    • commitTransaction

      public static CompletionStage<Void> commitTransaction(ClientSession session)
    • create

      public static CompletionStage<ClientSession> create(MongoClient client)
    • inTransaction

      public static <T> CompletionStage<T> inTransaction(Function<ClientSession,CompletionStage<T>> fn, ClientSession session)
      Runs a function in a transaction within a client session with the default transaction options.
      Type Parameters:
      T - the result type.
      Parameters:
      fn - the function to run. When its completion stage completes to null, the transaction will be aborted. When it is not null, the transaction will be committed. When the function throws an exception, it will be rethrown after the abortion of the transaction.
      session - the client session.
      Returns:
      The completion stage that returns success or failure.
      Since:
      2.2.1
    • inTransaction

      public static <T> CompletionStage<T> inTransaction(Function<ClientSession,CompletionStage<T>> fn, ClientSession session, com.mongodb.TransactionOptions options)
      Runs a function in a transaction within a client session.
      Type Parameters:
      T - the result type.
      Parameters:
      fn - the function to run. When its completion stage completes to null, the transaction will be aborted. When it is not null, the transaction will be committed. When the function throws an exception, it will be rethrown after the abortion of the transaction.
      session - the client session.
      options - the transaction options. It may be null, in which case the defaults are used.
      Returns:
      The completion stage that returns success or failure.
      Since:
      2.2.1