Skip to content

Commit e7380c6

Browse files
committed
Add RangeScan support.
Closes #1599.
1 parent 1a35469 commit e7380c6

13 files changed

+177
-380
lines changed

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

Lines changed: 24 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@
2222
import org.springframework.data.couchbase.core.support.InScope;
2323
import org.springframework.data.couchbase.core.support.WithBatchByteLimit;
2424
import org.springframework.data.couchbase.core.support.WithBatchItemLimit;
25-
import org.springframework.data.couchbase.core.support.IdsOnly;
26-
import org.springframework.data.couchbase.core.support.WithLimit;
27-
import org.springframework.data.couchbase.core.support.WithSampling;
2825
import org.springframework.data.couchbase.core.support.WithScanOptions;
2926
import org.springframework.data.couchbase.core.support.WithScanSort;
3027

3128
import com.couchbase.client.java.kv.MutationState;
3229
import com.couchbase.client.java.kv.ScanOptions;
33-
import com.couchbase.client.java.kv.ScanSort;
34-
import org.springframework.data.couchbase.core.support.WithSeed;
3530

3631
/**
3732
* Get Operations
@@ -68,10 +63,27 @@ interface TerminatingRangeScan<T> /*extends OneAndAllId<T>*/ {
6863
*
6964
* @param upper
7065
* @param lower
71-
* @return the list of found entities.
66+
* @return the list of found keys.
7267
*/
7368
Stream<String> rangeScanIds(String lower, String upper);
7469

70+
/**
71+
* Range Scan
72+
*
73+
* @param limit
74+
* @param seed
75+
* @return the list of found entities.
76+
*/
77+
Stream<T> samplingScan(Long limit, Long... seed);
78+
79+
/**
80+
* Range Scan Ids
81+
*
82+
* @param limit
83+
* @param seed
84+
* @return the list of keys
85+
*/
86+
Stream<String> samplingScanIds(Long limit, Long... seed);
7587
}
7688

7789
/**
@@ -119,24 +131,16 @@ interface RangeScanInScope<T> extends RangeScanInCollection<T>, InScope<T> {
119131
RangeScanInCollection<T> inScope(String scope);
120132
}
121133

122-
interface RangeScanWithSampling<T> extends RangeScanInScope<T>, WithSampling<T> {
123-
/**
124-
* sampling
125-
*
126-
* @param isSampling
127-
*/
128-
@Override
129-
RangeScanInScope<T> withSampling(Boolean isSampling);
130-
}
131134

132-
interface RangeScanWithSort<T> extends RangeScanWithSampling<T>, WithScanSort<T> {
135+
136+
interface RangeScanWithSort<T> extends RangeScanInScope<T>, WithScanSort<T> {
133137
/**
134138
* sort
135139
*
136140
* @param sort
137141
*/
138142
@Override
139-
RangeScanWithSampling<T> withSort(ScanSort sort);
143+
RangeScanInScope<T> withSort(Object sort);
140144
}
141145

142146
/**
@@ -173,46 +177,7 @@ interface RangeScanWithProjection<T> extends RangeScanConsistentWith<T> {
173177
<R> RangeScanConsistentWith<R> as(Class<R> returnType);
174178
}
175179

176-
interface RangeScanIdsOnly<T> extends RangeScanWithProjection<T>, IdsOnly<T> {
177-
178-
/**
179-
* determines if result are just ids or ids plus contents
180-
*
181-
* @param idsOnly must not be {@literal null}.
182-
* @return new instance of {@link RangeScanWithProjection}.
183-
* @throws IllegalArgumentException if returnType is {@literal null}.
184-
*/
185-
@Override
186-
RangeScanWithProjection<T> idsOnly(Boolean idsOnly);
187-
}
188-
189-
interface RangeScanWithLimit<T> extends RangeScanIdsOnly<T>, WithLimit<T> {
190-
191-
/**
192-
* determines if result are just ids or ids plus contents
193-
*
194-
* @param limit must not be {@literal null}.
195-
* @return new instance of {@link RangeScanWithProjection}.
196-
* @throws IllegalArgumentException if returnType is {@literal null}.
197-
*/
198-
@Override
199-
RangeScanIdsOnly<T> withLimit(Long limit);
200-
}
201-
202-
interface RangeScanWithSeed<T> extends RangeScanWithLimit<T>, WithSeed<T> {
203-
204-
/**
205-
* determines if result are just ids or ids plus contents
206-
*
207-
* @param seed must not be {@literal null}.
208-
* @return new instance of {@link RangeScanWithProjection}.
209-
* @throws IllegalArgumentException if returnType is {@literal null}.
210-
*/
211-
@Override
212-
RangeScanWithLimit<T> withSeed(Long seed);
213-
}
214-
215-
interface RangeScanWithBatchItemLimit<T> extends RangeScanWithSeed<T>, WithBatchItemLimit<T> {
180+
interface RangeScanWithBatchItemLimit<T> extends RangeScanWithProjection<T>, WithBatchItemLimit<T> {
216181

217182
/**
218183
* determines if result are just ids or ids plus contents
@@ -222,7 +187,7 @@ interface RangeScanWithBatchItemLimit<T> extends RangeScanWithSeed<T>, WithBatch
222187
* @throws IllegalArgumentException if returnType is {@literal null}.
223188
*/
224189
@Override
225-
RangeScanWithSeed<T> withBatchItemLimit(Integer batchByteLimit);
190+
RangeScanWithProjection<T> withBatchItemLimit(Integer batchByteLimit);
226191
}
227192

228193
interface RangeScanWithBatchByteLimit<T> extends RangeScanWithBatchItemLimit<T>, WithBatchByteLimit<T> {
@@ -235,7 +200,7 @@ interface RangeScanWithBatchByteLimit<T> extends RangeScanWithBatchItemLimit<T>,
235200
* @throws IllegalArgumentException if returnType is {@literal null}.
236201
*/
237202
@Override
238-
RangeScanWithBatchByteLimit<T> withBatchByteLimit(Integer batchByteLimit);
203+
RangeScanWithBatchItemLimit<T> withBatchByteLimit(Integer batchByteLimit);
239204
}
240205

241206
/**

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

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import com.couchbase.client.java.kv.MutationState;
2525
import com.couchbase.client.java.kv.ScanOptions;
26-
import com.couchbase.client.java.kv.ScanSort;
2726

2827
public class ExecutableRangeScanOperationSupport implements ExecutableRangeScanOperation {
2928

@@ -36,7 +35,7 @@ public class ExecutableRangeScanOperationSupport implements ExecutableRangeScanO
3635
@Override
3736
public <T> ExecutableRangeScan<T> rangeScan(Class<T> domainType) {
3837
return new ExecutableRangeScanSupport<>(template, domainType, OptionsBuilder.getScopeFrom(domainType),
39-
OptionsBuilder.getCollectionFrom(domainType), null, null, null, null, null, null, null, null, null);
38+
OptionsBuilder.getCollectionFrom(domainType), null, null, null, false, null, null);
4039
}
4140

4241
static class ExecutableRangeScanSupport<T> implements ExecutableRangeScan<T> {
@@ -46,121 +45,101 @@ static class ExecutableRangeScanSupport<T> implements ExecutableRangeScan<T> {
4645
private final String scope;
4746
private final String collection;
4847
private final ScanOptions options;
49-
private final Boolean isSamplingScan;
50-
private final ScanSort sort;
48+
private final Object sort;
5149
private final MutationState mutationState;
52-
private final Boolean withContent;
53-
private final Long limit;
54-
private final Long seed;
50+
private final Boolean idsOnly;
5551
private final Integer batchItemLimit;
5652
private final Integer batchByteLimit;
5753
private final ReactiveRangeScanSupport<T> reactiveSupport;
5854

5955
ExecutableRangeScanSupport(CouchbaseTemplate template, Class<T> domainType, String scope, String collection,
60-
ScanOptions options, Boolean isSamplingScan, ScanSort sort, MutationState mutationState, Boolean withContent,
61-
Long seed, Long limit, Integer batchItemLimit, Integer batchByteLimit) {
56+
ScanOptions options, Object sort, MutationState mutationState, Boolean idsOnly,
57+
Integer batchItemLimit, Integer batchByteLimit) {
6258
this.template = template;
6359
this.domainType = domainType;
6460
this.scope = scope;
6561
this.collection = collection;
6662
this.options = options;
67-
this.isSamplingScan = isSamplingScan;
6863
this.sort = sort;
6964
this.mutationState = mutationState;
70-
this.withContent = withContent;
71-
this.limit = limit;
72-
this.seed = seed;
65+
this.idsOnly = idsOnly;
7366
this.batchItemLimit = batchItemLimit;
7467
this.batchByteLimit = batchByteLimit;
7568
this.reactiveSupport = new ReactiveRangeScanSupport<>(template.reactive(), domainType, scope, collection, options,
76-
isSamplingScan, sort, mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit,
69+
sort, mutationState, batchItemLimit, batchByteLimit,
7770
new NonReactiveSupportWrapper(template.support()));
7871
}
7972

8073
@Override
8174
public TerminatingRangeScan<T> withOptions(final ScanOptions options) {
8275
Assert.notNull(options, "Options must not be null.");
83-
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, isSamplingScan, sort,
84-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
76+
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, sort,
77+
mutationState, idsOnly, batchItemLimit, batchByteLimit);
8578
}
8679

8780
@Override
8881
public RangeScanWithOptions<T> inCollection(final String collection) {
8982
return new ExecutableRangeScanSupport<>(template, domainType, scope,
90-
collection != null ? collection : this.collection, options, isSamplingScan, sort, mutationState, withContent,
91-
limit, seed, batchItemLimit, batchByteLimit);
83+
collection != null ? collection : this.collection, options, sort, mutationState, idsOnly,
84+
batchItemLimit, batchByteLimit);
9285
}
9386

9487
@Override
9588
public RangeScanInCollection<T> inScope(final String scope) {
9689
return new ExecutableRangeScanSupport<>(template, domainType, scope != null ? scope : this.scope, collection,
97-
options, isSamplingScan, sort, mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
90+
options, sort, mutationState, idsOnly, batchItemLimit, batchByteLimit);
9891
}
9992

10093
@Override
101-
public RangeScanInScope<T> withSampling(Boolean isSamplingScan) {
102-
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, isSamplingScan, sort,
103-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
104-
}
105-
106-
@Override
107-
public RangeScanWithSampling<T> withSort(ScanSort sort) {
108-
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, isSamplingScan, sort,
109-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
94+
public RangeScanInScope<T> withSort(Object sort) {
95+
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, sort,
96+
mutationState, idsOnly, batchItemLimit, batchByteLimit);
11097
}
11198

11299
@Override
113100
public RangeScanWithSort<T> consistentWith(MutationState mutationState) {
114-
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, isSamplingScan, sort,
115-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
101+
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, sort,
102+
mutationState, idsOnly, batchItemLimit, batchByteLimit);
116103
}
117104

118105
@Override
119106
public <R> RangeScanConsistentWith<R> as(Class<R> returnType) {
120-
return new ExecutableRangeScanSupport<>(template, returnType, scope, collection, options, isSamplingScan, sort,
121-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
122-
}
123-
124-
@Override
125-
public RangeScanWithProjection<T> idsOnly(Boolean withContent) {
126-
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, isSamplingScan, sort,
127-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
128-
}
129-
130-
@Override
131-
public RangeScanIdsOnly<T> withLimit(Long limit) {
132-
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, isSamplingScan, sort,
133-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
107+
return new ExecutableRangeScanSupport<>(template, returnType, scope, collection, options, sort,
108+
mutationState, idsOnly, batchItemLimit, batchByteLimit);
134109
}
135110

136111
@Override
137-
public RangeScanWithLimit<T> withSeed(Long seed) {
138-
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, isSamplingScan, sort,
139-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
112+
public RangeScanWithProjection<T> withBatchItemLimit(Integer batchItemLimit) {
113+
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, sort,
114+
mutationState, idsOnly, batchItemLimit, batchByteLimit);
140115
}
141116

142117
@Override
143-
public RangeScanWithSeed<T> withBatchItemLimit(Integer batchItemLimit) {
144-
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, isSamplingScan, sort,
145-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
146-
}
147-
148-
@Override
149-
public RangeScanWithBatchByteLimit<T> withBatchByteLimit(Integer batchByteLimit) {
150-
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, isSamplingScan, sort,
151-
mutationState, withContent, limit, seed, batchItemLimit, batchByteLimit);
118+
public RangeScanWithBatchItemLimit<T> withBatchByteLimit(Integer batchByteLimit) {
119+
return new ExecutableRangeScanSupport<>(template, domainType, scope, collection, options, sort,
120+
mutationState, idsOnly, batchItemLimit, batchByteLimit);
152121
}
153122

154123
@Override
155124
public Stream<T> rangeScan(String lower, String upper) {
156-
return reactiveSupport.rangeScan(lower, upper).toStream();
125+
return reactiveSupport.rangeScan(lower, upper, false, null, null).toStream();
157126
}
158127

159128
@Override
160129
public Stream<String> rangeScanIds(String lower, String upper) {
161-
return reactiveSupport.rangeScanIds(lower, upper).toStream();
130+
return reactiveSupport.rangeScanIds(lower, upper, false, null, null).toStream();
162131
}
163132

133+
@Override
134+
public Stream<T> samplingScan(Long limit, Long... seed) {
135+
return reactiveSupport.sampleScan(limit, seed).toStream();
136+
}
137+
138+
@Override
139+
public Stream<String> samplingScanIds(Long limit, Long... seed) {
140+
return reactiveSupport.sampleScanIds(limit, seed).toStream();
141+
}
142+
164143
}
165144

166145
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
public interface FluentCouchbaseOperations extends ExecutableUpsertByIdOperation, ExecutableInsertByIdOperation,
2323
ExecutableReplaceByIdOperation, ExecutableFindByIdOperation, ExecutableFindFromReplicasByIdOperation,
2424
ExecutableFindByQueryOperation, ExecutableFindByAnalyticsOperation, ExecutableExistsByIdOperation,
25-
ExecutableRemoveByIdOperation, ExecutableRemoveByQueryOperation, ExecutableRangeScanOperation,
25+
ExecutableRemoveByIdOperation, ExecutableRemoveByQueryOperation, ExecutableMutateInByIdOperation,
2626
ExecutableRangeScanOperation {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
public interface ReactiveFluentCouchbaseOperations extends ReactiveUpsertByIdOperation, ReactiveInsertByIdOperation,
2323
ReactiveReplaceByIdOperation, ReactiveFindByIdOperation, ReactiveExistsByIdOperation,
2424
ReactiveFindByAnalyticsOperation, ReactiveFindFromReplicasByIdOperation, ReactiveFindByQueryOperation,
25-
ReactiveRemoveByIdOperation, ReactiveRemoveByQueryOperation, ReactiveRangeScanOperation,
25+
ReactiveRemoveByIdOperation, ReactiveRemoveByQueryOperation, ReactiveMutateInByIdOperation,
2626
ReactiveRangeScanOperation {}

0 commit comments

Comments
 (0)