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:
@@ -26,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -80,9 +81,8 @@ public class RepositoryFactorySupportUnitTests {
|
||||
|
||||
Mockito.reset(factory.strategy);
|
||||
|
||||
when(
|
||||
factory.strategy.resolveQuery(Mockito.any(Method.class), Mockito.any(RepositoryMetadata.class),
|
||||
Mockito.any(NamedQueries.class))).thenReturn(factory.queryOne, factory.queryTwo);
|
||||
when(factory.strategy.resolveQuery(Mockito.any(Method.class), Mockito.any(RepositoryMetadata.class),
|
||||
Mockito.any(NamedQueries.class))).thenReturn(factory.queryOne, factory.queryTwo);
|
||||
|
||||
factory.addQueryCreationListener(listener);
|
||||
factory.addQueryCreationListener(otherListener);
|
||||
@@ -223,6 +223,26 @@ public class RepositoryFactorySupportUnitTests {
|
||||
factory.addRepositoryProxyPostProcessor(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-715, SPR-13109
|
||||
*/
|
||||
@Test
|
||||
public void addsTransactionProxyInterfaceIfAvailable() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
Class<?> type = ClassUtils.forName("org.springframework.transaction.interceptor.TransactionalProxy", null);
|
||||
|
||||
SimpleRepository repository = factory.getRepository(SimpleRepository.class);
|
||||
assertThat(repository, is(instanceOf(type)));
|
||||
|
||||
} catch (ClassNotFoundException o_O) {
|
||||
Assume.assumeFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
interface SimpleRepository extends Repository<Object, Serializable> {}
|
||||
|
||||
interface ObjectRepository extends Repository<Object, Serializable>, ObjectRepositoryCustom {
|
||||
|
||||
Object findByClass(Class<?> clazz);
|
||||
|
||||
Reference in New Issue
Block a user