From b17f0bf363dd6ac847a1242ad564cfe18792a207 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 11 Mar 2011 18:18:38 +0100 Subject: [PATCH] =?UTF-8?q?DATACMNS-20=20-=20Adapted=20refactoring=20of=20?= =?UTF-8?q?findById(=E2=80=A6)=20to=20findOne(=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/jpa/repository/JpaRepository.java | 2 +- .../repository/support/SimpleJpaRepository.java | 4 ++-- .../repository/RoleRepositoryIntegrationTests.java | 2 +- .../data/jpa/repository/UserRepositoryTests.java | 14 +++++++------- .../config/CustomRepositoryFactoryConfigTests.java | 2 +- .../custom/UserCustomExtendedRepository.java | 2 +- .../data/jpa/repository/sample/UserRepository.java | 4 ++-- .../jpa/repository/support/JpaRepositoryTests.java | 2 +- .../support/TransactionalRepositoryTests.java | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java index d1bd120fd..fdb5fa702 100644 --- a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java @@ -70,7 +70,7 @@ public interface JpaRepository extends * org.springframework.data.repository.Repository#findById(java.io.Serializable * ) */ - T findById(ID id); + T findOne(ID id); /* diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 2ed04572f..4622f10a9 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -165,7 +165,7 @@ public class SimpleJpaRepository implements * org.springframework.data.repository.Repository#readById(java.io.Serializable * ) */ - public T findById(ID id) { + public T findOne(ID id) { Assert.notNull(id, "The given id must not be null!"); return em.find(getDomainClass(), id); @@ -182,7 +182,7 @@ public class SimpleJpaRepository implements public boolean exists(ID id) { Assert.notNull(id, "The given id must not be null!"); - return null != findById(id); + return null != findOne(id); } diff --git a/src/test/java/org/springframework/data/jpa/repository/RoleRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/RoleRepositoryIntegrationTests.java index 1374c7bed..0ff2fea60 100644 --- a/src/test/java/org/springframework/data/jpa/repository/RoleRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/RoleRepositoryIntegrationTests.java @@ -63,6 +63,6 @@ public class RoleRepositoryIntegrationTests { ReflectionTestUtils.setField(reference, "name", "USER"); repository.save(reference); - assertThat(repository.findById(result.getId()), is(reference)); + assertThat(repository.findOne(result.getId()), is(reference)); } } diff --git a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java index 8e5c5d901..f46886349 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -114,7 +114,7 @@ public class UserRepositoryTests { flushTestUsers(); - User foundPerson = repository.findById(id); + User foundPerson = repository.findOne(id); assertEquals(firstUser.getFirstname(), foundPerson.getFirstname()); } @@ -128,7 +128,7 @@ public class UserRepositoryTests { flushTestUsers(); - assertNull(repository.findById(id * 27)); + assertNull(repository.findOne(id * 27)); } @@ -170,10 +170,10 @@ public class UserRepositoryTests { flushTestUsers(); - User foundPerson = repository.findById(id); + User foundPerson = repository.findOne(id); foundPerson.setLastname("Schlicht"); - User updatedPerson = repository.findById(id); + User updatedPerson = repository.findOne(id); assertEquals(foundPerson.getFirstname(), updatedPerson.getFirstname()); } @@ -196,7 +196,7 @@ public class UserRepositoryTests { flushTestUsers(); repository.delete(firstUser); - assertNull(repository.findById(id)); + assertNull(repository.findOne(id)); } @@ -366,7 +366,7 @@ public class UserRepositoryTests { flushTestUsers(); // Fetches first user from database - User firstReferenceUser = repository.findById(firstUser.getId()); + User firstReferenceUser = repository.findOne(firstUser.getId()); assertEquals(firstUser, firstReferenceUser); // Fetch colleagues and assert link @@ -401,7 +401,7 @@ public class UserRepositoryTests { firstUser.addColleague(new User("Florian", "Hopf", "hopf@synyx.de")); firstUser = repository.save(firstUser); - User reference = repository.findById(firstUser.getId()); + User reference = repository.findOne(firstUser.getId()); Set colleagues = reference.getColleagues(); assertNotNull(colleagues); diff --git a/src/test/java/org/springframework/data/jpa/repository/config/CustomRepositoryFactoryConfigTests.java b/src/test/java/org/springframework/data/jpa/repository/config/CustomRepositoryFactoryConfigTests.java index 3d023d157..5d2eae09c 100644 --- a/src/test/java/org/springframework/data/jpa/repository/config/CustomRepositoryFactoryConfigTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/config/CustomRepositoryFactoryConfigTests.java @@ -80,7 +80,7 @@ public class CustomRepositoryFactoryConfigTests { @Test public void reconfiguresTransactionalMethodWithGenericParameter() { - userRepository.findById(1); + userRepository.findOne(1); assertFalse(transactionManager.getDefinition().isReadOnly()); assertThat(transactionManager.getDefinition().getTimeout(), is(10)); diff --git a/src/test/java/org/springframework/data/jpa/repository/custom/UserCustomExtendedRepository.java b/src/test/java/org/springframework/data/jpa/repository/custom/UserCustomExtendedRepository.java index 67ec1250d..44cbb99e7 100644 --- a/src/test/java/org/springframework/data/jpa/repository/custom/UserCustomExtendedRepository.java +++ b/src/test/java/org/springframework/data/jpa/repository/custom/UserCustomExtendedRepository.java @@ -42,6 +42,6 @@ public interface UserCustomExtendedRepository extends @Transactional(readOnly = false, timeout = 10) - User findById(Integer id); + User findOne(Integer id); } \ No newline at end of file diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java b/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java index 4534adce1..6fc0e7861 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java @@ -54,11 +54,11 @@ public interface UserRepository extends JpaRepository, /** - * Redeclaration of {@link Repository#findById(java.io.Serializable)} to + * Redeclaration of {@link Repository#findOne(java.io.Serializable)} to * change transaction configuration. */ @Transactional - public User findById(Integer primaryKey); + public User findOne(Integer primaryKey); /** diff --git a/src/test/java/org/springframework/data/jpa/repository/support/JpaRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/support/JpaRepositoryTests.java index 6b7abbdab..3f657e6d9 100644 --- a/src/test/java/org/springframework/data/jpa/repository/support/JpaRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/support/JpaRepositoryTests.java @@ -65,7 +65,7 @@ public class JpaRepositoryTests { SampleEntity entity = new SampleEntity("foo", "bar"); repository.saveAndFlush(entity); assertThat(repository.count(), is(1L)); - assertThat(repository.findById(new SampleEntityPK("foo", "bar")), + assertThat(repository.findOne(new SampleEntityPK("foo", "bar")), is(entity)); repository.delete(Arrays.asList(entity)); diff --git a/src/test/java/org/springframework/data/jpa/repository/support/TransactionalRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/support/TransactionalRepositoryTests.java index 39a29af45..6fae1d4d5 100644 --- a/src/test/java/org/springframework/data/jpa/repository/support/TransactionalRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/support/TransactionalRepositoryTests.java @@ -90,7 +90,7 @@ public class TransactionalRepositoryTests extends @Test public void invokeRedeclaredMethod() throws Exception { - repository.findById(1); + repository.findOne(1); assertFalse(transactionManager.getDefinition().isReadOnly()); }