Search in sources :

Example 6 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute in project spring-framework by spring-projects.

the class JtaTransactionAnnotationParser method parseTransactionAnnotation.

protected TransactionAttribute parseTransactionAnnotation(AnnotationAttributes attributes) {
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.setPropagationBehaviorName(RuleBasedTransactionAttribute.PREFIX_PROPAGATION + attributes.getEnum("value").toString());
    ArrayList<RollbackRuleAttribute> rollBackRules = new ArrayList<>();
    Class<?>[] rbf = attributes.getClassArray("rollbackOn");
    for (Class<?> rbRule : rbf) {
        RollbackRuleAttribute rule = new RollbackRuleAttribute(rbRule);
        rollBackRules.add(rule);
    }
    Class<?>[] nrbf = attributes.getClassArray("dontRollbackOn");
    for (Class<?> rbRule : nrbf) {
        NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(rbRule);
        rollBackRules.add(rule);
    }
    rbta.getRollbackRules().addAll(rollBackRules);
    return rbta;
}
Also used : NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) ArrayList(java.util.ArrayList) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute)

Example 7 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute 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());
    rbta.setReadOnly(attributes.getBoolean("readOnly"));
    rbta.setQualifier(attributes.getString("value"));
    ArrayList<RollbackRuleAttribute> rollBackRules = new ArrayList<>();
    Class<?>[] rbf = attributes.getClassArray("rollbackFor");
    for (Class<?> rbRule : rbf) {
        RollbackRuleAttribute rule = new RollbackRuleAttribute(rbRule);
        rollBackRules.add(rule);
    }
    String[] rbfc = attributes.getStringArray("rollbackForClassName");
    for (String rbRule : rbfc) {
        RollbackRuleAttribute rule = new RollbackRuleAttribute(rbRule);
        rollBackRules.add(rule);
    }
    Class<?>[] nrbf = attributes.getClassArray("noRollbackFor");
    for (Class<?> rbRule : nrbf) {
        NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(rbRule);
        rollBackRules.add(rule);
    }
    String[] nrbfc = attributes.getStringArray("noRollbackForClassName");
    for (String rbRule : nrbfc) {
        NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(rbRule);
        rollBackRules.add(rule);
    }
    rbta.getRollbackRules().addAll(rollBackRules);
    return rbta;
}
Also used : NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) ArrayList(java.util.ArrayList) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute)

Example 8 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute in project spring-framework by spring-projects.

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("getName");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(interfaceMethod, TestBean3.class);
    assertEquals(TransactionAttribute.PROPAGATION_REQUIRES_NEW, actual.getPropagationBehavior());
    assertEquals(TransactionAttribute.ISOLATION_REPEATABLE_READ, actual.getIsolationLevel());
    assertEquals(5, actual.getTimeout());
    assertTrue(actual.isReadOnly());
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
    TransactionAttribute actual2 = atas.getTransactionAttribute(interfaceMethod2, TestBean3.class);
    assertEquals(TransactionAttribute.PROPAGATION_REQUIRED, actual2.getPropagationBehavior());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute 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);
    assertNull("AnnotationUtils.findAnnotation should not find @Transactional for TestBean9.getAge()", annotation);
    annotation = AnnotationUtils.findAnnotation(TestBean9.class, Transactional.class);
    assertNotNull("AnnotationUtils.findAnnotation failed to find @Transactional for TestBean9", annotation);
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean9.class);
    assertNotNull("Failed to retrieve TransactionAttribute for TestBean9.getAge()", actual);
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
    assertTrue(actual.isReadOnly());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with RollbackRuleAttribute

use of org.springframework.transaction.interceptor.RollbackRuleAttribute in project spring-framework by spring-projects.

the class AnnotationTransactionAttributeSourceTests method customMethodAttributeWithReadOnlyOverrideDetected.

@Test
public void customMethodAttributeWithReadOnlyOverrideDetected() throws Exception {
    Method method = TestBean8.class.getMethod("getAge");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean8.class);
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
    assertTrue(actual.isReadOnly());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

NoRollbackRuleAttribute (org.springframework.transaction.interceptor.NoRollbackRuleAttribute)15 RollbackRuleAttribute (org.springframework.transaction.interceptor.RollbackRuleAttribute)15 RuleBasedTransactionAttribute (org.springframework.transaction.interceptor.RuleBasedTransactionAttribute)14 IOException (java.io.IOException)11 Method (java.lang.reflect.Method)11 Test (org.junit.Test)11 TransactionAttribute (org.springframework.transaction.interceptor.TransactionAttribute)11 ArrayList (java.util.ArrayList)2 GroovyObject (groovy.lang.GroovyObject)1 LinkedList (java.util.LinkedList)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)1 ManagedMap (org.springframework.beans.factory.support.ManagedMap)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 Element (org.w3c.dom.Element)1