Skip to content

Commit 5fd523c

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

File tree

2 files changed

+57
-28
lines changed

2 files changed

+57
-28
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: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,14 @@
1515
*/
1616
package org.springframework.data.gemfire.repository.support;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
20-
import java.util.Arrays;
21-
import java.util.Collections;
22-
import java.util.List;
23-
24-
import javax.annotation.Resource;
25-
26-
import org.junit.Before;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
29-
3018
import org.apache.geode.cache.GemFireCache;
3119
import org.apache.geode.cache.Region;
3220
import org.apache.geode.cache.RegionEvent;
3321
import org.apache.geode.cache.query.SelectResults;
3422
import org.apache.geode.cache.util.CacheListenerAdapter;
35-
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
3626
import org.springframework.beans.factory.annotation.Autowired;
3727
import org.springframework.context.annotation.Bean;
3828
import org.springframework.data.domain.Page;
@@ -49,11 +39,19 @@
4939
import org.springframework.test.context.ContextConfiguration;
5040
import org.springframework.test.context.junit4.SpringRunner;
5141

42+
import javax.annotation.Resource;
43+
import java.util.Collections;
44+
import java.util.List;
45+
46+
import static java.util.Arrays.*;
47+
import static org.assertj.core.api.Assertions.*;
48+
5249
/**
5350
* Integration Tests for {@link SimpleGemfireRepository}.
5451
*
5552
* @author Oliver Gierke
5653
* @author John Blum
54+
* @author Jens Schauder
5755
* @see org.junit.Test
5856
* @see org.apache.geode.cache.GemFireCache
5957
* @see org.apache.geode.cache.Region
@@ -92,7 +90,7 @@ public void setUp() {
9290
GemfireMappingContext mappingContext = new GemfireMappingContext();
9391

9492
GemfirePersistentEntity<Person> personEntity =
95-
(GemfirePersistentEntity<Person>) mappingContext.getPersistentEntity(Person.class);
93+
(GemfirePersistentEntity<Person>) mappingContext.getPersistentEntity(Person.class);
9694

9795
EntityInformation<Person, Long> information = new PersistentEntityInformation<>(personEntity);
9896

@@ -114,12 +112,12 @@ public void findAllPaged() {
114112

115113
assertThat(this.repository.count()).isEqualTo(0);
116114

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")
115+
List<Person> people = asList(
116+
new Person(1L, "Jon", "Doe"),
117+
new Person(2L, "Jane", "Doe"),
118+
new Person(3L, "Cookie", "Doe"),
119+
new Person(4L, "Pie", "Doe"),
120+
new Person(5L, "Sour", "Doe")
123121
);
124122

125123
people.forEach(person -> this.template.put(person.getId(), person));
@@ -129,7 +127,7 @@ public void findAllPaged() {
129127
Sort orderByFirstNameAscending = Sort.by("firstname").ascending();
130128

131129
Page<Person> pageOne =
132-
this.repository.findAll(PageRequest.of(0, 3, orderByFirstNameAscending));
130+
this.repository.findAll(PageRequest.of(0, 3, orderByFirstNameAscending));
133131

134132
assertThat(pageOne).isNotNull();
135133
assertThat(pageOne).isNotEmpty();
@@ -142,7 +140,7 @@ public void findAllPaged() {
142140
assertThat(pageOne.getContent()).containsExactly(people.get(2), people.get(1), people.get(0));
143141

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

147145
assertThat(pageTwo).isNotNull();
148146
assertThat(pageTwo).isNotEmpty();
@@ -166,17 +164,17 @@ public void findAllWithIds() {
166164
this.template.put(carter.getId(), carter);
167165
this.template.put(leroi.getId(), leroi);
168166

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

171169
assertThat(result).isNotNull();
172170
assertThat(result).hasSize(2);
173-
assertThat(result).containsAll(Arrays.asList(carter, leroi));
171+
assertThat(result).containsAll(asList(carter, leroi));
174172
}
175173

176174
@Test
177175
public void findAllWithIdsReturnsNoMatches() {
178176

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

181179
assertThat(results).isNotNull();
182180
assertThat(results).isEmpty();
@@ -192,7 +190,7 @@ public void findAllWithIdsReturnsPartialMatches() {
192190
this.template.put(kurt.getId(), kurt);
193191
this.template.put(eddie.getId(), eddie);
194192

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

197195
assertThat(results).isNotNull();
198196
assertThat(results).hasSize(2);
@@ -208,7 +206,7 @@ public void queryRegion() {
208206
assertThat(this.template.put(oliverGierke.getId(), oliverGierke)).isNull();
209207

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

213211
assertThat(people.size()).isEqualTo(1);
214212
assertThat(people.iterator().next()).isEqualTo(oliverGierke);
@@ -231,6 +229,31 @@ public void saveAndDeleteEntity() {
231229
assertThat(this.repository.findAll()).isEmpty();
232230
}
233231

232+
@Test // DATAGEODE-387
233+
public void deleteAllById() {
234+
235+
assertThat(this.repository.count()).isEqualTo(0);
236+
237+
List<Person> people = asList(
238+
new Person(1L, "Jon", "Doe"),
239+
new Person(2L, "Jane", "Doe"),
240+
new Person(3L, "Cookie", "Doe"),
241+
new Person(4L, "Pie", "Doe"),
242+
new Person(5L, "Sour", "Doe")
243+
);
244+
245+
people.forEach(person -> this.template.put(person.getId(), person));
246+
247+
assertThat(this.repository.count()).isEqualTo(5);
248+
249+
this.repository.deleteAllById(asList(1L, 2L));
250+
251+
assertThat(this.repository.count()).isEqualTo(3L);
252+
assertThat(this.repository.findAll()) //
253+
.extracting(Person::getFirstname) //
254+
.containsExactlyInAnyOrder("Cookie", "Pie", "Sour");
255+
}
256+
234257
@Test
235258
public void saveEntities() {
236259

@@ -240,7 +263,7 @@ public void saveEntities() {
240263
Person jonBloom = new Person(2L, "Jon", "Bloom");
241264
Person juanBlume = new Person(3L, "Juan", "Blume");
242265

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

245268
assertThat(this.template.getRegion().size()).isEqualTo(3);
246269
assertThat((Person) this.template.get(johnBlum.getId())).isEqualTo(johnBlum);

0 commit comments

Comments
 (0)