Skip to content

Commit 3210802

Browse files
committed
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.
1 parent c6fa4ee commit 3210802

File tree

48 files changed

+584
-407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+584
-407
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020

2121
import org.springframework.data.couchbase.core.ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport;
22+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2223
import org.springframework.util.Assert;
2324

2425
import com.couchbase.client.java.kv.ExistsOptions;
@@ -39,7 +40,8 @@ public ExecutableExistsById existsById() {
3940

4041
@Override
4142
public ExecutableExistsById existsById(Class<?> domainType) {
42-
return new ExecutableExistsByIdSupport(template, domainType, null, null, null);
43+
return new ExecutableExistsByIdSupport(template, domainType, OptionsBuilder.getScopeFrom(domainType),
44+
OptionsBuilder.getCollectionFrom(domainType), null);
4345
}
4446

4547
static class ExecutableExistsByIdSupport implements ExecutableExistsById {
@@ -74,7 +76,8 @@ public Map<String, Boolean> all(final Collection<String> ids) {
7476

7577
@Override
7678
public ExistsByIdWithOptions inCollection(final String collection) {
77-
return new ExecutableExistsByIdSupport(template, domainType, scope, collection, options);
79+
return new ExecutableExistsByIdSupport(template, domainType, scope,
80+
collection != null ? collection : this.collection, options);
7881
}
7982

8083
@Override
@@ -85,7 +88,8 @@ public TerminatingExistsById withOptions(final ExistsOptions options) {
8588

8689
@Override
8790
public ExistsByIdInCollection inScope(final String scope) {
88-
return new ExecutableExistsByIdSupport(template, domainType, scope, collection, options);
91+
return new ExecutableExistsByIdSupport(template, domainType, scope != null ? scope : this.scope, collection,
92+
options);
8993
}
9094
}
9195

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.data.couchbase.core.ReactiveFindByAnalyticsOperationSupport.ReactiveFindByAnalyticsSupport;
2222
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
23+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2324
import org.springframework.util.Assert;
2425

2526
import com.couchbase.client.java.analytics.AnalyticsOptions;
@@ -37,7 +38,8 @@ public ExecutableFindByAnalyticsOperationSupport(final CouchbaseTemplate templat
3738

3839
@Override
3940
public <T> ExecutableFindByAnalytics<T> findByAnalytics(final Class<T> domainType) {
40-
return new ExecutableFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null, null, null, null);
41+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null,
42+
OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null);
4143
}
4244

4345
static class ExecutableFindByAnalyticsSupport<T> implements ExecutableFindByAnalytics<T> {
@@ -97,14 +99,14 @@ public FindByAnalyticsWithQuery<T> withOptions(final AnalyticsOptions options) {
9799

98100
@Override
99101
public FindByAnalyticsInCollection<T> inScope(final String scope) {
100-
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
101-
collection, options);
102+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency,
103+
scope != null ? scope : this.scope, collection, options);
102104
}
103105

104106
@Override
105107
public FindByAnalyticsWithConsistency<T> inCollection(final String collection) {
106108
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
107-
collection, options);
109+
collection != null ? collection : this.collection, options);
108110
}
109111

110112
@Override

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222

2323
import org.springframework.data.couchbase.core.ReactiveFindByIdOperationSupport.ReactiveFindByIdSupport;
24+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2425
import org.springframework.util.Assert;
2526

2627
import com.couchbase.client.java.kv.GetOptions;
@@ -35,7 +36,8 @@ public class ExecutableFindByIdOperationSupport implements ExecutableFindByIdOpe
3536

3637
@Override
3738
public <T> ExecutableFindById<T> findById(Class<T> domainType) {
38-
return new ExecutableFindByIdSupport<>(template, domainType, null, null, null, null, null);
39+
return new ExecutableFindByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType),
40+
OptionsBuilder.getCollectionFrom(domainType),null, null, null);
3941
}
4042

4143
static class ExecutableFindByIdSupport<T> implements ExecutableFindById<T> {
@@ -80,12 +82,12 @@ public TerminatingFindById<T> withOptions(final GetOptions options) {
8082

8183
@Override
8284
public FindByIdWithOptions<T> inCollection(final String collection) {
83-
return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields, expiry);
85+
return new ExecutableFindByIdSupport<>(template, domainType, scope, collection != null ? collection : this.collection, options, fields, expiry);
8486
}
8587

8688
@Override
8789
public FindByIdInCollection<T> inScope(final String scope) {
88-
return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields, expiry);
90+
return new ExecutableFindByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection, options, fields, expiry);
8991
}
9092

9193
@Override

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.util.stream.Stream;
2020

2121
import org.springframework.data.couchbase.core.ReactiveFindByQueryOperationSupport.ReactiveFindByQuerySupport;
22+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2223
import org.springframework.data.couchbase.core.query.Query;
2324
import org.springframework.util.Assert;
2425

@@ -43,8 +44,8 @@ public ExecutableFindByQueryOperationSupport(final CouchbaseTemplate template) {
4344

4445
@Override
4546
public <T> ExecutableFindByQuery<T> findByQuery(final Class<T> domainType) {
46-
return new ExecutableFindByQuerySupport<T>(template, domainType, domainType, ALL_QUERY, null, null, null, null,
47-
null, null);
47+
return new ExecutableFindByQuerySupport<T>(template, domainType, domainType, ALL_QUERY, null,
48+
OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null, null, null);
4849
}
4950

5051
static class ExecutableFindByQuerySupport<T> implements ExecutableFindByQuery<T> {
@@ -174,14 +175,14 @@ public TerminatingFindByQuery<T> withOptions(final QueryOptions options) {
174175

175176
@Override
176177
public FindByQueryInCollection<T> inScope(final String scope) {
177-
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
178-
collection, options, distinctFields, fields);
178+
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency,
179+
scope != null ? scope : this.scope, collection, options, distinctFields, fields);
179180
}
180181

181182
@Override
182183
public FindByQueryWithConsistency<T> inCollection(final String collection) {
183184
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
184-
collection, options, distinctFields, fields);
185+
collection != null ? collection : this.collection, options, distinctFields, fields);
185186
}
186187

187188
}

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
import java.util.Collection;
1919

2020
import org.springframework.data.couchbase.core.ReactiveFindFromReplicasByIdOperationSupport.ReactiveFindFromReplicasByIdSupport;
21+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2122
import org.springframework.util.Assert;
2223

2324
import com.couchbase.client.java.kv.GetAnyReplicaOptions;
@@ -32,7 +33,8 @@ public class ExecutableFindFromReplicasByIdOperationSupport implements Executabl
3233

3334
@Override
3435
public <T> ExecutableFindFromReplicasById<T> findFromReplicasById(Class<T> domainType) {
35-
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, domainType, null, null, null);
36+
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, domainType,
37+
OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null);
3638
}
3739

3840
static class ExecutableFindFromReplicasByIdSupport<T> implements ExecutableFindFromReplicasById<T> {
@@ -75,12 +77,14 @@ public TerminatingFindFromReplicasById<T> withOptions(final GetAnyReplicaOptions
7577

7678
@Override
7779
public FindFromReplicasByIdWithOptions<T> inCollection(final String collection) {
78-
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options);
80+
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope,
81+
collection != null ? collection : this.collection, options);
7982
}
8083

8184
@Override
8285
public FindFromReplicasByIdInCollection<T> inScope(final String scope) {
83-
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options);
86+
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType,
87+
scope != null ? scope : this.scope, collection, options);
8488
}
8589

8690
}

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Collection;
2020

2121
import org.springframework.data.couchbase.core.ReactiveInsertByIdOperationSupport.ReactiveInsertByIdSupport;
22+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2223
import org.springframework.util.Assert;
2324

2425
import com.couchbase.client.core.msg.kv.DurabilityLevel;
@@ -37,8 +38,9 @@ public ExecutableInsertByIdOperationSupport(final CouchbaseTemplate template) {
3738
@Override
3839
public <T> ExecutableInsertById<T> insertById(final Class<T> domainType) {
3940
Assert.notNull(domainType, "DomainType must not be null!");
40-
return new ExecutableInsertByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE,
41-
DurabilityLevel.NONE, null);
41+
return new ExecutableInsertByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType),
42+
OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE,
43+
null);
4244
}
4345

4446
static class ExecutableInsertByIdSupport<T> implements ExecutableInsertById<T> {
@@ -89,14 +91,14 @@ public TerminatingInsertById<T> withOptions(final InsertOptions options) {
8991

9092
@Override
9193
public InsertByIdInCollection<T> inScope(final String scope) {
92-
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
93-
durabilityLevel, expiry);
94+
return new ExecutableInsertByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection,
95+
options, persistTo, replicateTo, durabilityLevel, expiry);
9496
}
9597

9698
@Override
9799
public InsertByIdWithOptions<T> inCollection(final String collection) {
98-
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
99-
durabilityLevel, expiry);
100+
return new ExecutableInsertByIdSupport<>(template, domainType, scope,
101+
collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry);
100102
}
101103

102104
@Override

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020

2121
import org.springframework.data.couchbase.core.ReactiveRemoveByIdOperationSupport.ReactiveRemoveByIdSupport;
22+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2223
import org.springframework.util.Assert;
2324

2425
import com.couchbase.client.core.msg.kv.DurabilityLevel;
@@ -42,7 +43,9 @@ public ExecutableRemoveById removeById() {
4243

4344
@Override
4445
public ExecutableRemoveById removeById(Class<?> domainType) {
45-
return new ExecutableRemoveByIdSupport(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE,
46+
47+
return new ExecutableRemoveByIdSupport(template, domainType, OptionsBuilder.getScopeFrom(domainType),
48+
OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE,
4649
DurabilityLevel.NONE, null);
4750
}
4851

@@ -87,7 +90,7 @@ public List<RemoveResult> all(final Collection<String> ids) {
8790

8891
@Override
8992
public RemoveByIdWithOptions inCollection(final String collection) {
90-
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
93+
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection != null ? collection : this.collection, options, persistTo, replicateTo,
9194
durabilityLevel, cas);
9295
}
9396

@@ -115,7 +118,7 @@ public TerminatingRemoveById withOptions(final RemoveOptions options) {
115118

116119
@Override
117120
public RemoveByIdInCollection inScope(final String scope) {
118-
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
121+
return new ExecutableRemoveByIdSupport(template, domainType, scope != null ? scope : this.scope, collection, options, persistTo, replicateTo,
119122
durabilityLevel, cas);
120123
}
121124

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919

2020
import org.springframework.data.couchbase.core.ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport;
21+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2122
import org.springframework.data.couchbase.core.query.Query;
2223
import org.springframework.util.Assert;
2324

@@ -36,7 +37,8 @@ public ExecutableRemoveByQueryOperationSupport(final CouchbaseTemplate template)
3637

3738
@Override
3839
public <T> ExecutableRemoveByQuery<T> removeByQuery(Class<T> domainType) {
39-
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null, null, null, null);
40+
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null,
41+
OptionsBuilder.getScopeFrom(domainType), OptionsBuilder.getCollectionFrom(domainType), null);
4042
}
4143

4244
static class ExecutableRemoveByQuerySupport<T> implements ExecutableRemoveByQuery<T> {
@@ -89,8 +91,8 @@ public RemoveByQueryConsistentWith<T> withConsistency(final QueryScanConsistency
8991

9092
@Override
9193
public RemoveByQueryWithConsistency<T> inCollection(final String collection) {
92-
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection,
93-
options);
94+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope,
95+
collection != null ? collection : this.collection, options);
9496
}
9597

9698
@Override
@@ -102,8 +104,8 @@ public RemoveByQueryWithQuery<T> withOptions(final QueryOptions options) {
102104

103105
@Override
104106
public RemoveByQueryInCollection<T> inScope(final String scope) {
105-
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection,
106-
options);
107+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency,
108+
scope != null ? scope : this.scope, collection, options);
107109
}
108110
}
109111

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors
2+
* Copyright 2012-2022 the original author or authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.util.Collection;
2020

2121
import org.springframework.data.couchbase.core.ReactiveReplaceByIdOperationSupport.ReactiveReplaceByIdSupport;
22+
import org.springframework.data.couchbase.core.query.OptionsBuilder;
2223
import org.springframework.util.Assert;
2324

2425
import com.couchbase.client.core.msg.kv.DurabilityLevel;
@@ -37,8 +38,9 @@ public ExecutableReplaceByIdOperationSupport(final CouchbaseTemplate template) {
3738
@Override
3839
public <T> ExecutableReplaceById<T> replaceById(final Class<T> domainType) {
3940
Assert.notNull(domainType, "DomainType must not be null!");
40-
return new ExecutableReplaceByIdSupport<>(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE,
41-
DurabilityLevel.NONE, null);
41+
return new ExecutableReplaceByIdSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType),
42+
OptionsBuilder.getCollectionFrom(domainType), null, PersistTo.NONE, ReplicateTo.NONE, DurabilityLevel.NONE,
43+
null);
4244
}
4345

4446
static class ExecutableReplaceByIdSupport<T> implements ExecutableReplaceById<T> {
@@ -82,8 +84,8 @@ public Collection<? extends T> all(Collection<? extends T> objects) {
8284

8385
@Override
8486
public ReplaceByIdWithOptions<T> inCollection(final String collection) {
85-
return new ExecutableReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo,
86-
replicateTo, durabilityLevel, expiry);
87+
return new ExecutableReplaceByIdSupport<>(template, domainType, scope,
88+
collection != null ? collection : this.collection, options, persistTo, replicateTo, durabilityLevel, expiry);
8789
}
8890

8991
@Override
@@ -117,8 +119,8 @@ public TerminatingReplaceById<T> withOptions(final ReplaceOptions options) {
117119

118120
@Override
119121
public ReplaceByIdInCollection<T> inScope(final String scope) {
120-
return new ExecutableReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo,
121-
replicateTo, durabilityLevel, expiry);
122+
return new ExecutableReplaceByIdSupport<>(template, domainType, scope != null ? scope : this.scope, collection,
123+
options, persistTo, replicateTo, durabilityLevel, expiry);
122124
}
123125

124126
}

0 commit comments

Comments
 (0)