@Test public void testQueryBuilder() throws Exception { Calendar cal = new GregorianCalendar(2010, 0, 1, 12, 34, 56); try (Session session = getSession()) { QueryBuilder queryBuilder = new QueryBuilder().predicate(Predicates.not(Predicates.or(Predicates.eq("username", "user_1"), Predicates.eq("username", "Administrator")))) .and(Predicates.gt("intField", Long.valueOf(123))) .and(Predicates.noteq("booleanField", Long.valueOf(1))) .and(Predicates.between("intField", Long.valueOf(123), Long.valueOf(456))) .and(Predicates.like("firstName", "jo%n")) .and(Predicates.notlike("firstName", "bob")) .and(Predicates.gte("dateField", cal)) .and(Predicates.lt("doubleField", Double.valueOf(3.14))) .and(Predicates.in("company", "c1", "c2")) .and(Predicates.notin("company", "c3", "c4")) .and(Predicates.isnull("username")) .and(Predicates.ilike("firstName", "abc%")); LDAPFilterBuilder builder = new LDAPFilterBuilder(getDirectory()); builder.walk(queryBuilder.predicate()); assertEquals("(&" + "(!(|(uid={0})(uid={1})))" + "(intField>{2})" + "(!(booleanField={3}))" + "(&(intField>={4})(intField<={5}))" + "(givenName={6}*{7})" + "(!(givenName={8}))" + "(dateField>={9})" + "(doubleField<{10})" + "(|(o={11})(o={12}))" + "(!(|(o={13})(o={14})))" + "(!(uid=*))" + "(givenName={15}*)" + ")", builder.filter.toString()); assertEqualsNormalized(Arrays.asList( "user_1", "Administrator", Long.valueOf(123), Boolean.TRUE, Long.valueOf(123), Long.valueOf(456), "jo", "n", "bob", cal, Double.valueOf(3.14), "c1", "c2", "c3", "c4", "abc" ), builder.params.stream().collect(toList())); } }
public void walk(Expression expression) { if (expression instanceof MultiExpression && ((MultiExpression) expression).predicates.isEmpty()) { return; } else { walkExpression(expression); } }
LDAPFilterBuilder { public void walk(Expression expression) { if (expression instanceof MultiExpression && ((MultiExpression) expression).predicates.isEmpty()) { return; } else { walkExpression(expression); } } }
LDAPFilterBuilder { public void walk(Expression expression) { if (expression instanceof MultiExpression && ((MultiExpression) expression).predicates.isEmpty()) { return; } else { walkExpression(expression); } } LDAPFilterBuilder(LDAPDirectory directory); }
LDAPFilterBuilder { public void walk(Expression expression) { if (expression instanceof MultiExpression && ((MultiExpression) expression).predicates.isEmpty()) { return; } else { walkExpression(expression); } } LDAPFilterBuilder(LDAPDirectory directory); void walk(Expression expression); void walkExpression(Expression expr); void walkNot(Operand value); void walkIsNull(Operand value); void walkIsNotNull(Operand value); void walkAndMultiExpression(MultiExpression expr); void walkAnd(Expression expr); void walkOrMultiExpression(MultiExpression expr); void walkOr(Expression expr); void walkEq(Operand lvalue, Operand rvalue); void walkNotEq(Operand lvalue, Operand rvalue); void walkLt(Operand lvalue, Operand rvalue); void walkGt(Operand lvalue, Operand rvalue); void walkLtEq(Operand lvalue, Operand rvalue); void walkGtEq(Operand lvalue, Operand rvalue); void walkBetween(Operand lvalue, Operand rvalue, boolean positive); void walkIn(Operand lvalue, Operand rvalue, boolean positive); void walkLike(Operand lvalue, Operand rvalue, boolean positive, boolean caseInsensitive); void walkLikeWildcard(String like); void walkOperand(Operand operand); void walkLiteral(Operand operand); void walkBooleanLiteral(BooleanLiteral lit); void walkDateLiteral(DateLiteral lit); void walkDoubleLiteral(DoubleLiteral lit); void walkIntegerLiteral(IntegerLiteral lit); void walkStringLiteral(StringLiteral lit); Object walkFunction(Function func); Field walkReference(Operand value); }
LDAPFilterBuilder { public void walk(Expression expression) { if (expression instanceof MultiExpression && ((MultiExpression) expression).predicates.isEmpty()) { return; } else { walkExpression(expression); } } LDAPFilterBuilder(LDAPDirectory directory); void walk(Expression expression); void walkExpression(Expression expr); void walkNot(Operand value); void walkIsNull(Operand value); void walkIsNotNull(Operand value); void walkAndMultiExpression(MultiExpression expr); void walkAnd(Expression expr); void walkOrMultiExpression(MultiExpression expr); void walkOr(Expression expr); void walkEq(Operand lvalue, Operand rvalue); void walkNotEq(Operand lvalue, Operand rvalue); void walkLt(Operand lvalue, Operand rvalue); void walkGt(Operand lvalue, Operand rvalue); void walkLtEq(Operand lvalue, Operand rvalue); void walkGtEq(Operand lvalue, Operand rvalue); void walkBetween(Operand lvalue, Operand rvalue, boolean positive); void walkIn(Operand lvalue, Operand rvalue, boolean positive); void walkLike(Operand lvalue, Operand rvalue, boolean positive, boolean caseInsensitive); void walkLikeWildcard(String like); void walkOperand(Operand operand); void walkLiteral(Operand operand); void walkBooleanLiteral(BooleanLiteral lit); void walkDateLiteral(DateLiteral lit); void walkDoubleLiteral(DoubleLiteral lit); void walkIntegerLiteral(IntegerLiteral lit); void walkStringLiteral(StringLiteral lit); Object walkFunction(Function func); Field walkReference(Operand value); public StringBuilder filter; public int paramIndex; final List<Serializable> params; }