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 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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
close()
Destroy the session factory and clean up its connection pool.org.hibernate.Cache
getCache()
Obtain theCache
object for managing the second-level cache.jakarta.persistence.criteria.CriteriaBuilder
getCriteriaBuilder()
jakarta.persistence.metamodel.Metamodel
getMetamodel()
Obtain the JPAMetamodel
for the persistence unit.org.hibernate.stat.Statistics
getStatistics()
Obtain theStatistics
object exposing factory-level metrics.boolean
isOpen()
java.util.concurrent.CompletionStage<Stage.Session>
openSession()
Obtain a newreactive session
CompletionStage
, the main interaction point between the user's program and Hibernate Reactive.java.util.concurrent.CompletionStage<Stage.Session>
openSession(java.lang.String tenantId)
Obtain a newreactive session
CompletionStage
for a specified tenant.java.util.concurrent.CompletionStage<Stage.StatelessSession>
openStatelessSession()
Obtain areactive stateless session
CompletionStage
.java.util.concurrent.CompletionStage<Stage.StatelessSession>
openStatelessSession(java.lang.String tenantId)
Obtain areactive stateless session
CompletionStage
.<T> java.util.concurrent.CompletionStage<T>
withSession(java.lang.String tenantId, java.util.function.Function<Stage.Session,java.util.concurrent.CompletionStage<T>> work)
Perform work using areactive session
for a specified tenant.<T> java.util.concurrent.CompletionStage<T>
withSession(java.util.function.Function<Stage.Session,java.util.concurrent.CompletionStage<T>> work)
Perform work using areactive session
.<T> java.util.concurrent.CompletionStage<T>
withStatelessSession(java.lang.String tenantId, java.util.function.Function<Stage.StatelessSession,java.util.concurrent.CompletionStage<T>> work)
Perform work using astateless session
.<T> java.util.concurrent.CompletionStage<T>
withStatelessSession(java.util.function.Function<Stage.StatelessSession,java.util.concurrent.CompletionStage<T>> work)
Perform work using astateless session
.<T> java.util.concurrent.CompletionStage<T>
withStatelessTransaction(java.lang.String tenantId, java.util.function.BiFunction<Stage.StatelessSession,Stage.Transaction,java.util.concurrent.CompletionStage<T>> work)
Perform work using areactive session
within an associatedtransaction
.<T> java.util.concurrent.CompletionStage<T>
withStatelessTransaction(java.util.function.BiFunction<Stage.StatelessSession,Stage.Transaction,java.util.concurrent.CompletionStage<T>> work)
Perform work using areactive session
within an associatedtransaction
.default <T> java.util.concurrent.CompletionStage<T>
withStatelessTransaction(java.util.function.Function<Stage.StatelessSession,java.util.concurrent.CompletionStage<T>> work)
Perform work using areactive session
within an associatedtransaction
.<T> java.util.concurrent.CompletionStage<T>
withTransaction(java.lang.String tenantId, java.util.function.BiFunction<Stage.Session,Stage.Transaction,java.util.concurrent.CompletionStage<T>> work)
Perform work using areactive session
for a specified tenant within an associatedtransaction
.<T> java.util.concurrent.CompletionStage<T>
withTransaction(java.util.function.BiFunction<Stage.Session,Stage.Transaction,java.util.concurrent.CompletionStage<T>> work)
Perform work using areactive session
within an associatedtransaction
.default <T> java.util.concurrent.CompletionStage<T>
withTransaction(java.util.function.Function<Stage.Session,java.util.concurrent.CompletionStage<T>> work)
Perform work using areactive session
within an associated transaction.
-
-
-
Method Detail
-
openSession
java.util.concurrent.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
java.util.concurrent.CompletionStage<Stage.Session> openSession(java.lang.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
java.util.concurrent.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
java.util.concurrent.CompletionStage<Stage.StatelessSession> openStatelessSession(java.lang.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> java.util.concurrent.CompletionStage<T> withSession(java.util.function.Function<Stage.Session,java.util.concurrent.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> java.util.concurrent.CompletionStage<T> withSession(java.lang.String tenantId, java.util.function.Function<Stage.Session,java.util.concurrent.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> java.util.concurrent.CompletionStage<T> withTransaction(java.util.function.BiFunction<Stage.Session,Stage.Transaction,java.util.concurrent.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> java.util.concurrent.CompletionStage<T> withTransaction(java.util.function.Function<Stage.Session,java.util.concurrent.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> java.util.concurrent.CompletionStage<T> withTransaction(java.lang.String tenantId, java.util.function.BiFunction<Stage.Session,Stage.Transaction,java.util.concurrent.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> java.util.concurrent.CompletionStage<T> withStatelessTransaction(java.util.function.Function<Stage.StatelessSession,java.util.concurrent.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> java.util.concurrent.CompletionStage<T> withStatelessTransaction(java.util.function.BiFunction<Stage.StatelessSession,Stage.Transaction,java.util.concurrent.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> java.util.concurrent.CompletionStage<T> withStatelessTransaction(java.lang.String tenantId, java.util.function.BiFunction<Stage.StatelessSession,Stage.Transaction,java.util.concurrent.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> java.util.concurrent.CompletionStage<T> withStatelessSession(java.util.function.Function<Stage.StatelessSession,java.util.concurrent.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> java.util.concurrent.CompletionStage<T> withStatelessSession(java.lang.String tenantId, java.util.function.Function<Stage.StatelessSession,java.util.concurrent.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.
-
getCache
org.hibernate.Cache getCache()
Obtain theCache
object for managing the second-level cache.
-
getStatistics
org.hibernate.stat.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 interfacejava.lang.AutoCloseable
-
isOpen
boolean isOpen()
- Returns:
- false if
close()
has been called
-
-