public class GemfireTransactionManager
extends org.springframework.transaction.support.AbstractPlatformTransactionManager
implements org.springframework.beans.factory.InitializingBean, org.springframework.transaction.support.ResourceTransactionManager
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.
CopyHelper.copy(Object)
,
GemFireCache.setCopyOnRead(boolean)
,
CacheTransactionManager
,
Region
,
TransactionId
,
InitializingBean
,
PlatformTransactionManager
,
TransactionDefinition
,
AbstractPlatformTransactionManager
,
ResourceTransactionManager
,
TransactionSynchronizationManager
,
setCopyOnRead(boolean)
,
Serialized FormModifier and Type | Class and Description |
---|---|
protected static class |
GemfireTransactionManager.CacheHolder
Holder of GemFire cache transaction state.
|
protected static class |
GemfireTransactionManager.CacheTransactionObject
GemFire local cache transaction object.
|
Modifier and Type | Field and Description |
---|---|
protected static java.util.concurrent.TimeUnit |
DEFAULT_RESUME_WAIT_TIME_UNIT |
Constructor and Description |
---|
GemfireTransactionManager()
Constructs an instance of the
GemfireTransactionManager . |
GemfireTransactionManager(org.apache.geode.cache.GemFireCache cache)
Constructs an instance of the
GemfireTransactionManager initialized with
the given GemFireCache reference. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected void |
doBegin(java.lang.Object transaction,
org.springframework.transaction.TransactionDefinition definition) |
protected void |
doCleanupAfterCompletion(java.lang.Object transaction) |
protected void |
doCommit(org.springframework.transaction.support.DefaultTransactionStatus status) |
protected java.lang.Object |
doGetTransaction() |
protected void |
doResume(java.lang.Object transaction,
java.lang.Object suspendedResources) |
protected void |
doRollback(org.springframework.transaction.support.DefaultTransactionStatus status) |
protected void |
doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status) |
protected java.lang.Object |
doSuspend(java.lang.Object transaction) |
org.apache.geode.cache.GemFireCache |
getCache()
Returns a reference to the
GemFireCache for which this transaction manager
manages local cache transactions. |
protected org.apache.geode.cache.CacheTransactionManager |
getCacheTransactionManager()
Returns a reference to the
CacheTransactionManager used by Apache Geode to manage local,
cache transactions. |
java.lang.Object |
getResourceFactory() |
protected java.lang.Long |
getResumeWaitTime()
Returns the timeout used to wait for the GemFire cache transaction to resume.
|
protected java.util.concurrent.TimeUnit |
getResumeWaitTimeUnit()
Returns the
TimeUnit used in the wait timeout when resuming a GemFire cache transaction. |
boolean |
isCopyOnRead()
Indicates whether copy on read is set and used for fetch data access operations.
|
protected boolean |
isExistingTransaction(java.lang.Object transaction) |
protected boolean |
isResumeWaitTimeSet()
Determines whether the user specified a wait time for resuming a GemFire cache transaction.
|
void |
setCache(org.apache.geode.cache.GemFireCache cache)
Sets a reference to the
GemFireCache 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 |
setRegion(org.apache.geode.cache.Region<K,V> region)
Sets the GemFire cache
Region as an alternative in setting in the GemFireCache directly. |
void |
setResumeWaitTime(java.lang.Long resumeWaitTime)
Sets the timeout used to wait for the GemFire cache transaction to resume.
|
void |
setResumeWaitTimeUnit(java.util.concurrent.TimeUnit resumeWaitTimeUnit)
Sets the
TimeUnit used in the wait timeout when resuming a GemFire cache transaction. |
protected boolean |
useSavepointForNestedTransaction() |
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
protected static final java.util.concurrent.TimeUnit DEFAULT_RESUME_WAIT_TIME_UNIT
public GemfireTransactionManager()
GemfireTransactionManager
.public GemfireTransactionManager(org.apache.geode.cache.GemFireCache cache)
GemfireTransactionManager
initialized with
the given GemFireCache
reference.cache
- reference to the GemFireCache
associated with cache transactions.GemFireCache
,
afterPropertiesSet()
public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
protected java.lang.Object doGetTransaction() throws org.springframework.transaction.TransactionException
doGetTransaction
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected boolean isExistingTransaction(java.lang.Object transaction) throws org.springframework.transaction.TransactionException
isExistingTransaction
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doBegin(java.lang.Object transaction, org.springframework.transaction.TransactionDefinition definition) throws org.springframework.transaction.TransactionException
doBegin
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doCommit(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException
doCommit
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected java.lang.Object doSuspend(java.lang.Object transaction) throws org.springframework.transaction.TransactionException
doSuspend
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doResume(java.lang.Object transaction, java.lang.Object suspendedResources) throws org.springframework.transaction.TransactionException
doResume
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doRollback(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException
doRollback
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.TransactionException
protected void doCleanupAfterCompletion(java.lang.Object transaction)
doCleanupAfterCompletion
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
protected void doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)
doSetRollbackOnly
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
protected final boolean useSavepointForNestedTransaction()
useSavepointForNestedTransaction
in class org.springframework.transaction.support.AbstractPlatformTransactionManager
public void setCache(org.apache.geode.cache.GemFireCache cache)
GemFireCache
for which this transaction manager
manages local cache transactions.cache
- reference to the GemFireCache
.GemFireCache
public org.apache.geode.cache.GemFireCache getCache()
GemFireCache
for which this transaction manager
manages local cache transactions.GemFireCache
.GemFireCache
protected org.apache.geode.cache.CacheTransactionManager getCacheTransactionManager()
CacheTransactionManager
used by Apache Geode to manage local,
cache transactions.CacheTransactionManager
.CacheTransactionManager
,
getCache()
public void setCopyOnRead(boolean copyOnRead)
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
.copyOnRead
- boolean value indicating whether copies (default) rather then direct object references
will be returned on fetch operations.public boolean isCopyOnRead()
setCopyOnRead(boolean)
public <K,V> void setRegion(org.apache.geode.cache.Region<K,V> region)
Region
as an alternative in setting in the GemFireCache
directly.K
- Class
type of the Region
key.V
- Class
type of the Region
value.region
- GemFire cache Region
directly involved in the local cache transaction.java.lang.IllegalArgumentException
- if Region
is null.Region
public java.lang.Object getResourceFactory()
getResourceFactory
in interface org.springframework.transaction.support.ResourceTransactionManager
public void setResumeWaitTime(java.lang.Long resumeWaitTime)
resumeWaitTime
- long value with the timeout used to wait for the GemFire cache transaction to resume.CacheTransactionManager.tryResume(TransactionId, long, TimeUnit)
protected java.lang.Long getResumeWaitTime()
CacheTransactionManager.tryResume(TransactionId, long, TimeUnit)
protected boolean isResumeWaitTimeSet()
CacheTransactionManager.tryResume(TransactionId, long, TimeUnit)
,
getResumeWaitTime()
public void setResumeWaitTimeUnit(java.util.concurrent.TimeUnit resumeWaitTimeUnit)
TimeUnit
used in the wait timeout when resuming a GemFire cache transaction.resumeWaitTimeUnit
- TimeUnit
used in the wait timeout when resuming a GemFire cache transaction.CacheTransactionManager.tryResume(TransactionId, long, TimeUnit)
protected java.util.concurrent.TimeUnit getResumeWaitTimeUnit()
TimeUnit
used in the wait timeout when resuming a GemFire cache transaction.
Defaults to TimeUnit.SECONDS
.TimeUnit
used in the wait timeout when resuming a GemFire cache transaction.CacheTransactionManager.tryResume(TransactionId, long, TimeUnit)