@Test public void testQueryBuilderEmpty() throws Exception { try (Session session = getSession()) { QueryBuilder queryBuilder = new QueryBuilder(); SQLQueryBuilder builder = new SQLQueryBuilder(getDirectory()); builder.visitMultiExpression(queryBuilder.predicate()); assertEquals("", builder.clause.toString()); assertEquals(Collections.emptyList(), builder.params.stream().map(cv -> cv.value).collect(toList())); } }
@Override public void visitMultiExpression(MultiExpression node) { if (node.predicates.isEmpty()) { return; } clause.append('('); for (Iterator<Predicate> it = node.predicates.iterator(); it.hasNext();) { it.next().accept(this); if (it.hasNext()) { node.operator.accept(this); } } clause.append(')'); }
SQLQueryBuilder extends DefaultQueryVisitor { @Override public void visitMultiExpression(MultiExpression node) { if (node.predicates.isEmpty()) { return; } clause.append('('); for (Iterator<Predicate> it = node.predicates.iterator(); it.hasNext();) { it.next().accept(this); if (it.hasNext()) { node.operator.accept(this); } } clause.append(')'); } }
SQLQueryBuilder extends DefaultQueryVisitor { @Override public void visitMultiExpression(MultiExpression node) { if (node.predicates.isEmpty()) { return; } clause.append('('); for (Iterator<Predicate> it = node.predicates.iterator(); it.hasNext();) { it.next().accept(this); if (it.hasNext()) { node.operator.accept(this); } } clause.append(')'); } SQLQueryBuilder(SQLDirectory directory); }
SQLQueryBuilder extends DefaultQueryVisitor { @Override public void visitMultiExpression(MultiExpression node) { if (node.predicates.isEmpty()) { return; } clause.append('('); for (Iterator<Predicate> it = node.predicates.iterator(); it.hasNext();) { it.next().accept(this); if (it.hasNext()) { node.operator.accept(this); } } clause.append(')'); } SQLQueryBuilder(SQLDirectory directory); @Override void visitMultiExpression(MultiExpression node); @Override void visitExpression(Expression node); @Override void visitOperator(Operator node); @Override void visitReference(Reference node); @Override void visitLiteralList(LiteralList node); @Override void visitDateLiteral(DateLiteral node); @Override void visitStringLiteral(StringLiteral node); @Override void visitDoubleLiteral(DoubleLiteral node); @Override void visitIntegerLiteral(IntegerLiteral node); @Override void visitBooleanLiteral(BooleanLiteral node); @Override void visitFunction(Function node); }
SQLQueryBuilder extends DefaultQueryVisitor { @Override public void visitMultiExpression(MultiExpression node) { if (node.predicates.isEmpty()) { return; } clause.append('('); for (Iterator<Predicate> it = node.predicates.iterator(); it.hasNext();) { it.next().accept(this); if (it.hasNext()) { node.operator.accept(this); } } clause.append(')'); } SQLQueryBuilder(SQLDirectory directory); @Override void visitMultiExpression(MultiExpression node); @Override void visitExpression(Expression node); @Override void visitOperator(Operator node); @Override void visitReference(Reference node); @Override void visitLiteralList(LiteralList node); @Override void visitDateLiteral(DateLiteral node); @Override void visitStringLiteral(StringLiteral node); @Override void visitDoubleLiteral(DoubleLiteral node); @Override void visitIntegerLiteral(IntegerLiteral node); @Override void visitBooleanLiteral(BooleanLiteral node); @Override void visitFunction(Function node); final StringBuilder clause; final List<ColumnAndValue> params; }