DATAREDIS-547 - Polishing.

Return empty list if offset is greater than the available data set. Update supported keywords in reference docs.

Original pull request: #216.
This commit is contained in:
Mark Paluch
2016-09-12 14:27:18 +02:00
parent a93f81f043
commit 6280bd20b9
4 changed files with 52 additions and 3 deletions

View File

@@ -540,6 +540,7 @@ Here's an overview of the keywords supported for Redis and what a method contain
|`And`|`findByLastnameAndFirstname`|`SINTER …:firstname:rand …:lastname:althor`
|`Or`|`findByLastnameOrFirstname`|`SUNION …:firstname:rand …:lastname:althor`
|`Is,Equals`|`findByFirstname`,`findByFirstnameIs`,`findByFirstnameEquals`|`SINTER …:firstname:rand`
|`Top,First`|`findFirst10ByFirstname`,`findTop5ByFirstname`|
|===============
====

View File

@@ -17,6 +17,7 @@ package org.springframework.data.redis.core;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -357,6 +358,11 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
List<byte[]> keys = new ArrayList<byte[]>(ids);
if (keys.isEmpty() || keys.size() < offset) {
return Collections.emptyList();
}
offset = Math.max(0, offset);
if (offset >= 0 && rows > 0) {
keys = keys.subList(offset, Math.min(offset + rows, keys.size()));

View File

@@ -102,7 +102,7 @@ class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationC
final Map<byte[], Map<byte[], byte[]>> rawData = new LinkedHashMap<byte[], Map<byte[], byte[]>>();
if (allKeys.size() == 0 || allKeys.size() < offset) {
if (allKeys.isEmpty() || allKeys.size() < offset) {
return Collections.emptyMap();
}

View File

@@ -47,6 +47,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
* Base for testing Redis repository support in different configurations.
*
* @author Christoph Strobl
* @author Mark Paluch
*/
public abstract class RedisRepositoryIntegrationTestBase {
@@ -202,8 +203,49 @@ public abstract class RedisRepositoryIntegrationTestBase {
repo.save(Arrays.asList(eddard, robb, jon));
Page<Person> firstPage = repo.findAll(new PageRequest(0, 2));
assertThat(firstPage.getContent(), hasSize(2));
assertThat(repo.findAll(firstPage.nextPageable()).getContent(), hasSize(1));
assertThat(firstPage.getContent(), hasSize(2));
assertThat(repo.findAll(firstPage.nextPageable()).getContent(), hasSize(1));
}
/**
* @see DATAREDIS-547
*/
@Test
public void shouldReturnEmptyListWhenPageableOutOfBoundsUsingFindAll() {
Person eddard = new Person("eddard", "stark");
Person robb = new Person("robb", "stark");
Person jon = new Person("jon", "snow");
repo.save(Arrays.asList(eddard, robb, jon));
Page<Person> firstPage = repo.findAll(new PageRequest(100, 2));
assertThat(firstPage.getContent(), hasSize(0));
}
/**
* @see DATAREDIS-547
*/
@Test
public void shouldReturnEmptyListWhenPageableOutOfBoundsUsingQueryMethod() {
Person eddard = new Person("eddard", "stark");
Person robb = new Person("robb", "stark");
Person sansa = new Person("sansa", "stark");
repo.save(Arrays.asList(eddard, robb, sansa));
Page<Person> page1 = repo.findPersonByLastname("stark", new PageRequest(1, 3));
assertThat(page1.getNumberOfElements(), is(0));
assertThat(page1.getContent(), hasSize(0));
assertThat(page1.getTotalElements(), is(3L));
Page<Person> page2 = repo.findPersonByLastname("stark", new PageRequest(2, 3));
assertThat(page2.getNumberOfElements(), is(0));
assertThat(page2.getContent(), hasSize(0));
assertThat(page2.getTotalElements(), is(3L));
}
/**