From: <te...@us...> - 2008-08-17 17:50:12
|
Revision: 3713 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3713&view=rev Author: tehlike Date: 2008-08-17 17:50:20 +0000 (Sun, 17 Aug 2008) Log Message: ----------- Removed order by and limit fragment classes in order to make sure we work incrementally. Added NHibernateExpressionVisitor class which can visit nhibernate specific nodes. Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Linq/Expressions/EntityExpression.cs trunk/nhibernate/src/NHibernate.Linq/Expressions/ProjectionExpression.cs trunk/nhibernate/src/NHibernate.Linq/Expressions/SelectExpression.cs trunk/nhibernate/src/NHibernate.Linq/Expressions/SqlExpressionType.cs trunk/nhibernate/src/NHibernate.Linq/NHibernate.Linq.csproj trunk/nhibernate/src/NHibernate.Linq.Test/ExpressionEqualityChecker.cs trunk/nhibernate/src/NHibernate.Linq.Test/GlobalSetup.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate.Linq/Util/LinqUtil.cs trunk/nhibernate/src/NHibernate.Linq/Visitors/NHibernateExpressionVisitor.cs trunk/nhibernate/src/NHibernate.Linq/Visitors/NhibernateExpressionTransformer.cs trunk/nhibernate/src/NHibernate.Linq/Visitors/QueryTransformer.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate.Linq/Expressions/LimitFragment.cs trunk/nhibernate/src/NHibernate.Linq/Expressions/MemberAccessExpression.cs trunk/nhibernate/src/NHibernate.Linq/Expressions/OrderByDirection.cs trunk/nhibernate/src/NHibernate.Linq/Expressions/OrderByFragment.cs Modified: trunk/nhibernate/src/NHibernate.Linq/Expressions/EntityExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Expressions/EntityExpression.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq/Expressions/EntityExpression.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -9,7 +9,7 @@ { /// <summary> /// An entity is where we want to execute our query on, in RDBMS case it is a Table. - /// May also be used as from clause of a select expression + /// May also be used in from clause of a select expression /// </summary> public class EntityExpression:SqlExpression { Deleted: trunk/nhibernate/src/NHibernate.Linq/Expressions/LimitFragment.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Expressions/LimitFragment.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq/Expressions/LimitFragment.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace NHibernate.Linq.Expressions -{ - public class LimitFragment - { - public int? Skip { get; set; } - public int? Take { get; set; } - } -} Deleted: trunk/nhibernate/src/NHibernate.Linq/Expressions/MemberAccessExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Expressions/MemberAccessExpression.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq/Expressions/MemberAccessExpression.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -namespace NHibernate.Linq.Expressions -{ - /// <summary> - /// A member access expression is produced where a member of an object is accessed(can be field or Property) - /// </summary> - public class MemberAccessExpression:SqlExpression - { - public MemberAccessExpression(System.Type type, SqlExpression expression, string name) - : base(SqlExpressionType.MemberAccess, type) - { - this.Name = name; - this.Expression = expression; - } - - public string Name { get; protected set; } - public SqlExpression Expression { get; protected set; } - public override string ToString() - { - return string.Format("({0}.{1})", this.Expression, ".", this.Name); - } - } -} Deleted: trunk/nhibernate/src/NHibernate.Linq/Expressions/OrderByDirection.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Expressions/OrderByDirection.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq/Expressions/OrderByDirection.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace NHibernate.Linq.Expressions -{ - /// <summary> - /// The direction of the ordering, default is Ascending. - /// </summary> - public enum OrderByDirection - { - Ascending, - Descending - } -} Deleted: trunk/nhibernate/src/NHibernate.Linq/Expressions/OrderByFragment.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Expressions/OrderByFragment.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq/Expressions/OrderByFragment.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -namespace NHibernate.Linq.Expressions -{ - /// <summary> - /// An order by expression is an expression that the result is ordered. - /// This class holds reference to the actual expression(can be a projection, property, or an aggregate) - /// </summary> - public class OrderByFragment - { - public OrderByFragment(Expression orderBy,OrderByDirection direction) - { - this.OrderBy = orderBy; - this.Direction = direction; - } - - public Expression OrderBy { get; protected set; } - public OrderByDirection Direction { get;protected set; } - } -} Modified: trunk/nhibernate/src/NHibernate.Linq/Expressions/ProjectionExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Expressions/ProjectionExpression.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq/Expressions/ProjectionExpression.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -11,12 +11,14 @@ /// </summary> public class ProjectionExpression:SqlExpression { - public ProjectionExpression(System.Type type,LambdaExpression lambda):base(SqlExpressionType.Projection,type) + public ProjectionExpression(SelectExpression source, Expression lambda) + : base(SqlExpressionType.Projection, lambda.Type) { this.Projector = lambda; } - public LambdaExpression Projector { get; protected set; } + public Expression Projector { get; protected set; } + public SelectExpression Source { get; set; } public override string ToString() { return string.Format("({0})", this.Projector.ToString()); Modified: trunk/nhibernate/src/NHibernate.Linq/Expressions/SelectExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Expressions/SelectExpression.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq/Expressions/SelectExpression.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -11,17 +11,16 @@ /// </summary> public class SelectExpression : SqlExpression { - public SelectExpression(System.Type type, SqlExpression from, SqlExpression where, IList<OrderByFragment> orderBys) + public SelectExpression(System.Type type, string alias, Expression from, Expression where) : base(SqlExpressionType.Select, type) { this.Where = where; - this.OrderBys = orderBys; this.From = from; + this.Alias = alias; } - public SqlExpression Where { get; protected set; } - public SqlExpression From { get; protected set; } - public IList<OrderByFragment> OrderBys { get; protected set; } - public LimitFragment Limit { get; set; } + public string Alias { get; set; } + public Expression Where { get; protected set; } + public Expression From { get; protected set; } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Linq/Expressions/SqlExpressionType.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Expressions/SqlExpressionType.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq/Expressions/SqlExpressionType.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -9,7 +9,6 @@ { Entity=100, Select, - MemberAccess, Projection, } } Modified: trunk/nhibernate/src/NHibernate.Linq/NHibernate.Linq.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/NHibernate.Linq.csproj 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq/NHibernate.Linq.csproj 2008-08-17 17:50:20 UTC (rev 3713) @@ -46,10 +46,6 @@ </ProjectReference> </ItemGroup> <ItemGroup> - <Compile Include="Expressions\LimitFragment.cs" /> - <Compile Include="Expressions\MemberAccessExpression.cs" /> - <Compile Include="Expressions\OrderByDirection.cs" /> - <Compile Include="Expressions\OrderByFragment.cs" /> <Compile Include="Expressions\ProjectionExpression.cs" /> <Compile Include="Expressions\SelectExpression.cs" /> <Compile Include="Expressions\SelectFragment.cs" /> @@ -57,6 +53,7 @@ <Compile Include="Expressions\SqlExpressionType.cs" /> <Compile Include="Expressions\EntityExpression.cs" /> <Compile Include="Util\Guard.cs" /> + <Compile Include="Util\LinqUtil.cs" /> <Compile Include="Visitors\LogicalExpressionReducer.cs" /> <Compile Include="ExpressionVisitor.cs" /> <Compile Include="NHibernateExtensions.cs" /> @@ -65,6 +62,9 @@ <Compile Include="QueryProvider.cs" /> <Compile Include="Util\TypeSystem.cs" /> <Compile Include="Visitors\LocalVariableExpressionReducer.cs" /> + <Compile Include="Visitors\NhibernateExpressionTransformer.cs" /> + <Compile Include="Visitors\NHibernateExpressionVisitor.cs" /> + <Compile Include="Visitors\QueryTransformer.cs" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Added: trunk/nhibernate/src/NHibernate.Linq/Util/LinqUtil.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Util/LinqUtil.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Linq/Util/LinqUtil.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; + +namespace NHibernate.Linq.Util +{ + public static class LinqUtil + { + public static Expression StripQuotes(Expression expression) + { + while (expression.NodeType == ExpressionType.Quote) + { + expression=((UnaryExpression)expression).Operand; + } + return expression; + } + } +} Added: trunk/nhibernate/src/NHibernate.Linq/Visitors/NHibernateExpressionVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Visitors/NHibernateExpressionVisitor.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Linq/Visitors/NHibernateExpressionVisitor.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using NHibernate.Linq.Expressions; + +namespace NHibernate.Linq.Visitors +{ + /// <summary> + /// A visitor for nhibernate specific expression + /// </summary> + public class NHibernateExpressionVisitor:ExpressionVisitor + { + public override Expression Visit(Expression exp) + { + if(exp==null) + return null; + switch((SqlExpressionType)exp.NodeType) + { + case SqlExpressionType.Entity: + return this.VisitEntity((EntityExpression)exp); + case SqlExpressionType.Select: + return this.VisitSelect((SelectExpression)exp); + case SqlExpressionType.Projection: + return this.VisitProjection((ProjectionExpression)exp); + default: + return base.Visit(exp); + } + } + + protected virtual Expression VisitProjection(ProjectionExpression projection) + { + SelectExpression source = (SelectExpression)this.Visit(projection.Source); + Expression projector = this.Visit(projection.Projector); + if (source != projection.Source || projector != projection.Projector) + { + return new ProjectionExpression(source, projector); + } + else + return projection; + } + protected virtual Expression VisitSource(Expression source) + { + return this.Visit(source); + } + protected virtual Expression VisitSelect(SelectExpression select) + { + Expression from = this.VisitSource(select.From); + Expression where = this.Visit(select.Where); + + if (from != select.From || where != select.Where) + { + return new SelectExpression(select.Type, select.Alias, from, where); + } + else + return select; + } + protected virtual Expression VisitEntity(EntityExpression expr) + { + return this.Visit(expr); + } + + } +} Added: trunk/nhibernate/src/NHibernate.Linq/Visitors/NhibernateExpressionTransformer.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Visitors/NhibernateExpressionTransformer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Linq/Visitors/NhibernateExpressionTransformer.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NHibernate.Linq.Visitors +{ + public class NhibernateExpressionTransformer:ExpressionVisitor + { + } +} Added: trunk/nhibernate/src/NHibernate.Linq/Visitors/QueryTransformer.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq/Visitors/QueryTransformer.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Linq/Visitors/QueryTransformer.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NHibernate.Linq.Visitors +{ + public class QueryTransformer:ExpressionVisitor + { + } +} Modified: trunk/nhibernate/src/NHibernate.Linq.Test/ExpressionEqualityChecker.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq.Test/ExpressionEqualityChecker.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq.Test/ExpressionEqualityChecker.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -8,35 +8,35 @@ { public static class ExpressionEqualityChecker { - public static bool ExpressionEquals(this Expression source,Expression toBeCompared) + public static bool ExpressionEquals(this Expression source, Expression toBeCompared) { - if(object.Equals(source,toBeCompared)) + if (object.Equals(source, toBeCompared)) return true; else if ((source != null && toBeCompared == null) || (source == null && toBeCompared != null)) { return false; } - else if (source.NodeType == toBeCompared.NodeType && source.Type==toBeCompared.Type) + else if (source.NodeType == toBeCompared.NodeType && source.Type == toBeCompared.Type) { - System.Type sourceType = source.GetType(); - var properties = sourceType.GetProperties(); - bool value = true; + System.Type sourceType = source.GetType(); + var properties = sourceType.GetProperties(); + bool value = true; - for (int i = 0; i < properties.Length;i++ ) + for (int i = 0; i < properties.Length && value; i++) + { + var info = properties[i]; + var leftValue = info.GetValue(source, null); + var rightValue = info.GetValue(toBeCompared, null); + if (leftValue is Expression) { - var info = properties[i]; - var leftValue = info.GetValue(source, null); - var rightValue = info.GetValue(toBeCompared, null); - if (leftValue is Expression) - { - value &= ExpressionEquals((Expression)leftValue, (Expression)rightValue); - } - else - value &= object.Equals(leftValue,rightValue); + value &= ExpressionEquals((Expression)leftValue, (Expression)rightValue); } - return value; + else + value &= object.Equals(leftValue, rightValue); + } + return value; } - else + else return false; } } Modified: trunk/nhibernate/src/NHibernate.Linq.Test/GlobalSetup.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Linq.Test/GlobalSetup.cs 2008-08-16 23:15:16 UTC (rev 3712) +++ trunk/nhibernate/src/NHibernate.Linq.Test/GlobalSetup.cs 2008-08-17 17:50:20 UTC (rev 3713) @@ -2,10 +2,11 @@ using System.Collections.Generic; using System.Data; using NHibernate; +using NHibernate.Linq.Test.Model; using NUnit.Framework; using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; - +using M = NHibernate.Linq.Test.Model; namespace NHibernate.Linq.Test { public static class GlobalSetup @@ -19,14 +20,14 @@ factory = cfg.BuildSessionFactory(); } - public static ISession CreateSession() + public static void GenerateTestData() { - return factory.OpenSession(); + } - public static ISession CreateSession(IDbConnection con) + public static ISession CreateSession() { - return factory.OpenSession(con); + return factory.OpenSession(); } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |