public class MutinySessionImpl extends Object implements Mutiny.Session
Mutiny.Session
API. This delegating class is needed to avoid name clashes when implementing both Session
and org.hibernate.Session
.Constructor and Description |
---|
MutinySessionImpl(ReactiveSession session) |
Modifier and Type | Method and Description |
---|---|
Mutiny.Session | clear() Completely clear the session. |
void | close() Close the reactive session and release the underlying database connection. |
boolean | contains(Object entity) Determine if the given instance belongs to this persistence context. |
<T> <any> | createEntityGraph(Class<T> entity) Create a new mutable EntityGraph |
<T> <any> | createEntityGraph(Class<T> entity, String name) Create a new mutable copy of a named EntityGraph |
<R> Mutiny.Query<R> | createNamedQuery(String name) Create an instance of Mutiny.Query for the named query. |
<R> Mutiny.Query<R> | createNamedQuery(String name, Class<R> resultType) Create an instance of Mutiny.Query for the named query. |
<R> Mutiny.Query<R> | createNativeQuery(String sql) 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 sql, 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 sql, 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(<any> criteriaQuery) 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(<any> criteriaUpdate) 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(<any> criteriaDelete) 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 jpql) 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 jpql, Class<R> resultType) Create an instance of Mutiny.Query for the given HQL/JPQL query string. |
Mutiny.Session | detach(Object entity) Remove this instance from the session cache. |
Mutiny.Session | disableFetchProfile(String name) Disable a particular fetch profile on this session, or do nothing if the requested fetch profile is not enabled. |
void | disableFilter(String filterName) Disable the named filter for this session. |
Mutiny.Session | enableFetchProfile(String name) Enable a particular fetch profile on this session, or do nothing if requested fetch profile is already enabled. |
Filter | enableFilter(String filterName) Enable the named filter for this session. |
<E,T> <any> | fetch(E entity, <any> field) Fetch a lazy property of the given entity, identified by a JPA attribute metamodel . |
<T> <any> | fetch(T association) Asynchronously fetch an association that's configured for lazy loading. |
<T> <any> | find(<any> entityGraph, Object id) Asynchronously return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. |
<T> <any> | find(Class<T> entityClass, Object... ids) Asynchronously return the persistent instances of the given entity class with the given identifiers, or null if there is no such persistent instance. |
<T> <any> | find(Class<T> entityClass, Object primaryKey) Asynchronously return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. |
<T> <any> | find(Class<T> entityClass, Object primaryKey, LockMode lockMode) Asynchronously return the persistent instance of the given entity class with the given identifier, requesting the given LockMode . |
<T> <any> | find(Class<T> entityClass, Object primaryKey, LockOptions lockOptions) Asynchronously return the persistent instance of the given entity class with the given identifier, requesting the given LockMode . |
<any> | flush() Force this session to flush asynchronously. |
Integer | getBatchSize() The session-level JDBC batch size, or null if it has not been overridden. |
CacheMode | getCacheMode() Get the current cache mode. |
Filter | getEnabledFilter(String filterName) Retrieve a currently enabled filter by name. |
<T> <any> | getEntityGraph(Class<T> entity, String name) Obtain a named EntityGraph |
FlushMode | getFlushMode() Get the current flush mode for this session. |
LockMode | getLockMode(Object entity) Determine the current lock mode of the given entity. |
<T> T | getReference(Class<T> entityClass, Object id) Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. |
<T> T | getReference(T entity) Return the persistent instance of with the same identity as the given instance, which might be detached, assuming that the instance is still persistent in the database. |
<T> ResultSetMapping<T> | getResultSetMapping(Class<T> resultType, String mappingName) Obtain a native SQL result set mapping defined via the annotation javax.persistence.SqlResultSetMapping . |
boolean | isDefaultReadOnly() |
boolean | isFetchProfileEnabled(String name) Determine if the fetch profile with the given name is enabled for this session. |
boolean | isOpen() |
boolean | isReadOnly(Object entityOrProxy) Is the specified entity or proxy read-only? |
<any> | lock(Object entity, LockMode lockMode) Obtain the specified lock level upon the given object. |
<any> | lock(Object entity, LockOptions lockOptions) Obtain the specified lock level upon the given object. |
<T> <any> | merge(T entity) Copy the state of the given object onto the persistent instance with the same identifier. |
<T> <any> | mergeAll(T... entity) Merge multiple entity instances at once. |
<any> | persist(Object entity) Asynchronously persist the given transient instance, first assigning a generated identifier. |
<any> | persistAll(Object... entity) Persist multiple transient entity instances at once. |
<any> | refresh(Object entity) Re-read the state of the given instance from the underlying database. |
<any> | refresh(Object entity, LockMode lockMode) Re-read the state of the given instance from the underlying database, requesting the given LockMode . |
<any> | refresh(Object entity, LockOptions lockOptions) Re-read the state of the given instance from the underlying database, requesting the given LockMode . |
<any> | refreshAll(Object... entity) Refresh multiple entity instances at once. |
<any> | remove(Object entity) Asynchronously remove a persistent instance from the datastore. |
<any> | removeAll(Object... entity) Remove multiple entity instances at once. |
Mutiny.Session | setBatchSize(Integer batchSize) Set the session-level JDBC batch size, overriding the batch size set by the configuration property hibernate.jdbc.batch_size . |
Mutiny.Session | setCacheMode(CacheMode cacheMode) Set the cache mode for this session. |
Mutiny.Session | setDefaultReadOnly(boolean readOnly) Change the default for entities and proxies loaded into this session from modifiable to read-only mode, or from modifiable to read-only mode. |
Mutiny.Session | setFlushMode(FlushMode flushMode) Set the flush mode for this session. |
Mutiny.Session | setReadOnly(Object entityOrProxy, boolean readOnly) Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode. |
<T> <any> | unproxy(T association) Asynchronously fetch an association that's configured for lazy loading, and unwrap the underlying entity implementation from any proxy. |
<T> <any> | withTransaction(Function<Mutiny.Transaction,<any>> work) Performs the given work within the scope of a database transaction, automatically flushing the session. |
public MutinySessionImpl(ReactiveSession session)
public <any> flush()
Mutiny.Session
session.flush().thenAccept(v -> print("done saving changes"));
flush
in interface Mutiny.Session
javax.persistence.EntityManager#flush()
public <T> <any> fetch(T association)
Mutiny.Session
session.fetch(author.getBook()).thenAccept(book -> print(book.getTitle()));
fetch
in interface Mutiny.Session
association
- a lazy-loaded associationUni
Mutiny.fetch(Object)
, org.hibernate.Hibernate#initialize(Object)
public <E,T> <any> fetch(E entity, <any> field)
Mutiny.Session
attribute metamodel
. Note that this feature is only supported in conjunction with the Hibernate bytecode enhancer.
session.fetch(book, Book_.isbn).thenAccept(isbn -> print(isbn))
fetch
in interface Mutiny.Session
public <T> <any> unproxy(T association)
Mutiny.Session
session.unproxy(author.getBook()).thenAccept(book -> print(book.getTitle()));
unproxy
in interface Mutiny.Session
association
- a lazy-loaded associationUni
org.hibernate.Hibernate#unproxy(Object)
public <T> T getReference(Class<T> entityClass, Object id)
Mutiny.Session
Mutiny.Session.fetch(Object)
. You should not use this method to determine if an instance exists (use Mutiny.Session.find(java.lang.Class<T>, java.lang.Object)
instead). Use this only to retrieve an instance which you safely assume exists, where non-existence would be an actual error.
getReference
in interface Mutiny.Session
entityClass
- a persistent classid
- a valid identifier of an existing persistent instance of the classjavax.persistence.EntityManager#getReference(Class, Object)
public <T> T getReference(T entity)
Mutiny.Session
Mutiny.Session.fetch(Object)
.getReference
in interface Mutiny.Session
entity
- a detached persistent instancepublic LockMode getLockMode(Object entity)
Mutiny.Session
getLockMode
in interface Mutiny.Session
public boolean contains(Object entity)
Mutiny.Session
contains
in interface Mutiny.Session
public <T> <any> find(Class<T> entityClass, Object primaryKey)
Mutiny.Session
null
if there is no such persistent instance. If the instance is already associated with the session, return the associated instance. This method never returns an uninitialized instance.
session.find(Book.class, id).map(book -> print(book.getTitle()));
find
in interface Mutiny.Session
entityClass
- The entity typeprimaryKey
- an identifierUni
javax.persistence.EntityManager#find(Class, Object)
public <T> <any> find(Class<T> entityClass, Object... ids)
Mutiny.Session
find
in interface Mutiny.Session
entityClass
- The entity typeids
- the identifiersUni
public <T> <any> find(Class<T> entityClass, Object primaryKey, LockMode lockMode)
Mutiny.Session
LockMode
.find
in interface Mutiny.Session
entityClass
- The entity typeprimaryKey
- an identifierlockMode
- the requested LockMode
Uni
Mutiny.Session.find(Class,Object)
, this discussion of lock modes
public <T> <any> find(Class<T> entityClass, Object primaryKey, LockOptions lockOptions)
Mutiny.Session
LockMode
.find
in interface Mutiny.Session
entityClass
- The entity typeprimaryKey
- an identifierlockOptions
- the requested LockMode
Uni
Mutiny.Session.find(Class,Object)
, this discussion of lock modes
public <T> <any> find(<any> entityGraph, Object id)
Mutiny.Session
null
if there is no such persistent instance. If the instance is already associated with the session, return the associated instance. This method never returns an uninitialized instance.
session.find(Book.class, id).map(book -> print(book.getTitle()));
find
in interface Mutiny.Session
entityGraph
- The entity typeid
- an identifierUni
javax.persistence.EntityManager#find(Class, Object)
public <any> persist(Object entity)
Mutiny.Session
This operation cascades to associated instances if the association is mapped with javax.persistence.CascadeType#PERSIST
.
session.persist(newBook).map(v -> session.flush());
persist
in interface Mutiny.Session
entity
- a transient instance of a persistent classjavax.persistence.EntityManager#persist(Object)
public <any> persistAll(Object... entity)
Mutiny.Session
persistAll
in interface Mutiny.Session
Mutiny.Session.persist(Object)
public <any> remove(Object entity)
Mutiny.Session
This operation cascades to associated instances if the association is mapped with javax.persistence.CascadeType#REMOVE
.
session.delete(book).thenAccept(v -> session.flush());
remove
in interface Mutiny.Session
entity
- the managed persistent instance to be removedjavax.persistence.EntityManager#remove(Object)
public <any> removeAll(Object... entity)
Mutiny.Session
removeAll
in interface Mutiny.Session
Mutiny.Session.remove(Object)
public <T> <any> merge(T entity)
Mutiny.Session
This operation cascades to associated instances if the association is mapped with javax.persistence.CascadeType#MERGE
.
merge
in interface Mutiny.Session
entity
- a detached instance with state to be copiedjavax.persistence.EntityManager#merge(Object)
@SafeVarargs public final <T> <any> mergeAll(T... entity)
Mutiny.Session
mergeAll
in interface Mutiny.Session
Mutiny.Session.merge(Object)
public <any> refresh(Object entity)
Mutiny.Session
refresh
in interface Mutiny.Session
entity
- a managed persistent instancejavax.persistence.EntityManager#refresh(Object)
public <any> refresh(Object entity, LockMode lockMode)
Mutiny.Session
LockMode
.refresh
in interface Mutiny.Session
entity
- a managed persistent entity instancelockMode
- the requested lock modeMutiny.Session.refresh(Object)
public <any> refresh(Object entity, LockOptions lockOptions)
Mutiny.Session
LockMode
.refresh
in interface Mutiny.Session
entity
- a managed persistent entity instancelockOptions
- the requested lock modeMutiny.Session.refresh(Object)
public <any> refreshAll(Object... entity)
Mutiny.Session
refreshAll
in interface Mutiny.Session
Mutiny.Session.refresh(Object)
public <any> lock(Object entity, LockMode lockMode)
Mutiny.Session
LockMode#PESSIMISTIC_READ
, LockMode#PESSIMISTIC_WRITE
, LockMode#PESSIMISTIC_FORCE_INCREMENT
, LockMode#OPTIMISTIC
, or LockMode#OPTIMISTIC_FORCE_INCREMENT
. org.hibernate.annotations.CascadeType#LOCK
.lock
in interface Mutiny.Session
entity
- a managed persistent instancelockMode
- the lock levelpublic <any> lock(Object entity, LockOptions lockOptions)
Mutiny.Session
LockMode#PESSIMISTIC_READ
, LockMode#PESSIMISTIC_WRITE
, LockMode#PESSIMISTIC_FORCE_INCREMENT
, LockMode#OPTIMISTIC
, or LockMode#OPTIMISTIC_FORCE_INCREMENT
. org.hibernate.annotations.CascadeType#LOCK
.lock
in interface Mutiny.Session
entity
- a managed persistent instancelockOptions
- the lock levelpublic <R> Mutiny.Query<R> createQuery(String jpql, Class<R> resultType)
Mutiny.Session
Mutiny.Query
for the given HQL/JPQL query string.createQuery
in interface Mutiny.Session
jpql
- The HQL/JPQL queryresultType
- the Java type returned in each row of query resultsMutiny.Query
instance for manipulation and executionjavax.persistence.EntityManager#createQuery(String, Class)
public <R> Mutiny.Query<R> createQuery(String jpql)
Mutiny.Session
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.createQuery
in interface Mutiny.Session
jpql
- The HQL/JPQL query, update or delete statementMutiny.Query
instance for manipulation and executionjavax.persistence.EntityManager#createQuery(String)
public <R> Mutiny.Query<R> createNativeQuery(String sql, Class<R> resultType)
Mutiny.Session
Mutiny.Query
for the given SQL query string, using the given resultType
to interpret the results. Object
, or a built-in type such as String
or Integer
, the result set must have a single column, which will be returned as a scalar. Object[]
, then the result set must have multiple columns, which will be returned in arrays. createNativeQuery
in interface Mutiny.Session
sql
- The SQL queryresultType
- the Java type returned in each row of query resultsMutiny.Query
instance for manipulation and executionjavax.persistence.EntityManager#createNativeQuery(String, Class)
public <R> Mutiny.Query<R> createNativeQuery(String sql, ResultSetMapping<R> resultSetMapping)
Mutiny.Session
Mutiny.Query
for the given SQL query string, using the given ResultSetMapping
to interpret the result set.createNativeQuery
in interface Mutiny.Session
sql
- The SQL queryresultSetMapping
- the result set mappingMutiny.Query
instance for manipulation and executionMutiny.Session.getResultSetMapping(Class, String)
, javax.persistence.EntityManager#createNativeQuery(String, String)
public <R> Mutiny.Query<R> createNativeQuery(String sql)
Mutiny.Session
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. In the case of a query: Object[]
.createNativeQuery
in interface Mutiny.Session
sql
- The SQL select, update, insert, or delete statementpublic <R> Mutiny.Query<R> createNamedQuery(String name)
Mutiny.Session
Mutiny.Query
for the named query.createNamedQuery
in interface Mutiny.Session
name
- The name of the queryMutiny.Query
instance for manipulation and executionjavax.persistence.EntityManager#createQuery(String)
public <R> Mutiny.Query<R> createNamedQuery(String name, Class<R> resultType)
Mutiny.Session
Mutiny.Query
for the named query.createNamedQuery
in interface Mutiny.Session
name
- The name of the queryresultType
- the Java type returned in each row of query resultsMutiny.Query
instance for manipulation and executionjavax.persistence.EntityManager#createQuery(String, Class)
public <R> Mutiny.Query<R> createQuery(<any> criteriaQuery)
Mutiny.Session
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.createQuery
in interface Mutiny.Session
criteriaQuery
- The HQL/JPQL query, update or delete statementMutiny.Query
instance for manipulation and executionjavax.persistence.EntityManager#createQuery(String)
public <R> Mutiny.Query<R> createQuery(<any> criteriaUpdate)
Mutiny.Session
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.createQuery
in interface Mutiny.Session
criteriaUpdate
- The HQL/JPQL query, update or delete statementMutiny.Query
instance for manipulation and executionjavax.persistence.EntityManager#createQuery(String)
public <R> Mutiny.Query<R> createQuery(<any> criteriaDelete)
Mutiny.Session
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.createQuery
in interface Mutiny.Session
criteriaDelete
- The HQL/JPQL query, update or delete statementMutiny.Query
instance for manipulation and executionjavax.persistence.EntityManager#createQuery(String)
public FlushMode getFlushMode()
Mutiny.Session
getFlushMode
in interface Mutiny.Session
public Mutiny.Session setFlushMode(FlushMode flushMode)
Mutiny.Session
flush mode
for this session. The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
For a logically "read only" session, it is reasonable to set the session's flush mode to FlushMode#MANUAL
at the start of the session (in order to achieve some extra performance).
setFlushMode
in interface Mutiny.Session
flushMode
- the new flush modepublic Mutiny.Session setDefaultReadOnly(boolean readOnly)
Mutiny.Session
Read-only entities are not dirty-checked and snapshots of persistent state are not maintained. Read-only entities can be modified, but changes are not persisted.
setDefaultReadOnly
in interface Mutiny.Session
org.hibernate.Session#setDefaultReadOnly(boolean)
public boolean isDefaultReadOnly()
isDefaultReadOnly
in interface Mutiny.Session
public Mutiny.Session setReadOnly(Object entityOrProxy, boolean readOnly)
Mutiny.Session
setReadOnly
in interface Mutiny.Session
org.hibernate.Session#setReadOnly(Object, boolean)
public boolean isReadOnly(Object entityOrProxy)
Mutiny.Session
isReadOnly
in interface Mutiny.Session
org.hibernate.Session#isReadOnly(Object)
public CacheMode getCacheMode()
Mutiny.Session
getCacheMode
in interface Mutiny.Session
public Mutiny.Session setCacheMode(CacheMode cacheMode)
Mutiny.Session
cache mode
for this session. The cache mode determines the manner in which this session interacts with the second level cache.
setCacheMode
in interface Mutiny.Session
cacheMode
- The new cache mode.public Mutiny.Session setBatchSize(Integer batchSize)
Mutiny.Session
hibernate.jdbc.batch_size
.setBatchSize
in interface Mutiny.Session
public Integer getBatchSize()
Mutiny.Session
null
if it has not been overridden.getBatchSize
in interface Mutiny.Session
public Mutiny.Session detach(Object entity)
Mutiny.Session
This operation cascades to associated instances if the association is mapped with javax.persistence.CascadeType#DETACH
.
detach
in interface Mutiny.Session
entity
- The entity to evictjavax.persistence.EntityManager#detach(Object)
public Mutiny.Session clear()
Mutiny.Session
clear
in interface Mutiny.Session
javax.persistence.EntityManager#clear()
public Mutiny.Session enableFetchProfile(String name)
Mutiny.Session
enableFetchProfile
in interface Mutiny.Session
name
- The name of the fetch profile to be enabled.for discussion of this feature
public Mutiny.Session disableFetchProfile(String name)
Mutiny.Session
disableFetchProfile
in interface Mutiny.Session
name
- The name of the fetch profile to be disabled.for discussion of this feature
public boolean isFetchProfileEnabled(String name)
Mutiny.Session
isFetchProfileEnabled
in interface Mutiny.Session
name
- The name of the profile to be checked.for discussion of this feature
public <T> ResultSetMapping<T> getResultSetMapping(Class<T> resultType, String mappingName)
Mutiny.Session
javax.persistence.SqlResultSetMapping
.getResultSetMapping
in interface Mutiny.Session
public <T> <any> getEntityGraph(Class<T> entity, String name)
Mutiny.Session
EntityGraph
getEntityGraph
in interface Mutiny.Session
public <T> <any> createEntityGraph(Class<T> entity)
Mutiny.Session
EntityGraph
createEntityGraph
in interface Mutiny.Session
public <T> <any> createEntityGraph(Class<T> entity, String name)
Mutiny.Session
EntityGraph
createEntityGraph
in interface Mutiny.Session
public Filter enableFilter(String filterName)
Mutiny.Session
enableFilter
in interface Mutiny.Session
filterName
- The name of the filter to be enabled.public void disableFilter(String filterName)
Mutiny.Session
disableFilter
in interface Mutiny.Session
filterName
- The name of the filter to be disabled.public Filter getEnabledFilter(String filterName)
Mutiny.Session
getEnabledFilter
in interface Mutiny.Session
filterName
- The name of the filter to be retrieved.public <T> <any> withTransaction(Function<Mutiny.Transaction,<any>> work)
Mutiny.Session
Mutiny.Transaction.markForRollback()
is called.withTransaction
in interface Mutiny.Session
work
- a function which accepts Mutiny.Transaction
and returns the result of the work as a Uni
.public void close()
Mutiny.Session
close
in interface AutoCloseable
close
in interface Mutiny.Session
public boolean isOpen()
isOpen
in interface Mutiny.Session
Mutiny.Session.close()
has been called