Skip to content

Commit 201de27

Browse files
committed
DATAGEODE-387 - Implement CrudRepository.delete(Iterable<ID> ids).
1 parent 8ead9d8 commit 201de27

File tree

2 files changed

+46
-30
lines changed

2 files changed

+46
-30
lines changed

spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
* @author Oliver Gierke
6161
* @author David Turanski
6262
* @author John Blum
63+
* @author Jens Schauder
6364
* @see org.apache.geode.cache.Cache
6465
* @see org.apache.geode.cache.CacheTransactionManager
6566
* @see org.apache.geode.cache.Region
@@ -310,6 +311,11 @@ public void deleteAll(@NonNull Iterable<? extends T> entities) {
310311
CollectionUtils.nullSafeIterable(entities).forEach(this::delete);
311312
}
312313

314+
@Override
315+
public void deleteAllById(Iterable<? extends ID> ids) {
316+
CollectionUtils.nullSafeIterable(ids).forEach(this::deleteById);
317+
}
318+
313319
@Override
314320
public void deleteById(@NonNull ID id) {
315321
getTemplate().remove(id);

spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,22 @@
1515
*/
1616
package org.springframework.data.gemfire.repository.support;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
18+
import static java.util.Arrays.*;
19+
import static org.assertj.core.api.Assertions.*;
1920

20-
import java.util.Arrays;
2121
import java.util.Collections;
2222
import java.util.List;
2323

2424
import javax.annotation.Resource;
2525

26-
import org.junit.Before;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
29-
3026
import org.apache.geode.cache.GemFireCache;
3127
import org.apache.geode.cache.Region;
3228
import org.apache.geode.cache.RegionEvent;
3329
import org.apache.geode.cache.query.SelectResults;
3430
import org.apache.geode.cache.util.CacheListenerAdapter;
35-
31+
import org.junit.Before;
32+
import org.junit.Test;
33+
import org.junit.runner.RunWith;
3634
import org.springframework.beans.factory.annotation.Autowired;
3735
import org.springframework.context.annotation.Bean;
3836
import org.springframework.data.domain.Page;
@@ -54,6 +52,7 @@
5452
*
5553
* @author Oliver Gierke
5654
* @author John Blum
55+
* @author Jens Schauder
5756
* @see org.junit.Test
5857
* @see org.apache.geode.cache.GemFireCache
5958
* @see org.apache.geode.cache.Region
@@ -71,11 +70,9 @@ public class SimpleGemfireRepositoryIntegrationTests {
7170

7271
static final String GEMFIRE_LOG_LEVEL = "warning";
7372

74-
@Autowired
75-
private GemfireTemplate template;
73+
@Autowired private GemfireTemplate template;
7674

77-
@Resource(name = "People")
78-
private Region<?, ?> people;
75+
@Resource(name = "People") private Region<?, ?> people;
7976

8077
private RegionClearListener regionClearListener;
8178

@@ -91,8 +88,8 @@ public void setUp() {
9188

9289
GemfireMappingContext mappingContext = new GemfireMappingContext();
9390

94-
GemfirePersistentEntity<Person> personEntity =
95-
(GemfirePersistentEntity<Person>) mappingContext.getPersistentEntity(Person.class);
91+
GemfirePersistentEntity<Person> personEntity = (GemfirePersistentEntity<Person>) mappingContext
92+
.getPersistentEntity(Person.class);
9693

9794
EntityInformation<Person, Long> information = new PersistentEntityInformation<>(personEntity);
9895

@@ -114,22 +111,16 @@ public void findAllPaged() {
114111

115112
assertThat(this.repository.count()).isEqualTo(0);
116113

117-
List<Person> people = Arrays.asList(
118-
new Person(1L, "Jon", "Doe"),
119-
new Person(2L, "Jane", "Doe"),
120-
new Person(3L, "Cookie", "Doe"),
121-
new Person(4L, "Pie", "Doe"),
122-
new Person(5L, "Sour", "Doe")
123-
);
114+
List<Person> people = asList(new Person(1L, "Jon", "Doe"), new Person(2L, "Jane", "Doe"),
115+
new Person(3L, "Cookie", "Doe"), new Person(4L, "Pie", "Doe"), new Person(5L, "Sour", "Doe"));
124116

125117
people.forEach(person -> this.template.put(person.getId(), person));
126118

127119
assertThat(this.repository.count()).isEqualTo(5);
128120

129121
Sort orderByFirstNameAscending = Sort.by("firstname").ascending();
130122

131-
Page<Person> pageOne =
132-
this.repository.findAll(PageRequest.of(0, 3, orderByFirstNameAscending));
123+
Page<Person> pageOne = this.repository.findAll(PageRequest.of(0, 3, orderByFirstNameAscending));
133124

134125
assertThat(pageOne).isNotNull();
135126
assertThat(pageOne).isNotEmpty();
@@ -141,8 +132,7 @@ public void findAllPaged() {
141132
assertThat(pageOne.getTotalPages()).isEqualTo(2);
142133
assertThat(pageOne.getContent()).containsExactly(people.get(2), people.get(1), people.get(0));
143134

144-
Page<Person> pageTwo =
145-
this.repository.findAll(PageRequest.of(1, 3, Sort.by("firstname").ascending()));
135+
Page<Person> pageTwo = this.repository.findAll(PageRequest.of(1, 3, Sort.by("firstname").ascending()));
146136

147137
assertThat(pageTwo).isNotNull();
148138
assertThat(pageTwo).isNotEmpty();
@@ -166,17 +156,17 @@ public void findAllWithIds() {
166156
this.template.put(carter.getId(), carter);
167157
this.template.put(leroi.getId(), leroi);
168158

169-
Iterable<Person> result = this.repository.findAllById(Arrays.asList(carter.getId(), leroi.getId()));
159+
Iterable<Person> result = this.repository.findAllById(asList(carter.getId(), leroi.getId()));
170160

171161
assertThat(result).isNotNull();
172162
assertThat(result).hasSize(2);
173-
assertThat(result).containsAll(Arrays.asList(carter, leroi));
163+
assertThat(result).containsAll(asList(carter, leroi));
174164
}
175165

176166
@Test
177167
public void findAllWithIdsReturnsNoMatches() {
178168

179-
Iterable<Person> results = this.repository.findAllById(Arrays.asList(1L, 2L));
169+
Iterable<Person> results = this.repository.findAllById(asList(1L, 2L));
180170

181171
assertThat(results).isNotNull();
182172
assertThat(results).isEmpty();
@@ -192,7 +182,7 @@ public void findAllWithIdsReturnsPartialMatches() {
192182
this.template.put(kurt.getId(), kurt);
193183
this.template.put(eddie.getId(), eddie);
194184

195-
Iterable<Person> results = this.repository.findAllById(Arrays.asList(0L, 1L, 2L, 4L));
185+
Iterable<Person> results = this.repository.findAllById(asList(0L, 1L, 2L, 4L));
196186

197187
assertThat(results).isNotNull();
198188
assertThat(results).hasSize(2);
@@ -208,7 +198,7 @@ public void queryRegion() {
208198
assertThat(this.template.put(oliverGierke.getId(), oliverGierke)).isNull();
209199

210200
SelectResults<Person> people = this.template.find("SELECT * FROM /People p WHERE p.firstname = $1",
211-
oliverGierke.getFirstname());
201+
oliverGierke.getFirstname());
212202

213203
assertThat(people.size()).isEqualTo(1);
214204
assertThat(people.iterator().next()).isEqualTo(oliverGierke);
@@ -231,6 +221,26 @@ public void saveAndDeleteEntity() {
231221
assertThat(this.repository.findAll()).isEmpty();
232222
}
233223

224+
@Test // DATAGEODE-387
225+
public void deleteAllById() {
226+
227+
assertThat(this.repository.count()).isEqualTo(0);
228+
229+
List<Person> people = asList(new Person(1L, "Jon", "Doe"), new Person(2L, "Jane", "Doe"),
230+
new Person(3L, "Cookie", "Doe"), new Person(4L, "Pie", "Doe"), new Person(5L, "Sour", "Doe"));
231+
232+
people.forEach(person -> this.template.put(person.getId(), person));
233+
234+
assertThat(this.repository.count()).isEqualTo(5);
235+
236+
this.repository.deleteAllById(asList(1L, 2L));
237+
238+
assertThat(this.repository.count()).isEqualTo(3L);
239+
assertThat(this.repository.findAll()) //
240+
.extracting(Person::getFirstname) //
241+
.containsExactlyInAnyOrder("Cookie", "Pie", "Sour");
242+
}
243+
234244
@Test
235245
public void saveEntities() {
236246

@@ -240,7 +250,7 @@ public void saveEntities() {
240250
Person jonBloom = new Person(2L, "Jon", "Bloom");
241251
Person juanBlume = new Person(3L, "Juan", "Blume");
242252

243-
this.repository.saveAll(Arrays.asList(johnBlum, jonBloom, juanBlume));
253+
this.repository.saveAll(asList(johnBlum, jonBloom, juanBlume));
244254

245255
assertThat(this.template.getRegion().size()).isEqualTo(3);
246256
assertThat((Person) this.template.get(johnBlum.getId())).isEqualTo(johnBlum);

0 commit comments

Comments
 (0)