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)
CacheTransactionManager
Region
TransactionId
InitializingBean
PlatformTransactionManager
TransactionDefinition
AbstractPlatformTransactionManager
ResourceTransactionManager
TransactionSynchronizationManager
setCopyOnRead(boolean)
- Serialized Form
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Holder of GemFire cache transaction state.protected static class
GemFire local cache transaction object.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
ConstructorDescriptionConstructs an instance of theGemfireTransactionManager
.Constructs an instance of theGemfireTransactionManager
initialized with the givenGemFireCache
reference. -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected void
doBegin
(Object transaction, TransactionDefinition definition) protected void
doCleanupAfterCompletion
(Object transaction) protected void
doCommit
(DefaultTransactionStatus status) protected Object
protected void
protected void
doRollback
(DefaultTransactionStatus status) protected void
protected Object
getCache()
Returns a reference to theGemFireCache
for which this transaction manager manages local cache transactions.protected CacheTransactionManager
Returns a reference to theCacheTransactionManager
used by Apache Geode to manage local, cache transactions.protected Long
Returns the timeout used to wait for the GemFire cache transaction to resume.protected TimeUnit
Returns theTimeUnit
used in the wait timeout when resuming a GemFire cache transaction.boolean
Indicates whether copy on read is set and used for fetch data access operations.protected boolean
isExistingTransaction
(Object transaction) protected boolean
Determines whether the user specified a wait time for resuming a GemFire cache transaction.void
setCache
(GemFireCache cache) Sets a reference to theGemFireCache
for which this transaction manager manages local cache transactions.void
setCopyOnRead
(boolean copyOnRead) Set whether the cache returns direct object references or copies of the objects it manages.<K,
V> void Sets the GemFire cacheRegion
as an alternative in setting in theGemFireCache
directly.void
setResumeWaitTime
(Long resumeWaitTime) Sets the timeout used to wait for the GemFire cache transaction to resume.void
setResumeWaitTimeUnit
(TimeUnit resumeWaitTimeUnit) Sets theTimeUnit
used in the wait timeout when resuming a GemFire cache transaction.protected final boolean
Methods 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, 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
-
Field Details
-
DEFAULT_RESUME_WAIT_TIME_UNIT
-
-
Constructor Details
-
GemfireTransactionManager
public GemfireTransactionManager()Constructs an instance of theGemfireTransactionManager
. -
GemfireTransactionManager
Constructs an instance of theGemfireTransactionManager
initialized with the givenGemFireCache
reference.- Parameters:
cache
- reference to theGemFireCache
associated with cache transactions.- See Also:
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
doGetTransaction
- Specified by:
doGetTransaction
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
isExistingTransaction
- Overrides:
isExistingTransaction
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doBegin
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException - Specified by:
doBegin
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doCommit
- Specified by:
doCommit
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doSuspend
- Overrides:
doSuspend
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doResume
- Overrides:
doResume
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doRollback
- Specified by:
doRollback
in classAbstractPlatformTransactionManager
- Throws:
TransactionException
-
doCleanupAfterCompletion
- Overrides:
doCleanupAfterCompletion
in classAbstractPlatformTransactionManager
-
doSetRollbackOnly
- Overrides:
doSetRollbackOnly
in classAbstractPlatformTransactionManager
-
useSavepointForNestedTransaction
protected final boolean useSavepointForNestedTransaction()- Overrides:
useSavepointForNestedTransaction
in classAbstractPlatformTransactionManager
-
setCache
Sets a reference to theGemFireCache
for which this transaction manager manages local cache transactions.- Parameters:
cache
- reference to theGemFireCache
.- See Also:
-
getCache
Returns a reference to theGemFireCache
for which this transaction manager manages local cache transactions.- Returns:
- a reference to the
GemFireCache
. - See Also:
-
getCacheTransactionManager
Returns a reference to theCacheTransactionManager
used 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 tofalse
However, 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 cacheRegion
as an alternative in setting in theGemFireCache
directly. -
getResourceFactory
- Specified by:
getResourceFactory
in 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 theTimeUnit
used in the wait timeout when resuming a GemFire cache transaction.- Parameters:
resumeWaitTimeUnit
-TimeUnit
used in the wait timeout when resuming a GemFire cache transaction.- See Also:
-
getResumeWaitTimeUnit
Returns theTimeUnit
used in the wait timeout when resuming a GemFire cache transaction. Defaults toTimeUnit.SECONDS
.- Returns:
- the
TimeUnit
used in the wait timeout when resuming a GemFire cache transaction. - See Also:
-