Class GemfireTransactionManager

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

public class GemfireTransactionManager extends org.springframework.transaction.support.AbstractPlatformTransactionManager implements org.springframework.beans.factory.InitializingBean, org.springframework.transaction.support.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.

See Also:
  • CopyHelper.copy(Object)
  • GemFireCache.setCopyOnRead(boolean)
  • CacheTransactionManager
  • Region
  • TransactionId
  • InitializingBean
  • PlatformTransactionManager
  • TransactionDefinition
  • AbstractPlatformTransactionManager
  • ResourceTransactionManager
  • TransactionSynchronizationManager
  • setCopyOnRead(boolean)
  • Serialized Form
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected 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

    org.springframework.transaction.support.AbstractPlatformTransactionManager.SuspendedResourcesHolder
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final TimeUnit
     

    Fields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager

    logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
  • Constructor Summary

    Constructors
    Constructor
    Description
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected void
    doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition)
     
    protected void
     
    protected void
    doCommit(org.springframework.transaction.support.DefaultTransactionStatus status)
     
    protected Object
     
    protected void
    doResume(Object transaction, Object suspendedResources)
     
    protected void
    doRollback(org.springframework.transaction.support.DefaultTransactionStatus status)
     
    protected void
    doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)
     
    protected Object
    doSuspend(Object transaction)
     
    org.apache.geode.cache.GemFireCache
    Returns a reference to the GemFireCache for which this transaction manager manages local cache transactions.
    protected org.apache.geode.cache.CacheTransactionManager
    Returns a reference to the CacheTransactionManager 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 the TimeUnit 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
     
    protected boolean
    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(Long resumeWaitTime)
    Sets the timeout used to wait for the GemFire cache transaction to resume.
    void
    setResumeWaitTimeUnit(TimeUnit resumeWaitTimeUnit)
    Sets the TimeUnit 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

      protected static final TimeUnit DEFAULT_RESUME_WAIT_TIME_UNIT
  • Constructor Details

    • GemfireTransactionManager

      public GemfireTransactionManager()
      Constructs an instance of the GemfireTransactionManager.
    • GemfireTransactionManager

      public GemfireTransactionManager(org.apache.geode.cache.GemFireCache cache)
      Constructs an instance of the GemfireTransactionManager initialized with the given GemFireCache reference.
      Parameters:
      cache - reference to the GemFireCache associated with cache transactions.
      See Also:
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • doGetTransaction

      protected Object doGetTransaction() throws org.springframework.transaction.TransactionException
      Specified by:
      doGetTransaction in class org.springframework.transaction.support.AbstractPlatformTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • isExistingTransaction

      protected boolean isExistingTransaction(Object transaction) throws org.springframework.transaction.TransactionException
      Overrides:
      isExistingTransaction in class org.springframework.transaction.support.AbstractPlatformTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doBegin

      protected void doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition) throws org.springframework.transaction.TransactionException
      Specified by:
      doBegin in class org.springframework.transaction.support.AbstractPlatformTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doCommit

      protected void doCommit(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException
      Specified by:
      doCommit in class org.springframework.transaction.support.AbstractPlatformTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doSuspend

      protected Object doSuspend(Object transaction) throws org.springframework.transaction.TransactionException
      Overrides:
      doSuspend in class org.springframework.transaction.support.AbstractPlatformTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doResume

      protected void doResume(Object transaction, Object suspendedResources) throws org.springframework.transaction.TransactionException
      Overrides:
      doResume in class org.springframework.transaction.support.AbstractPlatformTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doRollback

      protected void doRollback(org.springframework.transaction.support.DefaultTransactionStatus status) throws org.springframework.transaction.TransactionException
      Specified by:
      doRollback in class org.springframework.transaction.support.AbstractPlatformTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doCleanupAfterCompletion

      protected void doCleanupAfterCompletion(Object transaction)
      Overrides:
      doCleanupAfterCompletion in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doSetRollbackOnly

      protected void doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)
      Overrides:
      doSetRollbackOnly in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • useSavepointForNestedTransaction

      protected final boolean useSavepointForNestedTransaction()
      Overrides:
      useSavepointForNestedTransaction in class org.springframework.transaction.support.AbstractPlatformTransactionManager
    • setCache

      public void setCache(org.apache.geode.cache.GemFireCache cache)
      Sets a reference to the GemFireCache for which this transaction manager manages local cache transactions.
      Parameters:
      cache - reference to the GemFireCache.
      See Also:
      • GemFireCache
    • getCache

      public org.apache.geode.cache.GemFireCache getCache()
      Returns a reference to the GemFireCache for which this transaction manager manages local cache transactions.
      Returns:
      a reference to the GemFireCache.
      See Also:
      • GemFireCache
    • getCacheTransactionManager

      protected org.apache.geode.cache.CacheTransactionManager getCacheTransactionManager()
      Returns a reference to the CacheTransactionManager 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 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 - 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

      public <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.
      Type Parameters:
      K - Class type of the Region key.
      V - Class type of the Region value.
      Parameters:
      region - GemFire cache Region directly involved in the local cache transaction.
      Throws:
      IllegalArgumentException - if Region is null.
      See Also:
      • Region
    • getResourceFactory

      public Object getResourceFactory()
      Specified by:
      getResourceFactory in interface org.springframework.transaction.support.ResourceTransactionManager
    • setResumeWaitTime

      public void setResumeWaitTime(Long resumeWaitTime)
      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:
      • CacheTransactionManager.tryResume(TransactionId, long, TimeUnit)
    • getResumeWaitTime

      protected Long 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:
      • CacheTransactionManager.tryResume(TransactionId, long, TimeUnit)
    • 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

      public void setResumeWaitTimeUnit(TimeUnit resumeWaitTimeUnit)
      Sets the TimeUnit 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:
      • CacheTransactionManager.tryResume(TransactionId, long, TimeUnit)
    • getResumeWaitTimeUnit

      protected TimeUnit getResumeWaitTimeUnit()
      Returns the TimeUnit used in the wait timeout when resuming a GemFire cache transaction. Defaults to TimeUnit.SECONDS.
      Returns:
      the TimeUnit used in the wait timeout when resuming a GemFire cache transaction.
      See Also:
      • CacheTransactionManager.tryResume(TransactionId, long, TimeUnit)