/** * append a custom expression to the string builder, replacing any * property tokens (i.e "{prop}") with a reference to the property. */ protected void appendCustomExpression(StringBuilder sb, SearchContext ctx, String expression) { Matcher matcher = Pattern.compile("\\{[\\w\\.]*\\}").matcher(expression); int lastEnd = 0; while (matcher.find()) { sb.append(expression.substring(lastEnd, matcher.start())); sb.append(getPathRef(ctx, expression.substring(matcher.start() + 1, matcher.end() - 1))); lastEnd = matcher.end(); } sb.append(expression.substring(lastEnd)); }
/** * append a custom expression to the string builder, replacing any * property tokens (i.e "{prop}") with a reference to the property and * value tokens (i.e. "?n") with params. */ protected void appendCustomExpression(StringBuilder sb, SearchContext ctx, String expression, List<?> values) { Matcher matcher = Pattern.compile("(\\{[\\w\\.]*\\})|(\\?\\d+\\b)").matcher(expression); int lastEnd = 0; while (matcher.find()) { sb.append(expression.substring(lastEnd, matcher.start())); if (expression.charAt(matcher.start()) == '{') { sb.append(getPathRef(ctx, expression.substring(matcher.start() + 1, matcher.end() - 1))); } else { int valueIndex = Integer.valueOf(expression.substring(matcher.start() + 1, matcher.end())); if (valueIndex == 0) { throw new IllegalArgumentException("This custom filter expression (" + expression + ") contains a value placeholder for zero (?0), but placeholders should be numbered starting at ?1."); } if (values == null || values.isEmpty()) { throw new IllegalArgumentException("This custom filter expression (" + expression + ") calls for a value placeholder number " + valueIndex + ", but no values were specified."); } if (valueIndex > values.size()) { throw new IllegalArgumentException("This custom filter expression (" + expression + ") calls for a value placeholder number " + valueIndex + ", but only " + values.size() + " values were specified."); } sb.append(param(ctx, values.get(valueIndex - 1))); } lastEnd = matcher.end(); } sb.append(expression.substring(lastEnd)); }
sb.append(getPathRef(ctx, property)); sb.append(" "); sb.append(ctx2.getRootAlias());
sb.append(ctx.getRootAlias()); } else { sb.append(getPathRef(ctx, prop));
} else if (sort.isIgnoreCase() && metadataUtil.get(ctx.rootClass, sort.getProperty()).isString()) { sb.append("lower("); sb.append(getPathRef(ctx, sort.getProperty())); sb.append(")"); } else { sb.append(getPathRef(ctx, sort.getProperty()));
return getPathRef(ctx, property) + " is null"; case Filter.OP_NOT_NULL: return getPathRef(ctx, property) + " is not null"; case Filter.OP_IN: return getPathRef(ctx, property) + " in (" + param(ctx, value) + ")"; case Filter.OP_NOT_IN: return getPathRef(ctx, property) + " not in (" + param(ctx, value) + ")"; case Filter.OP_EQUAL: return getPathRef(ctx, property) + " = " + param(ctx, value); case Filter.OP_NOT_EQUAL: return getPathRef(ctx, property) + " != " + param(ctx, value); case Filter.OP_GREATER_THAN: return getPathRef(ctx, property) + " > " + param(ctx, value); case Filter.OP_LESS_THAN: return getPathRef(ctx, property) + " < " + param(ctx, value); case Filter.OP_GREATER_OR_EQUAL: return getPathRef(ctx, property) + " >= " + param(ctx, value); case Filter.OP_LESS_OR_EQUAL: return getPathRef(ctx, property) + " <= " + param(ctx, value); case Filter.OP_LIKE: return getPathRef(ctx, property) + " like " + param(ctx, value.toString()); case Filter.OP_ILIKE: return "lower(" + getPathRef(ctx, property) + ") like lower(" + param(ctx, value.toString()) + ")"; case Filter.OP_AND: case Filter.OP_OR: metadata = metadataUtil.get(ctx.rootClass, property); if (metadata.isCollection()) { return "not exists elements(" + getPathRef(ctx, property) + ")";
prop = aliasNodeForProperty.alias; } else { prop = getPathRef(ctx, field.getProperty());
return param(ctx, value) + op + operation + " elements(" + getPathRef(ctx, property) + ")";