private static void AddImpliedFromToFromNode(IASTNode fromClause, string collectionRole, ISessionFactoryImplementor factory)
        {
            SessionFactoryHelperExtensions _sessionFactoryHelper = new SessionFactoryHelperExtensions(factory);
            IQueryableCollection           persister             = _sessionFactoryHelper.GetCollectionPersister(collectionRole);
            IType collectionElementType = persister.ElementType;

            if (!collectionElementType.IsEntityType)
            {
                throw new QueryException("collection of values in filter: this");
            }

            string collectionElementEntityName = persister.ElementPersister.EntityName;

            ITreeAdaptor adaptor = new ASTTreeAdaptor();

            IASTNode fromElement = (IASTNode)adaptor.Create(HqlParser.FILTER_ENTITY, collectionElementEntityName);
            IASTNode alias       = (IASTNode)adaptor.Create(HqlParser.ALIAS, "this");

            fromClause.AddChild(fromElement);
            fromClause.AddChild(alias);

            // Show the modified AST.
            if (log.IsDebugEnabled())
            {
                log.Debug("AddImpliedFormToFromNode() : Filter - Added 'this' as a from element...");
            }
        }
		private static void AddImpliedFromToFromNode(IASTNode fromClause, string collectionRole, ISessionFactoryImplementor factory)
		{
			SessionFactoryHelperExtensions _sessionFactoryHelper = new SessionFactoryHelperExtensions(factory);
			IQueryableCollection persister = _sessionFactoryHelper.GetCollectionPersister(collectionRole);
			IType collectionElementType = persister.ElementType;
			if (!collectionElementType.IsEntityType)
			{
				throw new QueryException("collection of values in filter: this");
			}

			string collectionElementEntityName = persister.ElementPersister.EntityName;

			ITreeAdaptor adaptor = new ASTTreeAdaptor();

			IASTNode fromElement = (IASTNode)adaptor.Create(HqlParser.FILTER_ENTITY, collectionElementEntityName);
			IASTNode alias = (IASTNode)adaptor.Create(HqlParser.ALIAS, "this");

			fromClause.AddChild(fromElement);
			fromClause.AddChild(alias);

			// Show the modified AST.
			if (log.IsDebugEnabled)
			{
				log.Debug("AddImpliedFormToFromNode() : Filter - Added 'this' as a from element...");
			}
		}
Example #3
0
        void PrepareFromClauseInputTree(IASTNode fromClauseInput, ITreeNodeStream input)
        {
            if (IsFilter())
            {
                // Handle collection-fiter compilation.
                // IMPORTANT NOTE: This is modifying the INPUT (HQL) tree, not the output tree!
                IQueryableCollection persister = _sessionFactoryHelper.GetCollectionPersister(_collectionFilterRole);
                IType collectionElementType    = persister.ElementType;
                if (!collectionElementType.IsEntityType)
                {
                    throw new QueryException("collection of values in filter: this");
                }

                string collectionElementEntityName = persister.ElementPersister.EntityName;

                IASTNode fromElement = (IASTNode)adaptor.Create(FILTER_ENTITY, collectionElementEntityName);
                IASTNode alias       = (IASTNode)adaptor.Create(ALIAS, "this");

                ((HqlSqlWalkerTreeNodeStream)input).InsertChild(fromClauseInput, fromElement);
                ((HqlSqlWalkerTreeNodeStream)input).InsertChild(fromClauseInput, alias);

//				fromClauseInput.AddChild(fromElement);
//				fromClauseInput.AddChild(alias);

                // Show the modified AST.
                if (log.IsDebugEnabled)
                {
                    log.Debug("prepareFromClauseInputTree() : Filter - Added 'this' as a from element...");
                }

                // Create a parameter specification for the collection filter...
                IType         collectionFilterKeyType      = _sessionFactoryHelper.RequireQueryableCollection(_collectionFilterRole).KeyType;
                ParameterNode collectionFilterKeyParameter = (ParameterNode)adaptor.Create(PARAM, "?");
                CollectionFilterKeyParameterSpecification collectionFilterKeyParameterSpec = new CollectionFilterKeyParameterSpecification(
                    _collectionFilterRole, collectionFilterKeyType, _positionalParameterCount++
                    );
                collectionFilterKeyParameter.HqlParameterSpecification = collectionFilterKeyParameterSpec;
                _parameters.Add(collectionFilterKeyParameterSpec);
            }
        }
Example #4
0
        IASTNode CreateFromFilterElement(IASTNode filterEntity, IASTNode alias)
        {
            var fromElementFound = true;

            var fromElement = _currentFromClause.GetFromElement(alias.Text) ??
                              _currentFromClause.GetFromElementByClassName(filterEntity.Text);

            if (fromElement == null)
            {
                fromElementFound = false;
                fromElement      = _currentFromClause.AddFromElement(filterEntity.Text, alias);
            }

            FromClause           fromClause = fromElement.FromClause;
            IQueryableCollection persister  = _sessionFactoryHelper.GetCollectionPersister(_collectionFilterRole);

            // Get the names of the columns used to link between the collection
            // owner and the collection elements.
            String[] keyColumnNames = persister.KeyColumnNames;
            String   fkTableAlias   = persister.IsOneToMany
                                        ? fromElement.TableAlias
                                        : fromClause.AliasGenerator.CreateName(_collectionFilterRole);

            JoinSequence join = _sessionFactoryHelper.CreateJoinSequence();

            join.SetRoot(persister, fkTableAlias);

            if (!persister.IsOneToMany)
            {
                join.AddJoin((IAssociationType)persister.ElementType,
                             fromElement.TableAlias,
                             JoinType.InnerJoin,
                             persister.GetElementColumnNames(fkTableAlias));
            }

            join.AddCondition(fkTableAlias, keyColumnNames, " = ", true);
            fromElement.JoinSequence = join;
            fromElement.Filter       = true;

            if (log.IsDebugEnabled())
            {
                log.Debug("createFromFilterElement() : processed filter FROM element.");
            }

            if (fromElementFound)
            {
                return((IASTNode)adaptor.Nil());
            }

            return(fromElement);
        }