diff --git a/pom.xml b/pom.xml index dac0554f1..218dfa3a9 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.springframework.data spring-data-geode-parent - 2.5.0-SNAPSHOT + 2.5.0-DATAGEODE-387-SNAPSHOT pom Spring Data for Apache Geode Parent @@ -49,7 +49,7 @@ 2.12.1 1.01 0.4 - 2.5.0-SNAPSHOT + 2.4.0-DATACMNS-800-SNAPSHOT 1.2.0.RELEASE diff --git a/spring-data-geode-distribution/pom.xml b/spring-data-geode-distribution/pom.xml index 7cf0e5fb6..9038c41e2 100644 --- a/spring-data-geode-distribution/pom.xml +++ b/spring-data-geode-distribution/pom.xml @@ -8,7 +8,7 @@ org.springframework.data spring-data-geode-parent - 2.5.0-SNAPSHOT + 2.5.0-DATAGEODE-387-SNAPSHOT spring-data-geode-distribution diff --git a/spring-data-geode/pom.xml b/spring-data-geode/pom.xml index 0d582873c..f796d30b6 100644 --- a/spring-data-geode/pom.xml +++ b/spring-data-geode/pom.xml @@ -8,7 +8,7 @@ org.springframework.data spring-data-geode-parent - 2.5.0-SNAPSHOT + 2.5.0-DATAGEODE-387-SNAPSHOT spring-data-geode diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java index 37d034b78..8a4be1c15 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java @@ -60,6 +60,7 @@ * @author Oliver Gierke * @author David Turanski * @author John Blum + * @author Jens Schauder * @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.CacheTransactionManager * @see org.apache.geode.cache.Region @@ -310,6 +311,11 @@ public void deleteAll(@NonNull Iterable entities) { CollectionUtils.nullSafeIterable(entities).forEach(this::delete); } + @Override + public void deleteAllById(Iterable ids) { + CollectionUtils.nullSafeIterable(ids).forEach(this::deleteById); + } + @Override public void deleteById(@NonNull ID id) { getTemplate().remove(id); diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java index 7e629c793..ef523de08 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java @@ -15,24 +15,22 @@ */ package org.springframework.data.gemfire.repository.support; -import static org.assertj.core.api.Assertions.assertThat; +import static java.util.Arrays.*; +import static org.assertj.core.api.Assertions.*; -import java.util.Arrays; import java.util.Collections; import java.util.List; import javax.annotation.Resource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - import org.apache.geode.cache.GemFireCache; import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionEvent; import org.apache.geode.cache.query.SelectResults; import org.apache.geode.cache.util.CacheListenerAdapter; - +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.data.domain.Page; @@ -54,6 +52,7 @@ * * @author Oliver Gierke * @author John Blum + * @author Jens Schauder * @see org.junit.Test * @see org.apache.geode.cache.GemFireCache * @see org.apache.geode.cache.Region @@ -71,11 +70,9 @@ public class SimpleGemfireRepositoryIntegrationTests { static final String GEMFIRE_LOG_LEVEL = "warning"; - @Autowired - private GemfireTemplate template; + @Autowired private GemfireTemplate template; - @Resource(name = "People") - private Region people; + @Resource(name = "People") private Region people; private RegionClearListener regionClearListener; @@ -91,8 +88,8 @@ public void setUp() { GemfireMappingContext mappingContext = new GemfireMappingContext(); - GemfirePersistentEntity personEntity = - (GemfirePersistentEntity) mappingContext.getPersistentEntity(Person.class); + GemfirePersistentEntity personEntity = (GemfirePersistentEntity) mappingContext + .getPersistentEntity(Person.class); EntityInformation information = new PersistentEntityInformation<>(personEntity); @@ -114,13 +111,8 @@ public void findAllPaged() { assertThat(this.repository.count()).isEqualTo(0); - List people = Arrays.asList( - new Person(1L, "Jon", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Cookie", "Doe"), - new Person(4L, "Pie", "Doe"), - new Person(5L, "Sour", "Doe") - ); + List people = asList(new Person(1L, "Jon", "Doe"), new Person(2L, "Jane", "Doe"), + new Person(3L, "Cookie", "Doe"), new Person(4L, "Pie", "Doe"), new Person(5L, "Sour", "Doe")); people.forEach(person -> this.template.put(person.getId(), person)); @@ -128,8 +120,7 @@ public void findAllPaged() { Sort orderByFirstNameAscending = Sort.by("firstname").ascending(); - Page pageOne = - this.repository.findAll(PageRequest.of(0, 3, orderByFirstNameAscending)); + Page pageOne = this.repository.findAll(PageRequest.of(0, 3, orderByFirstNameAscending)); assertThat(pageOne).isNotNull(); assertThat(pageOne).isNotEmpty(); @@ -141,8 +132,7 @@ public void findAllPaged() { assertThat(pageOne.getTotalPages()).isEqualTo(2); assertThat(pageOne.getContent()).containsExactly(people.get(2), people.get(1), people.get(0)); - Page pageTwo = - this.repository.findAll(PageRequest.of(1, 3, Sort.by("firstname").ascending())); + Page pageTwo = this.repository.findAll(PageRequest.of(1, 3, Sort.by("firstname").ascending())); assertThat(pageTwo).isNotNull(); assertThat(pageTwo).isNotEmpty(); @@ -166,17 +156,17 @@ public void findAllWithIds() { this.template.put(carter.getId(), carter); this.template.put(leroi.getId(), leroi); - Iterable result = this.repository.findAllById(Arrays.asList(carter.getId(), leroi.getId())); + Iterable result = this.repository.findAllById(asList(carter.getId(), leroi.getId())); assertThat(result).isNotNull(); assertThat(result).hasSize(2); - assertThat(result).containsAll(Arrays.asList(carter, leroi)); + assertThat(result).containsAll(asList(carter, leroi)); } @Test public void findAllWithIdsReturnsNoMatches() { - Iterable results = this.repository.findAllById(Arrays.asList(1L, 2L)); + Iterable results = this.repository.findAllById(asList(1L, 2L)); assertThat(results).isNotNull(); assertThat(results).isEmpty(); @@ -192,7 +182,7 @@ public void findAllWithIdsReturnsPartialMatches() { this.template.put(kurt.getId(), kurt); this.template.put(eddie.getId(), eddie); - Iterable results = this.repository.findAllById(Arrays.asList(0L, 1L, 2L, 4L)); + Iterable results = this.repository.findAllById(asList(0L, 1L, 2L, 4L)); assertThat(results).isNotNull(); assertThat(results).hasSize(2); @@ -208,7 +198,7 @@ public void queryRegion() { assertThat(this.template.put(oliverGierke.getId(), oliverGierke)).isNull(); SelectResults people = this.template.find("SELECT * FROM /People p WHERE p.firstname = $1", - oliverGierke.getFirstname()); + oliverGierke.getFirstname()); assertThat(people.size()).isEqualTo(1); assertThat(people.iterator().next()).isEqualTo(oliverGierke); @@ -231,6 +221,26 @@ public void saveAndDeleteEntity() { assertThat(this.repository.findAll()).isEmpty(); } + @Test // DATAGEODE-387 + public void deleteAllById() { + + assertThat(this.repository.count()).isEqualTo(0); + + List people = asList(new Person(1L, "Jon", "Doe"), new Person(2L, "Jane", "Doe"), + new Person(3L, "Cookie", "Doe"), new Person(4L, "Pie", "Doe"), new Person(5L, "Sour", "Doe")); + + people.forEach(person -> this.template.put(person.getId(), person)); + + assertThat(this.repository.count()).isEqualTo(5); + + this.repository.deleteAllById(asList(1L, 2L)); + + assertThat(this.repository.count()).isEqualTo(3L); + assertThat(this.repository.findAll()) // + .extracting(Person::getFirstname) // + .containsExactlyInAnyOrder("Cookie", "Pie", "Sour"); + } + @Test public void saveEntities() { @@ -240,7 +250,7 @@ public void saveEntities() { Person jonBloom = new Person(2L, "Jon", "Bloom"); Person juanBlume = new Person(3L, "Juan", "Blume"); - this.repository.saveAll(Arrays.asList(johnBlum, jonBloom, juanBlume)); + this.repository.saveAll(asList(johnBlum, jonBloom, juanBlume)); assertThat(this.template.getRegion().size()).isEqualTo(3); assertThat((Person) this.template.get(johnBlum.getId())).isEqualTo(johnBlum);