@Override public String visitPredicate(FilterPredicate filterPredicate) { return apply(filterPredicate, prefixWithAlias); }
filterClause = new HQLFilterOperation().apply(filterExpression.get(), USE_ALIAS);
assertValidValues(fieldPath, firstParam); return String.format("lower(%s) LIKE CONCAT(lower(%s), '%%')", fieldPath, firstParam); assertValidValues(fieldPath, firstParam); return String.format("lower(%s) LIKE CONCAT('%%', lower(%s))", fieldPath, firstParam); assertValidValues(fieldPath, firstParam); return String.format("lower(%s) LIKE CONCAT('%%', lower(%s), '%%')", fieldPath, firstParam); return String.format("%s < %s", fieldPath, params.size() == 1 ? firstParam : leastClause(params)); return String.format("%s <= %s", fieldPath, params.size() == 1 ? firstParam : leastClause(params)); return String.format("%s > %s", fieldPath, params.size() == 1 ? firstParam : greatestClause(params)); return String.format("%s >= %s", fieldPath, params.size() == 1 ? firstParam : greatestClause(params));
@Test(expectedExceptions = InvalidValueException.class) public void testEmptyFieldOnPrefix() throws Exception { FilterPredicate pred = new FilterPredicate(new Path.PathElement(Book.class, Author.class, ""), Operator.PREFIX_CASE_INSENSITIVE, Arrays.asList("value")); HQLFilterOperation filterOp = new HQLFilterOperation(); filterOp.apply(pred); }
@Test(expectedExceptions = InvalidValueException.class) public void testEmptyFieldOnInfix() throws Exception { FilterPredicate pred = new FilterPredicate(new Path.PathElement(Book.class, Author.class, ""), Operator.INFIX_CASE_INSENSITIVE, Arrays.asList("value")); HQLFilterOperation filterOp = new HQLFilterOperation(); filterOp.apply(pred); }
@Override public String apply(FilterPredicate filterPredicate) { return apply(filterPredicate, false); }
@Test(expectedExceptions = InvalidValueException.class) public void testEmptyFieldOnPostfix() throws Exception { FilterPredicate pred = new FilterPredicate(new Path.PathElement(Book.class, Author.class, ""), Operator.POSTFIX_CASE_INSENSITIVE, Arrays.asList("value")); HQLFilterOperation filterOp = new HQLFilterOperation(); filterOp.apply(pred); } }
String filterClause = new HQLFilterOperation().apply(filterExpression.get(), USE_ALIAS);
filterClause = new HQLFilterOperation().apply(joinedExpression, USE_ALIAS); } else { + SPACE; filterClause = new HQLFilterOperation().apply(idExpression, USE_ALIAS); predicates.add(idExpression);
PredicateExtractionVisitor extractor = new PredicateExtractionVisitor(); Collection<FilterPredicate> predicates = fe.accept(extractor); String filterClause = new HQLFilterOperation().apply(fe, USE_ALIAS);
@Test public void testHQLQueryVisitor() throws Exception { List<Path.PathElement> p1Path = Arrays.asList( new Path.PathElement(Book.class, Author.class, "authors"), new Path.PathElement(Author.class, String.class, "name") ); FilterPredicate p1 = new InPredicate(new Path(p1Path), "foo", "bar"); List<Path.PathElement> p2Path = Arrays.asList( new Path.PathElement(Book.class, String.class, "name") ); FilterPredicate p2 = new InPredicate(new Path(p2Path), "blah"); List<Path.PathElement> p3Path = Arrays.asList( new Path.PathElement(Book.class, String.class, "genre") ); FilterPredicate p3 = new InPredicate(new Path(p3Path), "scifi"); OrFilterExpression or = new OrFilterExpression(p2, p3); AndFilterExpression and = new AndFilterExpression(or, p1); NotFilterExpression not = new NotFilterExpression(and); HQLFilterOperation filterOp = new HQLFilterOperation(); String query = filterOp.apply(not, false); String p1Params = p1.getParameters().stream() .map(FilterPredicate.FilterParameter::getPlaceholder).collect(Collectors.joining(", ")); String p2Params = p2.getParameters().stream() .map(FilterPredicate.FilterParameter::getPlaceholder).collect(Collectors.joining(", ")); String p3Params = p3.getParameters().stream() .map(FilterPredicate.FilterParameter::getPlaceholder).collect(Collectors.joining(", ")); String expected = "WHERE NOT (((name IN (" + p2Params + ") OR genre IN (" + p3Params + ")) " + "AND authors.name IN (" + p1Params + ")))"; Assert.assertEquals(query, expected); }