use of org.springframework.transaction.interceptor.RuleBasedTransactionAttribute in project spring-framework by spring-projects.
the class SpringTransactionAnnotationParser method parseTransactionAnnotation.
protected TransactionAttribute parseTransactionAnnotation(AnnotationAttributes attributes) {
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
Propagation propagation = attributes.getEnum("propagation");
rbta.setPropagationBehavior(propagation.value());
Isolation isolation = attributes.getEnum("isolation");
rbta.setIsolationLevel(isolation.value());
rbta.setTimeout(attributes.getNumber("timeout").intValue());
String timeoutString = attributes.getString("timeoutString");
Assert.isTrue(!StringUtils.hasText(timeoutString) || rbta.getTimeout() < 0, "Specify 'timeout' or 'timeoutString', not both");
rbta.setTimeoutString(timeoutString);
rbta.setReadOnly(attributes.getBoolean("readOnly"));
rbta.setQualifier(attributes.getString("value"));
rbta.setLabels(Arrays.asList(attributes.getStringArray("label")));
List<RollbackRuleAttribute> rollbackRules = new ArrayList<>();
for (Class<?> rbRule : attributes.getClassArray("rollbackFor")) {
rollbackRules.add(new RollbackRuleAttribute(rbRule));
}
for (String rbRule : attributes.getStringArray("rollbackForClassName")) {
rollbackRules.add(new RollbackRuleAttribute(rbRule));
}
for (Class<?> rbRule : attributes.getClassArray("noRollbackFor")) {
rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
}
for (String rbRule : attributes.getStringArray("noRollbackForClassName")) {
rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
}
rbta.setRollbackRules(rollbackRules);
return rbta;
}
use of org.springframework.transaction.interceptor.RuleBasedTransactionAttribute in project spring-framework by spring-projects.
the class AnnotationTransactionAttributeSourceTests method defaultsToClassTransactionAttribute.
/**
* Test that transaction attribute is inherited from class
* if not specified on method.
*/
@Test
public void defaultsToClassTransactionAttribute() throws Exception {
Method method = TestBean4.class.getMethod("getAge");
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean4.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 org.springframework.transaction.interceptor.RuleBasedTransactionAttribute in project spring-framework by spring-projects.
the class AnnotationTransactionAttributeSourceTests method customClassAttributeWithReadOnlyOverrideOnInterface.
@Test
public void customClassAttributeWithReadOnlyOverrideOnInterface() throws Exception {
Method method = TestInterface9.class.getMethod("getAge");
Transactional annotation = AnnotationUtils.findAnnotation(method, Transactional.class);
assertThat(annotation).as("AnnotationUtils.findAnnotation should not find @Transactional for TestBean9.getAge()").isNull();
annotation = AnnotationUtils.findAnnotation(TestBean9.class, Transactional.class);
assertThat(annotation).as("AnnotationUtils.findAnnotation failed to find @Transactional for TestBean9").isNotNull();
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean9.class);
assertThat(actual).as("Failed to retrieve TransactionAttribute for TestBean9.getAge()").isNotNull();
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();
}
use of org.springframework.transaction.interceptor.RuleBasedTransactionAttribute in project spring-framework by spring-projects.
the class AnnotationTransactionAttributeSourceTests method transactionAttributeDeclaredOnInterfaceMethodOnly.
/**
* Test case where attribute is on the interface method.
*/
@Test
public void transactionAttributeDeclaredOnInterfaceMethodOnly() throws Exception {
Method interfaceMethod = ITestBean2.class.getMethod("getAge");
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
TransactionAttribute actual = atas.getTransactionAttribute(interfaceMethod, TestBean2.class);
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
assertThat(((RuleBasedTransactionAttribute) actual).getRollbackRules()).isEqualTo(rbta.getRollbackRules());
}
use of org.springframework.transaction.interceptor.RuleBasedTransactionAttribute in project spring-framework by spring-projects.
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());
}
Aggregations