public abstract class AbstractSharedSessionContract extends Object implements SharedSessionContractImplementor
getEventListenerManager()
getJdbcConnectionAccess()
getJdbcServices()
getTransaction()
(and therefore related methods such as beginTransaction()
, etc)LobCreationContext.Callback<T>
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed |
protected ExceptionConverter |
exceptionConverter |
protected boolean |
waitingForAutoClose |
Constructor and Description |
---|
AbstractSharedSessionContract(SessionFactoryImpl factory,
SessionCreationOptions options) |
Modifier and Type | Method and Description |
---|---|
Transaction |
accessTransaction()
Provides access to the underlying transaction or creates a new transaction if
one does not already exist or is active.
|
protected void |
addSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) |
void |
afterTransactionCompletion(boolean successful,
boolean delayed)
An after-completion callback to the owner.
|
protected void |
applyQuerySettingsAndHints(Query query) |
void |
beforeTransactionCompletion()
A before-completion callback to the owner.
|
Transaction |
beginTransaction()
Begin a unit of work and return the associated
Transaction object. |
protected <T> QueryImplementor<T> |
buildQueryFromName(String name,
Class<T> resultType) |
void |
checkOpen(boolean markForRollbackIfClosed)
Performs a check whether the Session is open, and if not:
if
markForRollbackIfClosed is true, marks current transaction (if one) for rollback only
throws an IllegalStateException (JPA defines the exception type)
|
protected void |
checkOpenOrWaitingForAutoClose() |
void |
checkTransactionNeededForUpdateOperation(String exceptionMessage)
Check if an active Transaction is necessary for the update operation to be executed.
|
protected void |
checkTransactionSynchStatus() |
protected void |
cleanupOnClose() |
void |
close()
End the session by releasing the JDBC connection and cleaning up.
|
QueryImplementor |
createNamedQuery(String name)
The JPA-defined named query creation method.
|
<R> QueryImplementor<R> |
createNamedQuery(String name,
Class<R> resultClass)
The JPA-defined named, typed query creation method.
|
protected <T> NativeQueryImplementor |
createNativeQuery(NamedSQLQueryDefinition queryDefinition,
Class<T> resultType) |
NativeQueryImplementor |
createNativeQuery(String sqlString)
Create a NativeQuery instance for the given native (SQL) query
|
NativeQueryImplementor |
createNativeQuery(String sqlString,
Class resultClass)
Create a NativeQuery instance for the given native (SQL) query using
implicit mapping to the specified Java type.
|
NativeQueryImplementor |
createNativeQuery(String sqlString,
String resultSetMapping)
Create a NativeQuery instance for the given native (SQL) query using
implicit mapping to the specified Java type.
|
protected QueryImplementor |
createQuery(NamedQueryDefinition queryDefinition) |
protected <T> QueryImplementor<T> |
createQuery(NamedQueryDefinition namedQueryDefinition,
Class<T> resultType) |
QueryImplementor |
createQuery(String queryString)
Create a
Query instance for the given HQL/JPQL query string. |
<T> QueryImplementor<T> |
createQuery(String queryString,
Class<T> resultClass)
Create a typed
Query instance for the given HQL/JPQL query string. |
NativeQueryImplementor |
createSQLQuery(String queryString)
Create a
NativeQuery instance for the given SQL query string. |
ProcedureCall |
createStoredProcedureCall(String procedureName)
Creates a call to a stored procedure.
|
ProcedureCall |
createStoredProcedureCall(String procedureName,
Class... resultClasses)
Creates a call to a stored procedure with specific result set entity mappings.
|
ProcedureCall |
createStoredProcedureCall(String procedureName,
String... resultSetMappings)
Creates a call to a stored procedure with specific result set entity mappings.
|
protected void |
delayedAfterCompletion() |
protected void |
errorIfClosed()
Deprecated.
(since 5.2) use
SharedSessionContractImplementor.checkOpen() instead |
<T> T |
execute(LobCreationContext.Callback<T> callback)
Execute the given callback, making sure it has access to a viable JDBC
Connection . |
EntityKey |
generateEntityKey(Serializable id,
EntityPersister persister)
Hide the changing requirements of entity key creation
|
CacheMode |
getCacheMode() |
CacheTransactionSynchronization |
getCacheTransactionSynchronization()
The current CacheTransactionContext associated with the Session.
|
protected TransactionImplementor |
getCurrentTransaction() |
EntityNameResolver |
getEntityNameResolver() |
SessionEventListenerManager |
getEventListenerManager() |
ExceptionConverter |
getExceptionConverter() |
SessionFactoryImplementor |
getFactory()
Get the creating SessionFactoryImplementor
|
FlushModeType |
getFlushMode()
Get the flush mode for this session.
|
FlushMode |
getHibernateFlushMode()
Get the current flush mode for this session.
|
Interceptor |
getInterceptor()
Retrieves the interceptor currently in use by this event source.
|
Integer |
getJdbcBatchSize()
Get the Session-level JDBC batch size for the current Session.
|
JdbcConnectionAccess |
getJdbcConnectionAccess() |
JdbcCoordinator |
getJdbcCoordinator() |
JdbcServices |
getJdbcServices() |
JdbcSessionContext |
getJdbcSessionContext() |
TimeZone |
getJdbcTimeZone()
The JDBC
TimeZone used when persisting Timestamp and DateTime properties into the database. |
LobCreator |
getLobCreator()
Obtain access to the
LobCreator |
NativeQueryImplementor |
getNamedNativeQuery(String name)
Get a NativeQuery instance for a named native SQL query
|
ProcedureCall |
getNamedProcedureCall(String name)
Gets a ProcedureCall based on a named template
|
QueryImplementor |
getNamedQuery(String name)
Create a
Query instance for the named query. |
NativeQueryImplementor |
getNamedSQLQuery(String name)
Get a NativeQuery instance for a named native SQL query
|
protected NativeQueryImplementor |
getNativeQueryImplementor(String queryString,
boolean isOrdinalParameterZeroBased) |
protected NativeSQLQueryPlan |
getNativeQueryPlan(NativeSQLQuerySpecification spec) |
protected HQLQueryPlan |
getQueryPlan(String query,
boolean shallow) |
UUID |
getSessionIdentifier()
A UUID associated with each Session.
|
String |
getTenantIdentifier()
The multi-tenancy tenant identifier, if one.
|
Transaction |
getTransaction()
Get the
Transaction instance associated with this session. |
TransactionCoordinator |
getTransactionCoordinator()
Obtain the builder for TransactionCoordinator instances
|
long |
getTransactionStartTimestamp()
A "timestamp" at or before the start of the current transaction.
|
protected void |
initQueryFromNamedDefinition(Query query,
NamedQueryDefinition nqd) |
boolean |
isClosed()
Checks whether the session is closed.
|
boolean |
isConnected()
Check if the session is currently connected.
|
boolean |
isOpen()
Check if the session is still open.
|
boolean |
isOpenOrWaitingForAutoClose()
Checks whether the session is open or is waiting for auto-close
|
protected boolean |
isTransactionAccessible() |
boolean |
isTransactionInProgress()
Does this Session have an active Hibernate transaction
or is there a JTA transaction in progress?
|
List |
list(NativeSQLQuerySpecification spec,
QueryParameters queryParameters)
Execute a native SQL query, and return the results as a fully built list.
|
protected abstract Object |
load(String entityName,
Serializable identifier) |
void |
markForRollbackOnly()
Marks current transaction (if one) for rollback only
|
protected void |
pulseTransactionCoordinator() |
SqlTypeDescriptor |
remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor)
Allow remapping of descriptors for dealing with sql type.
|
protected void |
removeSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) |
protected void |
resultClassChecking(Class resultType,
NamedSQLQueryDefinition namedQueryDefinition) |
protected void |
resultClassChecking(Class resultClass,
Query hqlQuery) |
ScrollableResultsImplementor |
scroll(NativeSQLQuerySpecification spec,
QueryParameters queryParameters)
Execute a native SQL query, and return the results as a scrollable result.
|
void |
setCacheMode(CacheMode cacheMode) |
protected void |
setClosed() |
void |
setFlushMode(FlushMode flushMode)
Set the flush mode for this session.
|
void |
setHibernateFlushMode(FlushMode flushMode)
Set the flush mode for this session.
|
void |
setJdbcBatchSize(Integer jdbcBatchSize)
Set the Session-level JDBC batch size.
|
boolean |
shouldAutoJoinTransaction()
Indicates whether an active transaction should be automatically joined.
|
protected boolean |
shouldCloseJdbcCoordinatorOnClose(boolean isTransactionCoordinatorShared) |
void |
startTransactionBoundary()
Callback indicating recognition of entering into a transactional
context whether that is explicitly via the Hibernate
Transaction API or via registration
of Hibernate's JTA Synchronization impl with a JTA Transaction |
boolean |
useStreamForLobBinding()
Should streams be used for binding LOB values.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
afterScrollOperation, bestGuessEntityName, checkOpen, connection, executeNativeUpdate, executeUpdate, flush, getConfiguredJdbcBatchSize, getContextEntityIdentifier, getDontFlushFromFind, getEntityPersister, getEntityUsingInterceptor, getLoadQueryInfluencers, getPersistenceContext, getTimestamp, guessEntityName, immediateLoad, initializeCollection, instantiate, internalLoad, isAutoCloseSessionEnabled, isEventSource, isQueryParametersValidationEnabled, iterate, iterateFilter, list, list, listCustomQuery, listFilter, scroll, scroll, scrollCustomQuery, setAutoClear, shouldAutoClose
createCriteria, createCriteria, createCriteria, createCriteria
afterTransactionBegin, flushBeforeTransactionCompletion
protected boolean closed
protected boolean waitingForAutoClose
protected transient ExceptionConverter exceptionConverter
public AbstractSharedSessionContract(SessionFactoryImpl factory, SessionCreationOptions options)
protected void addSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator)
protected void removeSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator)
public boolean shouldAutoJoinTransaction()
TransactionCoordinatorBuilder.Options
shouldAutoJoinTransaction
in interface TransactionCoordinatorBuilder.Options
true
indicates the active transaction should be auto joined; false
indicates it should not (until TransactionCoordinator.explicitJoin()
is called).public SessionFactoryImplementor getFactory()
SharedSessionContractImplementor
getFactory
in interface SharedSessionContractImplementor
getFactory
in interface QueryProducerImplementor
public Interceptor getInterceptor()
SharedSessionContractImplementor
getInterceptor
in interface SharedSessionContractImplementor
public JdbcCoordinator getJdbcCoordinator()
getJdbcCoordinator
in interface SharedSessionContractImplementor
public TransactionCoordinator getTransactionCoordinator()
JdbcSessionOwner
getTransactionCoordinator
in interface JdbcSessionOwner
public JdbcSessionContext getJdbcSessionContext()
getJdbcSessionContext
in interface JdbcSessionOwner
public EntityNameResolver getEntityNameResolver()
public SessionEventListenerManager getEventListenerManager()
getEventListenerManager
in interface SharedSessionContractImplementor
public UUID getSessionIdentifier()
SharedSessionContractImplementor
getSessionIdentifier
in interface SharedSessionContractImplementor
public String getTenantIdentifier()
SharedSessionContractImplementor
getTenantIdentifier
in interface SharedSessionContractImplementor
getTenantIdentifier
in interface SharedSessionContract
null
public boolean isOpen()
SharedSessionContract
isOpen
in interface SharedSessionContract
public boolean isClosed()
SharedSessionContractImplementor
SharedSessionContract.isOpen()
as this method does not attempt any JTA synchronization
registration, where as SharedSessionContract.isOpen()
does; which makes this one
nicer to use for most internal purposes.isClosed
in interface SharedSessionContractImplementor
true
if the session is closed; false
otherwise.public void close()
SharedSessionContract
close
in interface SharedSessionContract
protected void setClosed()
protected boolean shouldCloseJdbcCoordinatorOnClose(boolean isTransactionCoordinatorShared)
protected void cleanupOnClose()
public boolean isOpenOrWaitingForAutoClose()
SharedSessionContractImplementor
isOpenOrWaitingForAutoClose
in interface SharedSessionContractImplementor
true
if the session is closed or if it's waiting for auto-close; false
otherwise.public void checkOpen(boolean markForRollbackIfClosed)
SharedSessionContractImplementor
markForRollbackIfClosed
is true, marks current transaction (if one) for rollback onlycheckOpen
in interface SharedSessionContractImplementor
protected void checkOpenOrWaitingForAutoClose()
@Deprecated protected void errorIfClosed()
SharedSessionContractImplementor.checkOpen()
insteadpublic void markForRollbackOnly()
SharedSessionContractImplementor
markForRollbackOnly
in interface SharedSessionContractImplementor
public boolean isTransactionInProgress()
SharedSessionContractImplementor
isTransactionInProgress
in interface SharedSessionContractImplementor
public void checkTransactionNeededForUpdateOperation(String exceptionMessage)
SharedSessionContractImplementor
checkTransactionNeededForUpdateOperation
in interface SharedSessionContractImplementor
public Transaction getTransaction() throws HibernateException
SharedSessionContract
Transaction
instance associated with this session. The concrete type of the returned
Transaction
object is determined by the hibernate.transaction_factory
property.getTransaction
in interface SharedSessionContract
HibernateException
protected boolean isTransactionAccessible()
public Transaction accessTransaction()
SharedSessionContractImplementor
accessTransaction
in interface SharedSessionContractImplementor
public void startTransactionBoundary()
JdbcSessionOwner
Transaction
API or via registration
of Hibernate's JTA Synchronization impl with a JTA TransactionstartTransactionBoundary
in interface JdbcSessionOwner
public void beforeTransactionCompletion()
JdbcSessionOwner
beforeTransactionCompletion
in interface JdbcSessionOwner
public void afterTransactionCompletion(boolean successful, boolean delayed)
JdbcSessionOwner
afterTransactionCompletion
in interface JdbcSessionOwner
successful
- Was the transaction successful?delayed
- Is this a delayed after transaction completion call (aka after a timeout)?public CacheTransactionSynchronization getCacheTransactionSynchronization()
SharedSessionContractImplementor
null
when the Session is not currently part of a transaction.getCacheTransactionSynchronization
in interface SharedSessionContractImplementor
public long getTransactionStartTimestamp()
SharedSessionContractImplementor
getTransactionStartTimestamp
in interface SharedSessionContractImplementor
public Transaction beginTransaction()
SharedSessionContract
Transaction
object. If a new underlying transaction is
required, begin the transaction. Otherwise continue the new work in the context of the existing underlying
transaction.beginTransaction
in interface SharedSessionContract
SharedSessionContract.getTransaction()
protected void checkTransactionSynchStatus()
protected void pulseTransactionCoordinator()
protected void delayedAfterCompletion()
protected TransactionImplementor getCurrentTransaction()
public boolean isConnected()
SharedSessionContract
isConnected
in interface SharedSessionContract
public JdbcConnectionAccess getJdbcConnectionAccess()
getJdbcConnectionAccess
in interface JdbcSessionOwner
public EntityKey generateEntityKey(Serializable id, EntityPersister persister)
SharedSessionContractImplementor
generateEntityKey
in interface SharedSessionContractImplementor
id
- The entity idpersister
- The entity persisterpublic boolean useStreamForLobBinding()
WrapperOptions
useStreamForLobBinding
in interface WrapperOptions
true
/false
public LobCreator getLobCreator()
WrapperOptions
LobCreator
getLobCreator
in interface WrapperOptions
public <T> T execute(LobCreationContext.Callback<T> callback)
LobCreationContext
Connection
.execute
in interface LobCreationContext
T
- The Java type of the type of LOB being created. One of Blob
,
Clob
, NClob
callback
- The callback to execute .public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor)
WrapperOptions
remapSqlTypeDescriptor
in interface WrapperOptions
sqlTypeDescriptor
- The known descriptorpublic TimeZone getJdbcTimeZone()
WrapperOptions
TimeZone
used when persisting Timestamp and DateTime properties into the database.
This setting is used when storing timestamps using the PreparedStatement.setTimestamp(int, Timestamp, Calendar)
method.
This way, the storage TimeZone
can differ from the default JVM TimeZone given by TimeZone.getDefault()
.getJdbcTimeZone
in interface WrapperOptions
TimeZone
public JdbcServices getJdbcServices()
getJdbcServices
in interface SharedSessionContractImplementor
public void setFlushMode(FlushMode flushMode)
SharedSessionContractImplementor
FlushMode.MANUAL
at the start of the session (in
order to achieve some extra performance).setFlushMode
in interface SharedSessionContractImplementor
flushMode
- the new flush modepublic FlushModeType getFlushMode()
SharedSessionContractImplementor
FlushModeType
rather than Hibernate's FlushMode
. For
the former behavior, use SharedSessionContractImplementor.getHibernateFlushMode()
instead.getFlushMode
in interface SharedSessionContractImplementor
public void setHibernateFlushMode(FlushMode flushMode)
SharedSessionContractImplementor
FlushMode.MANUAL
at the start of the session (in
order to achieve some extra performance).setHibernateFlushMode
in interface SharedSessionContractImplementor
flushMode
- the new flush modepublic FlushMode getHibernateFlushMode()
SharedSessionContractImplementor
getHibernateFlushMode
in interface SharedSessionContractImplementor
getHibernateFlushMode
in interface QueryProducerImplementor
public CacheMode getCacheMode()
getCacheMode
in interface SharedSessionContractImplementor
getCacheMode
in interface QueryProducerImplementor
public void setCacheMode(CacheMode cacheMode)
setCacheMode
in interface SharedSessionContractImplementor
protected HQLQueryPlan getQueryPlan(String query, boolean shallow) throws HibernateException
HibernateException
protected NativeSQLQueryPlan getNativeQueryPlan(NativeSQLQuerySpecification spec) throws HibernateException
HibernateException
public QueryImplementor getNamedQuery(String name)
QueryProducer
Query
instance for the named query.getNamedQuery
in interface QueryProducer
getNamedQuery
in interface QueryProducerImplementor
getNamedQuery
in interface SharedSessionContract
name
- the name of a pre-defined, named queryprotected QueryImplementor createQuery(NamedQueryDefinition queryDefinition)
protected void initQueryFromNamedDefinition(Query query, NamedQueryDefinition nqd)
public QueryImplementor createQuery(String queryString)
QueryProducer
Query
instance for the given HQL/JPQL query string.createQuery
in interface QueryProducer
createQuery
in interface QueryProducerImplementor
createQuery
in interface SharedSessionContract
queryString
- The HQL/JPQL queryEntityManager.createQuery(String)
protected void applyQuerySettingsAndHints(Query query)
public <T> QueryImplementor<T> createQuery(String queryString, Class<T> resultClass)
QueryProducer
Query
instance for the given HQL/JPQL query string.createQuery
in interface QueryProducer
createQuery
in interface QueryProducerImplementor
queryString
- The HQL/JPQL queryEntityManager.createQuery(String,Class)
public QueryImplementor createNamedQuery(String name)
QueryProducer
createNamedQuery
in interface QueryProducer
createNamedQuery
in interface QueryProducerImplementor
name
- the name of a pre-defined, named queryEntityManager.createNamedQuery(String)
protected <T> QueryImplementor<T> buildQueryFromName(String name, Class<T> resultType)
protected <T> QueryImplementor<T> createQuery(NamedQueryDefinition namedQueryDefinition, Class<T> resultType)
protected <T> NativeQueryImplementor createNativeQuery(NamedSQLQueryDefinition queryDefinition, Class<T> resultType)
protected void resultClassChecking(Class resultType, NamedSQLQueryDefinition namedQueryDefinition)
public <R> QueryImplementor<R> createNamedQuery(String name, Class<R> resultClass)
QueryProducer
createNamedQuery
in interface QueryProducer
createNamedQuery
in interface QueryProducerImplementor
name
- the name of a query defined in metadataresultClass
- the type of the query resultEntityManager.createNamedQuery(String,Class)
public NativeQueryImplementor createNativeQuery(String sqlString)
QueryProducer
createNativeQuery
in interface QueryProducer
createNativeQuery
in interface QueryProducerImplementor
sqlString
- a native SQL query stringEntityManager.createNativeQuery(String)
public NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass)
QueryProducer
createNativeQuery
in interface QueryProducer
createNativeQuery
in interface QueryProducerImplementor
sqlString
- Native (SQL) query stringresultClass
- The Java type to map results toEntityManager.createNativeQuery(String,Class)
public NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMapping)
QueryProducer
createNativeQuery
in interface QueryProducer
createNativeQuery
in interface QueryProducerImplementor
sqlString
- Native (SQL) query stringresultSetMapping
- The explicit (named) result mappingEntityManager.createNativeQuery(String,Class)
,
SqlResultSetMapping
public NativeQueryImplementor getNamedNativeQuery(String name)
QueryProducer
getNamedNativeQuery
in interface QueryProducer
getNamedNativeQuery
in interface QueryProducerImplementor
name
- The name of the pre-defined querypublic NativeQueryImplementor createSQLQuery(String queryString)
QueryProducer
NativeQuery
instance for the given SQL query string.createSQLQuery
in interface QueryProducer
createSQLQuery
in interface QueryProducerImplementor
queryString
- The SQL queryprotected NativeQueryImplementor getNativeQueryImplementor(String queryString, boolean isOrdinalParameterZeroBased)
public NativeQueryImplementor getNamedSQLQuery(String name)
QueryProducer
getNamedSQLQuery
in interface QueryProducer
getNamedSQLQuery
in interface QueryProducerImplementor
name
- The name of the pre-defined querypublic ProcedureCall getNamedProcedureCall(String name)
SharedSessionContract
getNamedProcedureCall
in interface SharedSessionContract
name
- The name given to the templateNamedStoredProcedureQuery
public ProcedureCall createStoredProcedureCall(String procedureName)
SharedSessionContract
createStoredProcedureCall
in interface SharedSessionContract
procedureName
- The name of the procedure.public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses)
SharedSessionContract
createStoredProcedureCall
in interface SharedSessionContract
procedureName
- The name of the procedure.resultClasses
- The entity(s) to map the result on to.public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings)
SharedSessionContract
createStoredProcedureCall
in interface SharedSessionContract
procedureName
- The name of the procedure.resultSetMappings
- The explicit result set mapping(s) to use for mapping the resultsprotected abstract Object load(String entityName, Serializable identifier)
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
SharedSessionContractImplementor
list
in interface SharedSessionContractImplementor
spec
- The specification of the native SQL query to execute.queryParameters
- The parameters by which to perform the execution.public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
SharedSessionContractImplementor
scroll
in interface SharedSessionContractImplementor
spec
- The specification of the native SQL query to execute.queryParameters
- The parameters by which to perform the execution.public ExceptionConverter getExceptionConverter()
getExceptionConverter
in interface SharedSessionContractImplementor
public Integer getJdbcBatchSize()
SharedSessionContract
hibernate.default_batch_fetch_size
configuration property for the scope of the current Session
.getJdbcBatchSize
in interface JdbcSessionOwner
getJdbcBatchSize
in interface SharedSessionContract
SessionFactoryOptions.getJdbcBatchSize()
,
SessionFactoryBuilder.applyJdbcBatchSize(int)
public void setJdbcBatchSize(Integer jdbcBatchSize)
SharedSessionContract
hibernate.default_batch_fetch_size
configuration property for the scope of the current Session
.setJdbcBatchSize
in interface SharedSessionContract
jdbcBatchSize
- Session-level JDBC batch sizeSessionFactoryOptions.getJdbcBatchSize()
,
SessionFactoryBuilder.applyJdbcBatchSize(int)
Copyright © 2021 JBoss by Red Hat. All rights reserved.