Forward ported fix of Hades bug #421.
Moved transaction configuration into JpaRepository interface and redeclared methods of Repository and PagingAndSortingRepository. This is unfortunately necessary as otherwise the custom transaction configuration inside a user's repository interface (e.g. redefining transaction configuration in findAll()) would not be considered as AbstractFallbackTransactionAttributeSource prefers implementation configuration as this is usually more specific (except in our case). This unfortunately requires the redeclaration of the methods.
This commit is contained in:
@@ -15,10 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.config;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.custom.UserCustomExtendedRepository;
|
||||
import org.springframework.data.jpa.repository.support.TransactionalRepositoryTests.DelegatingTransactionManager;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -43,6 +48,16 @@ public class CustomRepositoryFactoryConfigTests {
|
||||
@Autowired(required = false)
|
||||
UserCustomExtendedRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
DelegatingTransactionManager transactionManager;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
transactionManager.resetCount();
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testCustomFactoryUsed() {
|
||||
@@ -50,4 +65,24 @@ public class CustomRepositoryFactoryConfigTests {
|
||||
Assert.notNull(userRepository);
|
||||
userRepository.customMethod(1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void reconfiguresTransactionalMethodWithoutGenericParameter() {
|
||||
|
||||
userRepository.findAll();
|
||||
|
||||
assertFalse(transactionManager.getDefinition().isReadOnly());
|
||||
assertThat(transactionManager.getDefinition().getTimeout(), is(10));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void reconfiguresTransactionalMethodWithGenericParameter() {
|
||||
|
||||
userRepository.findById(1);
|
||||
|
||||
assertFalse(transactionManager.getDefinition().isReadOnly());
|
||||
assertThat(transactionManager.getDefinition().getTimeout(), is(10));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.custom;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.domain.sample.User;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
/**
|
||||
@@ -27,4 +30,18 @@ import org.springframework.data.jpa.domain.sample.User;
|
||||
public interface UserCustomExtendedRepository extends
|
||||
CustomGenericRepository<User, Integer> {
|
||||
|
||||
/**
|
||||
* Sample method to test reconfiguring transactions on CRUD methods in
|
||||
* combination with custom factory.
|
||||
*
|
||||
* @see #421
|
||||
*/
|
||||
|
||||
@Transactional(readOnly = false, timeout = 10)
|
||||
List<User> findAll();
|
||||
|
||||
|
||||
@Transactional(readOnly = false, timeout = 10)
|
||||
User findById(Integer id);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user