introspect superclass when given a CGLIB proxy as target class (SPR-7448); use generic Class<?> in TransactionAttributeSource signature

This commit is contained in:
Juergen Hoeller
2010-08-11 21:47:50 +00:00
parent 8a23ce917a
commit 99733aef2a
5 changed files with 42 additions and 20 deletions

View File

@@ -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.
*/

View File

@@ -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);
}
}