Extend transaction attributes with labels
TransactionAttribute now exposes a labels attribute that associates a descriptive array of labels with a transaction. Labels may be of a pure descriptive nature or may get evaluated by transaction managers to associate technology-specific behavior with the actual transaction.
This commit is contained in:
committed by
Juergen Hoeller
parent
3e736898a6
commit
2aa8aef216
@@ -45,6 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Colin Sampaleanu
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class AnnotationTransactionAttributeSourceTests {
|
||||
|
||||
@@ -183,6 +184,21 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||
assertThat(actual.rollbackOn(new IOException())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void labelsAreApplied() throws Exception {
|
||||
Method method = TestBean11.class.getMethod("getAge");
|
||||
|
||||
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
||||
TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean11.class);
|
||||
|
||||
assertThat(actual.getLabels()).containsOnly("retryable", "long-running");
|
||||
|
||||
method = TestBean11.class.getMethod("setAge", Integer.TYPE);
|
||||
actual = atas.getTransactionAttribute(method, method.getDeclaringClass());
|
||||
|
||||
assertThat(actual.getLabels()).containsOnly("short-running");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that transaction attribute is inherited from class
|
||||
* if not specified on method.
|
||||
@@ -693,6 +709,21 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(label = {"retryable", "long-running"})
|
||||
static class TestBean11 {
|
||||
|
||||
private int age = 10;
|
||||
|
||||
@Transactional(label = "short-running")
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Ejb3AnnotatedBean1 implements ITestBean1 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user