本文整理汇总了Java中org.springframework.transaction.interceptor.TransactionAttributeSource类的典型用法代码示例。如果您正苦于以下问题:Java TransactionAttributeSource类的具体用法?Java TransactionAttributeSource怎么用?Java TransactionAttributeSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransactionAttributeSource类属于org.springframework.transaction.interceptor包,在下文中一共展示了TransactionAttributeSource类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransactionAttributeSource
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
@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;
}
};
}
示例2: setTxAdvice
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
/**
* 读取事务管理中的策略
*
* @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());
}
}
示例3: rollbackRules
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
@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()));
}
示例4: testRollbackRules
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
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()));
}
示例5: getTransactionAttributeSource
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
@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;
};
}
示例6: getTransactionAttributeSource
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
@Override
public TransactionAttributeSource getTransactionAttributeSource()
{
return attributes;
}
示例7: transactionAttributeSource
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionAttributeSource transactionAttributeSource() {
return new AnnotationTransactionAttributeSource();
}
示例8: getTransactionAttributeSource
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
public TransactionAttributeSource getTransactionAttributeSource() {
return transactionAttributeSource;
}
示例9: setTransactionAttributeSource
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
public void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource) {
this.transactionAttributeSource = transactionAttributeSource;
}
示例10: TransactionInterceptorEx
import org.springframework.transaction.interceptor.TransactionAttributeSource; //导入依赖的package包/类
protected TransactionInterceptorEx(Provider<PlatformTransactionManager> ptmp, TransactionAttributeSource tas) {
setTransactionAttributeSource(tas);
transactionManagerProvider = ptmp;
}