Java 类org.springframework.transaction.interceptor.TransactionAttributeSource 实例源码

项目:DynamicSpringTransactional    文件:DynamicTransactionInterceptor.java   
@Override
public TransactionAttributeSource getTransactionAttributeSource() {
    final TransactionAttributeSource origTxAttrSource = super.getTransactionAttributeSource();

    return new TransactionAttributeSource() {

        @Override
        public TransactionAttribute getTransactionAttribute(final Method method, final Class<?> targetClass) {
            TransactionAttribute txAttr = origTxAttrSource.getTransactionAttribute(method, targetClass);

            if (txAttr instanceof DefaultTransactionAttribute) {
                ((DefaultTransactionAttribute) txAttr).setQualifier(AuthContextUtils.getDomain());
            }

            return txAttr;
        }
    };
}
项目:spring-boot-starter-dynamic-datasource    文件:DataSourceAspect.java   
/**
 * 读取事务管理中的策略
 * 
 * @param txAdvice
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public void setTxAdvice(TransactionInterceptor txAdvice) throws Exception {
    if (txAdvice == null) {
        // 没有配置事务管理策略
        return;
    }
    // 从txAdvice获取到策略配置信息
    TransactionAttributeSource transactionAttributeSource = txAdvice.getTransactionAttributeSource();
    if (!(transactionAttributeSource instanceof NameMatchTransactionAttributeSource)) {
        return;
    }
    // 使用反射技术获取到NameMatchTransactionAttributeSource对象中的nameMap属性值
    NameMatchTransactionAttributeSource matchTransactionAttributeSource = (NameMatchTransactionAttributeSource) transactionAttributeSource;
    Field nameMapField = ReflectionUtils.findField(NameMatchTransactionAttributeSource.class, "nameMap");
    nameMapField.setAccessible(true); // 设置该字段可访问
    // 获取nameMap的值
    Map<String, TransactionAttribute> map = (Map<String, TransactionAttribute>) nameMapField.get(matchTransactionAttributeSource);

    // 遍历nameMap
    for (Map.Entry<String, TransactionAttribute> entry : map.entrySet()) {
        if (!entry.getValue().isReadOnly()) {// 判断之后定义了ReadOnly的策略才加入到slaveMethodPattern
            continue;
        }
        slaveMethodPattern.add(entry.getKey());
    }
}
项目:spring4-understanding    文件:TxNamespaceHandlerTests.java   
@Test
public void rollbackRules() {
    TransactionInterceptor txInterceptor = (TransactionInterceptor) context.getBean("txRollbackAdvice");
    TransactionAttributeSource txAttrSource = txInterceptor.getTransactionAttributeSource();
    TransactionAttribute txAttr = txAttrSource.getTransactionAttribute(getAgeMethod,ITestBean.class);
    assertTrue("should be configured to rollback on Exception",txAttr.rollbackOn(new Exception()));

    txAttr = txAttrSource.getTransactionAttribute(setAgeMethod, ITestBean.class);
    assertFalse("should not rollback on RuntimeException",txAttr.rollbackOn(new RuntimeException()));
}
项目:class-guard    文件:TxNamespaceHandlerTests.java   
public void testRollbackRules() {
    TransactionInterceptor txInterceptor = (TransactionInterceptor) context.getBean("txRollbackAdvice");
    TransactionAttributeSource txAttrSource = txInterceptor.getTransactionAttributeSource();
    TransactionAttribute txAttr = txAttrSource.getTransactionAttribute(getAgeMethod,ITestBean.class);
    assertTrue("should be configured to rollback on Exception",txAttr.rollbackOn(new Exception()));

    txAttr = txAttrSource.getTransactionAttribute(setAgeMethod, ITestBean.class);
    assertFalse("should not rollback on RuntimeException",txAttr.rollbackOn(new RuntimeException()));
}
项目:syncope    文件:DomainTransactionInterceptor.java   
@Override
public TransactionAttributeSource getTransactionAttributeSource() {
    final TransactionAttributeSource origTxAttrSource = super.getTransactionAttributeSource();

    return (final Method method, final Class<?> targetClass) -> {
        TransactionAttribute txAttr = origTxAttrSource.getTransactionAttribute(method, targetClass);

        if (txAttr instanceof DefaultTransactionAttribute) {
            ((DefaultTransactionAttribute) txAttr).setQualifier(AuthContextUtils.getDomain());
        }

        return txAttr;
    };
}
项目:Equella    文件:TLETransactionInterceptor.java   
@Override
public TransactionAttributeSource getTransactionAttributeSource()
{
    return attributes;
}
项目:lams    文件:ProxyTransactionManagementConfiguration.java   
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionAttributeSource transactionAttributeSource() {
    return new AnnotationTransactionAttributeSource();
}
项目:spring4-understanding    文件:ProxyTransactionManagementConfiguration.java   
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionAttributeSource transactionAttributeSource() {
    return new AnnotationTransactionAttributeSource();
}
项目:ldtm    文件:TransactionInterceptor.java   
public TransactionAttributeSource getTransactionAttributeSource() {
    return transactionAttributeSource;
}
项目:ldtm    文件:TransactionInterceptor.java   
public void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource) {
    this.transactionAttributeSource = transactionAttributeSource;
}
项目:dbflute-play-guice-java-example    文件:TransactionModule.java   
protected TransactionInterceptorEx(Provider<PlatformTransactionManager> ptmp, TransactionAttributeSource tas) {
    setTransactionAttributeSource(tas);
    transactionManagerProvider = ptmp;
}
项目:class-guard    文件:ProxyTransactionManagementConfiguration.java   
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionAttributeSource transactionAttributeSource() {
    return new AnnotationTransactionAttributeSource();
}