Interface Stage.SessionFactory
-
- All Superinterfaces:
AutoCloseable
- Enclosing interface:
- Stage
public static interface Stage.SessionFactory extends AutoCloseable
Factory forreactive sessions.A
Stage.SessionFactorymay be obtained from an instance ofEntityManagerFactoryas follows:Stage.SessionFactory sessionFactory = createEntityManagerFactory("example") .unwrap(Stage.SessionFactory.class);Here, configuration properties must be specified inpersistence.xml.Alternatively, a
Stage.SessionFactorymay 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 Summary
-
-
-
Method Detail
-
openSession
CompletionStage<Stage.Session> openSession()
Obtain a newreactive sessionCompletionStage, the main interaction point between the user's program and Hibernate Reactive.When the
CompletionStagecompletes successfully it returns a newly created session.The client must explicitly close the session by calling
Stage.Closeable.close().- See Also:
withSession(Function)
-
openSession
CompletionStage<Stage.Session> openSession(String tenantId)
Obtain a newreactive sessionCompletionStagefor a specified tenant.When the
CompletionStagecompletes 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
CompletionStage<Stage.StatelessSession> openStatelessSession()
Obtain areactive stateless sessionCompletionStage.When the
CompletionStagecompletes successfully it returns a newly created session.The client must explicitly close the session by calling
Stage.StatelessSession.close().
-
openStatelessSession
CompletionStage<Stage.StatelessSession> openStatelessSession(String tenantId)
Obtain areactive stateless sessionCompletionStage.When the
CompletionStagecompletes 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> CompletionStage<T> withSession(Function<Stage.Session,CompletionStage<T>> work)
Perform work using areactive 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 aCompletionStage.
-
withSession
<T> CompletionStage<T> withSession(String tenantId, Function<Stage.Session,CompletionStage<T>> work)
Perform work using areactive sessionfor a specified tenant.- If there is already a session associated with the current reactive stream, and the given tenant, then the work will be executed using that session.
- Otherwise, a new session will be created.
The session will be closed automatically, but must be flushed explicitly if necessary.
- Parameters:
tenantId- the id of the tenantwork- a function which accepts the session and returns the result of the work as aCompletionStage.
-
withTransaction
<T> CompletionStage<T> withTransaction(BiFunction<Stage.Session,Stage.Transaction,CompletionStage<T>> work)
Perform work using areactive sessionwithin an associatedtransaction.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be
flushedand closed automatically, and the transaction committed automatically.- Parameters:
work- a function which accepts the session and transaction and returns the result of the work as aCompletionStage.- See Also:
withSession(Function),Stage.Session.withTransaction(Function)
-
withTransaction
default <T> CompletionStage<T> withTransaction(Function<Stage.Session,CompletionStage<T>> work)
Perform work using areactive sessionwithin an associated transaction.- 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 stateless session associated with the current stream, a new stateless session will be created.
The session will be
flushedand closed automatically, and the transaction committed automatically.- Parameters:
work- a function which accepts the session and returns the result of the work as aCompletionStage.- See Also:
withTransaction(BiFunction),Stage.Session.withTransaction(Function)
-
withTransaction
<T> CompletionStage<T> withTransaction(String tenantId, BiFunction<Stage.Session,Stage.Transaction,CompletionStage<T>> work)
Perform work using areactive sessionfor a specified tenant within an associatedtransaction.- If there is already a session associated with the current reactive stream and the given tenant, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream and the given tenant, a new stateless session will be created.
The session will be
flushedand closed automatically, and the transaction committed automatically.- Parameters:
tenantId- the id of the tenantwork- a function which accepts the session and returns the result of the work as aCompletionStage.- See Also:
withSession(String, Function),Stage.Session.withTransaction(Function)
-
withStatelessTransaction
default <T> CompletionStage<T> withStatelessTransaction(Function<Stage.StatelessSession,CompletionStage<T>> work)
Perform work using areactive sessionwithin an associatedtransaction.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically, and the transaction committed automatically.
- Parameters:
work- a function which accepts the stateless session and returns the result of the work as aCompletionStage.- See Also:
withStatelessSession(Function),Stage.StatelessSession.withTransaction(Function)
-
withStatelessTransaction
<T> CompletionStage<T> withStatelessTransaction(BiFunction<Stage.StatelessSession,Stage.Transaction,CompletionStage<T>> work)
Perform work using areactive sessionwithin an associatedtransaction.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically, and the transaction committed automatically.
- Parameters:
work- a function which accepts the stateless session and returns the result of the work as aCompletionStage.- See Also:
withStatelessSession(Function),Stage.StatelessSession.withTransaction(Function)
-
withStatelessTransaction
<T> CompletionStage<T> withStatelessTransaction(String tenantId, BiFunction<Stage.StatelessSession,Stage.Transaction,CompletionStage<T>> work)
Perform work using areactive sessionwithin an associatedtransaction.- If there is already a stateless session associated with the current reactive stream and the given tenant, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically, and the transaction committed automatically.
- Parameters:
tenantId- the id of the tenantwork- a function which accepts the stateless session and returns the result of the work as aCompletionStage.- See Also:
withStatelessSession(String, Function),Stage.StatelessSession.withTransaction(Function)
-
withStatelessSession
<T> CompletionStage<T> withStatelessSession(Function<Stage.StatelessSession,CompletionStage<T>> work)
Perform work using astateless session.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically.
- Parameters:
work- a function which accepts the session and returns the result of the work as aCompletionStage.
-
withStatelessSession
<T> CompletionStage<T> withStatelessSession(String tenantId, Function<Stage.StatelessSession,CompletionStage<T>> work)
Perform work using astateless session.- If there is already a stateless session associated with the current reactive stream, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream, a new stateless session will be created.
The session will be closed automatically.
- Parameters:
tenantId- the id of the tenantwork- a function which accepts the session and returns the result of the work as aCompletionStage.
-
getCriteriaBuilder
jakarta.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
- Returns:
- an instance of
CriteriaBuilderfor creating criteria queries.
-
getMetamodel
jakarta.persistence.metamodel.Metamodel getMetamodel()
Obtain the JPAMetamodelfor the persistence unit.
-
getStatistics
Statistics getStatistics()
Obtain theStatisticsobject exposing factory-level metrics.
-
close
void close()
Destroy the session factory and clean up its connection pool.- Specified by:
closein interfaceAutoCloseable
-
isOpen
boolean isOpen()
- Returns:
- false if
close()has been called
-
-