|
|
|
|
@ -8,6 +8,7 @@ import javax.sql.DataSource;
|
|
|
|
|
import org.springframework.aop.Advisor;
|
|
|
|
|
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
|
|
|
|
|
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
|
|
import org.springframework.transaction.TransactionDefinition;
|
|
|
|
|
import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource;
|
|
|
|
|
@ -30,6 +31,9 @@ public class AbstractTransaction {
|
|
|
|
|
this.dataSource = dataSource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Value("${spring.transaction.enabled:true}")
|
|
|
|
|
private boolean transactionEnabled;
|
|
|
|
|
|
|
|
|
|
protected DataSourceTransactionManager txManager() {
|
|
|
|
|
DataSourceTransactionManager bean = new DataSourceTransactionManager();
|
|
|
|
|
bean.setDataSource(getDataSource());
|
|
|
|
|
@ -48,10 +52,9 @@ public class AbstractTransaction {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
NameMatchTransactionAttributeSource txAttrSrc = new NameMatchTransactionAttributeSource();
|
|
|
|
|
txAttrSrc.setNameMap(Map.of(
|
|
|
|
|
"get*", read,
|
|
|
|
|
"*", write
|
|
|
|
|
));
|
|
|
|
|
txAttrSrc.setNameMap(
|
|
|
|
|
transactionEnabled ? Map.of("get*", read,"*", write) : Map.of("*", read)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
TransactionInterceptor bean = new TransactionInterceptor();
|
|
|
|
|
bean.setTransactionManager(txManager());
|
|
|
|
|
|