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 51942a14..c60fd6a0 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.Collection; 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 class ExecutableExistsByIdOperationSupport implements ExecutableExistsByI @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 class ExecutableExistsByIdOperationSupport implements ExecutableExistsByI @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 class ExecutableExistsByIdOperationSupport implements ExecutableExistsByI @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 ad88bc4d..146359b9 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 java.util.stream.Stream; 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 class ExecutableFindByAnalyticsOperationSupport implements ExecutableFind @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 class ExecutableFindByAnalyticsOperationSupport implements ExecutableFind @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 38cf2716..75c7856e 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.Collection; 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 class ExecutableFindByIdOperationSupport implements ExecutableFindByIdOpe @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 cffdd571..571d6e99 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.List; 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 class ExecutableFindByQueryOperationSupport implements ExecutableFindByQu @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 class ExecutableFindByQueryOperationSupport implements ExecutableFindByQu @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 c087b920..a94e3908 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 @@ package org.springframework.data.couchbase.core; 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 class ExecutableFindFromReplicasByIdOperationSupport implements Executabl @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 8eb4b99f..f853522a 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.time.Duration; 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 class ExecutableInsertByIdOperationSupport implements ExecutableInsertByI @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 class ExecutableInsertByIdOperationSupport implements ExecutableInsertByI @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 e0721ce5..717d11a9 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.Collection; 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 class ExecutableRemoveByIdOperationSupport implements ExecutableRemoveByI @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 class ExecutableRemoveByIdOperationSupport implements ExecutableRemoveByI @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 class ExecutableRemoveByIdOperationSupport implements ExecutableRemoveByI @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 a97c62ba..74e9e01d 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 @@ package org.springframework.data.couchbase.core; 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 class ExecutableRemoveByQueryOperationSupport implements ExecutableRemove @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 class ExecutableRemoveByQueryOperationSupport implements ExecutableRemove @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 class ExecutableRemoveByQueryOperationSupport implements ExecutableRemove @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 ef47eb94..26f3dcb1 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.time.Duration; 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 class ExecutableReplaceByIdOperationSupport implements ExecutableReplaceB @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 class ExecutableReplaceByIdOperationSupport implements ExecutableReplaceB @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 class ExecutableReplaceByIdOperationSupport implements ExecutableReplaceB @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 61b7a394..f1b718a8 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.time.Duration; 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 class ExecutableUpsertByIdOperationSupport implements ExecutableUpsertByI @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 class ExecutableUpsertByIdOperationSupport implements ExecutableUpsertByI @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 56b64282..8436417d 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 class ReactiveExistsByIdOperationSupport implements ReactiveExistsByIdOpe @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 @@ public class ReactiveExistsByIdOperationSupport implements ReactiveExistsByIdOpe @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 class ReactiveExistsByIdOperationSupport implements ReactiveExistsByIdOpe @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 class ReactiveExistsByIdOperationSupport implements ReactiveExistsByIdOpe @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 87e617b2..a1599ac6 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.Flux; 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 class ReactiveFindByAnalyticsOperationSupport implements ReactiveFindByAn @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 class ReactiveFindByAnalyticsOperationSupport implements ReactiveFindByAn @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 34705457..a8391df0 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 java.util.List; 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 class ReactiveFindByIdOperationSupport implements ReactiveFindByIdOperati 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 class ReactiveFindByIdOperationSupport implements ReactiveFindByIdOperati @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 a5774e97..1952b821 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 reactor.core.publisher.Mono; 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 class ReactiveFindByQueryOperationSupport implements ReactiveFindByQueryO @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 class ReactiveFindByQueryOperationSupport implements ReactiveFindByQueryO @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 0e1372b4..0fee3b9e 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 java.util.Collection; 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 class ReactiveFindFromReplicasByIdOperationSupport implements ReactiveFin 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 class ReactiveFindFromReplicasByIdOperationSupport implements ReactiveFin @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 0d319fb4..516d41c0 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 class ReactiveInsertByIdOperationSupport implements ReactiveInsertByIdOpe @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 @@ public class ReactiveInsertByIdOperationSupport implements ReactiveInsertByIdOpe @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 class ReactiveInsertByIdOperationSupport implements ReactiveInsertByIdOpe @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 547c561e..d59de09c 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 class ReactiveRemoveByIdOperationSupport implements ReactiveRemoveByIdOpe @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 @@ public class ReactiveRemoveByIdOperationSupport implements ReactiveRemoveByIdOpe @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 class ReactiveRemoveByIdOperationSupport implements ReactiveRemoveByIdOpe @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 a9f1db8e..3437b8d5 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 java.util.Optional; 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 class ReactiveRemoveByQueryOperationSupport implements ReactiveRemoveByQu @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 class ReactiveRemoveByQueryOperationSupport implements ReactiveRemoveByQu @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 class ReactiveRemoveByQueryOperationSupport implements ReactiveRemoveByQu @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 ba96de24..246d76f4 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 class ReactiveReplaceByIdOperationSupport implements ReactiveReplaceByIdO @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 @@ public class ReactiveReplaceByIdOperationSupport implements ReactiveReplaceByIdO @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 class ReactiveReplaceByIdOperationSupport implements ReactiveReplaceByIdO @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 e84fe1fc..99760598 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 class ReactiveUpsertByIdOperationSupport implements ReactiveUpsertByIdOpe @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 @@ public class ReactiveUpsertByIdOperationSupport implements ReactiveUpsertByIdOpe @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 class ReactiveUpsertByIdOperationSupport implements ReactiveUpsertByIdOpe @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 80df2eb5..3d01fbdb 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 @@ import com.couchbase.client.java.query.QueryOptions; * 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 53835a40..bd325eb9 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 class N1QLExpression { * 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 93073709..20fe310d 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 class OptionsBuilder { 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 fb1bc9da..cb9ac9c9 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 class PseudoArgs { 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 class PseudoArgs { 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 39eab142..3d4496ea 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 @@ import org.springframework.data.couchbase.repository.query.StringN1qlQueryCreato * Also, SpEL in the form #{spelExpression} is supported, including the following N1QL variables that will * be replaced by the underlying {@link CouchbaseTemplate} associated information: *