introspect superclass when given a CGLIB proxy as target class (SPR-7448); use generic Class<?> in TransactionAttributeSource signature
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -95,6 +95,26 @@ public class AnnotationTransactionAttributeSourceTests {
|
||||
assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 testTransactionAttributeDeclaredOnCglibClassMethod() throws Exception {
|
||||
Method classMethod = ITestBean.class.getMethod("getAge", (Class[]) null);
|
||||
TestBean1 tb = new TestBean1();
|
||||
ProxyFactory pf = new ProxyFactory(tb);
|
||||
pf.setProxyTargetClass(true);
|
||||
Object proxy = pf.getProxy();
|
||||
|
||||
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
|
||||
TransactionAttribute actual = atas.getTransactionAttribute(classMethod, proxy.getClass());
|
||||
|
||||
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
|
||||
rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
|
||||
assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case where attribute is on the interface method.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,25 +27,25 @@ import java.util.Map;
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class MapTransactionAttributeSource extends AbstractFallbackTransactionAttributeSource {
|
||||
|
||||
/** Map from Method or Clazz to TransactionAttribute */
|
||||
private final Map attributeMap = new HashMap();
|
||||
|
||||
public void register(Method m, TransactionAttribute txAtt) {
|
||||
this.attributeMap.put(m, txAtt);
|
||||
|
||||
private final Map<Object, TransactionAttribute> attributeMap = new HashMap<Object, TransactionAttribute>();
|
||||
|
||||
|
||||
public void register(Method method, TransactionAttribute txAtt) {
|
||||
this.attributeMap.put(method, txAtt);
|
||||
}
|
||||
|
||||
|
||||
public void register(Class clazz, TransactionAttribute txAtt) {
|
||||
this.attributeMap.put(clazz, txAtt);
|
||||
}
|
||||
|
||||
|
||||
protected TransactionAttribute findTransactionAttribute(Method method) {
|
||||
return (TransactionAttribute) this.attributeMap.get(method);
|
||||
return this.attributeMap.get(method);
|
||||
}
|
||||
|
||||
protected TransactionAttribute findTransactionAttribute(Class clazz) {
|
||||
return (TransactionAttribute) this.attributeMap.get(clazz);
|
||||
return this.attributeMap.get(clazz);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user