Skip to content

Commit c0ead79

Browse files
committed
DATAKV-330 - Polishing.
Reorder methods. Original pull request: #52.
1 parent 54c7603 commit c0ead79

File tree

2 files changed

+55
-42
lines changed

2 files changed

+55
-42
lines changed

src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.springframework.util.Assert;
3131

3232
/**
33+
* Simple {@link KeyValueRepository} implementation.
34+
*
3335
* @author Christoph Strobl
3436
* @author Oliver Gierke
3537
* @author Mark Paluch
@@ -58,38 +60,9 @@ public SimpleKeyValueRepository(EntityInformation<T, ID> metadata, KeyValueOpera
5860
this.operations = operations;
5961
}
6062

61-
/*
62-
* (non-Javadoc)
63-
* @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort)
64-
*/
65-
@Override
66-
public Iterable<T> findAll(Sort sort) {
67-
68-
Assert.notNull(sort, "Sort must not be null!");
69-
70-
return operations.findAll(sort, entityInformation.getJavaType());
71-
}
72-
73-
/*
74-
* (non-Javadoc)
75-
* @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Pageable)
76-
*/
77-
@Override
78-
public Page<T> findAll(Pageable pageable) {
79-
80-
Assert.notNull(pageable, "Pageable must not be null!");
81-
82-
if (pageable.isUnpaged()) {
83-
List<T> result = findAll();
84-
return new PageImpl<>(result, Pageable.unpaged(), result.size());
85-
}
86-
87-
Iterable<T> content = operations.findInRange(pageable.getOffset(), pageable.getPageSize(), pageable.getSort(),
88-
entityInformation.getJavaType());
89-
90-
return new PageImpl<>(IterableConverter.toList(content), pageable,
91-
this.operations.count(entityInformation.getJavaType()));
92-
}
63+
// -------------------------------------------------------------------------
64+
// Methods from CrudRepository
65+
// -------------------------------------------------------------------------
9366

9467
/*
9568
* (non-Javadoc)
@@ -204,6 +177,18 @@ public void delete(T entity) {
204177
deleteById(entityInformation.getRequiredId(entity));
205178
}
206179

180+
/*
181+
* (non-Javadoc)
182+
* @see org.springframework.data.repository.CrudRepository#deleteAllById(java.lang.Iterable)
183+
*/
184+
@Override
185+
public void deleteAllById(Iterable<? extends ID> ids) {
186+
187+
Assert.notNull(ids, "The given Iterable of Ids must not be null!");
188+
189+
ids.forEach(this::deleteById);
190+
}
191+
207192
/*
208193
* (non-Javadoc)
209194
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable)
@@ -216,20 +201,49 @@ public void deleteAll(Iterable<? extends T> entities) {
216201
entities.forEach(this::delete);
217202
}
218203

204+
/*
205+
* (non-Javadoc)
206+
* @see org.springframework.data.repository.CrudRepository#deleteAll()
207+
*/
219208
@Override
220-
public void deleteAllById(Iterable<? extends ID> ids) {
209+
public void deleteAll() {
210+
operations.delete(entityInformation.getJavaType());
211+
}
221212

222-
Assert.notNull(ids, "The given Iterable of Ids must not be null!");
213+
// -------------------------------------------------------------------------
214+
// Methods from PagingAndSortingRepository
215+
// -------------------------------------------------------------------------
223216

224-
ids.forEach(this::deleteById);
217+
/*
218+
* (non-Javadoc)
219+
* @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort)
220+
*/
221+
@Override
222+
public Iterable<T> findAll(Sort sort) {
223+
224+
Assert.notNull(sort, "Sort must not be null!");
225+
226+
return operations.findAll(sort, entityInformation.getJavaType());
225227
}
226228

227229
/*
228230
* (non-Javadoc)
229-
* @see org.springframework.data.repository.CrudRepository#deleteAll()
231+
* @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Pageable)
230232
*/
231233
@Override
232-
public void deleteAll() {
233-
operations.delete(entityInformation.getJavaType());
234+
public Page<T> findAll(Pageable pageable) {
235+
236+
Assert.notNull(pageable, "Pageable must not be null!");
237+
238+
if (pageable.isUnpaged()) {
239+
List<T> result = findAll();
240+
return new PageImpl<>(result, Pageable.unpaged(), result.size());
241+
}
242+
243+
Iterable<T> content = operations.findInRange(pageable.getOffset(), pageable.getPageSize(), pageable.getSort(),
244+
entityInformation.getJavaType());
245+
246+
return new PageImpl<>(IterableConverter.toList(content), pageable,
247+
this.operations.count(entityInformation.getJavaType()));
234248
}
235249
}

src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.keyvalue.repository;
1717

18-
import static java.util.Arrays.*;
1918
import static org.assertj.core.api.Assertions.*;
2019
import static org.mockito.ArgumentMatchers.*;
2120
import static org.mockito.Mockito.*;
@@ -96,7 +95,7 @@ public void multipleSave() {
9695
Foo one = new Foo("one");
9796
Foo two = new Foo("two");
9897

99-
repo.saveAll(asList(one, two));
98+
repo.saveAll(Arrays.asList(one, two));
10099
verify(opsMock, times(1)).insert(eq(one));
101100
verify(opsMock, times(1)).insert(eq(two));
102101
}
@@ -123,7 +122,7 @@ public void deleteById() {
123122
@Test // DATAKV-330
124123
public void deleteAllById() {
125124

126-
repo.deleteAllById(asList("one", "two"));
125+
repo.deleteAllById(Arrays.asList("one", "two"));
127126

128127
verify(opsMock, times(1)).delete(eq("one"), eq(Foo.class));
129128
verify(opsMock, times(1)).delete(eq("two"), eq(Foo.class));
@@ -142,7 +141,7 @@ public void deleteAll() {
142141
public void findAllIds() {
143142

144143
when(opsMock.findById(any(), any(Class.class))).thenReturn(Optional.empty());
145-
repo.findAllById(asList("one", "two", "three"));
144+
repo.findAllById(Arrays.asList("one", "two", "three"));
146145

147146
verify(opsMock, times(3)).findById(anyString(), eq(Foo.class));
148147
}

0 commit comments

Comments
 (0)