Skip to content

Commit 43889e6

Browse files
authored
Scope and collection API for template. (#1133)
Scope and Collection API for template. Closes #963. Original pull request: #1071.
1 parent 5cf142d commit 43889e6

File tree

92 files changed

+4608
-727
lines changed

Some content is hidden

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

92 files changed

+4608
-727
lines changed

pom.xml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
</properties>
2626

2727
<dependencyManagement>
28-
<dependencies>
29-
<dependency>
30-
<groupId>org.testcontainers</groupId>
31-
<artifactId>testcontainers-bom</artifactId>
32-
<version>${testcontainers}</version>
33-
<type>pom</type>
34-
<scope>import</scope>
35-
</dependency>
36-
</dependencies>
37-
</dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.testcontainers</groupId>
31+
<artifactId>testcontainers-bom</artifactId>
32+
<version>${testcontainers}</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
3838

3939
<dependencies>
4040
<dependency>
@@ -88,7 +88,7 @@
8888
<dependency>
8989
<groupId>io.projectreactor</groupId>
9090
<artifactId>reactor-test</artifactId>
91-
<version>3.1.0.RELEASE</version>
91+
<version>3.4.6</version>
9292
<scope>test</scope>
9393
</dependency>
9494

@@ -170,12 +170,6 @@
170170
<scope>test</scope>
171171
</dependency>
172172

173-
<dependency>
174-
<groupId>io.projectreactor</groupId>
175-
<artifactId>reactor-test</artifactId>
176-
<scope>test</scope>
177-
</dependency>
178-
179173
<!-- Kotlin extension -->
180174
<dependency>
181175
<groupId>org.jetbrains.kotlin</groupId>

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
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;
3132
import org.springframework.data.mapping.context.MappingContext;
3233
import org.springframework.lang.Nullable;
3334

@@ -60,14 +61,14 @@ public CouchbaseTemplate(final CouchbaseClientFactory clientFactory, final Couch
6061
this.converter = converter;
6162
this.templateSupport = new CouchbaseTemplateSupport(converter, translationService);
6263
this.reactiveCouchbaseTemplate = new ReactiveCouchbaseTemplate(clientFactory, converter, translationService);
63-
64+
6465
this.mappingContext = this.converter.getMappingContext();
65-
if (mappingContext instanceof CouchbaseMappingContext) {
66-
CouchbaseMappingContext cmc = (CouchbaseMappingContext) mappingContext;
67-
if (cmc.isAutoIndexCreation()) {
68-
indexCreator = new CouchbasePersistentEntityIndexCreator(cmc, this);
69-
}
70-
}
66+
if (mappingContext instanceof CouchbaseMappingContext) {
67+
CouchbaseMappingContext cmc = (CouchbaseMappingContext) mappingContext;
68+
if (cmc.isAutoIndexCreation()) {
69+
indexCreator = new CouchbasePersistentEntityIndexCreator(cmc, this);
70+
}
71+
}
7172
}
7273

7374
@Override
@@ -184,4 +185,5 @@ private void prepareIndexCreator(final ApplicationContext context) {
184185
TemplateSupport support() {
185186
return templateSupport;
186187
}
188+
187189
}

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

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors
2+
* Copyright 2012-2021 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,16 +18,29 @@
1818
import java.util.Collection;
1919
import java.util.Map;
2020

21+
import org.springframework.data.couchbase.core.support.InCollection;
22+
import org.springframework.data.couchbase.core.support.InScope;
2123
import org.springframework.data.couchbase.core.support.OneAndAllExists;
22-
import org.springframework.data.couchbase.core.support.WithCollection;
24+
import org.springframework.data.couchbase.core.support.WithExistsOptions;
2325

26+
import com.couchbase.client.java.kv.ExistsOptions;
27+
28+
/**
29+
* Insert Operations
30+
*
31+
* @author Christoph Strobl
32+
* @since 2.0
33+
*/
2434
public interface ExecutableExistsByIdOperation {
2535

2636
/**
2737
* Checks if the document exists in the bucket.
2838
*/
2939
ExecutableExistsById existsById();
3040

41+
/**
42+
* Terminating operations invoking the actual execution.
43+
*/
3144
interface TerminatingExistsById extends OneAndAllExists {
3245

3346
/**
@@ -36,6 +49,7 @@ interface TerminatingExistsById extends OneAndAllExists {
3649
* @param id the ID to perform the operation on.
3750
* @return true if the document exists, false otherwise.
3851
*/
52+
@Override
3953
boolean one(String id);
4054

4155
/**
@@ -44,20 +58,59 @@ interface TerminatingExistsById extends OneAndAllExists {
4458
* @param ids the ids to check.
4559
* @return a map consisting of the document IDs as the keys and if they exist as the value.
4660
*/
61+
@Override
4762
Map<String, Boolean> all(Collection<String> ids);
63+
}
4864

65+
/**
66+
* Fluent method to specify options.
67+
*
68+
* @param <T> the entity type to use for the results.
69+
*/
70+
interface ExistsByIdWithOptions<T> extends TerminatingExistsById, WithExistsOptions<T> {
71+
/**
72+
* Fluent method to specify options to use for execution
73+
*
74+
* @param options options to use for execution
75+
*/
76+
@Override
77+
TerminatingExistsById withOptions(ExistsOptions options);
4978
}
5079

51-
interface ExistsByIdWithCollection extends TerminatingExistsById, WithCollection {
80+
/**
81+
*
82+
* Fluent method to specify the collection.
83+
*
84+
* @param <T> the entity type to use for the results.
85+
*/
86+
interface ExistsByIdInCollection<T> extends ExistsByIdWithOptions<T>, InCollection<T> {
87+
/**
88+
* With a different collection
89+
*
90+
* @param collection the collection to use.
91+
*/
92+
@Override
93+
ExistsByIdWithOptions<T> inCollection(String collection);
94+
}
5295

96+
/**
97+
* Fluent method to specify the scope.
98+
*
99+
* @param <T> the entity type to use for the results.
100+
*/
101+
interface ExistsByIdInScope<T> extends ExistsByIdInCollection<T>, InScope<T> {
53102
/**
54-
* Allows to specify a different collection than the default one configured.
103+
* With a different scope
55104
*
56-
* @param collection the collection to use in this scope.
105+
* @param scope the scope to use.
57106
*/
58-
TerminatingExistsById inCollection(String collection);
107+
@Override
108+
ExistsByIdInCollection<T> inScope(String scope);
59109
}
60110

61-
interface ExecutableExistsById extends ExistsByIdWithCollection {}
111+
/**
112+
* Provides methods for constructing KV exists operations in a fluent way.
113+
*/
114+
interface ExecutableExistsById extends ExistsByIdInScope {}
62115

63116
}

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors
2+
* Copyright 2012-2021 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.
@@ -15,13 +15,14 @@
1515
*/
1616
package org.springframework.data.couchbase.core;
1717

18-
import org.springframework.data.couchbase.core.ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport;
19-
2018
import java.util.Collection;
2119
import java.util.Map;
2220

21+
import org.springframework.data.couchbase.core.ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport;
2322
import org.springframework.util.Assert;
2423

24+
import com.couchbase.client.java.kv.ExistsOptions;
25+
2526
public class ExecutableExistsByIdOperationSupport implements ExecutableExistsByIdOperation {
2627

2728
private final CouchbaseTemplate template;
@@ -32,17 +33,25 @@ public class ExecutableExistsByIdOperationSupport implements ExecutableExistsByI
3233

3334
@Override
3435
public ExecutableExistsById existsById() {
35-
return new ExecutableExistsByIdSupport(template, null);
36+
return new ExecutableExistsByIdSupport(template, null, null, null);
3637
}
3738

3839
static class ExecutableExistsByIdSupport implements ExecutableExistsById {
3940

4041
private final CouchbaseTemplate template;
42+
private final String scope;
43+
private final String collection;
44+
private final ExistsOptions options;
45+
4146
private final ReactiveExistsByIdSupport reactiveSupport;
4247

43-
ExecutableExistsByIdSupport(final CouchbaseTemplate template, final String collection) {
48+
ExecutableExistsByIdSupport(final CouchbaseTemplate template, final String scope, final String collection,
49+
final ExistsOptions options) {
4450
this.template = template;
45-
this.reactiveSupport = new ReactiveExistsByIdSupport(template.reactive(), collection);
51+
this.scope = scope;
52+
this.collection = collection;
53+
this.options = options;
54+
this.reactiveSupport = new ReactiveExistsByIdSupport(template.reactive(), scope, collection, options);
4655
}
4756

4857
@Override
@@ -56,11 +65,22 @@ public Map<String, Boolean> all(final Collection<String> ids) {
5665
}
5766

5867
@Override
59-
public TerminatingExistsById inCollection(final String collection) {
68+
public ExistsByIdWithOptions inCollection(final String collection) {
6069
Assert.hasText(collection, "Collection must not be null nor empty.");
61-
return new ExecutableExistsByIdSupport(template, collection);
70+
return new ExecutableExistsByIdSupport(template, scope, collection, options);
6271
}
6372

73+
@Override
74+
public TerminatingExistsById withOptions(final ExistsOptions options) {
75+
Assert.notNull(options, "Options must not be null.");
76+
return new ExecutableExistsByIdSupport(template, scope, collection, options);
77+
}
78+
79+
@Override
80+
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);
83+
}
6484
}
6585

6686
}

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

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors
2+
* Copyright 2012-2021 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,14 +21,23 @@
2121

2222
import org.springframework.dao.IncorrectResultSizeDataAccessException;
2323
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
24+
import org.springframework.data.couchbase.core.support.InCollection;
25+
import org.springframework.data.couchbase.core.support.InScope;
2426
import org.springframework.data.couchbase.core.support.OneAndAll;
2527
import org.springframework.data.couchbase.core.support.WithAnalyticsConsistency;
28+
import org.springframework.data.couchbase.core.support.WithAnalyticsOptions;
2629
import org.springframework.data.couchbase.core.support.WithAnalyticsQuery;
2730
import org.springframework.lang.Nullable;
2831

32+
import com.couchbase.client.java.analytics.AnalyticsOptions;
2933
import com.couchbase.client.java.analytics.AnalyticsScanConsistency;
3034

31-
public interface ExecutableFindByAnalyticsOperation {
35+
/**
36+
* FindByAnalytics Operations
37+
*
38+
* @author Christoph Strobl
39+
* @since 2.0
40+
*/public interface ExecutableFindByAnalyticsOperation {
3241

3342
/**
3443
* Queries the analytics service.
@@ -117,8 +126,53 @@ interface FindByAnalyticsWithQuery<T> extends TerminatingFindByAnalytics<T>, Wit
117126

118127
}
119128

129+
/**
130+
* Fluent method to specify options.
131+
*
132+
* @param <T> the entity type to use.
133+
*/
134+
interface FindByAnalyticsWithOptions<T> extends FindByAnalyticsWithQuery<T>, WithAnalyticsOptions<T> {
135+
/**
136+
* Fluent method to specify options to use for execution
137+
*
138+
* @param options to use for execution
139+
*/
140+
@Override
141+
FindByAnalyticsWithQuery<T> withOptions(AnalyticsOptions options);
142+
}
143+
144+
/**
145+
* Fluent method to specify the collection.
146+
*
147+
* @param <T> the entity type to use for the results.
148+
*/
149+
interface FindByAnalyticsInCollection<T> extends FindByAnalyticsWithOptions<T>, InCollection<T> {
150+
/**
151+
* With a different collection
152+
*
153+
* @param collection the collection to use.
154+
*/
155+
@Override
156+
FindByAnalyticsWithOptions<T> inCollection(String collection);
157+
}
158+
159+
/**
160+
* Fluent method to specify the scope.
161+
*
162+
* @param <T> the entity type to use for the results.
163+
*/
164+
interface FindByAnalyticsInScope<T> extends FindByAnalyticsInCollection<T>, InScope<T> {
165+
/**
166+
* With a different scope
167+
*
168+
* @param scope the scope to use.
169+
*/
170+
@Override
171+
FindByAnalyticsInCollection<T> inScope(String scope);
172+
}
173+
120174
@Deprecated
121-
interface FindByAnalyticsConsistentWith<T> extends FindByAnalyticsWithQuery<T> {
175+
interface FindByAnalyticsConsistentWith<T> extends FindByAnalyticsInScope<T> {
122176

123177
/**
124178
* Allows to override the default scan consistency.
@@ -138,9 +192,24 @@ interface FindByAnalyticsWithConsistency<T> extends FindByAnalyticsConsistentWit
138192
* @param scanConsistency the custom scan consistency to use for this analytics query.
139193
*/
140194
FindByAnalyticsConsistentWith<T> withConsistency(AnalyticsScanConsistency scanConsistency);
195+
}
196+
197+
/**
198+
* Result type override (Optional).
199+
*/
200+
interface FindByAnalyticsWithProjection<T> extends FindByAnalyticsWithConsistency<T> {
141201

202+
/**
203+
* Define the target type fields should be mapped to. <br />
204+
* Skip this step if you are anyway only interested in the original domain type.
205+
*
206+
* @param returnType must not be {@literal null}.
207+
* @return new instance of {@link FindByAnalyticsWithConsistency}.
208+
* @throws IllegalArgumentException if returnType is {@literal null}.
209+
*/
210+
<R> FindByAnalyticsWithConsistency<R> as(Class<R> returnType);
142211
}
143212

144-
interface ExecutableFindByAnalytics<T> extends FindByAnalyticsWithConsistency<T> {}
213+
interface ExecutableFindByAnalytics<T> extends FindByAnalyticsWithProjection<T> {}
145214

146215
}

0 commit comments

Comments
 (0)