Skip to content

Accept target type in KeyValueAdapter.entries(…) and getAllOf(…) #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-keyvalue</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0-GH-1995-SNAPSHOT</version>

<name>Spring Data KeyValue</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ public interface KeyValueAdapter extends DisposableBean {
*/
Iterable<?> getAllOf(String keyspace);

/**
* Get all elements for given keyspace.
*
* @param type must not be {@literal null}.
* @param keyspace must not be {@literal null}.
* @return empty {@link Collection} if nothing found.
* @since 2.5
*/
@SuppressWarnings("unchecked")
default <T> Iterable<T> getAllOf(String keyspace, Class<T> type) {
return (Iterable<T>) getAllOf(keyspace);
}

/**
* Returns a {@link CloseableIterator} that iterates over all entries.
*
Expand All @@ -110,6 +123,19 @@ public interface KeyValueAdapter extends DisposableBean {
*/
CloseableIterator<Map.Entry<Object, Object>> entries(String keyspace);

/**
* Returns a {@link CloseableIterator} that iterates over all entries.
*
* @param type must not be {@literal null}.
* @param keyspace must not be {@literal null}.
* @return
* @since 2.5
*/
@SuppressWarnings("unchecked")
default <T> CloseableIterator<Map.Entry<Object, T>> entries(String keyspace, Class<T> type) {
return (CloseableIterator) entries(keyspace);
}

/**
* Remove all objects of given type.
*
Expand All @@ -129,7 +155,9 @@ public interface KeyValueAdapter extends DisposableBean {
* @param keyspace must not be {@literal null}.
* @return empty {@link Collection} if no match found.
*/
Iterable<?> find(KeyValueQuery<?> query, String keyspace);
default Iterable<?> find(KeyValueQuery<?> query, String keyspace) {
return find(query, keyspace, Object.class);
}

/**
* @param query must not be {@literal null}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public <T> Iterable<T> findAll(Class<T> type) {

return executeRequired(adapter -> {

Iterable<?> values = adapter.getAllOf(resolveKeySpace(type));
Iterable<?> values = adapter.getAllOf(resolveKeySpace(type), type);

ArrayList<T> filtered = new ArrayList<>();
for (Object candidate : values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void findAllOfShouldReturnEntireCollection() {

template.findAll(Foo.class);

verify(adapterMock, times(1)).getAllOf(Foo.class.getName());
verify(adapterMock, times(1)).getAllOf(Foo.class.getName(), Foo.class);
}

@Test // DATACMNS-525
Expand Down Expand Up @@ -327,7 +327,7 @@ void insertShouldRespectTypeAliasOnSubClass() {
void findAllOfShouldRespectTypeAliasAndFilterNonMatchingTypes() {

Collection foo = Arrays.asList(ALIASED_USING_ALIAS_FOR, SUBCLASS_OF_ALIASED_USING_ALIAS_FOR);
when(adapterMock.getAllOf("aliased")).thenReturn(foo);
when(adapterMock.getAllOf("aliased", SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass())).thenReturn(foo);

assertThat((Iterable) template.findAll(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass()))
.contains(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR);
Expand Down