Skip to content

Commit 3aeff66

Browse files
schaudermp911de
authored andcommitted
DATACOUCH-650 - Implements CrudRepository and ReactiveCrudRepository.deleteById(Iterable<ID> ids).
Original pull request: #279.
1 parent 6052851 commit 3aeff66

File tree

5 files changed

+85
-18
lines changed

5 files changed

+85
-18
lines changed

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<properties>
2121
<couchbase>3.0.9</couchbase>
2222
<couchbase.osgi>3.0.9</couchbase.osgi>
23-
<springdata.commons>2.5.0-SNAPSHOT</springdata.commons>
23+
<springdata.commons>2.4.0-DATACMNS-800-SNAPSHOT</springdata.commons>
2424
<java-module-name>spring.data.couchbase</java-module-name>
2525
</properties>
2626

@@ -161,6 +161,12 @@
161161
<scope>test</scope>
162162
</dependency>
163163

164+
<dependency>
165+
<groupId>io.projectreactor</groupId>
166+
<artifactId>reactor-test</artifactId>
167+
<scope>test</scope>
168+
</dependency>
169+
164170
<!-- Kotlin extension -->
165171
<dependency>
166172
<groupId>org.jetbrains.kotlin</groupId>

src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
*
4343
* @author Michael Nitschinger
4444
* @author Mark Paluch
45+
* @author Jens Schauder
4546
*/
4647
public class SimpleCouchbaseRepository<T, ID> implements CouchbaseRepository<T, ID> {
4748

@@ -130,6 +131,12 @@ public void deleteAll(final Iterable<? extends T> entities) {
130131
couchbaseOperations.removeById().all(Streamable.of(entities).map(entityInformation::getId).toList());
131132
}
132133

134+
@Override
135+
public void deleteAllById(Iterable<? extends ID> ids) {
136+
Assert.notNull(ids, "The given Iterable of ids must not be null!");
137+
couchbaseOperations.removeById().all(Streamable.of(ids).map(Objects::toString).toList());
138+
}
139+
133140
@Override
134141
public long count() {
135142
return couchbaseOperations.findByQuery(entityInformation.getJavaType()).consistentWith(buildQueryScanConsistency())

src/main/java/org/springframework/data/couchbase/repository/support/SimpleReactiveCouchbaseRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @author Christoph Strobl
4545
* @author David Kelly
4646
* @author Douglas Six
47+
* @author Jens Schauder
4748
* @since 3.0
4849
*/
4950
public class SimpleReactiveCouchbaseRepository<T, ID> implements ReactiveCouchbaseRepository<T, ID> {
@@ -185,6 +186,11 @@ public Mono<Void> deleteAll(final Publisher<? extends T> entityStream) {
185186
return Flux.from(entityStream).flatMap(this::delete).single();
186187
}
187188

189+
@Override
190+
public Mono<Void> deleteAllById(final Iterable<? extends ID> ids) {
191+
return operations.removeById().all(Streamable.of(ids).map(Object::toString).toList()).then();
192+
}
193+
188194
@SuppressWarnings("unchecked")
189195
@Override
190196
public Mono<Long> count() {

src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.data.couchbase.repository;
1818

19+
import static java.util.Arrays.*;
20+
import static org.assertj.core.api.Assertions.*;
1921
import static org.junit.jupiter.api.Assertions.*;
2022

2123
import java.util.ArrayList;
@@ -26,6 +28,7 @@
2628
import java.util.concurrent.ExecutorService;
2729
import java.util.concurrent.Executors;
2830
import java.util.concurrent.Future;
31+
import java.util.stream.Collectors;
2932

3033
import org.junit.jupiter.api.BeforeEach;
3134
import org.junit.jupiter.api.Test;
@@ -47,6 +50,7 @@
4750
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
4851
import org.springframework.data.couchbase.util.ClusterType;
4952
import org.springframework.data.couchbase.util.IgnoreWhen;
53+
import org.springframework.data.util.StreamUtils;
5054
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5155

5256
import com.couchbase.client.core.error.IndexExistsException;
@@ -56,6 +60,7 @@
5660
*
5761
* @author Michael Nitschinger
5862
* @author Michael Reiche
63+
* @author Jens Schauder
5964
*/
6065
@SpringJUnitConfig(CouchbaseRepositoryQueryIntegrationTests.Config.class)
6166
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
@@ -170,7 +175,7 @@ void count() {
170175
airportRepository.save(airport);
171176
}
172177

173-
Long count = airportRepository.countFancyExpression(Arrays.asList("JFK"), Arrays.asList("jfk"), false);
178+
Long count = airportRepository.countFancyExpression(asList("JFK"), asList("jfk"), false);
174179
assertEquals(1, count);
175180

176181
long airportCount = airportRepository.count();
@@ -277,6 +282,25 @@ void threadSafeStringParametersTest() throws Exception {
277282
}
278283
}
279284

285+
@Test // DATACOUCH-650
286+
void deleteAllById() {
287+
288+
Airport vienna = new Airport("airports::vie", "vie", "LOWW");
289+
Airport frankfurt = new Airport("airports::fra", "fra", "EDDF");
290+
Airport losAngeles = new Airport("airports::lax", "lax", "KLAX");
291+
292+
try {
293+
airportRepository.saveAll(asList(vienna, frankfurt, losAngeles));
294+
295+
airportRepository.deleteAllById(asList(vienna.getId(), losAngeles.getId()));
296+
297+
298+
assertThat(airportRepository.findAll()).containsExactly(frankfurt);
299+
} finally {
300+
airportRepository.deleteAll();
301+
}
302+
}
303+
280304
private void sleep(int millis) {
281305
try {
282306
Thread.sleep(millis); // so they are executed out-of-order

src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryQueryIntegrationTests.java

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@
1616

1717
package org.springframework.data.couchbase.repository;
1818

19-
import static org.junit.jupiter.api.Assertions.*;
20-
21-
import java.util.List;
22-
import java.util.concurrent.Callable;
23-
import java.util.concurrent.ExecutorService;
24-
import java.util.concurrent.Executors;
25-
import java.util.concurrent.Future;
26-
import java.util.stream.Collectors;
27-
19+
import com.couchbase.client.core.error.IndexExistsException;
2820
import org.junit.jupiter.api.BeforeEach;
2921
import org.junit.jupiter.api.Test;
3022
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,8 +35,18 @@
4335
import org.springframework.data.couchbase.util.ClusterType;
4436
import org.springframework.data.couchbase.util.IgnoreWhen;
4537
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
38+
import reactor.test.StepVerifier;
4639

47-
import com.couchbase.client.core.error.IndexExistsException;
40+
import java.util.List;
41+
import java.util.concurrent.Callable;
42+
import java.util.concurrent.ExecutorService;
43+
import java.util.concurrent.Executors;
44+
import java.util.concurrent.Future;
45+
import java.util.stream.Collectors;
46+
47+
import static java.util.Arrays.*;
48+
import static org.assertj.core.api.Assertions.*;
49+
import static org.junit.jupiter.api.Assertions.*;
4850

4951
/**
5052
* template class for Reactive Couchbase operations
@@ -56,10 +58,13 @@
5658
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
5759
public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegrationTests {
5860

59-
@Autowired CouchbaseClientFactory clientFactory;
61+
@Autowired
62+
CouchbaseClientFactory clientFactory;
6063

61-
@Autowired ReactiveAirportRepository airportRepository; // intellij flags "Could not Autowire", but it runs ok.
62-
@Autowired ReactiveUserRepository userRepository; // intellij flags "Could not Autowire", but it runs ok.
64+
@Autowired
65+
ReactiveAirportRepository airportRepository; // intellij flags "Could not Autowire", but it runs ok.
66+
@Autowired
67+
ReactiveUserRepository userRepository; // intellij flags "Could not Autowire", but it runs ok.
6368

6469
@BeforeEach
6570
void beforeEach() {
@@ -93,9 +98,9 @@ void findBySimpleProperty() {
9398
vie = new Airport("airports::vie", "vie", "loww");
9499
airportRepository.save(vie).block();
95100
List<Airport> airports1 = airportRepository.findAllByIata("vie").collectList().block();
96-
assertEquals(1,airports1.size());
101+
assertEquals(1, airports1.size());
97102
List<Airport> airports2 = airportRepository.findAllByIata("vie").collectList().block();
98-
assertEquals(1,airports2.size());
103+
assertEquals(1, airports2.size());
99104
} finally {
100105
airportRepository.delete(vie).block();
101106
}
@@ -114,7 +119,7 @@ public void testCas() {
114119

115120
@Test
116121
void count() {
117-
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
122+
String[] iatas = {"JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX"};
118123
Future[] future = new Future[iatas.length];
119124
ExecutorService executorService = Executors.newFixedThreadPool(iatas.length);
120125
try {
@@ -148,6 +153,25 @@ void count() {
148153
}
149154
}
150155

156+
@Test
157+
// DATACOUCH-650
158+
void deleteAllById() {
159+
160+
Airport vienna = new Airport("airports::vie", "vie", "LOWW");
161+
Airport frankfurt = new Airport("airports::fra", "fra", "EDDF");
162+
Airport losAngeles = new Airport("airports::lax", "lax", "KLAX");
163+
164+
try {
165+
airportRepository.saveAll(asList(vienna, frankfurt, losAngeles)).as(StepVerifier::create).verifyComplete();
166+
167+
airportRepository.deleteAllById(asList(vienna.getId(), losAngeles.getId())).as(StepVerifier::create).verifyComplete();
168+
169+
airportRepository.findAll().as(StepVerifier::create).expectNext(frankfurt).verifyComplete();
170+
} finally {
171+
airportRepository.deleteAll();
172+
}
173+
}
174+
151175
@Configuration
152176
@EnableReactiveCouchbaseRepositories("org.springframework.data.couchbase")
153177
static class Config extends AbstractCouchbaseConfiguration {

0 commit comments

Comments
 (0)