|
From: <ste...@us...> - 2009-10-23 12:21:37
|
Revision: 4798
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4798&view=rev
Author: steverstrong
Date: 2009-10-23 12:21:21 +0000 (Fri, 23 Oct 2009)
Log Message:
-----------
Restructured the Linq folder, it was getting messy
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Linq/NhNewExpression.cs
trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Linq/NhLinqExpression.cs
trunk/nhibernate/src/NHibernate/Linq/NhLinqExpressionReturnType.cs
trunk/nhibernate/src/NHibernate/Linq/NhQueryProvider.cs
trunk/nhibernate/src/NHibernate/Linq/ReWriters/
trunk/nhibernate/src/NHibernate/Linq/ReWriters/AggregatingGroupByRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/ReWriters/AggregatingGroupJoinRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/ReWriters/GroupBySelectClauseRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/ReWriters/MergeAggregatingResultsRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/ReWriters/NonAggregatingGroupByRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/ResultOperators/
trunk/nhibernate/src/NHibernate/Linq/ResultOperators/ClientSideTransformOperator.cs
trunk/nhibernate/src/NHibernate/Linq/ResultOperators/NonAggregatingGroupBy.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/
trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionKeyVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/ExpressionParameterVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/GroupByAggregateDetectionVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/GroupByKeySelectorVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/HqlGeneratorExpressionTreeVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/NhExpressionTreeVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/NhThrowingExpressionTreeVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/Nominator.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/ProjectionEvaluator.cs
trunk/nhibernate/src/NHibernate/Linq/Visitors/QueryModelVisitor.cs
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupByRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupJoinRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/ClientSideTransformOperator.cs
trunk/nhibernate/src/NHibernate/Linq/ExpressionKeyVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/GroupByAggregateDetectionVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/GroupByKeySelectorVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/HqlGeneratorExpressionTreeVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/MergeAggregatingResultsRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/NhExpressionTreeVisitor.cs
trunk/nhibernate/src/NHibernate/Linq/Nominator.cs
trunk/nhibernate/src/NHibernate/Linq/NonAggregatingGroupBy.cs
trunk/nhibernate/src/NHibernate/Linq/NonAggregatingGroupByRewriter.cs
trunk/nhibernate/src/NHibernate/Linq/ProjectionEvaluator.cs
trunk/nhibernate/src/NHibernate/Linq/QueryModelVisitor.cs
Deleted: trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupByRewriter.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupByRewriter.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupByRewriter.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,68 +0,0 @@
-using System;
-using System.Linq;
-using Remotion.Data.Linq;
-using Remotion.Data.Linq.Clauses;
-using Remotion.Data.Linq.Clauses.Expressions;
-using Remotion.Data.Linq.Clauses.ResultOperators;
-
-namespace NHibernate.Linq
-{
- public class AggregatingGroupByRewriter
- {
- public void ReWrite(QueryModel queryModel)
- {
- var subQueryExpression = queryModel.MainFromClause.FromExpression as SubQueryExpression;
-
- if ((subQueryExpression != null) &&
- (subQueryExpression.QueryModel.ResultOperators.Count() == 1) &&
- (subQueryExpression.QueryModel.ResultOperators[0] is GroupResultOperator) &&
- (IsAggregatingGroupBy(queryModel)))
- {
- FlattenSubQuery(subQueryExpression, queryModel.MainFromClause, queryModel);
- }
- }
-
- private static bool IsAggregatingGroupBy(QueryModel queryModel)
- {
- return new GroupByAggregateDetectionVisitor().Visit(queryModel.SelectClause.Selector);
- }
-
- private void FlattenSubQuery(SubQueryExpression subQueryExpression, FromClauseBase fromClause,
- QueryModel queryModel)
- {
- // Move the result operator up
- if (queryModel.ResultOperators.Count != 0)
- {
- throw new NotImplementedException();
- }
-
- var groupBy = (GroupResultOperator) subQueryExpression.QueryModel.ResultOperators[0];
-
- // Replace the outer select clause...
- queryModel.SelectClause.TransformExpressions(s => GroupBySelectClauseRewriter.ReWrite(s, groupBy, subQueryExpression.QueryModel));
-
- queryModel.SelectClause.TransformExpressions(
- s =>
- new SwapQuerySourceVisitor(queryModel.MainFromClause, subQueryExpression.QueryModel.MainFromClause).Swap
- (s));
-
-
- MainFromClause innerMainFromClause = subQueryExpression.QueryModel.MainFromClause;
- CopyFromClauseData(innerMainFromClause, fromClause);
-
- foreach (var bodyClause in subQueryExpression.QueryModel.BodyClauses)
- {
- queryModel.BodyClauses.Add(bodyClause);
- }
-
- queryModel.ResultOperators.Add(groupBy);
- }
-
- protected void CopyFromClauseData(FromClauseBase source, FromClauseBase destination)
- {
- destination.FromExpression = source.FromExpression;
- destination.ItemName = source.ItemName;
- destination.ItemType = source.ItemType;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupJoinRewriter.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupJoinRewriter.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupJoinRewriter.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,321 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-using Remotion.Data.Linq;
-using Remotion.Data.Linq.Clauses;
-using Remotion.Data.Linq.Clauses.Expressions;
-
-namespace NHibernate.Linq
-{
- public class AggregatingGroupJoinRewriter
- {
- public void ReWrite(QueryModel model)
- {
- // We want to take queries like this:
-
- //var q =
- // from c in db.Customers
- // join o in db.Orders on c.CustomerId equals o.Customer.CustomerId into ords
- // join e in db.Employees on c.Address.City equals e.Address.City into emps
- // select new { c.ContactName, ords = ords.Count(), emps = emps.Count() };
-
- // and turn them into this:
-
- //var q =
- // from c in db.Customers
- // select new
- // {
- // c.ContactName,
- // ords = (from o2 in db.Orders where o2.Customer.CustomerId == c.CustomerId select o2).Count(),
- // emps = (from e2 in db.Employees where e2.Address.City == c.Address.City select e2).Count()
- // };
-
- // so spot a group join where every use of the grouping in the selector is an aggregate
-
- // firstly, get the group join clauses
- var groupJoin = model.BodyClauses.Where(bc => bc is GroupJoinClause).Cast<GroupJoinClause>();
-
- if (groupJoin.Count() == 0)
- {
- // No group join here..
- return;
- }
-
- // Now walk the tree to decide which groupings are fully aggregated (and can hence be done in hql)
- var aggregateDetectorResults = IsAggregatingGroupJoin(model, groupJoin);
-
- if (aggregateDetectorResults.AggregatingClauses.Count > 0)
- {
- // Re-write the select expression
- model.SelectClause.TransformExpressions(s => GroupJoinSelectClauseRewriter.ReWrite(s, aggregateDetectorResults));
-
- // Remove the aggregating group joins
- foreach (GroupJoinClause aggregatingGroupJoin in aggregateDetectorResults.AggregatingClauses)
- {
- model.BodyClauses.Remove(aggregatingGroupJoin);
- }
- }
- }
-
- private static IsAggregatingResults IsAggregatingGroupJoin(QueryModel model, IEnumerable<GroupJoinClause> clause)
- {
- return new GroupJoinAggregateDetectionVisitor(clause).Visit(model.SelectClause.Selector);
- }
- }
-
- public class GroupJoinSelectClauseRewriter : NhExpressionTreeVisitor
- {
- private readonly IsAggregatingResults _results;
-
- public static Expression ReWrite(Expression expression, IsAggregatingResults results)
- {
- return new GroupJoinSelectClauseRewriter(results).VisitExpression(expression);
- }
-
- private GroupJoinSelectClauseRewriter(IsAggregatingResults results)
- {
- _results = results;
- }
-
- protected override Expression VisitSubQueryExpression(SubQueryExpression expression)
- {
- // If the sub queries main (and only) from clause is one of our aggregating group bys, then swap it
- GroupJoinClause groupJoin = LocateGroupJoinQuerySource(expression.QueryModel);
-
- if (groupJoin != null)
- {
- Expression innerSelector = new SwapQuerySourceVisitor(groupJoin.JoinClause, expression.QueryModel.MainFromClause).
- Swap(groupJoin.JoinClause.InnerKeySelector);
-
- expression.QueryModel.MainFromClause.FromExpression = groupJoin.JoinClause.InnerSequence;
-
-
- // TODO - this only works if the key selectors are not composite. Needs improvement...
- expression.QueryModel.BodyClauses.Add(new WhereClause(Expression.Equal(innerSelector, groupJoin.JoinClause.OuterKeySelector)));
- }
-
- return expression;
- }
-
- private GroupJoinClause LocateGroupJoinQuerySource(QueryModel model)
- {
- if (model.BodyClauses.Count > 0)
- {
- return null;
- }
- return new LocateGroupJoinQuerySource(_results).Detect(model.MainFromClause.FromExpression);
- }
- }
-
- public class SwapQuerySourceVisitor : NhExpressionTreeVisitor
- {
- private readonly IQuerySource _oldClause;
- private readonly IQuerySource _newClause;
-
- public SwapQuerySourceVisitor(IQuerySource oldClause, IQuerySource newClause)
- {
- _oldClause = oldClause;
- _newClause = newClause;
- }
-
- public Expression Swap(Expression expression)
- {
- return VisitExpression(expression);
- }
-
- protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression)
- {
- if (expression.ReferencedQuerySource == _oldClause)
- {
- return new QuerySourceReferenceExpression(_newClause);
- }
-
- // TODO - really don't like this drill down approach. Feels fragile
- var mainFromClause = expression.ReferencedQuerySource as MainFromClause;
-
- if (mainFromClause != null)
- {
- mainFromClause.FromExpression = VisitExpression(mainFromClause.FromExpression);
- }
-
- return expression;
- }
-
- protected override Expression VisitSubQueryExpression(SubQueryExpression expression)
- {
- expression.QueryModel.TransformExpressions(VisitExpression);
- return base.VisitSubQueryExpression(expression);
- }
- }
-
- public class LocateGroupJoinQuerySource : NhExpressionTreeVisitor
- {
- private readonly IsAggregatingResults _results;
- private GroupJoinClause _groupJoin;
-
- public LocateGroupJoinQuerySource(IsAggregatingResults results)
- {
- _results = results;
- }
-
- public GroupJoinClause Detect(Expression expression)
- {
- VisitExpression(expression);
- return _groupJoin;
- }
-
- protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression)
- {
- if (_results.AggregatingClauses.Contains(expression.ReferencedQuerySource as GroupJoinClause))
- {
- _groupJoin = expression.ReferencedQuerySource as GroupJoinClause;
- }
-
- return base.VisitQuerySourceReferenceExpression(expression);
- }
- }
-
- public class IsAggregatingResults
- {
- public List<GroupJoinClause> NonAggregatingClauses { get; set; }
- public List<GroupJoinClause> AggregatingClauses { get; set; }
- public List<Expression> NonAggregatingExpressions { get; set; }
- }
-
- internal class GroupJoinAggregateDetectionVisitor : NhExpressionTreeVisitor
- {
- private readonly HashSet<GroupJoinClause> _groupJoinClauses;
- private readonly StackFlag _inAggregate = new StackFlag();
- private readonly StackFlag _parentExpressionProcessed = new StackFlag();
-
- private readonly List<Expression> _nonAggregatingExpressions = new List<Expression>();
- private readonly List<GroupJoinClause> _nonAggregatingGroupJoins = new List<GroupJoinClause>();
- private readonly List<GroupJoinClause> _aggregatingGroupJoins = new List<GroupJoinClause>();
-
- public GroupJoinAggregateDetectionVisitor(IEnumerable<GroupJoinClause> groupJoinClause)
- {
- _groupJoinClauses = new HashSet<GroupJoinClause>(groupJoinClause);
- }
-
- public IsAggregatingResults Visit(Expression expression)
- {
- VisitExpression(expression);
-
- return new IsAggregatingResults { NonAggregatingClauses = _nonAggregatingGroupJoins, AggregatingClauses = _aggregatingGroupJoins, NonAggregatingExpressions = _nonAggregatingExpressions };
- }
-
- protected override Expression VisitSubQueryExpression(SubQueryExpression expression)
- {
- VisitExpression(expression.QueryModel.SelectClause.Selector);
- return expression;
- }
-
- protected override Expression VisitNhAverage(NhAverageExpression expression)
- {
- using (_inAggregate.SetFlag())
- {
- return base.VisitNhAverage(expression);
- }
- }
-
- protected override Expression VisitNhCount(NhCountExpression expression)
- {
- using (_inAggregate.SetFlag())
- {
- return base.VisitNhCount(expression);
- }
- }
-
- protected override Expression VisitNhMax(NhMaxExpression expression)
- {
- using (_inAggregate.SetFlag())
- {
- return base.VisitNhMax(expression);
- }
- }
-
- protected override Expression VisitNhMin(NhMinExpression expression)
- {
- using (_inAggregate.SetFlag())
- {
- return base.VisitNhMin(expression);
- }
- }
-
- protected override Expression VisitNhSum(NhSumExpression expression)
- {
- using (_inAggregate.SetFlag())
- {
- return base.VisitNhSum(expression);
- }
- }
-
- protected override Expression VisitMemberExpression(MemberExpression expression)
- {
- if (_inAggregate.FlagIsFalse && _parentExpressionProcessed.FlagIsFalse)
- {
- _nonAggregatingExpressions.Add(expression);
- }
-
- using (_parentExpressionProcessed.SetFlag())
- {
- return base.VisitMemberExpression(expression);
- }
- }
-
- protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression)
- {
- var fromClause = (FromClauseBase) expression.ReferencedQuerySource;
-
- if (fromClause.FromExpression is QuerySourceReferenceExpression)
- {
- var querySourceReference = (QuerySourceReferenceExpression) fromClause.FromExpression;
-
- if (_groupJoinClauses.Contains(querySourceReference.ReferencedQuerySource as GroupJoinClause))
- {
- if (_inAggregate.FlagIsFalse)
- {
- _nonAggregatingGroupJoins.Add((GroupJoinClause) querySourceReference.ReferencedQuerySource);
- }
- else
- {
- _aggregatingGroupJoins.Add((GroupJoinClause) querySourceReference.ReferencedQuerySource);
- }
- }
- }
-
- return base.VisitQuerySourceReferenceExpression(expression);
- }
-
- internal class StackFlag
- {
- public bool FlagIsTrue { get; private set; }
-
- public bool FlagIsFalse { get { return !FlagIsTrue; } }
-
- public IDisposable SetFlag()
- {
- return new StackFlagDisposable(this);
- }
-
- internal class StackFlagDisposable : IDisposable
- {
- private readonly StackFlag _parent;
- private readonly bool _old;
-
- public StackFlagDisposable(StackFlag parent)
- {
- _parent = parent;
- _old = parent.FlagIsTrue;
- parent.FlagIsTrue = true;
- }
-
- public void Dispose()
- {
- _parent.FlagIsTrue = _old;
- }
- }
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/ClientSideTransformOperator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/ClientSideTransformOperator.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/ClientSideTransformOperator.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,24 +0,0 @@
-using System;
-using Remotion.Data.Linq.Clauses;
-using Remotion.Data.Linq.Clauses.StreamedData;
-
-namespace NHibernate.Linq
-{
- public class ClientSideTransformOperator : ResultOperatorBase
- {
- public override IStreamedData ExecuteInMemory(IStreamedData input)
- {
- throw new NotImplementedException();
- }
-
- public override IStreamedDataInfo GetOutputDataInfo(IStreamedDataInfo inputInfo)
- {
- throw new NotImplementedException();
- }
-
- public override ResultOperatorBase Clone(CloneContext cloneContext)
- {
- throw new NotImplementedException();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/ExpressionKeyVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/ExpressionKeyVisitor.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/ExpressionKeyVisitor.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,217 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq.Expressions;
-using System.Text;
-using Remotion.Data.Linq.Parsing;
-
-namespace NHibernate.Linq
-{
- public class ExpressionKeyVisitor : ExpressionTreeVisitor
- {
- private readonly IDictionary<ConstantExpression, NamedParameter> _parameters;
- readonly StringBuilder _string = new StringBuilder();
-
- private ExpressionKeyVisitor(IDictionary<ConstantExpression, NamedParameter> parameters)
- {
- _parameters = parameters;
- }
-
- public static string Visit(Expression expression, IDictionary<ConstantExpression, NamedParameter> parameters)
- {
- var visitor = new ExpressionKeyVisitor(parameters);
-
- visitor.VisitExpression(expression);
-
- return visitor.ToString();
- }
-
- public override string ToString()
- {
- return _string.ToString();
- }
-
- protected override Expression VisitBinaryExpression(BinaryExpression expression)
- {
- if (expression.Method != null)
- {
- _string.Append(expression.Method.DeclaringType.Name);
- _string.Append(".");
- _string.Append(expression.Method.Name);
- }
- else
- {
- _string.Append(expression.NodeType);
- }
-
- _string.Append("(");
-
- VisitExpression(expression.Left);
- _string.Append(", ");
- VisitExpression(expression.Right);
-
- _string.Append(")");
-
- return expression;
- }
-
- protected override Expression VisitConditionalExpression(ConditionalExpression expression)
- {
- VisitExpression(expression.Test);
- _string.Append(" ? ");
- VisitExpression(expression.IfTrue);
- _string.Append(" : ");
- VisitExpression(expression.IfFalse);
-
- return expression;
- }
-
- protected override Expression VisitConstantExpression(ConstantExpression expression)
- {
- NamedParameter param;
-
- if (_parameters.TryGetValue(expression, out param))
- {
- _string.Append(param.Name);
- }
- else
- {
- _string.Append(expression.Value);
- }
-
- return base.VisitConstantExpression(expression);
- }
-
- protected override ElementInit VisitElementInit(ElementInit elementInit)
- {
- return base.VisitElementInit(elementInit);
- }
-
- protected override ReadOnlyCollection<T> VisitExpressionList<T>(ReadOnlyCollection<T> expressions)
- {
- if (expressions.Count > 0)
- {
- VisitExpression(expressions[0]);
-
- for (var i = 1; i < expressions.Count; i++)
- {
- _string.Append(", ");
- VisitExpression(expressions[i]);
- }
- }
-
- return expressions;
- }
-
- protected override Expression VisitInvocationExpression(InvocationExpression expression)
- {
- return base.VisitInvocationExpression(expression);
- }
-
- protected override Expression VisitLambdaExpression(LambdaExpression expression)
- {
- _string.Append('(');
- VisitExpressionList(expression.Parameters);
- _string.Append(") => (");
- VisitExpression(expression.Body);
- _string.Append(')');
-
- return expression;
- }
-
- protected override Expression VisitListInitExpression(ListInitExpression expression)
- {
- return base.VisitListInitExpression(expression);
- }
-
- protected override MemberBinding VisitMemberAssignment(MemberAssignment memberAssigment)
- {
- return base.VisitMemberAssignment(memberAssigment);
- }
-
- protected override MemberBinding VisitMemberBinding(MemberBinding memberBinding)
- {
- return base.VisitMemberBinding(memberBinding);
- }
-
- protected override Expression VisitMemberExpression(MemberExpression expression)
- {
- base.VisitMemberExpression(expression);
-
- _string.Append('.');
- _string.Append(expression.Member.Name);
-
- return expression;
- }
-
- protected override Expression VisitMemberInitExpression(MemberInitExpression expression)
- {
- return base.VisitMemberInitExpression(expression);
- }
-
- protected override MemberBinding VisitMemberListBinding(MemberListBinding listBinding)
- {
- return base.VisitMemberListBinding(listBinding);
- }
-
- protected override MemberBinding VisitMemberMemberBinding(MemberMemberBinding binding)
- {
- return base.VisitMemberMemberBinding(binding);
- }
-
- protected override Expression VisitMethodCallExpression(MethodCallExpression expression)
- {
- VisitExpression(expression.Object);
- _string.Append('.');
- _string.Append(expression.Method.Name);
- _string.Append('(');
- VisitExpressionList(expression.Arguments);
- _string.Append(')');
-
- return expression;
- }
-
- protected override Expression VisitNewArrayExpression(NewArrayExpression expression)
- {
- return base.VisitNewArrayExpression(expression);
- }
-
- protected override Expression VisitNewExpression(NewExpression expression)
- {
- _string.Append("new ");
- _string.Append(expression.Constructor.DeclaringType.Name);
- _string.Append('(');
- VisitExpressionList(expression.Arguments);
- _string.Append(')');
-
- return expression;
- }
-
- protected override Expression VisitParameterExpression(ParameterExpression expression)
- {
- _string.Append(expression.Name);
-
- return expression;
- }
-
- protected override Expression VisitTypeBinaryExpression(TypeBinaryExpression expression)
- {
- return base.VisitTypeBinaryExpression(expression);
- }
-
- protected override Expression VisitUnaryExpression(UnaryExpression expression)
- {
- _string.Append(expression.NodeType);
- _string.Append('(');
- VisitExpression(expression.Operand);
- _string.Append(')');
-
- return expression;
- }
-
- protected override Expression VisitUnknownExpression(Expression expression)
- {
- return base.VisitUnknownExpression(expression);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/GroupByAggregateDetectionVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/GroupByAggregateDetectionVisitor.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/GroupByAggregateDetectionVisitor.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,83 +0,0 @@
-using System.Linq;
-using System.Linq.Expressions;
-using Remotion.Data.Linq.Clauses.Expressions;
-using Remotion.Data.Linq.Clauses.ResultOperators;
-using Remotion.Data.Linq.Parsing;
-
-namespace NHibernate.Linq
-{
- // TODO: This needs strengthening. Possibly a lot in common with the GroupJoinAggregateDetectionVisitor class, which does many more checks
- internal class GroupByAggregateDetectionVisitor : NhExpressionTreeVisitor
- {
- public bool ContainsAggregateMethods { get; private set; }
-
- public bool Visit(Expression expression)
- {
- ContainsAggregateMethods = false;
-
- VisitExpression(expression);
-
- return ContainsAggregateMethods;
- }
-
- // TODO - this should not exist, since it should be handled either by re-linq or by the MergeAggregatingResultsRewriter
- protected override Expression VisitMethodCallExpression(MethodCallExpression m)
- {
- if (m.Method.DeclaringType == typeof (Queryable) ||
- m.Method.DeclaringType == typeof (Enumerable))
- {
- switch (m.Method.Name)
- {
- case "Count":
- case "Min":
- case "Max":
- case "Sum":
- case "Average":
- ContainsAggregateMethods = true;
- break;
- }
- }
-
- return m;
- }
-
- // TODO - having a VisitNhAggregation method or something in the base class would remove this duplication...
- protected override Expression VisitNhAverage(NhAverageExpression expression)
- {
- ContainsAggregateMethods = true;
- return expression;
- }
-
- protected override Expression VisitNhCount(NhCountExpression expression)
- {
- ContainsAggregateMethods = true;
- return expression;
- }
-
- protected override Expression VisitNhMax(NhMaxExpression expression)
- {
- ContainsAggregateMethods = true;
- return expression;
- }
-
- protected override Expression VisitNhMin(NhMinExpression expression)
- {
- ContainsAggregateMethods = true;
- return expression;
- }
-
- protected override Expression VisitNhSum(NhSumExpression expression)
- {
- ContainsAggregateMethods = true;
- return expression;
- }
-
- protected override Expression VisitSubQueryExpression(SubQueryExpression expression)
- {
- ContainsAggregateMethods =
- new GroupByAggregateDetectionVisitor().Visit(expression.QueryModel.SelectClause.Selector);
-
- return expression;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/GroupByKeySelectorVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/GroupByKeySelectorVisitor.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/GroupByKeySelectorVisitor.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,26 +0,0 @@
-using System.Linq.Expressions;
-using Remotion.Data.Linq.Clauses.Expressions;
-using Remotion.Data.Linq.Parsing;
-
-namespace NHibernate.Linq
-{
- internal class GroupByKeySelectorVisitor : ExpressionTreeVisitor
- {
- private readonly ParameterExpression _parameter;
-
- public GroupByKeySelectorVisitor(ParameterExpression parameter)
- {
- _parameter = parameter;
- }
-
- public Expression Visit(Expression expression)
- {
- return VisitExpression(expression);
- }
-
- protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression)
- {
- return _parameter;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseRewriter.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseRewriter.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseRewriter.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,202 +0,0 @@
-using System;
-using System.Linq.Expressions;
-using Remotion.Data.Linq;
-using Remotion.Data.Linq.Clauses;
-using Remotion.Data.Linq.Clauses.Expressions;
-using Remotion.Data.Linq.Clauses.ResultOperators;
-
-namespace NHibernate.Linq
-{
- internal class GroupBySelectClauseRewriter : NhExpressionTreeVisitor
- {
- public static Expression ReWrite(Expression expression, GroupResultOperator groupBy, QueryModel model)
- {
- var visitor = new GroupBySelectClauseRewriter(groupBy, model);
- return visitor.VisitExpression(expression);
- }
-
- private readonly GroupResultOperator _groupBy;
- private readonly QueryModel _model;
-
- public GroupBySelectClauseRewriter(GroupResultOperator groupBy, QueryModel model)
- {
- _groupBy = groupBy;
- _model = model;
- }
-
- protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression)
- {
- if (expression.ReferencedQuerySource == _groupBy)
- {
- return _groupBy.ElementSelector;
- }
-
- return base.VisitQuerySourceReferenceExpression(expression);
- }
-
- protected override Expression VisitMemberExpression(MemberExpression expression)
- {
- if (IsMemberOfModel(expression))
- {
- if (expression.Member.Name == "Key")
- {
- return _groupBy.KeySelector;
- }
- else
- {
- Expression elementSelector = _groupBy.ElementSelector;
-
- if ((elementSelector is MemberExpression) || (elementSelector is QuerySourceReferenceExpression))
- {
- // If ElementSelector is MemberExpression, just return
- return base.VisitMemberExpression(expression);
- }
- else if (elementSelector is NewExpression)
- {
- // If ElementSelector is NewExpression, then search for member of name "get_" + originalMemberExpression.Member.Name
- // TODO - this wouldn't handle nested initialisers. Should do a tree walk to find the correct member
- var nex = elementSelector as NewExpression;
-
- int i = 0;
- foreach (var member in nex.Members)
- {
- if (member.Name == "get_" + expression.Member.Name)
- {
- return nex.Arguments[i];
- }
- i++;
- }
-
- throw new NotImplementedException();
- }
- else
- {
- throw new NotImplementedException();
- }
- }
- }
- else
- {
- return base.VisitMemberExpression(expression);
- }
- }
-
- // TODO - dislike this code intensly. Should probably be a tree-walk in its own right
- private bool IsMemberOfModel(MemberExpression expression)
- {
- var querySourceRef = expression.Expression as QuerySourceReferenceExpression;
-
- if (querySourceRef == null)
- {
- return false;
- }
-
- var fromClause = querySourceRef.ReferencedQuerySource as FromClauseBase;
-
- if (fromClause == null)
- {
- return false;
- }
-
- var subQuery = fromClause.FromExpression as SubQueryExpression;
-
- if (subQuery != null)
- {
- return subQuery.QueryModel == _model;
- }
-
- var referencedQuery = fromClause.FromExpression as QuerySourceReferenceExpression;
-
- if (referencedQuery == null)
- {
- return false;
- }
-
- var querySource = referencedQuery.ReferencedQuerySource as FromClauseBase;
-
- var subQuery2 = querySource.FromExpression as SubQueryExpression;
-
- return (subQuery2.QueryModel == _model);
- }
-
- protected override Expression VisitSubQueryExpression(SubQueryExpression expression)
- {
- // TODO - is this safe? All we are extracting is the select clause from the sub-query. Assumes that everything
- // else in the subquery has been removed. If there were two subqueries, one aggregating & one not, this may not be a
- // valid assumption. Should probably be passed a list of aggregating subqueries that we are flattening so that we can check...
- return GroupBySelectClauseRewriter.ReWrite(expression.QueryModel.SelectClause.Selector, _groupBy, _model);
- }
- }
-
- public enum NhExpressionType
- {
- Average = 10000,
- Min,
- Max,
- Sum,
- Count,
- Distinct,
- New
- }
-
- public class NhAggregatedExpression : Expression
- {
- public Expression Expression { get; set; }
-
- public NhAggregatedExpression(Expression expression, NhExpressionType type)
- : base((ExpressionType)type, expression.Type)
- {
- Expression = expression;
- }
- }
-
- public class NhAverageExpression : NhAggregatedExpression
- {
- public NhAverageExpression(Expression expression) : base(expression, NhExpressionType.Average)
- {
- }
- }
-
- public class NhMinExpression : NhAggregatedExpression
- {
- public NhMinExpression(Expression expression)
- : base(expression, NhExpressionType.Min)
- {
- }
- }
-
- public class NhMaxExpression : NhAggregatedExpression
- {
- public NhMaxExpression(Expression expression)
- : base(expression, NhExpressionType.Max)
- {
- }
- }
-
- public class NhSumExpression : NhAggregatedExpression
- {
- public NhSumExpression(Expression expression)
- : base(expression, NhExpressionType.Sum)
- {
- }
- }
-
- public class NhDistinctExpression : NhAggregatedExpression
- {
- public NhDistinctExpression(Expression expression)
- : base(expression, NhExpressionType.Distinct)
- {
- }
- }
-
- public class NhCountExpression : Expression
- {
- public NhCountExpression(Expression expression)
- : base((ExpressionType)NhExpressionType.Count, typeof(int))
- {
- Expression = expression;
- }
-
- public Expression Expression { get; private set; }
- }
-}
Deleted: trunk/nhibernate/src/NHibernate/Linq/HqlGeneratorExpressionTreeVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/HqlGeneratorExpressionTreeVisitor.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/HqlGeneratorExpressionTreeVisitor.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,361 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-using NHibernate.Engine.Query;
-using NHibernate.Hql.Ast;
-using Remotion.Data.Linq.Clauses.Expressions;
-using Remotion.Data.Linq.Clauses.ExpressionTreeVisitors;
-
-namespace NHibernate.Linq
-{
- public class HqlGeneratorExpressionTreeVisitor : NhThrowingExpressionTreeVisitor
- {
- protected readonly HqlTreeBuilder _hqlTreeBuilder;
- protected readonly HqlNodeStack _stack;
- private readonly IDictionary<ConstantExpression, NamedParameter> _parameters;
- private readonly IList<NamedParameterDescriptor> _requiredHqlParameters;
-
- public HqlGeneratorExpressionTreeVisitor(IDictionary<ConstantExpression, NamedParameter> parameters, IList<NamedParameterDescriptor> requiredHqlParameters)
- {
- _parameters = parameters;
- _requiredHqlParameters = requiredHqlParameters;
- _hqlTreeBuilder = new HqlTreeBuilder();
- _stack = new HqlNodeStack(_hqlTreeBuilder);
- }
-
- public IEnumerable<HqlTreeNode> GetHqlTreeNodes()
- {
- return _stack.Finish();
- }
-
- public virtual void Visit(Expression expression)
- {
- VisitExpression(expression);
- }
-
- protected override Expression VisitNhAverage(NhAverageExpression expression)
- {
- var visitor = new HqlGeneratorExpressionTreeVisitor(_parameters, _requiredHqlParameters);
- visitor.Visit(expression.Expression);
-
- _stack.PushLeaf(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Average(visitor.GetHqlTreeNodes().Single()), expression.Type));
-
- return expression;
- }
-
- protected override Expression VisitNhCount(NhCountExpression expression)
- {
- var visitor = new HqlGeneratorExpressionTreeVisitor(_parameters, _requiredHqlParameters);
- visitor.Visit(expression.Expression);
-
- _stack.PushLeaf(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Count(visitor.GetHqlTreeNodes().Single()), expression.Type));
-
- return expression;
- }
-
- protected override Expression VisitNhMin(NhMinExpression expression)
- {
- var visitor = new HqlGeneratorExpressionTreeVisitor(_parameters, _requiredHqlParameters);
- visitor.Visit(expression.Expression);
-
- _stack.PushLeaf(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Min(visitor.GetHqlTreeNodes().Single()), expression.Type));
-
- return expression;
- }
-
- protected override Expression VisitNhMax(NhMaxExpression expression)
- {
- var visitor = new HqlGeneratorExpressionTreeVisitor(_parameters, _requiredHqlParameters);
- visitor.Visit(expression.Expression);
-
- _stack.PushLeaf(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Max(visitor.GetHqlTreeNodes().Single()), expression.Type));
-
- return expression;
- }
-
- protected override Expression VisitNhSum(NhSumExpression expression)
- {
- var visitor = new HqlGeneratorExpressionTreeVisitor(_parameters, _requiredHqlParameters);
- visitor.Visit(expression.Expression);
-
- _stack.PushLeaf(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Sum(visitor.GetHqlTreeNodes().Single()), expression.Type));
-
- return expression;
- }
-
- protected override Expression VisitNhDistinct(NhDistinctExpression expression)
- {
- var visitor = new HqlGeneratorExpressionTreeVisitor(_parameters, _requiredHqlParameters);
- visitor.Visit(expression.Expression);
-
- _stack.PushLeaf(_hqlTreeBuilder.Distinct());
-
- foreach (var node in visitor.GetHqlTreeNodes())
- {
- _stack.PushLeaf(node);
- }
-
- return expression;
- }
-
- protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression)
- {
- _stack.PushLeaf(_hqlTreeBuilder.Ident(expression.ReferencedQuerySource.ItemName));
-
- return expression;
- }
-
- protected override Expression VisitBinaryExpression(BinaryExpression expression)
- {
- HqlTreeNode operatorNode = GetHqlOperatorNodeForBinaryOperator(expression);
-
- using (_stack.PushNode(operatorNode))
- {
- VisitExpression(expression.Left);
-
- VisitExpression(expression.Right);
- }
-
- return expression;
- }
-
- private HqlTreeNode GetHqlOperatorNodeForBinaryOperator(BinaryExpression expression)
- {
- switch (expression.NodeType)
- {
- case ExpressionType.Equal:
- return _hqlTreeBuilder.Equality();
-
- case ExpressionType.NotEqual:
- return _hqlTreeBuilder.Inequality();
-
- case ExpressionType.And:
- case ExpressionType.AndAlso:
- return _hqlTreeBuilder.BooleanAnd();
-
- case ExpressionType.Or:
- case ExpressionType.OrElse:
- return _hqlTreeBuilder.BooleanOr();
-
- case ExpressionType.Add:
- return _hqlTreeBuilder.Add();
-
- case ExpressionType.Subtract:
- return _hqlTreeBuilder.Subtract();
-
- case ExpressionType.Multiply:
- return _hqlTreeBuilder.Multiply();
-
- case ExpressionType.Divide:
- return _hqlTreeBuilder.Divide();
-
- case ExpressionType.LessThan:
- return _hqlTreeBuilder.LessThan();
-
- case ExpressionType.LessThanOrEqual:
- return _hqlTreeBuilder.LessThanOrEqual();
-
- case ExpressionType.GreaterThan:
- return _hqlTreeBuilder.GreaterThan();
-
- case ExpressionType.GreaterThanOrEqual:
- return _hqlTreeBuilder.GreaterThanOrEqual();
- }
-
- throw new InvalidOperationException();
- }
-
- protected override Expression VisitUnaryExpression(UnaryExpression expression)
- {
- HqlTreeNode operatorNode = GetHqlOperatorNodeforUnaryOperator(expression);
-
- using (_stack.PushNode(operatorNode))
- {
- VisitExpression(expression.Operand);
- }
-
- return expression;
- }
-
- private HqlTreeNode GetHqlOperatorNodeforUnaryOperator(UnaryExpression expression)
- {
- switch (expression.NodeType)
- {
- case ExpressionType.Not:
- return _hqlTreeBuilder.Not();
- }
-
- throw new InvalidOperationException();
- }
-
- protected override Expression VisitMemberExpression(MemberExpression expression)
- {
- using (_stack.PushNode(_hqlTreeBuilder.Dot()))
- {
- Expression newExpression = VisitExpression(expression.Expression);
-
- _stack.PushLeaf(_hqlTreeBuilder.Ident(expression.Member.Name));
-
- if (newExpression != expression.Expression)
- {
- return Expression.MakeMemberAccess(newExpression, expression.Member);
- }
- }
-
- return expression;
- }
-
- protected override Expression VisitConstantExpression(ConstantExpression expression)
- {
- if (expression.Value != null)
- {
- System.Type t = expression.Value.GetType();
-
- if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof (NhQueryable<>))
- {
- _stack.PushLeaf(_hqlTreeBuilder.Ident(t.GetGenericArguments()[0].Name));
- return expression;
- }
- }
-
- NamedParameter namedParameter;
-
- if (_parameters.TryGetValue(expression, out namedParameter))
- {
- _stack.PushLeaf(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Parameter(namedParameter.Name), namedParameter.Value.GetType()));
- _requiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, new []{ _requiredHqlParameters.Count + 1}, false));
- }
- else
- {
- _stack.PushLeaf(_hqlTreeBuilder.Constant(expression.Value));
- }
-
- return expression;
- }
-
- protected override Expression VisitMethodCallExpression(MethodCallExpression expression)
- {
- if (expression.Method.DeclaringType == typeof(Enumerable) ||
- expression.Method.DeclaringType == typeof(Queryable))
- {
- switch (expression.Method.Name)
- {
- case "Any":
- // Any has one or two arguments. Arg 1 is the source and arg 2 is the optional predicate
- using (_stack.PushNode(_hqlTreeBuilder.Exists()))
- {
- using (_stack.PushNode(_hqlTreeBuilder.Query()))
- {
- using (_stack.PushNode(_hqlTreeBuilder.SelectFrom()))
- {
- using (_stack.PushNode(_hqlTreeBuilder.From()))
- {
- using (_stack.PushNode(_hqlTreeBuilder.Range()))
- {
- VisitExpression(expression.Arguments[0]);
-
- if (expression.Arguments.Count > 1)
- {
- var expr = (LambdaExpression) expression.Arguments[1];
- _stack.PushLeaf(_hqlTreeBuilder.Alias(expr.Parameters[0].Name));
- }
- }
- }
- }
- if (expression.Arguments.Count > 1)
- {
- using (_stack.PushNode(_hqlTreeBuilder.Where()))
- {
- VisitExpression(expression.Arguments[1]);
- }
- }
- }
- }
- break;
- case "Min":
- using (_stack.PushNode(_hqlTreeBuilder.Min()))
- {
- VisitExpression(expression.Arguments[1]);
- }
- break;
- case "Max":
- using (_stack.PushNode(_hqlTreeBuilder.Max()))
- {
- VisitExpression(expression.Arguments[1]);
- }
- break;
- default:
- throw new NotSupportedException(string.Format("The Enumerable method {0} is not supported", expression.Method.Name));
- }
-
- return expression;
- }
- else
- {
- return base.VisitMethodCallExpression(expression); // throws
- }
- }
-
- protected override Expression VisitLambdaExpression(LambdaExpression expression)
- {
- VisitExpression(expression.Body);
-
- return expression;
- }
-
- protected override Expression VisitParameterExpression(ParameterExpression expression)
- {
- _stack.PushLeaf(_hqlTreeBuilder.Ident(expression.Name));
-
- return expression;
- }
-
- protected override Expression VisitConditionalExpression(ConditionalExpression expression)
- {
- using (_stack.PushNode(_hqlTreeBuilder.Case()))
- {
- using (_stack.PushNode(_hqlTreeBuilder.When()))
- {
- VisitExpression(expression.Test);
-
- VisitExpression(expression.IfTrue);
- }
-
- if (expression.IfFalse != null)
- {
- using (_stack.PushNode(_hqlTreeBuilder.Else()))
- {
- VisitExpression(expression.IfFalse);
- }
- }
- }
-
- return expression;
- }
-
- protected override Expression VisitSubQueryExpression(SubQueryExpression expression)
- {
- CommandData query = QueryModelVisitor.GenerateHqlQuery(expression.QueryModel, _parameters, _requiredHqlParameters);
-
- _stack.PushLeaf(query.Statement);
-
- return expression;
- }
-
-
- // Called when a LINQ expression type is not handled above.
- protected override Exception CreateUnhandledItemException<T>(T unhandledItem, string visitMethod)
- {
- string itemText = FormatUnhandledItem(unhandledItem);
- var message = string.Format("The expression '{0}' (type: {1}) is not supported by this LINQ provider.", itemText, typeof(T));
- return new NotSupportedException(message);
- }
-
- private string FormatUnhandledItem<T>(T unhandledItem)
- {
- var itemAsExpression = unhandledItem as Expression;
- return itemAsExpression != null ? FormattingExpressionTreeVisitor.Format(itemAsExpression) : unhandledItem.ToString();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/MergeAggregatingResultsRewriter.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/MergeAggregatingResultsRewriter.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/MergeAggregatingResultsRewriter.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,123 +0,0 @@
-using System;
-using System.Linq;
-using System.Linq.Expressions;
-using Remotion.Data.Linq;
-using Remotion.Data.Linq.Clauses;
-using Remotion.Data.Linq.Clauses.Expressions;
-using Remotion.Data.Linq.Clauses.ResultOperators;
-using Remotion.Data.Linq.Parsing;
-using Remotion.Data.Linq.Parsing.ExpressionTreeVisitors;
-
-namespace NHibernate.Linq
-{
- public class MergeAggregatingResultsRewriter : QueryModelVisitorBase
- {
- public void ReWrite(QueryModel model)
- {
- this.VisitQueryModel(model);
- }
-
- public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index)
- {
- if (resultOperator is SumResultOperator)
- {
- queryModel.SelectClause.Selector = new NhSumExpression(queryModel.SelectClause.Selector);
- queryModel.ResultOperators.Remove(resultOperator);
- }
- else if (resultOperator is AverageResultOperator)
- {
- queryModel.SelectClause.Selector = new NhAverageExpression(queryModel.SelectClause.Selector);
- queryModel.ResultOperators.Remove(resultOperator);
- }
- else if (resultOperator is MinResultOperator)
- {
- queryModel.SelectClause.Selector = new NhMinExpression(queryModel.SelectClause.Selector);
- queryModel.ResultOperators.Remove(resultOperator);
- }
- else if (resultOperator is MaxResultOperator)
- {
- queryModel.SelectClause.Selector = new NhMaxExpression(queryModel.SelectClause.Selector);
- queryModel.ResultOperators.Remove(resultOperator);
- }
- else if (resultOperator is DistinctResultOperator)
- {
- queryModel.SelectClause.Selector = new NhDistinctExpression(queryModel.SelectClause.Selector);
- queryModel.ResultOperators.Remove(resultOperator);
- }
- else if (resultOperator is CountResultOperator)
- {
- queryModel.SelectClause.Selector = new NhCountExpression(queryModel.SelectClause.Selector);
- queryModel.ResultOperators.Remove(resultOperator);
- }
-
- base.VisitResultOperator(resultOperator, queryModel, index);
- }
-
- public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
- {
- selectClause.TransformExpressions(s => new MergeAggregatingResultsInExpressionRewriter().Visit(s));
- }
- }
-
- internal class MergeAggregatingResultsInExpressionRewriter : NhExpressionTreeVisitor
- {
- public Expression Visit(Expression expression)
- {
- return VisitExpression(expression);
- }
-
- protected override Expression VisitSubQueryExpression(SubQueryExpression expression)
- {
- new MergeAggregatingResultsRewriter().ReWrite(expression.QueryModel);
- return expression;
- }
-
- protected override Expression VisitMethodCallExpression(MethodCallExpression m)
- {
- if (m.Method.DeclaringType == typeof(Queryable) ||
- m.Method.DeclaringType == typeof(Enumerable))
- {
- // TODO - dynamic name generation needed here
- switch (m.Method.Name)
- {
- case "Count":
- return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1],
- e => new NhCountExpression(e));
- case "Min":
- return CreateAggregate(m.Arguments[0], (LambdaExpression) m.Arguments[1],
- e => new NhMinExpression(e));
- case "Max":
- return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1],
- e => new NhMaxExpression(e));
- case "Sum":
- return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1],
- e => new NhSumExpression(e));
- case "Average":
- return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1],
- e => new NhAverageExpression(e));
- }
- }
-
- return base.VisitMethodCallExpression(m);
- }
-
- private Expression CreateAggregate(Expression fromClauseExpression, LambdaExpression body, Func<Expression,Expression> factory)
- {
- var fromClause = new MainFromClause("x2", body.Parameters[0].Type, fromClauseExpression);
- var selectClause = body.Body;
- selectClause = ReplacingExpressionTreeVisitor.Replace(body.Parameters[0],
- new QuerySourceReferenceExpression(
- fromClause), selectClause);
- var queryModel = new QueryModel(fromClause,
- new SelectClause(factory(selectClause)));
-
- queryModel.ResultOperators.Add(new AverageResultOperator());
-
- var subQuery = new SubQueryExpression(queryModel);
-
- queryModel.ResultOperators.Clear();
-
- return subQuery;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Linq/NhExpressionTreeVisitor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Linq/NhExpressionTreeVisitor.cs 2009-10-22 20:30:27 UTC (rev 4797)
+++ trunk/nhibernate/src/NHibernate/Linq/NhExpressionTreeVisitor.cs 2009-10-23 12:21:21 UTC (rev 4798)
@@ -1,86 +0,0 @@
-using System;
-using System.Linq.Expressions;
-using Remotion.Data.Linq.Parsing;
-
-namespace NHibernate.Linq
-{
- public class NhExpressionTreeVisitor : ExpressionTreeVisitor
- {
- protected override Expression VisitExpression(Expression expression)
- {
- if (expression == null)
- {
- return null;
- }
-
- switch ((NhExpressionType) expression.NodeType)
- {
- case NhExpressionType.Average:
- return VisitNhAverage((NhAverageExpression) expression);
- case NhExpressionType.Min:
- return VisitNhMin((NhMinExpression)expression);
- case NhExpressionType.Max:
- return VisitNhMax((NhMaxExpression)expression);
- case NhExpressionType.Sum:
- return VisitNhSum((NhSumExpression)expression);
- case NhExpressionType.Count:
- return VisitNhCount((NhCountExpression)expression);
- case NhExpressionType.Distinct:
- return VisitNhDistinct((NhDistinctExpression) expression);
- case NhExpressionType.New:
- return VisitNhNew((NhNewExpression) expression);
- }
-
- return base.VisitExpression(expression);
- }
-
- private Expression VisitNhNew(NhNewExpression expression)
- {
- var arguments = VisitExpressionList(expression.Arguments);
-
- return arguments != expression.Arguments ? new NhNewExpression(expression.Members, arguments) : expression;
- }
-
- protected virtual Expression VisitNhDistinct(NhDistinctExpression expression)
- {
- ...
[truncated message content] |