Skip to content

Commit cb073e7

Browse files
committed
Consider scope and collection from repository annotations.
The scope and collection from the repository annotation are associated with the method call by CrudMethodMetadataProcessor. This will also need #1445 to work. Closes #1441.
1 parent c6fa4ee commit cb073e7

12 files changed

+45
-11
lines changed

src/main/java/org/springframework/data/couchbase/core/ReactiveExistsByIdOperationSupport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ static class ReactiveExistsByIdSupport implements ReactiveExistsById {
7272
@Override
7373
public Mono<Boolean> one(final String id) {
7474
PseudoArgs<ExistsOptions> pArgs = new PseudoArgs<>(template, scope, collection, options, domainType);
75-
LOG.trace("existsById {}", pArgs);
75+
LOG.trace("existsById key={} {}", id, pArgs);
7676
return Mono.just(id)
7777
.flatMap(docId -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
7878
.getCollection(pArgs.getCollection()).reactive().exists(id, buildOptions(pArgs.getOptions()))

src/main/java/org/springframework/data/couchbase/core/ReactiveFindByIdOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public Mono<T> one(final String id) {
8080

8181
CommonOptions<?> gOptions = initGetOptions();
8282
PseudoArgs<?> pArgs = new PseudoArgs(template, scope, collection, gOptions, domainType);
83-
LOG.trace("findById {}", pArgs);
83+
LOG.trace("findById key={} {}", id, pArgs);
8484

8585
return Mono.just(id).flatMap(docId -> {
8686
ReactiveCollection reactive = template.getCouchbaseClientFactory().withScope(pArgs.getScope())

src/main/java/org/springframework/data/couchbase/core/ReactiveFindFromReplicasByIdOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Mono<T> any(final String id) {
7373
garOptions.transcoder(RawJsonTranscoder.INSTANCE);
7474
}
7575
PseudoArgs<GetAnyReplicaOptions> pArgs = new PseudoArgs<>(template, scope, collection, garOptions, domainType);
76-
LOG.trace("getAnyReplica {}", pArgs);
76+
LOG.trace("getAnyReplica key={} {}", id, pArgs);
7777
return Mono.just(id)
7878
.flatMap(docId -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
7979
.getCollection(pArgs.getCollection()).reactive().getAnyReplica(docId, pArgs.getOptions()))

src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static class ReactiveInsertByIdSupport<T> implements ReactiveInsertById<T> {
8080
@Override
8181
public Mono<T> one(T object) {
8282
PseudoArgs<InsertOptions> pArgs = new PseudoArgs(template, scope, collection, options, domainType);
83-
LOG.trace("insertById {}", pArgs);
83+
LOG.trace("insertById object={} {}", object, pArgs);
8484
return Mono.just(object).flatMap(support::encodeEntity)
8585
.flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
8686
.getCollection(pArgs.getCollection()).reactive()

src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static class ReactiveRemoveByIdSupport implements ReactiveRemoveById {
8181
@Override
8282
public Mono<RemoveResult> one(final String id) {
8383
PseudoArgs<RemoveOptions> pArgs = new PseudoArgs<>(template, scope, collection, options, domainType);
84-
LOG.trace("removeById {}", pArgs);
84+
LOG.trace("removeById key={} {}", id, pArgs);
8585
return Mono.just(id)
8686
.flatMap(docId -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
8787
.getCollection(pArgs.getCollection()).reactive().remove(id, buildRemoveOptions(pArgs.getOptions()))

src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static class ReactiveReplaceByIdSupport<T> implements ReactiveReplaceById<T> {
8080
@Override
8181
public Mono<T> one(T object) {
8282
PseudoArgs<ReplaceOptions> pArgs = new PseudoArgs<>(template, scope, collection, options, domainType);
83-
LOG.trace("replaceById {}", pArgs);
83+
LOG.trace("replaceById object={} {}", object, pArgs);
8484
return Mono.just(object).flatMap(support::encodeEntity)
8585
.flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
8686
.getCollection(pArgs.getCollection()).reactive()

src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static class ReactiveUpsertByIdSupport<T> implements ReactiveUpsertById<T> {
8080
@Override
8181
public Mono<T> one(T object) {
8282
PseudoArgs<UpsertOptions> pArgs = new PseudoArgs(template, scope, collection, options, domainType);
83-
LOG.trace("upsertById {}", pArgs);
83+
LOG.trace("upsertById object={} {}", object, pArgs);
8484
return Mono.just(object).flatMap(support::encodeEntity)
8585
.flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope())
8686
.getCollection(pArgs.getCollection()).reactive()

src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 the original author or authors.
2+
* Copyright 2021-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -177,7 +177,7 @@ public static RemoveOptions buildRemoveOptions(RemoveOptions options, PersistTo
177177
options.cas(cas);
178178
}
179179
if (LOG.isTraceEnabled()) {
180-
LOG.trace("remove options: {}" + toString(options));
180+
LOG.trace("remove options: {}", toString(options));
181181
}
182182
return options;
183183
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public void beforeEach() {
142142
super.beforeEach();
143143
couchbaseTemplate.removeByQuery(User.class).withConsistency(REQUEST_PLUS).all();
144144
couchbaseTemplate.findByQuery(User.class).withConsistency(REQUEST_PLUS).all();
145+
couchbaseTemplate.removeByQuery(Airport.class).withConsistency(REQUEST_PLUS).all();
146+
couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).all();
145147
}
146148

147149
@Test

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

+24
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,28 @@ void findPlusN1qlJoinUnannotated() throws Exception {
359359
}
360360
}
361361

362+
@Test
363+
void stringDeleteCollectionTest() {
364+
String key0 = loc();
365+
String key1 = loc();
366+
Airport airport = new Airport(loc(), "vie", "abc");
367+
Airport otherAirport = new Airport(loc(), "xxx", "xyz");
368+
try {
369+
airportRepository.withScope(scopeName).withCollection(collectionName).deleteById(airport.getId());
370+
} catch (DataRetrievalFailureException drfe) {}
371+
try {
372+
airportRepository.withScope(scopeName).withCollection(collectionName).deleteById(otherAirport.getId());
373+
} catch (DataRetrievalFailureException drfe) {}
374+
try {
375+
airportRepository.withScope(scopeName).withCollection(collectionName).save(airport);
376+
airportRepository.withScope(scopeName).withCollection(collectionName).save(otherAirport);
377+
assertEquals(1, airportRepository.withScope(scopeName).withCollection(collectionName).deleteByIata(airport.getIata()).size());
378+
} catch (Exception e) {
379+
e.printStackTrace();
380+
throw e;
381+
} finally {
382+
airportRepository.withScope(scopeName).withCollection(collectionName).deleteById(otherAirport.getId());
383+
}
384+
}
385+
362386
}

src/test/java/org/springframework/data/couchbase/util/ClusterAwareIntegrationTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,12 @@ private static void callSuper(Object createdHere, Class annotationClass) {
215215
}
216216
}
217217

218+
/**
219+
* @return unique identifier for line - to use as key for documents to identify where they were created
220+
*/
221+
public static String loc() {
222+
StackTraceElement ste = Thread.currentThread().getStackTrace()[2];
223+
return ste.getClassName() + ":" + ste.getMethodName() + ":" + ste.getLineNumber();
224+
}
225+
218226
}

src/test/resources/logback.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- log additional debug info during automatic index creation
2323
-->
2424

25-
<logger name="org.springframework.data.couchbase.core" level="debug"/>"
25+
<logger name="org.springframework.data.couchbase.core" level="trace"/>"
2626
<logger name="org.springframework.data.couchbase.repository.query" level="debug"/>
2727
<logger name="org.springframework.data.couchbase.repository.query.SpatialViewQueryCreator" level="trace"/>
2828
<logger name="org.springframework.data.couchbase.repository.query.StringN1qlBasedQuery" level="trace"/>

0 commit comments

Comments
 (0)