Interface Stage.SessionFactory
-
- All Superinterfaces:
AutoCloseable
- Enclosing interface:
- Stage
public static interface Stage.SessionFactory extends AutoCloseable
Factory forreactive sessions
.A
Stage.SessionFactory
may be obtained from an instance ofEntityManagerFactory
as follows:Stage.SessionFactory sessionFactory = createEntityManagerFactory("example") .unwrap(Stage.SessionFactory.class);
Here, configuration properties must be specified inpersistence.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 Summary
-
-
-
Method Detail
-
openSession
CompletionStage<Stage.Session> openSession()
Obtain a newreactive 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
CompletionStage<Stage.Session> openSession(String tenantId)
Obtain a newreactive 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
CompletionStage<Stage.StatelessSession> openStatelessSession()
Obtain areactive 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()
.
-
openStatelessSession
CompletionStage<Stage.StatelessSession> openStatelessSession(String tenantId)
Obtain areactive 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> 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 session
for 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 session
within 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
flushed
and 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 session
within 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
flushed
and 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 session
for 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
flushed
and 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 session
within 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 session
within 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 session
within 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
CriteriaBuilder
for creating criteria queries.
-
getMetamodel
jakarta.persistence.metamodel.Metamodel getMetamodel()
Obtain the JPAMetamodel
for the persistence unit.
-
getStatistics
Statistics getStatistics()
Obtain theStatistics
object exposing factory-level metrics.
-
close
void close()
Destroy the session factory and clean up its connection pool.- Specified by:
close
in interfaceAutoCloseable
-
isOpen
boolean isOpen()
- Returns:
- false if
close()
has been called
-
-