Skip to content

DATAGEODE-387 - Implement CrudRepository.delete(Iterable<ID> ids). #45

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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-geode-parent</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0-DATAGEODE-387-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data for Apache Geode Parent</name>
Expand Down Expand Up @@ -49,7 +49,7 @@
<log4j.version>2.12.1</log4j.version>
<multithreadedtc.version>1.01</multithreadedtc.version>
<snappy.version>0.4</snappy.version>
<springdata.commons>2.5.0-SNAPSHOT</springdata.commons>
<springdata.commons>2.4.0-DATACMNS-800-SNAPSHOT</springdata.commons>
<spring-shell.version>1.2.0.RELEASE</spring-shell.version>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-geode-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-geode-parent</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0-DATAGEODE-387-SNAPSHOT</version>
</parent>

<artifactId>spring-data-geode-distribution</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-geode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-geode-parent</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0-DATAGEODE-387-SNAPSHOT</version>
</parent>

<artifactId>spring-data-geode</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -310,6 +311,11 @@ public void deleteAll(@NonNull Iterable<? extends T> entities) {
CollectionUtils.nullSafeIterable(entities).forEach(this::delete);
}

@Override
public void deleteAllById(Iterable<? extends ID> ids) {
CollectionUtils.nullSafeIterable(ids).forEach(this::deleteById);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jxblum does it make sense to expose removeAll(…) on the Template API?

}

@Override
public void deleteById(@NonNull ID id) {
getTemplate().remove(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;

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

GemfireMappingContext mappingContext = new GemfireMappingContext();

GemfirePersistentEntity<Person> personEntity =
(GemfirePersistentEntity<Person>) mappingContext.getPersistentEntity(Person.class);
GemfirePersistentEntity<Person> personEntity = (GemfirePersistentEntity<Person>) mappingContext
.getPersistentEntity(Person.class);

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

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

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

List<Person> 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<Person> 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);

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

Page<Person> pageOne =
this.repository.findAll(PageRequest.of(0, 3, orderByFirstNameAscending));
Page<Person> pageOne = this.repository.findAll(PageRequest.of(0, 3, orderByFirstNameAscending));

assertThat(pageOne).isNotNull();
assertThat(pageOne).isNotEmpty();
Expand All @@ -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<Person> pageTwo =
this.repository.findAll(PageRequest.of(1, 3, Sort.by("firstname").ascending()));
Page<Person> pageTwo = this.repository.findAll(PageRequest.of(1, 3, Sort.by("firstname").ascending()));

assertThat(pageTwo).isNotNull();
assertThat(pageTwo).isNotEmpty();
Expand All @@ -166,17 +156,17 @@ public void findAllWithIds() {
this.template.put(carter.getId(), carter);
this.template.put(leroi.getId(), leroi);

Iterable<Person> result = this.repository.findAllById(Arrays.asList(carter.getId(), leroi.getId()));
Iterable<Person> 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<Person> results = this.repository.findAllById(Arrays.asList(1L, 2L));
Iterable<Person> results = this.repository.findAllById(asList(1L, 2L));

assertThat(results).isNotNull();
assertThat(results).isEmpty();
Expand All @@ -192,7 +182,7 @@ public void findAllWithIdsReturnsPartialMatches() {
this.template.put(kurt.getId(), kurt);
this.template.put(eddie.getId(), eddie);

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

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

SelectResults<Person> 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);
Expand All @@ -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<Person> 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() {

Expand All @@ -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);
Expand Down