Interface Mutiny.SessionFactory
- All Superinterfaces:
AutoCloseable
- Enclosing interface:
- Mutiny
reactive sessions.
A Mutiny.SessionFactory may be obtained from an instance of
EntityManagerFactory as follows:
Mutiny.SessionFactory sessionFactory =
createEntityManagerFactory("example")
.unwrap(Mutiny.SessionFactory.class);
Here, configuration properties must be specified in
persistence.xml.
Alternatively, a Mutiny.SessionFactory may be obtained via
programmatic configuration of Hibernate using:
Configuration configuration = new Configuration();
...
Mutiny.SessionFactory sessionFactory =
configuration.buildSessionFactory(
new ReactiveServiceRegistryBuilder()
.applySettings( configuration.getProperties() )
.build()
)
.unwrap(Mutiny.SessionFactory.class);
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Destroy the session factory and clean up its connection pool.Obtain a newreactive session, the main interaction point between the user's program and Hibernate Reactive.createSession(String tenantId) Obtain a newreactive session.Obtain a newreactive stateless session.createStatelessSession(String tenantId) Obtain a newreactive stateless session.getCache()Obtain theCacheobject for managing the second-level cache.Return the current instance ofMutiny.Session, if any.Return the current instance ofMutiny.Session, if any.Obtain the JPAMetamodelfor the persistence unit.Obtain theStatisticsobject exposing factory-level metrics.booleanisOpen()io.smallrye.mutiny.Uni<Mutiny.Session>Obtain a newreactive sessionUni, the main interaction point between the user's program and Hibernate Reactive.io.smallrye.mutiny.Uni<Mutiny.Session>openSession(String tenantId) Obtain a newreactive sessionUnifor a specified tenant.io.smallrye.mutiny.Uni<Mutiny.StatelessSession>Obtain areactive stateless sessionUni.io.smallrye.mutiny.Uni<Mutiny.StatelessSession>openStatelessSession(String tenantId) Obtain areactive stateless sessionUni.<T> io.smallrye.mutiny.Uni<T>withSession(String tenantId, Function<Mutiny.Session, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session for a specified tenant.<T> io.smallrye.mutiny.Uni<T>withSession(Function<Mutiny.Session, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session.<T> io.smallrye.mutiny.Uni<T>withStatelessSession(String tenantId, Function<Mutiny.StatelessSession, io.smallrye.mutiny.Uni<T>> work) Perform work using a stateless session.<T> io.smallrye.mutiny.Uni<T>withStatelessSession(Function<Mutiny.StatelessSession, io.smallrye.mutiny.Uni<T>> work) Perform work using a stateless session.<T> io.smallrye.mutiny.Uni<T>withStatelessTransaction(String tenantId, BiFunction<Mutiny.StatelessSession, Mutiny.Transaction, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session for the tenant with the specified tenant id within an associatedtransaction.<T> io.smallrye.mutiny.Uni<T>withStatelessTransaction(BiFunction<Mutiny.StatelessSession, Mutiny.Transaction, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session within an associatedtransaction.default <T> io.smallrye.mutiny.Uni<T>withStatelessTransaction(Function<Mutiny.StatelessSession, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session within an associatedtransaction.<T> io.smallrye.mutiny.Uni<T>withTransaction(String tenantId, BiFunction<Mutiny.Session, Mutiny.Transaction, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session for the tenant with the specified tenant id within an associatedtransaction.<T> io.smallrye.mutiny.Uni<T>withTransaction(BiFunction<Mutiny.Session, Mutiny.Transaction, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session within an associatedtransaction.default <T> io.smallrye.mutiny.Uni<T>withTransaction(Function<Mutiny.Session, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session within an associated transaction.
-
Method Details
-
createSession
Obtain a newreactive session, the main interaction point between the user's program and Hibernate Reactive.The underlying database connection is obtained lazily when the returned
Mutiny.Sessionneeds to access the database.The client must close the session using
Mutiny.Closeable.close(). -
createSession
Obtain a newreactive session.The underlying database connection is obtained lazily when the returned
Mutiny.Sessionneeds to access the database.The client must close the session using
Mutiny.Closeable.close().- Parameters:
tenantId- the id of the tenant
-
createStatelessSession
Obtain a newreactive stateless session.The underlying database connection is obtained lazily when the returned
Mutiny.StatelessSessionneeds to access the database.The client must close the session using
Mutiny.Closeable.close(). -
createStatelessSession
Obtain a newreactive stateless session.The underlying database connection is obtained lazily when the returned
Mutiny.StatelessSessionneeds to access the database.The client must close the session using
Mutiny.Closeable.close().- Parameters:
tenantId- the id of the tenant
-
openSession
io.smallrye.mutiny.Uni<Mutiny.Session> openSession()Obtain a newreactive sessionUni, the main interaction point between the user's program and Hibernate Reactive.When the
Unicompletes successfully it returns a newly created session.The client must explicitly close the session by calling
Mutiny.Closeable.close().- See Also:
-
openSession
Obtain a newreactive sessionUnifor a specified tenant.When the
Unicompletes successfully it returns a newly created session.The client must explicitly close the session by calling
Mutiny.Closeable.close().- Parameters:
tenantId- the id of the tenant- See Also:
-
openStatelessSession
io.smallrye.mutiny.Uni<Mutiny.StatelessSession> openStatelessSession()Obtain areactive stateless sessionUni.When the
Unicompletes successfully it returns a newly created session.The client must explicitly close the session by calling
Mutiny.StatelessSession.close().- See Also:
-
openStatelessSession
Obtain areactive stateless sessionUni.When the
Unicompletes successfully it returns a newly created session.The client must explicitly close the session by calling
Mutiny.StatelessSession.close().- Parameters:
tenantId- the id of the tenant- See Also:
-
withSession
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 aUni.
-
withSession
<T> io.smallrye.mutiny.Uni<T> withSession(String tenantId, Function<Mutiny.Session, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive 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 aUni.
-
withTransaction
<T> io.smallrye.mutiny.Uni<T> withTransaction(BiFunction<Mutiny.Session, Mutiny.Transaction, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session within an associatedtransaction.- 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
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 aUni.- See Also:
-
withTransaction
default <T> io.smallrye.mutiny.Uni<T> withTransaction(Function<Mutiny.Session, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive 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 session associated with the current stream, a new 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 aUni.- See Also:
-
withStatelessTransaction
default <T> io.smallrye.mutiny.Uni<T> withStatelessTransaction(Function<Mutiny.StatelessSession, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive 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 aUni.- See Also:
-
withStatelessTransaction
<T> io.smallrye.mutiny.Uni<T> withStatelessTransaction(BiFunction<Mutiny.StatelessSession, Mutiny.Transaction, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive 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 aUni.- See Also:
-
withStatelessSession
<T> io.smallrye.mutiny.Uni<T> withStatelessSession(Function<Mutiny.StatelessSession, io.smallrye.mutiny.Uni<T>> work) Perform work using a stateless 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 aUni.
-
withStatelessSession
<T> io.smallrye.mutiny.Uni<T> withStatelessSession(String tenantId, Function<Mutiny.StatelessSession, io.smallrye.mutiny.Uni<T>> work) Perform work using a stateless session.- If there is already a stateless session associated with the current reactive stream and given tenant id, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream and given tenant id, 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 aUni.
-
withTransaction
<T> io.smallrye.mutiny.Uni<T> withTransaction(String tenantId, BiFunction<Mutiny.Session, Mutiny.Transaction, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session for the tenant with the specified tenant id within an associatedtransaction.- If there is already a session associated with the current reactive stream and given tenant id, then the work will be executed using that session.
- Otherwise, if there is no session associated with the current stream and given tenant id, 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 aUni.- See Also:
-
withStatelessTransaction
<T> io.smallrye.mutiny.Uni<T> withStatelessTransaction(String tenantId, BiFunction<Mutiny.StatelessSession, Mutiny.Transaction, io.smallrye.mutiny.Uni<T>> work) Perform work using a reactive session for the tenant with the specified tenant id within an associatedtransaction.- If there is already a stateless session associated with the current reactive stream and given tenant id, then the work will be executed using that session.
- Otherwise, if there is no stateless session associated with the current stream and given tenant id, 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 aUni.- See Also:
-
getCriteriaBuilder
HibernateCriteriaBuilder getCriteriaBuilder()- Returns:
- an instance of
CriteriaBuilderfor creating criteria queries.
-
getMetamodel
Metamodel getMetamodel()Obtain the JPAMetamodelfor the persistence unit. -
getCache
Cache getCache()Obtain theCacheobject for managing the second-level cache. -
getStatistics
Statistics getStatistics()Obtain theStatisticsobject exposing factory-level metrics. -
getCurrentSession
Mutiny.Session getCurrentSession()Return the current instance ofMutiny.Session, if any. A current session exists only when this method is called from within an invocation ofwithSession(Function)orwithTransaction(Function).- Returns:
- the current instance, if any, or
null - Since:
- 3.0
-
getCurrentStatelessSession
Mutiny.StatelessSession getCurrentStatelessSession()Return the current instance ofMutiny.Session, if any. A current session exists only when this method is called from within an invocation ofwithStatelessSession(Function)orwithStatelessTransaction(Function).- Returns:
- the current instance, if any, or
null - Since:
- 3.0
-
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
-