|
@@ -1,148 +0,0 @@
|
|
|
-//package com.gxzc.zen.orm.config
|
|
|
-//
|
|
|
-//import com.gxzc.zen.orm.DataSourceSwitchMethodInterceptor
|
|
|
-//import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor
|
|
|
-//import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator
|
|
|
-//import org.springframework.beans.factory.annotation.Qualifier
|
|
|
-//import org.springframework.context.annotation.Bean
|
|
|
-//import org.springframework.context.annotation.Configuration
|
|
|
-//import org.springframework.transaction.PlatformTransactionManager
|
|
|
-//import org.springframework.transaction.TransactionDefinition
|
|
|
-//import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource
|
|
|
-//import org.springframework.transaction.interceptor.RollbackRuleAttribute
|
|
|
-//import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute
|
|
|
-//import org.springframework.transaction.interceptor.TransactionInterceptor
|
|
|
-//
|
|
|
-//
|
|
|
-///**
|
|
|
-// * 事务配置 支持动态数据源
|
|
|
-// * @author NorthLan at 2018/1/31
|
|
|
-// */
|
|
|
-//@Configuration
|
|
|
-//class TransactionalConfig {
|
|
|
-// companion object {
|
|
|
-// private const val CUSTOMIZE_TRANSACTION_INTERCEPTOR_NAME = "customizeTransactionInterceptor"
|
|
|
-// private const val DATA_SOURCE_SWITCH_METHOD_INTERCEPTOR_NAME = "dataSourceSwitchMethodInterceptor"
|
|
|
-// /**
|
|
|
-// * 默认只对 "*Service" , "*ServiceImpl" Bean 进行事务处理,"*"表示模糊匹配, 比如 : userService,orderServiceImpl
|
|
|
-// */
|
|
|
-// private val DEFAULT_TRANSACTION_BEAN_NAMES = arrayOf("*Service", "*ServiceImpl", "*Mapper")
|
|
|
-// /**
|
|
|
-// * 可传播事务配置
|
|
|
-// */
|
|
|
-// private val DEFAULT_REQUIRED_METHOD_RULE_TRANSACTION_ATTRIBUTES = arrayOf(
|
|
|
-// "add*",
|
|
|
-// "save*",
|
|
|
-// "insert*",
|
|
|
-// "delete*",
|
|
|
-// "update*",
|
|
|
-// "edit*",
|
|
|
-// "batch*",
|
|
|
-// "create*",
|
|
|
-// "remove*"
|
|
|
-// )
|
|
|
-// /**
|
|
|
-// * 默认的只读事务
|
|
|
-// */
|
|
|
-// private val DEFAULT_READ_ONLY_METHOD_RULE_TRANSACTION_ATTRIBUTES = arrayOf(
|
|
|
-// "get*",
|
|
|
-// "count*",
|
|
|
-// "find*",
|
|
|
-// "query*",
|
|
|
-// "select*",
|
|
|
-// "list*",
|
|
|
-// "*"
|
|
|
-// )
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 自定义事务 BeanName 拦截
|
|
|
-// */
|
|
|
-// private val customizeTransactionBeanNames = arrayOf<String>()
|
|
|
-// /**
|
|
|
-// * 自定义方法名的事务属性相关联,可以使用通配符(*)字符关联相同的事务属性的设置方法; 只读事务
|
|
|
-// */
|
|
|
-// private val customizeReadOnlyMethodRuleTransactionAttributes = arrayOf<String>()
|
|
|
-// /**
|
|
|
-// * 自定义方法名的事务属性相关联,可以使用通配符(*)字符关联相同的事务属性的设置方法;
|
|
|
-// * 传播事务(默认的)[org.springframework.transaction.annotation.Propagation.REQUIRED]
|
|
|
-// */
|
|
|
-// private val customizeRequiredMethodRuleTransactionAttributes = arrayOf<String>()
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 配置事务拦截器
|
|
|
-// * @param platformTransactionManager 事务管理器
|
|
|
-// */
|
|
|
-// @Bean(CUSTOMIZE_TRANSACTION_INTERCEPTOR_NAME)
|
|
|
-// fun customizeTransactionInterceptor(platformTransactionManager: PlatformTransactionManager): TransactionInterceptor {
|
|
|
-// val transactionAttributeSource = NameMatchTransactionAttributeSource()
|
|
|
-// val readOnly = this.readOnlyTransactionRule()
|
|
|
-// val required = this.requiredTransactionRule()
|
|
|
-// // 默认的只读事务配置
|
|
|
-// for (methodName in DEFAULT_READ_ONLY_METHOD_RULE_TRANSACTION_ATTRIBUTES) {
|
|
|
-// transactionAttributeSource.addTransactionalMethod(methodName, readOnly)
|
|
|
-// }
|
|
|
-// // 默认的传播事务配置
|
|
|
-// for (methodName in DEFAULT_REQUIRED_METHOD_RULE_TRANSACTION_ATTRIBUTES) {
|
|
|
-// transactionAttributeSource.addTransactionalMethod(methodName, required)
|
|
|
-// }
|
|
|
-// // 定制的只读事务配置
|
|
|
-// for (methodName in customizeReadOnlyMethodRuleTransactionAttributes) {
|
|
|
-// transactionAttributeSource.addTransactionalMethod(methodName, readOnly)
|
|
|
-// }
|
|
|
-// // 定制的传播事务配置
|
|
|
-// for (methodName in customizeRequiredMethodRuleTransactionAttributes) {
|
|
|
-// transactionAttributeSource.addTransactionalMethod(methodName, required)
|
|
|
-// }
|
|
|
-// return TransactionInterceptor(platformTransactionManager, transactionAttributeSource)
|
|
|
-// }
|
|
|
-//
|
|
|
-//// @Bean
|
|
|
-//// fun aspectJExpressionPointcutAdvisor(@Qualifier(CUSTOMIZE_TRANSACTION_INTERCEPTOR_NAME) transactionInterceptor: TransactionInterceptor): AspectJExpressionPointcutAdvisor {
|
|
|
-//// return AspectJExpressionPointcutAdvisor().also {
|
|
|
-//// it.advice = transactionInterceptor
|
|
|
-//// it.expression = "execution (* com.gxzc.zen.api..*Service.*(..))"
|
|
|
-//// }
|
|
|
-//// }
|
|
|
-//
|
|
|
-//// @Bean
|
|
|
-//// fun beanNameAutoProxyCreator(): BeanNameAutoProxyCreator {
|
|
|
-//// return BeanNameAutoProxyCreator().also {
|
|
|
-//// it.setInterceptorNames(DATA_SOURCE_SWITCH_METHOD_INTERCEPTOR_NAME,
|
|
|
-//// CUSTOMIZE_TRANSACTION_INTERCEPTOR_NAME)
|
|
|
-//// // 归集
|
|
|
-//// it.setBeanNames(*arrayListOf<String>().also {
|
|
|
-//// it.addAll(DEFAULT_TRANSACTION_BEAN_NAMES) // 默认
|
|
|
-//// it.addAll(customizeTransactionBeanNames) // 定制
|
|
|
-//// }.toTypedArray())
|
|
|
-//// it.isProxyTargetClass = true
|
|
|
-//// }
|
|
|
-//// }
|
|
|
-////
|
|
|
-//// @Bean(DATA_SOURCE_SWITCH_METHOD_INTERCEPTOR_NAME)
|
|
|
-//// fun dataSourceSwitchMethodInterceptor(): DataSourceSwitchMethodInterceptor {
|
|
|
-//// return DataSourceSwitchMethodInterceptor()
|
|
|
-//// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 支持当前事务
|
|
|
-// * 如果不存在创建一个新的
|
|
|
-// */
|
|
|
-// private fun requiredTransactionRule(): RuleBasedTransactionAttribute {
|
|
|
-// return RuleBasedTransactionAttribute().also {
|
|
|
-// it.rollbackRules = arrayListOf(RollbackRuleAttribute(Exception::class.java))
|
|
|
-// it.propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRED
|
|
|
-// it.timeout = TransactionDefinition.TIMEOUT_DEFAULT
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 只读事务
|
|
|
-// */
|
|
|
-// private fun readOnlyTransactionRule(): RuleBasedTransactionAttribute {
|
|
|
-// return RuleBasedTransactionAttribute().also {
|
|
|
-// it.isReadOnly = true
|
|
|
-// it.propagationBehavior = TransactionDefinition.PROPAGATION_NOT_SUPPORTED
|
|
|
-// }
|
|
|
-// }
|
|
|
-//}
|