GetFromElement() public method

public GetFromElement ( ) : NHibernate.Hql.Ast.ANTLR.Tree.FromElement
return NHibernate.Hql.Ast.ANTLR.Tree.FromElement
Beispiel #1
0
        public FromElement AddFromElement()
        {
            FromClause parentFromClause = _fromClause.ParentFromClause;

            if (parentFromClause != null)
            {
                // Look up class name using the first identifier in the path.
                string      pathAlias         = PathHelper.GetAlias(_path);
                FromElement parentFromElement = parentFromClause.GetFromElement(pathAlias);
                if (parentFromElement != null)
                {
                    return(CreateFromElementInSubselect(_path, pathAlias, parentFromElement, _classAlias));
                }
            }

            IEntityPersister entityPersister = _fromClause.SessionFactoryHelper.RequireClassPersister(_path);

            FromElement elem = CreateAndAddFromElement(_path,
                                                       _classAlias,
                                                       entityPersister,
                                                       (EntityType)((IQueryable)entityPersister).Type,
                                                       null);

            // Add to the query spaces.
            _fromClause.Walker.AddQuerySpaces(entityPersister.QuerySpaces);

            return(elem);
        }
Beispiel #2
0
        /// <summary>
        /// Retrieves the from-element represented by the given alias.
        /// </summary>
        /// <param name="aliasOrClassName">The alias by which to locate the from-element.</param>
        /// <returns>The from-element assigned the given alias, or null if none.</returns>
        public FromElement GetFromElement(string aliasOrClassName)
        {
            FromElement fromElement;

            _fromElementByClassAlias.TryGetValue(aliasOrClassName, out fromElement);

            if (fromElement == null && SessionFactoryHelper.IsStrictJPAQLComplianceEnabled)
            {
                fromElement = FindIntendedAliasedFromElementBasedOnCrazyJPARequirements(aliasOrClassName);
            }
            if (fromElement == null && _parentFromClause != null)
            {
                fromElement = _parentFromClause.GetFromElement(aliasOrClassName);
            }
            return(fromElement);
        }
Beispiel #3
0
        public FromElement CreateCollection(IQueryableCollection queryableCollection,
                                            string role,
                                            JoinType joinType,
                                            bool fetchFlag,
                                            bool indexed)
        {
            if (!_collection)
            {
                throw new InvalidOperationException("FromElementFactory not initialized for collections!");
            }

            _inElementsFunction = indexed;
            FromElement elem;

            _queryableCollection = queryableCollection;
            _collectionType      = queryableCollection.CollectionType;
            string roleAlias = _fromClause.AliasGenerator.CreateName(role);

            // Correlated subqueries create 'special' implied from nodes
            // because correlated subselects can't use an ANSI-style join
            bool explicitSubqueryFromElement = _fromClause.IsSubQuery && !_implied;

            if (explicitSubqueryFromElement)
            {
                string      pathRoot = StringHelper.Root(_path);
                FromElement origin   = _fromClause.GetFromElement(pathRoot);
                if (origin == null || origin.FromClause != _fromClause)
                {
                    _implied = true;
                }
            }

            // super-duper-classic-parser-regression-testing-mojo-magic...
            if (explicitSubqueryFromElement && DotNode.UseThetaStyleImplicitJoins)
            {
                _implied = true;
            }

            IType elementType = queryableCollection.ElementType;

            if (elementType.IsEntityType)
            {
                // A collection of entities...
                elem = CreateEntityAssociation(role, roleAlias, joinType);
            }
            else if (elementType.IsComponentType)
            {
                // A collection of components...
                JoinSequence joinSequence = CreateJoinSequence(roleAlias, joinType);
                elem = CreateCollectionJoin(joinSequence, roleAlias);
            }
            else
            {
                // A collection of scalar elements...
                JoinSequence joinSequence = CreateJoinSequence(roleAlias, joinType);
                elem = CreateCollectionJoin(joinSequence, roleAlias);
            }

            elem.SetRole(role);
            elem.QueryableCollection = queryableCollection;
            // Don't include sub-classes for implied collection joins or subquery joins.
            if (_implied)
            {
                elem.IncludeSubclasses = false;
            }

            if (explicitSubqueryFromElement)
            {
                elem.InProjectionList = true;                   // Treat explict from elements in sub-queries properly.
            }

            if (fetchFlag)
            {
                elem.Fetch = true;
            }
            return(elem);
        }