Skip to content

Commit 570792d

Browse files
committed
DATACOUCH-588 - Refactoring part 1 of n. (#278)
* DATACOUCH-588 - Implement pageable and realign repo query This implements pageable for non-reactive queries and realigns reactive queries with other spring-data projects to facilitate the implementaion of pageable (done) and other types of queries such as projection and distinct (not yet done) * DATACOUCH-588 - Implement pageable and realign repo query This implements pageable for non-reactive queries and realigns reactive queries with other spring-data projects to facilitate the implementaion of pageable (done) and other types of queries such as projection and distinct (not yet done) * DATACOUCH-588 - Refactoring part 1 of n. Co-authored-by: mikereiche <[email protected]>
1 parent f65bd6a commit 570792d

File tree

59 files changed

+2397
-237
lines changed

Some content is hidden

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

59 files changed

+2397
-237
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
<scope>test</scope>
8686
</dependency>
8787

88+
<dependency>
89+
<groupId>io.projectreactor</groupId>
90+
<artifactId>reactor-test</artifactId>
91+
<version>3.1.0.RELEASE</version>
92+
<scope>test</scope>
93+
</dependency>
94+
8895
<dependency>
8996
<groupId>com.fasterxml.jackson.core</groupId>
9097
<artifactId>jackson-databind</artifactId>

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

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

18+
import org.springframework.data.couchbase.core.ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport;
19+
1820
import java.util.Collection;
1921
import java.util.Map;
2022

@@ -36,12 +38,11 @@ public ExecutableExistsById existsById() {
3638
static class ExecutableExistsByIdSupport implements ExecutableExistsById {
3739

3840
private final CouchbaseTemplate template;
39-
private final ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport reactiveSupport;
41+
private final ReactiveExistsByIdSupport reactiveSupport;
4042

4143
ExecutableExistsByIdSupport(final CouchbaseTemplate template, final String collection) {
4244
this.template = template;
43-
this.reactiveSupport = new ReactiveExistsByIdOperationSupport.ReactiveExistsByIdSupport(template.reactive(),
44-
collection);
45+
this.reactiveSupport = new ReactiveExistsByIdSupport(template.reactive(), collection);
4546
}
4647

4748
@Override

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

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

18+
import org.springframework.data.couchbase.core.ReactiveFindByAnalyticsOperationSupport.ReactiveFindByAnalyticsSupport;
19+
1820
import java.util.List;
1921
import java.util.stream.Stream;
2022

21-
import com.couchbase.client.java.analytics.AnalyticsScanConsistency;
22-
import com.couchbase.client.java.query.QueryScanConsistency;
2323
import org.springframework.data.couchbase.core.query.AnalyticsQuery;
24-
import org.springframework.data.couchbase.core.query.Query;
24+
25+
import com.couchbase.client.java.analytics.AnalyticsScanConsistency;
2526

2627
public class ExecutableFindByAnalyticsOperationSupport implements ExecutableFindByAnalyticsOperation {
2728

@@ -35,14 +36,15 @@ public ExecutableFindByAnalyticsOperationSupport(final CouchbaseTemplate templat
3536

3637
@Override
3738
public <T> ExecutableFindByAnalytics<T> findByAnalytics(final Class<T> domainType) {
38-
return new ExecutableFindByAnalyticsSupport<>(template, domainType, ALL_QUERY, AnalyticsScanConsistency.NOT_BOUNDED);
39+
return new ExecutableFindByAnalyticsSupport<>(template, domainType, ALL_QUERY,
40+
AnalyticsScanConsistency.NOT_BOUNDED);
3941
}
4042

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

4345
private final CouchbaseTemplate template;
4446
private final Class<T> domainType;
45-
private final ReactiveFindByAnalyticsOperationSupport.ReactiveFindByAnalyticsSupport<T> reactiveSupport;
47+
private final ReactiveFindByAnalyticsSupport<T> reactiveSupport;
4648
private final AnalyticsQuery query;
4749
private final AnalyticsScanConsistency scanConsistency;
4850

@@ -51,8 +53,8 @@ static class ExecutableFindByAnalyticsSupport<T> implements ExecutableFindByAnal
5153
this.template = template;
5254
this.domainType = domainType;
5355
this.query = query;
54-
this.reactiveSupport = new ReactiveFindByAnalyticsOperationSupport.ReactiveFindByAnalyticsSupport<>(
55-
template.reactive(), domainType, query, scanConsistency);
56+
this.reactiveSupport = new ReactiveFindByAnalyticsSupport<>(template.reactive(), domainType, query,
57+
scanConsistency);
5658
this.scanConsistency = scanConsistency;
5759
}
5860

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

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

18+
import org.springframework.data.couchbase.core.ReactiveFindByIdOperationSupport.ReactiveFindByIdSupport;
19+
1820
import java.util.Arrays;
1921
import java.util.Collection;
2022
import java.util.List;
@@ -40,15 +42,14 @@ static class ExecutableFindByIdSupport<T> implements ExecutableFindById<T> {
4042
private final Class<T> domainType;
4143
private final String collection;
4244
private final List<String> fields;
43-
private final ReactiveFindByIdOperationSupport.ReactiveFindByIdSupport<T> reactiveSupport;
45+
private final ReactiveFindByIdSupport<T> reactiveSupport;
4446

4547
ExecutableFindByIdSupport(CouchbaseTemplate template, Class<T> domainType, String collection, List<String> fields) {
4648
this.template = template;
4749
this.domainType = domainType;
4850
this.collection = collection;
4951
this.fields = fields;
50-
this.reactiveSupport = new ReactiveFindByIdOperationSupport.ReactiveFindByIdSupport<>(template.reactive(),
51-
domainType, collection, fields);
52+
this.reactiveSupport = new ReactiveFindByIdSupport<>(template.reactive(), domainType, collection, fields);
5253
}
5354

5455
@Override

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ interface FindByQueryConsistentWith<T> extends FindByQueryWithQuery<T> {
130130

131131
}
132132

133-
interface ExecutableFindByQuery<T> extends FindByQueryConsistentWith<T> {}
133+
interface FindByQueryInCollection<T> extends FindByQueryConsistentWith<T> {
134+
135+
/**
136+
* Allows to override the default scan consistency.
137+
*
138+
* @param collection the collection to use for this query.
139+
*/
140+
FindByQueryInCollection<T> inCollection(String collection);
141+
142+
}
143+
144+
interface ExecutableFindByQuery<T> extends FindByQueryInCollection<T> {}
134145

135146
}

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@
1818
import java.util.List;
1919
import java.util.stream.Stream;
2020

21+
import org.springframework.data.couchbase.core.ReactiveFindByQueryOperationSupport.ReactiveFindByQuerySupport;
2122
import org.springframework.data.couchbase.core.query.Query;
2223

2324
import com.couchbase.client.java.query.QueryScanConsistency;
24-
import org.springframework.data.couchbase.core.ReactiveFindByQueryOperationSupport.ReactiveFindByQuerySupport;
2525

26+
/**
27+
* {@link ExecutableFindByQueryOperation} implementations for Couchbase.
28+
*
29+
* @author Michael Nitschinger
30+
* @author Michael Reiche
31+
*/
2632
public class ExecutableFindByQueryOperationSupport implements ExecutableFindByQueryOperation {
2733

2834
private static final Query ALL_QUERY = new Query();
@@ -35,24 +41,28 @@ public ExecutableFindByQueryOperationSupport(final CouchbaseTemplate template) {
3541

3642
@Override
3743
public <T> ExecutableFindByQuery<T> findByQuery(final Class<T> domainType) {
38-
return new ExecutableFindByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED);
44+
return new ExecutableFindByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED,
45+
"_default._default");
3946
}
4047

4148
static class ExecutableFindByQuerySupport<T> implements ExecutableFindByQuery<T> {
4249

4350
private final CouchbaseTemplate template;
4451
private final Class<T> domainType;
4552
private final Query query;
46-
private final ReactiveFindByQueryOperationSupport.ReactiveFindByQuerySupport<T> reactiveSupport;
53+
private final ReactiveFindByQuerySupport<T> reactiveSupport;
4754
private final QueryScanConsistency scanConsistency;
55+
private final String collection;
4856

4957
ExecutableFindByQuerySupport(final CouchbaseTemplate template, final Class<T> domainType, final Query query,
50-
final QueryScanConsistency scanConsistency) {
58+
final QueryScanConsistency scanConsistency, final String collection) {
5159
this.template = template;
5260
this.domainType = domainType;
5361
this.query = query;
54-
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(), domainType, query, scanConsistency);
62+
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(), domainType, query, scanConsistency,
63+
collection);
5564
this.scanConsistency = scanConsistency;
65+
this.collection = collection;
5666
}
5767

5868
@Override
@@ -78,12 +88,17 @@ public TerminatingFindByQuery<T> matching(final Query query) {
7888
} else {
7989
scanCons = scanConsistency;
8090
}
81-
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanCons);
91+
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanCons, collection);
8292
}
8393

8494
@Override
8595
public FindByQueryConsistentWith<T> consistentWith(final QueryScanConsistency scanConsistency) {
86-
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanConsistency);
96+
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanConsistency, collection);
97+
}
98+
99+
@Override
100+
public FindByQueryInCollection<T> inCollection(final String collection) {
101+
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanConsistency, collection);
87102
}
88103

89104
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.Collection;
1919

20+
import org.springframework.data.couchbase.core.ReactiveFindFromReplicasByIdOperationSupport.ReactiveFindFromReplicasByIdSupport;
2021
import org.springframework.util.Assert;
2122

2223
public class ExecutableFindFromReplicasByIdOperationSupport implements ExecutableFindFromReplicasByIdOperation {
@@ -37,14 +38,13 @@ static class ExecutableFindFromReplicasByIdSupport<T> implements ExecutableFindF
3738
private final CouchbaseTemplate template;
3839
private final Class<T> domainType;
3940
private final String collection;
40-
private final ReactiveFindFromReplicasByIdOperationSupport.ReactiveFindFromReplicasByIdSupport<T> reactiveSupport;
41+
private final ReactiveFindFromReplicasByIdSupport<T> reactiveSupport;
4142

4243
ExecutableFindFromReplicasByIdSupport(CouchbaseTemplate template, Class<T> domainType, String collection) {
4344
this.template = template;
4445
this.domainType = domainType;
4546
this.collection = collection;
46-
this.reactiveSupport = new ReactiveFindFromReplicasByIdOperationSupport.ReactiveFindFromReplicasByIdSupport<>(
47-
template.reactive(), domainType, collection);
47+
this.reactiveSupport = new ReactiveFindFromReplicasByIdSupport<>(template.reactive(), domainType, collection);
4848
}
4949

5050
@Override

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.time.Duration;
1919
import java.util.Collection;
2020

21+
import org.springframework.data.couchbase.core.ReactiveInsertByIdOperationSupport.ReactiveInsertByIdSupport;
2122
import org.springframework.util.Assert;
2223

2324
import com.couchbase.client.core.msg.kv.DurabilityLevel;
@@ -48,7 +49,7 @@ static class ExecutableInsertByIdSupport<T> implements ExecutableInsertById<T> {
4849
private final ReplicateTo replicateTo;
4950
private final DurabilityLevel durabilityLevel;
5051
private final Duration expiry;
51-
private final ReactiveInsertByIdOperationSupport.ReactiveInsertByIdSupport<T> reactiveSupport;
52+
private final ReactiveInsertByIdSupport<T> reactiveSupport;
5253

5354
ExecutableInsertByIdSupport(final CouchbaseTemplate template, final Class<T> domainType, final String collection,
5455
final PersistTo persistTo, final ReplicateTo replicateTo, final DurabilityLevel durabilityLevel,
@@ -60,8 +61,8 @@ static class ExecutableInsertByIdSupport<T> implements ExecutableInsertById<T> {
6061
this.replicateTo = replicateTo;
6162
this.durabilityLevel = durabilityLevel;
6263
this.expiry = expiry;
63-
this.reactiveSupport = new ReactiveInsertByIdOperationSupport.ReactiveInsertByIdSupport<>(template.reactive(),
64-
domainType, collection, persistTo, replicateTo, durabilityLevel, expiry);
64+
this.reactiveSupport = new ReactiveInsertByIdSupport<>(template.reactive(), domainType, collection, persistTo,
65+
replicateTo, durabilityLevel, expiry);
6566
}
6667

6768
@Override

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

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

21+
import org.springframework.data.couchbase.core.ReactiveRemoveByIdOperationSupport.ReactiveRemoveByIdSupport;
2122
import org.springframework.util.Assert;
2223

2324
import com.couchbase.client.core.msg.kv.DurabilityLevel;
@@ -44,7 +45,7 @@ static class ExecutableRemoveByIdSupport implements ExecutableRemoveById {
4445
private final PersistTo persistTo;
4546
private final ReplicateTo replicateTo;
4647
private final DurabilityLevel durabilityLevel;
47-
private final ReactiveRemoveByIdOperationSupport.ReactiveRemoveByIdSupport reactiveRemoveByIdSupport;
48+
private final ReactiveRemoveByIdSupport reactiveRemoveByIdSupport;
4849

4950
ExecutableRemoveByIdSupport(final CouchbaseTemplate template, final String collection, final PersistTo persistTo,
5051
final ReplicateTo replicateTo, final DurabilityLevel durabilityLevel) {
@@ -53,8 +54,8 @@ static class ExecutableRemoveByIdSupport implements ExecutableRemoveById {
5354
this.persistTo = persistTo;
5455
this.replicateTo = replicateTo;
5556
this.durabilityLevel = durabilityLevel;
56-
this.reactiveRemoveByIdSupport = new ReactiveRemoveByIdOperationSupport.ReactiveRemoveByIdSupport(
57-
template.reactive(), collection, persistTo, replicateTo, durabilityLevel);
57+
this.reactiveRemoveByIdSupport = new ReactiveRemoveByIdSupport(template.reactive(), collection, persistTo,
58+
replicateTo, durabilityLevel);
5859
}
5960

6061
@Override

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ interface RemoveByQueryConsistentWith<T> extends RemoveByQueryWithQuery<T> {
4343

4444
}
4545

46-
interface ExecutableRemoveByQuery<T> extends RemoveByQueryConsistentWith<T> {}
46+
interface RemoveByQueryInCollection<T> extends RemoveByQueryConsistentWith<T> {
47+
48+
RemoveByQueryConsistentWith<T> inCollection(String collection);
49+
50+
}
51+
52+
interface ExecutableRemoveByQuery<T> extends RemoveByQueryInCollection<T> {}
4753

4854
}

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.List;
1919

20+
import org.springframework.data.couchbase.core.ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport;
2021
import org.springframework.data.couchbase.core.query.Query;
2122

2223
import com.couchbase.client.java.query.QueryScanConsistency;
@@ -33,25 +34,28 @@ public ExecutableRemoveByQueryOperationSupport(final CouchbaseTemplate template)
3334

3435
@Override
3536
public <T> ExecutableRemoveByQuery<T> removeByQuery(Class<T> domainType) {
36-
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED);
37+
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED,
38+
"_default._default");
3739
}
3840

3941
static class ExecutableRemoveByQuerySupport<T> implements ExecutableRemoveByQuery<T> {
4042

4143
private final CouchbaseTemplate template;
4244
private final Class<T> domainType;
4345
private final Query query;
44-
private final ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport<T> reactiveSupport;
46+
private final ReactiveRemoveByQuerySupport<T> reactiveSupport;
4547
private final QueryScanConsistency scanConsistency;
48+
private final String collection;
4649

4750
ExecutableRemoveByQuerySupport(final CouchbaseTemplate template, final Class<T> domainType, final Query query,
48-
final QueryScanConsistency scanConsistency) {
51+
final QueryScanConsistency scanConsistency, String collection) {
4952
this.template = template;
5053
this.domainType = domainType;
5154
this.query = query;
52-
this.reactiveSupport = new ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport<>(
53-
template.reactive(), domainType, query, scanConsistency);
55+
this.reactiveSupport = new ReactiveRemoveByQuerySupport<>(template.reactive(), domainType, query, scanConsistency,
56+
collection);
5457
this.scanConsistency = scanConsistency;
58+
this.collection = collection;
5559
}
5660

5761
@Override
@@ -61,12 +65,17 @@ public List<RemoveResult> all() {
6165

6266
@Override
6367
public TerminatingRemoveByQuery<T> matching(final Query query) {
64-
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency);
68+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, collection);
6569
}
6670

6771
@Override
6872
public RemoveByQueryWithQuery<T> consistentWith(final QueryScanConsistency scanConsistency) {
69-
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency);
73+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, collection);
74+
}
75+
76+
@Override
77+
public RemoveByQueryInCollection<T> inCollection(final String collection) {
78+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, collection);
7079
}
7180

7281
}

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

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

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

2324
import com.couchbase.client.core.msg.kv.DurabilityLevel;
2425
import com.couchbase.client.java.kv.PersistTo;
@@ -48,7 +49,7 @@ static class ExecutableReplaceByIdSupport<T> implements ExecutableReplaceById<T>
4849
private final ReplicateTo replicateTo;
4950
private final DurabilityLevel durabilityLevel;
5051
private final Duration expiry;
51-
private final ReactiveReplaceByIdOperationSupport.ReactiveReplaceByIdSupport<T> reactiveSupport;
52+
private final ReactiveReplaceByIdSupport<T> reactiveSupport;
5253

5354
ExecutableReplaceByIdSupport(final CouchbaseTemplate template, final Class<T> domainType, final String collection,
5455
final PersistTo persistTo, final ReplicateTo replicateTo, final DurabilityLevel durabilityLevel,
@@ -60,7 +61,7 @@ static class ExecutableReplaceByIdSupport<T> implements ExecutableReplaceById<T>
6061
this.replicateTo = replicateTo;
6162
this.durabilityLevel = durabilityLevel;
6263
this.expiry = expiry;
63-
this.reactiveSupport = new ReactiveReplaceByIdOperationSupport.ReactiveReplaceByIdSupport<>(template.reactive(),
64+
this.reactiveSupport = new ReactiveReplaceByIdSupport<>(template.reactive(),
6465
domainType, collection, persistTo, replicateTo, durabilityLevel, expiry);
6566
}
6667

0 commit comments

Comments
 (0)