Search in sources :

Example 1 with CollectionFunction

use of org.hibernate.hql.internal.ast.tree.CollectionFunction in project hibernate-orm by hibernate.

the class HqlSqlWalker method lookupProperty.

@Override
protected AST lookupProperty(AST dot, boolean root, boolean inSelect) throws SemanticException {
    DotNode dotNode = (DotNode) dot;
    FromReferenceNode lhs = dotNode.getLhs();
    AST rhs = lhs.getNextSibling();
    //		if both are true, we log a deprecation warning
    if (lhs.getDataType() != null && lhs.getDataType().isCollectionType()) {
        if (CollectionProperties.isCollectionProperty(rhs.getText())) {
            DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfCollectionPropertiesInHql(rhs.getText(), lhs.getPath());
        }
        // perform the re-arrangement
        if (CollectionPropertyNames.COLLECTION_INDICES.equalsIgnoreCase(rhs.getText()) || CollectionPropertyNames.COLLECTION_ELEMENTS.equalsIgnoreCase(rhs.getText())) {
            if (LOG.isDebugEnabled()) {
                LOG.debugf("lookupProperty() %s => %s(%s)", dotNode.getPath(), rhs.getText(), lhs.getPath());
            }
            final CollectionFunction f;
            if (rhs instanceof CollectionFunction) {
                f = (CollectionFunction) rhs;
            } else {
                f = new CollectionFunction();
                f.initialize(SqlTokenTypes.METHOD_CALL, rhs.getText());
                f.initialize(this);
            }
            // Re-arrange the tree so that the collection function is the root and the lhs is the path.
            f.setFirstChild(lhs);
            lhs.setNextSibling(null);
            dotNode.setFirstChild(f);
            // Don't forget to resolve the argument!
            resolve(lhs);
            // Resolve the collection function now.
            f.resolve(inSelect);
            return f;
        }
    }
    // otherwise, resolve the path and return it
    dotNode.resolveFirstChild();
    return dotNode;
}
Also used : FromReferenceNode(org.hibernate.hql.internal.ast.tree.FromReferenceNode) DotNode(org.hibernate.hql.internal.ast.tree.DotNode) AST(antlr.collections.AST) CollectionFunction(org.hibernate.hql.internal.ast.tree.CollectionFunction)

Aggregations

AST (antlr.collections.AST)1 CollectionFunction (org.hibernate.hql.internal.ast.tree.CollectionFunction)1 DotNode (org.hibernate.hql.internal.ast.tree.DotNode)1 FromReferenceNode (org.hibernate.hql.internal.ast.tree.FromReferenceNode)1