18
18
import reactor .core .publisher .Flux ;
19
19
import reactor .core .publisher .Mono ;
20
20
21
- import java .util .List ;
22
-
23
21
import org .springframework .data .domain .Sort ;
24
- import org .springframework .data .domain .Sort .Order ;
25
22
import org .springframework .data .mongodb .core .ReactiveMongoOperations ;
26
23
import org .springframework .data .mongodb .repository .query .MongoEntityInformation ;
27
24
import org .springframework .data .querydsl .EntityPathResolver ;
28
- import org .springframework .data .querydsl .QSort ;
29
25
import org .springframework .data .querydsl .QuerydslPredicateExecutor ;
30
26
import org .springframework .data .querydsl .ReactiveQuerydslPredicateExecutor ;
31
27
import org .springframework .data .querydsl .SimpleEntityPathResolver ;
32
- import org .springframework .data .repository .core .EntityInformation ;
33
28
import org .springframework .util .Assert ;
34
29
35
30
import com .querydsl .core .types .EntityPath ;
36
- import com .querydsl .core .types .Expression ;
37
31
import com .querydsl .core .types .OrderSpecifier ;
38
32
import com .querydsl .core .types .Predicate ;
39
- import com .querydsl .core .types .dsl .PathBuilder ;
40
33
41
34
/**
42
35
* MongoDB-specific {@link QuerydslPredicateExecutor} that allows execution {@link Predicate}s in various forms.
43
36
*
44
37
* @author Mark Paluch
38
+ * @author Christoph Strobl
45
39
* @since 2.2
46
40
*/
47
- public class ReactiveQuerydslMongoPredicateExecutor <T > implements ReactiveQuerydslPredicateExecutor <T > {
41
+ public class ReactiveQuerydslMongoPredicateExecutor <T > extends QuerydslPredicateExecutorSupport <T >
42
+ implements ReactiveQuerydslPredicateExecutor <T > {
48
43
49
- private final PathBuilder <T > builder ;
50
- private final EntityInformation <T , ?> entityInformation ;
51
44
private final ReactiveMongoOperations mongoOperations ;
52
45
53
46
/**
@@ -60,6 +53,7 @@ public class ReactiveQuerydslMongoPredicateExecutor<T> implements ReactiveQueryd
60
53
*/
61
54
public ReactiveQuerydslMongoPredicateExecutor (MongoEntityInformation <T , ?> entityInformation ,
62
55
ReactiveMongoOperations mongoOperations ) {
56
+
63
57
this (entityInformation , mongoOperations , SimpleEntityPathResolver .INSTANCE );
64
58
}
65
59
@@ -74,12 +68,8 @@ public ReactiveQuerydslMongoPredicateExecutor(MongoEntityInformation<T, ?> entit
74
68
public ReactiveQuerydslMongoPredicateExecutor (MongoEntityInformation <T , ?> entityInformation ,
75
69
ReactiveMongoOperations mongoOperations , EntityPathResolver resolver ) {
76
70
77
- Assert .notNull (resolver , "EntityPathResolver must not be null!" );
78
-
79
- EntityPath <T > path = resolver .createPath (entityInformation .getJavaType ());
80
-
81
- this .builder = new PathBuilder <T >(path .getType (), path .getMetadata ());
82
- this .entityInformation = entityInformation ;
71
+ super (mongoOperations .getConverter (), pathBuilderFor (resolver .createPath (entityInformation .getJavaType ())),
72
+ entityInformation );
83
73
this .mongoOperations = mongoOperations ;
84
74
}
85
75
@@ -185,10 +175,9 @@ private ReactiveSpringDataMongodbQuery<T> createQueryFor(Predicate predicate) {
185
175
* @return
186
176
*/
187
177
private ReactiveSpringDataMongodbQuery <T > createQuery () {
188
- SpringDataMongodbSerializer serializer = new SpringDataMongodbSerializer (mongoOperations .getConverter ());
189
178
190
- Class <T > javaType = entityInformation .getJavaType ();
191
- return new ReactiveSpringDataMongodbQuery <>(serializer , mongoOperations , javaType ,
179
+ Class <T > javaType = typeInformation () .getJavaType ();
180
+ return new ReactiveSpringDataMongodbQuery <>(mongodbSerializer () , mongoOperations , javaType ,
192
181
mongoOperations .getCollectionName (javaType ));
193
182
}
194
183
@@ -201,32 +190,8 @@ private ReactiveSpringDataMongodbQuery<T> createQuery() {
201
190
*/
202
191
private ReactiveSpringDataMongodbQuery <T > applySorting (ReactiveSpringDataMongodbQuery <T > query , Sort sort ) {
203
192
204
- // TODO: find better solution than instanceof check
205
- if (sort instanceof QSort ) {
206
-
207
- List <OrderSpecifier <?>> orderSpecifiers = ((QSort ) sort ).getOrderSpecifiers ();
208
- query .orderBy (orderSpecifiers .toArray (new OrderSpecifier <?>[orderSpecifiers .size ()]));
209
-
210
- return query ;
211
- }
212
-
213
- sort .stream ().map (this ::toOrder ).forEach (query ::orderBy );
214
-
193
+ toOrderSpecifiers (sort ).forEach (query ::orderBy );
215
194
return query ;
216
195
}
217
196
218
- /**
219
- * Transforms a plain {@link Order} into a Querydsl specific {@link OrderSpecifier}.
220
- *
221
- * @param order
222
- * @return
223
- */
224
- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
225
- private OrderSpecifier <?> toOrder (Order order ) {
226
-
227
- Expression <Object > property = builder .get (order .getProperty ());
228
-
229
- return new OrderSpecifier (
230
- order .isAscending () ? com .querydsl .core .types .Order .ASC : com .querydsl .core .types .Order .DESC , property );
231
- }
232
197
}
0 commit comments