Skip to content

Commit a41027c

Browse files
committed
Handle list argument for findById, deletedById.
Closes #1939.
1 parent 33bf8c8 commit a41027c

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
111111
.toArray(Class<?>[]::new);
112112
// the CouchbaseRepository methods - findById(id) etc - will have a parameter type of Object instead of ID
113113
if (method.getName().endsWith("ById") && args.length == 1) {
114-
paramTypes[0] = Object.class;
114+
// paramTypes[0] = Object.class;
115115
}
116116
}
117117

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public <S extends T> S save(S entity) {
7373
String scopeName = getScope();
7474
String collectionName = getCollection();
7575
// clear out the PseudoArgs here as whatever is called by operations.save() could be in a different thread.
76-
// not that this will also clear out Options, but that's ok as any options would not work
76+
// note that this will also clear out Options, but that's ok as any options would not work
7777
// with all of insert/upsert/replace. If Options are needed, use template.insertById/upsertById/replaceById
7878
getReactiveTemplate().setPseudoArgs(null);
7979
return operations.save(entity, scopeName, collectionName);
@@ -82,7 +82,13 @@ public <S extends T> S save(S entity) {
8282
@Override
8383
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
8484
Assert.notNull(entities, "The given Iterable of entities must not be null!");
85-
return Streamable.of(entities).stream().map((e) -> save(e)).collect(StreamUtils.toUnmodifiableList());
85+
String scopeName = getScope();
86+
String collectionName = getCollection();
87+
// clear out the PseudoArgs here as whatever is called by operations.save() could be in a different thread.
88+
// note that this will also clear out Options, but that's ok as any options would not work
89+
// with all of insert/upsert/replace. If Options are needed, use template.insertById/upsertById/replaceById
90+
getReactiveTemplate().setPseudoArgs(null);
91+
return Streamable.of(entities).stream().map((e) -> operations.save(e,scopeName, collectionName)).collect(StreamUtils.toUnmodifiableList());
8692
}
8793

8894
@Override

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public <S extends T> Mono<S> save(S entity) {
7777
String scopeName = getScope();
7878
String collectionName = getCollection();
7979
// clear out the PseudoArgs here as whatever is called by operations.save() could be in a different thread.
80-
// not that this will also clear out Options, but that's ok as any options would not work
80+
// note that this will also clear out Options, but that's ok as any options would not work
8181
// with all of insert/upsert/replace. If Options are needed, use template.insertById/upsertById/replaceById
8282
getReactiveTemplate().setPseudoArgs(null);
8383
return operations.save(entity, scopeName, collectionName);
@@ -88,6 +88,10 @@ public <S extends T> Flux<S> saveAll(Iterable<S> entities) {
8888
Assert.notNull(entities, "The given Iterable of entities must not be null!");
8989
String scope = getScope();
9090
String collection = getCollection();
91+
// clear out the PseudoArgs here as whatever is called by operations.save() could be in a different thread.
92+
// note that this will also clear out Options, but that's ok as any options would not work
93+
// with all of insert/upsert/replace. If Options are needed, use template.insertById/upsertById/replaceById
94+
getReactiveTemplate().setPseudoArgs(null);
9195
return Flux.fromIterable(entities).flatMap(e -> save(e, scope, collection));
9296
}
9397

@@ -96,6 +100,10 @@ public <S extends T> Flux<S> saveAll(Publisher<S> entityStream) {
96100
Assert.notNull(entityStream, "The given Iterable of entities must not be null!");
97101
String scope = getScope();
98102
String collection = getCollection();
103+
// clear out the PseudoArgs here as whatever is called by operations.save() could be in a different thread.
104+
// note that this will also clear out Options, but that's ok as any options would not work
105+
// with all of insert/upsert/replace. If Options are needed, use template.insertById/upsertById/replaceById
106+
getReactiveTemplate().setPseudoArgs(null);
99107
return Flux.from(entityStream).flatMap(e -> save(e, scope, collection));
100108
}
101109

src/test/java/org/springframework/data/couchbase/repository/query/CouchbaseRepositoryQueryCollectionIntegrationTests.java

+19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static com.couchbase.client.core.io.CollectionIdentifier.DEFAULT_SCOPE;
1919
import static com.couchbase.client.java.query.QueryScanConsistency.REQUEST_PLUS;
20+
import static java.util.Arrays.asList;
21+
import static org.assertj.core.api.Assertions.assertThat;
2022
import static org.junit.jupiter.api.Assertions.assertEquals;
2123
import static org.junit.jupiter.api.Assertions.assertThrows;
2224

@@ -443,4 +445,21 @@ void stringDeleteWithMethodAnnotationTest() {
443445
}
444446
}
445447

448+
449+
@Test
450+
// DATACOUCH-650
451+
void deleteAllById() {
452+
453+
Airport vienna = new Airport("airports::vie", "vie", "LOWW");
454+
Airport frankfurt = new Airport("airports::fra", "fra", "EDDZ");
455+
Airport losAngeles = new Airport("airports::lax", "lax", "KLAX");
456+
AirportRepository ar = airportRepository.withScope(scopeName).withCollection(collectionName);
457+
try {
458+
ar.saveAll(asList(vienna, frankfurt, losAngeles));
459+
ar.deleteAllById(asList(vienna.getId(), losAngeles.getId()));
460+
assertThat(ar.findAll()).containsExactly(frankfurt);
461+
} finally {
462+
ar.deleteAll();
463+
}
464+
}
446465
}

0 commit comments

Comments
 (0)