@@ -104,6 +104,129 @@ interface FindByQueryConsistentWith<T> extends FindByQueryWithQuery<T> {
104
104
105
105
}
106
106
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 {}
108
231
109
232
}
0 commit comments