Now I've adapted the method computeTransactionAttribute from class AbstractFallbackTransactionAttributeSource like the following:
Code:
private TransactionAttribute computeTransactionAttribute(Method method,
Class targetClass) {
// The method may be on an interface, but we need attributes from the
// target class. The AopUtils class provides a convenience method for
// this. If the target class is null, the method will be unchanged.
Method specificMethod = AopUtils.getMostSpecificMethod(method,
targetClass);
// First try is the method in the target class
TransactionAttribute txAtt = findTransactionAttribute(findAllAttributes(specificMethod));
if (txAtt != null)
return txAtt;
// Second try is the transaction attribute on the target class
txAtt = findTransactionAttribute(findAllAttributes(specificMethod
.getDeclaringClass()));
if (txAtt != null)
return txAtt;
if (specificMethod != method) {
// Fallback is to look at the original method
txAtt = findTransactionAttribute(findAllAttributes(method));
if (txAtt != null)
return txAtt;
// Fallback is the class of the original method
txAtt = findTransactionAttribute(findAllAttributes(method
.getDeclaringClass()));
if (txAtt != null)
return txAtt;
}
Class[] interfaces = method.getDeclaringClass().getInterfaces();
if (AopUtils.methodIsOnOneOfTheseInterfaces(method, interfaces)) {
Method interfaceMethod = null;
for (int i = 0; interfaceMethod == null && i < interfaces.length; i++) {
try {
interfaceMethod = interfaces[i].getMethod(method
.getName(), method.getParameterTypes());
} catch (SecurityException e) {
} catch (NoSuchMethodException e) {
}
}
if (interfaceMethod != null) {
// Fallback is to look at the declared method on interface
txAtt = findTransactionAttribute(findAllAttributes(interfaceMethod));
if (txAtt != null)
return txAtt;
// Last fallback is the interface of the method
return findTransactionAttribute(findAllAttributes(interfaceMethod
.getDeclaringClass()));
}
}
return null;
}
With the help of this modification it is also possible to define Attributes only in interfaces. I think this would be nice to have this modification in class AbstractFallbackTransactionAttributeSource. What's your opinion?
Cheers,
Martin