Skip to content

Commit 256c7a2

Browse files
committed
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)
1 parent 957744b commit 256c7a2

File tree

51 files changed

+386
-319
lines changed

Some content is hidden

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

51 files changed

+386
-319
lines changed

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: 20 additions & 8 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,25 +41,26 @@ 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, "_default._default");
3945
}
4046

4147
static class ExecutableFindByQuerySupport<T> implements ExecutableFindByQuery<T> {
4248

4349
private final CouchbaseTemplate template;
4450
private final Class<T> domainType;
4551
private final Query query;
46-
private final ReactiveFindByQueryOperationSupport.ReactiveFindByQuerySupport<T> reactiveSupport;
52+
private final ReactiveFindByQuerySupport<T> reactiveSupport;
4753
private final QueryScanConsistency scanConsistency;
54+
private final String collection;
4855

4956
ExecutableFindByQuerySupport(final CouchbaseTemplate template, final Class<T> domainType, final Query query,
50-
final QueryScanConsistency scanConsistency) {
57+
final QueryScanConsistency scanConsistency, final String collection) {
5158
this.template = template;
5259
this.domainType = domainType;
5360
this.query = query;
54-
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(),
55-
domainType, query, scanConsistency);
61+
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(), domainType, query, scanConsistency, collection);
5662
this.scanConsistency = scanConsistency;
63+
this.collection = collection;
5764
}
5865

5966
@Override
@@ -79,12 +86,17 @@ public TerminatingFindByQuery<T> matching(final Query query) {
7986
} else {
8087
scanCons = scanConsistency;
8188
}
82-
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanCons);
89+
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanCons, collection);
8390
}
8491

8592
@Override
8693
public FindByQueryConsistentWith<T> consistentWith(final QueryScanConsistency scanConsistency) {
87-
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanConsistency);
94+
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanConsistency, collection);
95+
}
96+
97+
@Override
98+
public FindByQueryInCollection<T> inCollection(final String collection) {
99+
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanConsistency, collection);
88100
}
89101

90102
@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: 14 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,27 @@ 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, "_default._default");
3738
}
3839

3940
static class ExecutableRemoveByQuerySupport<T> implements ExecutableRemoveByQuery<T> {
4041

4142
private final CouchbaseTemplate template;
4243
private final Class<T> domainType;
4344
private final Query query;
44-
private final ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport<T> reactiveSupport;
45+
private final ReactiveRemoveByQuerySupport<T> reactiveSupport;
4546
private final QueryScanConsistency scanConsistency;
47+
private final String collection;
4648

4749
ExecutableRemoveByQuerySupport(final CouchbaseTemplate template, final Class<T> domainType, final Query query,
48-
final QueryScanConsistency scanConsistency) {
50+
final QueryScanConsistency scanConsistency, String collection) {
4951
this.template = template;
5052
this.domainType = domainType;
5153
this.query = query;
52-
this.reactiveSupport = new ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport<>(
53-
template.reactive(), domainType, query, scanConsistency);
54+
this.reactiveSupport = new ReactiveRemoveByQuerySupport<>(template.reactive(), domainType, query,
55+
scanConsistency);
5456
this.scanConsistency = scanConsistency;
57+
this.collection = collection;
5558
}
5659

5760
@Override
@@ -61,12 +64,16 @@ public List<RemoveResult> all() {
6164

6265
@Override
6366
public TerminatingRemoveByQuery<T> matching(final Query query) {
64-
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency);
67+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, collection);
6568
}
6669

6770
@Override
6871
public RemoveByQueryWithQuery<T> consistentWith(final QueryScanConsistency scanConsistency) {
69-
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency);
72+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, collection);
73+
}
74+
@Override
75+
public RemoveByQueryInCollection<T> inCollection(final String collection) {
76+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, collection);
7077
}
7178

7279
}

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

src/main/java/org/springframework/data/couchbase/core/ExecutableUpsertByIdOperationSupport.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.ReactiveUpsertByIdOperationSupport.ReactiveUpsertByIdSupport;
2223

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

5354
ExecutableUpsertByIdSupport(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 ExecutableUpsertByIdSupport<T> implements ExecutableUpsertById<T> {
6061
this.replicateTo = replicateTo;
6162
this.durabilityLevel = durabilityLevel;
6263
this.expiry = expiry;
63-
this.reactiveSupport = new ReactiveUpsertByIdOperationSupport.ReactiveUpsertByIdSupport<>(template.reactive(),
64+
this.reactiveSupport = new ReactiveUpsertByIdSupport<>(template.reactive(),
6465
domainType, collection, persistTo, replicateTo, durabilityLevel, expiry);
6566
}
6667

0 commit comments

Comments
 (0)