private static void convertOperatorNode(final FilterTermsTree.OperatorNode oldNode, final SqlBuilder sql) {
        if (oldNode.getChildren().size() < 1) {
            throw new RuntimeException("Operator node cannot have no children");
        }

        if (oldNode.getFilterOperationMode().equals(FilterOperationMode.NOT)) {
            String sqlOp = OPERATOR_TO_SQL_TERM_MAP.get(oldNode.getFilterOperationMode());
            if (oldNode.getChildren().size() > 1) {
                // Stroom supports NOT() with multiple children. This is treated as NOT( child1 OR child2 )
                sql.append(" " + sqlOp + " (");
                for (int i = 0; i < oldNode.getChildren().size(); i++) {
                    convertNode(oldNode.getChildren().get(i), sql);
                    if (i < oldNode.getChildren().size() - 1) {
                        sql.append(" OR");
                    }
                }
                sql.append(")");
            } else {
                // should get something like ' NOT (.......) '
                sql.append(" " + sqlOp + " (");
                convertNode(oldNode.getChildren().get(0), sql);
                sql.append(")");
            }

        } else {
            // OR or AND
            // should get something like ' (... AND ... AND ...) '
            // where ... could be a term or another operator set
            sql.append(" (");
            int i = 1;
            for (final PrintableNode oldChild : oldNode.getChildren()) {
                convertNode(oldChild, sql);

                if (i != oldNode.getChildren().size()) {
                    // not the last child so add the operator in between
                    sql.append(" " + OPERATOR_TO_SQL_TERM_MAP.get(oldNode.getFilterOperationMode()));
                }
                i++;
            }
            sql.append(" )");
        }
    }
Recursive method to build up a where clause string (and associated list
of bind variables) from a tree of {@link PrintableNode} objects
stroom-statistics/stroom-statistics-impl-sql/src/main/java/stroom/statistics/impl/sql/search/SQLTagValueWhereClauseConverter.java