Search in sources :

Example 1 with JoinProcessor

use of org.hibernate.hql.internal.ast.util.JoinProcessor in project hibernate-orm by hibernate.

the class HqlSqlWalker method processQuery.

@Override
protected void processQuery(AST select, AST query) throws SemanticException {
    if (LOG.isDebugEnabled()) {
        LOG.debugf("processQuery() : %s", query.toStringTree());
    }
    try {
        QueryNode qn = (QueryNode) query;
        // Was there an explicit select expression?
        boolean explicitSelect = select != null && select.getNumberOfChildren() > 0;
        // Add in the EntityGraph attribute nodes.
        if (queryTranslatorImpl.getEntityGraphQueryHint() != null) {
            final boolean oldInEntityGraph = inEntityGraph;
            try {
                inEntityGraph = true;
                qn.getFromClause().getFromElements().addAll(queryTranslatorImpl.getEntityGraphQueryHint().toFromElements(qn.getFromClause(), this));
            } finally {
                inEntityGraph = oldInEntityGraph;
            }
        }
        if (!explicitSelect) {
            // No explicit select expression; render the id and properties
            // projection lists for every persister in the from clause into
            // a single 'token node'.
            //TODO: the only reason we need this stuff now is collection filters,
            //      we should get rid of derived select clause completely!
            createSelectClauseFromFromClause(qn);
        } else {
            // Use the explicitly declared select expression; determine the
            // return types indicated by each select token
            useSelectClause(select);
        }
        // After that, process the JOINs.
        // Invoke a delegate to do the work, as this is farily complex.
        JoinProcessor joinProcessor = new JoinProcessor(this);
        joinProcessor.processJoins(qn);
        // Attach any mapping-defined "ORDER BY" fragments
        Iterator itr = qn.getFromClause().getProjectionList().iterator();
        while (itr.hasNext()) {
            final FromElement fromElement = (FromElement) itr.next();
            //			if ( fromElement.isFetch() && fromElement.isCollectionJoin() ) {
            if (fromElement.isFetch() && fromElement.getQueryableCollection() != null) {
                // the query's order-by
                if (fromElement.getQueryableCollection().hasOrdering()) {
                    String orderByFragment = fromElement.getQueryableCollection().getSQLOrderByString(fromElement.getCollectionTableAlias());
                    qn.getOrderByClause().addOrderFragment(orderByFragment);
                }
                if (fromElement.getQueryableCollection().hasManyToManyOrdering()) {
                    String orderByFragment = fromElement.getQueryableCollection().getManyToManyOrderByString(fromElement.getTableAlias());
                    qn.getOrderByClause().addOrderFragment(orderByFragment);
                }
            }
        }
    } finally {
        popFromClause();
    }
}
Also used : QueryNode(org.hibernate.hql.internal.ast.tree.QueryNode) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) EntityJoinFromElement(org.hibernate.hql.internal.ast.tree.EntityJoinFromElement) Iterator(java.util.Iterator) JoinProcessor(org.hibernate.hql.internal.ast.util.JoinProcessor)

Aggregations

Iterator (java.util.Iterator)1 EntityJoinFromElement (org.hibernate.hql.internal.ast.tree.EntityJoinFromElement)1 FromElement (org.hibernate.hql.internal.ast.tree.FromElement)1 QueryNode (org.hibernate.hql.internal.ast.tree.QueryNode)1 JoinProcessor (org.hibernate.hql.internal.ast.util.JoinProcessor)1