app/src/main/java/db/juhaku/juhakudb/filter/QueryProcessor.java
/**
     * Create where statement without "WHERE" in the beginning. Where statement is created from
     * provided predicates.
     *
     * <p>Sql will be updated according the predicates provided and all provided parameters will be
     * returned by the method in correct order. Parameters are returned to support old api.</p>
     *
     * @param root {@link Root} of where statement.
     * @param sql {@link StringBuilder} current sql.
     * @param predicateBuilder {@link PredicateBuilder} WHERE statement query builder.
     * @return String array of parameters from predicates.
     *
     * @since 1.2.0
     *
     * @hide
     */
Create where statement without "WHERE" in the beginning. Where statement is created from
provided predicates.

Sql will be updated according the predicates provided and all provided parameters will be
returned by the method in correct order. Parameters are returned to support old api.

@param root  Root of where statement.
@param sql  StringBuilder current sql.
@param predicateBuilder  PredicateBuilder WHERE statement query builder.
@return String array of parameters from predicates.



@hide
Create where statement without " WHERE " in the beginning . Where statement is created from provided predicates . Sql will be updated according the predicates provided and all provided parameters will be returned by the method in correct order . Parameters are returned to support old api . @param root Root of where statement . @param sql StringBuilder current sql . @param predicateBuilder PredicateBuilder WHERE statement query builder . @return String array of parameters from predicates . @hide
private String[] createWhere(Root<?> root, StringBuilder sql, PredicateBuilder predicateBuilder) {
        String[] args = new String[0];
        String alias = null;
        if (root.getModel() != null) {
            alias = Alias.forModel(root.getModel());
        }
        Iterator<Predicate> iterator = predicateBuilder.getPredicates().iterator();
        while (iterator.hasNext()) {
            Predicate predicate = iterator.next();
            if (predicate instanceof Junction) {
                sql.append("(");
                Iterator<Predicate> junctionIterator = ((Junction) predicate).getPredicates().iterator();
                while (junctionIterator.hasNext()) {
                    Predicate junction = junctionIterator.next();
                    sql.append(formatClause(junction.getClause(), alias));
                    if (junctionIterator.hasNext()) {
                        sql.append(((Junction) predicate).getOperator().getValue());
                    }
                    String[] junctionArgs = junction.getArgs();
                    if (junctionArgs.length > 0) {
                        args = addArgsToArray(args, junctionArgs);
                    }
                }
                sql.append(")");
                if (iterator.hasNext()) {
                    sql.append(BooleanOperator.AND.getValue());
                }
            } else {
                /*
                 * Non junctions are just added to to where clause.
                 */
                sql.append(formatClause(predicate.getClause(), alias));
                if (iterator.hasNext()) {
                    sql.append(BooleanOperator.AND.getValue());
                }
                String[] predicateArgs = predicate.getArgs();
                if (predicateArgs.length > 0) {
                    args = addArgsToArray(args, predicateArgs);
                }
            }
        }
        return args;
    }
private String [ ] createWhere ( Root < ? > root , StringBuilder sql , PredicateBuilder predicateBuilder ) { String [ ] args = new String [ 0 ] ; String alias = null ; if ( root . getModel ( ) != null ) { alias = Alias . forModel ( root . getModel ( ) ) ; } Iterator < Predicate > iterator = predicateBuilder . getPredicates ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { Predicate predicate = iterator . next ( ) ; if ( predicate instanceof Junction ) { sql . append ( "(" ) ; Iterator < Predicate > junctionIterator = ( ( Junction ) predicate ) . getPredicates ( ) . iterator ( ) ; while ( junctionIterator . hasNext ( ) ) { Predicate junction = junctionIterator . next ( ) ; sql . append ( formatClause ( junction . getClause ( ) , alias ) ) ; if ( junctionIterator . hasNext ( ) ) { sql . append ( ( ( Junction ) predicate ) . getOperator ( ) . getValue ( ) ) ; } String [ ] junctionArgs = junction . getArgs ( ) ; if ( junctionArgs . length > 0 ) { args = addArgsToArray ( args , junctionArgs ) ; } } sql . append ( ")" ) ; if ( iterator . hasNext ( ) ) { sql . append ( BooleanOperator . AND . getValue ( ) ) ; } } else { /*
                 * Non junctions are just added to to where clause.
                 */ sql . append ( formatClause ( predicate . getClause ( ) , alias ) ) ; if ( iterator . hasNext ( ) ) { sql . append ( BooleanOperator . AND . getValue ( ) ) ; } String [ ] predicateArgs = predicate . getArgs ( ) ; if ( predicateArgs . length > 0 ) { args = addArgsToArray ( args , predicateArgs ) ; } } } return args ; }
Create where statement without "WHERE" in the beginning.
Create where statement without " WHERE " in the beginning .
// Loop through all predicates to create where clause // Create grouping for junctions // Only add args to array from junction if there actually is arguments. // Add args only if args are provided.