DATACMNS-715 - Repository factory now adds TransactionProxy interface if available.

We now leniently add the TransactionProxy marker interface to the repository proxy to opt-out of any further transaction handling potentially applied through @EnableTransactionManagement or its XML equivalent.

The interface will be introduced in Spring 4.1.7 / 4.2 RC2 so we're reflectively adding it if present. Might be something we can think of making less indirect for Fowler once 4.1.7 has been released.
This commit is contained in:
Oliver Gierke
2015-06-17 15:44:26 +02:00
parent b294bfce3b
commit 9eb4603503
2 changed files with 43 additions and 3 deletions

View File

@@ -60,6 +60,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware {
private static final boolean IS_JAVA_8 = org.springframework.util.ClassUtils.isPresent("java.util.Optional",
RepositoryFactorySupport.class.getClassLoader());
private static final Class<?> TRANSACTION_PROXY_TYPE = getTransactionProxyType();
private final Map<RepositoryInformationCacheKey, RepositoryInformation> repositoryInformationCache = new HashMap<RepositoryInformationCacheKey, RepositoryInformation>();
private final List<RepositoryProxyPostProcessor> postProcessors = new ArrayList<RepositoryProxyPostProcessor>();
@@ -187,6 +188,10 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware {
result.setTarget(target);
result.setInterfaces(new Class[] { repositoryInterface, Repository.class });
if (TRANSACTION_PROXY_TYPE != null) {
result.addInterface(TRANSACTION_PROXY_TYPE);
}
for (RepositoryProxyPostProcessor processor : postProcessors) {
processor.postProcess(result, information);
}
@@ -334,6 +339,21 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware {
return (R) BeanUtils.instantiateClass(constructor, constructorArguments);
}
/**
* Returns the TransactionProxy type or {@literal null} if not on the classpath.
*
* @return
*/
private static Class<?> getTransactionProxyType() {
try {
return org.springframework.util.ClassUtils
.forName("org.springframework.transaction.interceptor.TransactionalProxy", null);
} catch (ClassNotFoundException o_O) {
return null;
}
}
/**
* This {@code MethodInterceptor} intercepts calls to methods of the custom implementation and delegates the to it if
* configured. Furthermore it resolves method calls to finders and triggers execution of them. You can rely on having