DATACMNS-33 - Adapted API changes for Repository.count().

Also changed return types for count() methods on JpaSpecificationExecutore and QueryDslPredicateExecutor.
This commit is contained in:
Oliver Gierke
2011-04-21 10:02:10 +02:00
parent 97859f5dee
commit 33a3c8f5ae
6 changed files with 13 additions and 14 deletions

View File

@@ -23,7 +23,6 @@ import javax.persistence.EntityManager;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.Repository;
import org.springframework.transaction.annotation.Transactional;
@@ -96,7 +95,7 @@ public interface JpaRepository<T, ID extends Serializable> extends
*
* @see org.springframework.data.repository.Repository#count()
*/
Long count();
long count();
/*

View File

@@ -78,5 +78,5 @@ public interface JpaSpecificationExecutor<T> {
* @param spec the {@link Specification} to count instances for
* @return the number of instances
*/
Long count(Specification<T> spec);
long count(Specification<T> spec);
}

View File

@@ -77,5 +77,5 @@ public interface QueryDslPredicateExecutor<T> {
* @param predicate the {@link Predicate} to count instances for
* @return the number of instances
*/
Long count(Predicate predicate);
long count(Predicate predicate);
}

View File

@@ -146,7 +146,7 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends
* @see org.springframework.data.jpa.repository.querydsl.
* QueryDslSpecificationExecutor#count(com.mysema.query.types.Predicate)
*/
public Long count(Predicate predicate) {
public long count(Predicate predicate) {
return createQuery(predicate).count();
}

View File

@@ -304,7 +304,7 @@ public class SimpleJpaRepository<T, ID extends Serializable> implements
*
* @see org.springframework.data.repository.Repository#count()
*/
public Long count() {
public long count() {
return em.createQuery(getCountQueryString(), Long.class)
.getSingleResult();
@@ -318,7 +318,7 @@ public class SimpleJpaRepository<T, ID extends Serializable> implements
* org.springframework.data.jpa.repository.JpaSpecificationExecutor#count
* (org.springframework.data.jpa.domain.Specification)
*/
public Long count(Specification<T> spec) {
public long count(Specification<T> spec) {
return getCountQuery(spec).getSingleResult();
}

View File

@@ -254,7 +254,7 @@ public class UserRepositoryTests {
private void assertDeleteCallDoesNotDeleteAnything(List<User> collection) {
flushTestUsers();
Long count = repository.count();
long count = repository.count();
repository.delete(collection);
assertEquals(count, repository.count());
@@ -267,9 +267,9 @@ public class UserRepositoryTests {
flushTestUsers();
repository.renameAllUsersTo("newLastname");
Integer expected = repository.count().intValue();
assertThat(repository.findByLastname("newLastname").size(),
is(expected));
long expected = repository.count();
assertThat(repository.findByLastname("newLastname").size(), is(Long
.valueOf(expected).intValue()));
}
@@ -349,7 +349,7 @@ public class UserRepositoryTests {
repository.deleteAll();
assertEquals((Long) 0L, repository.count());
assertEquals(0L, repository.count());
}
@@ -415,13 +415,13 @@ public class UserRepositoryTests {
@Test
public void testCountsCorrectly() {
Long count = repository.count();
long count = repository.count();
User user = new User();
user.setEmailAddress("gierke@synyx.de");
repository.save(user);
assertTrue(repository.count().equals(count + 1));
assertTrue(repository.count() == count + 1);
}