DATAJPA-332 - Optimization for SimpleJpaRepository.findAll(…) taking Iterable.

We now shortcut the execution of SimpleJpaRepository.findAll(Iterable<Integer> ids) to return an empty collection in case no ids or null are given. Previously building a query with an IN clause failed with an empty parameter list given.
This commit is contained in:
Oliver Gierke
2013-04-19 10:29:52 +02:00
parent 4b1cd49079
commit edddb6dfb5
2 changed files with 16 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import static org.springframework.data.jpa.domain.sample.UserSpecifications.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -1049,6 +1050,16 @@ public class UserRepositoryTests {
assertThat(repository.countUsersByFirstname("Dave"), is(1));
}
/**
* @see DATAJPA-332
*/
@Test
public void findAllReturnsEmptyIterableIfNoIdsGiven() {
assertThat(repository.findAll(Collections.<Integer> emptySet()), is(emptyIterable()));
assertThat(repository.findAll((Iterable<Integer>) null), is(emptyIterable()));
}
private Page<User> executeSpecWithSort(Sort sort) {
flushTestUsers();