use of cn.taketoday.transaction.interceptor.NoRollbackRuleAttribute in project today-infrastructure by TAKETODAY.
the class JtaTransactionAnnotationParser method parseTransactionAnnotation.
protected TransactionAttribute parseTransactionAnnotation(MergedAnnotation<Transactional> attributes) {
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
rbta.setPropagationBehaviorName(RuleBasedTransactionAttribute.PREFIX_PROPAGATION + attributes.getEnum("value", Transactional.TxType.class).toString());
List<RollbackRuleAttribute> rollbackRules = new ArrayList<>();
for (Class<?> rbRule : attributes.getClassArray("rollbackOn")) {
rollbackRules.add(new RollbackRuleAttribute(rbRule));
}
for (Class<?> rbRule : attributes.getClassArray("dontRollbackOn")) {
rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
}
rbta.setRollbackRules(rollbackRules);
return rbta;
}
use of cn.taketoday.transaction.interceptor.NoRollbackRuleAttribute in project today-infrastructure by TAKETODAY.
the class AnnotationTransactionAttributeSourceTests method transactionAttributeOnTargetClassMethodOverridesAttributeOnInterfaceMethod.
/**
* Test that when an attribute exists on both class and interface, class takes precedence.
*/
@Test
public void transactionAttributeOnTargetClassMethodOverridesAttributeOnInterfaceMethod() throws Exception {
Method interfaceMethod = ITestBean3.class.getMethod("getAge");
Method interfaceMethod2 = ITestBean3.class.getMethod("setAge", int.class);
Method interfaceMethod3 = ITestBean3.class.getMethod("getName");
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
atas.setEmbeddedValueResolver(strVal -> ("${myTimeout}".equals(strVal) ? "5" : strVal));
TransactionAttribute actual = atas.getTransactionAttribute(interfaceMethod, TestBean3.class);
assertThat(actual.getPropagationBehavior()).isEqualTo(TransactionAttribute.PROPAGATION_REQUIRES_NEW);
assertThat(actual.getIsolationLevel()).isEqualTo(TransactionAttribute.ISOLATION_REPEATABLE_READ);
assertThat(actual.getTimeout()).isEqualTo(5);
assertThat(actual.isReadOnly()).isTrue();
TransactionAttribute actual2 = atas.getTransactionAttribute(interfaceMethod2, TestBean3.class);
assertThat(actual2.getPropagationBehavior()).isEqualTo(TransactionAttribute.PROPAGATION_REQUIRES_NEW);
assertThat(actual2.getIsolationLevel()).isEqualTo(TransactionAttribute.ISOLATION_REPEATABLE_READ);
assertThat(actual2.getTimeout()).isEqualTo(5);
assertThat(actual2.isReadOnly()).isTrue();
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
assertThat(((RuleBasedTransactionAttribute) actual).getRollbackRules()).isEqualTo(rbta.getRollbackRules());
TransactionAttribute actual3 = atas.getTransactionAttribute(interfaceMethod3, TestBean3.class);
assertThat(actual3.getPropagationBehavior()).isEqualTo(TransactionAttribute.PROPAGATION_REQUIRED);
}
use of cn.taketoday.transaction.interceptor.NoRollbackRuleAttribute in project today-infrastructure by TAKETODAY.
the class AnnotationTransactionAttributeSourceTests method customClassAttributeDetected.
@Test
public void customClassAttributeDetected() throws Exception {
Method method = TestBean5.class.getMethod("getAge");
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean5.class);
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
assertThat(((RuleBasedTransactionAttribute) actual).getRollbackRules()).isEqualTo(rbta.getRollbackRules());
}
use of cn.taketoday.transaction.interceptor.NoRollbackRuleAttribute in project today-infrastructure by TAKETODAY.
the class AnnotationTransactionAttributeSourceTests method customMethodAttributeDetected.
@Test
public void customMethodAttributeDetected() throws Exception {
Method method = TestBean6.class.getMethod("getAge");
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean6.class);
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
assertThat(((RuleBasedTransactionAttribute) actual).getRollbackRules()).isEqualTo(rbta.getRollbackRules());
}
use of cn.taketoday.transaction.interceptor.NoRollbackRuleAttribute in project today-infrastructure by TAKETODAY.
the class AnnotationTransactionAttributeSourceTests method customClassAttributeWithReadOnlyOverrideDetected.
@Test
public void customClassAttributeWithReadOnlyOverrideDetected() throws Exception {
Method method = TestBean7.class.getMethod("getAge");
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean7.class);
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
assertThat(((RuleBasedTransactionAttribute) actual).getRollbackRules()).isEqualTo(rbta.getRollbackRules());
assertThat(actual.isReadOnly()).isTrue();
}
Aggregations