From 3210802c6b76b0f9504fb8c817e829fcf3366deb Mon Sep 17 00:00:00 2001 From: Michael Reiche <48999328+mikereiche@users.noreply.github.com> Date: Thu, 16 Jun 2022 18:45:40 -0700 Subject: [PATCH] Rework the handling of annotations for scope and collection. The scope and collection repository annotations were not being passed on to derived and @Query remove operations. The handling of scope and collection annotations has been reworked in: 1) CrudMethodMetadataProcessor 2) All the *OperationSuppport constructors - the initial scope and collection is taken from the domainEntity class. 3) PseudoArgs 4) AbstractCouchbaseQuery/AbstractReactiveCouchbaseQuery add the scope/collection to the remove operation (analogous to the find Operation). 5) Scope/Collection is passed as args to the execute() method - even though this is redundant at the moment. Closes #1441. --- .../ExecutableExistsByIdOperationSupport.java | 12 ++- ...utableFindByAnalyticsOperationSupport.java | 12 ++- .../ExecutableFindByIdOperationSupport.java | 10 +- ...ExecutableFindByQueryOperationSupport.java | 13 +-- ...eFindFromReplicasByIdOperationSupport.java | 12 ++- .../ExecutableInsertByIdOperationSupport.java | 14 +-- .../ExecutableRemoveByIdOperationSupport.java | 9 +- ...ecutableRemoveByQueryOperationSupport.java | 14 +-- ...ExecutableReplaceByIdOperationSupport.java | 16 ++-- .../ExecutableUpsertByIdOperationSupport.java | 16 ++-- .../ReactiveExistsByIdOperationSupport.java | 13 ++- ...activeFindByAnalyticsOperationSupport.java | 10 +- .../ReactiveFindByIdOperationSupport.java | 12 ++- .../ReactiveFindByQueryOperationSupport.java | 12 ++- ...eFindFromReplicasByIdOperationSupport.java | 14 +-- .../ReactiveInsertByIdOperationSupport.java | 16 ++-- .../ReactiveRemoveByIdOperationSupport.java | 15 +-- ...ReactiveRemoveByQueryOperationSupport.java | 12 ++- .../ReactiveReplaceByIdOperationSupport.java | 16 ++-- .../ReactiveUpsertByIdOperationSupport.java | 16 ++-- .../core/convert/join/N1qlJoinResolver.java | 1 + .../couchbase/core/query/N1QLExpression.java | 2 +- .../couchbase/core/query/OptionsBuilder.java | 4 +- .../couchbase/core/support/PseudoArgs.java | 38 ++++++-- .../data/couchbase/repository/Query.java | 4 +- .../query/AbstractCouchbaseQuery.java | 47 ++++----- .../query/AbstractReactiveCouchbaseQuery.java | 40 ++++---- .../query/CouchbaseQueryExecution.java | 38 ++++---- .../query/CouchbaseQueryMethod.java | 96 +------------------ .../query/N1qlRepositoryQueryExecutor.java | 14 ++- .../ReactiveCouchbaseQueryExecution.java | 22 ++--- .../support/CouchbaseRepositoryBase.java | 10 +- .../CrudMethodMetadataPostProcessor.java | 12 ++- .../support/SimpleCouchbaseRepository.java | 8 +- .../SimpleReactiveCouchbaseRepository.java | 6 +- .../couchbase/domain/AirportRepository.java | 7 +- .../domain/AirportRepositoryAnnotated.java | 26 +++++ .../data/couchbase/domain/FluxTest.java | 10 +- .../domain/ReactiveAirportRepository.java | 13 ++- .../ReactiveAirportRepositoryAnnotated.java | 26 +++++ ...chbaseRepositoryQueryIntegrationTests.java | 2 + ...aseRepositoryKeyValueIntegrationTests.java | 8 +- ...chbaseRepositoryQueryIntegrationTests.java | 86 ++++++++--------- ...sitoryQueryCollectionIntegrationTests.java | 94 ++++++++++++++---- ...sitoryQueryCollectionIntegrationTests.java | 81 +++++++++++++--- ...tringN1qlQueryCreatorIntegrationTests.java | 19 +--- .../util/ClusterAwareIntegrationTests.java | 11 +++ src/test/resources/logback.xml | 2 +- 48 files changed, 584 insertions(+), 407 deletions(-) create mode 100644 src/test/java/org/springframework/data/couchbase/domain/AirportRepositoryAnnotated.java create mode 100644 src/test/java/org/springframework/data/couchbase/domain/ReactiveAirportRepositoryAnnotated.java diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperationSupport.java index 51942a141..c60fd6a0e 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableExistsByIdOperationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.util.Map; import org.springframework.data.couchbase.core.ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.util.Assert; import com.couchbase.client.java.kv.ExistsOptions; @@ -39,7 +40,8 @@ public ExecutableExistsById existsById() { @Override public ExecutableExistsById existsById(Class domainType) { - return new ExecutableExistsByIdSupport(template, domainType, null, null, null); + return new ExecutableExistsByIdSupport(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null); } static class ExecutableExistsByIdSupport implements ExecutableExistsById { @@ -74,7 +76,8 @@ public Map all(final Collection ids) { @Override public ExistsByIdWithOptions inCollection(final String collection) { - return new ExecutableExistsByIdSupport(template, domainType, scope, collection, options); + return new ExecutableExistsByIdSupport(template, domainType, scope, + collection != null ? collection : this.collection, options); } @Override @@ -85,7 +88,8 @@ public TerminatingExistsById withOptions(final ExistsOptions options) { @Override public ExistsByIdInCollection inScope(final String scope) { - return new ExecutableExistsByIdSupport(template, domainType, scope, collection, options); + return new ExecutableExistsByIdSupport(template, domainType, scope != null ? scope : this.scope, collection, + options); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java index ad88bc4de..146359b90 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByAnalyticsOperationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import org.springframework.data.couchbase.core.ReactiveFindByAnalyticsOperationSupport.ReactiveFindByAnalyticsSupport; import org.springframework.data.couchbase.core.query.AnalyticsQuery; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.util.Assert; import com.couchbase.client.java.analytics.AnalyticsOptions; @@ -37,7 +38,8 @@ public ExecutableFindByAnalyticsOperationSupport(final CouchbaseTemplate templat @Override public ExecutableFindByAnalytics findByAnalytics(final Class domainType) { - return new ExecutableFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null, null, null, null); + return new ExecutableFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null, + OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null); } static class ExecutableFindByAnalyticsSupport implements ExecutableFindByAnalytics { @@ -97,14 +99,14 @@ public FindByAnalyticsWithQuery withOptions(final AnalyticsOptions options) { @Override public FindByAnalyticsInCollection inScope(final String scope) { - return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope, - collection, options); + return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, + scope != null ? scope : this.scope, collection, options); } @Override public FindByAnalyticsWithConsistency inCollection(final String collection) { return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope, - collection, options); + collection != null ? collection : this.collection, options); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java index 38cf2716b..75c7856e5 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import java.util.List; import org.springframework.data.couchbase.core.ReactiveFindByIdOperationSupport.ReactiveFindByIdSupport; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.util.Assert; import com.couchbase.client.java.kv.GetOptions; @@ -35,7 +36,8 @@ public class ExecutableFindByIdOperationSupport implements ExecutableFindByIdOpe @Override public ExecutableFindById findById(Class domainType) { - return new ExecutableFindByIdSupport<>(template, domainType, null, null, null, null, null); + return new ExecutableFindByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType),null, null, null); } static class ExecutableFindByIdSupport implements ExecutableFindById { @@ -80,12 +82,12 @@ public TerminatingFindById withOptions(final GetOptions options) { @Override public FindByIdWithOptions inCollection(final String collection) { - return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields, expiry); + return new ExecutableFindByIdSupport<>(template, domainType, scope, collection != null ? collection : this.collection, options, fields, expiry); } @Override public FindByIdInCollection inScope(final String scope) { - return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields, expiry); + return new ExecutableFindByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, options, fields, expiry); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java index cffdd5716..571d6e995 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindByQueryOperationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.util.stream.Stream; import org.springframework.data.couchbase.core.ReactiveFindByQueryOperationSupport.ReactiveFindByQuerySupport; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.data.couchbase.core.query.Query; import org.springframework.util.Assert; @@ -43,8 +44,8 @@ public ExecutableFindByQueryOperationSupport(final CouchbaseTemplate template) { @Override public ExecutableFindByQuery findByQuery(final Class domainType) { - return new ExecutableFindByQuerySupport(template, domainType, domainType, ALL_QUERY, null, null, null, null, - null, null); + return new ExecutableFindByQuerySupport(template, domainType, domainType, ALL_QUERY, null, + OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null, null, null); } static class ExecutableFindByQuerySupport implements ExecutableFindByQuery { @@ -174,14 +175,14 @@ public TerminatingFindByQuery withOptions(final QueryOptions options) { @Override public FindByQueryInCollection inScope(final String scope) { - return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope, - collection, options, distinctFields, fields); + return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, + scope != null ? scope : this.scope, collection, options, distinctFields, fields); } @Override public FindByQueryWithConsistency inCollection(final String collection) { return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope, - collection, options, distinctFields, fields); + collection != null ? collection : this.collection, options, distinctFields, fields); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperationSupport.java index c087b9205..a94e3908b 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableFindFromReplicasByIdOperationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import java.util.Collection; import org.springframework.data.couchbase.core.ReactiveFindFromReplicasByIdOperationSupport.ReactiveFindFromReplicasByIdSupport; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.util.Assert; import com.couchbase.client.java.kv.GetAnyReplicaOptions; @@ -32,7 +33,8 @@ public class ExecutableFindFromReplicasByIdOperationSupport implements Executabl @Override public ExecutableFindFromReplicasById findFromReplicasById(Class domainType) { - return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, domainType, null, null, null); + return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, domainType, + OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null); } static class ExecutableFindFromReplicasByIdSupport implements ExecutableFindFromReplicasById { @@ -75,12 +77,14 @@ public TerminatingFindFromReplicasById withOptions(final GetAnyReplicaOptions @Override public FindFromReplicasByIdWithOptions inCollection(final String collection) { - return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options); + return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, + collection != null ? collection : this.collection, options); } @Override public FindFromReplicasByIdInCollection inScope(final String scope) { - return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options); + return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, + scope != null ? scope : this.scope, collection, options); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java index 8eb4b99f5..f853522a7 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableInsertByIdOperationSupport.java @@ -19,6 +19,7 @@ import java.util.Collection; import org.springframework.data.couchbase.core.ReactiveInsertByIdOperationSupport.ReactiveInsertByIdSupport; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.util.Assert; import com.couchbase.client.core.msg.kv.DurabilityLevel; @@ -37,8 +38,9 @@ public ExecutableInsertByIdOperationSupport(final CouchbaseTemplate template) { @Override public ExecutableInsertById insertById(final Class domainType) { Assert.notNull(domainType, "DomainType must not be null!"); - return new ExecutableInsertByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE, - DurabilityLevel.NONE, null); + return new ExecutableInsertByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE, + null); } static class ExecutableInsertByIdSupport implements ExecutableInsertById { @@ -89,14 +91,14 @@ public TerminatingInsertById withOptions(final InsertOptions options) { @Override public InsertByIdInCollection inScope(final String scope) { - return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry); + return new ExecutableInsertByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, + options, persistTo, replicateTo, durabilityLevel, expiry); } @Override public InsertByIdWithOptions inCollection(final String collection) { - return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry); + return new ExecutableInsertByIdSupport<>(template, domainType, scope, + collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperationSupport.java index e0721ce5a..717d11a98 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByIdOperationSupport.java @@ -19,6 +19,7 @@ import java.util.List; import org.springframework.data.couchbase.core.ReactiveRemoveByIdOperationSupport.ReactiveRemoveByIdSupport; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.util.Assert; import com.couchbase.client.core.msg.kv.DurabilityLevel; @@ -42,7 +43,9 @@ public ExecutableRemoveById removeById() { @Override public ExecutableRemoveById removeById(Class domainType) { - return new ExecutableRemoveByIdSupport(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE, + + return new ExecutableRemoveByIdSupport(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE, null); } @@ -87,7 +90,7 @@ public List all(final Collection ids) { @Override public RemoveByIdWithOptions inCollection(final String collection) { - return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo, + return new ExecutableRemoveByIdSupport(template, domainType, scope, collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, cas); } @@ -115,7 +118,7 @@ public TerminatingRemoveById withOptions(final RemoveOptions options) { @Override public RemoveByIdInCollection inScope(final String scope) { - return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo, + return new ExecutableRemoveByIdSupport(template, domainType, scope != null ? scope : this.scope, collection, options, persistTo, replicateTo, durabilityLevel, cas); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByQueryOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByQueryOperationSupport.java index a97c62ba3..74e9e01d4 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByQueryOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableRemoveByQueryOperationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import java.util.List; import org.springframework.data.couchbase.core.ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.data.couchbase.core.query.Query; import org.springframework.util.Assert; @@ -36,7 +37,8 @@ public ExecutableRemoveByQueryOperationSupport(final CouchbaseTemplate template) @Override public ExecutableRemoveByQuery removeByQuery(Class domainType) { - return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null, null, null, null); + return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null, + OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null); } static class ExecutableRemoveByQuerySupport implements ExecutableRemoveByQuery { @@ -89,8 +91,8 @@ public RemoveByQueryConsistentWith withConsistency(final QueryScanConsistency @Override public RemoveByQueryWithConsistency inCollection(final String collection) { - return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection, - options); + return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, + collection != null ? collection : this.collection, options); } @Override @@ -102,8 +104,8 @@ public RemoveByQueryWithQuery withOptions(final QueryOptions options) { @Override public RemoveByQueryInCollection inScope(final String scope) { - return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection, - options); + return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, + scope != null ? scope : this.scope, collection, options); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableReplaceByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableReplaceByIdOperationSupport.java index ef47eb94a..26f3dcb19 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableReplaceByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableReplaceByIdOperationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.util.Collection; import org.springframework.data.couchbase.core.ReactiveReplaceByIdOperationSupport.ReactiveReplaceByIdSupport; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.util.Assert; import com.couchbase.client.core.msg.kv.DurabilityLevel; @@ -37,8 +38,9 @@ public ExecutableReplaceByIdOperationSupport(final CouchbaseTemplate template) { @Override public ExecutableReplaceById replaceById(final Class domainType) { Assert.notNull(domainType, "DomainType must not be null!"); - return new ExecutableReplaceByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE, - DurabilityLevel.NONE, null); + return new ExecutableReplaceByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE, + null); } static class ExecutableReplaceByIdSupport implements ExecutableReplaceById { @@ -82,8 +84,8 @@ public Collection all(Collection objects) { @Override public ReplaceByIdWithOptions inCollection(final String collection) { - return new ExecutableReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, - replicateTo, durabilityLevel, expiry); + return new ExecutableReplaceByIdSupport<>(template, domainType, scope, + collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry); } @Override @@ -117,8 +119,8 @@ public TerminatingReplaceById withOptions(final ReplaceOptions options) { @Override public ReplaceByIdInCollection inScope(final String scope) { - return new ExecutableReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, - replicateTo, durabilityLevel, expiry); + return new ExecutableReplaceByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, + options, persistTo, replicateTo, durabilityLevel, expiry); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperationSupport.java index 61b7a3945..f1b718a84 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.util.Collection; import org.springframework.data.couchbase.core.ReactiveUpsertByIdOperationSupport.ReactiveUpsertByIdSupport; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.util.Assert; import com.couchbase.client.core.msg.kv.DurabilityLevel; @@ -37,8 +38,9 @@ public ExecutableUpsertByIdOperationSupport(final CouchbaseTemplate template) { @Override public ExecutableUpsertById upsertById(final Class domainType) { Assert.notNull(domainType, "DomainType must not be null!"); - return new ExecutableUpsertByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE, - DurabilityLevel.NONE, null); + return new ExecutableUpsertByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE, + null); } static class ExecutableUpsertByIdSupport implements ExecutableUpsertById { @@ -89,14 +91,14 @@ public TerminatingUpsertById withOptions(final UpsertOptions options) { @Override public UpsertByIdInCollection inScope(final String scope) { - return new ExecutableUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry); + return new ExecutableUpsertByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, + options, persistTo, replicateTo, durabilityLevel, expiry); } @Override public UpsertByIdWithOptions inCollection(final String collection) { - return new ExecutableUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry); + return new ExecutableUpsertByIdSupport<>(template, domainType, scope, + collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveExistsByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveExistsByIdOperationSupport.java index 56b642820..8436417d0 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveExistsByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveExistsByIdOperationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,8 @@ public ReactiveExistsById existsById() { @Override public ReactiveExistsById existsById(Class domainType) { - return new ReactiveExistsByIdSupport(template, domainType, null, null, null); + return new ReactiveExistsByIdSupport(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null); } static class ReactiveExistsByIdSupport implements ReactiveExistsById { @@ -72,7 +73,7 @@ static class ReactiveExistsByIdSupport implements ReactiveExistsById { @Override public Mono one(final String id) { PseudoArgs pArgs = new PseudoArgs<>(template, scope, collection, options, domainType); - LOG.trace("existsById {}", pArgs); + LOG.trace("existsById key={} {}", id, pArgs); return Mono.just(id) .flatMap(docId -> template.getCouchbaseClientFactory().withScope(pArgs.getScope()) .getCollection(pArgs.getCollection()).reactive().exists(id, buildOptions(pArgs.getOptions())) @@ -98,7 +99,8 @@ public Mono> all(final Collection ids) { @Override public ExistsByIdWithOptions inCollection(final String collection) { - return new ReactiveExistsByIdSupport(template, domainType, scope, collection, options); + return new ReactiveExistsByIdSupport(template, domainType, scope, + collection != null ? collection : this.collection, options); } @Override @@ -109,7 +111,8 @@ public TerminatingExistsById withOptions(final ExistsOptions options) { @Override public ExistsByIdInCollection inScope(final String scope) { - return new ReactiveExistsByIdSupport(template, domainType, scope, collection, options); + return new ReactiveExistsByIdSupport(template, domainType, scope != null ? scope : this.scope, collection, + options); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByAnalyticsOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByAnalyticsOperationSupport.java index 87e617b20..a1599ac6d 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByAnalyticsOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByAnalyticsOperationSupport.java @@ -19,6 +19,7 @@ import reactor.core.publisher.Mono; import org.springframework.data.couchbase.core.query.AnalyticsQuery; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.data.couchbase.core.support.TemplateUtils; import org.springframework.util.Assert; @@ -38,7 +39,8 @@ public ReactiveFindByAnalyticsOperationSupport(final ReactiveCouchbaseTemplate t @Override public ReactiveFindByAnalytics findByAnalytics(final Class domainType) { - return new ReactiveFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null, null, null, null, + return new ReactiveFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null, + OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null, template.support()); } @@ -165,14 +167,14 @@ public TerminatingFindByAnalytics withOptions(final AnalyticsOptions options) @Override public FindByAnalyticsInCollection inScope(final String scope) { - return new ReactiveFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope, - collection, options, support); + return new ReactiveFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, + scope != null ? scope : this.scope, collection, options, support); } @Override public FindByAnalyticsWithConsistency inCollection(final String collection) { return new ReactiveFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope, - collection, options, support); + collection != null ? collection : this.collection, options, support); } private String assembleEntityQuery(final boolean count) { diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByIdOperationSupport.java index 347054579..a8391df04 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByIdOperationSupport.java @@ -28,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.data.couchbase.core.support.PseudoArgs; import org.springframework.util.Assert; @@ -49,7 +50,8 @@ public class ReactiveFindByIdOperationSupport implements ReactiveFindByIdOperati @Override public ReactiveFindById findById(Class domainType) { - return new ReactiveFindByIdSupport<>(template, domainType, null, null, null, null, null, template.support()); + return new ReactiveFindByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null, null, null, template.support()); } static class ReactiveFindByIdSupport implements ReactiveFindById { @@ -80,7 +82,7 @@ public Mono one(final String id) { CommonOptions gOptions = initGetOptions(); PseudoArgs pArgs = new PseudoArgs(template, scope, collection, gOptions, domainType); - LOG.trace("findById {}", pArgs); + LOG.trace("findById key={} {}", id, pArgs); return Mono.just(id).flatMap(docId -> { ReactiveCollection reactive = template.getCouchbaseClientFactory().withScope(pArgs.getScope()) @@ -120,12 +122,14 @@ public TerminatingFindById withOptions(final GetOptions options) { @Override public FindByIdWithOptions inCollection(final String collection) { - return new ReactiveFindByIdSupport<>(template, domainType, scope, collection, options, fields, expiry, support); + return new ReactiveFindByIdSupport<>(template, domainType, scope, + collection != null ? collection : this.collection, options, fields, expiry, support); } @Override public FindByIdInCollection inScope(final String scope) { - return new ReactiveFindByIdSupport<>(template, domainType, scope, collection, options, fields, expiry, support); + return new ReactiveFindByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, + options, fields, expiry, support); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java index a5774e974..1952b8213 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java @@ -20,6 +20,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.data.couchbase.core.query.Query; import org.springframework.data.couchbase.core.support.PseudoArgs; import org.springframework.data.couchbase.core.support.TemplateUtils; @@ -48,8 +49,9 @@ public ReactiveFindByQueryOperationSupport(final ReactiveCouchbaseTemplate templ @Override public ReactiveFindByQuery findByQuery(final Class domainType) { - return new ReactiveFindByQuerySupport<>(template, domainType, domainType, ALL_QUERY, null, null, null, null, null, - null, template.support()); + return new ReactiveFindByQuerySupport<>(template, domainType, domainType, ALL_QUERY, null, + OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null, null, null, + template.support()); } static class ReactiveFindByQuerySupport implements ReactiveFindByQuery { @@ -107,14 +109,14 @@ public TerminatingFindByQuery withOptions(final QueryOptions options) { @Override public FindByQueryInCollection inScope(final String scope) { - return new ReactiveFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope, - collection, options, distinctFields, fields, support); + return new ReactiveFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, + scope != null ? scope : this.scope, collection, options, distinctFields, fields, support); } @Override public FindByQueryWithConsistency inCollection(final String collection) { return new ReactiveFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope, - collection, options, distinctFields, fields, support); + collection != null ? collection : this.collection, options, distinctFields, fields, support); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindFromReplicasByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindFromReplicasByIdOperationSupport.java index 0e1372b4f..0fee3b9e4 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveFindFromReplicasByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveFindFromReplicasByIdOperationSupport.java @@ -24,6 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.data.couchbase.core.support.PseudoArgs; import org.springframework.util.Assert; @@ -41,7 +42,8 @@ public class ReactiveFindFromReplicasByIdOperationSupport implements ReactiveFin @Override public ReactiveFindFromReplicasById findFromReplicasById(Class domainType) { - return new ReactiveFindFromReplicasByIdSupport<>(template, domainType, domainType, null, null, null, + return new ReactiveFindFromReplicasByIdSupport<>(template, domainType, domainType, + OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null, template.support()); } @@ -73,7 +75,7 @@ public Mono any(final String id) { garOptions.transcoder(RawJsonTranscoder.INSTANCE); } PseudoArgs pArgs = new PseudoArgs<>(template, scope, collection, garOptions, domainType); - LOG.trace("getAnyReplica {}", pArgs); + LOG.trace("getAnyReplica key={} {}", id, pArgs); return Mono.just(id) .flatMap(docId -> template.getCouchbaseClientFactory().withScope(pArgs.getScope()) .getCollection(pArgs.getCollection()).reactive().getAnyReplica(docId, pArgs.getOptions())) @@ -102,14 +104,14 @@ public TerminatingFindFromReplicasById withOptions(final GetAnyReplicaOptions @Override public FindFromReplicasByIdWithOptions inCollection(final String collection) { - return new ReactiveFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options, - support); + return new ReactiveFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, + collection != null ? collection : this.collection, options, support); } @Override public FindFromReplicasByIdInCollection inScope(final String scope) { - return new ReactiveFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options, - support); + return new ReactiveFindFromReplicasByIdSupport<>(template, domainType, returnType, + scope != null ? scope : this.scope, collection, options, support); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java index 0d319fb4a..516d41c0a 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java @@ -45,8 +45,9 @@ public ReactiveInsertByIdOperationSupport(final ReactiveCouchbaseTemplate templa @Override public ReactiveInsertById insertById(final Class domainType) { Assert.notNull(domainType, "DomainType must not be null!"); - return new ReactiveInsertByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE, - DurabilityLevel.NONE, null, template.support()); + return new ReactiveInsertByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE, + null, template.support()); } static class ReactiveInsertByIdSupport implements ReactiveInsertById { @@ -80,7 +81,7 @@ static class ReactiveInsertByIdSupport implements ReactiveInsertById { @Override public Mono one(T object) { PseudoArgs pArgs = new PseudoArgs(template, scope, collection, options, domainType); - LOG.trace("insertById {}", pArgs); + LOG.trace("insertById object={} {}", object, pArgs); return Mono.just(object).flatMap(support::encodeEntity) .flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope()) .getCollection(pArgs.getCollection()).reactive() @@ -114,14 +115,15 @@ public TerminatingInsertById withOptions(final InsertOptions options) { @Override public InsertByIdInCollection inScope(final String scope) { - return new ReactiveInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry, support); + return new ReactiveInsertByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, + options, persistTo, replicateTo, durabilityLevel, expiry, support); } @Override public InsertByIdWithOptions inCollection(final String collection) { - return new ReactiveInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry, support); + return new ReactiveInsertByIdSupport<>(template, domainType, scope, + collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry, + support); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java index 547c561e5..d59de09cc 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java @@ -48,8 +48,9 @@ public ReactiveRemoveById removeById() { @Override public ReactiveRemoveById removeById(Class domainType) { - return new ReactiveRemoveByIdSupport(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE, - DurabilityLevel.NONE, null); + return new ReactiveRemoveByIdSupport(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE, + null); } static class ReactiveRemoveByIdSupport implements ReactiveRemoveById { @@ -81,7 +82,7 @@ static class ReactiveRemoveByIdSupport implements ReactiveRemoveById { @Override public Mono one(final String id) { PseudoArgs pArgs = new PseudoArgs<>(template, scope, collection, options, domainType); - LOG.trace("removeById {}", pArgs); + LOG.trace("removeById key={} {}", id, pArgs); return Mono.just(id) .flatMap(docId -> template.getCouchbaseClientFactory().withScope(pArgs.getScope()) .getCollection(pArgs.getCollection()).reactive().remove(id, buildRemoveOptions(pArgs.getOptions())) @@ -121,14 +122,14 @@ public RemoveByIdInScope withDurability(final PersistTo persistTo, final Replica @Override public RemoveByIdWithDurability inCollection(final String collection) { - return new ReactiveRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, cas); + return new ReactiveRemoveByIdSupport(template, domainType, scope, + collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, cas); } @Override public RemoveByIdInCollection inScope(final String scope) { - return new ReactiveRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, cas); + return new ReactiveRemoveByIdSupport(template, domainType, scope != null ? scope : this.scope, collection, + options, persistTo, replicateTo, durabilityLevel, cas); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByQueryOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByQueryOperationSupport.java index a9f1db8e9..3437b8d51 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByQueryOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByQueryOperationSupport.java @@ -22,6 +22,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.data.couchbase.core.query.OptionsBuilder; import org.springframework.data.couchbase.core.query.Query; import org.springframework.data.couchbase.core.support.PseudoArgs; import org.springframework.data.couchbase.core.support.TemplateUtils; @@ -44,7 +45,8 @@ public ReactiveRemoveByQueryOperationSupport(final ReactiveCouchbaseTemplate tem @Override public ReactiveRemoveByQuery removeByQuery(Class domainType) { - return new ReactiveRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null, null, null, null); + return new ReactiveRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null, + OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null); } static class ReactiveRemoveByQuerySupport implements ReactiveRemoveByQuery { @@ -102,8 +104,8 @@ public TerminatingRemoveByQuery matching(final Query query) { @Override public RemoveByQueryWithConsistency inCollection(final String collection) { - return new ReactiveRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection, - options); + return new ReactiveRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, + collection != null ? collection : this.collection, options); } @Override @@ -132,8 +134,8 @@ public RemoveByQueryWithQuery withOptions(final QueryOptions options) { @Override public RemoveByQueryInCollection inScope(final String scope) { - return new ReactiveRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection, - options); + return new ReactiveRemoveByQuerySupport<>(template, domainType, query, scanConsistency, + scope != null ? scope : this.scope, collection, options); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java index ba96de24c..246d76f46 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java @@ -45,8 +45,9 @@ public ReactiveReplaceByIdOperationSupport(final ReactiveCouchbaseTemplate templ @Override public ReactiveReplaceById replaceById(final Class domainType) { Assert.notNull(domainType, "DomainType must not be null!"); - return new ReactiveReplaceByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE, - DurabilityLevel.NONE, null, template.support()); + return new ReactiveReplaceByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE, + null, template.support()); } static class ReactiveReplaceByIdSupport implements ReactiveReplaceById { @@ -80,7 +81,7 @@ static class ReactiveReplaceByIdSupport implements ReactiveReplaceById { @Override public Mono one(T object) { PseudoArgs pArgs = new PseudoArgs<>(template, scope, collection, options, domainType); - LOG.trace("replaceById {}", pArgs); + LOG.trace("replaceById object={} {}", object, pArgs); return Mono.just(object).flatMap(support::encodeEntity) .flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope()) .getCollection(pArgs.getCollection()).reactive() @@ -115,14 +116,15 @@ public TerminatingReplaceById withOptions(final ReplaceOptions options) { @Override public ReplaceByIdWithDurability inCollection(final String collection) { - return new ReactiveReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry, support); + return new ReactiveReplaceByIdSupport<>(template, domainType, scope, + collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry, + support); } @Override public ReplaceByIdInCollection inScope(final String scope) { - return new ReactiveReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry, support); + return new ReactiveReplaceByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, + options, persistTo, replicateTo, durabilityLevel, expiry, support); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java index e84fe1fca..997605983 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java @@ -45,8 +45,9 @@ public ReactiveUpsertByIdOperationSupport(final ReactiveCouchbaseTemplate templa @Override public ReactiveUpsertById upsertById(final Class domainType) { Assert.notNull(domainType, "DomainType must not be null!"); - return new ReactiveUpsertByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE, - DurabilityLevel.NONE, null, template.support()); + return new ReactiveUpsertByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType), + OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE, + null, template.support()); } static class ReactiveUpsertByIdSupport implements ReactiveUpsertById { @@ -80,7 +81,7 @@ static class ReactiveUpsertByIdSupport implements ReactiveUpsertById { @Override public Mono one(T object) { PseudoArgs pArgs = new PseudoArgs(template, scope, collection, options, domainType); - LOG.trace("upsertById {}", pArgs); + LOG.trace("upsertById object={} {}", object, pArgs); return Mono.just(object).flatMap(support::encodeEntity) .flatMap(converted -> template.getCouchbaseClientFactory().withScope(pArgs.getScope()) .getCollection(pArgs.getCollection()).reactive() @@ -114,14 +115,15 @@ public TerminatingUpsertById withOptions(final UpsertOptions options) { @Override public UpsertByIdWithDurability inCollection(final String collection) { - return new ReactiveUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry, support); + return new ReactiveUpsertByIdSupport<>(template, domainType, scope, + collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry, + support); } @Override public UpsertByIdInCollection inScope(final String scope) { - return new ReactiveUpsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo, - durabilityLevel, expiry, support); + return new ReactiveUpsertByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, + options, persistTo, replicateTo, durabilityLevel, expiry, support); } @Override diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/join/N1qlJoinResolver.java b/src/main/java/org/springframework/data/couchbase/core/convert/join/N1qlJoinResolver.java index 80df2eb57..3d01fbdb6 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/join/N1qlJoinResolver.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/join/N1qlJoinResolver.java @@ -53,6 +53,7 @@ * N1qlJoinResolver resolves by converting the join definition to query statement and executing using CouchbaseTemplate * * @author Subhashni Balakrishnan + * @author Michael Reiche */ public class N1qlJoinResolver { private static final Logger LOGGER = LoggerFactory.getLogger(N1qlJoinResolver.class); diff --git a/src/main/java/org/springframework/data/couchbase/core/query/N1QLExpression.java b/src/main/java/org/springframework/data/couchbase/core/query/N1QLExpression.java index 53835a40a..bd325eb9d 100644 --- a/src/main/java/org/springframework/data/couchbase/core/query/N1QLExpression.java +++ b/src/main/java/org/springframework/data/couchbase/core/query/N1QLExpression.java @@ -213,7 +213,7 @@ public static N1QLExpression count(N1QLExpression expression) { * Returned expression results in distinct of the expression */ public static N1QLExpression distinct(N1QLExpression expression) { - return x("distinct{" + expression.toString() + "}"); + return x("distinct{" + expression.toString() + "}"); } /** diff --git a/src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java b/src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java index 930737095..20fe310d5 100644 --- a/src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java +++ b/src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 the original author or authors. + * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -177,7 +177,7 @@ public static RemoveOptions buildRemoveOptions(RemoveOptions options, PersistTo options.cas(cas); } if (LOG.isTraceEnabled()) { - LOG.trace("remove options: {}" + toString(options)); + LOG.trace("remove options: {}", toString(options)); } return options; } diff --git a/src/main/java/org/springframework/data/couchbase/core/support/PseudoArgs.java b/src/main/java/org/springframework/data/couchbase/core/support/PseudoArgs.java index fb1bc9daa..cb9ac9c92 100644 --- a/src/main/java/org/springframework/data/couchbase/core/support/PseudoArgs.java +++ b/src/main/java/org/springframework/data/couchbase/core/support/PseudoArgs.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 the original author or authors + * Copyright 2021-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,18 @@ package org.springframework.data.couchbase.core.support; import static org.springframework.data.couchbase.core.query.OptionsBuilder.fromFirst; -import static org.springframework.data.couchbase.core.query.OptionsBuilder.getCollectionFrom; -import static org.springframework.data.couchbase.core.query.OptionsBuilder.getScopeFrom; import org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate; import com.couchbase.client.core.io.CollectionIdentifier; +/** + * determine the arguments to be used in the operation from various sources + * + * @author Michael Reiche + * + * @param + */ public class PseudoArgs { private final OPTS options; private final String scopeName; @@ -53,7 +58,12 @@ public PseudoArgs(ReactiveCouchbaseTemplate template, String scope, String colle String collectionForQuery = null; OPTS optionsForQuery = null; - // 1) repository from DynamicProxy via template threadLocal - has precedence over annotation + // threadlocal comes from the scope/collection of a repository from DynamicProxy via template threadLocal + // it - has precedence over the annotation of the method/entityClass/repositoryClass in the scope/collection args. + // note that there is no withScope()/withCollection() for repositories, so the scope/collection args can + // only be from annotations when scopeForQuery/collectionForQuery are non-null. + // + // for templates, there is no threadLocal, therefore scopeForQuery/collectionForQuery are always null PseudoArgs threadLocal = (PseudoArgs) template.getPseudoArgs(); template.setPseudoArgs(null); @@ -63,8 +73,24 @@ public PseudoArgs(ReactiveCouchbaseTemplate template, String scope, String colle optionsForQuery = threadLocal.getOptions(); } - scopeForQuery = fromFirst(null, scopeForQuery, scope, getScopeFrom(domainType)); - collectionForQuery = fromFirst(null, collectionForQuery, collection, getCollectionFrom(domainType)); + // the scope and collection args can come from + // - an annotation on the entity class in creation of the operation + // i.e. new ExecutableFindByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType), + // OptionsBuilder.getCollectionFrom(domainType)... + // + // - from CouchbaseRepositoryBase.getScope() that checks + // 1) crudMethodMetadata + // 2) entityClass annotation + // 3) repositoryClass annotation + // Note that it does not have the method to check for annotations. Only methods implemented in the base class + // are processed through the CouchbaseRepository class. + // + // - from the constructor of AbstractCouchbaseQueryBase. + // findOp = (ExecutableFindByQuery) (findOp.inScope(method.getScope()).inCollection(method.getCollection())); + // so is it also needed in the execute??? + + scopeForQuery = fromFirst(null, scopeForQuery, scope); + collectionForQuery = fromFirst(null, collectionForQuery, collection); optionsForQuery = fromFirst(null, options, optionsForQuery); // if a collection was specified but no scope, use the scope from the clientFactory diff --git a/src/main/java/org/springframework/data/couchbase/repository/Query.java b/src/main/java/org/springframework/data/couchbase/repository/Query.java index 39eab1425..3d4496eaa 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/Query.java +++ b/src/main/java/org/springframework/data/couchbase/repository/Query.java @@ -37,8 +37,8 @@ * Also, SpEL in the form #{spelExpression} is supported, including the following N1QL variables that will * be replaced by the underlying {@link CouchbaseTemplate} associated information: *