Commit 0b3f93c1c6110c12e04420ad99d96ecc4be6fb8f
Committed by
Andrew Shvayka
1 parent
5a4cb623
Fix for String filter on empty string received.
Showing
1 changed file
with
34 additions
and
7 deletions
... | ... | @@ -460,32 +460,59 @@ public class EntityKeyMapping { |
460 | 460 | } |
461 | 461 | switch (stringFilterPredicate.getOperation()) { |
462 | 462 | case EQUAL: |
463 | - stringOperationQuery = String.format("%s = :%s", operationField, paramName); | |
463 | + stringOperationQuery = String.format("%s = :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName); | |
464 | 464 | break; |
465 | 465 | case NOT_EQUAL: |
466 | - stringOperationQuery = String.format("%s != :%s", operationField, paramName); | |
466 | + stringOperationQuery = String.format("%s != :%s) or (%s is null and :%s != '')", operationField, paramName, operationField, paramName); | |
467 | 467 | break; |
468 | 468 | case STARTS_WITH: |
469 | 469 | value += "%"; |
470 | - stringOperationQuery = String.format("%s like :%s", operationField, paramName); | |
470 | + stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '%%')", operationField, paramName, operationField, paramName); | |
471 | 471 | break; |
472 | 472 | case ENDS_WITH: |
473 | 473 | value = "%" + value; |
474 | - stringOperationQuery = String.format("%s like :%s", operationField, paramName); | |
474 | + stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '%%')", operationField, paramName, operationField, paramName); | |
475 | 475 | break; |
476 | 476 | case CONTAINS: |
477 | 477 | value = "%" + value + "%"; |
478 | - stringOperationQuery = String.format("%s like :%s", operationField, paramName); | |
478 | + stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '%%%%')", operationField, paramName, operationField, paramName); | |
479 | 479 | break; |
480 | 480 | case NOT_CONTAINS: |
481 | 481 | value = "%" + value + "%"; |
482 | - stringOperationQuery = String.format("%s not like :%s", operationField, paramName); | |
482 | + stringOperationQuery = String.format("%s not like :%s) or (%s is null and :%s != '%%%%')", operationField, paramName, operationField, paramName); | |
483 | 483 | break; |
484 | 484 | } |
485 | 485 | ctx.addStringParameter(paramName, value); |
486 | - return String.format("(%s is not null and %s)", field, stringOperationQuery); | |
486 | + return String.format("((%s is not null and %s)", field, stringOperationQuery); | |
487 | 487 | } |
488 | 488 | |
489 | + | |
490 | +// case EQUAL: | |
491 | +// stringOperationQuery = String.format("%s = :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName); | |
492 | +// break; | |
493 | +// case NOT_EQUAL: | |
494 | +// stringOperationQuery = String.format("%s != :%s) or (%s is null and :%s != '')", operationField, paramName, operationField, paramName); | |
495 | +// break; | |
496 | +// case STARTS_WITH: | |
497 | +// value += "%"; | |
498 | +// stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName); | |
499 | +// break; | |
500 | +// case ENDS_WITH: | |
501 | +// value = "%" + value; | |
502 | +// stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName); | |
503 | +// break; | |
504 | +// case CONTAINS: | |
505 | +// value = "%" + value + "%"; | |
506 | +// stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName); | |
507 | +// break; | |
508 | +// case NOT_CONTAINS: | |
509 | +// value = "%" + value + "%"; | |
510 | +// stringOperationQuery = String.format("%s not like :%s) or (%s is null and :%s != '')", operationField, paramName, operationField, paramName); | |
511 | +// break; | |
512 | +//} | |
513 | +// ctx.addStringParameter(paramName, value); | |
514 | +// return String.format("((%s is not null and %s)", field, stringOperationQuery); | |
515 | + | |
489 | 516 | private String buildNumericPredicateQuery(QueryContext ctx, String field, NumericFilterPredicate numericFilterPredicate) { |
490 | 517 | String paramName = getNextParameterName(field); |
491 | 518 | ctx.addDoubleParameter(paramName, numericFilterPredicate.getValue().getValue()); | ... | ... |