You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(248) |
May
(82) |
Jun
(90) |
Jul
(177) |
Aug
(253) |
Sep
(157) |
Oct
(151) |
Nov
(143) |
Dec
(278) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(152) |
Feb
(107) |
Mar
(177) |
Apr
(133) |
May
(259) |
Jun
(81) |
Jul
(119) |
Aug
(306) |
Sep
(416) |
Oct
(240) |
Nov
(329) |
Dec
(206) |
2006 |
Jan
(466) |
Feb
(382) |
Mar
(153) |
Apr
(162) |
May
(133) |
Jun
(21) |
Jul
(18) |
Aug
(37) |
Sep
(97) |
Oct
(114) |
Nov
(110) |
Dec
(28) |
2007 |
Jan
(74) |
Feb
(65) |
Mar
(49) |
Apr
(76) |
May
(43) |
Jun
(15) |
Jul
(68) |
Aug
(55) |
Sep
(63) |
Oct
(59) |
Nov
(70) |
Dec
(66) |
2008 |
Jan
(71) |
Feb
(60) |
Mar
(120) |
Apr
(31) |
May
(48) |
Jun
(81) |
Jul
(107) |
Aug
(51) |
Sep
(80) |
Oct
(83) |
Nov
(83) |
Dec
(79) |
2009 |
Jan
(83) |
Feb
(110) |
Mar
(97) |
Apr
(91) |
May
(291) |
Jun
(250) |
Jul
(197) |
Aug
(58) |
Sep
(54) |
Oct
(122) |
Nov
(68) |
Dec
(34) |
2010 |
Jan
(50) |
Feb
(17) |
Mar
(63) |
Apr
(61) |
May
(84) |
Jun
(81) |
Jul
(138) |
Aug
(144) |
Sep
(78) |
Oct
(26) |
Nov
(30) |
Dec
(61) |
2011 |
Jan
(33) |
Feb
(35) |
Mar
(166) |
Apr
(221) |
May
(109) |
Jun
(76) |
Jul
(27) |
Aug
(37) |
Sep
(1) |
Oct
(4) |
Nov
(2) |
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
(1) |
2014 |
Jan
(1) |
Feb
(1) |
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ric...@us...> - 2011-05-22 14:59:04
|
Revision: 5854 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5854&view=rev Author: ricbrown Date: 2011-05-22 14:58:58 +0000 (Sun, 22 May 2011) Log Message: ----------- NH-2683: Updated Sqrt() QueryOver extension to return double Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs 2011-05-22 14:22:22 UTC (rev 5853) +++ trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs 2011-05-22 14:58:58 UTC (rev 5854) @@ -119,70 +119,46 @@ throw new Exception("Not to be used directly - use inside QueryOver expression"); } - internal static IProjection ProcessDoubleSqrt(MethodCallExpression methodCallExpression) - { - IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("sqrt", NHibernateUtil.Double, property); - } - /// <summary> /// Project SQL function sqrt() /// Note: throws an exception outside of a QueryOver expression /// </summary> - public static int Sqrt(this int numericProperty) + public static double Sqrt(this int numericProperty) { throw new Exception("Not to be used directly - use inside QueryOver expression"); } - internal static IProjection ProcessIntSqrt(MethodCallExpression methodCallExpression) - { - IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("sqrt", NHibernateUtil.Int32, property); - } - /// <summary> /// Project SQL function sqrt() /// Note: throws an exception outside of a QueryOver expression /// </summary> - public static Int64 Sqrt(this Int64 numericProperty) + public static double Sqrt(this long numericProperty) { throw new Exception("Not to be used directly - use inside QueryOver expression"); } - internal static IProjection ProcessInt64Sqrt(MethodCallExpression methodCallExpression) - { - IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("sqrt", NHibernateUtil.Int64, property); - } - /// <summary> /// Project SQL function sqrt() /// Note: throws an exception outside of a QueryOver expression /// </summary> - public static decimal Sqrt(this decimal numericProperty) + public static double Sqrt(this decimal numericProperty) { throw new Exception("Not to be used directly - use inside QueryOver expression"); } - internal static IProjection ProcessDecimalSqrt(MethodCallExpression methodCallExpression) - { - IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("sqrt", NHibernateUtil.Decimal, property); - } - /// <summary> /// Project SQL function sqrt() /// Note: throws an exception outside of a QueryOver expression /// </summary> - public static byte Sqrt(this byte numericProperty) + public static double Sqrt(this byte numericProperty) { throw new Exception("Not to be used directly - use inside QueryOver expression"); } - internal static IProjection ProcessByteSqrt(MethodCallExpression methodCallExpression) + internal static IProjection ProcessSqrt(MethodCallExpression methodCallExpression) { IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("sqrt", NHibernateUtil.Byte, property); + return Projections.SqlFunction("sqrt", NHibernateUtil.Double, property); } /// <summary> Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 14:22:22 UTC (rev 5853) +++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 14:58:58 UTC (rev 5854) @@ -95,11 +95,11 @@ RegisterCustomProjection(() => ProjectionsExtensions.HourPart(default(DateTime)), ProjectionsExtensions.ProcessHourPart); RegisterCustomProjection(() => ProjectionsExtensions.MinutePart(default(DateTime)), ProjectionsExtensions.ProcessMinutePart); RegisterCustomProjection(() => ProjectionsExtensions.SecondPart(default(DateTime)), ProjectionsExtensions.ProcessSecondPart); - RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(int)), ProjectionsExtensions.ProcessIntSqrt); - RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(double)), ProjectionsExtensions.ProcessDoubleSqrt); - RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(decimal)), ProjectionsExtensions.ProcessDecimalSqrt); - RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(byte)), ProjectionsExtensions.ProcessByteSqrt); - RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(Int64)), ProjectionsExtensions.ProcessInt64Sqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(int)), ProjectionsExtensions.ProcessSqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(double)), ProjectionsExtensions.ProcessSqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(decimal)), ProjectionsExtensions.ProcessSqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(byte)), ProjectionsExtensions.ProcessSqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(long)), ProjectionsExtensions.ProcessSqrt); RegisterCustomProjection(() => ProjectionsExtensions.Lower(string.Empty), ProjectionsExtensions.ProcessLower); RegisterCustomProjection(() => ProjectionsExtensions.Upper(string.Empty), ProjectionsExtensions.ProcessUpper); RegisterCustomProjection(() => ProjectionsExtensions.TrimStr(string.Empty), ProjectionsExtensions.ProcessTrimStr); Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 14:22:22 UTC (rev 5853) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 14:58:58 UTC (rev 5854) @@ -573,7 +573,7 @@ using (ISession s = OpenSession()) using (ITransaction t = s.BeginTransaction()) { - s.Save(new Person() { Name = "p1", BirthDate = new DateTime(2009, 08, 07) }); + s.Save(new Person() { Name = "p1", BirthDate = new DateTime(2009, 08, 07), Age = 90 }); s.Save(new Person() { Name = "p2", BirthDate = new DateTime(2008, 07, 06) }); s.Save(new Person() { Name = "p3", BirthDate = new DateTime(2007, 06, 05) }); @@ -602,6 +602,18 @@ yearOfBirth.GetType().Should().Be(typeof(int)); yearOfBirth.Should().Be(2008); } + + using (ISession s = OpenSession()) + { + var sqrtOfAge = + s.QueryOver<Person>() + .Where(p => p.Name == "p1") + .Select(p => p.Age.Sqrt()) + .SingleOrDefault<object>(); + + sqrtOfAge.GetType().Should().Be(typeof(double)); + string.Format("{0:0.00}", sqrtOfAge).Should().Be("9.49"); + } } [Test] Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 14:22:22 UTC (rev 5853) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 14:58:58 UTC (rev 5854) @@ -266,7 +266,7 @@ .Add(Restrictions.Eq(Projections.SqlFunction("hour", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1)) .Add(Restrictions.Eq(Projections.SqlFunction("minute", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1)) .Add(Restrictions.Eq(Projections.SqlFunction("second", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1)) - .Add(Restrictions.Eq(Projections.SqlFunction("sqrt", NHibernateUtil.Int32, Projections.Property("Height")), 10)) + .Add(Restrictions.Eq(Projections.SqlFunction("sqrt", NHibernateUtil.Double, Projections.Property("Height")), 10d)) .Add(Restrictions.Eq(Projections.SqlFunction("lower", NHibernateUtil.String, Projections.Property("Name")), "test")) .Add(Restrictions.Eq(Projections.SqlFunction("upper", NHibernateUtil.String, Projections.Property("Name")), "TEST")) .Add(Restrictions.Eq(Projections.SqlFunction("abs", NHibernateUtil.Int32, Projections.Property("Height")), 150)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-05-22 14:22:28
|
Revision: 5853 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5853&view=rev Author: ricbrown Date: 2011-05-22 14:22:22 +0000 (Sun, 22 May 2011) Log Message: ----------- NH-2683: Added projection of SQL function extensions in QueryOver. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverProjectionBuilder.cs trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ProjectionsFixture.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverProjectionBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverProjectionBuilder.cs 2011-05-22 13:28:51 UTC (rev 5852) +++ trunk/nhibernate/src/NHibernate/Criterion/Lambda/QueryOverProjectionBuilder.cs 2011-05-22 14:22:22 UTC (rev 5853) @@ -173,7 +173,7 @@ /// </summary> public QueryOverProjectionBuilder<T> Select(Expression<Func<T, object>> expression) { - PushProjection(Projections.Property(expression)); + PushProjection(ExpressionProcessor.FindMemberProjection(expression.Body)); return this; } @@ -182,7 +182,7 @@ /// </summary> public QueryOverProjectionBuilder<T> Select(Expression<Func<object>> expression) { - PushProjection(Projections.Property(expression)); + PushProjection(ExpressionProcessor.FindMemberProjection(expression.Body)); return this; } Modified: trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs 2011-05-22 13:28:51 UTC (rev 5852) +++ trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs 2011-05-22 14:22:22 UTC (rev 5853) @@ -32,7 +32,7 @@ internal static IProjection ProcessYearPart(MethodCallExpression methodCallExpression) { IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("year", NHibernateUtil.DateTime, property); + return Projections.SqlFunction("year", NHibernateUtil.Int32, property); } /// <summary> @@ -47,7 +47,7 @@ internal static IProjection ProcessDayPart(MethodCallExpression methodCallExpression) { IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("day", NHibernateUtil.DateTime, property); + return Projections.SqlFunction("day", NHibernateUtil.Int32, property); } /// <summary> @@ -62,7 +62,7 @@ internal static IProjection ProcessMonthPart(MethodCallExpression methodCallExpression) { IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("month", NHibernateUtil.DateTime, property); + return Projections.SqlFunction("month", NHibernateUtil.Int32, property); } /// <summary> @@ -77,7 +77,7 @@ internal static IProjection ProcessHourPart(MethodCallExpression methodCallExpression) { IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("hour", NHibernateUtil.DateTime, property); + return Projections.SqlFunction("hour", NHibernateUtil.Int32, property); } /// <summary> @@ -92,7 +92,7 @@ internal static IProjection ProcessMinutePart(MethodCallExpression methodCallExpression) { IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("minute", NHibernateUtil.DateTime, property); + return Projections.SqlFunction("minute", NHibernateUtil.Int32, property); } /// <summary> @@ -107,7 +107,7 @@ internal static IProjection ProcessSecondPart(MethodCallExpression methodCallExpression) { IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - return Projections.SqlFunction("second", NHibernateUtil.DateTime, property); + return Projections.SqlFunction("second", NHibernateUtil.Int32, property); } /// <summary> Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2011-05-22 13:28:51 UTC (rev 5852) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2011-05-22 14:22:22 UTC (rev 5853) @@ -392,7 +392,7 @@ List<IProjection> projectionList = new List<IProjection>(); foreach (var projection in projections) - projectionList.Add(Projections.Property(ExpressionProcessor.FindMemberExpression(projection.Body))); + projectionList.Add(ExpressionProcessor.FindMemberProjection(projection.Body)); criteria.SetProjection(projectionList.ToArray()); return this; Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 13:28:51 UTC (rev 5852) +++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 14:22:22 UTC (rev 5853) @@ -163,6 +163,16 @@ /// </summary> public static IProjection FindMemberProjection(Expression expression) { + if (expression is UnaryExpression) + { + UnaryExpression unaryExpression = (UnaryExpression)expression; + + if (unaryExpression.NodeType != ExpressionType.Convert) + throw new Exception("Cannot interpret member from " + expression.ToString()); + + return FindMemberProjection(unaryExpression.Operand); + } + if (expression is MethodCallExpression) { MethodCallExpression methodCallExpression = (MethodCallExpression)expression; Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 13:28:51 UTC (rev 5852) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 14:22:22 UTC (rev 5853) @@ -591,6 +591,17 @@ persons[0].Name.Should().Be("p2"); } + using (ISession s = OpenSession()) + { + var yearOfBirth = + s.QueryOver<Person>() + .Where(p => p.Name == "p2") + .Select(p => p.BirthDate.YearPart()) + .SingleOrDefault<object>(); + + yearOfBirth.GetType().Should().Be(typeof(int)); + yearOfBirth.Should().Be(2008); + } } [Test] Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ProjectionsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ProjectionsFixture.cs 2011-05-22 13:28:51 UTC (rev 5852) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ProjectionsFixture.cs 2011-05-22 14:22:22 UTC (rev 5853) @@ -137,6 +137,39 @@ AssertCriteriaAreEqual(expected, actual); } + [Test] + public void SelectSingleFunction() + { + ICriteria expected = + CreateTestCriteria(typeof(Person)) + .SetProjection(Projections.SqlFunction("year", NHibernateUtil.Int32, Projections.Property("BirthDate"))); + + var actual = + CreateTestQueryOver<Person>() + .Select(p => p.BirthDate.YearPart()); + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] + public void SelectMultipleFunction() + { + ICriteria expected = + CreateTestCriteria(typeof(Person), "personAlias") + .SetProjection(Projections.ProjectionList() + .Add(Projections.SqlFunction("year", NHibernateUtil.Int32, Projections.Property("BirthDate"))) + .Add(Projections.SqlFunction("month", NHibernateUtil.Int32, Projections.Property("personAlias.BirthDate")))); + + Person personAlias = null; + var actual = + CreateTestQueryOver<Person>(() => personAlias) + .SelectList(list => list + .Select(p => p.BirthDate.YearPart()) + .Select(() => personAlias.BirthDate.MonthPart())); + + AssertCriteriaAreEqual(expected, actual); + } + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 13:28:51 UTC (rev 5852) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 14:22:22 UTC (rev 5853) @@ -260,12 +260,12 @@ { ICriteria expected = CreateTestCriteria(typeof(Person)) - .Add(Restrictions.Eq(Projections.SqlFunction("year", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1970)) - .Add(Restrictions.Eq(Projections.SqlFunction("day", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) - .Add(Restrictions.Eq(Projections.SqlFunction("month", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) - .Add(Restrictions.Eq(Projections.SqlFunction("hour", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) - .Add(Restrictions.Eq(Projections.SqlFunction("minute", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) - .Add(Restrictions.Eq(Projections.SqlFunction("second", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("year", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1970)) + .Add(Restrictions.Eq(Projections.SqlFunction("day", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("month", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("hour", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("minute", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("second", NHibernateUtil.Int32, Projections.Property("BirthDate")), 1)) .Add(Restrictions.Eq(Projections.SqlFunction("sqrt", NHibernateUtil.Int32, Projections.Property("Height")), 10)) .Add(Restrictions.Eq(Projections.SqlFunction("lower", NHibernateUtil.String, Projections.Property("Name")), "test")) .Add(Restrictions.Eq(Projections.SqlFunction("upper", NHibernateUtil.String, Projections.Property("Name")), "TEST")) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-05-22 13:28:58
|
Revision: 5852 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5852&view=rev Author: ricbrown Date: 2011-05-22 13:28:51 +0000 (Sun, 22 May 2011) Log Message: ----------- NH-2683: Added first cut of the remaining dialect functions (thanks to Vahid Nasiri for the patch). Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs 2011-05-22 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate/Criterion/ProjectionsExtensions.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -24,15 +24,376 @@ /// Project SQL function year() /// Note: throws an exception outside of a QueryOver expression /// </summary> - public static int Year(this DateTime dateTimeProperty) + public static int YearPart(this DateTime dateTimeProperty) { throw new Exception("Not to be used directly - use inside QueryOver expression"); } - internal static IProjection ProcessYear(MethodCallExpression methodCallExpression) + internal static IProjection ProcessYearPart(MethodCallExpression methodCallExpression) { IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); return Projections.SqlFunction("year", NHibernateUtil.DateTime, property); } + + /// <summary> + /// Project SQL function day() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int DayPart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessDayPart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("day", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function month() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int MonthPart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessMonthPart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("month", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function hour() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int HourPart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessHourPart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("hour", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function minute() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int MinutePart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessMinutePart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("minute", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function second() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int SecondPart(this DateTime dateTimeProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessSecondPart(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("second", NHibernateUtil.DateTime, property); + } + + /// <summary> + /// Project SQL function sqrt() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static double Sqrt(this double numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessDoubleSqrt(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("sqrt", NHibernateUtil.Double, property); + } + + /// <summary> + /// Project SQL function sqrt() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int Sqrt(this int numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessIntSqrt(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("sqrt", NHibernateUtil.Int32, property); + } + + /// <summary> + /// Project SQL function sqrt() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static Int64 Sqrt(this Int64 numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessInt64Sqrt(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("sqrt", NHibernateUtil.Int64, property); + } + + /// <summary> + /// Project SQL function sqrt() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static decimal Sqrt(this decimal numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessDecimalSqrt(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("sqrt", NHibernateUtil.Decimal, property); + } + + /// <summary> + /// Project SQL function sqrt() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static byte Sqrt(this byte numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessByteSqrt(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("sqrt", NHibernateUtil.Byte, property); + } + + /// <summary> + /// Project SQL function lower() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string Lower(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessLower(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("lower", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function upper() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string Upper(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessUpper(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("upper", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function abs() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int Abs(this int numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessIntAbs(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("abs", NHibernateUtil.Int32, property); + } + + /// <summary> + /// Project SQL function abs() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static Int64 Abs(this Int64 numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessInt64Abs(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("abs", NHibernateUtil.Int64, property); + } + + /// <summary> + /// Project SQL function abs() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static double Abs(this double numericProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessDoubleAbs(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("abs", NHibernateUtil.Double, property); + } + + /// <summary> + /// Project SQL function trim() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string TrimStr(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessTrimStr(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("trim", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function length() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int StrLength(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessStrLength(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("length", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function bit_length() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int BitLength(this string stringProperty) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessBitLength(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + return Projections.SqlFunction("bit_length", NHibernateUtil.String, property); + } + + /// <summary> + /// Project SQL function substring() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string Substr(this string stringProperty, int startIndex, int length) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessSubstr(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object startIndex = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + object length = ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]); + return Projections.SqlFunction("substring", NHibernateUtil.String, property, Projections.Constant(startIndex), Projections.Constant(length)); + } + + /// <summary> + /// Project SQL function locate() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int CharIndex(this string stringProperty, string theChar, int startLocation) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessCharIndex(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object theChar = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + object startLocation = ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]); + return Projections.SqlFunction("locate", NHibernateUtil.String, Projections.Constant(theChar), property, Projections.Constant(startLocation)); + } + + /// <summary> + /// Project SQL function coalesce() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static T Coalesce<T>(this T objectProperty, T replaceValueIfIsNull) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + /// <summary> + /// Project SQL function coalesce() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static Nullable<T> Coalesce<T>(this Nullable<T> objectProperty, T replaceValueIfIsNull) where T : struct + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessCoalesce(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object replaceValueIfIsNull = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Projections.SqlFunction("coalesce", NHibernateUtil.Object, property, Projections.Constant(replaceValueIfIsNull)); + } + + /// <summary> + /// Project SQL function concat() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static string ConcatStr(this string stringProperty, string value) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessConcatStr(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object concatWithValue = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Projections.SqlFunction("concat", NHibernateUtil.String, property, Projections.Constant(string.Empty), Projections.Constant(concatWithValue)); + } + + /// <summary> + /// Project SQL function mod() + /// Note: throws an exception outside of a QueryOver expression + /// </summary> + public static int Mod(this int numericProperty, int divisor) + { + throw new Exception("Not to be used directly - use inside QueryOver expression"); + } + + internal static IProjection ProcessMod(MethodCallExpression methodCallExpression) + { + IProjection property = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + object divisor = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + return Projections.SqlFunction("mod", NHibernateUtil.Int32, property, Projections.Constant(divisor)); + } } } Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -89,7 +89,31 @@ RegisterCustomMethodCall(() => RestrictionExtensions.IsBetween(null, null).And(null), RestrictionExtensions.ProcessIsBetween); _customProjectionProcessors = new Dictionary<string, Func<MethodCallExpression, IProjection>>(); - RegisterCustomProjection(() => ProjectionsExtensions.Year(default(DateTime)), ProjectionsExtensions.ProcessYear); + RegisterCustomProjection(() => ProjectionsExtensions.YearPart(default(DateTime)), ProjectionsExtensions.ProcessYearPart); + RegisterCustomProjection(() => ProjectionsExtensions.DayPart(default(DateTime)), ProjectionsExtensions.ProcessDayPart); + RegisterCustomProjection(() => ProjectionsExtensions.MonthPart(default(DateTime)), ProjectionsExtensions.ProcessMonthPart); + RegisterCustomProjection(() => ProjectionsExtensions.HourPart(default(DateTime)), ProjectionsExtensions.ProcessHourPart); + RegisterCustomProjection(() => ProjectionsExtensions.MinutePart(default(DateTime)), ProjectionsExtensions.ProcessMinutePart); + RegisterCustomProjection(() => ProjectionsExtensions.SecondPart(default(DateTime)), ProjectionsExtensions.ProcessSecondPart); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(int)), ProjectionsExtensions.ProcessIntSqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(double)), ProjectionsExtensions.ProcessDoubleSqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(decimal)), ProjectionsExtensions.ProcessDecimalSqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(byte)), ProjectionsExtensions.ProcessByteSqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(Int64)), ProjectionsExtensions.ProcessInt64Sqrt); + RegisterCustomProjection(() => ProjectionsExtensions.Lower(string.Empty), ProjectionsExtensions.ProcessLower); + RegisterCustomProjection(() => ProjectionsExtensions.Upper(string.Empty), ProjectionsExtensions.ProcessUpper); + RegisterCustomProjection(() => ProjectionsExtensions.TrimStr(string.Empty), ProjectionsExtensions.ProcessTrimStr); + RegisterCustomProjection(() => ProjectionsExtensions.StrLength(string.Empty), ProjectionsExtensions.ProcessStrLength); + RegisterCustomProjection(() => ProjectionsExtensions.BitLength(string.Empty), ProjectionsExtensions.ProcessBitLength); + RegisterCustomProjection(() => ProjectionsExtensions.Substr(string.Empty, 0, 0), ProjectionsExtensions.ProcessSubstr); + RegisterCustomProjection(() => ProjectionsExtensions.CharIndex(string.Empty, string.Empty, 0), ProjectionsExtensions.ProcessCharIndex); + RegisterCustomProjection(() => ProjectionsExtensions.Coalesce<DBNull>(null, null), ProjectionsExtensions.ProcessCoalesce); + RegisterCustomProjection(() => ProjectionsExtensions.Coalesce<int>(null, 0), ProjectionsExtensions.ProcessCoalesce); + RegisterCustomProjection(() => ProjectionsExtensions.ConcatStr(string.Empty, string.Empty), ProjectionsExtensions.ProcessConcatStr); + RegisterCustomProjection(() => ProjectionsExtensions.Mod(0, 0), ProjectionsExtensions.ProcessMod); + RegisterCustomProjection(() => ProjectionsExtensions.Abs(default(int)), ProjectionsExtensions.ProcessIntAbs); + RegisterCustomProjection(() => ProjectionsExtensions.Abs(default(double)), ProjectionsExtensions.ProcessDoubleAbs); + RegisterCustomProjection(() => ProjectionsExtensions.Abs(default(Int64)), ProjectionsExtensions.ProcessInt64Abs); } private static ICriterion Eq(IProjection propertyName, object value) @@ -204,7 +228,7 @@ if (methodCallExpression.Method.Name == "First") return FindMemberExpression(methodCallExpression.Arguments[0]); - throw new Exception("Unrecognised method call in epression " + expression.ToString()); + throw new Exception("Unrecognised method call in expression " + expression.ToString()); } throw new Exception("Could not determine member from " + expression.ToString()); @@ -484,8 +508,11 @@ return "class"; } - private static string Signature(MethodInfo methodInfo) + public static string Signature(MethodInfo methodInfo) { + while (methodInfo.IsGenericMethod && !methodInfo.IsGenericMethodDefinition) + methodInfo = methodInfo.GetGenericMethodDefinition(); + return methodInfo.DeclaringType.FullName + ":" + methodInfo.ToString(); } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2011-05-22 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/ExpressionProcessorFixture.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -2,11 +2,11 @@ using System; using System.Linq; using System.Linq.Expressions; - +using System.Reflection; using NHibernate.Criterion; using NHibernate.Impl; - using NUnit.Framework; +using SharpTestsEx; namespace NHibernate.Test.Criteria.Lambda { @@ -155,6 +155,34 @@ Assert.AreEqual(before.ToString(), after.ToString()); } + public void NonGenericMethod(string param1) { } + public T GenericMethod<T>(T param1) { return param1; } + + [Test] + public void TestSignatureNonGeneric() + { + MethodInfo thisMethod = GetType().GetMethod("NonGenericMethod"); + + ExpressionProcessor.Signature(thisMethod).Should().Be("NHibernate.Test.Criteria.Lambda.ExpressionProcessorFixture:Void NonGenericMethod(System.String)"); + } + + [Test] + public void TestSignatureGeneric() + { + MethodInfo thisMethod = GetType().GetMethod("GenericMethod"); + + ExpressionProcessor.Signature(thisMethod).Should().Be("NHibernate.Test.Criteria.Lambda.ExpressionProcessorFixture:T GenericMethod[T](T)"); + } + + [Test] + public void TestSignatureQualifiedGeneric() + { + Expression<Func<string>> expression = () => this.GenericMethod("test"); + MethodInfo genericMethodWithQualifiedType = (expression.Body as MethodCallExpression).Method; + + ExpressionProcessor.Signature(genericMethodWithQualifiedType).Should().Be("NHibernate.Test.Criteria.Lambda.ExpressionProcessorFixture:T GenericMethod[T](T)"); + } + } } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -584,7 +584,7 @@ { var persons = s.QueryOver<Person>() - .Where(p => p.BirthDate.Year() == 2008) + .Where(p => p.BirthDate.YearPart() == 2008) .List(); persons.Count.Should().Be(1); Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 11:02:26 UTC (rev 5851) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/RestrictionsFixture.cs 2011-05-22 13:28:51 UTC (rev 5852) @@ -260,11 +260,47 @@ { ICriteria expected = CreateTestCriteria(typeof(Person)) - .Add(Restrictions.Eq(Projections.SqlFunction("year", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1970)); + .Add(Restrictions.Eq(Projections.SqlFunction("year", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1970)) + .Add(Restrictions.Eq(Projections.SqlFunction("day", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("month", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("hour", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("minute", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("second", NHibernateUtil.DateTime, Projections.Property("BirthDate")), 1)) + .Add(Restrictions.Eq(Projections.SqlFunction("sqrt", NHibernateUtil.Int32, Projections.Property("Height")), 10)) + .Add(Restrictions.Eq(Projections.SqlFunction("lower", NHibernateUtil.String, Projections.Property("Name")), "test")) + .Add(Restrictions.Eq(Projections.SqlFunction("upper", NHibernateUtil.String, Projections.Property("Name")), "TEST")) + .Add(Restrictions.Eq(Projections.SqlFunction("abs", NHibernateUtil.Int32, Projections.Property("Height")), 150)) + .Add(Restrictions.Eq(Projections.SqlFunction("trim", NHibernateUtil.String, Projections.Property("Name")), "test")) + .Add(Restrictions.Eq(Projections.SqlFunction("length", NHibernateUtil.String, Projections.Property("Name")), 4)) + .Add(Restrictions.Eq(Projections.SqlFunction("bit_length", NHibernateUtil.String, Projections.Property("Name")), 32)) + .Add(Restrictions.Eq(Projections.SqlFunction("substring", NHibernateUtil.String, Projections.Property("Name"), Projections.Constant(1), Projections.Constant(2)), "te")) + .Add(Restrictions.Eq(Projections.SqlFunction("locate", NHibernateUtil.String, Projections.Constant("e"), Projections.Property("Name"), Projections.Constant(1)), 2)) + .Add(Restrictions.Eq(Projections.SqlFunction("coalesce", NHibernateUtil.Object, Projections.Property("Name"), Projections.Constant("not-null-val")), "test")) + .Add(Restrictions.Eq(Projections.SqlFunction("coalesce", NHibernateUtil.Object, Projections.Property("NullableIsParent"), Projections.Constant(true)), true)) + .Add(Restrictions.Eq(Projections.SqlFunction("concat", NHibernateUtil.String, Projections.Property("Name"), Projections.Constant(string.Empty), Projections.Constant("A")), "testA")) + .Add(Restrictions.Eq(Projections.SqlFunction("mod", NHibernateUtil.Int32, Projections.Property("Height"), Projections.Constant(10)), 0)); IQueryOver<Person> actual = CreateTestQueryOver<Person>() - .Where(p => p.BirthDate.Year() == 1970); + .Where(p => p.BirthDate.YearPart() == 1970) + .And(p => p.BirthDate.DayPart() == 1) + .And(p => p.BirthDate.MonthPart() == 1) + .And(p => p.BirthDate.HourPart() == 1) + .And(p => p.BirthDate.MinutePart() == 1) + .And(p => p.BirthDate.SecondPart() == 1) + .And(p => p.Height.Sqrt() == 10) + .And(p => p.Name.Lower() == "test") + .And(p => p.Name.Upper() == "TEST") + .And(p => p.Height.Abs() == 150) + .And(p => p.Name.TrimStr() == "test") + .And(p => p.Name.StrLength() == 4) + .And(p => p.Name.BitLength() == 32) + .And(p => p.Name.Substr(1, 2) == "te") + .And(p => p.Name.CharIndex("e", 1) == 2) + .And(p => p.Name.Coalesce("not-null-val") == "test") + .And(p => p.NullableIsParent.Coalesce(true) == true) + .And(p => p.Name.ConcatStr("A") == "testA") + .And(p => p.Height.Mod(10) == 0); AssertCriteriaAreEqual(expected, actual); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-22 11:02:32
|
Revision: 5851 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5851&view=rev Author: fabiomaulo Date: 2011-05-22 11:02:26 +0000 (Sun, 22 May 2011) Log Message: ----------- Minor (reformat) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs 2011-05-22 10:59:47 UTC (rev 5850) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs 2011-05-22 11:02:26 UTC (rev 5851) @@ -316,36 +316,38 @@ writer = new QueryWriter(); } - private void EndQuery() - { - QueryWriter queryWriter = ((QueryWriter) writer); - SqlString sqlString = queryWriter.ToSqlString(); + private void EndQuery() + { + var queryWriter = ((QueryWriter) writer); + SqlString sqlString = queryWriter.ToSqlString(); - if (queryWriter.Take.HasValue || queryWriter.Skip.HasValue) - sqlString = sessionFactory.Dialect.GetLimitString(sqlString, queryWriter.Skip ?? 0, queryWriter.Take ?? int.MaxValue); + if (queryWriter.Take.HasValue || queryWriter.Skip.HasValue) + { + sqlString = sessionFactory.Dialect.GetLimitString(sqlString, queryWriter.Skip ?? 0, queryWriter.Take ?? int.MaxValue); + } - writer = outputStack[0]; - outputStack.RemoveAt(0); - Out(sqlString); - } + writer = outputStack[0]; + outputStack.RemoveAt(0); + Out(sqlString); + } - private void Skip(IASTNode node) - { - if(node is ParameterNode) - { - throw new NotSupportedException("Parameter limits is not supported yet."); - } - ((QueryWriter) writer).Skip = Convert.ToInt32(node.Text); - } + private void Skip(IASTNode node) + { + if (node is ParameterNode) + { + throw new NotSupportedException("Parameter limits is not supported yet."); + } + ((QueryWriter) writer).Skip = Convert.ToInt32(node.Text); + } - private void Take(IASTNode node) - { - if (node is ParameterNode) - { - throw new NotSupportedException("Parameter limits is not supported yet."); - } - ((QueryWriter)writer).Take = Convert.ToInt32(node.Text); - } + private void Take(IASTNode node) + { + if (node is ParameterNode) + { + throw new NotSupportedException("Parameter limits is not supported yet."); + } + ((QueryWriter) writer).Take = Convert.ToInt32(node.Text); + } #region Nested type: DefaultWriter This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-22 10:59:55
|
Revision: 5850 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5850&view=rev Author: fabiomaulo Date: 2011-05-22 10:59:47 +0000 (Sun, 22 May 2011) Log Message: ----------- Grammar changes to support NH-2702 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlParser.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlSqlWalker.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/SqlGenerator.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Hql.g trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.g trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SqlGenerator.g trunk/nhibernate/src/NHibernate.Test/Hql/Ast/LimitClauseFixture.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs 2011-05-21 13:23:05 UTC (rev 5849) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlLexer.cs 2011-05-22 10:59:47 UTC (rev 5850) @@ -1,4 +1,4 @@ -// $ANTLR 3.2 Sep 23, 2009 12:02:23 Hql.g 2011-04-11 10:19:40 +// $ANTLR 3.2 Sep 23, 2009 12:02:23 Hql.g 2011-05-22 07:45:50 // The variable 'variable' is assigned but its value is never used. #pragma warning disable 168, 219 @@ -17,15 +17,15 @@ namespace NHibernate.Hql.Ast.ANTLR { public partial class HqlLexer : Lexer { - public const int LT = 107; + public const int LT = 109; public const int EXPONENT = 130; - public const int STAR = 118; + public const int STAR = 120; public const int FLOAT_SUFFIX = 131; public const int LITERAL_by = 56; public const int CASE = 57; public const int NEW = 37; public const int FILTER_ENTITY = 76; - public const int PARAM = 123; + public const int PARAM = 106; public const int COUNT = 12; public const int NOT = 38; public const int EOF = -1; @@ -33,7 +33,7 @@ public const int QUOTED_String = 124; public const int ESCqs = 128; public const int WEIRD_IDENT = 93; - public const int OPEN_BRACKET = 120; + public const int OPEN_BRACKET = 122; public const int FULL = 23; public const int ORDER_ELEMENT = 85; public const int IS_NULL = 80; @@ -45,10 +45,10 @@ public const int EQ = 102; public const int SELECT = 45; public const int INTO = 30; - public const int NE = 105; - public const int GE = 110; + public const int NE = 107; + public const int GE = 112; public const int TAKE = 50; - public const int CONCAT = 111; + public const int CONCAT = 113; public const int ID_LETTER = 127; public const int NULL = 39; public const int ELSE = 59; @@ -75,9 +75,9 @@ public const int ALIAS = 72; public const int JAVA_CONSTANT = 100; public const int CONSTANT = 94; - public const int GT = 108; + public const int GT = 110; public const int QUERY = 86; - public const int BNOT = 112; + public const int BNOT = 114; public const int INDEX_OP = 78; public const int NUM_FLOAT = 98; public const int FROM = 22; @@ -87,7 +87,7 @@ public const int CONSTRUCTOR = 73; public const int T__133 = 133; public const int T__134 = 134; - public const int CLOSE_BRACKET = 121; + public const int CLOSE_BRACKET = 123; public const int WHERE = 55; public const int CLASS = 11; public const int MEMBER = 67; @@ -96,7 +96,7 @@ public const int ORDER = 41; public const int MAX = 35; public const int UPDATE = 53; - public const int SQL_NE = 106; + public const int SQL_NE = 108; public const int AND = 6; public const int SUM = 49; public const int ASCENDING = 8; @@ -111,11 +111,11 @@ public const int LEFT = 33; public const int SOME = 48; public const int ALL = 4; - public const int BOR = 113; + public const int BOR = 115; public const int IDENT = 125; public const int CASE2 = 74; - public const int BXOR = 114; - public const int PLUS = 116; + public const int BXOR = 116; + public const int PLUS = 118; public const int EXISTS = 19; public const int DOT = 15; public const int WITH = 63; @@ -132,23 +132,23 @@ public const int HAVING = 25; public const int MIN = 36; public const int IS_NOT_NULL = 79; - public const int MINUS = 117; + public const int MINUS = 119; public const int ELEMENTS = 17; - public const int BAND = 115; + public const int BAND = 117; public const int TRUE = 51; public const int JOIN = 32; public const int IN_LIST = 77; public const int UNION = 52; public const int OPEN = 103; - public const int COLON = 122; + public const int COLON = 105; public const int ANY = 5; public const int CLOSE = 104; public const int WHEN = 61; - public const int DIV = 119; + public const int DIV = 121; public const int DESCENDING = 14; public const int AGGREGATE = 71; public const int BETWEEN = 10; - public const int LE = 109; + public const int LE = 111; // delegates // delegators @@ -1810,8 +1810,8 @@ { int _type = EQ; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:684:3: ( '=' ) - // Hql.g:684:5: '=' + // Hql.g:689:3: ( '=' ) + // Hql.g:689:5: '=' { Match('='); if (state.failed) return ; @@ -1833,8 +1833,8 @@ { int _type = LT; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:685:3: ( '<' ) - // Hql.g:685:5: '<' + // Hql.g:690:3: ( '<' ) + // Hql.g:690:5: '<' { Match('<'); if (state.failed) return ; @@ -1856,8 +1856,8 @@ { int _type = GT; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:686:3: ( '>' ) - // Hql.g:686:5: '>' + // Hql.g:691:3: ( '>' ) + // Hql.g:691:5: '>' { Match('>'); if (state.failed) return ; @@ -1879,8 +1879,8 @@ { int _type = SQL_NE; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:687:7: ( '<>' ) - // Hql.g:687:9: '<>' + // Hql.g:692:7: ( '<>' ) + // Hql.g:692:9: '<>' { Match("<>"); if (state.failed) return ; @@ -1903,7 +1903,7 @@ { int _type = NE; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:688:3: ( '!=' | '^=' ) + // Hql.g:693:3: ( '!=' | '^=' ) int alt1 = 2; int LA1_0 = input.LA(1); @@ -1926,7 +1926,7 @@ switch (alt1) { case 1 : - // Hql.g:688:5: '!=' + // Hql.g:693:5: '!=' { Match("!="); if (state.failed) return ; @@ -1934,7 +1934,7 @@ } break; case 2 : - // Hql.g:688:12: '^=' + // Hql.g:693:12: '^=' { Match("^="); if (state.failed) return ; @@ -1959,8 +1959,8 @@ { int _type = LE; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:689:3: ( '<=' ) - // Hql.g:689:5: '<=' + // Hql.g:694:3: ( '<=' ) + // Hql.g:694:5: '<=' { Match("<="); if (state.failed) return ; @@ -1983,8 +1983,8 @@ { int _type = GE; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:690:3: ( '>=' ) - // Hql.g:690:5: '>=' + // Hql.g:695:3: ( '>=' ) + // Hql.g:695:5: '>=' { Match(">="); if (state.failed) return ; @@ -2007,8 +2007,8 @@ { int _type = BOR; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:692:5: ( '|' ) - // Hql.g:692:8: '|' + // Hql.g:697:5: ( '|' ) + // Hql.g:697:8: '|' { Match('|'); if (state.failed) return ; @@ -2030,8 +2030,8 @@ { int _type = BXOR; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:693:6: ( '^' ) - // Hql.g:693:8: '^' + // Hql.g:698:6: ( '^' ) + // Hql.g:698:8: '^' { Match('^'); if (state.failed) return ; @@ -2053,8 +2053,8 @@ { int _type = BAND; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:694:6: ( '&' ) - // Hql.g:694:8: '&' + // Hql.g:699:6: ( '&' ) + // Hql.g:699:8: '&' { Match('&'); if (state.failed) return ; @@ -2076,8 +2076,8 @@ { int _type = BNOT; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:695:6: ( '!' ) - // Hql.g:695:8: '!' + // Hql.g:700:6: ( '!' ) + // Hql.g:700:8: '!' { Match('!'); if (state.failed) return ; @@ -2099,8 +2099,8 @@ { int _type = COMMA; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:697:6: ( ',' ) - // Hql.g:697:8: ',' + // Hql.g:702:6: ( ',' ) + // Hql.g:702:8: ',' { Match(','); if (state.failed) return ; @@ -2122,8 +2122,8 @@ { int _type = OPEN; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:699:5: ( '(' ) - // Hql.g:699:7: '(' + // Hql.g:704:5: ( '(' ) + // Hql.g:704:7: '(' { Match('('); if (state.failed) return ; @@ -2145,8 +2145,8 @@ { int _type = CLOSE; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:700:6: ( ')' ) - // Hql.g:700:8: ')' + // Hql.g:705:6: ( ')' ) + // Hql.g:705:8: ')' { Match(')'); if (state.failed) return ; @@ -2168,8 +2168,8 @@ { int _type = OPEN_BRACKET; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:701:13: ( '[' ) - // Hql.g:701:15: '[' + // Hql.g:706:13: ( '[' ) + // Hql.g:706:15: '[' { Match('['); if (state.failed) return ; @@ -2191,8 +2191,8 @@ { int _type = CLOSE_BRACKET; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:702:14: ( ']' ) - // Hql.g:702:16: ']' + // Hql.g:707:14: ( ']' ) + // Hql.g:707:16: ']' { Match(']'); if (state.failed) return ; @@ -2214,8 +2214,8 @@ { int _type = CONCAT; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:704:7: ( '||' ) - // Hql.g:704:9: '||' + // Hql.g:709:7: ( '||' ) + // Hql.g:709:9: '||' { Match("||"); if (state.failed) return ; @@ -2238,8 +2238,8 @@ { int _type = PLUS; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:705:5: ( '+' ) - // Hql.g:705:7: '+' + // Hql.g:710:5: ( '+' ) + // Hql.g:710:7: '+' { Match('+'); if (state.failed) return ; @@ -2261,8 +2261,8 @@ { int _type = MINUS; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:706:6: ( '-' ) - // Hql.g:706:8: '-' + // Hql.g:711:6: ( '-' ) + // Hql.g:711:8: '-' { Match('-'); if (state.failed) return ; @@ -2284,8 +2284,8 @@ { int _type = STAR; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:707:5: ( '*' ) - // Hql.g:707:7: '*' + // Hql.g:712:5: ( '*' ) + // Hql.g:712:7: '*' { Match('*'); if (state.failed) return ; @@ -2307,8 +2307,8 @@ { int _type = DIV; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:708:4: ( '/' ) - // Hql.g:708:6: '/' + // Hql.g:713:4: ( '/' ) + // Hql.g:713:6: '/' { Match('/'); if (state.failed) return ; @@ -2330,8 +2330,8 @@ { int _type = COLON; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:709:6: ( ':' ) - // Hql.g:709:8: ':' + // Hql.g:714:6: ( ':' ) + // Hql.g:714:8: ':' { Match(':'); if (state.failed) return ; @@ -2353,8 +2353,8 @@ { int _type = PARAM; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:710:6: ( '?' ) - // Hql.g:710:8: '?' + // Hql.g:715:6: ( '?' ) + // Hql.g:715:8: '?' { Match('?'); if (state.failed) return ; @@ -2376,11 +2376,11 @@ { int _type = IDENT; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:713:2: ( ID_START_LETTER ( ID_LETTER )* ) - // Hql.g:713:4: ID_START_LETTER ( ID_LETTER )* + // Hql.g:718:2: ( ID_START_LETTER ( ID_LETTER )* ) + // Hql.g:718:4: ID_START_LETTER ( ID_LETTER )* { mID_START_LETTER(); if (state.failed) return ; - // Hql.g:713:20: ( ID_LETTER )* + // Hql.g:718:20: ( ID_LETTER )* do { int alt2 = 2; @@ -2395,7 +2395,7 @@ switch (alt2) { case 1 : - // Hql.g:713:22: ID_LETTER + // Hql.g:718:22: ID_LETTER { mID_LETTER(); if (state.failed) return ; @@ -2427,7 +2427,7 @@ { try { - // Hql.g:718:5: ( '_' | '$' | 'a' .. 'z' | 'A' .. 'Z' | '\\u0080' .. '\\ufffe' ) + // Hql.g:723:5: ( '_' | '$' | 'a' .. 'z' | 'A' .. 'Z' | '\\u0080' .. '\\ufffe' ) // Hql.g: { if ( input.LA(1) == '$' || (input.LA(1) >= 'A' && input.LA(1) <= 'Z') || input.LA(1) == '_' || (input.LA(1) >= 'a' && input.LA(1) <= 'z') || (input.LA(1) >= '\u0080' && input.LA(1) <= '\uFFFE') ) @@ -2457,7 +2457,7 @@ { try { - // Hql.g:727:5: ( ID_START_LETTER | '0' .. '9' ) + // Hql.g:732:5: ( ID_START_LETTER | '0' .. '9' ) // Hql.g: { if ( input.LA(1) == '$' || (input.LA(1) >= '0' && input.LA(1) <= '9') || (input.LA(1) >= 'A' && input.LA(1) <= 'Z') || input.LA(1) == '_' || (input.LA(1) >= 'a' && input.LA(1) <= 'z') || (input.LA(1) >= '\u0080' && input.LA(1) <= '\uFFFE') ) @@ -2489,11 +2489,11 @@ { int _type = QUOTED_String; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:732:4: ( '\\'' ( ( ESCqs )=> ESCqs | ~ '\\'' )* '\\'' ) - // Hql.g:732:6: '\\'' ( ( ESCqs )=> ESCqs | ~ '\\'' )* '\\'' + // Hql.g:737:4: ( '\\'' ( ( ESCqs )=> ESCqs | ~ '\\'' )* '\\'' ) + // Hql.g:737:6: '\\'' ( ( ESCqs )=> ESCqs | ~ '\\'' )* '\\'' { Match('\''); if (state.failed) return ; - // Hql.g:732:11: ( ( ESCqs )=> ESCqs | ~ '\\'' )* + // Hql.g:737:11: ( ( ESCqs )=> ESCqs | ~ '\\'' )* do { int alt3 = 3; @@ -2519,14 +2519,14 @@ switch (alt3) { case 1 : - // Hql.g:732:13: ( ESCqs )=> ESCqs + // Hql.g:737:13: ( ESCqs )=> ESCqs { mESCqs(); if (state.failed) return ; } break; case 2 : - // Hql.g:732:31: ~ '\\'' + // Hql.g:737:31: ~ '\\'' { if ( (input.LA(1) >= '\u0000' && input.LA(1) <= '&') || (input.LA(1) >= '(' && input.LA(1) <= '\uFFFF') ) { @@ -2570,8 +2570,8 @@ { try { - // Hql.g:737:2: ( '\\'' '\\'' ) - // Hql.g:738:3: '\\'' '\\'' + // Hql.g:742:2: ( '\\'' '\\'' ) + // Hql.g:743:3: '\\'' '\\'' { Match('\''); if (state.failed) return ; Match('\''); if (state.failed) return ; @@ -2592,10 +2592,10 @@ { int _type = WS; int _channel = DEFAULT_TOKEN_CHANNEL; - // Hql.g:741:5: ( ( ' ' | '\\t' | '\\r' '\\n' | '\\n' | '\\r' ) ) - // Hql.g:741:9: ( ' ' | '\\t' | '\\r' '\\n' | '\\n' | '\\r' ) + // Hql.g:746:5: ( ( ' ' | '\\t' | '\\r' '\\n' | '\\n' | '\\r' ) ) + // Hql.g:746:9: ( ' ' | '\\t' | '\\r' '\\n' | '\\n' | '\\r' ) { - // Hql.g:741:9: ( ' ' | '\\t' | '\\r' '\\n' | '\\n' | '\\r' ) + // Hql.g:746:9: ( ' ' | '\\t' | '\\r' '\\n' | '\\n' | '\\r' ) int alt4 = 5; switch ( input.LA(1) ) { @@ -2638,21 +2638,21 @@ switch (alt4) { case 1 : - // Hql.g:741:13: ' ' + // Hql.g:746:13: ' ' { Match(' '); if (state.failed) return ; } break; case 2 : - // Hql.g:742:7: '\\t' + // Hql.g:747:7: '\\t' { Match('\t'); if (state.failed) return ; } break; case 3 : - // Hql.g:743:7: '\\r' '\\n' + // Hql.g:748:7: '\\r' '\\n' { Match('\r'); if (state.failed) return ; Match('\n'); if (state.failed) return ; @@ -2660,14 +2660,14 @@ } break; case 4 : - // Hql.g:744:7: '\\n' + // Hql.g:749:7: '\\n' { Match('\n'); if (state.failed) return ; } break; case 5 : - // Hql.g:745:7: '\\r' + // Hql.g:750:7: '\\r' { Match('\r'); if (state.failed) return ; @@ -2705,7 +2705,7 @@ IToken f4 = null; bool isDecimal=false; IToken t=null; - // Hql.g:754:2: ( '.' ( ( '0' .. '9' )+ ( EXPONENT )? (f1= FLOAT_SUFFIX )? )? | ( '0' ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? | ( '1' .. '9' ) ( '0' .. '9' )* ) ( ( 'l' ) | {...}? ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) )? ) + // Hql.g:759:2: ( '.' ( ( '0' .. '9' )+ ( EXPONENT )? (f1= FLOAT_SUFFIX )? )? | ( '0' ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? | ( '1' .. '9' ) ( '0' .. '9' )* ) ( ( 'l' ) | {...}? ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) )? ) int alt20 = 2; int LA20_0 = input.LA(1); @@ -2728,14 +2728,14 @@ switch (alt20) { case 1 : - // Hql.g:754:6: '.' ( ( '0' .. '9' )+ ( EXPONENT )? (f1= FLOAT_SUFFIX )? )? + // Hql.g:759:6: '.' ( ( '0' .. '9' )+ ( EXPONENT )? (f1= FLOAT_SUFFIX )? )? { Match('.'); if (state.failed) return ; if ( (state.backtracking==0) ) { _type = DOT; } - // Hql.g:755:4: ( ( '0' .. '9' )+ ( EXPONENT )? (f1= FLOAT_SUFFIX )? )? + // Hql.g:760:4: ( ( '0' .. '9' )+ ( EXPONENT )? (f1= FLOAT_SUFFIX )? )? int alt8 = 2; int LA8_0 = input.LA(1); @@ -2746,9 +2746,9 @@ switch (alt8) { case 1 : - // Hql.g:755:6: ( '0' .. '9' )+ ( EXPONENT )? (f1= FLOAT_SUFFIX )? + // Hql.g:760:6: ( '0' .. '9' )+ ( EXPONENT )? (f1= FLOAT_SUFFIX )? { - // Hql.g:755:6: ( '0' .. '9' )+ + // Hql.g:760:6: ( '0' .. '9' )+ int cnt5 = 0; do { @@ -2764,7 +2764,7 @@ switch (alt5) { case 1 : - // Hql.g:755:7: '0' .. '9' + // Hql.g:760:7: '0' .. '9' { MatchRange('0','9'); if (state.failed) return ; @@ -2784,7 +2784,7 @@ loop5: ; // Stops C# compiler whining that label 'loop5' has no statements - // Hql.g:755:18: ( EXPONENT )? + // Hql.g:760:18: ( EXPONENT )? int alt6 = 2; int LA6_0 = input.LA(1); @@ -2795,7 +2795,7 @@ switch (alt6) { case 1 : - // Hql.g:755:19: EXPONENT + // Hql.g:760:19: EXPONENT { mEXPONENT(); if (state.failed) return ; @@ -2804,7 +2804,7 @@ } - // Hql.g:755:30: (f1= FLOAT_SUFFIX )? + // Hql.g:760:30: (f1= FLOAT_SUFFIX )? int alt7 = 2; int LA7_0 = input.LA(1); @@ -2815,7 +2815,7 @@ switch (alt7) { case 1 : - // Hql.g:755:31: f1= FLOAT_SUFFIX + // Hql.g:760:31: f1= FLOAT_SUFFIX { int f1Start1034 = CharIndex; mFLOAT_SUFFIX(); if (state.failed) return ; @@ -2857,9 +2857,9 @@ } break; case 2 : - // Hql.g:771:4: ( '0' ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? | ( '1' .. '9' ) ( '0' .. '9' )* ) ( ( 'l' ) | {...}? ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) )? + // Hql.g:776:4: ( '0' ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? | ( '1' .. '9' ) ( '0' .. '9' )* ) ( ( 'l' ) | {...}? ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) )? { - // Hql.g:771:4: ( '0' ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? | ( '1' .. '9' ) ( '0' .. '9' )* ) + // Hql.g:776:4: ( '0' ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? | ( '1' .. '9' ) ( '0' .. '9' )* ) int alt13 = 2; int LA13_0 = input.LA(1); @@ -2882,14 +2882,14 @@ switch (alt13) { case 1 : - // Hql.g:771:6: '0' ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? + // Hql.g:776:6: '0' ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? { Match('0'); if (state.failed) return ; if ( (state.backtracking==0) ) { isDecimal = true; } - // Hql.g:772:4: ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? + // Hql.g:777:4: ( ( 'x' ) ( HEX_DIGIT )+ | ( '0' .. '7' )+ )? int alt11 = 3; int LA11_0 = input.LA(1); @@ -2904,16 +2904,16 @@ switch (alt11) { case 1 : - // Hql.g:772:6: ( 'x' ) ( HEX_DIGIT )+ + // Hql.g:777:6: ( 'x' ) ( HEX_DIGIT )+ { - // Hql.g:772:6: ( 'x' ) - // Hql.g:772:7: 'x' + // Hql.g:777:6: ( 'x' ) + // Hql.g:777:7: 'x' { Match('x'); if (state.failed) return ; } - // Hql.g:773:5: ( HEX_DIGIT )+ + // Hql.g:778:5: ( HEX_DIGIT )+ int cnt9 = 0; do { @@ -2979,7 +2979,7 @@ switch (alt9) { case 1 : - // Hql.g:780:7: HEX_DIGIT + // Hql.g:785:7: HEX_DIGIT { mHEX_DIGIT(); if (state.failed) return ; @@ -3003,9 +3003,9 @@ } break; case 2 : - // Hql.g:782:6: ( '0' .. '7' )+ + // Hql.g:787:6: ( '0' .. '7' )+ { - // Hql.g:782:6: ( '0' .. '7' )+ + // Hql.g:787:6: ( '0' .. '7' )+ int cnt10 = 0; do { @@ -3021,7 +3021,7 @@ switch (alt10) { case 1 : - // Hql.g:782:7: '0' .. '7' + // Hql.g:787:7: '0' .. '7' { MatchRange('0','7'); if (state.failed) return ; @@ -3051,16 +3051,16 @@ } break; case 2 : - // Hql.g:784:5: ( '1' .. '9' ) ( '0' .. '9' )* + // Hql.g:789:5: ( '1' .. '9' ) ( '0' .. '9' )* { - // Hql.g:784:5: ( '1' .. '9' ) - // Hql.g:784:6: '1' .. '9' + // Hql.g:789:5: ( '1' .. '9' ) + // Hql.g:789:6: '1' .. '9' { MatchRange('1','9'); if (state.failed) return ; } - // Hql.g:784:16: ( '0' .. '9' )* + // Hql.g:789:16: ( '0' .. '9' )* do { int alt12 = 2; @@ -3075,7 +3075,7 @@ switch (alt12) { case 1 : - // Hql.g:784:17: '0' .. '9' + // Hql.g:789:17: '0' .. '9' { MatchRange('0','9'); if (state.failed) return ; @@ -3100,7 +3100,7 @@ } - // Hql.g:786:3: ( ( 'l' ) | {...}? ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) )? + // Hql.g:791:3: ( ( 'l' ) | {...}? ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) )? int alt19 = 3; int LA19_0 = input.LA(1); @@ -3115,10 +3115,10 @@ switch (alt19) { case 1 : - // Hql.g:786:5: ( 'l' ) + // Hql.g:791:5: ( 'l' ) { - // Hql.g:786:5: ( 'l' ) - // Hql.g:786:6: 'l' + // Hql.g:791:5: ( 'l' ) + // Hql.g:791:6: 'l' { Match('l'); if (state.failed) return ; @@ -3132,14 +3132,14 @@ } break; case 2 : - // Hql.g:789:5: {...}? ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) + // Hql.g:794:5: {...}? ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) { if ( !((isDecimal)) ) { if ( state.backtracking > 0 ) {state.failed = true; return ;} throw new FailedPredicateException(input, "NUM_INT", "isDecimal"); } - // Hql.g:790:4: ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) + // Hql.g:795:4: ( '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? | EXPONENT (f3= FLOAT_SUFFIX )? | f4= FLOAT_SUFFIX ) int alt18 = 3; switch ( input.LA(1) ) { @@ -3171,10 +3171,10 @@ switch (alt18) { case 1 : - // Hql.g:790:8: '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? + // Hql.g:795:8: '.' ( '0' .. '9' )* ( EXPONENT )? (f2= FLOAT_SUFFIX )? { Match('.'); if (state.failed) return ; - // Hql.g:790:12: ( '0' .. '9' )* + // Hql.g:795:12: ( '0' .. '9' )* do { int alt14 = 2; @@ -3189,7 +3189,7 @@ switch (alt14) { case 1 : - // Hql.g:790:13: '0' .. '9' + // Hql.g:795:13: '0' .. '9' { MatchRange('0','9'); if (state.failed) return ; @@ -3204,7 +3204,7 @@ loop14: ; // Stops C# compiler whining that label 'loop14' has no statements - // Hql.g:790:24: ( EXPONENT )? + // Hql.g:795:24: ( EXPONENT )? int alt15 = 2; int LA15_0 = input.LA(1); @@ -3215,7 +3215,7 @@ switch (alt15) { case 1 : - // Hql.g:790:25: EXPONENT + // Hql.g:795:25: EXPONENT { mEXPONENT(); if (state.failed) return ; @@ -3224,7 +3224,7 @@ } - // Hql.g:790:36: (f2= FLOAT_SUFFIX )? + // Hql.g:795:36: (f2= FLOAT_SUFFIX )? int alt16 = 2; int LA16_0 = input.LA(1); @@ -3235,7 +3235,7 @@ switch (alt16) { case 1 : - // Hql.g:790:37: f2= FLOAT_SUFFIX + // Hql.g:795:37: f2= FLOAT_SUFFIX { int f2Start1236 = CharIndex; mFLOAT_SUFFIX(); if (state.failed) return ; @@ -3254,10 +3254,10 @@ } break; case 2 : - // Hql.g:791:8: EXPONENT (f3= FLOAT_SUFFIX )? + // Hql.g:796:8: EXPONENT (f3= FLOAT_SUFFIX )? { mEXPONENT(); if (state.failed) return ; - // Hql.g:791:17: (f3= FLOAT_SUFFIX )? + // Hql.g:796:17: (f3= FLOAT_SUFFIX )? int alt17 = 2; int LA17_0 = input.LA(1); @@ -3268,7 +3268,7 @@ switch (alt17) { case 1 : - // Hql.g:791:18: f3= FLOAT_SUFFIX + // Hql.g:796:18: f3= FLOAT_SUFFIX { int f3Start1254 = CharIndex; mFLOAT_SUFFIX(); if (state.failed) return ; @@ -3287,7 +3287,7 @@ } break; case 3 : - // Hql.g:792:8: f4= FLOAT_SUFFIX + // Hql.g:797:8: f4= FLOAT_SUFFIX { int f4Start1269 = CharIndex; mFLOAT_SUFFIX(); if (state.failed) return ; @@ -3344,8 +3344,8 @@ { try { - // Hql.g:814:2: ( ( '0' .. '9' | 'a' .. 'f' ) ) - // Hql.g:814:4: ( '0' .. '9' | 'a' .. 'f' ) + // Hql.g:819:2: ( ( '0' .. '9' | 'a' .. 'f' ) ) + // Hql.g:819:4: ( '0' .. '9' | 'a' .. 'f' ) { if ( (input.LA(1) >= '0' && input.LA(1) <= '9') || (input.LA(1) >= 'a' && input.LA(1) <= 'f') ) { @@ -3374,17 +3374,17 @@ { try { - // Hql.g:820:2: ( ( 'e' ) ( '+' | '-' )? ( '0' .. '9' )+ ) - // Hql.g:820:4: ( 'e' ) ( '+' | '-' )? ( '0' .. '9' )+ + // Hql.g:825:2: ( ( 'e' ) ( '+' | '-' )? ( '0' .. '9' )+ ) + // Hql.g:825:4: ( 'e' ) ( '+' | '-' )? ( '0' .. '9' )+ { - // Hql.g:820:4: ( 'e' ) - // Hql.g:820:5: 'e' + // Hql.g:825:4: ( 'e' ) + // Hql.g:825:5: 'e' { Match('e'); if (state.failed) return ; } - // Hql.g:820:10: ( '+' | '-' )? + // Hql.g:825:10: ( '+' | '-' )? int alt21 = 2; int LA21_0 = input.LA(1); @@ -3415,7 +3415,7 @@ } - // Hql.g:820:21: ( '0' .. '9' )+ + // Hql.g:825:21: ( '0' .. '9' )+ int cnt22 = 0; do { @@ -3431,7 +3431,7 @@ switch (alt22) { case 1 : - // Hql.g:820:22: '0' .. '9' + // Hql.g:825:22: '0' .. '9' { MatchRange('0','9'); if (state.failed) return ; @@ -3466,7 +3466,7 @@ { try { - // Hql.g:825:2: ( 'f' | 'd' | 'm' ) + // Hql.g:830:2: ( 'f' | 'd' | 'm' ) // Hql.g: { if ( input.LA(1) == 'd' || input.LA(1) == 'f' || input.LA(1) == 'm' ) @@ -4170,8 +4170,8 @@ // $ANTLR start "synpred1_Hql" public void synpred1_Hql_fragment() { - // Hql.g:732:13: ( ESCqs ) - // Hql.g:732:14: ESCqs + // Hql.g:737:13: ( ESCqs ) + // Hql.g:737:14: ESCqs { mESCqs(); if (state.failed) return ; Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlParser.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlParser.cs 2011-05-21 13:23:05 UTC (rev 5849) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Generated/HqlParser.cs 2011-05-22 10:59:47 UTC (rev 5850) @@ -1,4 +1,4 @@ -// $ANTLR 3.2 Sep 23, 2009 12:02:23 Hql.g 2011-04-11 10:19:39 +// $ANTLR 3.2 Sep 23, 2009 12:02:23 Hql.g 2011-05-22 07:45:49 // The variable 'variable' is assigned but its value is never used. #pragma warning disable 168, 219 @@ -130,6 +130,8 @@ "EQ", "OPEN", "CLOSE", + "COLON", + "PARAM", "NE", "SQL_NE", "LT", @@ -147,8 +149,6 @@ "DIV", "OPEN_BRACKET", "CLOSE_BRACKET", - "COLON", - "PARAM", "QUOTED_String", "IDENT", "ID_START_LETTER", @@ -163,14 +163,14 @@ }; public const int EXPONENT = 130; - public const int LT = 107; + public const int LT = 109; public const int FLOAT_SUFFIX = 131; - public const int STAR = 118; + public const int STAR = 120; public const int LITERAL_by = 56; public const int CASE = 57; public const int NEW = 37; public const int FILTER_ENTITY = 76; - public const int PARAM = 123; + public const int PARAM = 106; public const int COUNT = 12; public const int NOT = 38; public const int EOF = -1; @@ -178,7 +178,7 @@ public const int QUOTED_String = 124; public const int ESCqs = 128; public const int WEIRD_IDENT = 93; - public const int OPEN_BRACKET = 120; + public const int OPEN_BRACKET = 122; public const int FULL = 23; public const int ORDER_ELEMENT = 85; public const int INSERT = 29; @@ -190,11 +190,11 @@ public const int VERSIONED = 54; public const int SELECT = 45; public const int INTO = 30; - public const int NE = 105; - public const int GE = 110; + public const int NE = 107; + public const int GE = 112; public const int TAKE = 50; public const int ID_LETTER = 127; - public const int CONCAT = 111; + public const int CONCAT = 113; public const int NULL = 39; public const int ELSE = 59; public const int SELECT_FROM = 89; @@ -220,9 +220,9 @@ public const int ALIAS = 72; public const int JAVA_CONSTANT = 100; public const int CONSTANT = 94; - public const int GT = 108; + public const int GT = 110; public const int QUERY = 86; - public const int BNOT = 112; + public const int BNOT = 114; public const int INDEX_OP = 78; public const int NUM_FLOAT = 98; public const int FROM = 22; @@ -232,7 +232,7 @@ public const int CONSTRUCTOR = 73; public const int T__133 = 133; public const int T__134 = 134; - public const int CLOSE_BRACKET = 121; + public const int CLOSE_BRACKET = 123; public const int WHERE = 55; public const int CLASS = 11; public const int MEMBER = 67; @@ -241,7 +241,7 @@ public const int ORDER = 41; public const int MAX = 35; public const int UPDATE = 53; - public const int SQL_NE = 106; + public const int SQL_NE = 108; public const int AND = 6; public const int SUM = 49; public const int ASCENDING = 8; @@ -255,11 +255,11 @@ public const int LEFT = 33; public const int AVG = 9; public const int SOME = 48; - public const int BOR = 113; + public const int BOR = 115; public const int ALL = 4; public const int IDENT = 125; - public const int PLUS = 116; - public const int BXOR = 114; + public const int PLUS = 118; + public const int BXOR = 116; public const int CASE2 = 74; public const int EXISTS = 19; public const int DOT = 15; @@ -276,24 +276,24 @@ public const int SET = 46; public const int HAVING = 25; public const int MIN = 36; - public const int MINUS = 117; + public const int MINUS = 119; public const int IS_NOT_NULL = 79; - public const int BAND = 115; + public const int BAND = 117; public const int ELEMENTS = 17; public const int TRUE = 51; public const int JOIN = 32; public const int UNION = 52; public const int IN_LIST = 77; - public const int COLON = 122; + public const int COLON = 105; public const int OPEN = 103; public const int ANY = 5; public const int CLOSE = 104; public const int WHEN = 61; - public const int DIV = 119; + public const int DIV = 121; public const int DESCENDING = 14; public const int BETWEEN = 10; public const int AGGREGATE = 71; - public const int LE = 109; + public const int LE = 111; // delegates // delegators @@ -2049,11 +2049,11 @@ case NUM_FLOAT: case NUM_LONG: case OPEN: + case COLON: + case PARAM: case BNOT: case PLUS: case MINUS: - case COLON: - case PARAM: case QUOTED_String: case IDENT: { @@ -2206,7 +2206,7 @@ // AST REWRITE - // elements: path, selectedPropertiesList + // elements: selectedPropertiesList, path // token labels: // rule labels: retval // token list labels: @@ -3338,30 +3338,30 @@ { int LA33_1 = input.LA(2); - if ( (LA33_1 == EOF || LA33_1 == AS || LA33_1 == DOT || LA33_1 == FETCH || (LA33_1 >= FULL && LA33_1 <= HAVING) || LA33_1 == INNER || (LA33_1 >= JOIN && LA33_1 <= LEFT) || LA33_1 == ORDER || LA33_1 == RIGHT || LA33_1 == SKIP || LA33_1 == TAKE || LA33_1 == UNION || LA33_1 == WHERE || LA33_1 == COMMA || LA33_1 == CLOSE || LA33_1 == IDENT) ) + if ( (LA33_1 == IN) ) { - alt33 = 1; - } - else if ( (LA33_1 == IN) ) - { - int LA33_5 = input.LA(3); + int LA33_4 = input.LA(3); - if ( (LA33_5 == ELEMENTS) ) + if ( (LA33_4 == ELEMENTS) ) { alt33 = 4; } - else if ( (LA33_5 == CLASS || LA33_5 == IDENT) ) + else if ( (LA33_4 == CLASS || LA33_4 == IDENT) ) { alt33 = 2; } else { - NoViableAltException nvae_d33s5 = - new NoViableAltException("", 33, 5, input); + NoViableAltException nvae_d33s4 = + new NoViableAltException("", 33, 4, input); - throw nvae_d33s5; + throw nvae_d33s4; } } + else if ( (LA33_1 == EOF || LA33_1 == AS || LA33_1 == DOT || LA33_1 == FETCH || (LA33_1 >= FULL && LA33_1 <= HAVING) || LA33_1 == INNER || (LA33_1 >= JOIN && LA33_1 <= LEFT) || LA33_1 == ORDER || LA33_1 == RIGHT || LA33_1 == SKIP || LA33_1 == TAKE || LA33_1 == UNION || LA33_1 == WHERE || LA33_1 == COMMA || LA33_1 == CLOSE || LA33_1 == IDENT) ) + { + alt33 = 1; + } else { NoViableAltException nvae_d33s1 = @@ -3555,7 +3555,7 @@ // AST REWRITE - // elements: propertyFetch, path, asAlias + // elements: propertyFetch, asAlias, path // token labels: // rule labels: retval // token list labels: @@ -4009,7 +4009,7 @@ // AST REWRITE - // elements: path, alias + // elements: alias, path // token labels: // rule labels: retval // token list labels: @@ -4507,7 +4507,7 @@ }; // $ANTLR start "skipClause" - // Hql.g:305:1: skipClause : SKIP NUM_INT ; + // Hql.g:305:1: skipClause : SKIP ( NUM_INT | parameter ) ; public HqlParser.skipClause_return skipClause() // throws RecognitionException [1] { HqlParser.skipClause_return retval = new HqlParser.skipClause_return(); @@ -4517,14 +4517,16 @@ IToken SKIP131 = null; IToken NUM_INT132 = null; + HqlParser.parameter_return parameter133 = default(HqlParser.parameter_return); + IASTNode SKIP131_tree=null; IASTNode NUM_INT132_tree=null; try { - // Hql.g:306:2: ( SKIP NUM_INT ) - // Hql.g:306:4: SKIP NUM_INT + // Hql.g:306:2: ( SKIP ( NUM_INT | parameter ) ) + // Hql.g:306:4: SKIP ( NUM_INT | parameter ) { root_0 = (IASTNode)adaptor.GetNilNode(); @@ -4532,11 +4534,52 @@ SKIP131_tree = (IASTNode)adaptor.Create(SKIP131); root_0 = (IASTNode)adaptor.BecomeRoot(SKIP131_tree, root_0); - NUM_INT132=(IToken)Match(input,NUM_INT,FOLLOW_NUM_INT_in_skipClause1645); - NUM_INT132_tree = (IASTNode)adaptor.Create(NUM_INT132); - adaptor.AddChild(root_0, NUM_INT132_tree); + // Hql.g:306:10: ( NUM_INT | parameter ) + int alt41 = 2; + int LA41_0 = input.LA(1); + if ( (LA41_0 == NUM_INT) ) + { + alt41 = 1; + } + else if ( ((LA41_0 >= COLON && LA41_0 <= PARAM)) ) + { + alt41 = 2; + } + else + { + NoViableAltException nvae_d41s0 = + new NoViableAltException("", 41, 0, input); + throw nvae_d41s0; + } + switch (alt41) + { + case 1 : + // Hql.g:306:11: NUM_INT + { + NUM_INT132=(IToken)Match(input,NUM_INT,FOLLOW_NUM_INT_in_skipClause1646); + NUM_INT132_tree = (IASTNode)adaptor.Create(NUM_INT132); + adaptor.AddChild(root_0, NUM_INT132_tree); + + + } + break; + case 2 : + // Hql.g:306:21: parameter + { + PushFollow(FOLLOW_parameter_in_skipClause1650); + parameter133 = parameter(); + state.followingStackPointer--; + + adaptor.AddChild(root_0, parameter133.Tree); + + } + break; + + } + + } retval.Stop = input.LT(-1); @@ -4570,7 +4613,7 @@ }; // $ANTLR start "takeClause" - // Hql.g:309:1: takeClause : TAKE NUM_INT ; + // Hql.g:309:1: takeClause : TAKE ( NUM_INT | parameter ) ; public HqlParser.takeClause_return takeClause() // throws RecognitionException [1] { HqlParser.takeClause_return retval = new HqlParser.takeClause_return(); @@ -4578,28 +4621,71 @@ IASTNode root_0 = null; - IToken TAKE133 = null; - IToken NUM_INT134 = null; + IToken TAKE134 = null; + IToken NUM_INT135 = null; + HqlParser.parameter_return parameter136 = default(HqlParser.parameter_return); - IASTNode TAKE133_tree=null; - IASTNode NUM_INT134_tree=null; + IASTNode TAKE134_tree=null; + IASTNode NUM_INT135_tree=null; + try { - // Hql.g:310:2: ( TAKE NUM_INT ) - // Hql.g:310:4: TAKE NUM_INT + // Hql.g:310:2: ( TAKE ( NUM_INT | parameter ) ) + // Hql.g:310:4: TAKE ( NUM_INT | parameter ) { root_0 = (IASTNode)adaptor.GetNilNode(); - TAKE133=(IToken)Match(input,TAKE,FOLLOW_TAKE_in_takeClause1656); - TAKE133_tree = (IASTNode)adaptor.Create(TAKE133); - root_0 = (IASTNode)adaptor.BecomeRoot(TAKE133_tree, root_0); + TAKE134=(IToken)Match(input,TAKE,FOLLOW_TAKE_in_takeClause1662); + TAKE134_tree = (IASTNode)adaptor.Create(TAKE134); + root_0 = (IASTNode)adaptor.BecomeRoot(TAKE134_tree, root_0); - NUM_INT134=(IToken)Match(input,NUM_INT,FOLLOW_NUM_INT_in_takeClause1659); - NUM_INT134_tree = (IASTNode)adaptor.Create(NUM_INT134); - adaptor.AddChild(root_0, NUM_INT134_tree); + // Hql.g:310:10: ( NUM_INT | parameter ) + int alt42 = 2; + int LA42_0 = input.LA(1); + if ( (LA42_0 == NUM_INT) ) + { + alt42 = 1; + } + else if ( ((LA42_0 >= COLON && LA42_0 <= PARAM)) ) + { + alt42 = 2; + } + else + { + NoViableAltException nvae_d42s0 = + new NoViableAltException("", 42, 0, input); + throw nvae_d42s0; + } + switch (alt42) + { + case 1 : + // Hql.g:310:11: NUM_INT + { + NUM_INT135=(IToken)Match(input,NUM_INT,FOLLOW_NUM_INT_in_takeClause1666); + NUM_INT135_tree = (IASTNode)adaptor.Create(NUM_INT135); + adaptor.AddChild(root_0, NUM_INT135_tree); + + + } + break; + case 2 : + // Hql.g:310:21: parameter + { + PushFollow(FOLLOW_parameter_in_takeClause1670); + parameter136 = parameter(); + state.followingStackPointer--; + + adaptor.AddChild(root_0, parameter136.Tree); + + } + break; + + } + + } retval.Stop = input.LT(-1); @@ -4622,6 +4708,132 @@ } // $ANTLR end "takeClause" + public class parameter_return : ParserRuleReturnScope + { + private IASTNode tree; + override public object Tree + { + get { return tree; } + set { tree = (IASTNode) value; } + } + }; + + // $ANTLR start "parameter" + // Hql.g:313:1: parameter : ( COLON identifier | PARAM ( NUM_INT )? ); + public HqlParser.parameter_return parameter() // throws RecognitionException [1] + { + HqlParser.parameter_return retval = new HqlParser.parameter_return(); + retval.Start = input.LT(1); + + IASTNode root_0 = null; + + IToken COLON137 = null; + IToken PARAM139 = null; + IToken NUM_INT140 = null; + HqlParser.identifier_return identifier138 = default(HqlParser.identifier_return); + + + IASTNode COLON137_tree=null; + IASTNode PARAM139_tree=null; + IASTNode NUM_INT140_tree=null; + + try + { + // Hql.g:314:2: ( COLON identifier | PARAM ( NUM_INT )? ) + int alt44 = 2; + int LA44_0 = input.LA(1); + + if ( (LA44_0 == COLON) ) + { + alt44 = 1; + } + else if ( (LA44_0 == PARAM) ) + { + alt44 = 2; + } + else + { + NoViableAltException nvae_d44s0 = + new NoViableAltException("", 44, 0, input); + + throw nvae_d44s0; + } + switch (alt44) + { + case 1 : + // Hql.g:314:4: COLON identifier + { + root_0 = (IASTNode)adaptor.GetNilNode(); + + COLON137=(IToken)Match(input,COLON,FOLLOW_COLON_in_parameter1682); + COLON137_tree = (IASTNode)adaptor.Create(COLON137); + root_0 = (IASTNode)adaptor.BecomeRoot(COLON137_tree, root_0); + + PushFollow(FOLLOW_identifier_in_parameter1685); + identifier138 = identifier(); + state.followingStackPointer--; + + adaptor.AddChild(root_0, identifier138.Tree); + + } + break; + case 2 : + // Hql.g:315:4: PARAM ( NUM_INT )? + { + root_0 = (IASTNode)adaptor.GetNilNode(); + + PARAM139=(IToken)Match(input,PARAM,FOLLOW_PARAM_in_parameter1690); + PARAM139_tree = (IASTNode)adaptor.Create(PARAM139); + root_0 = (IASTNode)adaptor.BecomeRoot(PARAM139_tree, root_0); + + // Hql.g:315:11: ( NUM_INT )? + int alt43 = 2; + int LA43_0 = input.LA(1); + + if ( (LA43_0 == NUM_INT) ) + { + alt43 = 1; + } + switch (alt43) + { + case 1 : + // Hql.g:315:12: NUM_INT + { + NUM_INT140=(IToken)Match(input,NUM_INT,FOLLOW_NUM_INT_in_parameter1694); + NUM_INT140_tree = (IASTNode)adaptor.Create(NUM_INT140); + adaptor.AddChild(root_0, NUM_INT140_tree); + + + } + break; + + } + + + } + break; + + } + retval.Stop = input.LT(-1); + + retval.Tree = (IASTNode)adaptor.RulePostProcessing(root_0); + adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop); + } + catch (RecognitionException re) + { + ReportError(re); + Recover(input,re); + // Conversion of the second argument necessary, but harmless + retval.Tree = (IASTNode)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re); + + } + finally + { + } + return retval; + } + // $ANTLR end "parameter" + public class orderElement_return : ParserRuleReturnScope { private IASTNode tree; @@ -4633,7 +4845,7 @@ }; // $ANTLR start "orderElement" - // Hql.g:313:1: orderElement : expression ( ascendingOrDescending )? ; + // Hql.g:318:1: orderElement : expression ( ascendingOrDescending )? ; public HqlParser.orderElement_return orderElement() // throws RecognitionException [1] { HqlParser.orderElement_return retval = new HqlParser.orderElement_return(); @@ -4641,42 +4853,42 @@ IASTNode root_0 = null; - HqlParser.expression_return expression135 = default(HqlParser.expression_return); + HqlParser.expression_return expression141 = default(HqlParser.expression_return); - HqlParser.ascendingOrDescending_return ascendingOrDescending136 = default(HqlParser.ascendingOrDescending_return); + HqlParser.ascendingOrDescending_return ascendingOrDescending142 = default(HqlParser.ascendingOrDescending_return); try { - // Hql.g:314:2: ( expression ( ascendingOrDescending )? ) - // Hql.g:314:4: expression ( ascendingOrDescending )? + // Hql.g:319:2: ( expression ( ascendingOrDescending )? ) + // Hql.g:319:4: expression ( ascendingOrDescending )? { root_0 = (IASTNode)adaptor.GetNilNode(); - PushFollow(FOLLOW_expression_in_orderElement1670); - expression135 = expression(); + PushFollow(FOLLOW_expression_in_orderElement1707); + expression141 = expression(); state.followingStackPointer--; - adaptor.AddChild(root_0, expression135.Tree); - // Hql.g:314:15: ( ascendingOrDescending )? - int alt41 = 2; - int LA41_0 = input.LA(1); + adaptor.AddChild(root_0, expression141.Tree); + // Hql.g:319:15: ( ascendingOrDescending )? + int alt45 = 2; + int LA45_0 = input.LA(1); - if ( (LA41_0 == ASCENDING || LA41_0 == DESCENDING || (LA41_0 >= 133 && LA41_0 <= 134)) ) + if ( (LA45_0 == ASCENDING || LA45_0 == DESCENDING || (LA45_0 >= 133 && LA45_0 <= 134)) ) { - alt41 = 1; + alt45 = 1; } - switch (alt41) + switch (alt45) { case 1 : - // Hql.g:314:17: ascendingOrDescending + // Hql.g:319:17: ascendingOrDescending { - PushFollow(FOLLOW_ascendingOrDescending_in_orderElement1674); - ascendingOrDescending136 = ascendingOrDescending(); + PushFollow(FOLLOW_ascendingOrDescending_in_orderElement1711); + ascendingOrDescending142 = ascendingOrDescending(); state.followingStackPointer--; - adaptor.AddChild(root_0, ascendingOrDescending136.Tree); + adaptor.AddChild(root_0, ascendingOrDescending142.Tree); } break; @@ -4717,7 +4929,7 @@ }; // $ANTLR start "ascendingOrDescending" - // Hql.g:317:1: ascendingOrDescending : ( (a= 'asc' | a= 'ascending' ) -> ^( ASCENDING[$a.Text] ) | (d= 'desc' | d= 'descending' ) -> ^( DESCENDING[$d.Text] ) ); + // Hql.g:322:1: ascendingOrDescending : ( (a= 'asc' | a= 'ascending' ) -> ^( ASCENDING[$a.Text] ) | (d= 'desc' | d= 'descending' ) -> ^( DESCENDING[$d.Text] ) ); public HqlParser.ascendingOrDescending_return ascendingOrDescending() // throws RecognitionException [1] { HqlParser.ascendingOrDescending_return retval = new HqlParser.ascendingOrDescending_return(); @@ -4737,64 +4949,64 @@ try { - // Hql.g:318:2: ( (a= 'asc' | a= 'ascending' ) -> ^( ASCENDING[$a.Text] ) | (d= 'desc' | d= 'descending' ) -> ^( DESCENDING[$d.Text] ) ) - int alt44 = 2; - int LA44_0 = input.LA(1); + // Hql.g:323:2: ( (a= 'asc' | a= 'ascending' ) -> ^( ASCENDING[$a.Text] ) | (d= 'desc' | d= 'descending' ) -> ^( DESCENDING[$d.Text] ) ) + int alt48 = 2; + int LA48_0 = input.LA(1); - if ( (LA44_0 == ASCENDING || LA44_0 == 133) ) + ... [truncated message content] |
From: <fab...@us...> - 2011-05-20 16:48:35
|
Revision: 5848 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5848&view=rev Author: fabiomaulo Date: 2011-05-20 16:48:28 +0000 (Fri, 20 May 2011) Log Message: ----------- Test for not fixed issue NH-2366 Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Model.cs Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Fixture.cs 2011-05-20 16:48:28 UTC (rev 5848) @@ -0,0 +1,54 @@ +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2366 +{ + [Ignore("Not fixed yet.")] + public class Fixture : BugTestCase + { + protected override void OnSetUp() + { + base.OnSetUp(); + + using (ISession session = OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + // Note: non-unique values for Value property + session.Save(new Two() { Id = 1, Value = "a" }); + session.Save(new Two() { Id = 2, Value = "b" }); + session.Save(new Two() { Id = 3, Value = "a" }); + transaction.Commit(); + } + using (ISession session = OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + session.Save(new One() { Id = 1, Value = "a" }); + session.Save(new One() { Id = 2, Value = "a" }); + transaction.Commit(); + } + } + + protected override void OnTearDown() + { + using (ISession session = OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + session.Delete("from One"); + session.Delete("from Two"); + + transaction.Commit(); + } + + base.OnTearDown(); + } + + [Test] + public void Test() + { + using (ISession session = OpenSession()) + { + session.Executing(s=> s.CreateQuery("from One").List()).NotThrows(); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Mappings.hbm.xml 2011-05-20 16:48:28 UTC (rev 5848) @@ -0,0 +1,31 @@ +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2366"> + + <class name="One" table="one"> + + <id name="Id" column="o_id_pk"> + <generator class="assigned" /> + </id> + + <property name="Value" column="o_val" /> + + <set name="Twos" lazy="false"> + <key column="t_val" property-ref="Value" not-null="false" /> + <one-to-many class="Two" /> + </set> + + </class> + + <class name="Two" table="two"> + + <id name="Id" column="t_id_pk"> + <generator class="assigned" /> + </id> + + <property name="Value" column="t_val" /> + + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2366/Model.cs 2011-05-20 16:48:28 UTC (rev 5848) @@ -0,0 +1,56 @@ +using System; +using Iesi.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH2366 +{ + public class One + { + private int id; + private string value; + private ISet<Two> twos = new HashedSet<Two>(); + + public virtual int Id + { + get { return id; } + set { id = value; } + } + + public virtual string Value + { + get { return value; } + set { this.value = value; } + } + + public virtual ISet<Two> Twos + { + get { return twos; } + set { twos = value; } + } + + public One() + { + } + } + + public class Two + { + private int id; + private string value; + + public virtual int Id + { + get { return id; } + set { id = value; } + } + + public virtual string Value + { + get { return value; } + set { this.value = value; } + } + + public Two() + { + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-20 16:10:15 UTC (rev 5847) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-20 16:48:28 UTC (rev 5848) @@ -743,6 +743,8 @@ <Compile Include="NHSpecificTest\NH2362\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2362\Product.cs" /> <Compile Include="NHSpecificTest\NH2362\Supplier.cs" /> + <Compile Include="NHSpecificTest\NH2366\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2366\Model.cs" /> <Compile Include="NHSpecificTest\NH2374\NH2374Fixture.cs" /> <Compile Include="NHSpecificTest\NH2378\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2378\TestEntity.cs" /> @@ -2684,6 +2686,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2366\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2404\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2705\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2546\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-20 16:10:23
|
Revision: 5847 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5847&view=rev Author: fabiomaulo Date: 2011-05-20 16:10:15 +0000 (Fri, 20 May 2011) Log Message: ----------- Another issue (NH-2206) already fixed fixing Cast{T} stuff Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/Linq/WhereTests.cs Modified: trunk/nhibernate/src/NHibernate.Test/Linq/WhereTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/WhereTests.cs 2011-05-20 15:36:29 UTC (rev 5846) +++ trunk/nhibernate/src/NHibernate.Test/Linq/WhereTests.cs 2011-05-20 16:10:15 UTC (rev 5847) @@ -477,7 +477,7 @@ Assert.AreEqual(2, query.Count); } - [Test(Description = "Reported as bug NH-2206"), Ignore("Not fixed yet")] + [Test(Description = "Reported as bug NH-2206")] public void SearchOnObjectTypeCast() { var query = (from Dog o in session.Query<Dog>() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-20 15:36:36
|
Revision: 5846 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5846&view=rev Author: fabiomaulo Date: 2011-05-20 15:36:29 +0000 (Fri, 20 May 2011) Log Message: ----------- Not failing test for NH-2657 Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs Modified: trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs 2011-05-20 15:09:45 UTC (rev 5845) +++ trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs 2011-05-20 15:36:29 UTC (rev 5846) @@ -34,6 +34,14 @@ query.Executing(q=> q.ToList()).Throws(); } + [Test] + public void OrderByAfterCast() + { + // NH-2657 + var query = session.Query<Dog>().Cast<Animal>().OrderBy(a=> a.BodyWeight); + query.Executing(q => q.ToList()).NotThrows(); + } + [Test, Ignore("Not fixed yet. The method OfType does not work as expected.")] public void CastDowncastUsingOfType() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-20 15:09:51
|
Revision: 5845 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5845&view=rev Author: fabiomaulo Date: 2011-05-20 15:09:45 +0000 (Fri, 20 May 2011) Log Message: ----------- Relax Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Event/Default/AbstractFlushingEventListener.cs Modified: trunk/nhibernate/src/NHibernate/Event/Default/AbstractFlushingEventListener.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Event/Default/AbstractFlushingEventListener.cs 2011-05-20 15:08:10 UTC (rev 5844) +++ trunk/nhibernate/src/NHibernate/Event/Default/AbstractFlushingEventListener.cs 2011-05-20 15:09:45 UTC (rev 5845) @@ -84,7 +84,7 @@ } } - private void FlushCollections(IEventSource session) + protected virtual void FlushCollections(IEventSource session) { log.Debug("Processing unreferenced collections"); @@ -133,7 +133,7 @@ // 1. detect any dirty entities // 2. schedule any entity updates // 3. search out any reachable collections - private void FlushEntities(FlushEvent @event) + protected virtual void FlushEntities(FlushEvent @event) { log.Debug("Flushing entities and processing referenced collections"); @@ -166,7 +166,7 @@ } // Initialize the flags of the CollectionEntry, including the dirty check. - private void PrepareCollectionFlushes(ISessionImplementor session) + protected virtual void PrepareCollectionFlushes(ISessionImplementor session) { // Initialize dirty flags for arrays + collections with composite elements // and reset reached, doupdate, etc. @@ -182,7 +182,7 @@ //process cascade save/update at the start of a flush to discover //any newly referenced entity that must be passed to saveOrUpdate(), //and also apply orphan delete - private void PrepareEntityFlushes(IEventSource session) + protected virtual void PrepareEntityFlushes(IEventSource session) { log.Debug("processing flush-time cascades"); @@ -199,7 +199,7 @@ } } - private void CascadeOnFlush(IEventSource session, IEntityPersister persister, object key, object anything) + protected virtual void CascadeOnFlush(IEventSource session, IEntityPersister persister, object key, object anything) { session.PersistenceContext.IncrementCascadeLevel(); try This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-20 15:08:17
|
Revision: 5844 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5844&view=rev Author: fabiomaulo Date: 2011-05-20 15:08:10 +0000 (Fri, 20 May 2011) Log Message: ----------- Minor refactoring Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs Modified: trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs 2011-05-20 15:00:09 UTC (rev 5843) +++ trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs 2011-05-20 15:08:10 UTC (rev 5844) @@ -45,7 +45,7 @@ } else { - toTransform = collection.Cast<object>().ToList(); + toTransform = collection.Cast<object>(); } object transformResult = _listTransformation.DynamicInvoke(toTransform); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-20 15:00:17
|
Revision: 5843 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5843&view=rev Author: fabiomaulo Date: 2011-05-20 15:00:09 +0000 (Fri, 20 May 2011) Log Message: ----------- Fix NH-2701 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/LinqFutureFixture.cs Modified: trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs 2011-05-20 14:31:58 UTC (rev 5842) +++ trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs 2011-05-20 15:00:09 UTC (rev 5843) @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Linq; using NHibernate.Transform; @@ -31,30 +32,25 @@ return collection; } - object transformResult = collection; - + IEnumerable<object> toTransform; if (collection.Count > 0 && collection[0] is object[]) { - if (((object[]) collection[0]).Length != 1) + if (((object[])collection[0]).Length != 1) { // We only expect single items throw new NotSupportedException(); } - transformResult = _listTransformation.DynamicInvoke(collection.Cast<object[]>().Select(o => o[0])); + toTransform = collection.Cast<object[]>().Select(o => o[0]); } else { - transformResult = _listTransformation.DynamicInvoke(collection); + toTransform = collection.Cast<object>().ToList(); } + object transformResult = _listTransformation.DynamicInvoke(toTransform); - if (transformResult is IList) - { - return (IList) transformResult; - } - - var list = new ArrayList {transformResult}; - return list; + var resultList = transformResult as IList; + return resultList ?? new List<object> { transformResult }; } #endregion Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/LinqFutureFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/LinqFutureFixture.cs 2011-05-20 14:31:58 UTC (rev 5842) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/LinqFutureFixture.cs 2011-05-20 15:00:09 UTC (rev 5843) @@ -42,7 +42,56 @@ tx.Commit(); } } - [Test] + + [Test] + public void CanUseSkipAndFetchManyWithToFuture() + { + using (var s = sessions.OpenSession()) + using (var tx = s.BeginTransaction()) + { + var p1 = new Person {Name = "Parent"}; + var p2 = new Person {Parent = p1, Name = "Child"}; + p1.Children.Add(p2); + s.Save(p1); + s.Save(p2); + tx.Commit(); + + s.Clear(); // we don't want caching + } + + using (var s = sessions.OpenSession()) + { + IgnoreThisTestIfMultipleQueriesArentSupportedByDriver(); + + var persons10 = s.Query<Person>() + .FetchMany(p => p.Children) + .Skip(5) + .Take(10) + .ToFuture(); + + var persons5 = s.Query<Person>() + .ToFuture(); + + using (var logSpy = new SqlLogSpy()) + { + foreach (var person in persons5) {} + + foreach (var person in persons10) {} + + var events = logSpy.Appender.GetEvents(); + Assert.AreEqual(1, events.Length); + } + } + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Delete("from Person"); + tx.Commit(); + } + } + + [Test] public void CanUseFutureQuery() { using (var s = sessions.OpenSession()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-20 14:32:04
|
Revision: 5842 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5842&view=rev Author: fabiomaulo Date: 2011-05-20 14:31:58 +0000 (Fri, 20 May 2011) Log Message: ----------- Minor (reformatted) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs Modified: trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs 2011-05-20 13:58:52 UTC (rev 5841) +++ trunk/nhibernate/src/NHibernate/Linq/ResultTransformer.cs 2011-05-20 14:31:58 UTC (rev 5842) @@ -5,85 +5,86 @@ namespace NHibernate.Linq { - [Serializable] - public class ResultTransformer : IResultTransformer - { - private readonly Delegate _listTransformation; - private readonly Delegate _itemTransformation; + [Serializable] + public class ResultTransformer : IResultTransformer + { + private readonly Delegate _itemTransformation; + private readonly Delegate _listTransformation; - public ResultTransformer(Delegate itemTransformation, Delegate listTransformation) - { - _itemTransformation = itemTransformation; - _listTransformation = listTransformation; - } + public ResultTransformer(Delegate itemTransformation, Delegate listTransformation) + { + _itemTransformation = itemTransformation; + _listTransformation = listTransformation; + } - public object TransformTuple(object[] tuple, string[] aliases) - { - return _itemTransformation == null ? tuple : _itemTransformation.DynamicInvoke(new object[] { tuple } ); - } + #region IResultTransformer Members - public IList TransformList(IList collection) - { - if (_listTransformation == null) - { - return collection; - } + public object TransformTuple(object[] tuple, string[] aliases) + { + return _itemTransformation == null ? tuple : _itemTransformation.DynamicInvoke(new object[] {tuple}); + } - object transformResult = collection; + public IList TransformList(IList collection) + { + if (_listTransformation == null) + { + return collection; + } - //if (collection.Count > 0) - { - if (collection.Count > 0 && collection[0] is object[]) - { - if ( ((object[])collection[0]).Length != 1) - { - // We only expect single items - throw new NotSupportedException(); - } + object transformResult = collection; - transformResult = _listTransformation.DynamicInvoke(collection.Cast<object[]>().Select(o => o[0])); - } - else - { - transformResult = _listTransformation.DynamicInvoke(collection); - } - } + if (collection.Count > 0 && collection[0] is object[]) + { + if (((object[]) collection[0]).Length != 1) + { + // We only expect single items + throw new NotSupportedException(); + } - if (transformResult is IList) - { - return (IList) transformResult; - } + transformResult = _listTransformation.DynamicInvoke(collection.Cast<object[]>().Select(o => o[0])); + } + else + { + transformResult = _listTransformation.DynamicInvoke(collection); + } - var list = new ArrayList {transformResult}; - return list; - } + if (transformResult is IList) + { + return (IList) transformResult; + } - public bool Equals(ResultTransformer other) - { - if (ReferenceEquals(null, other)) - { - return false; - } - if (ReferenceEquals(this, other)) - { - return true; - } - return Equals(other._listTransformation, _listTransformation) && Equals(other._itemTransformation, _itemTransformation); - } + var list = new ArrayList {transformResult}; + return list; + } - public override bool Equals(object obj) - { - return Equals(obj as ResultTransformer); - } + #endregion - public override int GetHashCode() - { - unchecked - { - var lt = (_listTransformation != null ? _listTransformation.GetHashCode() : 0); - var it = (_itemTransformation != null ? _itemTransformation.GetHashCode() : 0); - return (lt * 397) ^ (it * 17); - } - } - } + public bool Equals(ResultTransformer other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + if (ReferenceEquals(this, other)) + { + return true; + } + return Equals(other._listTransformation, _listTransformation) && Equals(other._itemTransformation, _itemTransformation); + } + + public override bool Equals(object obj) + { + return Equals(obj as ResultTransformer); + } + + public override int GetHashCode() + { + unchecked + { + int lt = (_listTransformation != null ? _listTransformation.GetHashCode() : 0); + int it = (_itemTransformation != null ? _itemTransformation.GetHashCode() : 0); + return (lt*397) ^ (it*17); + } + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-20 13:58:59
|
Revision: 5841 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5841&view=rev Author: fabiomaulo Date: 2011-05-20 13:58:52 +0000 (Fri, 20 May 2011) Log Message: ----------- Fix NH-2717 and NH-2708 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs trunk/nhibernate/src/NHibernate/Linq/ReWriters/ResultOperatorRewriter.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs Modified: trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs 2011-05-18 18:47:08 UTC (rev 5840) +++ trunk/nhibernate/src/NHibernate/Linq/ReWriters/RemoveUnnecessaryBodyOperators.cs 2011-05-20 13:58:52 UTC (rev 5841) @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Remotion.Linq; using Remotion.Linq.Clauses; using Remotion.Linq.Clauses.ResultOperators; @@ -26,6 +27,10 @@ queryModel.BodyClauses.Remove(orderby); } } + if (resultOperator is CastResultOperator) + { + Array.ForEach(queryModel.ResultOperators.OfType<CastResultOperator>().ToArray(), castOperator=> queryModel.ResultOperators.Remove(castOperator)); + } base.VisitResultOperator(resultOperator, queryModel, index); } Modified: trunk/nhibernate/src/NHibernate/Linq/ReWriters/ResultOperatorRewriter.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/ReWriters/ResultOperatorRewriter.cs 2011-05-18 18:47:08 UTC (rev 5840) +++ trunk/nhibernate/src/NHibernate/Linq/ReWriters/ResultOperatorRewriter.cs 2011-05-20 13:58:52 UTC (rev 5841) @@ -64,6 +64,7 @@ typeof(FetchRequestBase), typeof(OfTypeResultOperator), typeof(CacheableResultOperator), + typeof(CastResultOperator), // see ProcessCast class }; private readonly List<ResultOperatorBase> resultOperators = new List<ResultOperatorBase>(); Added: trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/CastTests.cs 2011-05-20 13:58:52 UTC (rev 5841) @@ -0,0 +1,45 @@ +using System.Linq; +using NHibernate.DomainModel.Northwind.Entities; +using NHibernate.Linq; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.Linq.ByMethod +{ + public class CastTests : LinqTestCase + { + [Test] + public void CastCount() + { + session.Query<Cat>() + .Cast<Animal>() + .Count().Should().Be(1); + } + + [Test] + public void CastWithWhere() + { + var pregnatMammal = (from a + in session.Query<Animal>().Cast<Cat>() + where a.Pregnant + select a).FirstOrDefault(); + pregnatMammal.Should().Not.Be.Null(); + } + + [Test] + public void CastDowncast() + { + var query = session.Query<Mammal>().Cast<Dog>(); + // the list contains at least one Cat then should Throws + query.Executing(q=> q.ToList()).Throws(); + } + + [Test, Ignore("Not fixed yet. The method OfType does not work as expected.")] + public void CastDowncastUsingOfType() + { + var query = session.Query<Animal>().OfType<Mammal>().Cast<Dog>(); + // the list contains at least one Cat then should Throws + query.Executing(q => q.ToList()).Throws(); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-18 18:47:08 UTC (rev 5840) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-20 13:58:52 UTC (rev 5841) @@ -481,6 +481,7 @@ <Compile Include="Linq\BinaryBooleanExpressionTests.cs" /> <Compile Include="Linq\BinaryExpressionOrdererTests.cs" /> <Compile Include="Linq\BooleanMethodExtensionExample.cs" /> + <Compile Include="Linq\ByMethod\CastTests.cs" /> <Compile Include="Linq\ByMethod\GroupByTests.cs" /> <Compile Include="Linq\CasingTest.cs" /> <Compile Include="Linq\CollectionAssert.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-18 18:47:14
|
Revision: 5840 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5840&view=rev Author: fabiomaulo Date: 2011-05-18 18:47:08 +0000 (Wed, 18 May 2011) Log Message: ----------- Actualization of current trunk version Modified Paths: -------------- trunk/nhibernate/build-common/common.xml Modified: trunk/nhibernate/build-common/common.xml =================================================================== --- trunk/nhibernate/build-common/common.xml 2011-05-18 18:08:18 UTC (rev 5839) +++ trunk/nhibernate/build-common/common.xml 2011-05-18 18:47:08 UTC (rev 5840) @@ -84,7 +84,7 @@ effectively SP0). --> - <property name="project.version" value="3.2.0.Beta1" overwrite="false" /> + <property name="project.version" value="3.2.0.CR1" overwrite="false" /> <!-- Compute short project version (major.minor) using a regex --> <regex input="${project.version}" pattern="^(?'shortversion'\d+\.\d+)" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-18 18:08:24
|
Revision: 5839 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5839&view=rev Author: fabiomaulo Date: 2011-05-18 18:08:18 +0000 (Wed, 18 May 2011) Log Message: ----------- Preparing release Modified Paths: -------------- trunk/nhibernate/build-common/common.xml trunk/nhibernate/releasenotes.txt Modified: trunk/nhibernate/build-common/common.xml =================================================================== --- trunk/nhibernate/build-common/common.xml 2011-05-18 17:51:09 UTC (rev 5838) +++ trunk/nhibernate/build-common/common.xml 2011-05-18 18:08:18 UTC (rev 5839) @@ -84,7 +84,7 @@ effectively SP0). --> - <property name="project.version" value="3.2.0.Alpha3" overwrite="false" /> + <property name="project.version" value="3.2.0.Beta1" overwrite="false" /> <!-- Compute short project version (major.minor) using a regex --> <regex input="${project.version}" pattern="^(?'shortversion'\d+\.\d+)" /> Modified: trunk/nhibernate/releasenotes.txt =================================================================== --- trunk/nhibernate/releasenotes.txt 2011-05-18 17:51:09 UTC (rev 5838) +++ trunk/nhibernate/releasenotes.txt 2011-05-18 18:08:18 UTC (rev 5839) @@ -10,6 +10,26 @@ * For users who don't look at Log-ERROR, to prevent wrong behavior when lazy-properties are used the DynamicProxyValidator validates the accessability of properties setters. * For those implementing IDrive without inherit from DriveBase: IDrive.AdjustCommand +Build 3.2.0.Beta1 (rev5839) +============================= +** Bug + * [NH-2404] - Future queries crash (MultiQuery) when using projection queries using hql + result transformer or the linq provider (which compiles into hql) + * [NH-2421] - NotSupportedException text in ToFuture and ToFutureValue does not make sense (or help) + * [NH-2422] - ToFuture throws NotSupportedException on IQueryable if Fetch is used. + * [NH-2559] - NH 3.0 Linq Provider : Issue using multiple filters on the same entity + * [NH-2615] - Linq Fetch cannot traverse through components + * [NH-2690] - Linq Select() broken with .ToFuture() + * [NH-2691] - Linq LongCount() behavior different from Count() + * [NH-2697] - Named parameter not found in HQL with mapping using "entity-name" + * [NH-2698] - Proxying fails for methods with generic type constraints + +** Improvement + * [NH-2568] - Create Custom Persister for Collection Type inherited from OneToManyPersister + * [NH-2695] - update default driver of firebird dialect to FirebirdClientDriver (FirebirdDriver is obsolete) + +** New Feature + * [NH-2699] - Sql Azure dialect + Build 3.2.0.Aplha3 (rev5803) ============================= ** Sub-task @@ -514,6 +534,19 @@ * [NH-2013] - HQL breaking change * [NH-2247] - Update FlushMode Documentation +Build 2.1.2.GA (rev4854) +============================= +** Bug + * [NH-2011] - Many-to-many inside a component will not be saved when using SaveOrUpdateCopy or Merge + * [NH-2283] - CLONE -one-to-many collection with table per subclass, using discriminator: wrong proxies in collection + +** Improvement + * [NH-2022] - Allow overriding in Query By Example + +** Patch + * [NH-2007] - SesssionIdLoggingContext patch for big resultsets + * [NH-2019] - Clarification about the use of <import> for polymorphic queries + Build 2.1.1.GA (rev4814) ============================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-18 17:51:16
|
Revision: 5838 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5838&view=rev Author: fabiomaulo Date: 2011-05-18 17:51:09 +0000 (Wed, 18 May 2011) Log Message: ----------- Fixed issue reported in dev-list regarding r5793 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2673/CachingWithTrasformerTests.cs Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-05-17 23:07:11 UTC (rev 5837) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaLoader.cs 2011-05-18 17:51:09 UTC (rev 5838) @@ -75,7 +75,7 @@ return List(session, translator.GetQueryParameters(), querySpaces, resultTypes); } - protected override object GetResultColumnOrRow(object[] row, IResultTransformer resultTransformer, IDataReader rs, + protected override object GetResultColumnOrRow(object[] row, IResultTransformer customResultTransformer, IDataReader rs, ISessionImplementor session) { object[] result; @@ -107,9 +107,10 @@ result = row; } - if (resultTransformer == null && result.Length == 1) + if (customResultTransformer == null) { - return result[0]; + // apply the defaut transformer of criteria aka RootEntityResultTransformer + return result[result.Length - 1]; } return result; } @@ -164,20 +165,20 @@ return lockModesArray; } - public override IList GetResultList(IList results, IResultTransformer resultTransformer) + public override IList GetResultList(IList results, IResultTransformer customResultTransformer) { - var transformer = resultTransformer ?? CriteriaSpecification.RootEntity; + if (customResultTransformer == null) + { + // apply the defaut transformer of criteria aka RootEntityResultTransformer + return results; + } for (int i = 0; i < results.Count; i++) { - var row = results[i] as object[]; - if(row == null) - { - row = new object[] { results[i] }; - } - object result = transformer.TransformTuple(row, translator.HasProjection ? translator.ProjectedAliases : userAliases); + var row = results[i] as object[] ?? new object[] { results[i] }; + object result = customResultTransformer.TransformTuple(row, translator.HasProjection ? translator.ProjectedAliases : userAliases); results[i] = result; } - return transformer.TransformList(results); + return customResultTransformer.TransformList(results); } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2673/CachingWithTrasformerTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2673/CachingWithTrasformerTests.cs 2011-05-17 23:07:11 UTC (rev 5837) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2673/CachingWithTrasformerTests.cs 2011-05-18 17:51:09 UTC (rev 5838) @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Linq; using NHibernate.Cache; using NHibernate.Cfg; using NHibernate.Cfg.MappingSchema; @@ -153,5 +154,57 @@ } } } + + [Test] + public void WhenEagerLoadingWithCriteriaThenNotThrows() + { + // reported in dev-list instead on JIRA + using (new Scenario(Sfi)) + { + using (var session = OpenSession()) + using (var tx = session.BeginTransaction()) + { + var query = session.CreateCriteria<Blog>() + .SetFetchMode("Posts", FetchMode.Eager) + .SetCacheable(true); + query.Executing(q => q.List<Blog>()).NotThrows(); + tx.Commit(); + } + } + } + + [Test] + public void WhenEagerLoadingWithMultiCriteriaThenNotThrows() + { + using (new Scenario(Sfi)) + { + using (var session = OpenSession()) + using (var tx = session.BeginTransaction()) + { + var query = session.CreateCriteria<Blog>() + .SetFetchMode("Posts", FetchMode.Eager) + .SetCacheable(true); + query.Executing(q => q.Future<Blog>().ToList()).NotThrows(); + tx.Commit(); + } + } + } + + [Test] + public void WhenEagerLoadingWithHqlThenNotThrows() + { + using (new Scenario(Sfi)) + { + using (var session = OpenSession()) + using (var tx = session.BeginTransaction()) + { + var query = session.CreateQuery("select b from Blog b join fetch b.Posts where b.Author = : author") + .SetString("author", "Gabriel") + .SetCacheable(true); + query.Executing(q => q.List<Blog>()).NotThrows(); + tx.Commit(); + } + } + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-17 23:07:18
|
Revision: 5837 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5837&view=rev Author: fabiomaulo Date: 2011-05-17 23:07:11 +0000 (Tue, 17 May 2011) Log Message: ----------- No failing test for NH-1845 Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Category.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Fixture.cs Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Category.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Category.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Category.cs 2011-05-17 23:07:11 UTC (rev 5837) @@ -0,0 +1,53 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH1845 +{ + public class Category + { + private readonly IList<Category> subcategories = new List<Category>(); + + public Category() : this("") {} + + public Category(string name) + { + Name = name; + } + + public virtual int Id { get; set; } + + public virtual string Name { get; set; } + + public virtual Category Parent { get; set; } + + public virtual IList<Category> Subcategories + { + get { return subcategories; } + } + + public virtual void AddSubcategory(Category subcategory) + { + subcategories.Add(subcategory); + subcategory.Parent = this; + } + + public override string ToString() + { + return Name; + } + + public override bool Equals(object obj) + { + var other = obj as Category; + if (other == null) + { + return false; + } + return other.Name == Name; + } + + public override int GetHashCode() + { + return Name.GetHashCode(); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1845/Fixture.cs 2011-05-17 23:07:11 UTC (rev 5837) @@ -0,0 +1,62 @@ +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; +namespace NHibernate.Test.NHSpecificTest.NH1845 +{ + public class Fixture: TestCaseMappingByCode + { + + protected override HbmMapping GetMappings() + { + var mapper = new ModelMapper(); + mapper.Class<Category>(rc => + { + rc.Id(x=> x.Id, map=> map.Generator(Generators.Native)); + rc.Property(x=> x.Name); + rc.ManyToOne(x=> x.Parent, map=> map.Column("ParentId")); + rc.Bag(x => x.Subcategories, map => + { + map.Access(Accessor.NoSetter); + map.Key(km=> km.Column("ParentId")); + map.Cascade(Mapping.ByCode.Cascade.All.Include(Mapping.ByCode.Cascade.DeleteOrphans)); + }, rel => rel.OneToMany()); + }); + var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + return mappings; + } + + [Test] + public void LazyLoad_Initialize_AndEvict() + { + Category category = new Category("parent"); + category.AddSubcategory(new Category("child")); + SaveCategory(category); + + using (ISession session = OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + Category loaded = session.Load<Category>(category.Id); + NHibernateUtil.Initialize(loaded.Subcategories[0]); + session.Evict(loaded); + transaction.Commit(); + Assert.AreEqual("child", loaded.Subcategories[0].Name, "cannot access child"); + } + using (ISession session = OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + session.CreateQuery("delete from Category").ExecuteUpdate(); + transaction.Commit(); + } + } + + private void SaveCategory(Category category) + { + using (ISession session = OpenSession()) + using (ITransaction transaction = session.BeginTransaction()) + { + session.SaveOrUpdate(category); + transaction.Commit(); + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-17 22:33:17 UTC (rev 5836) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-17 23:07:11 UTC (rev 5837) @@ -657,6 +657,8 @@ <Compile Include="NHSpecificTest\NH1836\Entity.cs" /> <Compile Include="NHSpecificTest\NH1836\EntityDTO.cs" /> <Compile Include="NHSpecificTest\NH1836\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1845\Category.cs" /> + <Compile Include="NHSpecificTest\NH1845\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1869\Entities.cs" /> <Compile Include="NHSpecificTest\NH1869\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1925\Fixture.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-17 22:33:23
|
Revision: 5836 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5836&view=rev Author: fabiomaulo Date: 2011-05-17 22:33:17 +0000 (Tue, 17 May 2011) Log Message: ----------- passing test for NH-2404 (was fixed fixing a similar case few days ago) Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/TestEntity.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/TestEntityDto.cs Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/Fixture.cs 2011-05-17 22:33:17 UTC (rev 5836) @@ -0,0 +1,95 @@ +using System.Linq; +using NHibernate.Impl; +using NHibernate.Linq; +using NHibernate.Transform; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH2404 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnSetUp() + { + base.OnSetUp(); + using (var session = this.OpenSession()) + using (var tx = session.BeginTransaction()) + { + var entity = new TestEntity(); + entity.Id = 1; + entity.Name = "Test Entity"; + session.Save(entity); + + var entity1 = new TestEntity(); + entity1.Id = 2; + entity1.Name = "Test Entity"; + session.Save(entity1); + + tx.Commit(); + } + } + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession session = this.OpenSession()) + { + string hql = "from System.Object"; + session.Delete(hql); + session.Flush(); + } + } + + [Test] + public void ProjectionsShouldWorkWithLinqProviderAndFutures() + { + using (ISession session = this.OpenSession()) + { + if (((SessionFactoryImpl)sessions).ConnectionProvider.Driver.SupportsMultipleQueries == false) + { + Assert.Ignore("Not applicable for dialects that do not support multiple queries"); + } + + var query1 = ( + from entity in session.Query<TestEntity>() + select new TestEntityDto {EntityId = entity.Id, EntityName = entity.Name} + ).ToList(); + + Assert.AreEqual(2, query1.Count()); + + var query2 = ( + from entity in session.Query<TestEntity>() + select new TestEntityDto { EntityId = entity.Id, EntityName = entity.Name } + ).ToFuture(); + + Assert.AreEqual(2, query2.Count()); + } + } + + [Test] + public void ProjectionsShouldWorkWithHqlAndFutures() + { + using (ISession session = this.OpenSession()) + { + if (((SessionFactoryImpl)sessions).ConnectionProvider.Driver.SupportsMultipleQueries == false) + { + Assert.Ignore("Not applicable for dialects that do not support multiple queries"); + } + + var query1 = + session.CreateQuery("select e.Id as EntityId, e.Name as EntityName from TestEntity e").SetResultTransformer( + Transformers.AliasToBean(typeof (TestEntityDto))) + .List<TestEntityDto>(); + + Assert.AreEqual(2, query1.Count()); + + var query2 = + session.CreateQuery("select e.Id as EntityId, e.Name as EntityName from TestEntity e").SetResultTransformer( + Transformers.AliasToBean(typeof (TestEntityDto))) + .Future<TestEntityDto>(); + + Assert.AreEqual(2, query2.Count()); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/Mappings.hbm.xml 2011-05-17 22:33:17 UTC (rev 5836) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2404" default-access="field.camelcase" + default-lazy="false"> + <class name="TestEntity"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="Name" /> + </class> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/TestEntity.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/TestEntity.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/TestEntity.cs 2011-05-17 22:33:17 UTC (rev 5836) @@ -0,0 +1,20 @@ +namespace NHibernate.Test.NHSpecificTest.NH2404 +{ + public class TestEntity + { + private string name; + private int id; + + public int Id + { + get { return id; } + set { id = value; } + } + + public string Name + { + get { return name; } + set { name = value; } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/TestEntityDto.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/TestEntityDto.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2404/TestEntityDto.cs 2011-05-17 22:33:17 UTC (rev 5836) @@ -0,0 +1,8 @@ +namespace NHibernate.Test.NHSpecificTest.NH2404 +{ + public class TestEntityDto + { + public int EntityId { get; set; } + public string EntityName { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-17 22:15:39 UTC (rev 5835) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-17 22:33:17 UTC (rev 5836) @@ -759,6 +759,9 @@ <Compile Include="NHSpecificTest\NH2394\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2394\PhoneNumber.cs" /> <Compile Include="NHSpecificTest\NH2394\PhoneNumberUserType.cs" /> + <Compile Include="NHSpecificTest\NH2404\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2404\TestEntity.cs" /> + <Compile Include="NHSpecificTest\NH2404\TestEntityDto.cs" /> <Compile Include="NHSpecificTest\NH2409\Contest.cs" /> <Compile Include="NHSpecificTest\NH2409\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2409\Message.cs" /> @@ -2678,6 +2681,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2404\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2705\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2546\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2697\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-17 22:15:45
|
Revision: 5835 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5835&view=rev Author: fabiomaulo Date: 2011-05-17 22:15:39 +0000 (Tue, 17 May 2011) Log Message: ----------- Test for NH-2559 (does not fail) Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/AnyTests.cs Modified: trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/AnyTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/AnyTests.cs 2011-05-17 21:23:50 UTC (rev 5834) +++ trunk/nhibernate/src/NHibernate.Test/Linq/ByMethod/AnyTests.cs 2011-05-17 22:15:39 UTC (rev 5835) @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; using NUnit.Framework; namespace NHibernate.Test.Linq.ByMethod @@ -9,25 +6,34 @@ [TestFixture] public class AnyTests : LinqTestCase { - [Test] - public void AnySublist() - { - var orders = db.Orders.Where(o => o.OrderLines.Any(ol => ol.Quantity == 5)).ToList(); - Assert.AreEqual(61, orders.Count); + [Test] + public void AnySublist() + { + var orders = db.Orders.Where(o => o.OrderLines.Any(ol => ol.Quantity == 5)).ToList(); + Assert.AreEqual(61, orders.Count); - orders = db.Orders.Where(o => o.OrderLines.Any(ol => ol.Order == null)).ToList(); - Assert.AreEqual(0, orders.Count); - } + orders = db.Orders.Where(o => o.OrderLines.Any(ol => ol.Order == null)).ToList(); + Assert.AreEqual(0, orders.Count); + } - [Test] - public void NestedAny() - { - var test = (from c in db.Customers - where c.ContactName == "Bob" && - (c.CompanyName == "NormalooCorp" || - c.Orders.Any(o => o.OrderLines.Any(ol => ol.Discount < 20 && ol.Discount >= 10))) - select c).ToList(); - Assert.AreEqual(0, test.Count); - } + [Test] + public void NestedAny() + { + var test = (from c in db.Customers + where c.ContactName == "Bob" && + (c.CompanyName == "NormalooCorp" || + c.Orders.Any(o => o.OrderLines.Any(ol => ol.Discount < 20 && ol.Discount >= 10))) + select c).ToList(); + Assert.AreEqual(0, test.Count); + } + + [Test] + public void ManyToManyAny() + { + var test = db.Orders.Where(o => o.Employee.FirstName == "test"); + var result = test.Where(o => o.Employee.Territories.Any(t => t.Description == "test")).ToList(); + + Assert.AreEqual(0, result.Count); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-17 21:23:56
|
Revision: 5834 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5834&view=rev Author: fabiomaulo Date: 2011-05-17 21:23:50 +0000 (Tue, 17 May 2011) Log Message: ----------- - Fix NH-2568 - added persister conf. support to mapping-by-code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICollectionPropertiesMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/BagMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/CollectionPropertiesCustomizer.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ListMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/MapMapper.cs trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SetMapper.cs trunk/nhibernate/src/NHibernate/Persister/PersisterFactory.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2568/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2568/UsageOfCustomCollectionPersisterTests.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -531,6 +531,11 @@ } } + public void AddMapping(HbmMapping mappingDocument) + { + AddDeserializedMapping(mappingDocument, "mapping_by_code"); + } + private void OnAfterBindMapping(BindMappingEventArgs bindMappingEventArgs) { var handler = AfterBindMapping; Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICollectionPropertiesMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICollectionPropertiesMapper.cs 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/ICollectionPropertiesMapper.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -1,6 +1,7 @@ using System; using System.Linq.Expressions; using System.Reflection; +using NHibernate.Persister.Collection; using NHibernate.UserTypes; namespace NHibernate.Mapping.ByCode @@ -27,6 +28,7 @@ void Cache(Action<ICacheMapper> cacheMapping); void Filter(string filterName, Action<IFilterMapper> filterMapping); void Fetch(CollectionFetchMode fetchMode); + void Persister(System.Type persister); } public interface ICollectionPropertiesMapper<TEntity, TElement> : IEntityPropertyMapper, ICollectionSqlsMapper where TEntity : class @@ -50,5 +52,6 @@ void Cache(Action<ICacheMapper> cacheMapping); void Filter(string filterName, Action<IFilterMapper> filterMapping); void Fetch(CollectionFetchMode fetchMode); + void Persister<TPersister>() where TPersister : ICollectionPersister; } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/BagMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/BagMapper.cs 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/BagMapper.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using NHibernate.Cfg.MappingSchema; +using NHibernate.Persister.Collection; using NHibernate.UserTypes; namespace NHibernate.Mapping.ByCode.Impl @@ -188,6 +189,19 @@ mapping.fetchSpecified = mapping.fetch != HbmCollectionFetchMode.Select; } + public void Persister(System.Type persister) + { + if (persister == null) + { + throw new ArgumentNullException("persister"); + } + if (!typeof(ICollectionPersister).IsAssignableFrom(persister)) + { + throw new ArgumentOutOfRangeException("persister", "Expected type implementing ICollectionPersister."); + } + mapping.persister = persister.AssemblyQualifiedName; + } + #endregion #region Implementation of IEntityPropertyMapper Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/CollectionPropertiesCustomizer.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/CollectionPropertiesCustomizer.cs 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/CustomizersImpl/CollectionPropertiesCustomizer.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -1,6 +1,7 @@ using System; using System.Linq.Expressions; using System.Reflection; +using NHibernate.Persister.Collection; using NHibernate.UserTypes; namespace NHibernate.Mapping.ByCode.Impl.CustomizersImpl @@ -118,6 +119,11 @@ CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.Fetch(fetchMode)); } + public void Persister<TPersister>() where TPersister : ICollectionPersister + { + CustomizersHolder.AddCustomizer(PropertyPath, (ICollectionPropertiesMapper x) => x.Persister(typeof(TPersister))); + } + #endregion #region ICollectionPropertiesMapper<TEntity,TElement> Members Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/IdBagMapper.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using NHibernate.Cfg.MappingSchema; +using NHibernate.Persister.Collection; using NHibernate.UserTypes; namespace NHibernate.Mapping.ByCode.Impl @@ -194,6 +195,19 @@ mapping.fetchSpecified = mapping.fetch != HbmCollectionFetchMode.Select; } + public void Persister(System.Type persister) + { + if (persister == null) + { + throw new ArgumentNullException("persister"); + } + if (!typeof(ICollectionPersister).IsAssignableFrom(persister)) + { + throw new ArgumentOutOfRangeException("persister", "Expected type implementing ICollectionPersister."); + } + mapping.persister = persister.AssemblyQualifiedName; + } + public void Id(Action<ICollectionIdMapper> idMapping) { idMapping(idMapper); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ListMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ListMapper.cs 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/ListMapper.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using NHibernate.Cfg.MappingSchema; +using NHibernate.Persister.Collection; using NHibernate.UserTypes; namespace NHibernate.Mapping.ByCode.Impl @@ -192,6 +193,19 @@ mapping.fetchSpecified = mapping.fetch != HbmCollectionFetchMode.Select; } + public void Persister(System.Type persister) + { + if (persister == null) + { + throw new ArgumentNullException("persister"); + } + if (!typeof(ICollectionPersister).IsAssignableFrom(persister)) + { + throw new ArgumentOutOfRangeException("persister", "Expected type implementing ICollectionPersister."); + } + mapping.persister = persister.AssemblyQualifiedName; + } + public void Index(Action<IListIndexMapper> listIndexMapping) { listIndexMapping(listIndexMapper); Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/MapMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/MapMapper.cs 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/MapMapper.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using NHibernate.Cfg.MappingSchema; +using NHibernate.Persister.Collection; using NHibernate.UserTypes; namespace NHibernate.Mapping.ByCode.Impl @@ -209,6 +210,19 @@ mapping.fetchSpecified = mapping.fetch != HbmCollectionFetchMode.Select; } + public void Persister(System.Type persister) + { + if (persister == null) + { + throw new ArgumentNullException("persister"); + } + if (!typeof(ICollectionPersister).IsAssignableFrom(persister)) + { + throw new ArgumentOutOfRangeException("persister", "Expected type implementing ICollectionPersister."); + } + mapping.persister = persister.AssemblyQualifiedName; + } + #endregion #region Implementation of IEntityPropertyMapper Modified: trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SetMapper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SetMapper.cs 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate/Mapping/ByCode/Impl/SetMapper.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using NHibernate.Cfg.MappingSchema; +using NHibernate.Persister.Collection; using NHibernate.UserTypes; namespace NHibernate.Mapping.ByCode.Impl @@ -194,6 +195,19 @@ mapping.fetchSpecified = mapping.fetch != HbmCollectionFetchMode.Select; } + public void Persister(System.Type persister) + { + if (persister == null) + { + throw new ArgumentNullException("persister"); + } + if (!typeof(ICollectionPersister).IsAssignableFrom(persister)) + { + throw new ArgumentOutOfRangeException("persister", "Expected type implementing ICollectionPersister."); + } + mapping.persister = persister.AssemblyQualifiedName; + } + #endregion #region Implementation of IEntityPropertyMapper Modified: trunk/nhibernate/src/NHibernate/Persister/PersisterFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Persister/PersisterFactory.cs 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate/Persister/PersisterFactory.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -1,5 +1,6 @@ using System; using System.Reflection; +using System.Text; using NHibernate.Cache; using NHibernate.Cfg; using NHibernate.Engine; @@ -38,6 +39,14 @@ typeof(ISessionFactoryImplementor) }; + private static readonly System.Type[] CollectionPersisterConstructor2Args = new System.Type[] + { + typeof(Mapping.Collection), + typeof(ICacheConcurrencyStrategy), + typeof(Configuration), + typeof(ISessionFactoryImplementor) + }; + /// <summary> /// Creates a built in Entity Persister or a custom Persister. /// </summary> @@ -78,7 +87,7 @@ } else { - return Create(persisterClass, model, cache, factory); + return Create(persisterClass, model, cache, factory, cfg); } } @@ -122,21 +131,41 @@ } public static ICollectionPersister Create(System.Type persisterClass, Mapping.Collection model, - ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory) + ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, Configuration cfg) { ConstructorInfo pc; + var use4Parameters = false; try { pc = persisterClass.GetConstructor(CollectionPersisterConstructorArgs); + if (pc == null) + { + use4Parameters = true; + pc = persisterClass.GetConstructor(CollectionPersisterConstructor2Args); + } } catch (Exception e) { throw new MappingException("Could not get constructor for " + persisterClass.Name, e); } - + if(pc == null) + { + var messageBuilder = new StringBuilder(); + messageBuilder.AppendLine("Could not find a public constructor for " + persisterClass.Name +";"); + messageBuilder.AppendLine("- The ctor may have " + CollectionPersisterConstructorArgs.Length + " parameters of types (in order):"); + System.Array.ForEach(CollectionPersisterConstructorArgs, t=> messageBuilder.AppendLine(t.FullName)); + messageBuilder.AppendLine(); + messageBuilder.AppendLine("- The ctor may have " + CollectionPersisterConstructor2Args.Length + " parameters of types (in order):"); + System.Array.ForEach(CollectionPersisterConstructor2Args, t => messageBuilder.AppendLine(t.FullName)); + throw new MappingException(messageBuilder.ToString()); + } try { - return (ICollectionPersister) pc.Invoke(new object[] {model, cache, factory}); + if (!use4Parameters) + { + return (ICollectionPersister) pc.Invoke(new object[] {model, cache, factory}); + } + return (ICollectionPersister)pc.Invoke(new object[] { model, cache, cfg, factory }); } catch (TargetInvocationException tie) { Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2568/UsageOfCustomCollectionPersisterTests.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2568/UsageOfCustomCollectionPersisterTests.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2568/UsageOfCustomCollectionPersisterTests.cs 2011-05-17 21:23:50 UTC (rev 5834) @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using NHibernate.Cache; +using NHibernate.Cfg; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Engine; +using NHibernate.Mapping.ByCode; +using NHibernate.Persister.Collection; +using NUnit.Framework; +using SharpTestsEx; + +namespace NHibernate.Test.NHSpecificTest.NH2568 +{ + public class MyEntity + { + public virtual int Id { get; set; } + public virtual ICollection<MyRelated> Relateds { get; set; } + } + public class MyRelated + { + public virtual int Id { get; set; } + } + + public class UsageOfCustomCollectionPersisterTests + { + private HbmMapping GetMappings() + { + var mapper = new ModelMapper(); + mapper.Class<MyRelated>(rm=> rm.Id(x=> x.Id)); + mapper.Class<MyEntity>(rm => + { + rm.Id(x => x.Id); + rm.Bag(x => x.Relateds, am => am.Persister<MyCollectionPersister>(), rel=> rel.OneToMany()); + }); + var mappings = mapper.CompileMappingForAllExplicitAddedEntities(); + return mappings; + } + + [Test] + public void BuildingSessionFactoryShouldNotThrows() + { + Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration(); + cfg.AddMapping(GetMappings()); + cfg.Executing(c=>c.BuildSessionFactory()).NotThrows(); + } + } + + public class MyCollectionPersister: OneToManyPersister + { + public MyCollectionPersister(Mapping.Collection collection, ICacheConcurrencyStrategy cache, Configuration cfg, ISessionFactoryImplementor factory) : base(collection, cache, cfg, factory) {} + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-17 20:45:36 UTC (rev 5833) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-17 21:23:50 UTC (rev 5834) @@ -804,6 +804,7 @@ <Compile Include="NHSpecificTest\NH2554\Model.cs" /> <Compile Include="NHSpecificTest\NH2565\Domain.cs" /> <Compile Include="NHSpecificTest\NH2565\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH2568\UsageOfCustomCollectionPersisterTests.cs" /> <Compile Include="NHSpecificTest\NH2569\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2580\Fixture.cs" /> <Compile Include="NHSpecificTest\NH2583\AbstractMassTestingFixture.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-05-17 20:45:42
|
Revision: 5833 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5833&view=rev Author: ricbrown Date: 2011-05-17 20:45:36 +0000 (Tue, 17 May 2011) Log Message: ----------- Reverted rev 5770 (no longer needed after Firebird Dialect had corrected default Driver) Revision Links: -------------- http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5770&view=rev Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml trunk/nhibernate/src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj trunk/nhibernate/teamcity.build Removed Paths: ------------- trunk/nhibernate/src/NHibernate.Test/DialectTest/FirebirdClientDialect.cs Deleted: trunk/nhibernate/src/NHibernate.Test/DialectTest/FirebirdClientDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DialectTest/FirebirdClientDialect.cs 2011-05-17 20:07:15 UTC (rev 5832) +++ trunk/nhibernate/src/NHibernate.Test/DialectTest/FirebirdClientDialect.cs 2011-05-17 20:45:36 UTC (rev 5833) @@ -1,14 +0,0 @@ -using NHibernate.Cfg; -using NHibernate.Dialect; - -namespace NHibernate.Test.DialectTest -{ - public class FirebirdClientDialect : FirebirdDialect - { - public FirebirdClientDialect() : base() - { - // overrides default driver to allow tests to run using embedded client - DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.FirebirdClientDriver"; - } - } -} Modified: trunk/nhibernate/src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml 2011-05-17 20:07:15 UTC (rev 5832) +++ trunk/nhibernate/src/NHibernate.Test/GeneratedTest/ComponentOwner.hbm.xml 2011-05-17 20:45:36 UTC (rev 5833) @@ -70,7 +70,6 @@ <![CDATA[DROP TRIGGER t_iu_part_gen_comp]]> </drop> <dialect-scope name="NHibernate.Dialect.FirebirdDialect"/> - <dialect-scope name="NHibernate.Test.DialectTest.FirebirdClientDialect"/> </database-object> </hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml 2011-05-17 20:07:15 UTC (rev 5832) +++ trunk/nhibernate/src/NHibernate.Test/Generatedkeys/Select/MyEntity.hbm.xml 2011-05-17 20:45:36 UTC (rev 5833) @@ -21,7 +21,6 @@ DROP GENERATOR MYGENERATOR; </drop> <dialect-scope name="NHibernate.Dialect.FirebirdDialect"/> - <dialect-scope name="NHibernate.Test.DialectTest.FirebirdClientDialect"/> </database-object> <database-object> @@ -37,9 +36,8 @@ <drop> DROP TRIGGER my_entity_BI; </drop> - <dialect-scope name="NHibernate.Dialect.FirebirdDialect"/> - <dialect-scope name="NHibernate.Test.DialectTest.FirebirdClientDialect"/> - </database-object> + <dialect-scope name="NHibernate.Dialect.FirebirdDialect"/> + </database-object> <database-object> <create> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-17 20:07:15 UTC (rev 5832) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-17 20:45:36 UTC (rev 5833) @@ -212,7 +212,6 @@ <Compile Include="Criteria\MaterialResource.cs" /> <Compile Include="Criteria\ProjectionsTest.cs" /> <Compile Include="Criteria\Reptile.cs" /> - <Compile Include="DialectTest\FirebirdClientDialect.cs" /> <Compile Include="DialectTest\MsSqlCe40DialectFixture.cs" /> <Compile Include="DriverTest\DbProviderFactoryDriveConnectionCommandProviderTest.cs" /> <Compile Include="DriverTest\ReflectionBasedDriverTest.cs" /> Modified: trunk/nhibernate/teamcity.build =================================================================== --- trunk/nhibernate/teamcity.build 2011-05-17 20:07:15 UTC (rev 5832) +++ trunk/nhibernate/teamcity.build 2011-05-17 20:45:36 UTC (rev 5833) @@ -35,7 +35,7 @@ <target name="setup-teamcity-firebird32"> <property name="nhibernate.connection.driver_class" value="NHibernate.Driver.FirebirdClientDriver" /> - <property name="nhibernate.dialect" value="NHibernate.Test.DialectTest.FirebirdClientDialect, NHibernate.Test" /> + <property name="nhibernate.dialect" value="NHibernate.Dialect.FirebirdDialect" /> <property name="nhibernate.connection.connection_string" value="Database=NHibernate.fdb;ServerType=1;UserID=SYSDBA" /> <copy todir="${bin.dir}"> <fileset basedir="${root.dir}/lib/teamcity/firebird/x86"> @@ -51,7 +51,7 @@ <property name="nunit-console" value="${tools.dir}/NUnit/nunit-console.exe" /> <property name="nunit.found" value="true" /> <property name="nhibernate.connection.driver_class" value="NHibernate.Driver.FirebirdClientDriver" /> - <property name="nhibernate.dialect" value="NHibernate.Test.DialectTest.FirebirdClientDialect, NHibernate.Test" /> + <property name="nhibernate.dialect" value="NHibernate.Dialect.FirebirdDialect" /> <property name="nhibernate.connection.connection_string" value="Database=NHibernate.fdb;ServerType=1;UserID=SYSDBA" /> <copy todir="${bin.dir}"> <fileset basedir="${root.dir}/lib/teamcity/firebird/x64"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-17 20:07:21
|
Revision: 5832 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5832&view=rev Author: fabiomaulo Date: 2011-05-17 20:07:15 +0000 (Tue, 17 May 2011) Log Message: ----------- Fix NH-2695 part 2 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/FirebirdDialect.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/FirebirdDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/FirebirdDialect.cs 2011-05-17 18:04:43 UTC (rev 5831) +++ trunk/nhibernate/src/NHibernate/Dialect/FirebirdDialect.cs 2011-05-17 20:07:15 UTC (rev 5832) @@ -138,7 +138,7 @@ RegisterFunction("tan", new StandardSQLFunction("tan", NHibernateUtil.Double)); RegisterFunction("tanh", new StandardSQLFunction("tanh", NHibernateUtil.Double)); - DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.FirebirdDriver"; + DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.FirebirdClientDriver"; } /// <summary></summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-17 18:04:49
|
Revision: 5831 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5831&view=rev Author: fabiomaulo Date: 2011-05-17 18:04:43 +0000 (Tue, 17 May 2011) Log Message: ----------- Fix NH-2695 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Driver/FirebirdDriver.cs Modified: trunk/nhibernate/src/NHibernate/Driver/FirebirdDriver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/FirebirdDriver.cs 2011-05-17 17:45:09 UTC (rev 5830) +++ trunk/nhibernate/src/NHibernate/Driver/FirebirdDriver.cs 2011-05-17 18:04:43 UTC (rev 5831) @@ -9,12 +9,12 @@ /// Initializes a new instance of the <see cref="FirebirdDriver"/> class. /// </summary> /// <exception cref="HibernateException"> - /// Thrown when the <c>FirebirdSql.Data.Firebird</c> assembly can not be loaded. + /// Thrown when the <c>FirebirdSql.Data.FirebirdClient</c> assembly can not be loaded. /// </exception> public FirebirdDriver() : base( - "FirebirdSql.Data.Firebird", - "FirebirdSql.Data.Firebird.FbConnection", - "FirebirdSql.Data.Firebird.FbCommand") + "FirebirdSql.Data.FirebirdClient", + "FirebirdSql.Data.FirebirdClient.FbConnection", + "FirebirdSql.Data.FirebirdClient.FbCommand") { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-17 17:45:16
|
Revision: 5830 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5830&view=rev Author: fabiomaulo Date: 2011-05-17 17:45:09 +0000 (Tue, 17 May 2011) Log Message: ----------- Fix NH-2705 and NH-2615 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromClause.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementFactory.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementType.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate/PropertyNotFoundException.cs trunk/nhibernate/src/NHibernate/Type/ComponentType.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/ItemBase.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemBase.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Test.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/ComponentJoin.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -678,23 +678,30 @@ // to the root dot node. dot.Resolve( true, false, alias == null ? null : alias.Text ); - FromElement fromElement = dot.GetImpliedJoin(); - - if (fromElement == null) + FromElement fromElement; + if (dot.DataType != null && dot.DataType.IsComponentType) { - throw new InvalidPathException("Invalid join: " + dot.Path); + var factory = new FromElementFactory(CurrentFromClause, dot.GetLhs().FromElement, dot.PropertyPath, alias == null ? null : alias.Text, null, false); + fromElement = factory.CreateComponentJoin((ComponentType) dot.DataType); } - - fromElement.SetAllPropertyFetch(propertyFetch!=null); - - if ( with != null ) + else { - if ( fetch ) + fromElement = dot.GetImpliedJoin(); + if (fromElement == null) { - throw new SemanticException( "with-clause not allowed on fetched associations; use filters" ); + throw new InvalidPathException("Invalid join: " + dot.Path); } + fromElement.SetAllPropertyFetch(propertyFetch != null); - HandleWithFragment( fromElement, with ); + if (with != null) + { + if (fetch) + { + throw new SemanticException("with-clause not allowed on fetched associations; use filters"); + } + + HandleWithFragment(fromElement, with); + } } if ( log.IsDebugEnabled ) Added: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/ComponentJoin.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/ComponentJoin.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/ComponentJoin.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -0,0 +1,175 @@ +using System; +using System.Text; +using NHibernate.Persister.Collection; +using NHibernate.Persister.Entity; +using NHibernate.Type; +using NHibernate.Util; + +namespace NHibernate.Hql.Ast.ANTLR.Tree +{ + public class ComponentJoin : FromElement + { + private readonly string columns; + private readonly string componentPath; + private readonly string componentProperty; + private readonly ComponentType componentType; + + public ComponentJoin(FromClause fromClause, FromElement origin, string alias, string componentPath, ComponentType componentType) + : base(fromClause, origin, alias) + { + this.componentPath = componentPath; + this.componentType = componentType; + componentProperty = StringHelper.Unqualify(componentPath); + fromClause.AddJoinByPathMap(componentPath, this); + InitializeComponentJoin(new ComponentFromElementType(this)); + + string[] cols = origin.GetPropertyMapping("").ToColumns(TableAlias, componentProperty); + columns = string.Join(", ", cols); + } + + public string ComponentPath + { + get { return componentPath; } + } + + public ComponentType ComponentType + { + get { return componentType; } + } + + public string ComponentProperty + { + get { return componentProperty; } + } + + public override IType DataType + { + get { return ComponentType; } + set { base.DataType = value; } + } + + public override string GetIdentityColumn() + { + return columns; + } + + public override string GetDisplayText() + { + return "ComponentJoin{path=" + ComponentPath + ", type=" + componentType.ReturnedClass + "}"; + } + + #region Nested type: ComponentFromElementType + + public class ComponentFromElementType : FromElementType + { + private readonly ComponentJoin fromElement; + private readonly IPropertyMapping propertyMapping; + + public ComponentFromElementType(ComponentJoin fromElement) + : base(fromElement) + { + this.fromElement = fromElement; + propertyMapping = new ComponentPropertyMapping(this); + } + + public ComponentJoin FromElement + { + get { return fromElement; } + } + + public override IType DataType + { + get { return fromElement.ComponentType; } + } + + public override IQueryableCollection QueryableCollection + { + get { return null; } + set { base.QueryableCollection = value; } + } + + public override IPropertyMapping GetPropertyMapping(string propertyName) + { + return propertyMapping; + } + + public override IType GetPropertyType(string propertyName, string propertyPath) + { + int index = fromElement.ComponentType.GetPropertyIndex(propertyName); + return fromElement.ComponentType.Subtypes[index]; + } + + public override string RenderScalarIdentifierSelect(int i) + { + String[] cols = GetBasePropertyMapping().ToColumns(fromElement.TableAlias, fromElement.ComponentProperty); + var buf = new StringBuilder(); + // For property references generate <tablealias>.<columnname> as <projectionalias> + for (int j = 0; j < cols.Length; j++) + { + string column = cols[j]; + if (j > 0) + { + buf.Append(", "); + } + buf.Append(column).Append(" as ").Append(NameGenerator.ScalarName(i, j)); + } + return buf.ToString(); + } + + protected IPropertyMapping GetBasePropertyMapping() + { + return fromElement.Origin.GetPropertyMapping(""); + } + + #region Nested type: ComponentPropertyMapping + + private class ComponentPropertyMapping : IPropertyMapping + { + private readonly ComponentFromElementType fromElementType; + + public ComponentPropertyMapping(ComponentFromElementType fromElementType) + { + this.fromElementType = fromElementType; + } + + #region IPropertyMapping Members + + public IType Type + { + get { return fromElementType.FromElement.ComponentType; } + } + + public IType ToType(string propertyName) + { + return fromElementType.GetBasePropertyMapping().ToType(GetPropertyPath(propertyName)); + } + + public bool TryToType(string propertyName, out IType type) + { + return fromElementType.GetBasePropertyMapping().TryToType(GetPropertyPath(propertyName), out type); + } + + public string[] ToColumns(string alias, string propertyName) + { + return fromElementType.GetBasePropertyMapping().ToColumns(alias, GetPropertyPath(propertyName)); + } + + public string[] ToColumns(string propertyName) + { + return fromElementType.GetBasePropertyMapping().ToColumns(GetPropertyPath(propertyName)); + } + + #endregion + + private string GetPropertyPath(string propertyName) + { + return fromElementType.FromElement.ComponentPath + '.' + propertyName; + } + } + + #endregion + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromClause.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromClause.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromClause.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -342,7 +342,7 @@ string tableAlias = element.TableAlias; if (tableAlias != null) { - _fromElementByTableAlias.Add(tableAlias, element); + _fromElementByTableAlias[tableAlias] = element; } } Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElement.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -39,12 +39,35 @@ private string _withClauseFragment; private string _withClauseJoinAlias; private bool _filter; + private IToken _token; - public FromElement(IToken token) : base(token) { + _token= token; } + /// <summary> + /// Constructor form used to initialize <see cref="ComponentJoin"/>. + /// </summary> + /// <param name="fromClause">The FROM clause to which this element belongs.</param> + /// <param name="origin">The origin (LHS) of this element.</param> + /// <param name="alias">The alias applied to this element.</param> + protected FromElement(FromClause fromClause,FromElement origin,string alias):this(origin._token) + { + _fromClause = fromClause; + _origin = origin; + _classAlias = alias; + _tableAlias = origin.TableAlias; + base.Initialize(fromClause.Walker); + } + + protected void InitializeComponentJoin(FromElementType elementType) + { + _elementType = elementType; + _fromClause.RegisterFromElement(this); + _initialized = true; + } + public void SetAllPropertyFetch(bool fetch) { _isAllPropertyFetch = fetch; @@ -429,7 +452,7 @@ return _elementType.GetPropertyType(propertyName, propertyPath); } - public string GetIdentityColumn() + public virtual string GetIdentityColumn() { CheckInitialized(); string table = TableAlias; Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementFactory.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementFactory.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -562,5 +562,10 @@ } } + public FromElement CreateComponentJoin(ComponentType type) + { + // need to create a "place holder" from-element that can store the component/alias for this component join + return new ComponentJoin(_fromClause, _origin, _classAlias, _path, type); + } } } Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementType.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementType.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -42,6 +42,11 @@ } } + protected FromElementType(FromElement fromElement) + { + _fromElement = fromElement; + } + public IEntityPersister EntityPersister { get { return _persister; } @@ -57,7 +62,7 @@ get { return _fromElement.CollectionTableAlias; } } - public IType DataType + public virtual IType DataType { get { @@ -167,7 +172,7 @@ /// </summary> /// <param name="i">the sequence of the returned type</param> /// <returns>the identifier select with the column alias.</returns> - public string RenderScalarIdentifierSelect(int i) + public virtual string RenderScalarIdentifierSelect(int i) { CheckInitialized(); string[] cols = GetPropertyMapping(Persister.Entity.EntityPersister.EntityID).ToColumns(TableAlias, Persister.Entity.EntityPersister.EntityID); @@ -273,7 +278,7 @@ } } - public IPropertyMapping GetPropertyMapping(string propertyName) + public virtual IPropertyMapping GetPropertyMapping(string propertyName) { CheckInitialized(); @@ -317,7 +322,7 @@ /// <param name="propertyName">The last part of the full path to the property.</param> /// <param name="propertyPath">The full property path.</param> /// <returns>The type</returns> - public IType GetPropertyType(string propertyName, string propertyPath) + public virtual IType GetPropertyType(string propertyName, string propertyPath) { CheckInitialized(); @@ -359,7 +364,7 @@ get { return (_persister is IQueryable) ? (IQueryable) _persister : null; } } - public IQueryableCollection QueryableCollection + public virtual IQueryableCollection QueryableCollection { get { return _queryableCollection; } set Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2011-05-17 17:45:09 UTC (rev 5830) @@ -206,6 +206,7 @@ <Compile Include="FetchMode.cs" /> <Compile Include="FlushMode.cs" /> <Compile Include="HibernateException.cs" /> + <Compile Include="Hql\Ast\ANTLR\Tree\ComponentJoin.cs" /> <Compile Include="Hql\Classic\ClauseParser.cs" /> <Compile Include="Hql\Classic\FromParser.cs" /> <Compile Include="Hql\Classic\FromPathExpressionParser.cs" /> Modified: trunk/nhibernate/src/NHibernate/PropertyNotFoundException.cs =================================================================== --- trunk/nhibernate/src/NHibernate/PropertyNotFoundException.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate/PropertyNotFoundException.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -38,7 +38,7 @@ /// <param name="targetType">The <see cref="System.Type" /> that is missing the field</param> /// <param name="propertyName">The name of the missing property</param> public PropertyNotFoundException(System.Type targetType, string propertyName) - : base(String.Format("Could not find field '{0}' in class '{1}'", + : base(String.Format("Could not find property nor field '{0}' in class '{1}'", propertyName, targetType)) { this.targetType = targetType; Modified: trunk/nhibernate/src/NHibernate/Type/ComponentType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/ComponentType.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate/Type/ComponentType.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -688,5 +688,18 @@ { get { return true; } } + + public int GetPropertyIndex(string name) + { + string[] names = PropertyNames; + for (int i = 0; i < names.Length; i++) + { + if (names[i].Equals(name)) + { + return i; + } + } + throw new PropertyNotFoundException(ReturnedClass, name); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/ItemBase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/ItemBase.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/ItemBase.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -7,6 +7,4 @@ } public class ItemWithComponentSubItem : ItemBase {} - - public class ItemWithManyToOneSubItem : ItemBase {} } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Mappings.hbm.xml 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Mappings.hbm.xml 2011-05-17 17:45:09 UTC (rev 5830) @@ -14,20 +14,8 @@ <many-to-one class="SubItemDetails" name="Details" column="SubItemDetails_id"/> </component> </joined-subclass> - <joined-subclass name="ItemWithManyToOneSubItem"> - <key column="ItemBase_id"/> - <many-to-one class="SubItemEntity" name="SubItem" column="SubItem_id"/> - </joined-subclass> </class> - <class name="SubItemEntity"> - <id name="Id" type="int"> - <generator class="native" /> - </id> - <property name="Name" /> - <many-to-one class="SubItemDetails" name="Details" column="SubItemDetails_id" /> - </class> - <class name="SubItemDetails"> <id name="Id" type="int"> <generator class="native" /> Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemBase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemBase.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemBase.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -1,5 +1,7 @@ namespace NHibernate.Test.NHSpecificTest.NH2705 { + // NOTE: an Entity and a Component in the same hierarchy is not supported + // we are using this trick just to ""simplify"" the test. public class SubItemBase { public virtual string Name { get; set; } @@ -7,9 +9,4 @@ } public class SubItemComponent : SubItemBase {} - - public class SubItemEntity : SubItemBase - { - public virtual int Id { get; set; } - } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Test.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Test.cs 2011-05-16 14:37:27 UTC (rev 5829) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Test.cs 2011-05-17 17:45:09 UTC (rev 5830) @@ -8,7 +8,7 @@ namespace NHibernate.Test.NHSpecificTest.NH2705 { - [TestFixture, Ignore("Not fixed yet")] + [TestFixture] public class Test : BugTestCase { private static IEnumerable<T> GetAndFetch<T>(string name, ISession session) where T : ItemBase @@ -30,22 +30,26 @@ } [Test] - public void Fetch_OnManyToOne_ShouldNotThrow() + public void HqlQueryWithFetch_WhenDerivedClassesUseComponentAndManyToOne_DoesNotGenerateInvalidSql() { using (ISession s = OpenSession()) { - Executing.This(() => GetAndFetch<ItemWithManyToOneSubItem>("hello", s)).Should().NotThrow(); + using (var log = new SqlLogSpy()) + { + Executing.This(() => s.CreateQuery("from ItemWithComponentSubItem i left join fetch i.SubItem").List() + ).Should().NotThrow(); + } } } [Test] - public void HqlQueryWithFetch_WhenDerivedClassesUseComponentAndManyToOne_DoesNotGenerateInvalidSql() + public void HqlQueryWithFetch_WhenDerivedClassesUseComponentAndEagerFetchManyToOne_DoesNotGenerateInvalidSql() { using (ISession s = OpenSession()) { using (var log = new SqlLogSpy()) { - Executing.This(() => s.CreateQuery("from ItemBase i left join fetch i.SubItem").List() + Executing.This(() => s.CreateQuery("from ItemWithComponentSubItem i left join fetch i.SubItem.Details").List() ).Should().NotThrow(); } } @@ -64,11 +68,23 @@ // fetching second level properties should work too - Executing.This(() => s.Query<ItemBase>() + Executing.This(() => s.Query<ItemWithComponentSubItem>() .Fetch(p => p.SubItem).ThenFetch(p => p.Details).ToList() ).Should().NotThrow(); } } } + + [Test, Ignore("Locked by re-linq")] + public void LinqQueryWithFetch_WhenDerivedClassesUseComponentAndEagerFetchManyToOne_DoesNotGenerateInvalidSql() + { + using (ISession s = OpenSession()) + { + using (var log = new SqlLogSpy()) + { + Executing.This(() => s.Query<ItemWithComponentSubItem>().Fetch(p => p.SubItem.Details).ToList()).Should().NotThrow(); + } + } + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2011-05-16 14:37:33
|
Revision: 5829 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5829&view=rev Author: fabiomaulo Date: 2011-05-16 14:37:27 +0000 (Mon, 16 May 2011) Log Message: ----------- Tests (not fixed) for NH-2705 and NH-2615 Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/ItemBase.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemBase.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemDetails.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Test.cs Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/ItemBase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/ItemBase.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/ItemBase.cs 2011-05-16 14:37:27 UTC (rev 5829) @@ -0,0 +1,12 @@ +namespace NHibernate.Test.NHSpecificTest.NH2705 +{ + public class ItemBase + { + public virtual int Id { get; set; } + public virtual SubItemBase SubItem { get; set; } + } + + public class ItemWithComponentSubItem : ItemBase {} + + public class ItemWithManyToOneSubItem : ItemBase {} +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Mappings.hbm.xml 2011-05-16 14:37:27 UTC (rev 5829) @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH2705"> + + <class name="ItemBase"> + <id name="Id" type="int"> + <generator class="native" /> + </id> + <joined-subclass name="ItemWithComponentSubItem"> + <key column="ItemBase_id"/> + <component name="SubItem" class="SubItemComponent"> + <property name="Name" /> + <many-to-one class="SubItemDetails" name="Details" column="SubItemDetails_id"/> + </component> + </joined-subclass> + <joined-subclass name="ItemWithManyToOneSubItem"> + <key column="ItemBase_id"/> + <many-to-one class="SubItemEntity" name="SubItem" column="SubItem_id"/> + </joined-subclass> + </class> + + <class name="SubItemEntity"> + <id name="Id" type="int"> + <generator class="native" /> + </id> + <property name="Name" /> + <many-to-one class="SubItemDetails" name="Details" column="SubItemDetails_id" /> + </class> + + <class name="SubItemDetails"> + <id name="Id" type="int"> + <generator class="native" /> + </id> + <property name="Name" /> + </class> +</hibernate-mapping> + Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemBase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemBase.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemBase.cs 2011-05-16 14:37:27 UTC (rev 5829) @@ -0,0 +1,15 @@ +namespace NHibernate.Test.NHSpecificTest.NH2705 +{ + public class SubItemBase + { + public virtual string Name { get; set; } + public virtual SubItemDetails Details { get; set; } + } + + public class SubItemComponent : SubItemBase {} + + public class SubItemEntity : SubItemBase + { + public virtual int Id { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemDetails.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemDetails.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/SubItemDetails.cs 2011-05-16 14:37:27 UTC (rev 5829) @@ -0,0 +1,8 @@ +namespace NHibernate.Test.NHSpecificTest.NH2705 +{ + public class SubItemDetails + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Test.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Test.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2705/Test.cs 2011-05-16 14:37:27 UTC (rev 5829) @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using System.Linq; +using NHibernate.Linq; +using NUnit.Framework; +using SharpTestsEx; + +// ReSharper disable InconsistentNaming + +namespace NHibernate.Test.NHSpecificTest.NH2705 +{ + [TestFixture, Ignore("Not fixed yet")] + public class Test : BugTestCase + { + private static IEnumerable<T> GetAndFetch<T>(string name, ISession session) where T : ItemBase + { + // this is a valid abstraction, the calling code should be able to ask that a property is eagerly loaded/available + // without having to know how it is mapped + return session.Query<T>() + .Fetch(p => p.SubItem).ThenFetch(p => p.Details) // should be able to fetch .Details when used with components (NH2615) + .Where(p => p.SubItem.Name == name).ToList(); + } + + [Test] + public void Fetch_OnComponent_ShouldNotThrow() + { + using (ISession s = OpenSession()) + { + Executing.This(() => GetAndFetch<ItemWithComponentSubItem>("hello", s)).Should().NotThrow(); + } + } + + [Test] + public void Fetch_OnManyToOne_ShouldNotThrow() + { + using (ISession s = OpenSession()) + { + Executing.This(() => GetAndFetch<ItemWithManyToOneSubItem>("hello", s)).Should().NotThrow(); + } + } + + [Test] + public void HqlQueryWithFetch_WhenDerivedClassesUseComponentAndManyToOne_DoesNotGenerateInvalidSql() + { + using (ISession s = OpenSession()) + { + using (var log = new SqlLogSpy()) + { + Executing.This(() => s.CreateQuery("from ItemBase i left join fetch i.SubItem").List() + ).Should().NotThrow(); + } + } + } + + [Test] + public void LinqQueryWithFetch_WhenDerivedClassesUseComponentAndManyToOne_DoesNotGenerateInvalidSql() + { + using (ISession s = OpenSession()) + { + using (var log = new SqlLogSpy()) + { + Executing.This(() => s.Query<ItemBase>() + .Fetch(p => p.SubItem).ToList() + ).Should().NotThrow(); + + + // fetching second level properties should work too + Executing.This(() => s.Query<ItemBase>() + .Fetch(p => p.SubItem).ThenFetch(p => p.Details).ToList() + ).Should().NotThrow(); + } + } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-16 02:07:33 UTC (rev 5828) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-05-16 14:37:27 UTC (rev 5829) @@ -832,6 +832,10 @@ <Compile Include="NHSpecificTest\NH2697\ArticleGroupItem.cs" /> <Compile Include="NHSpecificTest\NH2697\ArticleItem.cs" /> <Compile Include="NHSpecificTest\NH2697\SampleTest.cs" /> + <Compile Include="NHSpecificTest\NH2705\ItemBase.cs" /> + <Compile Include="NHSpecificTest\NH2705\SubItemBase.cs" /> + <Compile Include="NHSpecificTest\NH2705\SubItemDetails.cs" /> + <Compile Include="NHSpecificTest\NH2705\Test.cs" /> <Compile Include="NHSpecificTest\Properties\CompositePropertyRefTest.cs" /> <Compile Include="NHSpecificTest\Properties\DynamicEntityTest.cs" /> <Compile Include="NHSpecificTest\Properties\Model.cs" /> @@ -2674,6 +2678,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="NHSpecificTest\NH2705\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2546\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH2697\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1642\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |