Skip to content

Commit e6ee57b

Browse files
committed
DATACOUCH-588 - Refactoring part 1 of n.
1 parent a765e06 commit e6ee57b

24 files changed

+445
-915
lines changed

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

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

131131
}
132132

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> {}
133+
interface ExecutableFindByQuery<T> extends FindByQueryConsistentWith<T> {}
145134

146135
}

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
import com.couchbase.client.java.query.QueryScanConsistency;
2424
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-
*/
3226
public class ExecutableFindByQueryOperationSupport implements ExecutableFindByQueryOperation {
3327

3428
private static final Query ALL_QUERY = new Query();
@@ -41,7 +35,7 @@ public ExecutableFindByQueryOperationSupport(final CouchbaseTemplate template) {
4135

4236
@Override
4337
public <T> ExecutableFindByQuery<T> findByQuery(final Class<T> domainType) {
44-
return new ExecutableFindByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED, null);
38+
return new ExecutableFindByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED);
4539
}
4640

4741
static class ExecutableFindByQuerySupport<T> implements ExecutableFindByQuery<T> {
@@ -51,16 +45,14 @@ static class ExecutableFindByQuerySupport<T> implements ExecutableFindByQuery<T>
5145
private final Query query;
5246
private final ReactiveFindByQueryOperationSupport.ReactiveFindByQuerySupport<T> reactiveSupport;
5347
private final QueryScanConsistency scanConsistency;
54-
private final String collection;
5548

5649
ExecutableFindByQuerySupport(final CouchbaseTemplate template, final Class<T> domainType, final Query query,
57-
final QueryScanConsistency scanConsistency, final String collection) {
50+
final QueryScanConsistency scanConsistency) {
5851
this.template = template;
5952
this.domainType = domainType;
6053
this.query = query;
61-
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(), domainType, query, scanConsistency, collection);
54+
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(), domainType, query, scanConsistency);
6255
this.scanConsistency = scanConsistency;
63-
this.collection = collection;
6456
}
6557

6658
@Override
@@ -86,17 +78,12 @@ public TerminatingFindByQuery<T> matching(final Query query) {
8678
} else {
8779
scanCons = scanConsistency;
8880
}
89-
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanCons, collection);
81+
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanCons);
9082
}
9183

9284
@Override
9385
public FindByQueryConsistentWith<T> consistentWith(final QueryScanConsistency 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);
86+
return new ExecutableFindByQuerySupport<>(template, domainType, query, scanConsistency);
10087
}
10188

10289
@Override

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

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

4444
}
4545

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

5448
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public ExecutableRemoveByQueryOperationSupport(final CouchbaseTemplate template)
3333

3434
@Override
3535
public <T> ExecutableRemoveByQuery<T> removeByQuery(Class<T> domainType) {
36-
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED, null);
36+
return new ExecutableRemoveByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED);
3737
}
3838

3939
static class ExecutableRemoveByQuerySupport<T> implements ExecutableRemoveByQuery<T> {
@@ -43,17 +43,15 @@ static class ExecutableRemoveByQuerySupport<T> implements ExecutableRemoveByQuer
4343
private final Query query;
4444
private final ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport<T> reactiveSupport;
4545
private final QueryScanConsistency scanConsistency;
46-
private final String collection;
4746

4847
ExecutableRemoveByQuerySupport(final CouchbaseTemplate template, final Class<T> domainType, final Query query,
49-
final QueryScanConsistency scanConsistency, String collection) {
48+
final QueryScanConsistency scanConsistency) {
5049
this.template = template;
5150
this.domainType = domainType;
5251
this.query = query;
5352
this.reactiveSupport = new ReactiveRemoveByQueryOperationSupport.ReactiveRemoveByQuerySupport<>(
5453
template.reactive(), domainType, query, scanConsistency);
5554
this.scanConsistency = scanConsistency;
56-
this.collection = collection;
5755
}
5856

5957
@Override
@@ -63,16 +61,12 @@ public List<RemoveResult> all() {
6361

6462
@Override
6563
public TerminatingRemoveByQuery<T> matching(final Query query) {
66-
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, collection);
64+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency);
6765
}
6866

6967
@Override
7068
public RemoveByQueryWithQuery<T> consistentWith(final QueryScanConsistency scanConsistency) {
71-
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, collection);
72-
}
73-
@Override
74-
public RemoveByQueryInCollection<T> inCollection(final String collection) {
75-
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency, collection);
69+
return new ExecutableRemoveByQuerySupport<>(template, domainType, query, scanConsistency);
7670
}
7771

7872
}

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

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

18+
import org.springframework.dao.IncorrectResultSizeDataAccessException;
1819
import reactor.core.publisher.Flux;
1920
import reactor.core.publisher.Mono;
2021

21-
import org.springframework.dao.IncorrectResultSizeDataAccessException;
2222
import org.springframework.data.couchbase.core.query.Query;
2323

2424
import com.couchbase.client.java.query.QueryScanConsistency;
2525

26-
/**
27-
* ReactiveFindByQueryOperation
28-
*
29-
* @author Michael Nitschinger
30-
* @author Michael Reiche
31-
*/
3226
public interface ReactiveFindByQueryOperation {
3327

3428
/**
@@ -110,124 +104,6 @@ interface FindByQueryConsistentWith<T> extends FindByQueryWithQuery<T> {
110104

111105
}
112106

113-
/**
114-
* Collection override (optional).
115-
*/
116-
interface FindInCollection<T> extends FindByQueryWithQuery<T> {
117-
118-
/**
119-
* Explicitly set the name of the collection to perform the query on. <br />
120-
* Skip this step to use the default collection derived from the domain type.
121-
*
122-
* @param collection must not be {@literal null} nor {@literal empty}.
123-
* @return new instance of {@link FindWithProjection}.
124-
* @throws IllegalArgumentException if collection is {@literal null}.
125-
*/
126-
FindInCollection<T> inCollection(String collection);
127-
}
128-
129-
/**
130-
* Result type override (optional).
131-
*/
132-
interface FindWithProjection<T> extends FindInCollection<T>, FindDistinct {
133-
134-
/**
135-
* Define the target type fields should be mapped to. <br />
136-
* Skip this step if you are anyway only interested in the original domain type.
137-
*
138-
* @param resultType must not be {@literal null}.
139-
* @param <R> result type.
140-
* @return new instance of {@link FindWithProjection}.
141-
* @throws IllegalArgumentException if resultType is {@literal null}.
142-
*/
143-
<R> FindByQueryWithQuery<R> as(Class<R> resultType);
144-
}
145-
146-
/**
147-
* Distinct Find support.
148-
*
149-
* @author Michael Reiche
150-
*/
151-
interface FindDistinct {
152-
153-
/**
154-
* Finds the distinct values for a specified {@literal field} across a single {@link } or view.
155-
*
156-
* @param field name of the field. Must not be {@literal null}.
157-
* @return new instance of {@link TerminatingDistinct}.
158-
* @throws IllegalArgumentException if field is {@literal null}.
159-
*/
160-
TerminatingDistinct<Object> distinct(String field);
161-
}
162-
163-
/**
164-
* Result type override. Optional.
165-
*
166-
* @author Michael Reiche
167-
*/
168-
interface DistinctWithProjection {
169-
170-
/**
171-
* Define the target type the result should be mapped to. <br />
172-
* Skip this step if you are anyway fine with the default conversion.
173-
* <dl>
174-
* <dt>{@link Object} (the default)</dt>
175-
* <dd>Result is mapped according to the {@link } converting eg. {@link } into plain {@link String}, {@link } to
176-
* {@link Long}, etc. always picking the most concrete type with respect to the domain types property.<br />
177-
* Any {@link } is run through the {@link org.springframework.data.convert.EntityReader} to obtain the domain type.
178-
* <br />
179-
* Using {@link Object} also works for non strictly typed fields. Eg. a mixture different types like fields using
180-
* {@link String} in one {@link } while {@link Long} in another.</dd>
181-
* <dt>Any Simple type like {@link String}, {@link Long}, ...</dt>
182-
* <dd>The result is mapped directly by the Couchbase Java driver and the {@link } in place. This works only for
183-
* results where all documents considered for the operation use the very same type for the field.</dd>
184-
* <dt>Any Domain type</dt>
185-
* <dd>Domain types can only be mapped if the if the result of the actual {@code distinct()} operation returns
186-
* {@link }.</dd>
187-
* <dt>{@link }</dt>
188-
* <dd>Using {@link } allows retrieval of the raw driver specific format, which returns eg. {@link }.</dd>
189-
* </dl>
190-
*
191-
* @param resultType must not be {@literal null}.
192-
* @param <R> result type.
193-
* @return new instance of {@link TerminatingDistinct}.
194-
* @throws IllegalArgumentException if resultType is {@literal null}.
195-
*/
196-
<R> TerminatingDistinct<R> as(Class<R> resultType);
197-
}
198-
199-
/**
200-
* Result restrictions. Optional.
201-
*
202-
* @author Michael Reiche
203-
*/
204-
interface DistinctWithQuery<T> extends DistinctWithProjection {
205-
206-
/**
207-
* Set the filter {@link Query criteria} to be used.
208-
*
209-
* @param query must not be {@literal null}.
210-
* @return new instance of {@link TerminatingDistinct}.
211-
* @throws IllegalArgumentException if criteria is {@literal null}.
212-
*/
213-
TerminatingDistinct<T> matching(Query query);
214-
}
215-
216-
/**
217-
* Terminating distinct find operations.
218-
*
219-
* @author Michael Reiche
220-
*/
221-
interface TerminatingDistinct<T> extends DistinctWithQuery<T> {
222-
223-
/**
224-
* Get all matching distinct field values.
225-
*
226-
* @return empty {@link Flux} if not match found. Never {@literal null}.
227-
*/
228-
Flux<T> all();
229-
}
230-
231-
interface ReactiveFindByQuery<T> extends FindByQueryConsistentWith<T>, FindInCollection<T>, FindDistinct {}
107+
interface ReactiveFindByQuery<T> extends FindByQueryConsistentWith<T> {}
232108

233109
}

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

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

18+
import org.springframework.data.couchbase.core.support.TemplateUtils;
19+
import org.springframework.data.couchbase.core.query.Query;
20+
1821
import reactor.core.publisher.Flux;
1922
import reactor.core.publisher.Mono;
2023

21-
import org.springframework.data.couchbase.core.query.Query;
22-
import org.springframework.data.couchbase.core.support.TemplateUtils;
23-
2424
import com.couchbase.client.java.query.QueryScanConsistency;
2525
import com.couchbase.client.java.query.ReactiveQueryResult;
2626

2727
/**
28-
* {@link ReactiveFindByQueryOperation} implementations for Couchbase.
29-
*
3028
* @author Michael Nitschinger
3129
* @author Michael Reiche
3230
*/
@@ -42,8 +40,7 @@ public ReactiveFindByQueryOperationSupport(final ReactiveCouchbaseTemplate templ
4240

4341
@Override
4442
public <T> ReactiveFindByQuery<T> findByQuery(final Class<T> domainType) {
45-
return new ReactiveFindByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED,
46-
null);
43+
return new ReactiveFindByQuerySupport<>(template, domainType, ALL_QUERY, QueryScanConsistency.NOT_BOUNDED);
4744
}
4845

4946
static class ReactiveFindByQuerySupport<T> implements ReactiveFindByQuery<T> {
@@ -52,15 +49,13 @@ static class ReactiveFindByQuerySupport<T> implements ReactiveFindByQuery<T> {
5249
private final Class<T> domainType;
5350
private final Query query;
5451
private final QueryScanConsistency scanConsistency;
55-
private final String collection;
5652

5753
ReactiveFindByQuerySupport(final ReactiveCouchbaseTemplate template, final Class<T> domainType, final Query query,
58-
final QueryScanConsistency scanConsistency, final String collection) {
54+
final QueryScanConsistency scanConsistency) {
5955
this.template = template;
6056
this.domainType = domainType;
6157
this.query = query;
6258
this.scanConsistency = scanConsistency;
63-
this.collection = collection;
6459
}
6560

6661
@Override
@@ -71,22 +66,12 @@ public TerminatingFindByQuery<T> matching(Query query) {
7166
} else {
7267
scanCons = scanConsistency;
7368
}
74-
return new ReactiveFindByQuerySupport<>(template, domainType, query, scanCons, collection);
69+
return new ReactiveFindByQuerySupport<>(template, domainType, query, scanCons);
7570
}
7671

7772
@Override
7873
public FindByQueryConsistentWith<T> consistentWith(QueryScanConsistency scanConsistency) {
79-
return new ReactiveFindByQuerySupport<>(template, domainType, query, scanConsistency, collection);
80-
}
81-
82-
@Override
83-
public FindInCollection<T> inCollection(String collection) {
84-
return new ReactiveFindByQuerySupport<>(template, domainType, query, scanConsistency, collection);
85-
}
86-
87-
@Override
88-
public TerminatingDistinct<Object> distinct(String field) {
89-
throw new RuntimeException(("not implemented"));
74+
return new ReactiveFindByQuerySupport<>(template, domainType, query, scanConsistency);
9075
}
9176

9277
@Override
@@ -144,6 +129,7 @@ public Mono<Boolean> exists() {
144129
private String assembleEntityQuery(final boolean count) {
145130
return query.toN1qlSelectString(template, this.domainType, count);
146131
}
132+
147133
}
148134

149135
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ interface RemoveByQueryConsistentWith<T> extends RemoveByQueryWithQuery<T> {
4141

4242
}
4343

44-
interface RemoveByQueryInCollection<T> extends RemoveByQueryConsistentWith<T> {
45-
46-
RemoveByQueryConsistentWith<T> inCollection(String collection);
47-
48-
}
49-
50-
interface ReactiveRemoveByQuery<T> extends RemoveByQueryInCollection<T> {}
44+
interface ReactiveRemoveByQuery<T> extends RemoveByQueryConsistentWith<T> {}
5145

5246
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ public RemoveByQueryWithQuery<T> consistentWith(final QueryScanConsistency scanC
9191
return new ReactiveRemoveByQuerySupport<>(template, domainType, query, scanConsistency);
9292
}
9393

94-
@Override
95-
public RemoveByQueryConsistentWith<T> inCollection(final String collection) {
96-
return new ReactiveRemoveByQuerySupport<>(template, domainType, query, scanConsistency);
97-
}
9894
private String assembleDeleteQuery() {
9995
return query.toN1qlRemoveString(template, this.domainType);
10096
}

0 commit comments

Comments
 (0)