Search in sources :

Example 1 with FromReferenceNode

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

the class HqlSqlWalker method lookupAlias.

@Override
protected void lookupAlias(AST aliasRef) throws SemanticException {
    FromElement alias = currentFromClause.getFromElement(aliasRef.getText());
    FromReferenceNode aliasRefNode = (FromReferenceNode) aliasRef;
    aliasRefNode.setFromElement(alias);
}
Also used : FromReferenceNode(org.hibernate.hql.internal.ast.tree.FromReferenceNode) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) EntityJoinFromElement(org.hibernate.hql.internal.ast.tree.EntityJoinFromElement)

Example 2 with FromReferenceNode

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

the class HQLTest method prepareTest.

@Override
protected void prepareTest() throws Exception {
    super.prepareTest();
    SelectClause.VERSION2_SQL = true;
    DotNode.regressionStyleJoinSuppression = true;
    DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER = new DotNode.IllegalCollectionDereferenceExceptionBuilder() {

        public QueryException buildIllegalCollectionDereferenceException(String propertyName, FromReferenceNode lhs) {
            throw new QueryException("illegal syntax near collection: " + propertyName);
        }
    };
    SqlGenerator.REGRESSION_STYLE_CROSS_JOINS = true;
}
Also used : FromReferenceNode(org.hibernate.hql.internal.ast.tree.FromReferenceNode) DotNode(org.hibernate.hql.internal.ast.tree.DotNode) QueryException(org.hibernate.QueryException)

Example 3 with FromReferenceNode

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

the class HqlSqlWalker method validateMapPropertyExpression.

@Override
protected void validateMapPropertyExpression(AST node) throws SemanticException {
    try {
        FromReferenceNode fromReferenceNode = (FromReferenceNode) node;
        QueryableCollection collectionPersister = fromReferenceNode.getFromElement().getQueryableCollection();
        if (!Map.class.isAssignableFrom(collectionPersister.getCollectionType().getReturnedClass())) {
            throw new SemanticException("node did not reference a map");
        }
    } catch (SemanticException se) {
        throw se;
    } catch (Throwable t) {
        throw new SemanticException("node did not reference a map");
    }
}
Also used : FromReferenceNode(org.hibernate.hql.internal.ast.tree.FromReferenceNode) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) Map(java.util.Map) HashMap(java.util.HashMap) SemanticException(antlr.SemanticException)

Example 4 with FromReferenceNode

use of org.hibernate.hql.internal.ast.tree.FromReferenceNode 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)

Example 5 with FromReferenceNode

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

the class HqlSqlWalker method createFromJoinElement.

@Override
protected void createFromJoinElement(AST path, AST alias, int joinType, AST fetchNode, AST propertyFetch, AST with) throws SemanticException {
    boolean fetch = fetchNode != null;
    if (fetch && isSubQuery()) {
        throw new QueryException("fetch not allowed in subquery from-elements");
    }
    // the incoming "path" can be either:
    //		1) an implicit join path (join p.address.city)
    // 		2) an entity-join (join com.acme.User)
    //
    // so make the proper interpretation here...
    final EntityPersister entityJoinReferencedPersister = resolveEntityJoinReferencedPersister(path);
    if (entityJoinReferencedPersister != null) {
        // `path` referenced an entity
        final EntityJoinFromElement join = createEntityJoin(entityJoinReferencedPersister, alias, joinType, propertyFetch, with);
        ((FromReferenceNode) path).setFromElement(join);
    } else {
        if (path.getType() != SqlTokenTypes.DOT) {
            throw new SemanticException("Path expected for join!");
        }
        DotNode dot = (DotNode) path;
        JoinType hibernateJoinType = JoinProcessor.toHibernateJoinType(joinType);
        // Tell the dot node about the join type.
        dot.setJoinType(hibernateJoinType);
        dot.setFetch(fetch);
        // Generate an explicit join for the root dot node.   The implied joins will be collected and passed up
        // to the root dot node.
        dot.resolve(true, false, alias == null ? null : alias.getText());
        final FromElement fromElement;
        if (dot.getDataType() != null && dot.getDataType().isComponentType()) {
            if (dot.getDataType().isAnyType()) {
                throw new SemanticException("An AnyType attribute cannot be join fetched");
            // ^^ because the discriminator (aka, the "meta columns") must be known to the SQL in
            // 		a non-parameterized way.
            }
            FromElementFactory factory = new FromElementFactory(getCurrentFromClause(), dot.getLhs().getFromElement(), dot.getPropertyPath(), alias == null ? null : alias.getText(), null, false);
            fromElement = factory.createComponentJoin((CompositeType) dot.getDataType());
        } else {
            fromElement = dot.getImpliedJoin();
            fromElement.setAllPropertyFetch(propertyFetch != null);
            if (with != null) {
                if (fetch) {
                    throw new SemanticException("with-clause not allowed on fetched associations; use filters");
                }
                handleWithFragment(fromElement, with);
            }
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("createFromJoinElement() : " + getASTPrinter().showAsString(fromElement, "-- join tree --"));
        }
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) FromReferenceNode(org.hibernate.hql.internal.ast.tree.FromReferenceNode) QueryException(org.hibernate.QueryException) EntityJoinFromElement(org.hibernate.hql.internal.ast.tree.EntityJoinFromElement) DotNode(org.hibernate.hql.internal.ast.tree.DotNode) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) EntityJoinFromElement(org.hibernate.hql.internal.ast.tree.EntityJoinFromElement) JoinType(org.hibernate.sql.JoinType) FromElementFactory(org.hibernate.hql.internal.ast.tree.FromElementFactory) SemanticException(antlr.SemanticException) CompositeType(org.hibernate.type.CompositeType)

Aggregations

FromReferenceNode (org.hibernate.hql.internal.ast.tree.FromReferenceNode)5 DotNode (org.hibernate.hql.internal.ast.tree.DotNode)3 SemanticException (antlr.SemanticException)2 QueryException (org.hibernate.QueryException)2 EntityJoinFromElement (org.hibernate.hql.internal.ast.tree.EntityJoinFromElement)2 FromElement (org.hibernate.hql.internal.ast.tree.FromElement)2 AST (antlr.collections.AST)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CollectionFunction (org.hibernate.hql.internal.ast.tree.CollectionFunction)1 FromElementFactory (org.hibernate.hql.internal.ast.tree.FromElementFactory)1 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 JoinType (org.hibernate.sql.JoinType)1 CompositeType (org.hibernate.type.CompositeType)1