Search in sources :

Example 6 with TransactionAttribute

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

the class AnnotationTransactionAttributeSourceTests method transactionAttributeDeclaredOnClassMethodWithEjb3.

@Test
public void transactionAttributeDeclaredOnClassMethodWithEjb3() throws Exception {
    Method getAgeMethod = ITestBean.class.getMethod("getAge");
    Method getNameMethod = ITestBean.class.getMethod("getName");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, Ejb3AnnotatedBean1.class);
    assertEquals(TransactionAttribute.PROPAGATION_REQUIRED, getAgeAttr.getPropagationBehavior());
    TransactionAttribute getNameAttr = atas.getTransactionAttribute(getNameMethod, Ejb3AnnotatedBean1.class);
    assertEquals(TransactionAttribute.PROPAGATION_SUPPORTS, getNameAttr.getPropagationBehavior());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 7 with TransactionAttribute

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

the class AnnotationTransactionAttributeSourceTests method transactionAttributeDeclaredOnClassWithJta.

@Test
public void transactionAttributeDeclaredOnClassWithJta() throws Exception {
    Method getAgeMethod = ITestBean.class.getMethod("getAge");
    Method getNameMethod = ITestBean.class.getMethod("getName");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, JtaAnnotatedBean2.class);
    assertEquals(TransactionAttribute.PROPAGATION_REQUIRED, getAgeAttr.getPropagationBehavior());
    TransactionAttribute getNameAttr = atas.getTransactionAttribute(getNameMethod, JtaAnnotatedBean2.class);
    assertEquals(TransactionAttribute.PROPAGATION_SUPPORTS, getNameAttr.getPropagationBehavior());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 8 with TransactionAttribute

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

the class AnnotationTransactionAttributeSourceTests method transactionAttributeDeclaredOnInterfaceWithEjb3.

@Test
public void transactionAttributeDeclaredOnInterfaceWithEjb3() throws Exception {
    Method getAgeMethod = ITestEjb.class.getMethod("getAge");
    Method getNameMethod = ITestEjb.class.getMethod("getName");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute getAgeAttr = atas.getTransactionAttribute(getAgeMethod, Ejb3AnnotatedBean3.class);
    assertEquals(TransactionAttribute.PROPAGATION_REQUIRED, getAgeAttr.getPropagationBehavior());
    TransactionAttribute getNameAttr = atas.getTransactionAttribute(getNameMethod, Ejb3AnnotatedBean3.class);
    assertEquals(TransactionAttribute.PROPAGATION_SUPPORTS, getNameAttr.getPropagationBehavior());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 9 with TransactionAttribute

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

the class AnnotationTransactionAttributeSourceTests method transactionAttributeDeclaredOnClassMethod.

/**
	 * Test the important case where the invocation is on a proxied interface method
	 * but the attribute is defined on the target class.
	 */
@Test
public void transactionAttributeDeclaredOnClassMethod() throws Exception {
    Method classMethod = ITestBean.class.getMethod("getAge");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(classMethod, TestBean1.class);
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
}
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) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with TransactionAttribute

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

the class AnnotationTransactionAttributeSourceTests method rollbackRulesAreApplied.

@Test
public void rollbackRulesAreApplied() throws Exception {
    Method method = TestBean3.class.getMethod("getAge");
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean3.class);
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute("java.lang.Exception"));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
    assertTrue(actual.rollbackOn(new Exception()));
    assertFalse(actual.rollbackOn(new IOException()));
    actual = atas.getTransactionAttribute(method, method.getDeclaringClass());
    rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute("java.lang.Exception"));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
    assertTrue(actual.rollbackOn(new Exception()));
    assertFalse(actual.rollbackOn(new IOException()));
}
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

TransactionAttribute (org.springframework.transaction.interceptor.TransactionAttribute)23 Method (java.lang.reflect.Method)21 Test (org.junit.Test)21 RuleBasedTransactionAttribute (org.springframework.transaction.interceptor.RuleBasedTransactionAttribute)19 IOException (java.io.IOException)11 NoRollbackRuleAttribute (org.springframework.transaction.interceptor.NoRollbackRuleAttribute)11 RollbackRuleAttribute (org.springframework.transaction.interceptor.RollbackRuleAttribute)11 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)2 GroovyObject (groovy.lang.GroovyObject)1 DataSource (javax.sql.DataSource)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 ResourceDatabasePopulator (org.springframework.jdbc.datasource.init.ResourceDatabasePopulator)1 ITestBean (org.springframework.tests.sample.beans.ITestBean)1 AnnotationTransactionAttributeSource (org.springframework.transaction.annotation.AnnotationTransactionAttributeSource)1 DefaultTransactionAttribute (org.springframework.transaction.interceptor.DefaultTransactionAttribute)1 TransactionAttributeSource (org.springframework.transaction.interceptor.TransactionAttributeSource)1 TransactionInterceptor (org.springframework.transaction.interceptor.TransactionInterceptor)1