public class ConversationHolder
extends java.lang.Object
This behaviour essentially revolves around the resources map in the TransactionSynchronizationManager
.
This resources map contains two entries of interest,
SessionFactory
mapped to the SessionHolder
DataSource
mapped to the ConnectionHolder
The SessionHolder object itself contains the Session
as well as the org.hibernate.Transaction object.
The ConnectionHolder contains the (JDBC) {@link java.sql.Connection Connection} to the database. For every action to do with the
transaction object it is required to have both entries present in the resources. Both the session as well as the connection
objects must not be null and the corresponding holders must have their 'synchronizedWithTransaction' flag set to true.
The default behaviour of the {@link org.springframework.transaction.PlatformTransactionManager PlatformTransactionManager} which in the CDM case is autowired to {@link org.springframework.orm.hibernate5.HibernateTransactionManager HibernateTransactionManager}, is to check these entries when starting a transaction. If this entries do not exist in the resource map then they are created, implying a new session, which is in fact how hibernate implements the default 'session-per-request' pattern internally.
Given the above conditions, this class manages long running sessions by providing the following methods,
With the exception of {@link #unbind()} (which should be called explicitly), the above sequence must be strictly followed to maintain a consistent session state. Even though it is possible to interweave multiple conversations at the same time, for a specific conversation the above sequence must be followed.
http://www.hibernate.org/42.html
Modifier | Constructor and Description |
---|---|
protected |
ConversationHolder()
Simple constructor used by Spring only
|
|
ConversationHolder(javax.sql.DataSource dataSource,
org.hibernate.SessionFactory sessionFactory,
org.springframework.transaction.PlatformTransactionManager transactionManager)
Create a new Conversation holder and bind it immediately.
|
|
ConversationHolder(javax.sql.DataSource dataSource,
org.hibernate.SessionFactory sessionFactory,
org.springframework.transaction.PlatformTransactionManager transactionManager,
boolean bindNow)
Create a new Conversation holder and optionally bind it immediately.
|
Modifier and Type | Method and Description |
---|---|
void |
bind()
This method has to be called when starting a new unit-of-work.
|
void |
clear() |
void |
close()
Free resources bound to this conversationHolder
|
void |
commit()
Commit the running transaction.
|
org.springframework.transaction.TransactionStatus |
commit(boolean restartTransaction)
Commit the running transaction but optionally start a
new one right away.
|
void |
delete(java.lang.Object object) |
void |
evict(java.lang.Object object) |
org.hibernate.FlushMode |
getDefaultFlushMode() |
org.springframework.transaction.TransactionDefinition |
getDefinition() |
org.hibernate.Session |
getSession() |
org.hibernate.SessionFactory |
getSessionFactory() |
org.springframework.orm.hibernate5.SessionHolder |
getSessionHolder() |
boolean |
isBound() |
boolean |
isClosed() |
boolean |
isCompleted() |
boolean |
isTransactionActive() |
void |
lock(java.lang.Object persistentObject,
org.hibernate.LockMode lockMode)
Facades Session.lock()
|
void |
lock(java.lang.String entityName,
java.lang.Object persistentObject,
org.hibernate.LockMode lockMode) |
void |
refresh(java.lang.Object object) |
void |
registerForDataStoreChanges(IConversationEnabled observer)
Register to get updated after any interaction with the datastore
|
void |
setDefaultFlushMode(org.hibernate.FlushMode defaultFlushMode) |
void |
setDefinition(org.springframework.transaction.TransactionDefinition definition) |
org.springframework.transaction.TransactionStatus |
startTransaction()
Creates an instance of TransactionStatus and binds it to this conversation manager.
|
void |
unbind()
This method has to be called when suspending the current unit of work.
|
void |
unregisterForDataStoreChanges(IConversationEnabled observer)
Register to get updated after any interaction with the datastore
|
protected ConversationHolder()
public ConversationHolder(javax.sql.DataSource dataSource, org.hibernate.SessionFactory sessionFactory, org.springframework.transaction.PlatformTransactionManager transactionManager)
dataSource
- sessionFactory
- transactionManager
- public ConversationHolder(javax.sql.DataSource dataSource, org.hibernate.SessionFactory sessionFactory, org.springframework.transaction.PlatformTransactionManager transactionManager, boolean bindNow)
dataSource
- sessionFactory
- transactionManager
- public void bind()
public void unbind()
public org.springframework.orm.hibernate5.SessionHolder getSessionHolder()
public boolean isBound()
public org.springframework.transaction.TransactionStatus startTransaction()
public boolean isTransactionActive()
public void evict(java.lang.Object object)
public void refresh(java.lang.Object object)
public void clear()
public void commit()
public org.springframework.transaction.TransactionStatus commit(boolean restartTransaction)
restartTransaction
- whether to start a new transactionpublic org.hibernate.Session getSession()
public org.hibernate.SessionFactory getSessionFactory()
public void delete(java.lang.Object object)
public void lock(java.lang.Object persistentObject, org.hibernate.LockMode lockMode)
public void lock(java.lang.String entityName, java.lang.Object persistentObject, org.hibernate.LockMode lockMode)
public org.springframework.transaction.TransactionDefinition getDefinition()
public void setDefinition(org.springframework.transaction.TransactionDefinition definition)
definition
- the definition to setpublic void registerForDataStoreChanges(IConversationEnabled observer)
public void unregisterForDataStoreChanges(IConversationEnabled observer)
public void close()
public boolean isClosed()
public boolean isCompleted()
public org.hibernate.FlushMode getDefaultFlushMode()
public void setDefaultFlushMode(org.hibernate.FlushMode defaultFlushMode)
defaultFlushMode
- the defaultFlushMode to setCopyright © 2007-2020 EDIT. All Rights Reserved.