public static interface Mutiny.StatelessSession extends Mutiny.Closeable
StatelessSession
interface, which provides a
command-oriented API for performing bulk operations against a database.
A stateless session does not implement a first-level cache nor interact with any second-level cache, nor does it implement transactional write-behind or automatic dirty checking, nor do operations cascade to associated instances. Changes to many to many associations and element collections may not be made persistent in a stateless session. Operations performed via a stateless session bypass Hibernate's event model and interceptors.
For certain kinds of work, a stateless session may perform slightly better than a stateful session.
In particular, for a session which loads many entities, use of a
StatelessSession
alleviates the need to call:
Mutiny.Session.clear()
or Mutiny.Session.detach(Object)
to perform
first-level cache management, and
Mutiny.Session.setCacheMode(CacheMode)
to bypass interaction with
the second-level cache.
Stateless sessions are vulnerable to data aliasing effects, due to the lack of a first-level cache.
StatelessSession
Modifier and Type | Method and Description |
---|---|
io.smallrye.mutiny.Uni<Void> |
close()
Close the reactive session and release the underlying database
connection.
|
<T> EntityGraph<T> |
createEntityGraph(Class<T> rootType)
Create a new mutable
EntityGraph |
<T> EntityGraph<T> |
createEntityGraph(Class<T> rootType,
String graphName)
Create a new mutable copy of a named
EntityGraph |
<R> Mutiny.Query<R> |
createNamedQuery(String queryName)
Create an instance of
Mutiny.Query for the named query. |
<R> Mutiny.Query<R> |
createNamedQuery(String queryName,
Class<R> resultType)
Create an instance of
Mutiny.Query for the named query. |
<R> Mutiny.Query<R> |
createNativeQuery(String queryString)
Create an instance of
Mutiny.Query for the given SQL query string,
or SQL update, insert, or delete statement. |
<R> Mutiny.Query<R> |
createNativeQuery(String queryString,
Class<R> resultType)
Create an instance of
Mutiny.Query for the given SQL query string,
using the given resultType to interpret the results. |
<R> Mutiny.Query<R> |
createNativeQuery(String queryString,
ResultSetMapping<R> resultSetMapping)
Create an instance of
Mutiny.Query for the given SQL query string,
using the given ResultSetMapping to interpret the result set. |
<R> Mutiny.Query<R> |
createQuery(CriteriaDelete<R> criteriaDelete)
Create an instance of
Mutiny.Query for the given criteria delete. |
<R> Mutiny.Query<R> |
createQuery(CriteriaQuery<R> criteriaQuery)
Create an instance of
Mutiny.Query for the given criteria query. |
<R> Mutiny.Query<R> |
createQuery(CriteriaUpdate<R> criteriaUpdate)
Create an instance of
Mutiny.Query for the given criteria update. |
<R> Mutiny.Query<R> |
createQuery(String queryString)
Create an instance of
Mutiny.Query for the given HQL/JPQL query
string or HQL/JPQL update or delete statement. |
<R> Mutiny.Query<R> |
createQuery(String queryString,
Class<R> resultType)
Create an instance of
Mutiny.Query for the given HQL/JPQL query
string. |
Mutiny.Transaction |
currentTransaction()
Obtain the transaction currently associated with this session,
if any.
|
io.smallrye.mutiny.Uni<Void> |
delete(Object entity)
Delete a row.
|
io.smallrye.mutiny.Uni<Void> |
deleteAll(int batchSize,
Object... entities)
Delete multiple rows.
|
io.smallrye.mutiny.Uni<Void> |
deleteAll(Object... entities)
Delete multiple rows.
|
<T> io.smallrye.mutiny.Uni<T> |
fetch(T association)
Asynchronously fetch an association that's configured for lazy loading.
|
<T> io.smallrye.mutiny.Uni<T> |
get(Class<T> entityClass,
Object id)
Retrieve a row.
|
<T> io.smallrye.mutiny.Uni<T> |
get(Class<T> entityClass,
Object id,
org.hibernate.LockMode lockMode)
Retrieve a row, obtaining the specified lock mode.
|
<T> io.smallrye.mutiny.Uni<T> |
get(EntityGraph<T> entityGraph,
Object id)
Retrieve a row, using the given
EntityGraph as a fetch plan. |
<T> EntityGraph<T> |
getEntityGraph(Class<T> rootType,
String graphName)
Obtain a named
EntityGraph |
<T> ResultSetMapping<T> |
getResultSetMapping(Class<T> resultType,
String mappingName)
Obtain a native SQL result set mapping defined via the annotation
SqlResultSetMapping . |
io.smallrye.mutiny.Uni<Void> |
insert(Object entity)
Insert a row.
|
io.smallrye.mutiny.Uni<Void> |
insertAll(int batchSize,
Object... entities)
Insert multiple rows using the specified batch size.
|
io.smallrye.mutiny.Uni<Void> |
insertAll(Object... entities)
Insert multiple rows.
|
boolean |
isOpen() |
io.smallrye.mutiny.Uni<Void> |
refresh(Object entity)
Refresh the entity instance state from the database.
|
io.smallrye.mutiny.Uni<Void> |
refresh(Object entity,
org.hibernate.LockMode lockMode)
Refresh the entity instance state from the database.
|
io.smallrye.mutiny.Uni<Void> |
refreshAll(int batchSize,
Object... entities)
Refresh the entity instance state from the database
using the selected batch size.
|
io.smallrye.mutiny.Uni<Void> |
refreshAll(Object... entities)
Refresh the entity instance state from the database.
|
io.smallrye.mutiny.Uni<Void> |
update(Object entity)
Update a row.
|
io.smallrye.mutiny.Uni<Void> |
updateAll(int batchSize,
Object... entities)
Update multiple rows.
|
io.smallrye.mutiny.Uni<Void> |
updateAll(Object... entities)
Update multiple rows.
|
<T> io.smallrye.mutiny.Uni<T> |
withTransaction(Function<Mutiny.Transaction,io.smallrye.mutiny.Uni<T>> work)
Performs the given work within the scope of a database transaction,
automatically flushing the session.
|
<T> io.smallrye.mutiny.Uni<T> get(Class<T> entityClass, Object id)
entityClass
- The class of the entity to retrieveid
- The id of the entity to retrieveUni
StatelessSession.get(Class, Serializable)
<T> io.smallrye.mutiny.Uni<T> get(Class<T> entityClass, Object id, org.hibernate.LockMode lockMode)
entityClass
- The class of the entity to retrieveid
- The id of the entity to retrievelockMode
- The lock mode to apply to the entityUni
StatelessSession.get(Class, Serializable, LockMode)
<T> io.smallrye.mutiny.Uni<T> get(EntityGraph<T> entityGraph, Object id)
EntityGraph
as a fetch plan.entityGraph
- an EntityGraph
specifying the entity
and associations to be fetchedid
- The id of the entity to retrieveUni
<R> Mutiny.Query<R> createQuery(String queryString)
Mutiny.Query
for the given HQL/JPQL query
string or HQL/JPQL update or delete statement. In the case of an
update or delete, the returned Mutiny.Query
must be executed using
Mutiny.Query.executeUpdate()
which returns an affected row count.queryString
- The HQL/JPQL query, update or delete statementMutiny.Query
instance for manipulation and executionMutiny.Session.createQuery(String)
<R> Mutiny.Query<R> createQuery(String queryString, Class<R> resultType)
Mutiny.Query
for the given HQL/JPQL query
string.queryString
- The HQL/JPQL queryresultType
- the Java type returned in each row of query resultsMutiny.Query
instance for manipulation and executionMutiny.Session.createQuery(String, Class)
<R> Mutiny.Query<R> createNamedQuery(String queryName)
Mutiny.Query
for the named query.queryName
- The name of the queryMutiny.Query
instance for manipulation and executionEntityManager.createQuery(String)
<R> Mutiny.Query<R> createNamedQuery(String queryName, Class<R> resultType)
Mutiny.Query
for the named query.queryName
- The name of the queryresultType
- the Java type returned in each row of query resultsMutiny.Query
instance for manipulation and executionEntityManager.createQuery(String, Class)
<R> Mutiny.Query<R> createNativeQuery(String queryString)
Mutiny.Query
for the given SQL query string,
or SQL update, insert, or delete statement. In the case of an update,
insert, or delete, the returned Mutiny.Query
must be executed using
Mutiny.Query.executeUpdate()
which returns an affected row count.queryString
- The SQL select, update, insert, or delete statementMutiny.Session.createNativeQuery(String)
<R> Mutiny.Query<R> createNativeQuery(String queryString, Class<R> resultType)
Mutiny.Query
for the given SQL query string,
using the given resultType
to interpret the results.queryString
- The SQL queryresultType
- the Java type returned in each row of query resultsMutiny.Query
instance for manipulation and executionMutiny.Session.createNativeQuery(String, Class)
<R> Mutiny.Query<R> createNativeQuery(String queryString, ResultSetMapping<R> resultSetMapping)
Mutiny.Query
for the given SQL query string,
using the given ResultSetMapping
to interpret the result set.queryString
- The SQL queryresultSetMapping
- the result set mappingMutiny.Query
instance for manipulation and executionMutiny.Session.createNativeQuery(String, ResultSetMapping)
<R> Mutiny.Query<R> createQuery(CriteriaQuery<R> criteriaQuery)
Mutiny.Query
for the given criteria query.criteriaQuery
- The CriteriaQuery
Mutiny.Query
instance for manipulation and executionEntityManager.createQuery(String)
<R> Mutiny.Query<R> createQuery(CriteriaUpdate<R> criteriaUpdate)
Mutiny.Query
for the given criteria update.criteriaUpdate
- The CriteriaUpdate
Mutiny.Query
instance for manipulation and executionEntityManager.createQuery(String)
<R> Mutiny.Query<R> createQuery(CriteriaDelete<R> criteriaDelete)
Mutiny.Query
for the given criteria delete.criteriaDelete
- The CriteriaDelete
Mutiny.Query
instance for manipulation and executionEntityManager.createQuery(String)
io.smallrye.mutiny.Uni<Void> insert(Object entity)
entity
- a new transient instanceStatelessSession.insert(Object)
io.smallrye.mutiny.Uni<Void> insertAll(Object... entities)
entities
- new transient instancesStatelessSession.insert(Object)
io.smallrye.mutiny.Uni<Void> insertAll(int batchSize, Object... entities)
batchSize
- the batch sizeentities
- new transient instancesStatelessSession.insert(Object)
io.smallrye.mutiny.Uni<Void> delete(Object entity)
entity
- a detached entity instanceStatelessSession.delete(Object)
io.smallrye.mutiny.Uni<Void> deleteAll(Object... entities)
entities
- detached entity instancesStatelessSession.delete(Object)
io.smallrye.mutiny.Uni<Void> deleteAll(int batchSize, Object... entities)
batchSize
- the batch sizeentities
- detached entity instancesStatelessSession.delete(Object)
io.smallrye.mutiny.Uni<Void> update(Object entity)
entity
- a detached entity instanceStatelessSession.update(Object)
io.smallrye.mutiny.Uni<Void> updateAll(Object... entities)
entities
- detached entity instancesStatelessSession.update(Object)
io.smallrye.mutiny.Uni<Void> updateAll(int batchSize, Object... entities)
batchSize
- the batch sizeentities
- detached entity instancesStatelessSession.update(Object)
io.smallrye.mutiny.Uni<Void> refresh(Object entity)
entity
- The entity to be refreshed.StatelessSession.refresh(Object)
io.smallrye.mutiny.Uni<Void> refreshAll(Object... entities)
entities
- The entities to be refreshed.StatelessSession.refresh(Object)
io.smallrye.mutiny.Uni<Void> refreshAll(int batchSize, Object... entities)
batchSize
- the batch sizeentities
- The entities to be refreshed.StatelessSession.refresh(Object)
io.smallrye.mutiny.Uni<Void> refresh(Object entity, org.hibernate.LockMode lockMode)
entity
- The entity to be refreshed.lockMode
- The LockMode to be applied.StatelessSession.refresh(Object, LockMode)
<T> io.smallrye.mutiny.Uni<T> fetch(T association)
session.fetch(author.getBook()).thenAccept(book -> print(book.getTitle()))
Warning: this operation in a stateless session is quite sensitive to
data aliasing effects and should be used with great care.association
- a lazy-loaded associationUni
Hibernate.initialize(Object)
<T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String mappingName)
SqlResultSetMapping
.<T> EntityGraph<T> getEntityGraph(Class<T> rootType, String graphName)
EntityGraph
<T> EntityGraph<T> createEntityGraph(Class<T> rootType)
EntityGraph
<T> EntityGraph<T> createEntityGraph(Class<T> rootType, String graphName)
EntityGraph
<T> io.smallrye.mutiny.Uni<T> withTransaction(Function<Mutiny.Transaction,io.smallrye.mutiny.Uni<T>> work)
Mutiny.Transaction.markForRollback()
is called.
work
- a function which accepts Mutiny.Transaction
and returns
the result of the work as a Uni
.Mutiny.SessionFactory.withTransaction(BiFunction)
Mutiny.Transaction currentTransaction()
Mutiny.Transaction
, or null if no transaction
was started using withTransaction(Function)
.withTransaction(Function)
,
Mutiny.SessionFactory.withTransaction(BiFunction)
boolean isOpen()
close()
has been calledio.smallrye.mutiny.Uni<Void> close()
close
in interface Mutiny.Closeable
Copyright © 2020-2022 Red Hat, Inc. All Rights Reserved.