Commit 0b3f93c1c6110c12e04420ad99d96ecc4be6fb8f

Authored by zbeacon
Committed by Andrew Shvayka
1 parent 5a4cb623

Fix for String filter on empty string received.

@@ -460,32 +460,59 @@ public class EntityKeyMapping { @@ -460,32 +460,59 @@ public class EntityKeyMapping {
460 } 460 }
461 switch (stringFilterPredicate.getOperation()) { 461 switch (stringFilterPredicate.getOperation()) {
462 case EQUAL: 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 break; 464 break;
465 case NOT_EQUAL: 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 break; 467 break;
468 case STARTS_WITH: 468 case STARTS_WITH:
469 value += "%"; 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 break; 471 break;
472 case ENDS_WITH: 472 case ENDS_WITH:
473 value = "%" + value; 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 break; 475 break;
476 case CONTAINS: 476 case CONTAINS:
477 value = "%" + value + "%"; 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 break; 479 break;
480 case NOT_CONTAINS: 480 case NOT_CONTAINS:
481 value = "%" + value + "%"; 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 break; 483 break;
484 } 484 }
485 ctx.addStringParameter(paramName, value); 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 private String buildNumericPredicateQuery(QueryContext ctx, String field, NumericFilterPredicate numericFilterPredicate) { 516 private String buildNumericPredicateQuery(QueryContext ctx, String field, NumericFilterPredicate numericFilterPredicate) {
490 String paramName = getNextParameterName(field); 517 String paramName = getNextParameterName(field);
491 ctx.addDoubleParameter(paramName, numericFilterPredicate.getValue().getValue()); 518 ctx.addDoubleParameter(paramName, numericFilterPredicate.getValue().getValue());