Package org.hibernate.internal
Class StatelessSessionImpl
- java.lang.Object
-
- org.hibernate.internal.AbstractSharedSessionContract
-
- org.hibernate.internal.StatelessSessionImpl
-
- All Implemented Interfaces:
Closeable
,Serializable
,AutoCloseable
,LobCreationContext
,SharedSessionContractImplementor
,QueryProducer
,QueryProducerImplementor
,JdbcSessionOwner
,TransactionCoordinatorBuilder.Options
,SharedSessionContract
,StatelessSession
,JavaType.CoercionContext
,WrapperOptions
public class StatelessSessionImpl extends AbstractSharedSessionContract implements StatelessSession
Concrete implementation of theStatelessSession
API. Exposes two interfaces:StatelessSession
to the applicationSharedSessionContractImplementor
to other Hibernate components (SPI)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.hibernate.engine.jdbc.LobCreationContext
LobCreationContext.Callback<T>
-
-
Field Summary
-
Fields inherited from class org.hibernate.internal.AbstractSharedSessionContract
closed, fastSessionServices, waitingForAutoClose
-
-
Constructor Summary
Constructors Constructor Description StatelessSessionImpl(SessionFactoryImpl factory, SessionCreationOptions options)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterOperation(boolean success)
Check if there is a Hibernate or JTA transaction in progress and, if there is not, flush if necessary, make sure the connection has been committed (if it is not in autocommit mode) and run the after completion processingvoid
afterScrollOperation()
void
afterTransactionBegin()
A after-begin callback from the coordinator to its owner.void
afterTransactionCompletion(boolean successful, boolean delayed)
An after-completion callback to the owner.boolean
autoFlushIfRequired(Set<String> querySpaces)
detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flushvoid
beforeTransactionCompletion()
A before-completion callback to the owner.String
bestGuessEntityName(Object object)
The best guess entity name for an entity not in an associationvoid
delete(Object entity)
Delete a row.void
delete(String entityName, Object entity)
Delete a row.void
fetch(Object association)
Fetch an association that's configured for lazy loading.void
flush()
void
flushBeforeTransactionCompletion()
<T> T
get(Class<T> entityClass, Object id)
Retrieve a row.<T> T
get(Class<T> entityClass, Object id, LockMode lockMode)
Retrieve a row, obtaining the specified lock mode.Object
get(String entityName, Object id)
Retrieve a row.Object
get(String entityName, Object id, LockMode lockMode)
Retrieve a row, obtaining the specified lock mode.CacheMode
getCacheMode()
Object
getContextEntityIdentifier(Object object)
Return the identifier of the persistent object, or null if not associated with the sessionEntityPersister
getEntityPersister(String entityName, Object object)
Get theEntityPersister
for any instanceObject
getEntityUsingInterceptor(EntityKey key)
Get the entity instance associated with the givenKey
, calling the Interceptor if necessaryLoadQueryInfluencers
getLoadQueryInfluencers()
Get the load query influencers associated with this session.PersistenceContext
getPersistenceContext()
Get the persistence context for this session.PersistenceContext
getPersistenceContextInternal()
This is similar toSharedSessionContractImplementor.getPersistenceContext()
, with two main differences: a) this version performs better as it allows for inlining and probably better prediction b) see SessionImplSharedSessionContractImplementor.getPersistenceContext()
: it does some checks on the current state of the Session.String
guessEntityName(Object entity)
The guessed entity name for an entity not in an associationObject
immediateLoad(String entityName, Object id)
Load an instance immediately.void
initializeCollection(PersistentCollection<?> collection, boolean writing)
Initialize the collection (if not already initialized)Object
insert(Object entity)
Insert a row.Object
insert(String entityName, Object entity)
Insert a row.Object
instantiate(String entityName, Object id)
Instantiate the entity class, initializing with the given identifierObject
instantiate(EntityPersister persister, Object id)
Instantiate the entity class of an EntityPersister, initializing with the given identifier.Object
internalLoad(String entityName, Object id, boolean eager, boolean nullable)
Load an instance without checking if it was deleted.boolean
isAutoCloseSessionEnabled()
boolean
isDefaultReadOnly()
boolean
isEventSource()
boolean
isTransactionInProgress()
Does thisSession
have an active Hibernate transaction or is there a JTA transaction in progress?protected Object
load(String entityName, Object identifier)
void
refresh(Object entity)
Refresh the entity instance state from the database.void
refresh(Object entity, LockMode lockMode)
Refresh the entity instance state from the database.void
refresh(String entityName, Object entity)
Refresh the entity instance state from the database.void
refresh(String entityName, Object entity, LockMode lockMode)
Refresh the entity instance state from the database.void
setAutoClear(boolean enabled)
Enable/disable automatic cache clearing from after transaction completion (for EJB3)void
setCacheMode(CacheMode cm)
void
setDefaultReadOnly(boolean readOnly)
void
setHibernateFlushMode(FlushMode flushMode)
Set the flush mode for this session.boolean
shouldAutoClose()
boolean
shouldAutoJoinTransaction()
Indicates whether an active transaction should be automatically joined.void
update(Object entity)
Update a row.void
update(String entityName, Object entity)
Update a row.-
Methods inherited from class org.hibernate.internal.AbstractSharedSessionContract
accessTransaction, addSharedSessionTransactionObserver, applyQuerySettingsAndHints, applyQuerySettingsAndHints, beginTransaction, buildNamedQuery, buildNamedQuery, checkOpen, checkOpenOrWaitingForAutoClose, checkTransactionNeededForUpdateOperation, checkTransactionSynchStatus, cleanupOnClose, close, createMutationQuery, createMutationQuery, createMutationQuery, createMutationQuery, createNamedMutationQuery, createNamedQuery, createNamedQuery, createNamedSelectionQuery, createNamedSelectionQuery, createNamedStoredProcedureQuery, createNativeMutationQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createNativeQuery, createQuery, createQuery, createQuery, createQuery, createQuery, createSelectionQuery, createSelectionQuery, createSelectionQuery, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureQuery, createStoredProcedureQuery, createStoredProcedureQuery, delayedAfterCompletion, doReturningWork, doWork, execute, generateEntityKey, getCacheTransactionSynchronization, getConfiguredJdbcBatchSize, getCriteriaBuilder, getCurrentTransaction, getEntityNameResolver, getEventListenerManager, getExceptionConverter, getFactory, getFlushMode, getHibernateFlushMode, getInterceptor, getJdbcBatchSize, getJdbcConnectionAccess, getJdbcCoordinator, getJdbcServices, getJdbcSessionContext, getJdbcTimeZone, getLobCreator, getNamedNativeQuery, getNamedNativeQuery, getNamedProcedureCall, getNamedQuery, getPreferredSqlTypeCodeForBoolean, getSessionIdentifier, getSessionToken, getTenantIdentifier, getTransaction, getTransactionCoordinator, getTransactionStartTimestamp, isClosed, isConnected, isCriteriaCopyTreeEnabled, isOpen, isOpenOrWaitingForAutoClose, markForRollbackOnly, prepareForAutoClose, prepareForQueryExecution, pulseTransactionCoordinator, removeSharedSessionTransactionObserver, setClosed, setCriteriaCopyTreeEnabled, setJdbcBatchSize, shouldCloseJdbcCoordinatorOnClose, startTransactionBoundary, useStreamForLobBinding
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hibernate.query.QueryProducer
createMutationQuery, createNamedSelectionQuery, createNamedSelectionQuery, createSelectionQuery, createSelectionQuery, createSelectionQuery
-
Methods inherited from interface org.hibernate.SharedSessionContract
beginTransaction, createNamedStoredProcedureQuery, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureCall, createStoredProcedureQuery, createStoredProcedureQuery, createStoredProcedureQuery, doReturningWork, doWork, getCriteriaBuilder, getJdbcBatchSize, getNamedProcedureCall, getTransaction, isConnected, isOpen, setJdbcBatchSize
-
Methods inherited from interface org.hibernate.engine.spi.SharedSessionContractImplementor
checkOpen, getSession, getSessionFactory, getTypeConfiguration, isEnforcingFetchGraph, setEnforcingFetchGraph
-
Methods inherited from interface org.hibernate.StatelessSession
close
-
-
-
-
Constructor Detail
-
StatelessSessionImpl
public StatelessSessionImpl(SessionFactoryImpl factory, SessionCreationOptions options)
-
-
Method Detail
-
shouldAutoJoinTransaction
public boolean shouldAutoJoinTransaction()
Description copied from interface:TransactionCoordinatorBuilder.Options
Indicates whether an active transaction should be automatically joined. Only relevant for JTA-based TransactionCoordinator instances.- Specified by:
shouldAutoJoinTransaction
in interfaceTransactionCoordinatorBuilder.Options
- Overrides:
shouldAutoJoinTransaction
in classAbstractSharedSessionContract
- Returns:
true
indicates the active transaction should be auto joined;false
indicates it should not (untilTransactionCoordinator.explicitJoin()
is called).
-
insert
public Object insert(Object entity)
Description copied from interface:StatelessSession
Insert a row.- Specified by:
insert
in interfaceStatelessSession
- Parameters:
entity
- a new transient instance- Returns:
- The identifier of the inserted entity
-
insert
public Object insert(String entityName, Object entity)
Description copied from interface:StatelessSession
Insert a row.- Specified by:
insert
in interfaceStatelessSession
- Parameters:
entityName
- The entityName for the entity to be insertedentity
- a new transient instance- Returns:
- the identifier of the instance
-
delete
public void delete(Object entity)
Description copied from interface:StatelessSession
Delete a row.- Specified by:
delete
in interfaceStatelessSession
- Parameters:
entity
- a detached entity instance
-
delete
public void delete(String entityName, Object entity)
Description copied from interface:StatelessSession
Delete a row.- Specified by:
delete
in interfaceStatelessSession
- Parameters:
entityName
- The entityName for the entity to be deletedentity
- a detached entity instance
-
update
public void update(Object entity)
Description copied from interface:StatelessSession
Update a row.- Specified by:
update
in interfaceStatelessSession
- Parameters:
entity
- a detached entity instance
-
update
public void update(String entityName, Object entity)
Description copied from interface:StatelessSession
Update a row.- Specified by:
update
in interfaceStatelessSession
- Parameters:
entityName
- The entityName for the entity to be updatedentity
- a detached entity instance
-
get
public <T> T get(Class<T> entityClass, Object id)
Description copied from interface:StatelessSession
Retrieve a row.- Specified by:
get
in interfaceStatelessSession
- Parameters:
entityClass
- The class of the entity to retrieveid
- The id of the entity to retrieve- Returns:
- a detached entity instance
-
get
public <T> T get(Class<T> entityClass, Object id, LockMode lockMode)
Description copied from interface:StatelessSession
Retrieve a row, obtaining the specified lock mode.- Specified by:
get
in interfaceStatelessSession
- Parameters:
entityClass
- The class of the entity to retrieveid
- The id of the entity to retrievelockMode
- The lock mode to apply to the entity- Returns:
- a detached entity instance
-
get
public Object get(String entityName, Object id)
Description copied from interface:StatelessSession
Retrieve a row.- Specified by:
get
in interfaceStatelessSession
- Parameters:
entityName
- The name of the entity to retrieveid
- The id of the entity to retrieve- Returns:
- a detached entity instance
-
get
public Object get(String entityName, Object id, LockMode lockMode)
Description copied from interface:StatelessSession
Retrieve a row, obtaining the specified lock mode.- Specified by:
get
in interfaceStatelessSession
- Parameters:
entityName
- The name of the entity to retrieveid
- The id of the entity to retrievelockMode
- The lock mode to apply to the entity- Returns:
- a detached entity instance
-
refresh
public void refresh(Object entity)
Description copied from interface:StatelessSession
Refresh the entity instance state from the database.- Specified by:
refresh
in interfaceStatelessSession
- Parameters:
entity
- The entity to be refreshed.
-
refresh
public void refresh(String entityName, Object entity)
Description copied from interface:StatelessSession
Refresh the entity instance state from the database.- Specified by:
refresh
in interfaceStatelessSession
- Parameters:
entityName
- The entityName for the entity to be refreshed.entity
- The entity to be refreshed.
-
refresh
public void refresh(Object entity, LockMode lockMode)
Description copied from interface:StatelessSession
Refresh the entity instance state from the database.- Specified by:
refresh
in interfaceStatelessSession
- Parameters:
entity
- The entity to be refreshed.lockMode
- The LockMode to be applied.
-
refresh
public void refresh(String entityName, Object entity, LockMode lockMode)
Description copied from interface:StatelessSession
Refresh the entity instance state from the database.- Specified by:
refresh
in interfaceStatelessSession
- Parameters:
entityName
- The entityName for the entity to be refreshed.entity
- The entity to be refreshed.lockMode
- The LockMode to be applied.
-
immediateLoad
public Object immediateLoad(String entityName, Object id) throws HibernateException
Description copied from interface:SharedSessionContractImplementor
Load an instance immediately. This method is only called when lazily initializing a proxy. Do not return the proxy.- Specified by:
immediateLoad
in interfaceSharedSessionContractImplementor
- Throws:
HibernateException
-
initializeCollection
public void initializeCollection(PersistentCollection<?> collection, boolean writing) throws HibernateException
Description copied from interface:SharedSessionContractImplementor
Initialize the collection (if not already initialized)- Specified by:
initializeCollection
in interfaceSharedSessionContractImplementor
- Throws:
HibernateException
-
instantiate
public Object instantiate(String entityName, Object id) throws HibernateException
Description copied from interface:SharedSessionContractImplementor
Instantiate the entity class, initializing with the given identifier- Specified by:
instantiate
in interfaceSharedSessionContractImplementor
- Throws:
HibernateException
-
instantiate
public Object instantiate(EntityPersister persister, Object id) throws HibernateException
Description copied from interface:SharedSessionContractImplementor
Instantiate the entity class of an EntityPersister, initializing with the given identifier. This is more efficient thanSharedSessionContractImplementor.instantiate(String, Object)
but not always interchangeable: a single persister might be responsible for multiple types.- Specified by:
instantiate
in interfaceSharedSessionContractImplementor
- Throws:
HibernateException
-
internalLoad
public Object internalLoad(String entityName, Object id, boolean eager, boolean nullable) throws HibernateException
Description copied from interface:SharedSessionContractImplementor
Load an instance without checking if it was deleted. Whennullable
is disabled this method may create a new proxy or return an existing proxy; if it does not exist, throw an exception. Whennullable
is enabled, the method does not create new proxies (but might return an existing proxy); if it does not exist, returnnull
. Wheneager
is enabled, the object is eagerly fetched- Specified by:
internalLoad
in interfaceSharedSessionContractImplementor
- Throws:
HibernateException
-
fetch
public void fetch(Object association)
Description copied from interface:StatelessSession
Fetch an association that's configured for lazy loading.Warning: this operation in a stateless session is quite sensitive to data aliasing effects and should be used with great care.
- Specified by:
fetch
in interfaceStatelessSession
- Parameters:
association
- a lazy-loaded association- See Also:
Hibernate.initialize(Object)
-
isAutoCloseSessionEnabled
public boolean isAutoCloseSessionEnabled()
- Specified by:
isAutoCloseSessionEnabled
in interfaceSharedSessionContractImplementor
-
shouldAutoClose
public boolean shouldAutoClose()
- Specified by:
shouldAutoClose
in interfaceSharedSessionContractImplementor
-
bestGuessEntityName
public String bestGuessEntityName(Object object)
Description copied from interface:SharedSessionContractImplementor
The best guess entity name for an entity not in an association- Specified by:
bestGuessEntityName
in interfaceSharedSessionContractImplementor
-
getCacheMode
public CacheMode getCacheMode()
- Specified by:
getCacheMode
in interfaceQueryProducerImplementor
- Specified by:
getCacheMode
in interfaceSharedSessionContractImplementor
- Overrides:
getCacheMode
in classAbstractSharedSessionContract
-
setCacheMode
public void setCacheMode(CacheMode cm)
- Specified by:
setCacheMode
in interfaceSharedSessionContractImplementor
- Overrides:
setCacheMode
in classAbstractSharedSessionContract
-
setHibernateFlushMode
public void setHibernateFlushMode(FlushMode flushMode)
Description copied from interface:SharedSessionContractImplementor
Set the 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 toFlushMode.MANUAL
at the start of the session (in order to achieve some extra performance).- Specified by:
setHibernateFlushMode
in interfaceSharedSessionContractImplementor
- Overrides:
setHibernateFlushMode
in classAbstractSharedSessionContract
- Parameters:
flushMode
- the new flush mode
-
getContextEntityIdentifier
public Object getContextEntityIdentifier(Object object)
Description copied from interface:SharedSessionContractImplementor
Return the identifier of the persistent object, or null if not associated with the session- Specified by:
getContextEntityIdentifier
in interfaceSharedSessionContractImplementor
-
guessEntityName
public String guessEntityName(Object entity) throws HibernateException
Description copied from interface:SharedSessionContractImplementor
The guessed entity name for an entity not in an association- Specified by:
guessEntityName
in interfaceSharedSessionContractImplementor
- Throws:
HibernateException
-
getEntityPersister
public EntityPersister getEntityPersister(String entityName, Object object) throws HibernateException
Description copied from interface:SharedSessionContractImplementor
Get theEntityPersister
for any instance- Specified by:
getEntityPersister
in interfaceSharedSessionContractImplementor
- Parameters:
entityName
- optional entity nameobject
- the entity instance- Throws:
HibernateException
-
getEntityUsingInterceptor
public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException
Description copied from interface:SharedSessionContractImplementor
Get the entity instance associated with the givenKey
, calling the Interceptor if necessary- Specified by:
getEntityUsingInterceptor
in interfaceSharedSessionContractImplementor
- Throws:
HibernateException
-
getPersistenceContext
public PersistenceContext getPersistenceContext()
Description copied from interface:SharedSessionContractImplementor
Get the persistence context for this session. See alsoSharedSessionContractImplementor.getPersistenceContextInternal()
for an alternative. This method is not extremely fast: if you need to access the PersistenceContext multiple times, prefer keeping a reference to it over invoking this method multiple times.- Specified by:
getPersistenceContext
in interfaceSharedSessionContractImplementor
-
setAutoClear
public void setAutoClear(boolean enabled)
Description copied from interface:SharedSessionContractImplementor
Enable/disable automatic cache clearing from after transaction completion (for EJB3)- Specified by:
setAutoClear
in interfaceSharedSessionContractImplementor
-
load
protected Object load(String entityName, Object identifier)
- Specified by:
load
in classAbstractSharedSessionContract
-
isEventSource
public boolean isEventSource()
- Specified by:
isEventSource
in interfaceSharedSessionContractImplementor
-
isDefaultReadOnly
public boolean isDefaultReadOnly()
- Specified by:
isDefaultReadOnly
in interfaceSharedSessionContractImplementor
-
setDefaultReadOnly
public void setDefaultReadOnly(boolean readOnly) throws HibernateException
- Throws:
HibernateException
-
afterOperation
public void afterOperation(boolean success)
Description copied from interface:SharedSessionContractImplementor
Check if there is a Hibernate or JTA transaction in progress and, if there is not, flush if necessary, make sure the connection has been committed (if it is not in autocommit mode) and run the after completion processing- Specified by:
afterOperation
in interfaceSharedSessionContractImplementor
- Parameters:
success
- Was the operation a success
-
afterScrollOperation
public void afterScrollOperation()
- Specified by:
afterScrollOperation
in interfaceSharedSessionContractImplementor
-
flush
public void flush()
- Specified by:
flush
in interfaceSharedSessionContractImplementor
-
getLoadQueryInfluencers
public LoadQueryInfluencers getLoadQueryInfluencers()
Description copied from interface:SharedSessionContractImplementor
Get the load query influencers associated with this session.- Specified by:
getLoadQueryInfluencers
in interfaceSharedSessionContractImplementor
- Returns:
- the load query influencers associated with this session; should never be null.
-
getPersistenceContextInternal
public PersistenceContext getPersistenceContextInternal()
Description copied from interface:SharedSessionContractImplementor
This is similar toSharedSessionContractImplementor.getPersistenceContext()
, with two main differences: a) this version performs better as it allows for inlining and probably better prediction b) see SessionImplSharedSessionContractImplementor.getPersistenceContext()
: it does some checks on the current state of the Session. Choose wisely: performance is important, correctness comes first.- Specified by:
getPersistenceContextInternal
in interfaceSharedSessionContractImplementor
- Returns:
- the PersistenceContext associated to this session.
-
autoFlushIfRequired
public boolean autoFlushIfRequired(Set<String> querySpaces) throws HibernateException
Description copied from interface:SharedSessionContractImplementor
detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush- Specified by:
autoFlushIfRequired
in interfaceSharedSessionContractImplementor
- Parameters:
querySpaces
- the tables named in the query.- Returns:
- true if flush is required, false otherwise.
- Throws:
HibernateException
-
afterTransactionBegin
public void afterTransactionBegin()
Description copied from interface:JdbcSessionOwner
A after-begin callback from the coordinator to its owner.- Specified by:
afterTransactionBegin
in interfaceJdbcSessionOwner
-
beforeTransactionCompletion
public void beforeTransactionCompletion()
Description copied from interface:JdbcSessionOwner
A before-completion callback to the owner.- Specified by:
beforeTransactionCompletion
in interfaceJdbcSessionOwner
- Overrides:
beforeTransactionCompletion
in classAbstractSharedSessionContract
-
afterTransactionCompletion
public void afterTransactionCompletion(boolean successful, boolean delayed)
Description copied from interface:JdbcSessionOwner
An after-completion callback to the owner.- Specified by:
afterTransactionCompletion
in interfaceJdbcSessionOwner
- Overrides:
afterTransactionCompletion
in classAbstractSharedSessionContract
- Parameters:
successful
- Was the transaction successful?delayed
- Is this a delayed after transaction completion call (aka after a timeout)?
-
isTransactionInProgress
public boolean isTransactionInProgress()
Description copied from interface:SharedSessionContractImplementor
Does thisSession
have an active Hibernate transaction or is there a JTA transaction in progress?- Specified by:
isTransactionInProgress
in interfaceSharedSessionContractImplementor
- Overrides:
isTransactionInProgress
in classAbstractSharedSessionContract
-
flushBeforeTransactionCompletion
public void flushBeforeTransactionCompletion()
- Specified by:
flushBeforeTransactionCompletion
in interfaceJdbcSessionOwner
-
-