app/src/main/java/db/juhaku/juhakudb/filter/QueryProcessor.java
/**
     * Create joins from given root. Root is the first table of query which contains joins to other
     * tables in treelike format.
     *
     * @param root Instance of {@link Root} where to create joins from.
     * @param sql Instance of {@link StringBuilder} that contains current sql.
     *
     * @since 1.2.0
     *
     * @hide
     */
Create joins from given root. Root is the first table of query which contains joins to other
tables in treelike format.

@param root Instance of  Root where to create joins from.
@param sql Instance of  StringBuilder that contains current sql.



@hide
Create joins from given root . Root is the first table of query which contains joins to other tables in treelike format . @param root Instance of Root where to create joins from . @param sql Instance of StringBuilder that contains current sql . @hide
private void createJoins(Root<?> root, StringBuilder sql) {
        Class<?> model = root.getModel();
        String rootAlias = Alias.forModel(model);
        String rootTable = resolveName(model);
        for (Root<?> r : root.getJoins()) {
            Join join = (Join) r;
            Field targetField = ReflectionUtils.findField(model, join.getTarget());
            if (targetField.isAnnotationPresent(ManyToMany.class)) {
                createMiddleTableJoin(rootAlias, rootTable, join, sql);
            } else if (targetField.isAnnotationPresent(ManyToOne.class) ||
                    (targetField.isAnnotationPresent(OneToOne.class)
                            && StringUtils.isBlank(targetField.getAnnotation(OneToOne.class).mappedBy()))) {
                /*
                 * Join sql for join where root table is the owner of the join.
                 */
                joinSql(sql, join.getJoinMode(), resolveName(join.getModel()),
                        resolvePrimaryKey(model), rootAlias, resolveReverseJoinColumnName(model, join.getModel()),
                        Alias.forJoin(join), true);
            } else {
                /*
                 * Join sql for join where target table is the owner of the join.
                 */
                joinSql(sql, join.getJoinMode(), resolveName(join.getModel()), resolvePrimaryKey(model),
                        rootAlias, resolveReverseJoinColumnName(join.getModel(), model), Alias.forJoin(join), false);
            }
            if (!join.getJoins().isEmpty()) {
                createJoins(join, sql);
            }
        }
    }
private void createJoins ( Root < ? > root , StringBuilder sql ) { Class < ? > model = root . getModel ( ) ; String rootAlias = Alias . forModel ( model ) ; String rootTable = resolveName ( model ) ; for ( Root < ? > r : root . getJoins ( ) ) { Join join = ( Join ) r ; Field targetField = ReflectionUtils . findField ( model , join . getTarget ( ) ) ; if ( targetField . isAnnotationPresent ( ManyToMany . class ) ) { createMiddleTableJoin ( rootAlias , rootTable , join , sql ) ; } else if ( targetField . isAnnotationPresent ( ManyToOne . class ) || ( targetField . isAnnotationPresent ( OneToOne . class ) && StringUtils . isBlank ( targetField . getAnnotation ( OneToOne . class ) . mappedBy ( ) ) ) ) { /*
                 * Join sql for join where root table is the owner of the join.
                 */ joinSql ( sql , join . getJoinMode ( ) , resolveName ( join . getModel ( ) ) , resolvePrimaryKey ( model ) , rootAlias , resolveReverseJoinColumnName ( model , join . getModel ( ) ) , Alias . forJoin ( join ) , true ) ; } else { /*
                 * Join sql for join where target table is the owner of the join.
                 */ joinSql ( sql , join . getJoinMode ( ) , resolveName ( join . getModel ( ) ) , resolvePrimaryKey ( model ) , rootAlias , resolveReverseJoinColumnName ( join . getModel ( ) , model ) , Alias . forJoin ( join ) , false ) ; } if ( ! join . getJoins ( ) . isEmpty ( ) ) { createJoins ( join , sql ) ; } } }
Create joins from given root.
Create joins from given root .
//TODO if target field has column annotation use it as the name