Browse Source

Fix for String filter on empty string received.

pull/3172/head
zbeacon 6 years ago
committed by Andrew Shvayka
parent
commit
0b3f93c1c6
  1. 41
      dao/src/main/java/org/thingsboard/server/dao/sql/query/EntityKeyMapping.java

41
dao/src/main/java/org/thingsboard/server/dao/sql/query/EntityKeyMapping.java

@ -460,32 +460,59 @@ public class EntityKeyMapping {
}
switch (stringFilterPredicate.getOperation()) {
case EQUAL:
stringOperationQuery = String.format("%s = :%s", operationField, paramName);
stringOperationQuery = String.format("%s = :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName);
break;
case NOT_EQUAL:
stringOperationQuery = String.format("%s != :%s", operationField, paramName);
stringOperationQuery = String.format("%s != :%s) or (%s is null and :%s != '')", operationField, paramName, operationField, paramName);
break;
case STARTS_WITH:
value += "%";
stringOperationQuery = String.format("%s like :%s", operationField, paramName);
stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '%%')", operationField, paramName, operationField, paramName);
break;
case ENDS_WITH:
value = "%" + value;
stringOperationQuery = String.format("%s like :%s", operationField, paramName);
stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '%%')", operationField, paramName, operationField, paramName);
break;
case CONTAINS:
value = "%" + value + "%";
stringOperationQuery = String.format("%s like :%s", operationField, paramName);
stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '%%%%')", operationField, paramName, operationField, paramName);
break;
case NOT_CONTAINS:
value = "%" + value + "%";
stringOperationQuery = String.format("%s not like :%s", operationField, paramName);
stringOperationQuery = String.format("%s not like :%s) or (%s is null and :%s != '%%%%')", operationField, paramName, operationField, paramName);
break;
}
ctx.addStringParameter(paramName, value);
return String.format("(%s is not null and %s)", field, stringOperationQuery);
return String.format("((%s is not null and %s)", field, stringOperationQuery);
}
// case EQUAL:
// stringOperationQuery = String.format("%s = :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName);
// break;
// case NOT_EQUAL:
// stringOperationQuery = String.format("%s != :%s) or (%s is null and :%s != '')", operationField, paramName, operationField, paramName);
// break;
// case STARTS_WITH:
// value += "%";
// stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName);
// break;
// case ENDS_WITH:
// value = "%" + value;
// stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName);
// break;
// case CONTAINS:
// value = "%" + value + "%";
// stringOperationQuery = String.format("%s like :%s) or (%s is null and :%s = '')", operationField, paramName, operationField, paramName);
// break;
// case NOT_CONTAINS:
// value = "%" + value + "%";
// stringOperationQuery = String.format("%s not like :%s) or (%s is null and :%s != '')", operationField, paramName, operationField, paramName);
// break;
//}
// ctx.addStringParameter(paramName, value);
// return String.format("((%s is not null and %s)", field, stringOperationQuery);
private String buildNumericPredicateQuery(QueryContext ctx, String field, NumericFilterPredicate numericFilterPredicate) {
String paramName = getNextParameterName(field);
ctx.addDoubleParameter(paramName, numericFilterPredicate.getValue().getValue());

Loading…
Cancel
Save