示例#1
0
        protected IASTNode LookupProperty(IASTNode dot, bool root, bool inSelect)
        {
            DotNode           dotNode = (DotNode)dot;
            FromReferenceNode lhs     = dotNode.GetLhs();
            IASTNode          rhs     = lhs.NextSibling;

            switch (rhs.Type)
            {
            case ELEMENTS:
            case INDICES:
                if (log.IsDebugEnabled)
                {
                    log.Debug("lookupProperty() " + dotNode.Path + " => " + rhs.Text + "(" + lhs.Path + ")");
                }

                CollectionFunction f = (CollectionFunction)rhs;
                // Re-arrange the tree so that the collection function is the root and the lhs is the path.

                f.SetFirstChild(lhs);
                lhs.NextSibling = null;
                dotNode.SetFirstChild(f);

                Resolve(lhs);                         // Don't forget to resolve the argument!
                f.Resolve(inSelect);                  // Resolve the collection function now.
                return(f);

            default:
                // Resolve everything up to this dot, but don't resolve the placeholders yet.
                dotNode.ResolveFirstChild();
                return(dotNode);
            }
        }
        private static string GetPropertyPath(DotNode dotNode, IASTNode alias)
        {
            var lhs = dotNode.GetLhs();
            var rhs = (SqlNode)lhs.NextSibling;

            if (lhs is DotNode nextDotNode)
            {
                return(GetPropertyPath(nextDotNode, alias) + "." + rhs.OriginalText);
            }

            var path = rhs.OriginalText;

            if (alias != null && alias.Text == lhs.Text)
            {
                return(path);
            }

            return(lhs.Path + "." + path);
        }
示例#3
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 --"));
            }
        }
示例#4
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 --"));
            }
        }