public static interface Mutiny.SessionFactory extends AutoCloseable
reactive sessions
. A Mutiny.SessionFactory
may be obtained from an instance of javax.persistence.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);
Modifier and Type | Method and Description |
---|---|
void | close() Destroy the session factory and clean up its connection pool. |
Cache | getCache() Obtain the Cache object for managing the second-level cache. |
CriteriaBuilder | getCriteriaBuilder() |
Metamodel | getMetamodel() Obtain the JPA Metamodel for the persistence unit. |
boolean | isOpen() |
Mutiny.Session | openSession() Obtain a new reactive session , the main interaction point between the user's program and Hibernate Reactive. |
Mutiny.Session | openSession(String tenantId) Obtain a new reactive session for a specified tenant. |
Mutiny.StatelessSession | openStatelessSession() Obtain a reactive stateless session . |
<T> <any> | withSession(Function<Mutiny.Session,<any>> work) Perform work using a reactive session . |
<T> <any> | withSession(String tenantId, Function<Mutiny.Session,<any>> work) Perform work using a reactive session for a specified tenant. |
<T> <any> | withTransaction(BiFunction<Mutiny.Session,Mutiny.Transaction,<any>> work) Perform work using a reactive session within an associated transaction . |
<T> <any> | withTransaction(String tenantId, BiFunction<Mutiny.Session,Mutiny.Transaction,<any>> work) Perform work using a reactive session for a specified tenant within an associated transaction . |
Mutiny.Session openSession()
reactive session
, the main interaction point between the user's program and Hibernate Reactive. The underlying database connection is obtained lazily when the returned Mutiny.Session
needs to access the database.
The client must explicitly close the session by calling Mutiny.Session.close()
.
withSession(Function)
Mutiny.Session openSession(String tenantId)
reactive session
for a specified tenant. The underlying database connection is obtained lazily when the returned Mutiny.Session
needs to access the database.
The client must explicitly close the session by calling Mutiny.Session.close()
.
tenantId
- the id of the tenantwithSession(Function)
Mutiny.StatelessSession openStatelessSession()
reactive stateless session
. The underlying database connection is obtained lazily when the returned Mutiny.StatelessSession
needs to access the database.
The client must explicitly close the session by calling Mutiny.StatelessSession.close()
.
<T> <any> withSession(Function<Mutiny.Session,<any>> work)
reactive session
. The session will be closed automatically.
work
- a function which accepts the session and returns the result of the work as a Uni
.<T> <any> withSession(String tenantId, Function<Mutiny.Session,<any>> work)
reactive session
for a specified tenant. The session will be closed automatically.
tenantId
- the id of the tenantwork
- a function which accepts the session and returns the result of the work as a Uni
.<T> <any> withTransaction(BiFunction<Mutiny.Session,Mutiny.Transaction,<any>> work)
reactive session
within an associated transaction
. The session will be flushed
and closed automatically, and the transaction committed automatically.
work
- a function which accepts the session and returns the result of the work as a Uni
.withSession(Function)
, Mutiny.Session.withTransaction(Function)
<T> <any> withTransaction(String tenantId, BiFunction<Mutiny.Session,Mutiny.Transaction,<any>> work)
reactive session
for a specified tenant within an associated transaction
. The session will be flushed
and closed automatically, and the transaction committed automatically.
tenantId
- the id of the tenantwork
- a function which accepts the session and returns the result of the work as a Uni
.withSession(Function)
, Mutiny.Session.withTransaction(Function)
CriteriaBuilder getCriteriaBuilder()
CriteriaBuilder
for creating criteria queries.Metamodel getMetamodel()
Metamodel
for the persistence unit.Cache getCache()
Cache
object for managing the second-level cache.void close()
close
in interface AutoCloseable
boolean isOpen()
close()
has been called