Class ChainedTransactionManagerPostProcessor

  • All Implemented Interfaces:
    org.springframework.beans.factory.config.BeanFactoryPostProcessor, 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 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 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 .
    Since:
    2.3.6
    • Field Detail

      • DATA_SOURCE_SETTING

        public static final java.lang.String DATA_SOURCE_SETTING
        See Also:
        Constant Field Values
      • DATA_SOURCES_SETTING

        public static final java.lang.String DATA_SOURCES_SETTING
        See Also:
        Constant Field Values
      • DATA_SOURCES_PREFIX

        public static final java.lang.String DATA_SOURCES_PREFIX
        See Also:
        Constant Field Values
    • Constructor Detail

      • ChainedTransactionManagerPostProcessor

        public ChainedTransactionManagerPostProcessor​(grails.config.Config config)
      • ChainedTransactionManagerPostProcessor

        public ChainedTransactionManagerPostProcessor​(grails.config.Config config,
                                                      java.lang.String whitelistPattern,
                                                      java.lang.String blacklistPattern)
      • ChainedTransactionManagerPostProcessor

        public ChainedTransactionManagerPostProcessor()
    • Method Detail

      • postProcessBeanFactory

        public void postProcessBeanFactory​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
                                    throws org.springframework.beans.BeansException
        Specified by:
        postProcessBeanFactory in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
        Throws:
        org.springframework.beans.BeansException
      • registerAdditionalTransactionManagers

        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)
      • getTransactionManagerBeanNames

        protected static java.lang.String[] getTransactionManagerBeanNames​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
      • postProcessBeanDefinitionRegistry

        public void postProcessBeanDefinitionRegistry​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
                                               throws org.springframework.beans.BeansException
        Specified by:
        postProcessBeanDefinitionRegistry in interface org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
        Throws:
        org.springframework.beans.BeansException
      • createTransactionManagerBeanReferences

        protected org.springframework.beans.factory.support.ManagedList<org.springframework.beans.factory.config.RuntimeBeanReference> createTransactionManagerBeanReferences​(org.springframework.beans.factory.config.BeanDefinition chainedTransactionManagerBeanDefinition)
      • addChainedTransactionManager

        protected org.springframework.beans.factory.config.BeanDefinition addChainedTransactionManager​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
      • hasJtaOrChainedTransactionManager

        protected boolean hasJtaOrChainedTransactionManager​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
      • resolveTransactionManagerClass

        protected java.lang.Class<?> resolveTransactionManagerClass​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
      • countChainableTransactionManagerBeans

        protected int countChainableTransactionManagerBeans​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
      • isValidTransactionManagerBeanDefinition

        protected boolean isValidTransactionManagerBeanDefinition​(java.lang.String beanName,
                                                                  org.springframework.beans.factory.config.BeanDefinition beanDefinition)
      • isNotTransactional

        protected boolean isNotTransactional​(java.lang.String suffix)
      • resolveDataSourceSuffix

        protected java.lang.String resolveDataSourceSuffix​(java.lang.String transactionManagerBeanName)
      • getOrder

        public int getOrder()
        Specified by:
        getOrder in interface org.springframework.core.Ordered
      • setConfig

        public void setConfig​(grails.config.Config config)
      • getBeanNameWhitelistPattern

        public java.lang.String getBeanNameWhitelistPattern()
      • setBeanNameWhitelistPattern

        public void setBeanNameWhitelistPattern​(java.lang.String beanNameWhitelistPattern)
      • getBeanNameBlacklistPattern

        public java.lang.String getBeanNameBlacklistPattern()
      • setBeanNameBlacklistPattern

        public void setBeanNameBlacklistPattern​(java.lang.String beanNameBlacklistPattern)
      • getBeanNameInternalBlacklistPattern

        public java.lang.String getBeanNameInternalBlacklistPattern()
      • setBeanNameInternalBlacklistPattern

        public void setBeanNameInternalBlacklistPattern​(java.lang.String beanNameInternalBlacklistPattern)