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 theStatelessSessionAPI. Exposes two interfaces:StatelessSessionto the applicationSharedSessionContractImplementorto 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 voidafterOperation(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 processingvoidafterScrollOperation()voidafterTransactionBegin()A after-begin callback from the coordinator to its owner.voidafterTransactionCompletion(boolean successful, boolean delayed)An after-completion callback to the owner.booleanautoFlushIfRequired(Set<String> querySpaces)detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flushvoidbeforeTransactionCompletion()A before-completion callback to the owner.StringbestGuessEntityName(Object object)The best guess entity name for an entity not in an associationvoiddelete(Object entity)Delete a row.voiddelete(String entityName, Object entity)Delete a row.voidfetch(Object association)Fetch an association that's configured for lazy loading.voidflush()voidflushBeforeTransactionCompletion()<T> Tget(Class<T> entityClass, Object id)Retrieve a row.<T> Tget(Class<T> entityClass, Object id, LockMode lockMode)Retrieve a row, obtaining the specified lock mode.Objectget(String entityName, Object id)Retrieve a row.Objectget(String entityName, Object id, LockMode lockMode)Retrieve a row, obtaining the specified lock mode.CacheModegetCacheMode()ObjectgetContextEntityIdentifier(Object object)Return the identifier of the persistent object, or null if not associated with the sessionEntityPersistergetEntityPersister(String entityName, Object object)Get theEntityPersisterfor any instanceObjectgetEntityUsingInterceptor(EntityKey key)Get the entity instance associated with the givenKey, calling the Interceptor if necessaryLoadQueryInfluencersgetLoadQueryInfluencers()Get the load query influencers associated with this session.PersistenceContextgetPersistenceContext()Get the persistence context for this session.PersistenceContextgetPersistenceContextInternal()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.StringguessEntityName(Object entity)The guessed entity name for an entity not in an associationObjectimmediateLoad(String entityName, Object id)Load an instance immediately.voidinitializeCollection(PersistentCollection<?> collection, boolean writing)Initialize the collection (if not already initialized)Objectinsert(Object entity)Insert a row.Objectinsert(String entityName, Object entity)Insert a row.Objectinstantiate(String entityName, Object id)Instantiate the entity class, initializing with the given identifierObjectinstantiate(EntityPersister persister, Object id)Instantiate the entity class of an EntityPersister, initializing with the given identifier.ObjectinternalLoad(String entityName, Object id, boolean eager, boolean nullable)Load an instance without checking if it was deleted.booleanisAutoCloseSessionEnabled()booleanisDefaultReadOnly()booleanisEventSource()booleanisTransactionInProgress()Does thisSessionhave an active Hibernate transaction or is there a JTA transaction in progress?protected Objectload(String entityName, Object identifier)voidrefresh(Object entity)Refresh the entity instance state from the database.voidrefresh(Object entity, LockMode lockMode)Refresh the entity instance state from the database.voidrefresh(String entityName, Object entity)Refresh the entity instance state from the database.voidrefresh(String entityName, Object entity, LockMode lockMode)Refresh the entity instance state from the database.voidsetAutoClear(boolean enabled)Enable/disable automatic cache clearing from after transaction completion (for EJB3)voidsetCacheMode(CacheMode cm)voidsetDefaultReadOnly(boolean readOnly)voidsetHibernateFlushMode(FlushMode flushMode)Set the flush mode for this session.booleanshouldAutoClose()booleanshouldAutoJoinTransaction()Indicates whether an active transaction should be automatically joined.voidupdate(Object entity)Update a row.voidupdate(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.OptionsIndicates whether an active transaction should be automatically joined. Only relevant for JTA-based TransactionCoordinator instances.- Specified by:
shouldAutoJoinTransactionin interfaceTransactionCoordinatorBuilder.Options- Overrides:
shouldAutoJoinTransactionin classAbstractSharedSessionContract- Returns:
trueindicates the active transaction should be auto joined;falseindicates it should not (untilTransactionCoordinator.explicitJoin()is called).
-
insert
public Object insert(Object entity)
Description copied from interface:StatelessSessionInsert a row.- Specified by:
insertin 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:StatelessSessionInsert a row.- Specified by:
insertin 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:StatelessSessionDelete a row.- Specified by:
deletein interfaceStatelessSession- Parameters:
entity- a detached entity instance
-
delete
public void delete(String entityName, Object entity)
Description copied from interface:StatelessSessionDelete a row.- Specified by:
deletein 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:StatelessSessionUpdate a row.- Specified by:
updatein interfaceStatelessSession- Parameters:
entity- a detached entity instance
-
update
public void update(String entityName, Object entity)
Description copied from interface:StatelessSessionUpdate a row.- Specified by:
updatein 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:StatelessSessionRetrieve a row.- Specified by:
getin 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:StatelessSessionRetrieve a row, obtaining the specified lock mode.- Specified by:
getin 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:StatelessSessionRetrieve a row.- Specified by:
getin 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:StatelessSessionRetrieve a row, obtaining the specified lock mode.- Specified by:
getin 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:StatelessSessionRefresh the entity instance state from the database.- Specified by:
refreshin interfaceStatelessSession- Parameters:
entity- The entity to be refreshed.
-
refresh
public void refresh(String entityName, Object entity)
Description copied from interface:StatelessSessionRefresh the entity instance state from the database.- Specified by:
refreshin 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:StatelessSessionRefresh the entity instance state from the database.- Specified by:
refreshin 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:StatelessSessionRefresh the entity instance state from the database.- Specified by:
refreshin 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:SharedSessionContractImplementorLoad an instance immediately. This method is only called when lazily initializing a proxy. Do not return the proxy.- Specified by:
immediateLoadin interfaceSharedSessionContractImplementor- Throws:
HibernateException
-
initializeCollection
public void initializeCollection(PersistentCollection<?> collection, boolean writing) throws HibernateException
Description copied from interface:SharedSessionContractImplementorInitialize the collection (if not already initialized)- Specified by:
initializeCollectionin interfaceSharedSessionContractImplementor- Throws:
HibernateException
-
instantiate
public Object instantiate(String entityName, Object id) throws HibernateException
Description copied from interface:SharedSessionContractImplementorInstantiate the entity class, initializing with the given identifier- Specified by:
instantiatein interfaceSharedSessionContractImplementor- Throws:
HibernateException
-
instantiate
public Object instantiate(EntityPersister persister, Object id) throws HibernateException
Description copied from interface:SharedSessionContractImplementorInstantiate 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:
instantiatein interfaceSharedSessionContractImplementor- Throws:
HibernateException
-
internalLoad
public Object internalLoad(String entityName, Object id, boolean eager, boolean nullable) throws HibernateException
Description copied from interface:SharedSessionContractImplementorLoad an instance without checking if it was deleted. Whennullableis disabled this method may create a new proxy or return an existing proxy; if it does not exist, throw an exception. Whennullableis enabled, the method does not create new proxies (but might return an existing proxy); if it does not exist, returnnull. Wheneageris enabled, the object is eagerly fetched- Specified by:
internalLoadin interfaceSharedSessionContractImplementor- Throws:
HibernateException
-
fetch
public void fetch(Object association)
Description copied from interface:StatelessSessionFetch 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:
fetchin interfaceStatelessSession- Parameters:
association- a lazy-loaded association- See Also:
Hibernate.initialize(Object)
-
isAutoCloseSessionEnabled
public boolean isAutoCloseSessionEnabled()
- Specified by:
isAutoCloseSessionEnabledin interfaceSharedSessionContractImplementor
-
shouldAutoClose
public boolean shouldAutoClose()
- Specified by:
shouldAutoClosein interfaceSharedSessionContractImplementor
-
bestGuessEntityName
public String bestGuessEntityName(Object object)
Description copied from interface:SharedSessionContractImplementorThe best guess entity name for an entity not in an association- Specified by:
bestGuessEntityNamein interfaceSharedSessionContractImplementor
-
getCacheMode
public CacheMode getCacheMode()
- Specified by:
getCacheModein interfaceQueryProducerImplementor- Specified by:
getCacheModein interfaceSharedSessionContractImplementor- Overrides:
getCacheModein classAbstractSharedSessionContract
-
setCacheMode
public void setCacheMode(CacheMode cm)
- Specified by:
setCacheModein interfaceSharedSessionContractImplementor- Overrides:
setCacheModein classAbstractSharedSessionContract
-
setHibernateFlushMode
public void setHibernateFlushMode(FlushMode flushMode)
Description copied from interface:SharedSessionContractImplementorSet 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.MANUALat the start of the session (in order to achieve some extra performance).- Specified by:
setHibernateFlushModein interfaceSharedSessionContractImplementor- Overrides:
setHibernateFlushModein classAbstractSharedSessionContract- Parameters:
flushMode- the new flush mode
-
getContextEntityIdentifier
public Object getContextEntityIdentifier(Object object)
Description copied from interface:SharedSessionContractImplementorReturn the identifier of the persistent object, or null if not associated with the session- Specified by:
getContextEntityIdentifierin interfaceSharedSessionContractImplementor
-
guessEntityName
public String guessEntityName(Object entity) throws HibernateException
Description copied from interface:SharedSessionContractImplementorThe guessed entity name for an entity not in an association- Specified by:
guessEntityNamein interfaceSharedSessionContractImplementor- Throws:
HibernateException
-
getEntityPersister
public EntityPersister getEntityPersister(String entityName, Object object) throws HibernateException
Description copied from interface:SharedSessionContractImplementorGet theEntityPersisterfor any instance- Specified by:
getEntityPersisterin interfaceSharedSessionContractImplementor- Parameters:
entityName- optional entity nameobject- the entity instance- Throws:
HibernateException
-
getEntityUsingInterceptor
public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException
Description copied from interface:SharedSessionContractImplementorGet the entity instance associated with the givenKey, calling the Interceptor if necessary- Specified by:
getEntityUsingInterceptorin interfaceSharedSessionContractImplementor- Throws:
HibernateException
-
getPersistenceContext
public PersistenceContext getPersistenceContext()
Description copied from interface:SharedSessionContractImplementorGet 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:
getPersistenceContextin interfaceSharedSessionContractImplementor
-
setAutoClear
public void setAutoClear(boolean enabled)
Description copied from interface:SharedSessionContractImplementorEnable/disable automatic cache clearing from after transaction completion (for EJB3)- Specified by:
setAutoClearin interfaceSharedSessionContractImplementor
-
load
protected Object load(String entityName, Object identifier)
- Specified by:
loadin classAbstractSharedSessionContract
-
isEventSource
public boolean isEventSource()
- Specified by:
isEventSourcein interfaceSharedSessionContractImplementor
-
isDefaultReadOnly
public boolean isDefaultReadOnly()
- Specified by:
isDefaultReadOnlyin interfaceSharedSessionContractImplementor
-
setDefaultReadOnly
public void setDefaultReadOnly(boolean readOnly) throws HibernateException- Throws:
HibernateException
-
afterOperation
public void afterOperation(boolean success)
Description copied from interface:SharedSessionContractImplementorCheck 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:
afterOperationin interfaceSharedSessionContractImplementor- Parameters:
success- Was the operation a success
-
afterScrollOperation
public void afterScrollOperation()
- Specified by:
afterScrollOperationin interfaceSharedSessionContractImplementor
-
flush
public void flush()
- Specified by:
flushin interfaceSharedSessionContractImplementor
-
getLoadQueryInfluencers
public LoadQueryInfluencers getLoadQueryInfluencers()
Description copied from interface:SharedSessionContractImplementorGet the load query influencers associated with this session.- Specified by:
getLoadQueryInfluencersin interfaceSharedSessionContractImplementor- Returns:
- the load query influencers associated with this session; should never be null.
-
getPersistenceContextInternal
public PersistenceContext getPersistenceContextInternal()
Description copied from interface:SharedSessionContractImplementorThis 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:
getPersistenceContextInternalin interfaceSharedSessionContractImplementor- Returns:
- the PersistenceContext associated to this session.
-
autoFlushIfRequired
public boolean autoFlushIfRequired(Set<String> querySpaces) throws HibernateException
Description copied from interface:SharedSessionContractImplementordetect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush- Specified by:
autoFlushIfRequiredin 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:JdbcSessionOwnerA after-begin callback from the coordinator to its owner.- Specified by:
afterTransactionBeginin interfaceJdbcSessionOwner
-
beforeTransactionCompletion
public void beforeTransactionCompletion()
Description copied from interface:JdbcSessionOwnerA before-completion callback to the owner.- Specified by:
beforeTransactionCompletionin interfaceJdbcSessionOwner- Overrides:
beforeTransactionCompletionin classAbstractSharedSessionContract
-
afterTransactionCompletion
public void afterTransactionCompletion(boolean successful, boolean delayed)Description copied from interface:JdbcSessionOwnerAn after-completion callback to the owner.- Specified by:
afterTransactionCompletionin interfaceJdbcSessionOwner- Overrides:
afterTransactionCompletionin 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:SharedSessionContractImplementorDoes thisSessionhave an active Hibernate transaction or is there a JTA transaction in progress?- Specified by:
isTransactionInProgressin interfaceSharedSessionContractImplementor- Overrides:
isTransactionInProgressin classAbstractSharedSessionContract
-
flushBeforeTransactionCompletion
public void flushBeforeTransactionCompletion()
- Specified by:
flushBeforeTransactionCompletionin interfaceJdbcSessionOwner
-
-