Class GemfireTransactionManager
java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.data.gemfire.transaction.GemfireTransactionManager
- All Implemented Interfaces:
Serializable,InitializingBean,PlatformTransactionManager,ResourceTransactionManager,TransactionManager
public class GemfireTransactionManager
extends AbstractPlatformTransactionManager
implements InitializingBean, ResourceTransactionManager
Local Transaction Management for Pivotal GemFire. Provides a Spring
PlatformTransactionManager implementation
for the Pivotal GemFire CacheTransactionManager.
Binds one or multiple GemFire Regions for the specified GemFireCache to the thread,
potentially allowing for one Region per GemFireCache 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.
By default, to prevent dirty reads, the GemFireCache is configured to return copies rather then direct references
for get data access operations. As a workaround, one could use explicitly deep copy objects before
making changes to them to avoid unnecessary copying on every fetch.
- Author:
- Costin Leau, John Blum
- See Also:
-
CopyHelper.copy(Object)GemFireCache.setCopyOnRead(boolean)CacheTransactionManagerRegionTransactionIdInitializingBeanPlatformTransactionManagerTransactionDefinitionAbstractPlatformTransactionManagerResourceTransactionManagerTransactionSynchronizationManagersetCopyOnRead(boolean)- Serialized Form
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classHolder of GemFire cache transaction state.protected static classGemFire local cache transaction object.Nested classes/interfaces inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
AbstractPlatformTransactionManager.SuspendedResourcesHolder -
Field Summary
FieldsFields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an instance of theGemfireTransactionManager.Constructs an instance of theGemfireTransactionManagerinitialized with the givenGemFireCachereference. -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voiddoBegin(Object transaction, TransactionDefinition definition) protected voiddoCleanupAfterCompletion(Object transaction) protected voiddoCommit(DefaultTransactionStatus status) protected Objectprotected voidprotected voiddoRollback(DefaultTransactionStatus status) protected voidprotected ObjectgetCache()Returns a reference to theGemFireCachefor which this transaction manager manages local cache transactions.protected CacheTransactionManagerReturns a reference to theCacheTransactionManagerused by Apache Geode to manage local, cache transactions.protected LongReturns the timeout used to wait for the GemFire cache transaction to resume.protected TimeUnitReturns theTimeUnitused in the wait timeout when resuming a GemFire cache transaction.booleanIndicates whether copy on read is set and used for fetch data access operations.protected booleanisExistingTransaction(Object transaction) protected booleanDetermines whether the user specified a wait time for resuming a GemFire cache transaction.voidsetCache(GemFireCache cache) Sets a reference to theGemFireCachefor which this transaction manager manages local cache transactions.voidsetCopyOnRead(boolean copyOnRead) Set whether the cache returns direct object references or copies of the objects it manages.<K,V> void Sets the GemFire cacheRegionas an alternative in setting in theGemFireCachedirectly.voidsetResumeWaitTime(Long resumeWaitTime) Sets the timeout used to wait for the GemFire cache transaction to resume.voidsetResumeWaitTimeUnit(TimeUnit resumeWaitTimeUnit) Sets theTimeUnitused in the wait timeout when resuming a GemFire cache transaction.protected final booleanMethods inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager
commit, determineTimeout, 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, triggerBeforeCompletionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.transaction.PlatformTransactionManager
commit, getTransaction, rollback
-
Field Details
-
DEFAULT_RESUME_WAIT_TIME_UNIT
-
-
Constructor Details
-
GemfireTransactionManager
public GemfireTransactionManager()Constructs an instance of theGemfireTransactionManager. -
GemfireTransactionManager
Constructs an instance of theGemfireTransactionManagerinitialized with the givenGemFireCachereference.- Parameters:
cache- reference to theGemFireCacheassociated with cache transactions.- See Also:
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
doGetTransaction
- Specified by:
doGetTransactionin classAbstractPlatformTransactionManager- Throws:
TransactionException
-
isExistingTransaction
- Overrides:
isExistingTransactionin classAbstractPlatformTransactionManager- Throws:
TransactionException
-
doBegin
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException - Specified by:
doBeginin classAbstractPlatformTransactionManager- Throws:
TransactionException
-
doCommit
- Specified by:
doCommitin classAbstractPlatformTransactionManager- Throws:
TransactionException
-
doSuspend
- Overrides:
doSuspendin classAbstractPlatformTransactionManager- Throws:
TransactionException
-
doResume
- Overrides:
doResumein classAbstractPlatformTransactionManager- Throws:
TransactionException
-
doRollback
- Specified by:
doRollbackin classAbstractPlatformTransactionManager- Throws:
TransactionException
-
doCleanupAfterCompletion
- Overrides:
doCleanupAfterCompletionin classAbstractPlatformTransactionManager
-
doSetRollbackOnly
- Overrides:
doSetRollbackOnlyin classAbstractPlatformTransactionManager
-
useSavepointForNestedTransaction
protected final boolean useSavepointForNestedTransaction()- Overrides:
useSavepointForNestedTransactionin classAbstractPlatformTransactionManager
-
setCache
Sets a reference to theGemFireCachefor which this transaction manager manages local cache transactions.- Parameters:
cache- reference to theGemFireCache.- See Also:
-
getCache
Returns a reference to theGemFireCachefor which this transaction manager manages local cache transactions.- Returns:
- a reference to the
GemFireCache. - See Also:
-
getCacheTransactionManager
Returns a reference to theCacheTransactionManagerused by Apache Geode to manage local, cache transactions.- Returns:
- a reference to the
CacheTransactionManager. - See Also:
-
setCopyOnRead
public void setCopyOnRead(boolean copyOnRead) Set whether the cache returns direct object references or copies of the objects it manages. While copies imply additional work for every fetch operation, direct object 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 usingCopyHelper.copy(Object)in which case this setting can be set tofalseHowever, unless there is a measurable performance penalty, the recommendation is to keep this setting totrue.- Parameters:
copyOnRead- boolean value indicating whether copies (default) rather then direct object references will be returned on fetch operations.
-
isCopyOnRead
public boolean isCopyOnRead()Indicates whether copy on read is set and used for fetch data access operations.- Returns:
- the setting for copy-on-read.
- See Also:
-
setRegion
Sets the GemFire cacheRegionas an alternative in setting in theGemFireCachedirectly. -
getResourceFactory
- Specified by:
getResourceFactoryin interfaceResourceTransactionManager
-
setResumeWaitTime
Sets the timeout used to wait for the GemFire cache transaction to resume.- Parameters:
resumeWaitTime- long value with the timeout used to wait for the GemFire cache transaction to resume.- See Also:
-
getResumeWaitTime
Returns the timeout used to wait for the GemFire cache transaction to resume.- Returns:
- the long value with the timeout used to wait for the GemFire cache transaction to resume.
- See Also:
-
isResumeWaitTimeSet
protected boolean isResumeWaitTimeSet()Determines whether the user specified a wait time for resuming a GemFire cache transaction.- Returns:
- a boolean value to indicate whether the user specified a wait time for resuming a GemFire cache transaction.
- See Also:
-
setResumeWaitTimeUnit
Sets theTimeUnitused in the wait timeout when resuming a GemFire cache transaction.- Parameters:
resumeWaitTimeUnit-TimeUnitused in the wait timeout when resuming a GemFire cache transaction.- See Also:
-
getResumeWaitTimeUnit
Returns theTimeUnitused in the wait timeout when resuming a GemFire cache transaction. Defaults toTimeUnit.SECONDS.- Returns:
- the
TimeUnitused in the wait timeout when resuming a GemFire cache transaction. - See Also:
-