Skip to content

Commit 161d70c

Browse files
committed
Scopes and Collections for Repositories.
This adds scope and collection support to repositories via the DynamicInvocationHandler and PseudoArgs. It also adds annotations for scopes and collections. Closes #963
1 parent c53378e commit 161d70c

File tree

62 files changed

+1121
-333
lines changed

Some content is hidden

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

62 files changed

+1121
-333
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
2929
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
3030
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
31-
import org.springframework.data.couchbase.core.support.PseudoArgs;
3231
import org.springframework.data.mapping.context.MappingContext;
3332
import org.springframework.lang.Nullable;
3433

@@ -108,12 +107,22 @@ public <T> ExecutableFindByAnalytics<T> findByAnalytics(Class<T> domainType) {
108107

109108
@Override
110109
public ExecutableRemoveById removeById() {
111-
return new ExecutableRemoveByIdOperationSupport(this).removeById();
110+
return removeById(null);
111+
}
112+
113+
@Override
114+
public ExecutableRemoveById removeById(Class<?> domainType) {
115+
return new ExecutableRemoveByIdOperationSupport(this).removeById(domainType);
112116
}
113117

114118
@Override
115119
public ExecutableExistsById existsById() {
116-
return new ExecutableExistsByIdOperationSupport(this).existsById();
120+
return existsById(null);
121+
}
122+
123+
@Override
124+
public ExecutableExistsById existsById(Class<?> domainType) {
125+
return new ExecutableExistsByIdOperationSupport(this).existsById(domainType);
117126
}
118127

119128
@Override

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ public interface ExecutableExistsByIdOperation {
3636
/**
3737
* Checks if the document exists in the bucket.
3838
*/
39+
@Deprecated
3940
ExecutableExistsById existsById();
4041

42+
/**
43+
* Checks if the document exists in the bucket.
44+
*/
45+
ExecutableExistsById existsById(Class<?> domainType);
46+
4147
/**
4248
* Terminating operations invoking the actual execution.
4349
*/
@@ -78,7 +84,6 @@ interface ExistsByIdWithOptions<T> extends TerminatingExistsById, WithExistsOpti
7884
}
7985

8086
/**
81-
*
8287
* Fluent method to specify the collection.
8388
*
8489
* @param <T> the entity type to use for the results.

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,32 @@ public class ExecutableExistsByIdOperationSupport implements ExecutableExistsByI
3333

3434
@Override
3535
public ExecutableExistsById existsById() {
36-
return new ExecutableExistsByIdSupport(template, null, null, null);
36+
return existsById(null);
37+
}
38+
39+
@Override
40+
public ExecutableExistsById existsById(Class<?> domainType) {
41+
return new ExecutableExistsByIdSupport(template, domainType, null, null, null);
3742
}
3843

3944
static class ExecutableExistsByIdSupport implements ExecutableExistsById {
4045

4146
private final CouchbaseTemplate template;
47+
private final Class<?> domainType;
4248
private final String scope;
4349
private final String collection;
4450
private final ExistsOptions options;
4551

4652
private final ReactiveExistsByIdSupport reactiveSupport;
4753

48-
ExecutableExistsByIdSupport(final CouchbaseTemplate template, final String scope, final String collection,
49-
final ExistsOptions options) {
54+
ExecutableExistsByIdSupport(final CouchbaseTemplate template, final Class<?> domainType, final String scope,
55+
final String collection, final ExistsOptions options) {
5056
this.template = template;
57+
this.domainType = domainType;
5158
this.scope = scope;
5259
this.collection = collection;
5360
this.options = options;
54-
this.reactiveSupport = new ReactiveExistsByIdSupport(template.reactive(), scope, collection, options);
61+
this.reactiveSupport = new ReactiveExistsByIdSupport(template.reactive(), domainType, scope, collection, options);
5562
}
5663

5764
@Override
@@ -66,20 +73,18 @@ public Map<String, Boolean> all(final Collection<String> ids) {
6673

6774
@Override
6875
public ExistsByIdWithOptions inCollection(final String collection) {
69-
Assert.hasText(collection, "Collection must not be null nor empty.");
70-
return new ExecutableExistsByIdSupport(template, scope, collection, options);
76+
return new ExecutableExistsByIdSupport(template, domainType, scope, collection, options);
7177
}
7278

7379
@Override
7480
public TerminatingExistsById withOptions(final ExistsOptions options) {
7581
Assert.notNull(options, "Options must not be null.");
76-
return new ExecutableExistsByIdSupport(template, scope, collection, options);
82+
return new ExecutableExistsByIdSupport(template, domainType, scope, collection, options);
7783
}
7884

7985
@Override
8086
public ExistsByIdInCollection inScope(final String scope) {
81-
Assert.hasText(scope, "Scope must not be null nor empty.");
82-
return new ExecutableExistsByIdSupport(template, scope, collection, options);
87+
return new ExecutableExistsByIdSupport(template, domainType, scope, collection, options);
8388
}
8489
}
8590

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,12 @@ public FindByAnalyticsWithQuery<T> withOptions(final AnalyticsOptions options) {
9797

9898
@Override
9999
public FindByAnalyticsInCollection<T> inScope(final String scope) {
100-
Assert.hasText(scope, "Scope must not be null nor empty.");
101100
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
102101
collection, options);
103102
}
104103

105104
@Override
106105
public FindByAnalyticsWithConsistency<T> inCollection(final String collection) {
107-
Assert.hasText(collection, "Collection must not be null nor empty.");
108106
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
109107
collection, options);
110108
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ public TerminatingFindById<T> withOptions(final GetOptions options) {
7777

7878
@Override
7979
public FindByIdWithOptions<T> inCollection(final String collection) {
80-
Assert.hasText(collection, "Collection must not be null nor empty.");
8180
return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields);
8281
}
8382

8483
@Override
8584
public FindByIdInCollection<T> inScope(final String scope) {
86-
Assert.hasText(scope, "Scope must not be null nor empty.");
8785
return new ExecutableFindByIdSupport<>(template, domainType, scope, collection, options, fields);
8886
}
8987

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ static class ExecutableFindByQuerySupport<T> implements ExecutableFindByQuery<T>
6868
this.returnType = returnType;
6969
this.query = query;
7070
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(), domainType, returnType, query,
71-
scanConsistency, scope, collection, options, distinctFields, new NonReactiveSupportWrapper(template.support()));
71+
scanConsistency, scope, collection, options, distinctFields,
72+
new NonReactiveSupportWrapper(template.support()));
7273
this.scanConsistency = scanConsistency;
7374
this.scope = scope;
7475
this.collection = collection;
@@ -154,14 +155,12 @@ public TerminatingFindByQuery<T> withOptions(final QueryOptions options) {
154155

155156
@Override
156157
public FindByQueryInCollection<T> inScope(final String scope) {
157-
Assert.hasText(scope, "Scope must not be null nor empty.");
158158
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
159159
collection, options, distinctFields);
160160
}
161161

162162
@Override
163163
public FindByQueryWithConsistency<T> inCollection(final String collection) {
164-
Assert.hasText(collection, "Collection must not be null nor empty.");
165164
return new ExecutableFindByQuerySupport<>(template, domainType, returnType, query, scanConsistency, scope,
166165
collection, options, distinctFields);
167166
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import java.util.Collection;
1919

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

2223
import com.couchbase.client.java.kv.GetAnyReplicaOptions;
23-
import org.springframework.util.Assert;
2424

2525
public class ExecutableFindFromReplicasByIdOperationSupport implements ExecutableFindFromReplicasByIdOperation {
2626

@@ -54,7 +54,7 @@ static class ExecutableFindFromReplicasByIdSupport<T> implements ExecutableFindF
5454
this.options = options;
5555
this.returnType = returnType;
5656
this.reactiveSupport = new ReactiveFindFromReplicasByIdSupport<>(template.reactive(), domainType, returnType,
57-
scope, collection, options, new NonReactiveSupportWrapper(template.support()));
57+
scope, collection, options, new NonReactiveSupportWrapper(template.support()));
5858
}
5959

6060
@Override
@@ -75,13 +75,11 @@ public TerminatingFindFromReplicasById<T> withOptions(final GetAnyReplicaOptions
7575

7676
@Override
7777
public FindFromReplicasByIdWithOptions<T> inCollection(final String collection) {
78-
Assert.hasText(collection, "Collection must not be null nor empty.");
7978
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options);
8079
}
8180

8281
@Override
8382
public FindFromReplicasByIdInCollection<T> inScope(final String scope) {
84-
Assert.hasText(scope, "Scope must not be null nor empty.");
8583
return new ExecutableFindFromReplicasByIdSupport<>(template, domainType, returnType, scope, collection, options);
8684
}
8785

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,12 @@ public TerminatingInsertById<T> withOptions(final InsertOptions options) {
8989

9090
@Override
9191
public InsertByIdInCollection<T> inScope(final String scope) {
92-
Assert.hasText(scope, "Scope must not be null nor empty.");
9392
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
9493
durabilityLevel, expiry);
9594
}
9695

9796
@Override
9897
public InsertByIdWithOptions<T> inCollection(final String collection) {
99-
Assert.hasText(collection, "Collection must not be null nor empty.");
10098
return new ExecutableInsertByIdSupport<>(template, domainType, scope, collection, options, persistTo, replicateTo,
10199
durabilityLevel, expiry);
102100
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Collection;
1919
import java.util.List;
2020

21-
import org.springframework.data.couchbase.core.query.WithConsistency;
2221
import org.springframework.data.couchbase.core.support.InCollection;
2322
import org.springframework.data.couchbase.core.support.InScope;
2423
import org.springframework.data.couchbase.core.support.OneAndAllId;
@@ -39,8 +38,12 @@ public interface ExecutableRemoveByIdOperation {
3938
/**
4039
* Removes a document.
4140
*/
41+
ExecutableRemoveById removeById(Class<?> domainType);
42+
/**
43+
* Removes a document.
44+
*/
45+
@Deprecated
4246
ExecutableRemoveById removeById();
43-
4447
/**
4548
* Terminating operations invoking the actual execution.
4649
*/

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ public ExecutableRemoveByIdOperationSupport(final CouchbaseTemplate template) {
3636

3737
@Override
3838
public ExecutableRemoveById removeById() {
39-
return new ExecutableRemoveByIdSupport(template, null, null, null, PersistTo.NONE, ReplicateTo.NONE,
39+
return removeById(null);
40+
}
41+
42+
@Override
43+
public ExecutableRemoveById removeById(Class<?> domainType) {
44+
return new ExecutableRemoveByIdSupport(template, domainType, null, null, null, PersistTo.NONE, ReplicateTo.NONE,
4045
DurabilityLevel.NONE, null);
4146
}
4247

4348
static class ExecutableRemoveByIdSupport implements ExecutableRemoveById {
4449

4550
private final CouchbaseTemplate template;
51+
private final Class<?> domainType;
4652
private final String scope;
4753
private final String collection;
4854
private final RemoveOptions options;
@@ -52,18 +58,19 @@ static class ExecutableRemoveByIdSupport implements ExecutableRemoveById {
5258
private final Long cas;
5359
private final ReactiveRemoveByIdSupport reactiveRemoveByIdSupport;
5460

55-
ExecutableRemoveByIdSupport(final CouchbaseTemplate template, final String scope, final String collection,
56-
final RemoveOptions options, final PersistTo persistTo, final ReplicateTo replicateTo,
61+
ExecutableRemoveByIdSupport(final CouchbaseTemplate template, final Class<?> domainType, final String scope,
62+
final String collection, final RemoveOptions options, final PersistTo persistTo, final ReplicateTo replicateTo,
5763
final DurabilityLevel durabilityLevel, Long cas) {
5864
this.template = template;
65+
this.domainType = domainType;
5966
this.scope = scope;
6067
this.collection = collection;
6168
this.options = options;
6269
this.persistTo = persistTo;
6370
this.replicateTo = replicateTo;
6471
this.durabilityLevel = durabilityLevel;
65-
this.reactiveRemoveByIdSupport = new ReactiveRemoveByIdSupport(template.reactive(), scope, collection, options,
66-
persistTo, replicateTo, durabilityLevel, cas);
72+
this.reactiveRemoveByIdSupport = new ReactiveRemoveByIdSupport(template.reactive(), domainType, scope, collection,
73+
options, persistTo, replicateTo, durabilityLevel, cas);
6774
this.cas = cas;
6875
}
6976

@@ -79,43 +86,41 @@ public List<RemoveResult> all(final Collection<String> ids) {
7986

8087
@Override
8188
public RemoveByIdWithOptions inCollection(final String collection) {
82-
Assert.hasText(collection, "Collection must not be null nor empty.");
83-
return new ExecutableRemoveByIdSupport(template, scope, collection, options, persistTo, replicateTo,
89+
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
8490
durabilityLevel, cas);
8591
}
8692

8793
@Override
8894
public RemoveByIdInCollection withDurability(final DurabilityLevel durabilityLevel) {
8995
Assert.notNull(durabilityLevel, "Durability Level must not be null.");
90-
return new ExecutableRemoveByIdSupport(template, scope, collection, options, persistTo, replicateTo,
96+
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
9197
durabilityLevel, cas);
9298
}
9399

94100
@Override
95101
public RemoveByIdInCollection withDurability(final PersistTo persistTo, final ReplicateTo replicateTo) {
96102
Assert.notNull(persistTo, "PersistTo must not be null.");
97103
Assert.notNull(replicateTo, "ReplicateTo must not be null.");
98-
return new ExecutableRemoveByIdSupport(template, scope, collection, options, persistTo, replicateTo,
104+
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
99105
durabilityLevel, cas);
100106
}
101107

102108
@Override
103109
public TerminatingRemoveById withOptions(final RemoveOptions options) {
104110
Assert.notNull(options, "Options must not be null.");
105-
return new ExecutableRemoveByIdSupport(template, scope, collection, options, persistTo, replicateTo,
111+
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
106112
durabilityLevel, cas);
107113
}
108114

109115
@Override
110116
public RemoveByIdInCollection inScope(final String scope) {
111-
Assert.hasText(scope, "Scope must not be null nor empty.");
112-
return new ExecutableRemoveByIdSupport(template, scope, collection, options, persistTo, replicateTo,
117+
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
113118
durabilityLevel, cas);
114119
}
115120

116121
@Override
117122
public RemoveByIdWithDurability withCas(Long cas) {
118-
return new ExecutableRemoveByIdSupport(template, scope, collection, options, persistTo, replicateTo,
123+
return new ExecutableRemoveByIdSupport(template, domainType, scope, collection, options, persistTo, replicateTo,
119124
durabilityLevel, cas);
120125
}
121126
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
import org.springframework.data.couchbase.core.ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport;
2121
import org.springframework.data.couchbase.core.query.Query;
22+
import org.springframework.util.Assert;
2223

2324
import com.couchbase.client.java.query.QueryOptions;
2425
import com.couchbase.client.java.query.QueryScanConsistency;
25-
import org.springframework.util.Assert;
2626

2727
public class ExecutableRemoveByQueryOperationSupport implements ExecutableRemoveByQueryOperation {
2828

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

3737
@Override
3838
public <T> ExecutableRemoveByQuery<T> removeByQuery(Class<T> domainType) {
39-
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null, null,
40-
null, null);
39+
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, null, null, null, null);
4140
}
4241

4342
static class ExecutableRemoveByQuerySupport<T> implements ExecutableRemoveByQuery<T> {
@@ -90,7 +89,6 @@ public RemoveByQueryConsistentWith<T> withConsistency(final QueryScanConsistency
9089

9190
@Override
9291
public RemoveByQueryWithConsistency<T> inCollection(final String collection) {
93-
Assert.hasText(collection, "Collection must not be null nor empty.");
9492
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection,
9593
options);
9694
}
@@ -104,7 +102,6 @@ public RemoveByQueryWithQuery<T> withOptions(final QueryOptions options) {
104102

105103
@Override
106104
public RemoveByQueryInCollection<T> inScope(final String scope) {
107-
Assert.hasText(scope, "Scope must not be null nor empty.");
108105
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, scope, collection,
109106
options);
110107
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public Collection<? extends T> all(Collection<? extends T> objects) {
8282

8383
@Override
8484
public ReplaceByIdWithOptions<T> inCollection(final String collection) {
85-
Assert.hasText(collection, "Collection must not be null nor empty.");
8685
return new ExecutableReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo,
8786
replicateTo, durabilityLevel, expiry);
8887
}
@@ -118,7 +117,6 @@ public TerminatingReplaceById<T> withOptions(final ReplaceOptions options) {
118117

119118
@Override
120119
public ReplaceByIdInCollection<T> inScope(final String scope) {
121-
Assert.hasText(scope, "Scope must not be null nor empty.");
122120
return new ExecutableReplaceByIdSupport<>(template, domainType, scope, collection, options, persistTo,
123121
replicateTo, durabilityLevel, expiry);
124122
}

0 commit comments

Comments
 (0)