Package: org.grails.transaction

## [Java] Class ChainedTransactionManagerPostProcessor

- org.grails.transaction.ChainedTransactionManagerPostProcessor

- All Implemented Interfaces and Traits:
    org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.core.Ordered

      public class ChainedTransactionManagerPostProcessor
      extends java.lang.Object
      implements org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.core.Ordered

  A org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor for using the "Best Effort 1 Phase Commit" (BE1PC) in Grails applications when there are multiple data sources. When the context contains multiple transactionManager beans, the bean with the name "transactionManager" will be renamed to "$primaryTransactionManager" and a new ChainedTransactionManager bean will be added with the name "transactionManager". All transactionManager beans will be registered in the ChainedTransactionManager bean. The post processor checks if the previous transactionManager bean is an instance of org.springframework.transaction.jta.JtaTransactionManager. In that case it will not do anything since it's assumed that JTA/XA is handling transactions spanning multiple datasources. For performance reasons an additional dataSource can be marked as non-transactional by adding a property 'transactional = false' in it's dataSource configuration. This will leave the dataSource out of the transactions initiated by Grails transactions. This is the default behaviour in Grails versions before Grails 2.3.6 .

  Authors:
    Lari Hotari
  Since:
    2.3.6

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static java.lang.String` | `DATA_SOURCES_PREFIX` |
    `static java.lang.String` | `DATA_SOURCES_SETTING` |
    `static java.lang.String` | `DATA_SOURCE_SETTING` |
    `private static java.lang.String` | `DEFAULT_TRANSACTION_MANAGER_BEAN_NAME_WHITELIST_PATTERN` |
    `private static java.lang.String` | `DEFAULT_TRANSACTION_MANAGER_INTERNAL_BEAN_NAME_BLACKLIST_PATTERN` |
    `private static java.lang.String` | `PRIMARY_TRANSACTION_MANAGER` |
    `private static java.lang.String` | `READONLY` |
    `private static java.util.regex.Pattern` | `SUFFIX_PATTERN` |
    `private static java.lang.String` | `TRANSACTIONAL` |
    `private static java.lang.String` | `TRANSACTION_MANAGER` |
    `private java.lang.String` | `beanNameBlacklistPattern` |
    `private java.lang.String` | `beanNameInternalBlacklistPattern` |
    `private java.lang.String` | `beanNameWhitelistPattern` |
    `private Config` | `config` |
    `private java.util.Map<java.lang.String, java.util.Map>` | `dsConfigs` |
    `private static java.lang.String[]` | `transactionManagerBeanNames` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ChainedTransactionManagerPostProcessor (Config config)`
    `ChainedTransactionManagerPostProcessor (Config config, java.lang.String whitelistPattern, java.lang.String blacklistPattern)`
    `ChainedTransactionManagerPostProcessor ()`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected org.springframework.beans.factory.config.BeanDefinition` | `addChainedTransactionManager(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)`
    `` | `protected int` | `countChainableTransactionManagerBeans(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)`
    `` | `protected org.springframework.beans.factory.support.ManagedList<org.springframework.beans.factory.config.RuntimeBeanReference>` | `createTransactionManagerBeanReferences(org.springframework.beans.factory.config.BeanDefinition chainedTransactionManagerBeanDefinition)`
    `` | `public java.lang.String` | `getBeanNameBlacklistPattern()`
    `` | `public java.lang.String` | `getBeanNameInternalBlacklistPattern()`
    `` | `public java.lang.String` | `getBeanNameWhitelistPattern()`
    `` | `public int` | `getOrder()`
    `` | `protected static java.lang.String[]` | `getTransactionManagerBeanNames(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)`
    `` | `protected boolean` | `hasJtaOrChainedTransactionManager(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)`
    `` | `protected boolean` | `isNotTransactional(java.lang.String suffix)`
    `` | `protected boolean` | `isValidTransactionManagerBeanDefinition(java.lang.String beanName, org.springframework.beans.factory.config.BeanDefinition beanDefinition)`
    `` | `public void` | `postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)`
    `` | `public void` | `postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)`
    `` | `protected void` | `registerAdditionalTransactionManagers(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, org.springframework.beans.factory.config.BeanDefinition chainedTransactionManagerBeanDefinition, org.springframework.beans.factory.support.ManagedList<org.springframework.beans.factory.config.RuntimeBeanReference> transactionManagerRefs)`
    `` | `private static boolean` | `renameBean(java.lang.String oldName, java.lang.String newName, org.springframework.beans.factory.support.BeanDefinitionRegistry registry)`
    `` | `protected java.lang.String` | `resolveDataSourceSuffix(java.lang.String transactionManagerBeanName)`
    `` | `protected java.lang.Class<?>` | `resolveTransactionManagerClass(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)`
    `` | `public void` | `setBeanNameBlacklistPattern(java.lang.String beanNameBlacklistPattern)`
    `` | `public void` | `setBeanNameInternalBlacklistPattern(java.lang.String beanNameInternalBlacklistPattern)`
    `` | `public void` | `setBeanNameWhitelistPattern(java.lang.String beanNameWhitelistPattern)`
    `` | `public void` | `setConfig(Config config)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Field Detail

    - #### public static final java.lang.String DATA_SOURCES_PREFIX

    - #### public static final java.lang.String DATA_SOURCES_SETTING

    - #### public static final java.lang.String DATA_SOURCE_SETTING

    - #### private static final java.lang.String DEFAULT_TRANSACTION_MANAGER_BEAN_NAME_WHITELIST_PATTERN

    - #### private static final java.lang.String DEFAULT_TRANSACTION_MANAGER_INTERNAL_BEAN_NAME_BLACKLIST_PATTERN

    - #### private static final java.lang.String PRIMARY_TRANSACTION_MANAGER

    - #### private static final java.lang.String READONLY

    - #### private static final java.util.regex.Pattern SUFFIX_PATTERN

    - #### private static final java.lang.String TRANSACTIONAL

    - #### private static final java.lang.String TRANSACTION_MANAGER

    - #### private java.lang.String beanNameBlacklistPattern

    - #### private java.lang.String beanNameInternalBlacklistPattern

    - #### private java.lang.String beanNameWhitelistPattern

    - #### private Config config

    - #### private java.util.Map<java.lang.String, java.util.Map> dsConfigs

    - #### private static java.lang.String[] transactionManagerBeanNames

  - ### Constructor Detail

    - #### public ChainedTransactionManagerPostProcessor(Config config)

    - #### public ChainedTransactionManagerPostProcessor(Config config, java.lang.String whitelistPattern, java.lang.String blacklistPattern)

    - #### public ChainedTransactionManagerPostProcessor()

  - ### Method Detail

    - #### protected org.springframework.beans.factory.config.BeanDefinition addChainedTransactionManager(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)

    - #### protected int countChainableTransactionManagerBeans(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)

    - #### protected org.springframework.beans.factory.support.ManagedList<org.springframework.beans.factory.config.RuntimeBeanReference> createTransactionManagerBeanReferences(org.springframework.beans.factory.config.BeanDefinition chainedTransactionManagerBeanDefinition)

    - #### public java.lang.String getBeanNameBlacklistPattern()

    - #### public java.lang.String getBeanNameInternalBlacklistPattern()

    - #### public java.lang.String getBeanNameWhitelistPattern()

    - #### @java.lang.Override public int getOrder()

    - #### protected static java.lang.String[] getTransactionManagerBeanNames(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)

    - #### protected boolean hasJtaOrChainedTransactionManager(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)

    - #### protected boolean isNotTransactional(java.lang.String suffix)

    - #### protected boolean isValidTransactionManagerBeanDefinition(java.lang.String beanName, org.springframework.beans.factory.config.BeanDefinition beanDefinition)

    - #### @java.lang.Override public void postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)

    - #### @java.lang.Override public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)

    - #### protected void registerAdditionalTransactionManagers(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, org.springframework.beans.factory.config.BeanDefinition chainedTransactionManagerBeanDefinition, org.springframework.beans.factory.support.ManagedList<org.springframework.beans.factory.config.RuntimeBeanReference> transactionManagerRefs)

    - #### private static boolean renameBean(java.lang.String oldName, java.lang.String newName, org.springframework.beans.factory.support.BeanDefinitionRegistry registry)

    - #### protected java.lang.String resolveDataSourceSuffix(java.lang.String transactionManagerBeanName)

    - #### protected java.lang.Class<?> resolveTransactionManagerClass(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)

    - #### public void setBeanNameBlacklistPattern(java.lang.String beanNameBlacklistPattern)

    - #### public void setBeanNameInternalBlacklistPattern(java.lang.String beanNameInternalBlacklistPattern)

    - #### public void setBeanNameWhitelistPattern(java.lang.String beanNameWhitelistPattern)

    - #### public void setConfig(Config config)