Interface Stage.SessionFactory

  • All Superinterfaces:
    java.lang.AutoCloseable
    All Known Implementing Classes:
    StageSessionFactoryImpl
    Enclosing interface:
    Stage

    public static interface Stage.SessionFactory
    extends java.lang.AutoCloseable
    Factory for reactive sessions.

    A Stage.SessionFactory may be obtained from an instance of EntityManagerFactory as follows:

     Stage.SessionFactory sessionFactory =
                            createEntityManagerFactory("example")
                                    .unwrap(Stage.SessionFactory.class);
     
    Here, configuration properties must be specified in persistence.xml.

    Alternatively, a Stage.SessionFactory may be obtained via programmatic configuration of Hibernate using:

     Configuration configuration = new Configuration();
     ...
     Stage.SessionFactory sessionFactory =
                    configuration.buildSessionFactory(
                            new ReactiveServiceRegistryBuilder()
                                    .applySettings( configuration.getProperties() )
                                    .build()
                    )
                    .unwrap(Stage.SessionFactory.class);
     
    • Method Detail

      • openSession

        java.util.concurrent.CompletionStage<Stage.Session> openSession()
        Obtain a new reactive session CompletionStage, the main interaction point between the user's program and Hibernate Reactive.

        When the CompletionStage completes successfully it returns a newly created session.

        The client must explicitly close the session by calling Stage.Closeable.close().

        See Also:
        withSession(Function)
      • openSession

        java.util.concurrent.CompletionStage<Stage.Session> openSession​(java.lang.String tenantId)
        Obtain a new reactive session CompletionStage for a specified tenant.

        When the CompletionStage completes successfully it returns a newly created session.

        The client must explicitly close the session by calling Stage.Closeable.close().

        Parameters:
        tenantId - the id of the tenant
        See Also:
        withSession(Function)
      • openStatelessSession

        java.util.concurrent.CompletionStage<Stage.StatelessSession> openStatelessSession​(java.lang.String tenantId)
        Obtain a reactive stateless session CompletionStage.

        When the CompletionStage completes successfully it returns a newly created session.

        The client must explicitly close the session by calling Stage.StatelessSession.close().

        Parameters:
        tenantId - the id of the tenant
      • withSession

        <T> java.util.concurrent.CompletionStage<T> withSession​(java.util.function.Function<Stage.Session,​java.util.concurrent.CompletionStage<T>> work)
        Perform work using a reactive session.

      • If there is already a session associated with the current reactive stream, then the work will be executed using that session.
      • Otherwise, if there is no session associated with the current stream, a new session will be created.

        The session will be closed automatically, but must be flushed explicitly if necessary.

Parameters:
work - a function which accepts the session and returns the result of the work as a CompletionStage.
Parameters:
tenantId - the id of the tenant
work - a function which accepts the session and returns the result of the work as a CompletionStage.