org.springframework.data.mongodb.core

Interface SessionScoped



  • public interface SessionScoped
    Gateway interface to execute ClientSession bound operations against MongoDB via a SessionCallback.

    The very same bound ClientSession is used for all invocations of execute on the instance.

    Since:
    2.1
    Author:
    Christoph Strobl, Mark Paluch
    • Method Detail

      • execute

        @Nullable
        default <T> T execute(SessionCallback<T> action)
        Executes the given SessionCallback within the ClientSession.

        It is up to the caller to make sure the ClientSession is closed when done.

        Type Parameters:
        T - return type.
        Parameters:
        action - callback object that specifies the MongoDB action the callback action. Must not be null.
        Returns:
        a result object returned by the action. Can be null.
      • execute

        @Nullable
        <T> T execute(SessionCallback<T> action,
                                Consumer<com.mongodb.client.ClientSession> doFinally)
        Executes the given SessionCallback within the ClientSession.

        It is up to the caller to make sure the ClientSession is closed when done.

        Type Parameters:
        T - return type.
        Parameters:
        action - callback object that specifies the MongoDB action the callback action. Must not be null.
        doFinally - callback object that accepts ClientSession after invoking SessionCallback. This Consumer is guaranteed to be notified in any case (successful and exceptional outcome of SessionCallback).
        Returns:
        a result object returned by the action. Can be null.