Skip to content

Commit ce42488

Browse files
committed
DATACOUCH-963 - Scope and Collection API.
Draft of changes for scope and collection API to share with Michael Nitschinger. Some of the mechanisms in this change-set have been ruled out (the proliferation of all the method signatures, for instance). Closes #963 Original pull request: #0000.
1 parent 75ddd5a commit ce42488

File tree

81 files changed

+2090
-413
lines changed

Some content is hidden

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

81 files changed

+2090
-413
lines changed

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
<dependency>
174174
<groupId>io.projectreactor</groupId>
175175
<artifactId>reactor-test</artifactId>
176+
<version>3.1.0.RELEASE</version>
176177
<scope>test</scope>
177178
</dependency>
178179

@@ -284,6 +285,14 @@
284285
<groupId>org.asciidoctor</groupId>
285286
<artifactId>asciidoctor-maven-plugin</artifactId>
286287
</plugin>
288+
<plugin>
289+
<groupId>org.apache.maven.plugins</groupId>
290+
<artifactId>maven-compiler-plugin</artifactId>
291+
<configuration>
292+
<source>8</source>
293+
<target>8</target>
294+
</configuration>
295+
</plugin>
287296
</plugins>
288297
</build>
289298
</project>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.data.couchbase.CouchbaseClientFactory;
2020
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
21+
import org.springframework.data.couchbase.core.support.PseudoArgs;
2122

2223
/**
2324
* Defines common operations on the Couchbase data source, most commonly implemented by {@link CouchbaseTemplate}.
@@ -44,4 +45,9 @@ public interface CouchbaseOperations extends FluentCouchbaseOperations {
4445
*/
4546
CouchbaseClientFactory getCouchbaseClientFactory();
4647

48+
/**
49+
* @param pseudoArgs - the metaArgs to set on the ThreadLocal field of the CouchbaseOperations
50+
*/
51+
void setThrdLocalArgs(PseudoArgs<?> pseudoArgs);
52+
4753
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.data.couchbase.core;
1818

19+
import com.couchbase.client.java.CommonOptions;
1920
import org.springframework.beans.BeansException;
2021
import org.springframework.context.ApplicationContext;
2122
import org.springframework.context.ApplicationContextAware;
@@ -25,6 +26,7 @@
2526
import org.springframework.data.couchbase.core.convert.translation.TranslationService;
2627

2728
import com.couchbase.client.java.Collection;
29+
import org.springframework.data.couchbase.core.support.PseudoArgs;
2830

2931
/**
3032
* Implements lower-level couchbase operations on top of the SDK with entity mapping capabilities.
@@ -47,7 +49,7 @@ public CouchbaseTemplate(final CouchbaseClientFactory clientFactory, final Couch
4749
}
4850

4951
public CouchbaseTemplate(final CouchbaseClientFactory clientFactory, final CouchbaseConverter converter,
50-
final TranslationService translationService) {
52+
final TranslationService translationService) {
5153
this.clientFactory = clientFactory;
5254
this.converter = converter;
5355
this.templateSupport = new CouchbaseTemplateSupport(converter, translationService);
@@ -143,4 +145,13 @@ public void setApplicationContext(final ApplicationContext applicationContext) t
143145
templateSupport.setApplicationContext(applicationContext);
144146
reactiveCouchbaseTemplate.setApplicationContext(applicationContext);
145147
}
148+
149+
/**
150+
* {@inheritDoc}
151+
*/
152+
@Override
153+
public void setThrdLocalArgs(PseudoArgs pseudoArgs) {
154+
reactiveCouchbaseTemplate.setThrdLocalArgs(pseudoArgs);
155+
}
156+
146157
}

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import java.util.Collection;
1919
import java.util.Map;
2020

21+
import com.couchbase.client.java.kv.GetOptions;
2122
import org.springframework.data.couchbase.core.support.OneAndAllExists;
2223
import org.springframework.data.couchbase.core.support.WithCollection;
24+
import org.springframework.data.couchbase.core.support.WithGetOptions;
25+
import org.springframework.data.couchbase.core.support.WithScope;
2326

2427
public interface ExecutableExistsByIdOperation {
2528

@@ -48,16 +51,18 @@ interface TerminatingExistsById extends OneAndAllExists {
4851

4952
}
5053

51-
interface ExistsByIdWithCollection extends TerminatingExistsById, WithCollection {
54+
interface ExistsByIdWithOptions<T> extends TerminatingExistsById, WithGetOptions<T> {
55+
TerminatingExistsById withOptions(GetOptions options);
56+
}
5257

53-
/**
54-
* Allows to specify a different collection than the default one configured.
55-
*
56-
* @param collection the collection to use in this scope.
57-
*/
58-
TerminatingExistsById inCollection(String collection);
58+
interface ExistsByIdWithCollection<T> extends ExistsByIdWithOptions<T>, WithCollection<T> {
59+
ExistsByIdWithOptions<T> inCollection(String collection);
60+
}
61+
62+
interface ExistsByIdWithScope<T> extends ExistsByIdWithCollection<T>, WithScope<T> {
63+
ExistsByIdWithCollection<T> inScope(String collection);
5964
}
6065

61-
interface ExecutableExistsById extends ExistsByIdWithCollection {}
66+
interface ExecutableExistsById extends ExistsByIdWithScope {}
6267

6368
}

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
*/
1616
package org.springframework.data.couchbase.core;
1717

18+
import com.couchbase.client.java.kv.GetOptions;
1819
import org.springframework.data.couchbase.core.ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport;
1920

2021
import java.util.Collection;
2122
import java.util.Map;
2223

23-
import org.springframework.util.Assert;
24-
2524
public class ExecutableExistsByIdOperationSupport implements ExecutableExistsByIdOperation {
2625

2726
private final CouchbaseTemplate template;
@@ -32,17 +31,21 @@ public class ExecutableExistsByIdOperationSupport implements ExecutableExistsByI
3231

3332
@Override
3433
public ExecutableExistsById existsById() {
35-
return new ExecutableExistsByIdSupport(template, null);
34+
return new ExecutableExistsByIdSupport(template, null, null, null);
3635
}
3736

3837
static class ExecutableExistsByIdSupport implements ExecutableExistsById {
3938

4039
private final CouchbaseTemplate template;
40+
private String scope;
41+
private String collection;
42+
private GetOptions options;
43+
4144
private final ReactiveExistsByIdSupport reactiveSupport;
4245

43-
ExecutableExistsByIdSupport(final CouchbaseTemplate template, final String collection) {
46+
ExecutableExistsByIdSupport(final CouchbaseTemplate template, final String scope, final String collection, final GetOptions options) {
4447
this.template = template;
45-
this.reactiveSupport = new ReactiveExistsByIdSupport(template.reactive(), collection);
48+
this.reactiveSupport = new ReactiveExistsByIdSupport(template.reactive(), scope, collection, options);
4649
}
4750

4851
@Override
@@ -56,11 +59,19 @@ public Map<String, Boolean> all(final Collection<String> ids) {
5659
}
5760

5861
@Override
59-
public TerminatingExistsById inCollection(final String collection) {
60-
Assert.hasText(collection, "Collection must not be null nor empty.");
61-
return new ExecutableExistsByIdSupport(template, collection);
62+
public ExistsByIdWithOptions inCollection(final String collection) {
63+
return new ExecutableExistsByIdSupport(template, scope, collection, options);
6264
}
6365

66+
@Override
67+
public TerminatingExistsById withOptions(GetOptions options) {
68+
return new ExecutableExistsByIdSupport(template, scope, collection, options);
69+
}
70+
71+
@Override
72+
public ExistsByIdWithCollection inScope(String collection) {
73+
return new ExecutableExistsByIdSupport(template, scope, collection, options);
74+
}
6475
}
6576

6677
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919
import java.util.Optional;
2020
import java.util.stream.Stream;
2121

22+
import com.couchbase.client.java.analytics.AnalyticsOptions;
23+
import com.couchbase.client.java.query.QueryOptions;
2224
import org.springframework.dao.IncorrectResultSizeDataAccessException;
2325
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
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;
30+
import org.springframework.data.couchbase.core.support.WithCollection;
31+
import org.springframework.data.couchbase.core.support.WithQueryOptions;
32+
import org.springframework.data.couchbase.core.support.WithScope;
2733
import org.springframework.lang.Nullable;
2834

2935
import com.couchbase.client.java.analytics.AnalyticsScanConsistency;
@@ -117,8 +123,20 @@ interface FindByAnalyticsWithQuery<T> extends TerminatingFindByAnalytics<T>, Wit
117123

118124
}
119125

126+
interface FindByAnalyticsWithOptions<T> extends FindByAnalyticsWithQuery<T>, WithAnalyticsOptions<T> {
127+
FindByAnalyticsWithQuery<T> withOptions(AnalyticsOptions options);
128+
}
129+
130+
interface FindByAnalyticsInCollection<T> extends FindByAnalyticsWithOptions<T>, WithCollection<T> {
131+
FindByAnalyticsWithOptions<T> inCollection(String collection);
132+
}
133+
134+
interface FindByAnalyticsWithScope<T> extends FindByAnalyticsInCollection<T>, WithScope<T> {
135+
FindByAnalyticsInCollection<T> inScope(String collection);
136+
}
137+
120138
@Deprecated
121-
interface FindByAnalyticsConsistentWith<T> extends FindByAnalyticsWithQuery<T> {
139+
interface FindByAnalyticsConsistentWith<T> extends FindByAnalyticsWithScope<T> {
122140

123141
/**
124142
* Allows to override the default scan consistency.

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

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
package org.springframework.data.couchbase.core;
1717

1818
import java.util.List;
19+
import java.util.Optional;
1920
import java.util.stream.Stream;
2021

22+
import com.couchbase.client.java.analytics.AnalyticsOptions;
23+
import com.couchbase.client.java.query.QueryOptions;
2124
import org.springframework.data.couchbase.core.ReactiveFindByAnalyticsOperationSupport.ReactiveFindByAnalyticsSupport;
2225
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
2326

@@ -35,26 +38,36 @@ public ExecutableFindByAnalyticsOperationSupport(final CouchbaseTemplate templat
3538

3639
@Override
3740
public <T> ExecutableFindByAnalytics<T> findByAnalytics(final Class<T> domainType) {
38-
return new ExecutableFindByAnalyticsSupport<>(template, domainType, ALL_QUERY,
39-
AnalyticsScanConsistency.NOT_BOUNDED);
41+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, domainType, ALL_QUERY, null, null, null, null, null);
4042
}
4143

4244
static class ExecutableFindByAnalyticsSupport<T> implements ExecutableFindByAnalytics<T> {
4345

4446
private final CouchbaseTemplate template;
45-
private final Class<T> domainType;
47+
private final Class<?> domainType;
48+
private final Class<T> returnType;
4649
private final ReactiveFindByAnalyticsSupport<T> reactiveSupport;
4750
private final AnalyticsQuery query;
4851
private final AnalyticsScanConsistency scanConsistency;
49-
50-
ExecutableFindByAnalyticsSupport(final CouchbaseTemplate template, final Class<T> domainType,
51-
final AnalyticsQuery query, final AnalyticsScanConsistency scanConsistency) {
52+
private final String scope;
53+
private final String collection;
54+
private final AnalyticsOptions options;
55+
private final String[] distinctFields;
56+
57+
ExecutableFindByAnalyticsSupport(final CouchbaseTemplate template, final Class<?> domainType,
58+
final Class<T> returnType, final AnalyticsQuery query, final AnalyticsScanConsistency scanConsistency,
59+
final String scope, final String collection, final AnalyticsOptions options, String[] distinctFields) {
5260
this.template = template;
5361
this.domainType = domainType;
62+
this.returnType = returnType;
5463
this.query = query;
55-
this.reactiveSupport = new ReactiveFindByAnalyticsSupport<>(template.reactive(), domainType, query,
56-
scanConsistency);
64+
this.reactiveSupport = new ReactiveFindByAnalyticsSupport<>(template.reactive(), domainType, returnType, query,
65+
scanConsistency, scope, collection, options, distinctFields);
5766
this.scanConsistency = scanConsistency;
67+
this.scope = scope;
68+
this.collection = collection;
69+
this.options = options;
70+
this.distinctFields = distinctFields;
5871
}
5972

6073
@Override
@@ -74,18 +87,38 @@ public List<T> all() {
7487

7588
@Override
7689
public TerminatingFindByAnalytics<T> matching(final AnalyticsQuery query) {
77-
return new ExecutableFindByAnalyticsSupport<>(template, domainType, query, scanConsistency);
90+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
91+
collection, options, distinctFields);
92+
}
93+
94+
@Override
95+
public FindByAnalyticsWithQuery<T> withOptions(AnalyticsOptions options) {
96+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
97+
collection, options, distinctFields);
98+
}
99+
100+
@Override
101+
public FindByAnalyticsInCollection<T> inScope(String scope) {
102+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
103+
collection, options, distinctFields);
78104
}
79105

106+
@Override
107+
public FindByAnalyticsWithConsistency<T> inCollection(final String collection) {
108+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
109+
collection, options, distinctFields);
110+
}
80111
@Override
81112
@Deprecated
82113
public FindByAnalyticsWithQuery<T> consistentWith(final AnalyticsScanConsistency scanConsistency) {
83-
return new ExecutableFindByAnalyticsSupport<>(template, domainType, query, scanConsistency);
114+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
115+
collection, options, distinctFields);
84116
}
85117

86118
@Override
87119
public FindByAnalyticsWithConsistency<T> withConsistency(final AnalyticsScanConsistency scanConsistency) {
88-
return new ExecutableFindByAnalyticsSupport<>(template, domainType, query, scanConsistency);
120+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, returnType, query, scanConsistency, scope,
121+
collection, options, distinctFields);
89122
}
90123

91124
@Override
@@ -103,6 +136,7 @@ public boolean exists() {
103136
return count() > 0;
104137
}
105138

139+
106140
}
107141

108142
}

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717

1818
import java.util.Collection;
1919

20+
import com.couchbase.client.java.CommonOptions;
21+
import com.couchbase.client.java.kv.GetOptions;
2022
import org.springframework.data.couchbase.core.support.OneAndAllId;
2123
import org.springframework.data.couchbase.core.support.WithCollection;
24+
import org.springframework.data.couchbase.core.support.WithGetOptions;
2225
import org.springframework.data.couchbase.core.support.WithProjectionId;
26+
import org.springframework.data.couchbase.core.support.WithReplaceOptions;
27+
import org.springframework.data.couchbase.core.support.WithScope;
2328

2429
public interface ExecutableFindByIdOperation {
2530

@@ -50,25 +55,26 @@ interface TerminatingFindById<T> extends OneAndAllId<T> {
5055

5156
}
5257

53-
interface FindByIdWithCollection<T> extends TerminatingFindById<T>, WithCollection<T> {
58+
interface FindByIdWithOptions<T> extends TerminatingFindById<T>, WithGetOptions<T> {
59+
TerminatingFindById<T> withOptions(GetOptions options);
60+
}
5461

55-
/**
56-
* Allows to specify a different collection than the default one configured.
57-
*
58-
* @param collection the collection to use in this scope.
59-
*/
60-
TerminatingFindById<T> inCollection(String collection);
62+
interface FindByIdWithCollection<T> extends FindByIdWithOptions<T>, WithCollection<T> {
63+
FindByIdWithOptions<T> inCollection(String collection);
64+
}
6165

62-
}
66+
interface FindByIdWithScope<T> extends FindByIdWithCollection<T>, WithScope<T> {
67+
FindByIdWithCollection<T> inScope(String collection);
68+
}
6369

64-
interface FindByIdWithProjection<T> extends FindByIdWithCollection<T>, WithProjectionId<T> {
70+
interface FindByIdWithProjection<T> extends FindByIdWithScope<T>, WithProjectionId<T> {
6571

6672
/**
6773
* Load only certain fields for the document.
6874
*
6975
* @param fields the projected fields to load.
7076
*/
71-
FindByIdWithCollection<T> project(String... fields);
77+
FindByIdWithScope<T> project(String... fields);
7278

7379
}
7480

0 commit comments

Comments
 (0)