Exemple #1
0
        public void Process(AllResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            tree.AddWhereClause(tree.TreeBuilder.BooleanNot(
                                    HqlGeneratorExpressionTreeVisitor.Visit(resultOperator.Predicate, queryModelVisitor.VisitorParameters).
                                    ToBooleanExpression()));

            if (tree.IsRoot)
            {
                tree.AddTakeClause(tree.TreeBuilder.Constant(1));

                Expression <Func <IEnumerable <object>, bool> > x = l => !l.Any();
                tree.AddListTransformer(x);
            }
            else
            {
                tree.SetRoot(tree.TreeBuilder.BooleanNot(tree.TreeBuilder.Exists((HqlQuery)tree.Root)));
            }
        }
Exemple #2
0
        public void Process(GroupResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            IEnumerable <Expression> groupByKeys;

            if (resultOperator.KeySelector is NewExpression)
            {
                groupByKeys = (resultOperator.KeySelector as NewExpression).Arguments;
            }
            else
            {
                groupByKeys = new[] { resultOperator.KeySelector }
            };

            IEnumerable <HqlExpression> hqlGroupByKeys = groupByKeys.Select(k => HqlGeneratorExpressionTreeVisitor.Visit(k, queryModelVisitor.VisitorParameters).AsExpression());

            tree.AddGroupByClause(tree.TreeBuilder.GroupBy(hqlGroupByKeys.ToArray()));
        }
    }
        protected override Expression VisitExpression(Expression expression)
        {
            if (expression == null)
            {
                return null;
            }

            if (_hqlNodes.Contains(expression))
            {
                // Pure HQL evaluation
                var hqlVisitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator);
                hqlVisitor.Visit(expression);
                hqlVisitor.GetHqlTreeNodes().ForEach(n =>_stack.PushLeaf(n) );

                return Expression.Convert(Expression.ArrayIndex(_inputParameter, Expression.Constant(_iColumn++)),
                                          expression.Type);
            }

            // Can't handle this node with HQL.  Just recurse down, and emit the expression
            return base.VisitExpression(expression);
        }
Exemple #4
0
        public void Process(AllResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            tree.AddWhereClause(tree.TreeBuilder.BooleanNot(
                                    HqlGeneratorExpressionTreeVisitor.Visit(resultOperator.Predicate, queryModelVisitor.VisitorParameters).
                                    ToBooleanExpression()));

            if (tree.IsRoot)
            {
                tree.AddTakeClause(tree.TreeBuilder.Constant(1));

                Expression <Func <IEnumerable <object>, bool> > x = l => !l.Any();
                tree.AddListTransformer(x);

                // NH-3850: Queries with polymorphism yields many results which must be combined.
                Expression <Func <IEnumerable <bool>, bool> > px = l => l.All(r => r);
                tree.AddPostExecuteTransformer(px);
            }
            else
            {
                tree.SetRoot(tree.TreeBuilder.BooleanNot(tree.TreeBuilder.Exists((HqlQuery)tree.Root)));
            }
        }
Exemple #5
0
        public void Process(ContainsResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            var itemExpression =
                HqlGeneratorExpressionTreeVisitor.Visit(resultOperator.Item, queryModelVisitor.VisitorParameters)
                .AsExpression();

            var from   = GetFromRangeClause(tree.Root);
            var source = from.Children.First();

            if (source is HqlParameter)
            {
                // This is an "in" style statement
                if (IsEmptyList((HqlParameter)source, queryModelVisitor.VisitorParameters))
                {
                    // if the list is empty the expression will always be false, so generate "1 = 0"
                    tree.SetRoot(tree.TreeBuilder.Equality(tree.TreeBuilder.Constant(1), tree.TreeBuilder.Constant(0)));
                }
                else
                {
                    tree.SetRoot(tree.TreeBuilder.In(itemExpression, source));
                }
            }
            else
            {
                // This is an "exists" style statement
                if (itemExpression is HqlParameter)
                {
                    tree.AddWhereClause(tree.TreeBuilder.Equality(
                                            tree.TreeBuilder.Ident(GetFromAlias(tree.Root).AstNode.Text),
                                            itemExpression));
                    tree.SetRoot(tree.TreeBuilder.Exists((HqlQuery)tree.Root));
                }
                else
                {
                    tree.SetRoot(tree.TreeBuilder.In(itemExpression, tree.Root));
                }
            }
        }
        public void Process(ContainsResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            var itemExpression =
                HqlGeneratorExpressionTreeVisitor.Visit(resultOperator.Item, queryModelVisitor.VisitorParameters)
                .AsExpression();

            var from   = GetFromRangeClause(tree.Root);
            var source = from.Children.First();

            if (source is HqlParameter)
            {
                // This is an "in" style statement
                tree.SetRoot(tree.TreeBuilder.In(itemExpression, source));
            }
            else
            {
                // This is an "exists" style statement
                tree.AddWhereClause(tree.TreeBuilder.Equality(
                                        tree.TreeBuilder.Ident(GetFromAlias(tree.Root).AstNode.Text),
                                        itemExpression));
                tree.SetRoot(tree.TreeBuilder.Exists((HqlQuery)tree.Root));
            }
        }
Exemple #7
0
 public void Process(GroupResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
 {
     tree.AddGroupByClause(tree.TreeBuilder.GroupBy(
                               HqlGeneratorExpressionTreeVisitor.Visit(resultOperator.KeySelector, queryModelVisitor.VisitorParameters)
                               .AsExpression()));
 }
		public override void VisitAdditionalFromClause(AdditionalFromClause fromClause, QueryModel queryModel, int index)
		{
			if (fromClause.FromExpression is MemberExpression)
			{
				var member = (MemberExpression) fromClause.FromExpression;

				if (member.Expression is QuerySourceReferenceExpression)
				{
					// It's a join
					var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator);
					visitor.Visit(fromClause.FromExpression);

					HqlJoin joinNode = _hqlTreeBuilder.Join(
						visitor.GetHqlTreeNodes().Single(),
						_hqlTreeBuilder.Alias(fromClause.ItemName));

					_fromClause.AddChild(joinNode);
				}
			}

			base.VisitAdditionalFromClause(fromClause, queryModel, index);
		}
		public override void VisitOrderByClause(OrderByClause orderByClause, QueryModel queryModel, int index)
		{
			_orderByClause = _hqlTreeBuilder.OrderBy();

			foreach (Ordering clause in orderByClause.Orderings)
			{
				var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator);
				visitor.Visit(clause.Expression);

				_orderByClause.AddChild(visitor.GetHqlTreeNodes().Single());
				_orderByClause.AddChild(clause.OrderingDirection == OrderingDirection.Asc
				                        	? _hqlTreeBuilder.Ascending()
				                        	: (HqlTreeNode) _hqlTreeBuilder.Descending());
			}

			base.VisitOrderByClause(orderByClause, queryModel, index);
		}
		public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
		{
			// Visit the predicate to build the query
			var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator);
			visitor.Visit(whereClause.Predicate);

			// There maybe a where clause in existence already, in which case we AND with it.
			if (_whereClause == null)
			{
				_whereClause = _hqlTreeBuilder.Where(visitor.GetHqlTreeNodes().Single());
			}
			else
			{
				HqlAnd mergedPredicates = _hqlTreeBuilder.And(_whereClause.Children.Single(),
				                                              visitor.GetHqlTreeNodes().Single());
				_whereClause = _hqlTreeBuilder.Where(mergedPredicates);
			}
		}
		private void ProcessGroupByOperator(GroupResultOperator resultOperator)
		{
			var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator);
			visitor.Visit(resultOperator.KeySelector);
			_groupByClause = _hqlTreeBuilder.GroupBy();
			_groupByClause.AddChild(visitor.GetHqlTreeNodes().Single());
		}
		public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel)
		{
			var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator);
			visitor.Visit(fromClause.FromExpression);

			_fromClause = _hqlTreeBuilder.From(
				_hqlTreeBuilder.Range(
					visitor.GetHqlTreeNodes().Single(),
					_hqlTreeBuilder.Alias(fromClause.ItemName)));

			base.VisitMainFromClause(fromClause, queryModel);
		}