Permalink
Browse files

DATACMNS-129 - Implement CrudRepository.findAll(Iterable<ID> ids).

  • Loading branch information...
1 parent 8a18cd4 commit f8daa69e535b6f1298b5d2fb354fe9403c5fe0e0 @olivergierke olivergierke committed Feb 2, 2012
@@ -20,7 +20,9 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
@@ -171,10 +173,23 @@ public void deleteAll() {
* @see org.springframework.data.repository.CrudRepository#findAll()
*/
public List<T> findAll() {
-
return findAll(new Query());
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable)
+ */
+ public Iterable<T> findAll(Iterable<ID> ids) {
+
+ Set<ID> parameters = new HashSet<ID>();
+ for (ID id : ids) {
+ parameters.add(id);
+ }
+
+ return findAll(new Query(new Criteria(entityInformation.getIdAttribute()).in(parameters)));
+ }
+
/*
* (non-Javadoc)
* @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Pageable)
@@ -91,6 +91,14 @@ public void findsAllMusicians() throws Exception {
}
@Test
+ public void findsAllWithGivenIds() {
+
+ Iterable<Person> result = repository.findAll(Arrays.asList(dave.id, boyd.id));
+ assertThat(result, hasItems(dave, boyd));
+ assertThat(result, not(hasItems(oliver, carter, stefan, leroi, alicia)));
+ }
+
+ @Test
public void deletesPersonCorrectly() throws Exception {
repository.delete(dave);

0 comments on commit f8daa69

Please sign in to comment.