DATACMNS-656 - Make application of default transactions configurable on TrasnactionalRepositoryFactoryBeanSupport.

TrasnactionalRepositoryFactoryBeanSupport now exposes a setEnableDefaultTransactions(…) which, if disabled, causes the TransactionalRepositoryProxyPostProcessor not to be registered and thus no default transactions to be applied.

Related tickets: DATAJPA-685.
This commit is contained in:
Oliver Gierke
2015-03-10 19:11:06 +01:00
parent 57180568c5
commit d7adfbd859
4 changed files with 105 additions and 4 deletions

View File

@@ -134,7 +134,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware {
*/
public void addRepositoryProxyPostProcessor(RepositoryProxyPostProcessor processor) {
Assert.notNull(processor);
Assert.notNull(processor, "RepositoryProxyPostProcessor must not be null!");
this.postProcessors.add(processor);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2013 the original author or authors.
* Copyright 2008-2015 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.
@@ -38,6 +38,7 @@ public abstract class TransactionalRepositoryFactoryBeanSupport<T extends Reposi
private String transactionManagerName = TxUtils.DEFAULT_TRANSACTION_MANAGER;
private RepositoryProxyPostProcessor txPostProcessor;
private RepositoryProxyPostProcessor exceptionPostProcessor;
private boolean enableDefaultTransactions = true;
/**
* Setter to configure which transaction manager to be used. We have to use the bean name explicitly as otherwise the
@@ -50,6 +51,15 @@ public abstract class TransactionalRepositoryFactoryBeanSupport<T extends Reposi
this.transactionManagerName = transactionManager == null ? TxUtils.DEFAULT_TRANSACTION_MANAGER : transactionManager;
}
/**
* Configures whether to enable the default transactions configured at the repository base implementation class.
*
* @param enableDefaultTransactions the enableDefaultTransactions to set
*/
public void setEnableDefaultTransactions(boolean enableDefaultTransactions) {
this.enableDefaultTransactions = enableDefaultTransactions;
}
/**
* Delegates {@link RepositoryFactorySupport} creation to {@link #doCreateRepositoryFactory()} and applies the
* {@link TransactionalRepositoryProxyPostProcessor} to the created instance.
@@ -61,7 +71,11 @@ public abstract class TransactionalRepositoryFactoryBeanSupport<T extends Reposi
RepositoryFactorySupport factory = doCreateRepositoryFactory();
factory.addRepositoryProxyPostProcessor(exceptionPostProcessor);
factory.addRepositoryProxyPostProcessor(txPostProcessor);
if (enableDefaultTransactions) {
factory.addRepositoryProxyPostProcessor(txPostProcessor);
}
return factory;
}