org.springframework.data.gemfire
Class GemfireTransactionManager

java.lang.Object
  extended by org.springframework.transaction.support.AbstractPlatformTransactionManager
      extended by org.springframework.data.gemfire.GemfireTransactionManager
All Implemented Interfaces:
Serializable, InitializingBean, PlatformTransactionManager, ResourceTransactionManager

public class GemfireTransactionManager
extends AbstractPlatformTransactionManager
implements InitializingBean, ResourceTransactionManager

Local transaction manager for GemFire Enterprise Fabric (GEF). Provides a PlatformTransactionManager implementation for a single GemFire CacheTransactionManager. Binds one or multiple GemFire regions for the specified Cache to the thread, potentially allowing for one region per cache model.

This local strategy is an alternative to executing cache operations within JTA transactions. Its advantage is that is able to work in any environment, for example a stand-alone application or a test suite. It is not able to provide XA transactions, for example to share transactions with data access.

To prevent dirty reads, by default, the cache is configured to return copies rather then direct references for get operations. As a workaround, one could use explicitly deep copy objects before making changes to them to avoid unnecessary copying on every fetch.

See Also:
CacheTransactionManager, GemFireCache.setCopyOnRead(boolean), Region.get(Object), CopyHelper.copy(Object), setCopyOnRead(boolean), AbstractPlatformTransactionManager, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
AbstractPlatformTransactionManager.SuspendedResourcesHolder
 
Field Summary
 
Fields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
 
Constructor Summary
GemfireTransactionManager()
          Creates a new GemfireTransactionManager instance.
GemfireTransactionManager(com.gemstone.gemfire.cache.Cache cache)
          Creates a new GemfireTransactionManager instance.
 
Method Summary
 void afterPropertiesSet()
           
protected  void doBegin(Object transaction, TransactionDefinition definition)
           
protected  void doCleanupAfterCompletion(Object transaction)
           
protected  void doCommit(DefaultTransactionStatus status)
           
protected  Object doGetTransaction()
           
protected  void doRollback(DefaultTransactionStatus status)
           
protected  void doSetRollbackOnly(DefaultTransactionStatus status)
           
 com.gemstone.gemfire.cache.Cache getCache()
          Returns the Cache that this instance manages local transactions for.
 Object getResourceFactory()
           
 boolean isCopyOnRead()
          Indicates whether copy on read is set or not on the transaction manager.
protected  boolean isExistingTransaction(Object transaction)
           
 void setCache(com.gemstone.gemfire.cache.Cache cache)
          Sets the Cache that this instance manages local transactions for.
 void setCopyOnRead(boolean copyOnRead)
          Indicates whether the cache returns direct references or copies of the objects (default) it manages.
<K,V> void
setRegion(com.gemstone.gemfire.cache.Region<K,V> region)
          Sets the Gemfire Region (as an alternative in setting in the cache directly).
protected  boolean useSavepointForNestedTransaction()
           
 
Methods inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
commit, determineTimeout, doResume, doSuspend, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, newTransactionStatus, prepareForCommit, prepareSynchronization, prepareTransactionStatus, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.transaction.PlatformTransactionManager
commit, getTransaction, rollback
 

Constructor Detail

GemfireTransactionManager

public GemfireTransactionManager()
Creates a new GemfireTransactionManager instance.


GemfireTransactionManager

public GemfireTransactionManager(com.gemstone.gemfire.cache.Cache cache)
Creates a new GemfireTransactionManager instance.

Parameters:
cache -
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

doGetTransaction

protected Object doGetTransaction()
                           throws TransactionException
Specified by:
doGetTransaction in class AbstractPlatformTransactionManager
Throws:
TransactionException

isExistingTransaction

protected boolean isExistingTransaction(Object transaction)
                                 throws TransactionException
Overrides:
isExistingTransaction in class AbstractPlatformTransactionManager
Throws:
TransactionException

doBegin

protected void doBegin(Object transaction,
                       TransactionDefinition definition)
                throws TransactionException
Specified by:
doBegin in class AbstractPlatformTransactionManager
Throws:
TransactionException

doCommit

protected void doCommit(DefaultTransactionStatus status)
                 throws TransactionException
Specified by:
doCommit in class AbstractPlatformTransactionManager
Throws:
TransactionException

doRollback

protected void doRollback(DefaultTransactionStatus status)
                   throws TransactionException
Specified by:
doRollback in class AbstractPlatformTransactionManager
Throws:
TransactionException

doSetRollbackOnly

protected void doSetRollbackOnly(DefaultTransactionStatus status)
Overrides:
doSetRollbackOnly in class AbstractPlatformTransactionManager

doCleanupAfterCompletion

protected void doCleanupAfterCompletion(Object transaction)
Overrides:
doCleanupAfterCompletion in class AbstractPlatformTransactionManager

useSavepointForNestedTransaction

protected final boolean useSavepointForNestedTransaction()
Overrides:
useSavepointForNestedTransaction in class AbstractPlatformTransactionManager

getCache

public com.gemstone.gemfire.cache.Cache getCache()
Returns the Cache that this instance manages local transactions for.

Returns:
Gemfire cache

setCache

public void setCache(com.gemstone.gemfire.cache.Cache cache)
Sets the Cache that this instance manages local transactions for.

Parameters:
cache - Gemfire cache

getResourceFactory

public Object getResourceFactory()
Specified by:
getResourceFactory in interface ResourceTransactionManager

setRegion

public <K,V> void setRegion(com.gemstone.gemfire.cache.Region<K,V> region)
Sets the Gemfire Region (as an alternative in setting in the cache directly).

Parameters:
region - Gemfire region

setCopyOnRead

public void setCopyOnRead(boolean copyOnRead)
Indicates whether the cache returns direct references or copies of the objects (default) it manages. While copies imply additional work for every fetch operation, direct references can cause dirty reads across concurrent threads in the same VM, whether or not transactions are used.

One could explicitly deep copy objects before making changes (for example by using CopyHelper.copy(Object) in which case this setting can be set to false. However, unless there is a measurable performance penalty, the recommendation is to keep this setting to true

Parameters:
copyOnRead - whether copies (default) rather then direct references will be returned on fetch operations

isCopyOnRead

public boolean isCopyOnRead()
Indicates whether copy on read is set or not on the transaction manager.

Returns:
the copyOnRead
See Also:
setCopyOnRead(boolean)