3333import org .springframework .data .relational .core .dialect .Escaper ;
3434import org .springframework .data .relational .core .mapping .RelationalPersistentEntity ;
3535import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
36+ import org .springframework .data .relational .core .query .Comparator ;
3637import org .springframework .data .relational .core .query .CriteriaDefinition ;
37- import org .springframework .data .relational .core .query .CriteriaDefinition .Comparator ;
3838import org .springframework .data .relational .core .query .ValueFunction ;
39+ import org .springframework .data .relational .core .query .Comparators ;
3940import org .springframework .data .relational .core .sql .*;
4041import org .springframework .data .relational .domain .SqlSort ;
4142import org .springframework .data .util .Pair ;
5859 * @author Manousos Mathioudakis
5960 * @author Jens Schauder
6061 * @author Yan Qiang
62+ * @author Mikhail Polivakha
6163 */
6264public class QueryMapper {
6365
@@ -325,7 +327,7 @@ private Condition mapCondition(CriteriaDefinition criteria, MutableBindings bind
325327
326328 private Escaper getEscaper (Comparator comparator ) {
327329
328- if (comparator == Comparator .LIKE || comparator == Comparator .NOT_LIKE ) {
330+ if (comparator == Comparators .LIKE || comparator == Comparators .NOT_LIKE ) {
329331 return dialect .getLikeEscaper ();
330332 }
331333
@@ -351,7 +353,7 @@ public Parameter getBindValue(Parameter value) {
351353 @ Nullable
352354 private Object convertValue (Comparator comparator , @ Nullable Object value , TypeInformation <?> typeHint ) {
353355
354- if ((Comparator .IN .equals (comparator ) || Comparator .NOT_IN .equals (comparator ))
356+ if ((Comparators .IN .equals (comparator ) || Comparators .NOT_IN .equals (comparator ))
355357 && value instanceof Collection <?> collection && !collection .isEmpty ()) {
356358
357359 Collection <Object > mapped = new ArrayList <>(collection .size ());
@@ -396,21 +398,21 @@ protected MappingContext<? extends RelationalPersistentEntity<?>, RelationalPers
396398 private Condition createCondition (Column column , @ Nullable Object mappedValue , Class <?> valueType ,
397399 MutableBindings bindings , Comparator comparator , boolean ignoreCase ) {
398400
399- if (comparator .equals (Comparator .IS_NULL )) {
401+ if (comparator .equals (Comparators .IS_NULL )) {
400402 return column .isNull ();
401403 }
402404
403- if (comparator .equals (Comparator .IS_NOT_NULL )) {
405+ if (comparator .equals (Comparators .IS_NOT_NULL )) {
404406 return column .isNotNull ();
405407 }
406408
407- if (comparator == Comparator .IS_TRUE ) {
409+ if (comparator == Comparators .IS_TRUE ) {
408410 Expression bind = booleanBind (column , mappedValue , valueType , bindings , ignoreCase );
409411
410412 return column .isEqualTo (bind );
411413 }
412414
413- if (comparator == Comparator .IS_FALSE ) {
415+ if (comparator == Comparators .IS_FALSE ) {
414416 Expression bind = booleanBind (column , mappedValue , valueType , bindings , ignoreCase );
415417
416418 return column .isEqualTo (bind );
@@ -421,7 +423,7 @@ private Condition createCondition(Column column, @Nullable Object mappedValue, C
421423 columnExpression = Functions .upper (column );
422424 }
423425
424- if (comparator == Comparator .NOT_IN || comparator == Comparator .IN ) {
426+ if (comparator == Comparators .NOT_IN || comparator == Comparators .IN ) {
425427
426428 Condition condition ;
427429
@@ -446,14 +448,14 @@ private Condition createCondition(Column column, @Nullable Object mappedValue, C
446448 condition = Conditions .in (columnExpression , expression );
447449 }
448450
449- if (comparator == Comparator .NOT_IN ) {
451+ if (comparator == Comparators .NOT_IN ) {
450452 condition = condition .not ();
451453 }
452454
453455 return condition ;
454456 }
455457
456- if (comparator == Comparator .BETWEEN || comparator == Comparator .NOT_BETWEEN ) {
458+ if (comparator == Comparators .BETWEEN || comparator == Comparators .NOT_BETWEEN ) {
457459
458460 Pair <Object , Object > pair = (Pair <Object , Object >) mappedValue ;
459461
@@ -462,49 +464,46 @@ private Condition createCondition(Column column, @Nullable Object mappedValue, C
462464 Expression end = bind (pair .getSecond (), valueType , bindings , bindings .nextMarker (column .getName ().getReference ()),
463465 ignoreCase );
464466
465- return comparator == Comparator .BETWEEN ? Conditions .between (columnExpression , begin , end )
467+ return comparator == Comparators .BETWEEN ? Conditions .between (columnExpression , begin , end )
466468 : Conditions .notBetween (columnExpression , begin , end );
467469 }
468470
469471 BindMarker bindMarker = bindings .nextMarker (column .getName ().getReference ());
470472
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+ }
508507
509508 Field createPropertyField (@ Nullable RelationalPersistentEntity <?> entity , SqlIdentifier key ) {
510509 return entity == null ? new Field (key ) : new MetadataBackedField (key , entity , mappingContext );
0 commit comments