Skip to content

Commit 957744b

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 9c9dde7 commit 957744b

30 files changed

+2211
-125
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ static class ExecutableFindByQuerySupport<T> implements ExecutableFindByQuery<T>
5151
this.template = template;
5252
this.domainType = domainType;
5353
this.query = query;
54-
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(), domainType, query, scanConsistency);
54+
this.reactiveSupport = new ReactiveFindByQuerySupport<T>(template.reactive(),
55+
domainType, query, scanConsistency);
5556
this.scanConsistency = scanConsistency;
5657
}
5758

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

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,129 @@ interface FindByQueryConsistentWith<T> extends FindByQueryWithQuery<T> {
104104

105105
}
106106

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

109232
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ private String assembleEntityQuery(final boolean count) {
130130
return query.toN1qlSelectString(template, this.domainType, count);
131131
}
132132

133+
@Override
134+
public FindWithProjection<T> inCollection(String collection) {
135+
throw new RuntimeException(("not implemented"));
136+
}
137+
138+
@Override
139+
public TerminatingDistinct<Object> distinct(String field) {
140+
throw new RuntimeException(("not implemented"));
141+
}
133142
}
134143

135144
}

src/main/java/org/springframework/data/couchbase/core/query/Query.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,22 @@ public Query skip(long skip) {
106106
* Limit the number of returned documents to {@code limit}.
107107
*
108108
* @param limit
109-
* @return
109+
* @return this
110110
*/
111111
public Query limit(int limit) {
112112
this.limit = limit;
113113
return this;
114114
}
115115

116+
/**
117+
* limit
118+
*
119+
* @return limit
120+
*/
121+
public int getLimit() {
122+
return limit;
123+
}
124+
116125
/**
117126
* Sets the given pagination information on the {@link Query} instance. Will transparently set {@code skip} and
118127
* {@code limit} as well as applying the {@link Sort} instance defined with the {@link Pageable}.

0 commit comments

Comments
 (0)