Example #1
0
        void CreateFromJoinElement(
            IASTNode path,
            IASTNode alias,
            int joinType,
            IASTNode fetchNode,
            IASTNode propertyFetch,
            IASTNode with)
        {
            bool fetch = fetchNode != null;

            if (fetch && IsSubQuery)
            {
                throw new QueryException("fetch not allowed in subquery from-elements");
            }
            // The path AST should be a DotNode, and it should have been evaluated already.
            if (path.Type != DOT)
            {
                throw new SemanticException("Path expected for join!");
            }

            DotNode dot = ( DotNode )path;
            //JoinType hibernateJoinType = JoinProcessor.ToHibernateJoinType( joinType );
            JoinType hibernateJoinType = _impliedJoinType;

            dot.JoinType = hibernateJoinType;                   // Tell the dot node about the join type.
            dot.Fetch    = 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.Text);

            FromElement fromElement;

            if (dot.DataType != null && dot.DataType.IsComponentType)
            {
                var factory = new FromElementFactory(CurrentFromClause, dot.GetLhs().FromElement, dot.PropertyPath, alias == null ? null : alias.Text, null, false);
                fromElement = factory.CreateComponentJoin((ComponentType)dot.DataType);
            }
            else
            {
                fromElement = dot.GetImpliedJoin();
                if (fromElement == null)
                {
                    throw new InvalidPathException("Invalid join: " + dot.Path);
                }
                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() : {0}", _printer.ShowAsString(fromElement, "-- join tree --"));
            }
        }
Example #2
0
        void CreateFromJoinElement(
            IASTNode path,
            IASTNode alias,
            int joinType,
            IASTNode fetchNode,
            IASTNode propertyFetch,
            IASTNode with)
        {
            bool 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...
            var entityJoinReferencedPersister = ResolveEntityJoinReferencedPersister(path);

            if (entityJoinReferencedPersister != null)
            {
                var entityJoin = CreateEntityJoin(entityJoinReferencedPersister, alias, joinType, with);
                ((FromReferenceNode)path).FromElement = entityJoin;
                SetPropertyFetch(entityJoin, propertyFetch, alias);
                return;
            }
            // The path AST should be a DotNode, and it should have been evaluated already.
            if (path.Type != DOT)
            {
                throw new SemanticException("Path expected for join!");
            }

            DotNode dot = ( DotNode )path;
            //JoinType hibernateJoinType = JoinProcessor.ToHibernateJoinType( joinType );
            JoinType hibernateJoinType = _impliedJoinType;

            dot.JoinType = hibernateJoinType;                   // Tell the dot node about the join type.
            dot.Fetch    = 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.Text);

            FromElement fromElement;

            if (dot.DataType != null && dot.DataType.IsComponentType)
            {
                var factory = new FromElementFactory(CurrentFromClause, dot.GetLhs().FromElement, dot.PropertyPath, alias == null ? null : alias.Text, null, false);
                fromElement = factory.CreateComponentJoin((ComponentType)dot.DataType);
            }
            else
            {
                fromElement = dot.GetImpliedJoin();
                if (fromElement == null)
                {
                    throw new InvalidPathException("Invalid join: " + dot.Path);
                }
                SetPropertyFetch(fromElement, propertyFetch, alias);

                if (with != null)
                {
                    if (fetch)
                    {
                        throw new SemanticException("with-clause not allowed on fetched associations; use filters");
                    }

                    HandleWithFragment(fromElement, with);
                }

                if (fromElement.Parent == null)
                {
                    fromElement.FromClause.AddChild(fromElement);
                }
            }

            if (log.IsDebugEnabled())
            {
                log.Debug("createFromJoinElement() : {0}", _printer.ShowAsString(fromElement, "-- join tree --"));
            }
        }