33
33
import org .springframework .data .relational .core .dialect .Escaper ;
34
34
import org .springframework .data .relational .core .mapping .RelationalPersistentEntity ;
35
35
import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
36
+ import org .springframework .data .relational .core .query .Comparator ;
36
37
import org .springframework .data .relational .core .query .CriteriaDefinition ;
37
- import org .springframework .data .relational .core .query .CriteriaDefinition .Comparator ;
38
38
import org .springframework .data .relational .core .query .ValueFunction ;
39
+ import org .springframework .data .relational .core .query .Comparators ;
39
40
import org .springframework .data .relational .core .sql .*;
40
41
import org .springframework .data .relational .domain .SqlSort ;
41
42
import org .springframework .data .util .Pair ;
58
59
* @author Manousos Mathioudakis
59
60
* @author Jens Schauder
60
61
* @author Yan Qiang
62
+ * @author Mikhail Polivakha
61
63
*/
62
64
public class QueryMapper {
63
65
@@ -325,7 +327,7 @@ private Condition mapCondition(CriteriaDefinition criteria, MutableBindings bind
325
327
326
328
private Escaper getEscaper (Comparator comparator ) {
327
329
328
- if (comparator == Comparator .LIKE || comparator == Comparator .NOT_LIKE ) {
330
+ if (comparator == Comparators .LIKE || comparator == Comparators .NOT_LIKE ) {
329
331
return dialect .getLikeEscaper ();
330
332
}
331
333
@@ -351,7 +353,7 @@ public Parameter getBindValue(Parameter value) {
351
353
@ Nullable
352
354
private Object convertValue (Comparator comparator , @ Nullable Object value , TypeInformation <?> typeHint ) {
353
355
354
- if ((Comparator .IN .equals (comparator ) || Comparator .NOT_IN .equals (comparator ))
356
+ if ((Comparators .IN .equals (comparator ) || Comparators .NOT_IN .equals (comparator ))
355
357
&& value instanceof Collection <?> collection && !collection .isEmpty ()) {
356
358
357
359
Collection <Object > mapped = new ArrayList <>(collection .size ());
@@ -396,21 +398,21 @@ protected MappingContext<? extends RelationalPersistentEntity<?>, RelationalPers
396
398
private Condition createCondition (Column column , @ Nullable Object mappedValue , Class <?> valueType ,
397
399
MutableBindings bindings , Comparator comparator , boolean ignoreCase ) {
398
400
399
- if (comparator .equals (Comparator .IS_NULL )) {
401
+ if (comparator .equals (Comparators .IS_NULL )) {
400
402
return column .isNull ();
401
403
}
402
404
403
- if (comparator .equals (Comparator .IS_NOT_NULL )) {
405
+ if (comparator .equals (Comparators .IS_NOT_NULL )) {
404
406
return column .isNotNull ();
405
407
}
406
408
407
- if (comparator == Comparator .IS_TRUE ) {
409
+ if (comparator == Comparators .IS_TRUE ) {
408
410
Expression bind = booleanBind (column , mappedValue , valueType , bindings , ignoreCase );
409
411
410
412
return column .isEqualTo (bind );
411
413
}
412
414
413
- if (comparator == Comparator .IS_FALSE ) {
415
+ if (comparator == Comparators .IS_FALSE ) {
414
416
Expression bind = booleanBind (column , mappedValue , valueType , bindings , ignoreCase );
415
417
416
418
return column .isEqualTo (bind );
@@ -421,7 +423,7 @@ private Condition createCondition(Column column, @Nullable Object mappedValue, C
421
423
columnExpression = Functions .upper (column );
422
424
}
423
425
424
- if (comparator == Comparator .NOT_IN || comparator == Comparator .IN ) {
426
+ if (comparator == Comparators .NOT_IN || comparator == Comparators .IN ) {
425
427
426
428
Condition condition ;
427
429
@@ -446,14 +448,14 @@ private Condition createCondition(Column column, @Nullable Object mappedValue, C
446
448
condition = Conditions .in (columnExpression , expression );
447
449
}
448
450
449
- if (comparator == Comparator .NOT_IN ) {
451
+ if (comparator == Comparators .NOT_IN ) {
450
452
condition = condition .not ();
451
453
}
452
454
453
455
return condition ;
454
456
}
455
457
456
- if (comparator == Comparator .BETWEEN || comparator == Comparator .NOT_BETWEEN ) {
458
+ if (comparator == Comparators .BETWEEN || comparator == Comparators .NOT_BETWEEN ) {
457
459
458
460
Pair <Object , Object > pair = (Pair <Object , Object >) mappedValue ;
459
461
@@ -462,49 +464,46 @@ private Condition createCondition(Column column, @Nullable Object mappedValue, C
462
464
Expression end = bind (pair .getSecond (), valueType , bindings , bindings .nextMarker (column .getName ().getReference ()),
463
465
ignoreCase );
464
466
465
- return comparator == Comparator .BETWEEN ? Conditions .between (columnExpression , begin , end )
467
+ return comparator == Comparators .BETWEEN ? Conditions .between (columnExpression , begin , end )
466
468
: Conditions .notBetween (columnExpression , begin , end );
467
469
}
468
470
469
471
BindMarker bindMarker = bindings .nextMarker (column .getName ().getReference ());
470
472
471
- switch (comparator ) {
472
- case EQ : {
473
- Expression expression = bind (mappedValue , valueType , bindings , bindMarker , ignoreCase );
474
- return Conditions .isEqual (columnExpression , expression );
475
- }
476
- case NEQ : {
477
- Expression expression = bind (mappedValue , valueType , bindings , bindMarker , ignoreCase );
478
- return Conditions .isEqual (columnExpression , expression ).not ();
479
- }
480
- case LT : {
481
- Expression expression = bind (mappedValue , valueType , bindings , bindMarker );
482
- return column .isLess (expression );
483
- }
484
- case LTE : {
485
- Expression expression = bind (mappedValue , valueType , bindings , bindMarker );
486
- return column .isLessOrEqualTo (expression );
487
- }
488
- case GT : {
489
- Expression expression = bind (mappedValue , valueType , bindings , bindMarker );
490
- return column .isGreater (expression );
491
- }
492
- case GTE : {
493
- Expression expression = bind (mappedValue , valueType , bindings , bindMarker );
494
- return column .isGreaterOrEqualTo (expression );
495
- }
496
- case LIKE : {
497
- Expression expression = bind (mappedValue , valueType , bindings , bindMarker , ignoreCase );
498
- return Conditions .like (columnExpression , expression );
499
- }
500
- case NOT_LIKE : {
501
- Expression expression = bind (mappedValue , valueType , bindings , bindMarker , ignoreCase );
502
- return Conditions .notLike (columnExpression , expression );
503
- }
504
- default :
505
- throw new UnsupportedOperationException ("Comparator " + comparator + " not supported" );
506
- }
507
- }
473
+ if (Comparators .EQUALS .equals (comparator )) {
474
+ Expression expression = bind (mappedValue , valueType , bindings , bindMarker , ignoreCase );
475
+ return Conditions .isEqual (columnExpression , expression );
476
+
477
+ } else if (Comparators .NOT_EQUALS .equals (comparator )) {
478
+ Expression expression = bind (mappedValue , valueType , bindings , bindMarker , ignoreCase );
479
+ return Conditions .isEqual (columnExpression , expression ).not ();
480
+
481
+ } else if (Comparators .LESS_THAN .equals (comparator )) {
482
+ Expression expression = bind (mappedValue , valueType , bindings , bindMarker );
483
+ return column .isLess (expression );
484
+
485
+ } else if (Comparators .LESS_THAN_OR_EQUALS .equals (comparator )) {
486
+ Expression expression = bind (mappedValue , valueType , bindings , bindMarker );
487
+ return column .isLessOrEqualTo (expression );
488
+
489
+ } else if (Comparators .GREATER_THAN .equals (comparator )) {
490
+ Expression expression = bind (mappedValue , valueType , bindings , bindMarker );
491
+ return column .isGreater (expression );
492
+
493
+ } else if (Comparators .GREATER_THAN_OR_EQUALS .equals (comparator )) {
494
+ Expression expression = bind (mappedValue , valueType , bindings , bindMarker );
495
+ return column .isGreaterOrEqualTo (expression );
496
+
497
+ } else if (Comparators .LIKE .equals (comparator )) {
498
+ Expression expression = bind (mappedValue , valueType , bindings , bindMarker , ignoreCase );
499
+ return Conditions .like (columnExpression , expression );
500
+
501
+ } else if (Comparators .NOT_LIKE .equals (comparator )) {
502
+ Expression expression = bind (mappedValue , valueType , bindings , bindMarker , ignoreCase );
503
+ return Conditions .notLike (columnExpression , expression );
504
+ }
505
+ throw new UnsupportedOperationException ("Comparator " + comparator + " not supported" );
506
+ }
508
507
509
508
Field createPropertyField (@ Nullable RelationalPersistentEntity <?> entity , SqlIdentifier key ) {
510
509
return entity == null ? new Field (key ) : new MetadataBackedField (key , entity , mappingContext );
0 commit comments