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...> - 2009-10-08 17:51:06
|
Revision: 4741 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4741&view=rev Author: ricbrown Date: 2009-10-08 17:50:58 +0000 (Thu, 08 Oct 2009) Log Message: ----------- Merge r4740 (Fix NH-1964, NH-1983, Blobs and Clobs with Sql Server CE) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Driver/SqlServerCeDriver.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeDriverFixture.cs trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeEntity.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Driver/SqlServerCeDriver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/SqlServerCeDriver.cs 2009-10-08 17:50:20 UTC (rev 4740) +++ trunk/nhibernate/src/NHibernate/Driver/SqlServerCeDriver.cs 2009-10-08 17:50:58 UTC (rev 4741) @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Data; +using System.Reflection; using NHibernate.Cfg; using NHibernate.SqlCommand; using NHibernate.SqlTypes; @@ -24,11 +25,18 @@ } private bool prepareSql; + private PropertyInfo dbParamSqlDbTypeProperty; public override void Configure(IDictionary<string, string> settings) { base.Configure(settings); prepareSql = PropertiesHelper.GetBoolean(Environment.PrepareSql, settings, false); + + using (IDbCommand cmd = CreateCommand()) + { + IDbDataParameter dbParam = cmd.CreateParameter(); + dbParamSqlDbTypeProperty = dbParam.GetType().GetProperty("SqlDbType"); + } } /// <summary> @@ -94,5 +102,24 @@ { get { return true; } } + + protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType) + { + base.InitializeParameter(dbParam, name, sqlType); + + AdjustDbParamTypeForLargeObjects(dbParam, sqlType); + } + + private void AdjustDbParamTypeForLargeObjects(IDbDataParameter dbParam, SqlType sqlType) + { + if (sqlType is BinaryBlobSqlType) + { + dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.Image, null); + } + else if (sqlType is StringClobSqlType) + { + dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.NText, null); + } + } } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeDriverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeDriverFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeDriverFixture.cs 2009-10-08 17:50:58 UTC (rev 4741) @@ -0,0 +1,112 @@ +using System; +using System.Collections; +using NHibernate.Cfg; +using NHibernate.Dialect; +using NUnit.Framework; +using NHibernate.Criterion; +using System.Collections.Generic; + +namespace NHibernate.Test.DriverTest +{ + public class SqlServerCeEntity + { + public virtual int Id { get; set; } + + public virtual string StringProp { get; set; } + public virtual byte[] BinaryProp { get; set; } + + public virtual string StringClob { get; set; } + public virtual byte[] BinaryBlob { get; set; } + } + + [TestFixture] + public class SqlServerCeDriverFixture : TestCase + { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override IList Mappings + { + get { return new[] { "DriverTest.SqlServerCeEntity.hbm.xml" }; } + } + + protected override bool AppliesTo(Dialect.Dialect dialect) + { + return dialect is MsSqlCeDialect; + } + + protected override void OnTearDown() + { + base.OnTearDown(); + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Delete("from SqlServerCeEntity"); + tx.Commit(); + } + } + + [Test] + public void SaveLoad() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + SqlServerCeEntity entity = new SqlServerCeEntity(); + entity.StringProp = "a small string"; + entity.BinaryProp = new byte[100]; + + entity.StringClob = new String('a', 8193); + entity.BinaryBlob = new byte[8193]; + + s.Save(entity); + tx.Commit(); + } + + using (ISession s = OpenSession()) + { + SqlServerCeEntity entity = + s.CreateCriteria(typeof(SqlServerCeEntity)) + .UniqueResult<SqlServerCeEntity>(); + + Assert.That(entity.StringProp, Is.EqualTo("a small string")); + Assert.That(entity.BinaryProp.Length, Is.EqualTo(100)); + + Assert.That(entity.StringClob, Is.EqualTo(new String('a', 8193))); + Assert.That(entity.BinaryBlob.Length, Is.EqualTo(8193)); + } + } + + [Test] + public void Query() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + SqlServerCeEntity entity = new SqlServerCeEntity(); + entity.StringProp = "a small string"; + entity.BinaryProp = System.Text.ASCIIEncoding.ASCII.GetBytes("binary string"); + + entity.StringClob = new String('a', 8193); + entity.BinaryBlob = new byte[8193]; + + s.Save(entity); + tx.Commit(); + } + + using (ISession s = OpenSession()) + { + IList<SqlServerCeEntity> entities = + s.CreateCriteria(typeof(SqlServerCeEntity)) + .Add(Restrictions.Eq("StringProp", "a small string")) + .Add(Restrictions.Eq("BinaryProp", System.Text.ASCIIEncoding.ASCII.GetBytes("binary string"))) + .List<SqlServerCeEntity>(); + + Assert.That(entities.Count, Is.EqualTo(1)); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeEntity.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeEntity.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeEntity.hbm.xml 2009-10-08 17:50:58 UTC (rev 4741) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.DriverTest" + assembly="NHibernate.Test"> + + <class name="SqlServerCeEntity"> + <id name="Id"> + <generator class="native" /> + </id> + + <property name="StringProp"/> <!-- maps to NVARCHAR(255) --> + <property name="BinaryProp"/> <!-- maps to VARBINARY(8000) --> + + <property name="StringClob" type="StringClob"> + <column name="StringClob" sql-type="ntext"/> + </property> + + <property name="BinaryBlob" type="BinaryBlob"> + <column name="BinaryBlob" sql-type="image"/> + </property> + + </class> +</hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-08 17:50:20 UTC (rev 4740) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-08 17:50:58 UTC (rev 4741) @@ -160,6 +160,7 @@ <Compile Include="Criteria\ProjectionsTest.cs" /> <Compile Include="Criteria\Reptile.cs" /> <Compile Include="DriverTest\SqlClientDriverFixture.cs" /> + <Compile Include="DriverTest\SqlServerCeDriverFixture.cs" /> <Compile Include="ExpressionTest\RestrictionsFixture.cs" /> <Compile Include="Criteria\Student.cs" /> <Compile Include="Criteria\StudentDTO.cs" /> @@ -2029,6 +2030,7 @@ <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> <EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" /> <EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" /> + <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> <EmbeddedResource Include="NHSpecificTest\NH1959\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1948\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-10-08 17:50:32
|
Revision: 4740 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4740&view=rev Author: ricbrown Date: 2009-10-08 17:50:20 +0000 (Thu, 08 Oct 2009) Log Message: ----------- Fix NH-1964, NH-1983, Blobs and Clobs with Sql Server CE Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Driver/SqlServerCeDriver.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeDriverFixture.cs branches/2.1.x/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeEntity.hbm.xml Modified: branches/2.1.x/nhibernate/src/NHibernate/Driver/SqlServerCeDriver.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Driver/SqlServerCeDriver.cs 2009-10-01 12:44:34 UTC (rev 4739) +++ branches/2.1.x/nhibernate/src/NHibernate/Driver/SqlServerCeDriver.cs 2009-10-08 17:50:20 UTC (rev 4740) @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Data; +using System.Reflection; using NHibernate.Cfg; using NHibernate.SqlCommand; using NHibernate.SqlTypes; @@ -24,11 +25,18 @@ } private bool prepareSql; + private PropertyInfo dbParamSqlDbTypeProperty; public override void Configure(IDictionary<string, string> settings) { base.Configure(settings); prepareSql = PropertiesHelper.GetBoolean(Environment.PrepareSql, settings, false); + + using (IDbCommand cmd = CreateCommand()) + { + IDbDataParameter dbParam = cmd.CreateParameter(); + dbParamSqlDbTypeProperty = dbParam.GetType().GetProperty("SqlDbType"); + } } /// <summary> @@ -94,5 +102,24 @@ { get { return true; } } + + protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType) + { + base.InitializeParameter(dbParam, name, sqlType); + + AdjustDbParamTypeForLargeObjects(dbParam, sqlType); + } + + private void AdjustDbParamTypeForLargeObjects(IDbDataParameter dbParam, SqlType sqlType) + { + if (sqlType is BinaryBlobSqlType) + { + dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.Image, null); + } + else if (sqlType is StringClobSqlType) + { + dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.NText, null); + } + } } } \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeDriverFixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeDriverFixture.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeDriverFixture.cs 2009-10-08 17:50:20 UTC (rev 4740) @@ -0,0 +1,112 @@ +using System; +using System.Collections; +using NHibernate.Cfg; +using NHibernate.Dialect; +using NUnit.Framework; +using NHibernate.Criterion; +using System.Collections.Generic; + +namespace NHibernate.Test.DriverTest +{ + public class SqlServerCeEntity + { + public virtual int Id { get; set; } + + public virtual string StringProp { get; set; } + public virtual byte[] BinaryProp { get; set; } + + public virtual string StringClob { get; set; } + public virtual byte[] BinaryBlob { get; set; } + } + + [TestFixture] + public class SqlServerCeDriverFixture : TestCase + { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override IList Mappings + { + get { return new[] { "DriverTest.SqlServerCeEntity.hbm.xml" }; } + } + + protected override bool AppliesTo(Dialect.Dialect dialect) + { + return dialect is MsSqlCeDialect; + } + + protected override void OnTearDown() + { + base.OnTearDown(); + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Delete("from SqlServerCeEntity"); + tx.Commit(); + } + } + + [Test] + public void SaveLoad() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + SqlServerCeEntity entity = new SqlServerCeEntity(); + entity.StringProp = "a small string"; + entity.BinaryProp = new byte[100]; + + entity.StringClob = new String('a', 8193); + entity.BinaryBlob = new byte[8193]; + + s.Save(entity); + tx.Commit(); + } + + using (ISession s = OpenSession()) + { + SqlServerCeEntity entity = + s.CreateCriteria(typeof(SqlServerCeEntity)) + .UniqueResult<SqlServerCeEntity>(); + + Assert.That(entity.StringProp, Is.EqualTo("a small string")); + Assert.That(entity.BinaryProp.Length, Is.EqualTo(100)); + + Assert.That(entity.StringClob, Is.EqualTo(new String('a', 8193))); + Assert.That(entity.BinaryBlob.Length, Is.EqualTo(8193)); + } + } + + [Test] + public void Query() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + SqlServerCeEntity entity = new SqlServerCeEntity(); + entity.StringProp = "a small string"; + entity.BinaryProp = System.Text.ASCIIEncoding.ASCII.GetBytes("binary string"); + + entity.StringClob = new String('a', 8193); + entity.BinaryBlob = new byte[8193]; + + s.Save(entity); + tx.Commit(); + } + + using (ISession s = OpenSession()) + { + IList<SqlServerCeEntity> entities = + s.CreateCriteria(typeof(SqlServerCeEntity)) + .Add(Restrictions.Eq("StringProp", "a small string")) + .Add(Restrictions.Eq("BinaryProp", System.Text.ASCIIEncoding.ASCII.GetBytes("binary string"))) + .List<SqlServerCeEntity>(); + + Assert.That(entities.Count, Is.EqualTo(1)); + } + } + } +} \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeEntity.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeEntity.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/DriverTest/SqlServerCeEntity.hbm.xml 2009-10-08 17:50:20 UTC (rev 4740) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.DriverTest" + assembly="NHibernate.Test"> + + <class name="SqlServerCeEntity"> + <id name="Id"> + <generator class="native" /> + </id> + + <property name="StringProp"/> <!-- maps to NVARCHAR(255) --> + <property name="BinaryProp"/> <!-- maps to VARBINARY(8000) --> + + <property name="StringClob" type="StringClob"> + <column name="StringClob" sql-type="ntext"/> + </property> + + <property name="BinaryBlob" type="BinaryBlob"> + <column name="BinaryBlob" sql-type="image"/> + </property> + + </class> +</hibernate-mapping> Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-01 12:44:34 UTC (rev 4739) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-08 17:50:20 UTC (rev 4740) @@ -105,6 +105,7 @@ <Compile Include="CfgTest\ConfigurationSchemaFixture.cs" /> <Compile Include="CfgTest\ConfigurationSerializationTests.cs" /> <Compile Include="CfgTest\DefaultNsAssmFixture.cs" /> + <Compile Include="DriverTest\SqlServerCeDriverFixture.cs" /> <Compile Include="FilterTest\ConfigFixture.cs" /> <Compile Include="FilterTest\FilterSecondPassArgsFixture.cs" /> <Compile Include="CfgTest\HbmBinderFixture.cs" /> @@ -1992,6 +1993,7 @@ <EmbeddedResource Include="Classic\EntityWithLifecycle.hbm.xml" /> <EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" /> <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> + <EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> <EmbeddedResource Include="NHSpecificTest\NH1959\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1948\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-02 03:19:35
|
Revision: 4738 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4738&view=rev Author: darioquintana Date: 2009-10-01 12:35:54 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Minor: test changed to explicit Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/FileStreamSql2008/Fixture.cs Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/FileStreamSql2008/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/FileStreamSql2008/Fixture.cs 2009-10-01 12:29:45 UTC (rev 4737) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/FileStreamSql2008/Fixture.cs 2009-10-01 12:35:54 UTC (rev 4738) @@ -10,7 +10,7 @@ /// Workaround to use FileStream feature /// http://blogs.msdn.com/manisblog/archive/2007/10/21/filestream-data-type-sql-server-2008.aspx /// </summary> - [TestFixture] + [TestFixture, Explicit] public class Fixture : TestCase { protected override IList Mappings This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-01 22:16:03
|
Revision: 4739 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4739&view=rev Author: darioquintana Date: 2009-10-01 12:44:34 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Minor: test changed to explicit Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/FileStreamSql2008/Fixture.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/FileStreamSql2008/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/FileStreamSql2008/Fixture.cs 2009-10-01 12:35:54 UTC (rev 4738) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/FileStreamSql2008/Fixture.cs 2009-10-01 12:44:34 UTC (rev 4739) @@ -10,7 +10,7 @@ /// Workaround to use FileStream feature /// http://blogs.msdn.com/manisblog/archive/2007/10/21/filestream-data-type-sql-server-2008.aspx /// </summary> - [TestFixture] + [TestFixture, Explicit] public class Fixture : TestCase { protected override IList Mappings This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-10-01 13:40:43
|
Revision: 4737 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4737&view=rev Author: ricbrown Date: 2009-10-01 12:29:45 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Merge r4736 (Fix NH-1915, throw correct exception when joining on invalid path) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs 2009-10-01 12:29:05 UTC (rev 4736) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs 2009-10-01 12:29:45 UTC (rev 4737) @@ -679,6 +679,12 @@ dot.Resolve( true, false, alias == null ? null : alias.Text ); FromElement fromElement = dot.GetImpliedJoin(); + + if (fromElement == null) + { + throw new InvalidPathException("Invalid join: " + dot.Path); + } + fromElement.SetAllPropertyFetch(propertyFetch!=null); if ( with != null ) Modified: trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs 2009-10-01 12:29:05 UTC (rev 4736) +++ trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs 2009-10-01 12:29:45 UTC (rev 4737) @@ -1,6 +1,7 @@ using System; using System.Collections; using NHibernate.Engine.Query; +using NHibernate.Hql.Ast.ANTLR; using NHibernate.Util; using NUnit.Framework; @@ -131,5 +132,20 @@ s.CreateQuery(string.Format("from SimpleClass sc where sc.LongValue = {0}", int.MaxValue + 1L)).List(); } } + + [Test] + public void InvalidJoinOnProperty() + { + // NH-1915 + using (ISession s = OpenSession()) + { + Assert.Throws<InvalidPathException>( + () => + { + s.CreateQuery("from Zoo z inner join fetch z.classification").List(); + }, + "Incorrect path not caught during parsing"); + } + } } } \ 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: <ric...@us...> - 2009-10-01 13:40:01
|
Revision: 4736 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4736&view=rev Author: ricbrown Date: 2009-10-01 12:29:05 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Fix NH-1915, throw correct exception when joining on invalid path Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs branches/2.1.x/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs 2009-10-01 10:02:34 UTC (rev 4735) +++ branches/2.1.x/nhibernate/src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs 2009-10-01 12:29:05 UTC (rev 4736) @@ -679,6 +679,12 @@ dot.Resolve( true, false, alias == null ? null : alias.Text ); FromElement fromElement = dot.GetImpliedJoin(); + + if (fromElement == null) + { + throw new InvalidPathException("Invalid join: " + dot.Path); + } + fromElement.SetAllPropertyFetch(propertyFetch!=null); if ( with != null ) Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs 2009-10-01 10:02:34 UTC (rev 4735) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs 2009-10-01 12:29:05 UTC (rev 4736) @@ -1,6 +1,7 @@ using System; using System.Collections; using NHibernate.Engine.Query; +using NHibernate.Hql.Ast.ANTLR; using NHibernate.Util; using NUnit.Framework; @@ -131,5 +132,20 @@ s.CreateQuery(string.Format("from SimpleClass sc where sc.LongValue = {0}", int.MaxValue + 1L)).List(); } } + + [Test] + public void InvalidJoinOnProperty() + { + // NH-1915 + using (ISession s = OpenSession()) + { + Assert.Throws<InvalidPathException>( + () => + { + s.CreateQuery("from Zoo z inner join fetch z.classification").List(); + }, + "Incorrect path not caught during parsing"); + } + } } } \ 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: <ric...@us...> - 2009-10-01 10:02:47
|
Revision: 4735 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4735&view=rev Author: ricbrown Date: 2009-10-01 10:02:34 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Added arbitrary IProjection to IQueryOver (allows protected properties, and eventual lambda-expression overloads for projections). Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-09-30 13:56:12 UTC (rev 4734) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-10-01 10:02:34 UTC (rev 4735) @@ -83,6 +83,12 @@ return this; } + public QueryOver<T> Select(params IProjection[] projections) + { + _criteria.SetProjection(projections); + return this; + } + public QueryOverOrderBuilder<T> OrderBy(Expression<Func<T, object>> path) { return new QueryOverOrderBuilder<T>(this, path); @@ -346,6 +352,9 @@ IQueryOver<T> IQueryOver<T>.Select(params Expression<Func<T, object>>[] projections) { return Select(projections); } + IQueryOver<T> IQueryOver<T>.Select(params IProjection[] projections) + { return Select(projections); } + IQueryOverOrderBuilder<T> IQueryOver<T>.OrderBy(Expression<Func<T, object>> path) { return new IQueryOverOrderBuilder<T>(this, path); } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-09-30 13:56:12 UTC (rev 4734) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-10-01 10:02:34 UTC (rev 4735) @@ -75,6 +75,11 @@ IQueryOver<T> Select(params Expression<Func<T, object>>[] projections); /// <summary> + /// Add arbitrary IProjections to query + /// </summary> + IQueryOver<T> Select(params IProjection[] projections); + + /// <summary> /// Add order expressed as a lambda expression /// </summary> /// <param name="path">Lambda expression</param> Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-09-30 13:56:12 UTC (rev 4734) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-10-01 10:02:34 UTC (rev 4735) @@ -122,11 +122,13 @@ { ICriteria expected = CreateTestCriteria(typeof(Person)) + .SetProjection(Projections.Property("Name")) .Add(Restrictions.Eq("Name", "test name")) .Add(Restrictions.Not(Restrictions.Eq("Name", "not test name"))); IQueryOver<Person> actual = CreateTestQueryOver<Person>() + .Select(Projections.Property("Name")) .Where(Restrictions.Eq("Name", "test name")) .And(Restrictions.Not(Restrictions.Eq("Name", "not test name"))); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-30 13:56:20
|
Revision: 4734 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4734&view=rev Author: ricbrown Date: 2009-09-30 13:56:12 +0000 (Wed, 30 Sep 2009) Log Message: ----------- Added UniqueResult and Futures to IQueryOver. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/FutureQueryOverFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-09-30 10:29:35 UTC (rev 4733) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-09-30 13:56:12 UTC (rev 4734) @@ -258,6 +258,36 @@ return _criteria.List<U>(); } + public T UniqueResult() + { + return _criteria.UniqueResult<T>(); + } + + public U UniqueResult<U>() + { + return _criteria.UniqueResult<U>(); + } + + IEnumerable<T> Future() + { + return _criteria.Future<T>(); + } + + IEnumerable<U> Future<U>() + { + return _criteria.Future<U>(); + } + + IFutureValue<T> FutureValue() + { + return _criteria.FutureValue<T>(); + } + + IFutureValue<U> FutureValue<U>() + { + return _criteria.FutureValue<U>(); + } + /// <summary> /// Get an executable instance of <c>IQueryOver<T></c>, /// to actually run the query.</summary> @@ -400,6 +430,24 @@ IList<U> IQueryOver<T>.List<U>() { return List<U>(); } + T IQueryOver<T>.UniqueResult() + { return UniqueResult(); } + + U IQueryOver<T>.UniqueResult<U>() + { return UniqueResult<U>(); } + + IEnumerable<T> IQueryOver<T>.Future() + { return Future(); } + + IEnumerable<U> IQueryOver<T>.Future<U>() + { return Future<U>(); } + + IFutureValue<T> IQueryOver<T>.FutureValue() + { return FutureValue(); } + + IFutureValue<U> IQueryOver<T>.FutureValue<U>() + { return FutureValue<U>(); } + } } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-09-30 10:29:35 UTC (rev 4733) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-09-30 13:56:12 UTC (rev 4734) @@ -259,6 +259,49 @@ /// <returns>The list filled with the results.</returns> IList<U> List<U>(); + /// <summary> + /// Convenience method to return a single instance that matches + /// the query, or null if the query returns no results. + /// </summary> + /// <returns>the single result or <see langword="null" /></returns> + /// <exception cref="HibernateException"> + /// If there is more than one matching result + /// </exception> + T UniqueResult(); + + /// <summary> + /// Override type of <see cref="UniqueResult()" />. + /// </summary> + U UniqueResult<U>(); + + /// <summary> + /// Get a enumerable that when enumerated will execute + /// a batch of queries in a single database roundtrip + /// </summary> + IEnumerable<T> Future(); + + /// <summary> + /// Get a enumerable that when enumerated will execute + /// a batch of queries in a single database roundtrip + /// </summary> + IEnumerable<U> Future<U>(); + + /// <summary> + /// Get an IFutureValue instance, whose value can be retrieved through + /// its Value property. The query is not executed until the Value property + /// is retrieved, which will execute other Future queries as well in a + /// single roundtrip + /// </summary> + IFutureValue<T> FutureValue(); + + /// <summary> + /// Get an IFutureValue instance, whose value can be retrieved through + /// its Value property. The query is not executed until the Value property + /// is retrieved, which will execute other Future queries as well in a + /// single roundtrip + /// </summary> + IFutureValue<U> FutureValue<U>(); + } } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2009-09-30 10:29:35 UTC (rev 4733) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/IntegrationFixture.cs 2009-09-30 13:56:12 UTC (rev 4734) @@ -145,6 +145,36 @@ } } + [Test] + public void UniqueResult() + { + using (ISession s = OpenSession()) + using (ITransaction t = s.BeginTransaction()) + { + s.Save(new Person() { Name = "test person 1", Age = 20 }); + t.Commit(); + } + + using (ISession s = OpenSession()) + { + Person actual = + s.QueryOver<Person>() + .UniqueResult(); + + Assert.That(actual.Name, Is.EqualTo("test person 1")); + } + + using (ISession s = OpenSession()) + { + string actual = + s.QueryOver<Person>() + .Select(p => p.Name) + .UniqueResult<string>(); + + Assert.That(actual, Is.EqualTo("test person 1")); + } + } + } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/FutureQueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/FutureQueryOverFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Futures/FutureQueryOverFixture.cs 2009-09-30 13:56:12 UTC (rev 4734) @@ -0,0 +1,132 @@ +using NHibernate.Criterion; +using NHibernate.Impl; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.Futures +{ + [TestFixture] + public class FutureQueryOverFixture : FutureFixture + { + + protected override void OnSetUp() + { + base.OnSetUp(); + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(new Person()); + tx.Commit(); + } + } + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Delete("from Person"); + tx.Commit(); + } + } + + [Test] + public void CanUseFutureCriteria() + { + using (var s = sessions.OpenSession()) + { + IgnoreThisTestIfMultipleQueriesArentSupportedByDriver(); + + var persons10 = s.QueryOver<Person>() + .Take(10) + .Future(); + var persons5 = s.QueryOver<Person>() + .Select(p => p.Id) + .Take(5) + .Future<int>(); + + using (var logSpy = new SqlLogSpy()) + { + int actualPersons5Count = 0; + foreach (var person in persons5) + actualPersons5Count++; + + int actualPersons10Count = 0; + foreach (var person in persons10) + actualPersons10Count++; + + var events = logSpy.Appender.GetEvents(); + Assert.AreEqual(1, events.Length); + + Assert.That(actualPersons5Count, Is.EqualTo(1)); + Assert.That(actualPersons10Count, Is.EqualTo(1)); + } + } + } + + [Test] + public void TwoFuturesRunInTwoRoundTrips() + { + using (var s = sessions.OpenSession()) + { + IgnoreThisTestIfMultipleQueriesArentSupportedByDriver(); + + using (var logSpy = new SqlLogSpy()) + { + var persons10 = s.QueryOver<Person>() + .Take(10) + .Future(); + + foreach (var person in persons10) { } // fire first future round-trip + + var persons5 = s.QueryOver<Person>() + .Select(p => p.Id) + .Take(5) + .Future<int>(); + + foreach (var person in persons5) { } // fire second future round-trip + + var events = logSpy.Appender.GetEvents(); + Assert.AreEqual(2, events.Length); + } + } + } + + [Test] + public void CanCombineSingleFutureValueWithEnumerableFutures() + { + using (var s = sessions.OpenSession()) + { + IgnoreThisTestIfMultipleQueriesArentSupportedByDriver(); + + var persons = s.QueryOver<Person>() + .Take(10) + .Future(); + + var personIds = s.QueryOver<Person>() + .Select(p => p.Id) + .FutureValue<int>(); + + var singlePerson = s.QueryOver<Person>() + .FutureValue(); + + using (var logSpy = new SqlLogSpy()) + { + Person singlePersonValue = singlePerson.Value; + int personId = personIds.Value; + + foreach (var person in persons) + { + + } + + var events = logSpy.Appender.GetEvents(); + Assert.AreEqual(1, events.Length); + + Assert.That(singlePersonValue, Is.Not.Null); + Assert.That(personId, Is.Not.EqualTo(0)); + } + } + } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-30 10:29:35 UTC (rev 4733) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-30 13:56:12 UTC (rev 4734) @@ -390,6 +390,7 @@ <Compile Include="NHSpecificTest\ElementsEnums\IntEnumsBagPartialNameFixture.cs" /> <Compile Include="NHSpecificTest\ElementsEnums\IntEnumsBagFixture.cs" /> <Compile Include="NHSpecificTest\ElementsEnums\Something.cs" /> + <Compile Include="NHSpecificTest\Futures\FutureQueryOverFixture.cs" /> <Compile Include="NHSpecificTest\NH1922\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1922\Model.cs" /> <Compile Include="NHSpecificTest\NH1927\Fixture.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-30 10:29:49
|
Revision: 4733 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4733&view=rev Author: ricbrown Date: 2009-09-30 10:29:35 +0000 (Wed, 30 Sep 2009) Log Message: ----------- Added arbitrary ICriterion to IQueryOver (allows protected properties, and eventual lambda-expression overloads for criterion). Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-09-30 09:40:08 UTC (rev 4732) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-09-30 10:29:35 UTC (rev 4733) @@ -52,6 +52,11 @@ return Add(expression); } + public QueryOver<T> And(ICriterion expression) + { + return Add(expression); + } + public QueryOver<T> Where(Expression<Func<T, bool>> expression) { return Add(expression); @@ -62,6 +67,11 @@ return Add(expression); } + public QueryOver<T> Where(ICriterion expression) + { + return Add(expression); + } + public QueryOver<T> Select(params Expression<Func<T, object>>[] projections) { List<IProjection> projectionList = new List<IProjection>(); @@ -275,7 +285,13 @@ return this; } + private QueryOver<T> Add(ICriterion expression) + { + _criteria.Add(expression); + return this; + } + ICriteria IQueryOver<T>.UnderlyingCriteria { get { return UnderlyingCriteria; } } @@ -285,12 +301,18 @@ IQueryOver<T> IQueryOver<T>.And(Expression<Func<bool>> expression) { return And(expression); } + IQueryOver<T> IQueryOver<T>.And(ICriterion expression) + { return And(expression); } + IQueryOver<T> IQueryOver<T>.Where(Expression<Func<T, bool>> expression) { return Where(expression); } IQueryOver<T> IQueryOver<T>.Where(Expression<Func<bool>> expression) { return Where(expression); } + IQueryOver<T> IQueryOver<T>.Where(ICriterion expression) + { return Where(expression); } + IQueryOver<T> IQueryOver<T>.Select(params Expression<Func<T, object>>[] projections) { return Select(projections); } Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-09-30 09:40:08 UTC (rev 4732) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-09-30 10:29:35 UTC (rev 4733) @@ -44,6 +44,11 @@ IQueryOver<T> And(Expression<Func<bool>> expression); /// <summary> + /// Add arbitrary ICriterion (e.g., to allow protected member access) + /// </summary> + IQueryOver<T> And(ICriterion expression); + + /// <summary> /// Identical semantics to Add() to allow more readable queries /// </summary> /// <param name="expression">Lambda expression</param> @@ -58,6 +63,11 @@ IQueryOver<T> Where(Expression<Func<bool>> expression); /// <summary> + /// Add arbitrary ICriterion (e.g., to allow protected member access) + /// </summary> + IQueryOver<T> Where(ICriterion expression); + + /// <summary> /// Add projection expressed as a lambda expression /// </summary> /// <param name="projections">Lambda expressions</param> Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-09-30 09:40:08 UTC (rev 4732) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-09-30 10:29:35 UTC (rev 4733) @@ -118,6 +118,22 @@ } [Test] + public void PrivateProperties() + { + ICriteria expected = + CreateTestCriteria(typeof(Person)) + .Add(Restrictions.Eq("Name", "test name")) + .Add(Restrictions.Not(Restrictions.Eq("Name", "not test name"))); + + IQueryOver<Person> actual = + CreateTestQueryOver<Person>() + .Where(Restrictions.Eq("Name", "test name")) + .And(Restrictions.Not(Restrictions.Eq("Name", "not test name"))); + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] public void SimpleCriterion_AliasReferenceSyntax() { ICriteria expected = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-30 09:40:15
|
Revision: 4732 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4732&view=rev Author: ricbrown Date: 2009-09-30 09:40:08 +0000 (Wed, 30 Sep 2009) Log Message: ----------- Added IQueryOver.Lock(...) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs trunk/nhibernate/src/NHibernate/IQueryOver.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Criterion/QueryOverLockBuilder.cs Modified: trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-09-28 17:04:14 UTC (rev 4731) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOver.cs 2009-09-30 09:40:08 UTC (rev 4732) @@ -128,6 +128,16 @@ return new QueryOverFetchBuilder<T>(this, path); } + public QueryOverLockBuilder<T> Lock() + { + return new QueryOverLockBuilder<T>(this, null); + } + + public QueryOverLockBuilder<T> Lock(Expression<Func<object>> alias) + { + return new QueryOverLockBuilder<T>(this, alias); + } + public QueryOver<U> JoinQueryOver<U>(Expression<Func<T, U>> path) { return new QueryOver<U>(_impl, @@ -314,6 +324,12 @@ IQueryOverFetchBuilder<T> IQueryOver<T>.Fetch(Expression<Func<T, object>> path) { return new IQueryOverFetchBuilder<T>(this, path); } + IQueryOverLockBuilder<T> IQueryOver<T>.Lock() + { return new IQueryOverLockBuilder<T>(this, null); } + + IQueryOverLockBuilder<T> IQueryOver<T>.Lock(Expression<Func<object>> alias) + { return new IQueryOverLockBuilder<T>(this, alias); } + IQueryOver<U> IQueryOver<T>.JoinQueryOver<U>(Expression<Func<T, U>> path) { return JoinQueryOver(path); } Added: trunk/nhibernate/src/NHibernate/Criterion/QueryOverLockBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/QueryOverLockBuilder.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Criterion/QueryOverLockBuilder.cs 2009-09-30 09:40:08 UTC (rev 4732) @@ -0,0 +1,106 @@ + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; + +using NHibernate.Impl; +using NHibernate.SqlCommand; + +namespace NHibernate.Criterion +{ + + public class QueryOverLockBuilder<T> : QueryOverLockBuilderBase<QueryOver<T>, T> + { + + public QueryOverLockBuilder(QueryOver<T> root, Expression<Func<object>> alias) + : base(root, alias) { } + + } + + public class IQueryOverLockBuilder<T> : QueryOverLockBuilderBase<IQueryOver<T>, T> + { + + public IQueryOverLockBuilder(IQueryOver<T> root, Expression<Func<object>> alias) + : base(root, alias) { } + + } + + public class QueryOverLockBuilderBase<R, T> where R : IQueryOver<T> + { + + protected R root; + protected string alias; + + protected QueryOverLockBuilderBase(R root, Expression<Func<object>> alias) + { + this.root = root; + + if (alias != null) + this.alias = ExpressionProcessor.FindMemberExpression(alias.Body); + } + + private void SetLockMode(LockMode lockMode) + { + if (alias != null) + root.UnderlyingCriteria.SetLockMode(alias, lockMode); + else + root.UnderlyingCriteria.SetLockMode(lockMode); + } + + public R Force + { + get + { + SetLockMode(LockMode.Force); + return this.root; + } + } + + public R None + { + get + { + SetLockMode(LockMode.None); + return this.root; + } + } + + public R Read + { + get + { + SetLockMode(LockMode.Read); + return this.root; + } + } + + public R Upgrade + { + get + { + SetLockMode(LockMode.Upgrade); + return this.root; + } + } + + public R UpgradeNoWait + { + get + { + SetLockMode(LockMode.UpgradeNoWait); + return this.root; + } + } + + public R Write + { + get + { + SetLockMode(LockMode.Write); + return this.root; + } + } + + } + +} Modified: trunk/nhibernate/src/NHibernate/IQueryOver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-09-28 17:04:14 UTC (rev 4731) +++ trunk/nhibernate/src/NHibernate/IQueryOver.cs 2009-09-30 09:40:08 UTC (rev 4732) @@ -130,6 +130,16 @@ IQueryOverFetchBuilder<T> Fetch(Expression<Func<T, object>> path); /// <summary> + /// Set the lock mode of the current entity + /// </summary> + IQueryOverLockBuilder<T> Lock(); + + /// <summary> + /// Set the lock mode of the aliased entity + /// </summary> + IQueryOverLockBuilder<T> Lock(Expression<Func<object>> alias); + + /// <summary> /// Creates a new NHibernate.ICriteria<T>, "rooted" at the associated entity /// </summary> /// <typeparam name="U">Type of sub-criteria</typeparam> Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-09-28 17:04:14 UTC (rev 4731) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-09-30 09:40:08 UTC (rev 4732) @@ -507,6 +507,7 @@ <Compile Include="Criterion\IPropertyProjection.cs" /> <Compile Include="Criterion\QueryOverFetchBuilder.cs" /> <Compile Include="Criterion\QueryOverJoinBuilder.cs" /> + <Compile Include="Criterion\QueryOverLockBuilder.cs" /> <Compile Include="Criterion\QueryOverOrderBuilder.cs" /> <Compile Include="Dialect\MsSql2008Dialect.cs" /> <Compile Include="Dialect\InformixDialect0940.cs" /> Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-09-28 17:04:14 UTC (rev 4731) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-09-30 09:40:08 UTC (rev 4732) @@ -347,6 +347,35 @@ AssertCriteriaAreEqual(expected, actual); } + [Test] + public void LockAll() + { + ICriteria expected = + CreateTestCriteria(typeof(Person)) + .SetLockMode(LockMode.UpgradeNoWait); + + IQueryOver<Person> actual = + CreateTestQueryOver<Person>() + .Lock().UpgradeNoWait; + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] + public void LockAlias() + { + ICriteria expected = + CreateTestCriteria(typeof(Person), "personAlias") + .SetLockMode("personAlias", LockMode.UpgradeNoWait); + + Person personAlias = null; + IQueryOver<Person> actual = + CreateTestQueryOver<Person>(() => personAlias) + .Lock(() => personAlias).UpgradeNoWait; + + AssertCriteriaAreEqual(expected, actual); + } + } } \ 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: <ste...@us...> - 2009-09-28 17:04:24
|
Revision: 4731 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4731&view=rev Author: steverstrong Date: 2009-09-28 17:04:14 +0000 (Mon, 28 Sep 2009) Log Message: ----------- Changes to Linq execution to tie in with HQLQueryPlan caching Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs trunk/nhibernate/src/NHibernate/IQueryExpression.cs trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs trunk/nhibernate/src/NHibernate/Impl/QueryImpl.cs trunk/nhibernate/src/NHibernate/Linq/CommandData.cs trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/Linq/LinqTestCase.cs trunk/nhibernate/src/NHibernate.Test/Linq/ReadonlyTestCase.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlExpression.cs trunk/nhibernate/src/NHibernate/Linq/NhQueryExecutor.cs Modified: trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/Engine/Query/HQLQueryPlan.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -28,8 +28,9 @@ private readonly HashedSet<string> enabledFilterNames; private readonly bool shallow; + private IQueryExpression sourceQueryExpression; - public HQLQueryPlan(string hql, bool shallow, + public HQLQueryPlan(string hql, bool shallow, IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) : this(hql, (string) null, shallow, enabledFilters, factory) { @@ -110,6 +111,7 @@ protected internal HQLQueryPlan(string expressionStr, IQueryExpression queryExpression, string collectionRole, bool shallow, IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) { + sourceQueryExpression = queryExpression; sourceQuery = expressionStr; this.shallow = shallow; @@ -192,7 +194,12 @@ } } - private static ParameterMetadata BuildParameterMetadata(IParameterTranslations parameterTranslations, string hql) + public IQueryExpression QueryExpression + { + get { return sourceQueryExpression; } + } + + private static ParameterMetadata BuildParameterMetadata(IParameterTranslations parameterTranslations, string hql) { long start = DateTime.Now.Ticks; ParamLocationRecognizer recognizer = ParamLocationRecognizer.ParseLocations(hql); Modified: trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/Engine/Query/QueryPlanCache.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -86,6 +86,7 @@ log.Debug("unable to locate HQL query plan in cache; generating (" + expressionStr + ")"); } plan = new HQLQueryPlan(expressionStr, queryExpression, shallow, enabledFilters, factory); + planCache.Put(key, plan); } else { @@ -95,8 +96,6 @@ } } - planCache.Put(key, plan); - return plan; } Deleted: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlExpression.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlExpression.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Reflection; -using NHibernate.Hql.Ast.ANTLR; -using NHibernate.Hql.Ast.ANTLR.Tree; - -namespace NHibernate.Hql.Ast -{ - public class HqlExpression : IQueryExpression - { - private readonly IASTNode _node; - private readonly System.Type _type; - private readonly string _key; - - public HqlExpression(HqlQuery node, System.Type type) - { - _node = node.AstNode; - _type = type; - _key = _node.ToStringTree(); - } - - public IASTNode Translate(ISessionFactory sessionFactory) - { - return _node; - } - - public string Key - { - get { return _key; } - } - - public System.Type Type - { - get { return _type; } - } - } -} Modified: trunk/nhibernate/src/NHibernate/IQueryExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/IQueryExpression.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/IQueryExpression.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -1,4 +1,6 @@ +using NHibernate.Engine; using NHibernate.Hql.Ast.ANTLR.Tree; +using NHibernate.Impl; namespace NHibernate { @@ -7,5 +9,6 @@ IASTNode Translate(ISessionFactory sessionFactory); string Key { get; } System.Type Type { get; } + void SetQueryParametersPriorToExecute(QueryImpl impl); } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -252,8 +252,9 @@ using (new SessionIdLoggingContext(SessionId)) { CheckAndUpdateSessionStatus(); - QueryImpl query = new QueryImpl(queryExpression, this, - GetHQLQueryPlan(queryExpression, false).ParameterMetadata); + HQLQueryPlan queryPlan = GetHQLQueryPlan(queryExpression, false); + QueryImpl query = new QueryImpl(queryPlan.QueryExpression, this, + queryPlan.ParameterMetadata); query.SetComment("[expression]"); return query; } Modified: trunk/nhibernate/src/NHibernate/Impl/QueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/QueryImpl.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/Impl/QueryImpl.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -74,6 +74,7 @@ } else { + _queryExpression.SetQueryParametersPriorToExecute(this); return Session.List(_queryExpression, GetQueryParameters(namedParams)); } } Modified: trunk/nhibernate/src/NHibernate/Linq/CommandData.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/CommandData.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/Linq/CommandData.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -8,8 +8,10 @@ { public class CommandData { + private readonly NamedParameter[] _namedParameters; private readonly List<LambdaExpression> _itemTransformers; private readonly List<LambdaExpression> _listTransformers; + private readonly List<Action<IQuery>> _additionalCriteria; public CommandData(HqlQuery statement, NamedParameter[] namedParameters, List<LambdaExpression> itemTransformers, List<LambdaExpression> listTransformers, List<Action<IQuery>> additionalCriteria) { @@ -17,47 +19,29 @@ _listTransformers = listTransformers; Statement = statement; - NamedParameters = namedParameters; - AdditionalCriteria = additionalCriteria; + _namedParameters = namedParameters; + _additionalCriteria = additionalCriteria; } public HqlQuery Statement { get; private set; } - public NamedParameter[] NamedParameters { get; private set; } - public List<Action<IQuery>> AdditionalCriteria { get; set; } - - public System.Type QueryResultType { get; set; } - - public IQuery CreateQuery(ISession session, System.Type type) + public void SetParameters(IQuery query) { - var query = session.CreateQuery(new HqlExpression(Statement, type)); - - SetParameters(query); - - SetResultTransformer(query); - - AddAdditionalCriteria(query); - - return query; - } - - private void SetParameters(IQuery query) - { - foreach (var parameter in NamedParameters) + foreach (var parameter in _namedParameters) { query.SetParameter(parameter.Name, parameter.Value); } } - private void AddAdditionalCriteria(IQuery query) + public void AddAdditionalCriteria(IQuery query) { - foreach (var criteria in AdditionalCriteria) + foreach (var criteria in _additionalCriteria) { criteria(query); } } - private void SetResultTransformer(IQuery query) + public void SetResultTransformer(IQuery query) { var itemTransformer = MergeLambdas(_itemTransformers); var listTransformer = MergeLambdas(_listTransformers); Deleted: trunk/nhibernate/src/NHibernate/Linq/NhQueryExecutor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhQueryExecutor.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/Linq/NhQueryExecutor.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -1,39 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Remotion.Data.Linq; - -namespace NHibernate.Linq -{ - public class NhQueryExecutor : IQueryExecutor - { - private readonly ISession _session; - - public NhQueryExecutor(ISession session) - { - _session = session; - } - - // Executes a query with a scalar result, i.e. a query that ends with a result operator such as Count, Sum, or Average. - public T ExecuteScalar<T>(QueryModel queryModel) - { - return ExecuteCollection<T>(queryModel).Single(); - } - - // Executes a query with a single result object, i.e. a query that ends with a result operator such as First, Last, Single, Min, or Max. - public T ExecuteSingle<T>(QueryModel queryModel, bool returnDefaultWhenEmpty) - { - return returnDefaultWhenEmpty ? ExecuteCollection<T>(queryModel).SingleOrDefault() : ExecuteCollection<T>(queryModel).Single(); - } - - // Executes a query with a collection result. - public IEnumerable<T> ExecuteCollection<T>(QueryModel queryModel) - { - var commandData = QueryModelVisitor.GenerateHqlQuery(queryModel); - - var query = commandData.CreateQuery(_session, typeof(T)); - - // TODO - check which call on Query makes most sense... - return (IEnumerable<T>) query.List(); - } - } -} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/Linq/NhQueryable.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -1,6 +1,10 @@ +using System; using System.Linq; using System.Linq.Expressions; +using NHibernate.Hql.Ast.ANTLR.Tree; +using NHibernate.Impl; using Remotion.Data.Linq; +using Remotion.Data.Linq.Parsing.Structure; namespace NHibernate.Linq { @@ -9,14 +13,9 @@ /// </summary> public class NhQueryable<T> : QueryableBase<T> { - private static IQueryExecutor CreateExecutor(ISession session) - { - return new NhQueryExecutor(session); - } - // This constructor is called by our users, create a new IQueryExecutor. public NhQueryable(ISession session) - : base(CreateExecutor(session)) + : base(new NhQueryProvider(session)) { } @@ -26,4 +25,95 @@ { } } + + public class NhQueryProvider : IQueryProvider + { + private readonly ISession _session; + + public NhQueryProvider(ISession session) + { + _session = session; + } + + public object Execute(Expression expression) + { + var nhLinqExpression = new NhLinqExpression(expression); + + var query = _session.CreateQuery(nhLinqExpression).List(); + + if (nhLinqExpression.ReturnType == NhLinqExpressionReturnType.Sequence) + { + return query.AsQueryable(); + } + + return query[0]; + } + + public TResult Execute<TResult>(Expression expression) + { + return (TResult) Execute(expression); + } + + public IQueryable CreateQuery(Expression expression) + { + throw new NotImplementedException(); + } + + public IQueryable<T> CreateQuery<T>(Expression expression) + { + return new NhQueryable<T>(this, expression); + } + } + + public enum NhLinqExpressionReturnType + { + Sequence, + Scalar + } + + public class NhLinqExpression : IQueryExpression + { + private readonly Expression _expression; + private CommandData _commandData; + + public NhLinqExpression(Expression expression) + { + _expression = expression; + + Key = expression.ToString(); + + Type = expression.Type; + + // Note - re-linq handles return types via the GetOutputDataInfo method, and allows for SingleOrDefault here for the ChoiceResultOperator... + ReturnType = NhLinqExpressionReturnType.Scalar; + + if (typeof(IQueryable).IsAssignableFrom(Type)) + { + Type = Type.GetGenericArguments()[0]; + ReturnType = NhLinqExpressionReturnType.Sequence; + } + } + + public IASTNode Translate(ISessionFactory sessionFactory) + { + var queryModel = new QueryParser(new ExpressionTreeParser(MethodCallExpressionNodeTypeRegistry.CreateDefault())).GetParsedQuery(_expression); + + _commandData = QueryModelVisitor.GenerateHqlQuery(queryModel); + + return _commandData.Statement.AstNode; + } + + public string Key { get; private set; } + + public NhLinqExpressionReturnType ReturnType { get; private set; } + + public System.Type Type { get; private set; } + + public void SetQueryParametersPriorToExecute(QueryImpl impl) + { + _commandData.SetParameters(impl); + _commandData.SetResultTransformer(impl); + _commandData.AddAdditionalCriteria(impl); + } + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-09-28 17:04:14 UTC (rev 4731) @@ -557,7 +557,6 @@ <Compile Include="Hql\Ast\ANTLR\Tree\ASTErrorNode.cs" /> <Compile Include="Hql\Ast\ANTLR\Tree\InsertStatement.cs" /> <Compile Include="Hql\Ast\ANTLR\Tree\UpdateStatement.cs" /> - <Compile Include="Hql\Ast\HqlExpression.cs" /> <Compile Include="Hql\Ast\HqlTreeBuilder.cs" /> <Compile Include="Hql\Ast\HqlTreeNode.cs" /> <Compile Include="IQueryExpression.cs" /> @@ -581,7 +580,6 @@ <Compile Include="Linq\NhExpressionTreeVisitor.cs" /> <Compile Include="Linq\NhNewExpression.cs" /> <Compile Include="Linq\NhQueryable.cs" /> - <Compile Include="Linq\NhQueryExecutor.cs" /> <Compile Include="Linq\NhThrowingExpressionTreeVisitor.cs" /> <Compile Include="Linq\Nominator.cs" /> <Compile Include="Linq\NonAggregatingGroupBy.cs" /> Modified: trunk/nhibernate/src/NHibernate.Test/Linq/LinqTestCase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/LinqTestCase.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate.Test/Linq/LinqTestCase.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -13,6 +13,16 @@ private Northwind _northwind; private ISession _session; + protected override bool PerformDbDataSetup + { + get { return true; } + } + + protected override bool PerformDbDataTeardown + { + get { return true; } + } + protected override string MappingsAssembly { get { return "NHibernate.Test"; } Modified: trunk/nhibernate/src/NHibernate.Test/Linq/ReadonlyTestCase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/ReadonlyTestCase.cs 2009-09-27 10:06:52 UTC (rev 4730) +++ trunk/nhibernate/src/NHibernate.Test/Linq/ReadonlyTestCase.cs 2009-09-28 17:04:14 UTC (rev 4731) @@ -63,6 +63,9 @@ get { return "NHibernate.DomainModel"; } } + protected abstract bool PerformDbDataSetup { get; } + protected abstract bool PerformDbDataTeardown { get; } + static ReadonlyTestCase() { // Configure log4net here since configuration through an attribute doesn't always work. @@ -84,7 +87,12 @@ } BuildSessionFactory(); - CreateSchema(); + + if (PerformDbDataSetup) + { + CreateSchema(); + } + if (!AppliesTo(_sessions)) { DropSchema(); @@ -92,7 +100,10 @@ Assert.Ignore(GetType() + " does not apply with the current session-factory configuration"); } - OnFixtureSetup(); + if (PerformDbDataSetup) + { + OnFixtureSetup(); + } } catch (Exception e) { @@ -114,8 +125,12 @@ public void TestFixtureTearDown() { OnFixtureTeardown(); - - DropSchema(); + + if (PerformDbDataTeardown) + { + DropSchema(); + } + Cleanup(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-27 10:07:02
|
Revision: 4730 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4730&view=rev Author: ricbrown Date: 2009-09-27 10:06:52 +0000 (Sun, 27 Sep 2009) Log Message: ----------- Merge r4729 (Fix NH-1959, add/remove from IdBag causing KeyNotFoundException) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs Modified: trunk/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs 2009-09-27 10:06:11 UTC (rev 4729) +++ trunk/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs 2009-09-27 10:06:52 UTC (rev 4730) @@ -290,6 +290,9 @@ protected void BeforeRemove(int index) { + if (!identifiers.ContainsKey(index)) + return; // index not previously persisted, nothing to do + // Move the identifier being removed to the end of the list (i.e. it isn't actually removed). object removedId = identifiers[index]; int last = values.Count - 1; Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs 2009-09-27 10:06:52 UTC (rev 4730) @@ -0,0 +1,74 @@ +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1959 +{ + [TestFixture] + public class Fixture : BugTestCase + { + + protected override void OnTearDown() + { + using (ISession s = OpenSession()) + using(ITransaction tx = s.BeginTransaction()) + { + s.Delete("from ClassB"); + s.Delete("from ClassA"); + tx.Commit(); + } + } + + [Test] + public void StartWithEmptyDoAddAndRemove() + { + ClassB b = new ClassB(); + ClassA a = new ClassA(); + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(a); + s.Save(b); + tx.Commit(); + } + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + ClassA loadedA = s.Get<ClassA>(a.Id); + ClassB loadedB = s.Get<ClassB>(b.Id); + loadedA.TheBag.Add(loadedB); + loadedA.TheBag.Remove(loadedB); + tx.Commit(); + } + + using (ISession s = OpenSession()) + Assert.AreEqual(0, s.Get<ClassA>(a.Id).TheBag.Count); + } + + [Test] + public void StartWithEmptyDoAddAndRemoveAt() + { + ClassB b = new ClassB(); + ClassA a = new ClassA(); + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(a); + s.Save(b); + tx.Commit(); + } + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + ClassA loadedA = s.Get<ClassA>(a.Id); + ClassB loadedB = s.Get<ClassB>(b.Id); + loadedA.TheBag.Add(loadedB); + loadedA.TheBag.RemoveAt(0); + tx.Commit(); + } + + using (ISession s = OpenSession()) + Assert.AreEqual(0, s.Get<ClassA>(a.Id).TheBag.Count); + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml 2009-09-27 10:06:52 UTC (rev 4730) @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH1959" + assembly="NHibernate.Test"> + + <class name="ClassA"> + <id name="Id"> + <generator class="guid.comb"/> + </id> + <idbag name="TheBag"> + <collection-id column="collection_id" type="guid"> + <generator class="guid.comb"/> + </collection-id> + <key> + <column name="classA" not-null="true" /> + </key> + <many-to-many class="ClassB"> + <column name="classB" not-null="true" /> + </many-to-many> + </idbag> + </class> + + <class name="ClassB"> + <id name="Id"> + <generator class="guid.comb"/> + </id> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs 2009-09-27 10:06:52 UTC (rev 4730) @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH1959 +{ + public class ClassA + { + public virtual Guid Id { get; set; } + public virtual IList<ClassB> TheBag { get; set; } + + public ClassA() + { + TheBag = new List<ClassB>(); + } + } + + public class ClassB + { + public virtual Guid Id { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-27 10:06:11 UTC (rev 4729) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-27 10:06:52 UTC (rev 4730) @@ -608,6 +608,8 @@ <Compile Include="NHSpecificTest\NH1941\SexEnumStringType.cs" /> <Compile Include="NHSpecificTest\NH1948\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1948\Model.cs" /> + <Compile Include="NHSpecificTest\NH1959\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1959\Model.cs" /> <Compile Include="NHSpecificTest\NH1963\CacheableQueryOnByteArray.cs" /> <Compile Include="NHSpecificTest\NH1963\DomainClass.cs" /> <Compile Include="NHSpecificTest\NH1969\DummyEntity.cs" /> @@ -2027,6 +2029,7 @@ <EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" /> <EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1959\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1948\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1941\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1963\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-27 10:06:26
|
Revision: 4729 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4729&view=rev Author: ricbrown Date: 2009-09-27 10:06:11 +0000 (Sun, 27 Sep 2009) Log Message: ----------- Fix NH-1959, add/remove from IdBag causing KeyNotFoundException Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs 2009-09-26 12:07:41 UTC (rev 4728) +++ branches/2.1.x/nhibernate/src/NHibernate/Collection/PersistentIdentifierBag.cs 2009-09-27 10:06:11 UTC (rev 4729) @@ -290,6 +290,9 @@ protected void BeforeRemove(int index) { + if (!identifiers.ContainsKey(index)) + return; // index not previously persisted, nothing to do + // Move the identifier being removed to the end of the list (i.e. it isn't actually removed). object removedId = identifiers[index]; int last = values.Count - 1; Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Fixture.cs 2009-09-27 10:06:11 UTC (rev 4729) @@ -0,0 +1,74 @@ +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1959 +{ + [TestFixture] + public class Fixture : BugTestCase + { + + protected override void OnTearDown() + { + using (ISession s = OpenSession()) + using(ITransaction tx = s.BeginTransaction()) + { + s.Delete("from ClassB"); + s.Delete("from ClassA"); + tx.Commit(); + } + } + + [Test] + public void StartWithEmptyDoAddAndRemove() + { + ClassB b = new ClassB(); + ClassA a = new ClassA(); + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(a); + s.Save(b); + tx.Commit(); + } + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + ClassA loadedA = s.Get<ClassA>(a.Id); + ClassB loadedB = s.Get<ClassB>(b.Id); + loadedA.TheBag.Add(loadedB); + loadedA.TheBag.Remove(loadedB); + tx.Commit(); + } + + using (ISession s = OpenSession()) + Assert.AreEqual(0, s.Get<ClassA>(a.Id).TheBag.Count); + } + + [Test] + public void StartWithEmptyDoAddAndRemoveAt() + { + ClassB b = new ClassB(); + ClassA a = new ClassA(); + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(a); + s.Save(b); + tx.Commit(); + } + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + ClassA loadedA = s.Get<ClassA>(a.Id); + ClassB loadedB = s.Get<ClassB>(b.Id); + loadedA.TheBag.Add(loadedB); + loadedA.TheBag.RemoveAt(0); + tx.Commit(); + } + + using (ISession s = OpenSession()) + Assert.AreEqual(0, s.Get<ClassA>(a.Id).TheBag.Count); + } + } +} \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Mappings.hbm.xml 2009-09-27 10:06:11 UTC (rev 4729) @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH1959" + assembly="NHibernate.Test"> + + <class name="ClassA"> + <id name="Id"> + <generator class="guid.comb"/> + </id> + <idbag name="TheBag"> + <collection-id column="collection_id" type="guid"> + <generator class="guid.comb"/> + </collection-id> + <key> + <column name="classA" not-null="true" /> + </key> + <many-to-many class="ClassB"> + <column name="classB" not-null="true" /> + </many-to-many> + </idbag> + </class> + + <class name="ClassB"> + <id name="Id"> + <generator class="guid.comb"/> + </id> + </class> + +</hibernate-mapping> Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1959/Model.cs 2009-09-27 10:06:11 UTC (rev 4729) @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH1959 +{ + public class ClassA + { + public virtual Guid Id { get; set; } + public virtual IList<ClassB> TheBag { get; set; } + + public ClassA() + { + TheBag = new List<ClassB>(); + } + } + + public class ClassB + { + public virtual Guid Id { get; set; } + } +} Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-26 12:07:41 UTC (rev 4728) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-27 10:06:11 UTC (rev 4729) @@ -580,6 +580,8 @@ <Compile Include="NHSpecificTest\NH1941\SexEnumStringType.cs" /> <Compile Include="NHSpecificTest\NH1948\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1948\Model.cs" /> + <Compile Include="NHSpecificTest\NH1959\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1959\Model.cs" /> <Compile Include="NHSpecificTest\NH473\Child.cs" /> <Compile Include="NHSpecificTest\NH473\Fixture.cs" /> <Compile Include="NHSpecificTest\NH473\Parent.cs" /> @@ -1991,6 +1993,7 @@ <EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" /> <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1959\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1948\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1941\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1922\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-26 12:07:51
|
Revision: 4728 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4728&view=rev Author: ricbrown Date: 2009-09-26 12:07:41 +0000 (Sat, 26 Sep 2009) Log Message: ----------- Fix NH-1975, using primitive with QueryOver. Patch supplied by Ken Tong. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs Modified: trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2009-09-25 21:59:02 UTC (rev 4727) +++ trunk/nhibernate/src/NHibernate/Impl/ExpressionProcessor.cs 2009-09-26 12:07:41 UTC (rev 4728) @@ -261,6 +261,9 @@ if (type.IsEnum) return Enum.ToObject(type, value); + if (type.IsPrimitive) + return Convert.ChangeType(value, type); + throw new Exception("Cannot convert '" + value.ToString() + "' to " + type.ToString()); } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Mappings.hbm.xml 2009-09-25 21:59:02 UTC (rev 4727) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Mappings.hbm.xml 2009-09-26 12:07:41 UTC (rev 4728) @@ -9,6 +9,7 @@ </id> <property name="Name" /> <property name="Age" /> + <property name="Blood" /> </class> <class name="Child"> Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-09-25 21:59:02 UTC (rev 4727) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/Model.cs 2009-09-26 12:07:41 UTC (rev 4728) @@ -23,6 +23,7 @@ public virtual bool HasCar { get; set; } public virtual Person Father { get; set; } public virtual bool IsParent { get; set; } + public virtual char Blood { get; set; } public virtual IEnumerable<Child> Children { get; set; } public virtual IList<Person> PersonList { get; set; } Modified: trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-09-25 21:59:02 UTC (rev 4727) +++ trunk/nhibernate/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs 2009-09-26 12:07:41 UTC (rev 4728) @@ -67,6 +67,22 @@ } [Test] + public void SimpleCriterion_Char() + { + ICriteria expected = + CreateTestCriteria(typeof(Person)) + .Add(Restrictions.Eq("Blood", 'A')) + .Add(Restrictions.Not(Restrictions.Eq("Blood", 'B'))); + + IQueryOver<Person> actual = + CreateTestQueryOver<Person>() + .And(p => p.Blood == 'A') + .And(p => p.Blood != 'B'); + + AssertCriteriaAreEqual(expected, actual); + } + + [Test] public void MultipleCriterionExpression() { ICriteria expected = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ste...@us...> - 2009-09-25 21:59:08
|
Revision: 4727 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4727&view=rev Author: steverstrong Date: 2009-09-25 21:59:02 +0000 (Fri, 25 Sep 2009) Log Message: ----------- Fixed schoolboy error in the Linq tests :( Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/Linq/ReadonlyTestCase.cs Modified: trunk/nhibernate/src/NHibernate.Test/Linq/ReadonlyTestCase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Linq/ReadonlyTestCase.cs 2009-09-25 21:06:49 UTC (rev 4726) +++ trunk/nhibernate/src/NHibernate.Test/Linq/ReadonlyTestCase.cs 2009-09-25 21:59:02 UTC (rev 4727) @@ -84,7 +84,7 @@ } BuildSessionFactory(); - //CreateSchema(); + CreateSchema(); if (!AppliesTo(_sessions)) { DropSchema(); @@ -92,7 +92,7 @@ Assert.Ignore(GetType() + " does not apply with the current session-factory configuration"); } - //OnFixtureSetup(); + OnFixtureSetup(); } catch (Exception e) { @@ -115,7 +115,7 @@ { OnFixtureTeardown(); - //DropSchema(); + DropSchema(); Cleanup(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ste...@us...> - 2009-09-25 21:07:04
|
Revision: 4726 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4726&view=rev Author: steverstrong Date: 2009-09-25 21:06:49 +0000 (Fri, 25 Sep 2009) Log Message: ----------- Latest re-linq libraries Modified Paths: -------------- trunk/nhibernate/lib/net/3.5/Remotion.Data.Linq.dll trunk/nhibernate/lib/net/3.5/Remotion.Interfaces.dll trunk/nhibernate/lib/net/3.5/Remotion.dll Property Changed: ---------------- trunk/nhibernate/lib/net/ Property changes on: trunk/nhibernate/lib/net ___________________________________________________________________ Added: svn:ignore + 2.0 Modified: trunk/nhibernate/lib/net/3.5/Remotion.Data.Linq.dll =================================================================== (Binary files differ) Modified: trunk/nhibernate/lib/net/3.5/Remotion.Interfaces.dll =================================================================== (Binary files differ) Modified: trunk/nhibernate/lib/net/3.5/Remotion.dll =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ste...@us...> - 2009-09-25 21:05:16
|
Revision: 4725 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4725&view=rev Author: steverstrong Date: 2009-09-25 21:04:56 +0000 (Fri, 25 Sep 2009) Log Message: ----------- Further updates to the Linq provider Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupByRewriter.cs trunk/nhibernate/src/NHibernate/Linq/HqlGeneratorExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate/Linq/NhExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate/Linq/NhThrowingExpressionTreeVisitor.cs trunk/nhibernate/src/NHibernate/Linq/NonAggregatingGroupByRewriter.cs trunk/nhibernate/src/NHibernate/Linq/QueryModelVisitor.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/Linq/LinqQuerySamples.cs trunk/nhibernate/src/NHibernate.Test/Linq/ReadonlyTestCase.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupJoinRewriter.cs trunk/nhibernate/src/NHibernate/Linq/GroupByAggregateDetectionVisitor.cs trunk/nhibernate/src/NHibernate/Linq/GroupByKeySelectorVisitor.cs trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseRewriter.cs trunk/nhibernate/src/NHibernate/Linq/MergeAggregatingResultsRewriter.cs trunk/nhibernate/src/NHibernate/Linq/NhNewExpression.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate/Linq/AggregateDetectionVisitor.cs trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseVisitor.cs trunk/nhibernate/src/NHibernate/Linq/GroupBySelectorVisitor.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2009-09-24 11:22:59 UTC (rev 4724) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -100,6 +100,11 @@ return new HqlEquality(_factory); } + public HqlEquality Equality(HqlTreeNode lhs, HqlTreeNode rhs) + { + return new HqlEquality(_factory, lhs, rhs); + } + public HqlBooleanAnd BooleanAnd() { return new HqlBooleanAnd(_factory); Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2009-09-24 11:22:59 UTC (rev 4724) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -229,6 +229,11 @@ : base(HqlSqlWalker.EQ, "==", factory) { } + + public HqlEquality(IASTFactory factory, HqlTreeNode lhs, HqlTreeNode rhs) + : base(HqlSqlWalker.EQ, "==", factory, lhs, rhs) + { + } } public class HqlParameter : HqlTreeNode Deleted: trunk/nhibernate/src/NHibernate/Linq/AggregateDetectionVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/AggregateDetectionVisitor.cs 2009-09-24 11:22:59 UTC (rev 4724) +++ trunk/nhibernate/src/NHibernate/Linq/AggregateDetectionVisitor.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -1,54 +0,0 @@ -using System.Linq; -using System.Linq.Expressions; -using Remotion.Data.Linq.Clauses.Expressions; -using Remotion.Data.Linq.Clauses.ResultOperators; -using Remotion.Data.Linq.Parsing; - -namespace NHibernate.Linq -{ - // TODO: This needs strengthening. For example, it doesn't recurse into SubQueries at present - internal class AggregateDetectionVisitor : ExpressionTreeVisitor - { - public bool ContainsAggregateMethods { get; private set; } - - public bool Visit(Expression expression) - { - ContainsAggregateMethods = false; - - VisitExpression(expression); - - return ContainsAggregateMethods; - } - - protected override Expression VisitMethodCallExpression(MethodCallExpression m) - { - if (m.Method.DeclaringType == typeof (Queryable) || - m.Method.DeclaringType == typeof (Enumerable)) - { - switch (m.Method.Name) - { - case "Count": - case "Min": - case "Max": - case "Sum": - case "Average": - ContainsAggregateMethods = true; - break; - } - } - - return base.VisitMethodCallExpression(m); - } - - protected override Expression VisitSubQueryExpression(SubQueryExpression expression) - { - if (expression.QueryModel.ResultOperators.Count == 1 - && typeof(ValueFromSequenceResultOperatorBase).IsAssignableFrom(expression.QueryModel.ResultOperators[0].GetType())) - { - ContainsAggregateMethods = true; - } - - return base.VisitSubQueryExpression(expression); - } - } -} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupByRewriter.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupByRewriter.cs 2009-09-24 11:22:59 UTC (rev 4724) +++ trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupByRewriter.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -7,44 +7,55 @@ namespace NHibernate.Linq { - public class AggregatingGroupByRewriter : QueryModelVisitorBase + public class AggregatingGroupByRewriter { - public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel) + public void ReWrite(QueryModel queryModel) { - var subQueryExpression = fromClause.FromExpression as SubQueryExpression; + var subQueryExpression = queryModel.MainFromClause.FromExpression as SubQueryExpression; if ((subQueryExpression != null) && (subQueryExpression.QueryModel.ResultOperators.Count() == 1) && (subQueryExpression.QueryModel.ResultOperators[0] is GroupResultOperator) && (IsAggregatingGroupBy(queryModel))) { - FlattenSubQuery(subQueryExpression, fromClause, queryModel); + FlattenSubQuery(subQueryExpression, queryModel.MainFromClause, queryModel); } - - base.VisitMainFromClause(fromClause, queryModel); } private static bool IsAggregatingGroupBy(QueryModel queryModel) { - return new AggregateDetectionVisitor().Visit(queryModel.SelectClause.Selector); + return new GroupByAggregateDetectionVisitor().Visit(queryModel.SelectClause.Selector); } private void FlattenSubQuery(SubQueryExpression subQueryExpression, FromClauseBase fromClause, QueryModel queryModel) { + // Move the result operator up + if (queryModel.ResultOperators.Count != 0) + { + throw new NotImplementedException(); + } + + var groupBy = (GroupResultOperator) subQueryExpression.QueryModel.ResultOperators[0]; + // Replace the outer select clause... - queryModel.SelectClause.TransformExpressions(GroupBySelectClauseVisitor.Visit); + queryModel.SelectClause.TransformExpressions(s => GroupBySelectClauseRewriter.ReWrite(s, groupBy, subQueryExpression.QueryModel)); + queryModel.SelectClause.TransformExpressions( + s => + new SwapQuerySourceVisitor(queryModel.MainFromClause, subQueryExpression.QueryModel.MainFromClause).Swap + (s)); + + MainFromClause innerMainFromClause = subQueryExpression.QueryModel.MainFromClause; CopyFromClauseData(innerMainFromClause, fromClause); - // Move the result operator up - if (queryModel.ResultOperators.Count != 0) + foreach (var bodyClause in subQueryExpression.QueryModel.BodyClauses) { - throw new NotImplementedException(); + queryModel.BodyClauses.Add(bodyClause); } - queryModel.ResultOperators.Add(subQueryExpression.QueryModel.ResultOperators[0]); + queryModel.ResultOperators.Add(groupBy); } protected void CopyFromClauseData(FromClauseBase source, FromClauseBase destination) Added: trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupJoinRewriter.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupJoinRewriter.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Linq/AggregatingGroupJoinRewriter.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -0,0 +1,321 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using Remotion.Data.Linq; +using Remotion.Data.Linq.Clauses; +using Remotion.Data.Linq.Clauses.Expressions; + +namespace NHibernate.Linq +{ + public class AggregatingGroupJoinRewriter + { + public void ReWrite(QueryModel model) + { + // We want to take queries like this: + + //var q = + // from c in db.Customers + // join o in db.Orders on c.CustomerId equals o.Customer.CustomerId into ords + // join e in db.Employees on c.Address.City equals e.Address.City into emps + // select new { c.ContactName, ords = ords.Count(), emps = emps.Count() }; + + // and turn them into this: + + //var q = + // from c in db.Customers + // select new + // { + // c.ContactName, + // ords = (from o2 in db.Orders where o2.Customer.CustomerId == c.CustomerId select o2).Count(), + // emps = (from e2 in db.Employees where e2.Address.City == c.Address.City select e2).Count() + // }; + + // so spot a group join where every use of the grouping in the selector is an aggregate + + // firstly, get the group join clauses + var groupJoin = model.BodyClauses.Where(bc => bc is GroupJoinClause).Cast<GroupJoinClause>(); + + if (groupJoin.Count() == 0) + { + // No group join here.. + return; + } + + // Now walk the tree to decide which groupings are fully aggregated (and can hence be done in hql) + var aggregateDetectorResults = IsAggregatingGroupJoin(model, groupJoin); + + if (aggregateDetectorResults.AggregatingClauses.Count > 0) + { + // Re-write the select expression + model.SelectClause.TransformExpressions(s => GroupJoinSelectClauseRewriter.ReWrite(s, aggregateDetectorResults)); + + // Remove the aggregating group joins + foreach (GroupJoinClause aggregatingGroupJoin in aggregateDetectorResults.AggregatingClauses) + { + model.BodyClauses.Remove(aggregatingGroupJoin); + } + } + } + + private static IsAggregatingResults IsAggregatingGroupJoin(QueryModel model, IEnumerable<GroupJoinClause> clause) + { + return new GroupJoinAggregateDetectionVisitor(clause).Visit(model.SelectClause.Selector); + } + } + + public class GroupJoinSelectClauseRewriter : NhExpressionTreeVisitor + { + private readonly IsAggregatingResults _results; + + public static Expression ReWrite(Expression expression, IsAggregatingResults results) + { + return new GroupJoinSelectClauseRewriter(results).VisitExpression(expression); + } + + private GroupJoinSelectClauseRewriter(IsAggregatingResults results) + { + _results = results; + } + + protected override Expression VisitSubQueryExpression(SubQueryExpression expression) + { + // If the sub queries main (and only) from clause is one of our aggregating group bys, then swap it + GroupJoinClause groupJoin = LocateGroupJoinQuerySource(expression.QueryModel); + + if (groupJoin != null) + { + Expression innerSelector = new SwapQuerySourceVisitor(groupJoin.JoinClause, expression.QueryModel.MainFromClause). + Swap(groupJoin.JoinClause.InnerKeySelector); + + expression.QueryModel.MainFromClause.FromExpression = groupJoin.JoinClause.InnerSequence; + + + // TODO - this only works if the key selectors are not composite. Needs improvement... + expression.QueryModel.BodyClauses.Add(new WhereClause(Expression.Equal(innerSelector, groupJoin.JoinClause.OuterKeySelector))); + } + + return expression; + } + + private GroupJoinClause LocateGroupJoinQuerySource(QueryModel model) + { + if (model.BodyClauses.Count > 0) + { + return null; + } + return new LocateGroupJoinQuerySource(_results).Detect(model.MainFromClause.FromExpression); + } + } + + public class SwapQuerySourceVisitor : NhExpressionTreeVisitor + { + private readonly IQuerySource _oldClause; + private readonly IQuerySource _newClause; + + public SwapQuerySourceVisitor(IQuerySource oldClause, IQuerySource newClause) + { + _oldClause = oldClause; + _newClause = newClause; + } + + public Expression Swap(Expression expression) + { + return VisitExpression(expression); + } + + protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression) + { + if (expression.ReferencedQuerySource == _oldClause) + { + return new QuerySourceReferenceExpression(_newClause); + } + + // TODO - really don't like this drill down approach. Feels fragile + var mainFromClause = expression.ReferencedQuerySource as MainFromClause; + + if (mainFromClause != null) + { + mainFromClause.FromExpression = VisitExpression(mainFromClause.FromExpression); + } + + return expression; + } + + protected override Expression VisitSubQueryExpression(SubQueryExpression expression) + { + expression.QueryModel.TransformExpressions(VisitExpression); + return base.VisitSubQueryExpression(expression); + } + } + + public class LocateGroupJoinQuerySource : NhExpressionTreeVisitor + { + private readonly IsAggregatingResults _results; + private GroupJoinClause _groupJoin; + + public LocateGroupJoinQuerySource(IsAggregatingResults results) + { + _results = results; + } + + public GroupJoinClause Detect(Expression expression) + { + VisitExpression(expression); + return _groupJoin; + } + + protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression) + { + if (_results.AggregatingClauses.Contains(expression.ReferencedQuerySource as GroupJoinClause)) + { + _groupJoin = expression.ReferencedQuerySource as GroupJoinClause; + } + + return base.VisitQuerySourceReferenceExpression(expression); + } + } + + public class IsAggregatingResults + { + public List<GroupJoinClause> NonAggregatingClauses { get; set; } + public List<GroupJoinClause> AggregatingClauses { get; set; } + public List<Expression> NonAggregatingExpressions { get; set; } + } + + internal class GroupJoinAggregateDetectionVisitor : NhExpressionTreeVisitor + { + private readonly HashSet<GroupJoinClause> _groupJoinClauses; + private readonly StackFlag _inAggregate = new StackFlag(); + private readonly StackFlag _parentExpressionProcessed = new StackFlag(); + + private readonly List<Expression> _nonAggregatingExpressions = new List<Expression>(); + private readonly List<GroupJoinClause> _nonAggregatingGroupJoins = new List<GroupJoinClause>(); + private readonly List<GroupJoinClause> _aggregatingGroupJoins = new List<GroupJoinClause>(); + + public GroupJoinAggregateDetectionVisitor(IEnumerable<GroupJoinClause> groupJoinClause) + { + _groupJoinClauses = new HashSet<GroupJoinClause>(groupJoinClause); + } + + public IsAggregatingResults Visit(Expression expression) + { + VisitExpression(expression); + + return new IsAggregatingResults { NonAggregatingClauses = _nonAggregatingGroupJoins, AggregatingClauses = _aggregatingGroupJoins, NonAggregatingExpressions = _nonAggregatingExpressions }; + } + + protected override Expression VisitSubQueryExpression(SubQueryExpression expression) + { + VisitExpression(expression.QueryModel.SelectClause.Selector); + return expression; + } + + protected override Expression VisitNhAverage(NhAverageExpression expression) + { + using (_inAggregate.SetFlag()) + { + return base.VisitNhAverage(expression); + } + } + + protected override Expression VisitNhCount(NhCountExpression expression) + { + using (_inAggregate.SetFlag()) + { + return base.VisitNhCount(expression); + } + } + + protected override Expression VisitNhMax(NhMaxExpression expression) + { + using (_inAggregate.SetFlag()) + { + return base.VisitNhMax(expression); + } + } + + protected override Expression VisitNhMin(NhMinExpression expression) + { + using (_inAggregate.SetFlag()) + { + return base.VisitNhMin(expression); + } + } + + protected override Expression VisitNhSum(NhSumExpression expression) + { + using (_inAggregate.SetFlag()) + { + return base.VisitNhSum(expression); + } + } + + protected override Expression VisitMemberExpression(MemberExpression expression) + { + if (_inAggregate.FlagIsFalse && _parentExpressionProcessed.FlagIsFalse) + { + _nonAggregatingExpressions.Add(expression); + } + + using (_parentExpressionProcessed.SetFlag()) + { + return base.VisitMemberExpression(expression); + } + } + + protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression) + { + var fromClause = (FromClauseBase) expression.ReferencedQuerySource; + + if (fromClause.FromExpression is QuerySourceReferenceExpression) + { + var querySourceReference = (QuerySourceReferenceExpression) fromClause.FromExpression; + + if (_groupJoinClauses.Contains(querySourceReference.ReferencedQuerySource as GroupJoinClause)) + { + if (_inAggregate.FlagIsFalse) + { + _nonAggregatingGroupJoins.Add((GroupJoinClause) querySourceReference.ReferencedQuerySource); + } + else + { + _aggregatingGroupJoins.Add((GroupJoinClause) querySourceReference.ReferencedQuerySource); + } + } + } + + return base.VisitQuerySourceReferenceExpression(expression); + } + + internal class StackFlag + { + public bool FlagIsTrue { get; private set; } + + public bool FlagIsFalse { get { return !FlagIsTrue; } } + + public IDisposable SetFlag() + { + return new StackFlagDisposable(this); + } + + internal class StackFlagDisposable : IDisposable + { + private readonly StackFlag _parent; + private readonly bool _old; + + public StackFlagDisposable(StackFlag parent) + { + _parent = parent; + _old = parent.FlagIsTrue; + parent.FlagIsTrue = true; + } + + public void Dispose() + { + _parent.FlagIsTrue = _old; + } + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Linq/GroupByAggregateDetectionVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/GroupByAggregateDetectionVisitor.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Linq/GroupByAggregateDetectionVisitor.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -0,0 +1,83 @@ +using System.Linq; +using System.Linq.Expressions; +using Remotion.Data.Linq.Clauses.Expressions; +using Remotion.Data.Linq.Clauses.ResultOperators; +using Remotion.Data.Linq.Parsing; + +namespace NHibernate.Linq +{ + // TODO: This needs strengthening. Possibly a lot in common with the GroupJoinAggregateDetectionVisitor class, which does many more checks + internal class GroupByAggregateDetectionVisitor : NhExpressionTreeVisitor + { + public bool ContainsAggregateMethods { get; private set; } + + public bool Visit(Expression expression) + { + ContainsAggregateMethods = false; + + VisitExpression(expression); + + return ContainsAggregateMethods; + } + + // TODO - this should not exist, since it should be handled either by re-linq or by the MergeAggregatingResultsRewriter + protected override Expression VisitMethodCallExpression(MethodCallExpression m) + { + if (m.Method.DeclaringType == typeof (Queryable) || + m.Method.DeclaringType == typeof (Enumerable)) + { + switch (m.Method.Name) + { + case "Count": + case "Min": + case "Max": + case "Sum": + case "Average": + ContainsAggregateMethods = true; + break; + } + } + + return m; + } + + // TODO - having a VisitNhAggregation method or something in the base class would remove this duplication... + protected override Expression VisitNhAverage(NhAverageExpression expression) + { + ContainsAggregateMethods = true; + return expression; + } + + protected override Expression VisitNhCount(NhCountExpression expression) + { + ContainsAggregateMethods = true; + return expression; + } + + protected override Expression VisitNhMax(NhMaxExpression expression) + { + ContainsAggregateMethods = true; + return expression; + } + + protected override Expression VisitNhMin(NhMinExpression expression) + { + ContainsAggregateMethods = true; + return expression; + } + + protected override Expression VisitNhSum(NhSumExpression expression) + { + ContainsAggregateMethods = true; + return expression; + } + + protected override Expression VisitSubQueryExpression(SubQueryExpression expression) + { + ContainsAggregateMethods = + new GroupByAggregateDetectionVisitor().Visit(expression.QueryModel.SelectClause.Selector); + + return expression; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Linq/GroupByKeySelectorVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/GroupByKeySelectorVisitor.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Linq/GroupByKeySelectorVisitor.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -0,0 +1,26 @@ +using System.Linq.Expressions; +using Remotion.Data.Linq.Clauses.Expressions; +using Remotion.Data.Linq.Parsing; + +namespace NHibernate.Linq +{ + internal class GroupByKeySelectorVisitor : ExpressionTreeVisitor + { + private readonly ParameterExpression _parameter; + + public GroupByKeySelectorVisitor(ParameterExpression parameter) + { + _parameter = parameter; + } + + public Expression Visit(Expression expression) + { + return VisitExpression(expression); + } + + protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression) + { + return _parameter; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseRewriter.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseRewriter.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseRewriter.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -0,0 +1,202 @@ +using System; +using System.Linq.Expressions; +using Remotion.Data.Linq; +using Remotion.Data.Linq.Clauses; +using Remotion.Data.Linq.Clauses.Expressions; +using Remotion.Data.Linq.Clauses.ResultOperators; + +namespace NHibernate.Linq +{ + internal class GroupBySelectClauseRewriter : NhExpressionTreeVisitor + { + public static Expression ReWrite(Expression expression, GroupResultOperator groupBy, QueryModel model) + { + var visitor = new GroupBySelectClauseRewriter(groupBy, model); + return visitor.VisitExpression(expression); + } + + private readonly GroupResultOperator _groupBy; + private readonly QueryModel _model; + + public GroupBySelectClauseRewriter(GroupResultOperator groupBy, QueryModel model) + { + _groupBy = groupBy; + _model = model; + } + + protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression) + { + if (expression.ReferencedQuerySource == _groupBy) + { + return _groupBy.ElementSelector; + } + + return base.VisitQuerySourceReferenceExpression(expression); + } + + protected override Expression VisitMemberExpression(MemberExpression expression) + { + if (IsMemberOfModel(expression)) + { + if (expression.Member.Name == "Key") + { + return _groupBy.KeySelector; + } + else + { + Expression elementSelector = _groupBy.ElementSelector; + + if ((elementSelector is MemberExpression) || (elementSelector is QuerySourceReferenceExpression)) + { + // If ElementSelector is MemberExpression, just return + return base.VisitMemberExpression(expression); + } + else if (elementSelector is NewExpression) + { + // If ElementSelector is NewExpression, then search for member of name "get_" + originalMemberExpression.Member.Name + // TODO - this wouldn't handle nested initialisers. Should do a tree walk to find the correct member + var nex = elementSelector as NewExpression; + + int i = 0; + foreach (var member in nex.Members) + { + if (member.Name == "get_" + expression.Member.Name) + { + return nex.Arguments[i]; + } + i++; + } + + throw new NotImplementedException(); + } + else + { + throw new NotImplementedException(); + } + } + } + else + { + return base.VisitMemberExpression(expression); + } + } + + // TODO - dislike this code intensly. Should probably be a tree-walk in its own right + private bool IsMemberOfModel(MemberExpression expression) + { + var querySourceRef = expression.Expression as QuerySourceReferenceExpression; + + if (querySourceRef == null) + { + return false; + } + + var fromClause = querySourceRef.ReferencedQuerySource as FromClauseBase; + + if (fromClause == null) + { + return false; + } + + var subQuery = fromClause.FromExpression as SubQueryExpression; + + if (subQuery != null) + { + return subQuery.QueryModel == _model; + } + + var referencedQuery = fromClause.FromExpression as QuerySourceReferenceExpression; + + if (referencedQuery == null) + { + return false; + } + + var querySource = referencedQuery.ReferencedQuerySource as FromClauseBase; + + var subQuery2 = querySource.FromExpression as SubQueryExpression; + + return (subQuery2.QueryModel == _model); + } + + protected override Expression VisitSubQueryExpression(SubQueryExpression expression) + { + // TODO - is this safe? All we are extracting is the select clause from the sub-query. Assumes that everything + // else in the subquery has been removed. If there were two subqueries, one aggregating & one not, this may not be a + // valid assumption. Should probably be passed a list of aggregating subqueries that we are flattening so that we can check... + return GroupBySelectClauseRewriter.ReWrite(expression.QueryModel.SelectClause.Selector, _groupBy, _model); + } + } + + public enum NhExpressionType + { + Average = 10000, + Min, + Max, + Sum, + Count, + Distinct, + New + } + + public class NhAggregatedExpression : Expression + { + public Expression Expression { get; set; } + + public NhAggregatedExpression(Expression expression, NhExpressionType type) + : base((ExpressionType)type, expression.Type) + { + Expression = expression; + } + } + + public class NhAverageExpression : NhAggregatedExpression + { + public NhAverageExpression(Expression expression) : base(expression, NhExpressionType.Average) + { + } + } + + public class NhMinExpression : NhAggregatedExpression + { + public NhMinExpression(Expression expression) + : base(expression, NhExpressionType.Min) + { + } + } + + public class NhMaxExpression : NhAggregatedExpression + { + public NhMaxExpression(Expression expression) + : base(expression, NhExpressionType.Max) + { + } + } + + public class NhSumExpression : NhAggregatedExpression + { + public NhSumExpression(Expression expression) + : base(expression, NhExpressionType.Sum) + { + } + } + + public class NhDistinctExpression : NhAggregatedExpression + { + public NhDistinctExpression(Expression expression) + : base(expression, NhExpressionType.Distinct) + { + } + } + + public class NhCountExpression : Expression + { + public NhCountExpression(Expression expression) + : base((ExpressionType)NhExpressionType.Count, typeof(int)) + { + Expression = expression; + } + + public Expression Expression { get; private set; } + } +} Deleted: trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseVisitor.cs 2009-09-24 11:22:59 UTC (rev 4724) +++ trunk/nhibernate/src/NHibernate/Linq/GroupBySelectClauseVisitor.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -1,148 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using Remotion.Data.Linq.Clauses; -using Remotion.Data.Linq.Clauses.Expressions; -using Remotion.Data.Linq.Clauses.ResultOperators; -using Remotion.Data.Linq.Parsing; - -namespace NHibernate.Linq -{ - internal class GroupBySelectClauseVisitor : ExpressionTreeVisitor - { - public static Expression Visit(Expression expression) - { - var visitor = new GroupBySelectClauseVisitor(); - return visitor.VisitExpression(expression); - } - - protected override Expression VisitMemberExpression(MemberExpression expression) - { - if (expression.Member.Name == "Key" && - expression.Member.DeclaringType.GetGenericTypeDefinition() == typeof (IGrouping<,>)) - { - var querySourceRef = expression.Expression as QuerySourceReferenceExpression; - - var fromClause = querySourceRef.ReferencedQuerySource as FromClauseBase; - - var subQuery = fromClause.FromExpression as SubQueryExpression; - - var groupBy = - subQuery.QueryModel.ResultOperators.Where(r => r is GroupResultOperator).Single() as - GroupResultOperator; - - return groupBy.KeySelector; - } - else - { - return base.VisitMemberExpression(expression); - } - } - - protected override Expression VisitSubQueryExpression(SubQueryExpression expression) - { - if (expression.QueryModel.ResultOperators.Count == 1) - { - ResultOperatorBase resultOperator = expression.QueryModel.ResultOperators[0]; - - if (resultOperator is AverageResultOperator) - { - return new AverageExpression(expression.QueryModel.SelectClause.Selector); - } - else if (resultOperator is MinResultOperator) - { - return new MinExpression(expression.QueryModel.SelectClause.Selector); - } - else if (resultOperator is MaxResultOperator) - { - return new MaxExpression(expression.QueryModel.SelectClause.Selector); - } - else if (resultOperator is CountResultOperator) - { - return new CountExpression(); - } - else if (resultOperator is SumResultOperator) - { - return new SumExpression(expression.QueryModel.SelectClause.Selector); - } - else - { - throw new NotImplementedException(); - } - } - else - { - return base.VisitSubQueryExpression(expression); - } - } - } - - public enum NhExpressionType - { - Average = 10000, - Min, - Max, - Sum, - Count, - Distinct - } - - public class NhAggregatedExpression : Expression - { - public Expression Expression { get; set; } - - public NhAggregatedExpression(Expression expression, NhExpressionType type) - : base((ExpressionType)type, expression.Type) - { - Expression = expression; - } - } - - public class AverageExpression : NhAggregatedExpression - { - public AverageExpression(Expression expression) : base(expression, NhExpressionType.Average) - { - } - } - - public class MinExpression : NhAggregatedExpression - { - public MinExpression(Expression expression) - : base(expression, NhExpressionType.Min) - { - } - } - - public class MaxExpression : NhAggregatedExpression - { - public MaxExpression(Expression expression) - : base(expression, NhExpressionType.Max) - { - } - } - - public class SumExpression : NhAggregatedExpression - { - public SumExpression(Expression expression) - : base(expression, NhExpressionType.Sum) - { - } - } - - public class DistinctExpression : NhAggregatedExpression - { - public DistinctExpression(Expression expression) - : base(expression, NhExpressionType.Distinct) - { - } - } - - public class CountExpression : Expression - { - public CountExpression() - : base((ExpressionType)NhExpressionType.Count, typeof(int)) - { - } - } -} Deleted: trunk/nhibernate/src/NHibernate/Linq/GroupBySelectorVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/GroupBySelectorVisitor.cs 2009-09-24 11:22:59 UTC (rev 4724) +++ trunk/nhibernate/src/NHibernate/Linq/GroupBySelectorVisitor.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -1,26 +0,0 @@ -using System.Linq.Expressions; -using Remotion.Data.Linq.Clauses.Expressions; -using Remotion.Data.Linq.Parsing; - -namespace NHibernate.Linq -{ - internal class GroupBySelectorVisitor : ExpressionTreeVisitor - { - private readonly ParameterExpression _parameter; - - public GroupBySelectorVisitor(ParameterExpression parameter) - { - _parameter = parameter; - } - - public Expression Visit(Expression expression) - { - return VisitExpression(expression); - } - - protected override Expression VisitQuerySourceReferenceExpression(QuerySourceReferenceExpression expression) - { - return _parameter; - } - } -} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/HqlGeneratorExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/HqlGeneratorExpressionTreeVisitor.cs 2009-09-24 11:22:59 UTC (rev 4724) +++ trunk/nhibernate/src/NHibernate/Linq/HqlGeneratorExpressionTreeVisitor.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -31,7 +31,7 @@ VisitExpression(expression); } - protected override Expression VisitNhAverage(AverageExpression expression) + protected override Expression VisitNhAverage(NhAverageExpression expression) { var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator); visitor.Visit(expression.Expression); @@ -41,14 +41,17 @@ return expression; } - protected override Expression VisitNhCount(CountExpression expression) + protected override Expression VisitNhCount(NhCountExpression expression) { - _stack.PushLeaf(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Count(_hqlTreeBuilder.RowStar()), expression.Type)); + var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator); + visitor.Visit(expression.Expression); + _stack.PushLeaf(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Count(visitor.GetHqlTreeNodes().Single()), expression.Type)); + return expression; } - protected override Expression VisitNhMin(MinExpression expression) + protected override Expression VisitNhMin(NhMinExpression expression) { var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator); visitor.Visit(expression.Expression); @@ -58,7 +61,7 @@ return expression; } - protected override Expression VisitNhMax(MaxExpression expression) + protected override Expression VisitNhMax(NhMaxExpression expression) { var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator); visitor.Visit(expression.Expression); @@ -68,7 +71,7 @@ return expression; } - protected override Expression VisitNhSum(SumExpression expression) + protected override Expression VisitNhSum(NhSumExpression expression) { var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator); visitor.Visit(expression.Expression); @@ -78,7 +81,7 @@ return expression; } - protected override Expression VisitNhDistinct(DistinctExpression expression) + protected override Expression VisitNhDistinct(NhDistinctExpression expression) { var visitor = new HqlGeneratorExpressionTreeVisitor(_parameterAggregator); visitor.Visit(expression.Expression); Added: trunk/nhibernate/src/NHibernate/Linq/MergeAggregatingResultsRewriter.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/MergeAggregatingResultsRewriter.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Linq/MergeAggregatingResultsRewriter.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -0,0 +1,123 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using Remotion.Data.Linq; +using Remotion.Data.Linq.Clauses; +using Remotion.Data.Linq.Clauses.Expressions; +using Remotion.Data.Linq.Clauses.ResultOperators; +using Remotion.Data.Linq.Parsing; +using Remotion.Data.Linq.Parsing.ExpressionTreeVisitors; + +namespace NHibernate.Linq +{ + public class MergeAggregatingResultsRewriter : QueryModelVisitorBase + { + public void ReWrite(QueryModel model) + { + this.VisitQueryModel(model); + } + + public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index) + { + if (resultOperator is SumResultOperator) + { + queryModel.SelectClause.Selector = new NhSumExpression(queryModel.SelectClause.Selector); + queryModel.ResultOperators.Remove(resultOperator); + } + else if (resultOperator is AverageResultOperator) + { + queryModel.SelectClause.Selector = new NhAverageExpression(queryModel.SelectClause.Selector); + queryModel.ResultOperators.Remove(resultOperator); + } + else if (resultOperator is MinResultOperator) + { + queryModel.SelectClause.Selector = new NhMinExpression(queryModel.SelectClause.Selector); + queryModel.ResultOperators.Remove(resultOperator); + } + else if (resultOperator is MaxResultOperator) + { + queryModel.SelectClause.Selector = new NhMaxExpression(queryModel.SelectClause.Selector); + queryModel.ResultOperators.Remove(resultOperator); + } + else if (resultOperator is DistinctResultOperator) + { + queryModel.SelectClause.Selector = new NhDistinctExpression(queryModel.SelectClause.Selector); + queryModel.ResultOperators.Remove(resultOperator); + } + else if (resultOperator is CountResultOperator) + { + queryModel.SelectClause.Selector = new NhCountExpression(queryModel.SelectClause.Selector); + queryModel.ResultOperators.Remove(resultOperator); + } + + base.VisitResultOperator(resultOperator, queryModel, index); + } + + public override void VisitSelectClause(SelectClause selectClause, QueryModel queryModel) + { + selectClause.TransformExpressions(s => new MergeAggregatingResultsInExpressionRewriter().Visit(s)); + } + } + + internal class MergeAggregatingResultsInExpressionRewriter : NhExpressionTreeVisitor + { + public Expression Visit(Expression expression) + { + return VisitExpression(expression); + } + + protected override Expression VisitSubQueryExpression(SubQueryExpression expression) + { + new MergeAggregatingResultsRewriter().ReWrite(expression.QueryModel); + return expression; + } + + protected override Expression VisitMethodCallExpression(MethodCallExpression m) + { + if (m.Method.DeclaringType == typeof(Queryable) || + m.Method.DeclaringType == typeof(Enumerable)) + { + // TODO - dynamic name generation needed here + switch (m.Method.Name) + { + case "Count": + return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1], + e => new NhCountExpression(e)); + case "Min": + return CreateAggregate(m.Arguments[0], (LambdaExpression) m.Arguments[1], + e => new NhMinExpression(e)); + case "Max": + return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1], + e => new NhMaxExpression(e)); + case "Sum": + return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1], + e => new NhSumExpression(e)); + case "Average": + return CreateAggregate(m.Arguments[0], (LambdaExpression)m.Arguments[1], + e => new NhAverageExpression(e)); + } + } + + return base.VisitMethodCallExpression(m); + } + + private Expression CreateAggregate(Expression fromClauseExpression, LambdaExpression body, Func<Expression,Expression> factory) + { + var fromClause = new MainFromClause("x2", body.Parameters[0].Type, fromClauseExpression); + var selectClause = body.Body; + selectClause = ReplacingExpressionTreeVisitor.Replace(body.Parameters[0], + new QuerySourceReferenceExpression( + fromClause), selectClause); + var queryModel = new QueryModel(fromClause, + new SelectClause(factory(selectClause))); + + queryModel.ResultOperators.Add(new AverageResultOperator()); + + var subQuery = new SubQueryExpression(queryModel); + + queryModel.ResultOperators.Clear(); + + return subQuery; + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/NhExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhExpressionTreeVisitor.cs 2009-09-24 11:22:59 UTC (rev 4724) +++ trunk/nhibernate/src/NHibernate/Linq/NhExpressionTreeVisitor.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -1,3 +1,4 @@ +using System; using System.Linq.Expressions; using Remotion.Data.Linq.Parsing; @@ -7,63 +8,79 @@ { protected override Expression VisitExpression(Expression expression) { + if (expression == null) + { + return null; + } + switch ((NhExpressionType) expression.NodeType) { case NhExpressionType.Average: - return VisitNhAverage((AverageExpression) expression); + return VisitNhAverage((NhAverageExpression) expression); case NhExpressionType.Min: - return VisitNhMin((MinExpression)expression); + return VisitNhMin((NhMinExpression)expression); case NhExpressionType.Max: - return VisitNhMax((MaxExpression)expression); + return VisitNhMax((NhMaxExpression)expression); case NhExpressionType.Sum: - return VisitNhSum((SumExpression)expression); + return VisitNhSum((NhSumExpression)expression); case NhExpressionType.Count: - return VisitNhCount((CountExpression)expression); + return VisitNhCount((NhCountExpression)expression); case NhExpressionType.Distinct: - return VisitNhDistinct((DistinctExpression) expression); + return VisitNhDistinct((NhDistinctExpression) expression); + case NhExpressionType.New: + return VisitNhNew((NhNewExpression) expression); } return base.VisitExpression(expression); } - protected virtual Expression VisitNhDistinct(DistinctExpression expression) + private Expression VisitNhNew(NhNewExpression expression) { + var arguments = VisitExpressionList(expression.Arguments); + + return arguments != expression.Arguments ? new NhNewExpression(expression.Members, arguments) : expression; + } + + protected virtual Expression VisitNhDistinct(NhDistinctExpression expression) + { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new DistinctExpression(nx) : expression; + return nx != expression.Expression ? new NhDistinctExpression(nx) : expression; } - protected virtual Expression VisitNhCount(CountExpression expression) + protected virtual Expression VisitNhCount(NhCountExpression expression) { - return expression; + Expression nx = base.VisitExpression(expression.Expression); + + return nx != expression.Expression ? new NhCountExpression(nx) : expression; } - protected virtual Expression VisitNhSum(SumExpression expression) + protected virtual Expression VisitNhSum(NhSumExpression expression) { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new SumExpression(nx) : expression; + return nx != expression.Expression ? new NhSumExpression(nx) : expression; } - protected virtual Expression VisitNhMax(MaxExpression expression) + protected virtual Expression VisitNhMax(NhMaxExpression expression) { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new MaxExpression(nx) : expression; + return nx != expression.Expression ? new NhMaxExpression(nx) : expression; } - protected virtual Expression VisitNhMin(MinExpression expression) + protected virtual Expression VisitNhMin(NhMinExpression expression) { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new MinExpression(nx) : expression; + return nx != expression.Expression ? new NhMinExpression(nx) : expression; } - protected virtual Expression VisitNhAverage(AverageExpression expression) + protected virtual Expression VisitNhAverage(NhAverageExpression expression) { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new AverageExpression(nx) : expression; + return nx != expression.Expression ? new NhAverageExpression(nx) : expression; } } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Linq/NhNewExpression.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhNewExpression.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Linq/NhNewExpression.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Linq.Expressions; + +namespace NHibernate.Linq +{ + public class NhNewExpression : Expression + { + private readonly ReadOnlyCollection<string> _members; + private readonly ReadOnlyCollection<Expression> _arguments; + + public NhNewExpression(IList<string> members, IList<Expression> arguments) + : base((ExpressionType)NhExpressionType.New, typeof(object)) + { + _members = new ReadOnlyCollection<string>(members); + _arguments = new ReadOnlyCollection<Expression>(arguments); + } + + public ReadOnlyCollection<Expression> Arguments + { + get { return _arguments; } + } + + public ReadOnlyCollection<string> Members + { + get { return _members; } + } + } +} Modified: trunk/nhibernate/src/NHibernate/Linq/NhThrowingExpressionTreeVisitor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/NhThrowingExpressionTreeVisitor.cs 2009-09-24 11:22:59 UTC (rev 4724) +++ trunk/nhibernate/src/NHibernate/Linq/NhThrowingExpressionTreeVisitor.cs 2009-09-25 21:04:56 UTC (rev 4725) @@ -1,4 +1,3 @@ -using System; using System.Linq.Expressions; using Remotion.Data.Linq.Parsing; @@ -11,91 +10,106 @@ switch ((NhExpressionType)expression.NodeType) { case NhExpressionType.Average: - return VisitNhAverage((AverageExpression)expression); + return VisitNhAverage((NhAverageExpression)expression); case NhExpressionType.Min: - return VisitNhMin((MinExpression)expression); + return VisitNhMin((NhMinExpression)expression); case NhExpressionType.Max: - return VisitNhMax((MaxExpression)expression); + return VisitNhMax((NhMaxExpression)expression); case NhExpressionType.Sum: - return VisitNhSum((SumExpression)expression); + return VisitNhSum((NhSumExpression)expression); case NhExpressionType.Count: - return VisitNhCount((CountExpression)expression); + return VisitNhCount((NhCountExpression)expression); case NhExpressionType.Distinct: - return VisitNhDistinct((DistinctExpression) expression); + return VisitNhDistinct((NhDistinctExpression) expression); + case NhExpressionType.New: + return VisitNhNew((NhNewExpression) expression); } return base.VisitExpression(expression); } - protected virtual Expression VisitNhDistinct(DistinctExpression expression) + protected virtual Expression VisitNhNew(NhNewExpression expression) { - return VisitUnhandledItem<DistinctExpression, Expression>(expression, "VisitNhDistinct", BaseVisitNhDistinct); + return VisitUnhandledItem<NhNewExpression, Expression>(expression, "VisitNhNew", BaseVisitNhNew); } - protected virtual Expression VisitNhAverage(AverageExpression expression) + protected virtual Expression VisitNhDistinct(NhDistinctExpression expression) { - return VisitUnhandledItem<AverageExpression, Expression>(expression, "VisitNhAverage", BaseVisitNhAverage); + return VisitUnhandledItem<NhDistinctExpression, Expression>(expression, "VisitNhDistinct", BaseVisitNhDistinct); } - protected virtual Expression VisitNhMin(MinExpression expression) + protected virtual Expression VisitNhAverage(NhAverageExpression expression) { - return VisitUnhandledItem<MinExpression, Expression>(expression, "VisitNhMin", BaseVisitNhMin); + return VisitUnhandledItem<NhAverageExpression, Expression>(expression, "VisitNhAverage", BaseVisitNhAverage); } - protected virtual Expression VisitNhMax(MaxExpression expression) + protected virtual Expression VisitNhMin(NhMinExpression expression) { - return VisitUnhandledItem<MaxExpression, Expression>(expression, "VisitNhMax", BaseVisitNhMax); + return VisitUnhandledItem<NhMinExpression, Expression>(expression, "VisitNhMin", BaseVisitNhMin); } - protected virtual Expression VisitNhSum(SumExpression expression) + protected virtual Expression VisitNhMax(NhMaxExpression expression) { - return VisitUnhandledItem<SumExpression, Expression>(expression, "VisitNhSum", BaseVisitNhSum); + return VisitUnhandledItem<NhMaxExpression, Expression>(expression, "VisitNhMax", BaseVisitNhMax); } - protected virtual Expression VisitNhCount(CountExpression expression) + protected virtual Expression VisitNhSum(NhSumExpression expression) { - return VisitUnhandledItem<CountExpression, Expression>(expression, "VisitNhCount", BaseVisitNhCount); + return VisitUnhandledItem<NhSumExpression, Expression>(expression, "VisitNhSum", BaseVisitNhSum); } - protected virtual Expression BaseVisitNhCount(CountExpression expression) + protected virtual Expression VisitNhCount(NhCountExpression expression) { - return expression; + return VisitUnhandledItem<NhCountExpression, Expression>(expression, "VisitNhCount", BaseVisitNhCount); } - protected virtual Expression BaseVisitNhSum(SumExpression expression) + protected virtual Expression BaseVisitNhCount(NhCountExpression expression) { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new SumExpression(nx) : expression; + return nx != expression.Expression ? new NhCountExpression(nx) : expression; } - protected virtual Expression BaseVisitNhMax(MaxExpression expression) + protected virtual Expression BaseVisitNhSum(NhSumExpression expression) { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new MaxExpression(nx) : expression; + return nx != expression.Expression ? new NhSumExpression(nx) : expression; } - protected virtual Expression BaseVisitNhMin(MinExpression expression) + protected virtual Expression BaseVisitNhMax(NhMaxExpression expression) { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new MinExpression(nx) : expression; + return nx != expression.Expression ? new NhMaxExpression(nx) : expression; } - protected virtual Expression BaseVisitNhAverage(AverageExpression expression) + protected virtual Expression BaseVisitNhMin(NhMinExpression expression) { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new AverageExpression(nx) : expression; + return nx != expression.Expression ? new NhMinExpression(nx) : expression; } - private Expression BaseVisitNhDistinct(DistinctExpression expression) + protected virtual Expression BaseVisitNhAverage(NhAverageExpression expression) { Expression nx = base.VisitExpression(expression.Expression); - return nx != expression.Expression ? new DistinctExpression(nx) : expression; + ... [truncated message content] |
From: <ric...@us...> - 2009-09-24 11:23:08
|
Revision: 4724 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4724&view=rev Author: ricbrown Date: 2009-09-24 11:22:59 +0000 (Thu, 24 Sep 2009) Log Message: ----------- Merge r4723 (Fix NH-1948 Allow scale of zero) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Model.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs 2009-09-24 11:20:25 UTC (rev 4723) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs 2009-09-24 11:22:59 UTC (rev 4724) @@ -152,7 +152,7 @@ public string precision; /// <remarks/> - [System.Xml.Serialization.XmlAttributeAttribute(DataType="positiveInteger")] + [System.Xml.Serialization.XmlAttributeAttribute(DataType="nonNegativeInteger")] public string scale; /// <remarks/> @@ -937,7 +937,7 @@ public string precision; /// <remarks/> - [System.Xml.Serialization.XmlAttributeAttribute(DataType="positiveInteger")] + [System.Xml.Serialization.XmlAttributeAttribute(DataType="nonNegativeInteger")] public string scale; /// <remarks/> @@ -1101,7 +1101,7 @@ public string precision; /// <remarks/> - [System.Xml.Serialization.XmlAttributeAttribute(DataType="positiveInteger")] + [System.Xml.Serialization.XmlAttributeAttribute(DataType="nonNegativeInteger")] public string scale; /// <remarks/> Modified: trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd =================================================================== --- trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2009-09-24 11:20:25 UTC (rev 4723) +++ trunk/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2009-09-24 11:22:59 UTC (rev 4724) @@ -233,7 +233,7 @@ </xs:attribute> <xs:attribute name="length" type="xs:positiveInteger" /> <xs:attribute name="precision" type="xs:positiveInteger" /> - <xs:attribute name="scale" type="xs:positiveInteger" /> + <xs:attribute name="scale" type="xs:nonNegativeInteger" /> <xs:attribute name="not-null" type="xs:boolean"> </xs:attribute> <xs:attribute name="unique" type="xs:boolean"> @@ -448,7 +448,7 @@ <xs:attribute name="type" type="xs:string" /> <xs:attribute name="length" type="xs:positiveInteger" /> <xs:attribute name="precision" type="xs:positiveInteger" /> - <xs:attribute name="scale" type="xs:positiveInteger" /> + <xs:attribute name="scale" type="xs:nonNegativeInteger" /> <xs:attribute name="not-null" default="false" type="xs:boolean"> </xs:attribute> <xs:attribute name="unique" default="false" type="xs:boolean"> @@ -1158,7 +1158,7 @@ <xs:attribute name="column" type="xs:string" /> <xs:attribute name="length" type="xs:positiveInteger" /> <xs:attribute name="precision" type="xs:positiveInteger" /> - <xs:attribute name="scale" type="xs:positiveInteger" /> + <xs:attribute name="scale" type="xs:nonNegativeInteger" /> <xs:attribute name="not-null" type="xs:boolean"> </xs:attribute> <xs:attribute name="unique" default="false" type="xs:boolean"> Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Fixture.cs 2009-09-24 11:22:59 UTC (rev 4724) @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1948 +{ + [TestFixture] + public class Fixture : BugTestCase + { + + [Test] + public void CanUseDecimalScaleZero() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + Person person = + new Person() + { + Age = 50, + ShoeSize = 10, + FavouriteNumbers = + new List<decimal>() + { + 20, + 30, + 40, + }, + }; + + s.Save(person); + s.Flush(); + tx.Rollback(); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Mappings.hbm.xml 2009-09-24 11:22:59 UTC (rev 4724) @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1948"> + + <class name="Person"> + <id name="Id"> + <generator class="native" /> + </id> + + <property name="Age" type="decimal" precision="2" scale="0" /> + + <property name="ShoeSize"> + <column name="ShoeSizeColumn" precision="2" scale="0"/> + </property> + + <bag name="FavouriteNumbers" table="FavNum"> + <key column="Person" /> + <element type="decimal" precision="2" scale="0" /> + </bag> + + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Model.cs 2009-09-24 11:22:59 UTC (rev 4724) @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH1948 +{ + public class Person + { + public virtual int Id { get; set; } + public virtual decimal Age { get; set; } + public virtual decimal ShoeSize { get; set; } + public virtual IList<decimal> FavouriteNumbers { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-24 11:20:25 UTC (rev 4723) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-24 11:22:59 UTC (rev 4724) @@ -606,6 +606,8 @@ <Compile Include="NHSpecificTest\NH1941\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1941\Model.cs" /> <Compile Include="NHSpecificTest\NH1941\SexEnumStringType.cs" /> + <Compile Include="NHSpecificTest\NH1948\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1948\Model.cs" /> <Compile Include="NHSpecificTest\NH1963\CacheableQueryOnByteArray.cs" /> <Compile Include="NHSpecificTest\NH1963\DomainClass.cs" /> <Compile Include="NHSpecificTest\NH1969\DummyEntity.cs" /> @@ -2025,6 +2027,7 @@ <EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" /> <EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1948\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1941\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1963\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1969\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-24 11:20:31
|
Revision: 4723 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4723&view=rev Author: ricbrown Date: 2009-09-24 11:20:25 +0000 (Thu, 24 Sep 2009) Log Message: ----------- Fix NH-1948 Allow scale of zero Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs branches/2.1.x/nhibernate/src/NHibernate/nhibernate-mapping.xsd branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Fixture.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Mappings.hbm.xml branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Model.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs 2009-09-23 10:10:00 UTC (rev 4722) +++ branches/2.1.x/nhibernate/src/NHibernate/Cfg/MappingSchema/Hbm.generated.cs 2009-09-24 11:20:25 UTC (rev 4723) @@ -152,7 +152,7 @@ public string precision; /// <remarks/> - [System.Xml.Serialization.XmlAttributeAttribute(DataType="positiveInteger")] + [System.Xml.Serialization.XmlAttributeAttribute(DataType="nonNegativeInteger")] public string scale; /// <remarks/> @@ -937,7 +937,7 @@ public string precision; /// <remarks/> - [System.Xml.Serialization.XmlAttributeAttribute(DataType="positiveInteger")] + [System.Xml.Serialization.XmlAttributeAttribute(DataType="nonNegativeInteger")] public string scale; /// <remarks/> @@ -1101,7 +1101,7 @@ public string precision; /// <remarks/> - [System.Xml.Serialization.XmlAttributeAttribute(DataType="positiveInteger")] + [System.Xml.Serialization.XmlAttributeAttribute(DataType="nonNegativeInteger")] public string scale; /// <remarks/> Modified: branches/2.1.x/nhibernate/src/NHibernate/nhibernate-mapping.xsd =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2009-09-23 10:10:00 UTC (rev 4722) +++ branches/2.1.x/nhibernate/src/NHibernate/nhibernate-mapping.xsd 2009-09-24 11:20:25 UTC (rev 4723) @@ -233,7 +233,7 @@ </xs:attribute> <xs:attribute name="length" type="xs:positiveInteger" /> <xs:attribute name="precision" type="xs:positiveInteger" /> - <xs:attribute name="scale" type="xs:positiveInteger" /> + <xs:attribute name="scale" type="xs:nonNegativeInteger" /> <xs:attribute name="not-null" type="xs:boolean"> </xs:attribute> <xs:attribute name="unique" type="xs:boolean"> @@ -448,7 +448,7 @@ <xs:attribute name="type" type="xs:string" /> <xs:attribute name="length" type="xs:positiveInteger" /> <xs:attribute name="precision" type="xs:positiveInteger" /> - <xs:attribute name="scale" type="xs:positiveInteger" /> + <xs:attribute name="scale" type="xs:nonNegativeInteger" /> <xs:attribute name="not-null" default="false" type="xs:boolean"> </xs:attribute> <xs:attribute name="unique" default="false" type="xs:boolean"> @@ -1158,7 +1158,7 @@ <xs:attribute name="column" type="xs:string" /> <xs:attribute name="length" type="xs:positiveInteger" /> <xs:attribute name="precision" type="xs:positiveInteger" /> - <xs:attribute name="scale" type="xs:positiveInteger" /> + <xs:attribute name="scale" type="xs:nonNegativeInteger" /> <xs:attribute name="not-null" type="xs:boolean"> </xs:attribute> <xs:attribute name="unique" default="false" type="xs:boolean"> Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Fixture.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Fixture.cs 2009-09-24 11:20:25 UTC (rev 4723) @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1948 +{ + [TestFixture] + public class Fixture : BugTestCase + { + + [Test] + public void CanUseDecimalScaleZero() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + Person person = + new Person() + { + Age = 50, + ShoeSize = 10, + FavouriteNumbers = + new List<decimal>() + { + 20, + 30, + 40, + }, + }; + + s.Save(person); + s.Flush(); + tx.Rollback(); + } + } + } +} \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Mappings.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Mappings.hbm.xml 2009-09-24 11:20:25 UTC (rev 4723) @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1948"> + + <class name="Person"> + <id name="Id"> + <generator class="native" /> + </id> + + <property name="Age" type="decimal" precision="2" scale="0" /> + + <property name="ShoeSize"> + <column name="ShoeSizeColumn" precision="2" scale="0"/> + </property> + + <bag name="FavouriteNumbers" table="FavNum"> + <key column="Person" /> + <element type="decimal" precision="2" scale="0" /> + </bag> + + </class> + +</hibernate-mapping> Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Model.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Model.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1948/Model.cs 2009-09-24 11:20:25 UTC (rev 4723) @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH1948 +{ + public class Person + { + public virtual int Id { get; set; } + public virtual decimal Age { get; set; } + public virtual decimal ShoeSize { get; set; } + public virtual IList<decimal> FavouriteNumbers { get; set; } + } +} Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-23 10:10:00 UTC (rev 4722) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-24 11:20:25 UTC (rev 4723) @@ -578,6 +578,8 @@ <Compile Include="NHSpecificTest\NH1941\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1941\Model.cs" /> <Compile Include="NHSpecificTest\NH1941\SexEnumStringType.cs" /> + <Compile Include="NHSpecificTest\NH1948\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1948\Model.cs" /> <Compile Include="NHSpecificTest\NH473\Child.cs" /> <Compile Include="NHSpecificTest\NH473\Fixture.cs" /> <Compile Include="NHSpecificTest\NH473\Parent.cs" /> @@ -1989,6 +1991,7 @@ <EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" /> <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1948\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1941\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1922\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-23 10:10:11
|
Revision: 4722 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4722&view=rev Author: ricbrown Date: 2009-09-23 10:10:00 +0000 (Wed, 23 Sep 2009) Log Message: ----------- Merge r4721 (Fix NH-1941 Overriding GetValue in EnumStringType) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/EnumStringType.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Model.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/SexEnumStringType.cs Modified: trunk/nhibernate/src/NHibernate/Type/EnumStringType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/EnumStringType.cs 2009-09-23 10:09:13 UTC (rev 4721) +++ trunk/nhibernate/src/NHibernate/Type/EnumStringType.cs 2009-09-23 10:10:00 UTC (rev 4722) @@ -126,7 +126,7 @@ public virtual object GetValue(object code) { //code is an enum instance. - return code == null ? string.Empty : code.ToString(); + return code == null ? string.Empty : Enum.Format(ReturnedClass, code, "G"); } /// <summary> @@ -144,7 +144,7 @@ } else { - par.Value = Enum.Format(ReturnedClass, value, "G"); + par.Value = GetValue(value); } } Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941 ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs 2009-09-23 10:10:00 UTC (rev 4722) @@ -0,0 +1,50 @@ +using System; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1941 +{ + [TestFixture] + public class Fixture : BugTestCase + { + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession s = OpenSession()) + { + s.Delete("from Person"); + } + } + [Test] + public void CanOverrideStringEnumGetValue() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + using (SqlLogSpy ls = new SqlLogSpy()) + { + Person person = new Person() { Sex = Sex.Male }; + s.Save(person); + + string log = ls.GetWholeLog(); + Assert.IsTrue(log.Contains("@p0 = 'M'")); + } + + using (SqlLogSpy ls = new SqlLogSpy()) + { + Person person = + s.CreateQuery("from Person p where p.Sex = :personSex") + .SetParameter("personSex", Sex.Female) + .UniqueResult<Person>(); + + Assert.That(person, Is.Null); + + string log = ls.GetWholeLog(); + Assert.IsTrue(log.Contains("@p0 = 'F'")); + } + + tx.Rollback(); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Mappings.hbm.xml 2009-09-23 10:10:00 UTC (rev 4722) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1941"> + + <class name="Person" > + <id name="Id"> + <generator class="native" /> + </id> + + <property name="Sex" type="SexEnumStringType" /> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Model.cs 2009-09-23 10:10:00 UTC (rev 4722) @@ -0,0 +1,14 @@ +namespace NHibernate.Test.NHSpecificTest.NH1941 +{ + public enum Sex + { + Male, + Female, + } + + public class Person + { + public virtual int Id { get; set; } + public virtual Sex Sex { get; set; } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/SexEnumStringType.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/SexEnumStringType.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/SexEnumStringType.cs 2009-09-23 10:10:00 UTC (rev 4722) @@ -0,0 +1,28 @@ +using System; +using NHibernate.Type; + +namespace NHibernate.Test.NHSpecificTest.NH1941 +{ + public class SexEnumStringType : EnumStringType<Sex> + { + public override object GetValue(object enumValue) + { + if (enumValue == null) + { + return string.Empty; + } + + return (Sex)enumValue == Sex.Male ? "M" : "F"; + } + + public override object GetInstance(object value) + { + if (value == null) + { + throw new ArgumentNullException("value"); + } + + return (value.ToString() == "M") ? Sex.Male : Sex.Female; + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-23 10:09:13 UTC (rev 4721) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-23 10:10:00 UTC (rev 4722) @@ -603,6 +603,9 @@ <Compile Include="NHSpecificTest\NH1938\Model.cs" /> <Compile Include="NHSpecificTest\NH1939\AuxType.cs" /> <Compile Include="NHSpecificTest\NH1939\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1941\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1941\Model.cs" /> + <Compile Include="NHSpecificTest\NH1941\SexEnumStringType.cs" /> <Compile Include="NHSpecificTest\NH1963\CacheableQueryOnByteArray.cs" /> <Compile Include="NHSpecificTest\NH1963\DomainClass.cs" /> <Compile Include="NHSpecificTest\NH1969\DummyEntity.cs" /> @@ -2022,6 +2025,7 @@ <EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" /> <EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1941\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1963\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1969\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1922\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2009-09-23 10:09:25
|
Revision: 4721 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4721&view=rev Author: ricbrown Date: 2009-09-23 10:09:13 +0000 (Wed, 23 Sep 2009) Log Message: ----------- Fix NH-1941 (Overriding GetValue in EnumStringType) Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Type/EnumStringType.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Mappings.hbm.xml branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Model.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/SexEnumStringType.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/Type/EnumStringType.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Type/EnumStringType.cs 2009-09-21 02:04:47 UTC (rev 4720) +++ branches/2.1.x/nhibernate/src/NHibernate/Type/EnumStringType.cs 2009-09-23 10:09:13 UTC (rev 4721) @@ -126,7 +126,7 @@ public virtual object GetValue(object code) { //code is an enum instance. - return code == null ? string.Empty : code.ToString(); + return code == null ? string.Empty : Enum.Format(ReturnedClass, code, "G"); } /// <summary> @@ -144,7 +144,7 @@ } else { - par.Value = Enum.Format(ReturnedClass, value, "G"); + par.Value = GetValue(value); } } Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Fixture.cs 2009-09-23 10:09:13 UTC (rev 4721) @@ -0,0 +1,50 @@ +using System; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1941 +{ + [TestFixture] + public class Fixture : BugTestCase + { + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession s = OpenSession()) + { + s.Delete("from Person"); + } + } + [Test] + public void CanOverrideStringEnumGetValue() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + using (SqlLogSpy ls = new SqlLogSpy()) + { + Person person = new Person() { Sex = Sex.Male }; + s.Save(person); + + string log = ls.GetWholeLog(); + Assert.IsTrue(log.Contains("@p0 = 'M'")); + } + + using (SqlLogSpy ls = new SqlLogSpy()) + { + Person person = + s.CreateQuery("from Person p where p.Sex = :personSex") + .SetParameter("personSex", Sex.Female) + .UniqueResult<Person>(); + + Assert.That(person, Is.Null); + + string log = ls.GetWholeLog(); + Assert.IsTrue(log.Contains("@p0 = 'F'")); + } + + tx.Rollback(); + } + } + } +} \ No newline at end of file Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Mappings.hbm.xml (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Mappings.hbm.xml 2009-09-23 10:09:13 UTC (rev 4721) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1941"> + + <class name="Person" > + <id name="Id"> + <generator class="native" /> + </id> + + <property name="Sex" type="SexEnumStringType" /> + </class> + +</hibernate-mapping> Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Model.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Model.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/Model.cs 2009-09-23 10:09:13 UTC (rev 4721) @@ -0,0 +1,14 @@ +namespace NHibernate.Test.NHSpecificTest.NH1941 +{ + public enum Sex + { + Male, + Female, + } + + public class Person + { + public virtual int Id { get; set; } + public virtual Sex Sex { get; set; } + } +} Added: branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/SexEnumStringType.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/SexEnumStringType.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1941/SexEnumStringType.cs 2009-09-23 10:09:13 UTC (rev 4721) @@ -0,0 +1,28 @@ +using System; +using NHibernate.Type; + +namespace NHibernate.Test.NHSpecificTest.NH1941 +{ + public class SexEnumStringType : EnumStringType<Sex> + { + public override object GetValue(object enumValue) + { + if (enumValue == null) + { + return string.Empty; + } + + return (Sex)enumValue == Sex.Male ? "M" : "F"; + } + + public override object GetInstance(object value) + { + if (value == null) + { + throw new ArgumentNullException("value"); + } + + return (value.ToString() == "M") ? Sex.Male : Sex.Female; + } + } +} Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-21 02:04:47 UTC (rev 4720) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-23 10:09:13 UTC (rev 4721) @@ -575,6 +575,9 @@ <Compile Include="NHSpecificTest\NH1938\Model.cs" /> <Compile Include="NHSpecificTest\NH1939\AuxType.cs" /> <Compile Include="NHSpecificTest\NH1939\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1941\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1941\Model.cs" /> + <Compile Include="NHSpecificTest\NH1941\SexEnumStringType.cs" /> <Compile Include="NHSpecificTest\NH473\Child.cs" /> <Compile Include="NHSpecificTest\NH473\Fixture.cs" /> <Compile Include="NHSpecificTest\NH473\Parent.cs" /> @@ -1986,6 +1989,7 @@ <EmbeddedResource Include="Bytecode\Lightweight\ProductLine.hbm.xml" /> <EmbeddedResource Include="DriverTest\MultiTypeEntity.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1941\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1922\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1908ThreadSafety\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <te...@us...> - 2009-09-21 02:05:16
|
Revision: 4720 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4720&view=rev Author: tehlike Date: 2009-09-21 02:04:47 +0000 (Mon, 21 Sep 2009) Log Message: ----------- Adding tests for NH-1963 Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/CacheableQueryOnByteArray.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/DomainClass.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/Mappings.hbm.xml Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/CacheableQueryOnByteArray.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/CacheableQueryOnByteArray.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/CacheableQueryOnByteArray.cs 2009-09-21 02:04:47 UTC (rev 4720) @@ -0,0 +1,96 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using NHibernate.Dialect; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1963 +{ + [TestFixture] + public class CacheableQueryOnByteArray : BugTestCase + { + protected override void OnSetUp() + { + base.OnSetUp(); + using (ISession session = this.OpenSession()) + { + DomainClass entity = new DomainClass(); + entity.Id = 1; + entity.ByteData = new byte[] {1, 2, 3}; + session.Save(entity); + session.Flush(); + } + } + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession session = this.OpenSession()) + { + string hql = "from System.Object"; + session.Delete(hql); + session.Flush(); + } + } + + protected override bool AppliesTo(NHibernate.Dialect.Dialect dialect) + { + return dialect as MsSql2000Dialect != null; + } + + [Test,Ignore] + public void Should_be_able_to_do_cacheable_query_on_byte_array_field() + { + using (ISession session = this.OpenSession()) + { + var data = new byte[] { 1, 2, 3 }; + + var result = session.CreateQuery("from DomainClass d where d.ByteData = :data") + .SetParameter("data", data) + .SetCacheable(true) + .UniqueResult<DomainClass>(); + + Assert.IsNotNull(result); + } + + using (ISession session = this.OpenSession()) + { + var data = new byte[] { 1, 2, 3 }; + + var result = session.CreateQuery("from DomainClass d where d.ByteData = :data") + .SetParameter("data", data) + .SetCacheable(true) + .UniqueResult<DomainClass>(); + + Assert.IsNotNull(result); + } + } + + [Test] + public void Should_work_when_query_is_not_cachable() + { + using (ISession session = this.OpenSession()) + { + var data = new byte[] { 1, 2, 3 }; + + var result = session.CreateQuery("from DomainClass d where d.ByteData = :data") + .SetParameter("data", data) + .UniqueResult<DomainClass>(); + + Assert.IsNotNull(result); + } + + using (ISession session = this.OpenSession()) + { + var data = new byte[] { 1, 2, 3 }; + + var result = session.CreateQuery("from DomainClass d where d.ByteData = :data") + .SetParameter("data", data) + .UniqueResult<DomainClass>(); + + Assert.IsNotNull(result); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/DomainClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/DomainClass.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/DomainClass.cs 2009-09-21 02:04:47 UTC (rev 4720) @@ -0,0 +1,22 @@ + + +namespace NHibernate.Test.NHSpecificTest.NH1963 +{ + public class DomainClass + { + private byte[] byteData; + private int id; + + public int Id + { + get { return id; } + set { id = value; } + } + + public byte[] ByteData + { + get { return byteData; } + set { byteData = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1963/Mappings.hbm.xml 2009-09-21 02:04:47 UTC (rev 4720) @@ -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.NH1963" default-access="field.camelcase" + default-lazy="false"> + <class name="DomainClass"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="ByteData"/> + </class> +</hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-21 01:57:56 UTC (rev 4719) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-21 02:04:47 UTC (rev 4720) @@ -603,6 +603,8 @@ <Compile Include="NHSpecificTest\NH1938\Model.cs" /> <Compile Include="NHSpecificTest\NH1939\AuxType.cs" /> <Compile Include="NHSpecificTest\NH1939\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1963\CacheableQueryOnByteArray.cs" /> + <Compile Include="NHSpecificTest\NH1963\DomainClass.cs" /> <Compile Include="NHSpecificTest\NH1969\DummyEntity.cs" /> <Compile Include="NHSpecificTest\NH1969\EntityWithTypeProperty.cs" /> <Compile Include="NHSpecificTest\NH1969\Fixture.cs" /> @@ -2020,6 +2022,7 @@ <EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" /> <EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1963\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1969\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1922\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <te...@us...> - 2009-09-21 01:58:12
|
Revision: 4719 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4719&view=rev Author: tehlike Date: 2009-09-21 01:57:56 +0000 (Mon, 21 Sep 2009) Log Message: ----------- Adding tests for NH-1969 Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/DummyEntity.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/EntityWithTypeProperty.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/Mappings.hbm.xml Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/DummyEntity.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/DummyEntity.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/DummyEntity.cs 2009-09-21 01:57:56 UTC (rev 4719) @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NHibernate.Test.NHSpecificTest.NH1969 +{ + /// <summary> + /// Author : Stephane Verlet + /// </summary> + public class DummyEntity + { + + private int _id; + + + public int Id + { + get { return _id; } + set { _id = value; } + } + + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/EntityWithTypeProperty.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/EntityWithTypeProperty.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/EntityWithTypeProperty.cs 2009-09-21 01:57:56 UTC (rev 4719) @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NHibernate.Test.NHSpecificTest.NH1969 +{ + /// <summary> + /// Author : Stephane Verlet + /// </summary> + public class EntityWithTypeProperty + { + + private int _id; + private System.Type _typeValue; + + public EntityWithTypeProperty() + { + _id = 0; + } + + public int Id + { + get { return _id; } + set { _id = value; } + } + + public System.Type TypeValue + { + get { return _typeValue; } + set { _typeValue = value; } + } + + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/Fixture.cs 2009-09-21 01:57:56 UTC (rev 4719) @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1969 +{ + using Criterion; + + /// <summary> + /// Author : Stephane Verlet + /// </summary> + [TestFixture] + public class Fixture : BugTestCase + { + + protected override void OnSetUp() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + + EntityWithTypeProperty entity = new EntityWithTypeProperty(); + entity.Id = 1; + entity.TypeValue = typeof(System.IO.File); //A random not mapped type + s.Save(entity); + + entity = new EntityWithTypeProperty(); + entity.Id = 2; + entity.TypeValue = typeof(DummyEntity); // A mapped entity + s.Save(entity); + + tx.Commit(); + } + + } + + protected override void OnTearDown() + { + using (ISession session = this.OpenSession()) + using (ITransaction tx = session.BeginTransaction()) + { + string hql = "from System.Object"; + session.Delete(hql); + tx.Commit(); + } + } + + [Test,Ignore] + public void TestMappedTypeCriteria() + { + using (ISession s = OpenSession()) + { + ICriteria criteria = s.CreateCriteria(typeof(EntityWithTypeProperty)); + criteria.Add(Restrictions.Eq("TypeValue", typeof(DummyEntity))); + IList<EntityWithTypeProperty> results = criteria.List<EntityWithTypeProperty>(); + Assert.AreEqual(1, results.Count); + Assert.AreEqual(2, results[0].Id); + } + } + + + [Test] + public void TestMappedTypeHQL() + { + using (ISession s = OpenSession()) + { + + IQuery q = s.CreateQuery("select t from EntityWithTypeProperty as t where t.TypeValue = :type"); + q.SetParameter("type", typeof(DummyEntity)); + IList<EntityWithTypeProperty> results = q.List<EntityWithTypeProperty>(); + Assert.AreEqual(1, results.Count); + Assert.AreEqual(2, results[0].Id); + + } + } + + + + + [Test] + public void TestNonMappedTypeCriteria() + { + using (ISession s = OpenSession()) + { + ICriteria criteria = s.CreateCriteria(typeof(EntityWithTypeProperty)); + criteria.Add(Restrictions.Eq("TypeValue", typeof(System.IO.File))); + IList<EntityWithTypeProperty> results = criteria.List<EntityWithTypeProperty>(); + Assert.AreEqual(1, results.Count); + Assert.AreEqual(1, results[0].Id); + } + } + + [Test] + public void TestNonMappedTypeHQL() + { + using (ISession s = OpenSession()) + { + + IQuery q = s.CreateQuery("select t from EntityWithTypeProperty as t where t.TypeValue = :type"); + q.SetParameter("type", typeof(System.IO.File)); + IList<EntityWithTypeProperty> results = q.List<EntityWithTypeProperty>(); + Assert.AreEqual(1, results.Count); + Assert.AreEqual(1, results[0].Id); + + } + } + + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1969/Mappings.hbm.xml 2009-09-21 01:57:56 UTC (rev 4719) @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false"> + <class + name="NHibernate.Test.NHSpecificTest.NH1969.EntityWithTypeProperty, NHibernate.Test" + table="EntityWithTypeProperty"> + <id name="Id" column="id"> + <generator class="assigned" /> + </id> + + <property name="TypeValue" column="typeValue" /> + </class> + + <class + name="NHibernate.Test.NHSpecificTest.NH1969.DummyEntity, NHibernate.Test" + table="DummyEntity"> + + <id name="Id" column="id"> + <generator class="assigned" /> + </id> + + + </class> + + +</hibernate-mapping> \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-16 10:53:14 UTC (rev 4718) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-21 01:57:56 UTC (rev 4719) @@ -603,6 +603,9 @@ <Compile Include="NHSpecificTest\NH1938\Model.cs" /> <Compile Include="NHSpecificTest\NH1939\AuxType.cs" /> <Compile Include="NHSpecificTest\NH1939\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1969\DummyEntity.cs" /> + <Compile Include="NHSpecificTest\NH1969\EntityWithTypeProperty.cs" /> + <Compile Include="NHSpecificTest\NH1969\Fixture.cs" /> <Compile Include="NHSpecificTest\NH473\Child.cs" /> <Compile Include="NHSpecificTest\NH473\Fixture.cs" /> <Compile Include="NHSpecificTest\NH473\Parent.cs" /> @@ -2017,6 +2020,7 @@ <EmbeddedResource Include="Criteria\Lambda\Mappings.hbm.xml" /> <EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1969\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1922\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1908ThreadSafety\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2009-09-16 10:53:29
|
Revision: 4718 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4718&view=rev Author: ayenderahien Date: 2009-09-16 10:53:14 +0000 (Wed, 16 Sep 2009) Log Message: ----------- Merging from 2.1.x branch r4690 - NH-1928 r4691 - NH-1927 r4696 - Minor comment removal r4697 - Log session factory that opened the sessionFactory r4711 - better error message for failure in identifier generator creation r4715 - Better support for criteria queries on composite element collections r4716 - NH-1922 - DetachedCriteria with IStatelessSession Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SessionFactoryHelperExtensions.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Hql/Classic/SelectParser.cs trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs trunk/nhibernate/src/NHibernate/Hql/QuerySplitter.cs trunk/nhibernate/src/NHibernate/Hql/Util/SessionFactoryHelper.cs trunk/nhibernate/src/NHibernate/Id/IdentifierGeneratorFactory.cs trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs trunk/nhibernate/src/NHibernate/Impl/SessionFactoryObjectFactory.cs trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH830/AutoFlushTestFixture.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Loader/Criteria/ComponentCollectionCriteriaInfoProvider.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/EntityCriteriaInfoProvider.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/ICriteriaInfoProvider.cs trunk/nhibernate/src/NHibernate/Loader/Criteria/ScalarCollectionCriteriaInfoProvider.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Employee.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Money.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1922/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1922/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1922/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1922/Model.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927/Model.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928/Model.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Employee.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Money.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1922/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1922/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1922/Model.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1927/Model.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1928/Model.cs Property Changed: ---------------- trunk/nhibernate/ trunk/nhibernate/src/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Customer.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1850/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1904/Model.cs trunk/nhibernate/src/NHibernate.Test/Tools/hbm2ddl/SchemaExportTests/ Property changes on: trunk/nhibernate ___________________________________________________________________ Added: svn:mergeinfo + /branches/2.1.x/nhibernate:4690-4691,4696-4697,4711,4715-4716 Property changes on: trunk/nhibernate/src ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src:4659,4671,4681 + /branches/2.1.x/nhibernate/src:4659,4671,4681,4690-4691,4696-4697,4711,4715-4716 Modified: trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Criterion/DetachedCriteria.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -1,4 +1,5 @@ using System; +using NHibernate.Engine; using NHibernate.Impl; using NHibernate.SqlCommand; using NHibernate.Transform; @@ -65,6 +66,15 @@ return impl; } + /// <summary> + /// Get an executable instance of <c>Criteria</c>, + /// to actually run the query.</summary> + public ICriteria GetExecutableCriteria(IStatelessSession session) + { + impl.Session = (ISessionImplementor)session; + return impl; + } + public static DetachedCriteria For(System.Type entityType) { return new DetachedCriteria(entityType); Modified: trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Engine/Query/ParameterParser.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -64,7 +64,17 @@ if (afterNewLine && (indx + 1 < stringLength) && sqlString.Substring(indx, 2) == "--") { var closeCommentIdx = sqlString.IndexOf(Environment.NewLine, indx + 2); - recognizer.Other(sqlString.Substring(indx, closeCommentIdx - indx)); + string comment; + if (closeCommentIdx == -1) + { + closeCommentIdx = sqlString.Length; + comment = sqlString.Substring(indx); + } + else + { + comment = sqlString.Substring(indx, closeCommentIdx - indx + Environment.NewLine.Length); + } + recognizer.Other(comment); indx = closeCommentIdx + NewLineLength - 1; continue; } Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SessionFactoryHelperExtensions.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SessionFactoryHelperExtensions.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/SessionFactoryHelperExtensions.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -17,6 +17,7 @@ { private readonly ISessionFactoryImplementor _sfi; private readonly NullableDictionary<string, IPropertyMapping> _collectionPropertyMappingByRole; + private readonly SessionFactoryHelper helper; /// <summary> /// Construct a new SessionFactoryHelperExtensions instance. @@ -25,6 +26,7 @@ public SessionFactoryHelperExtensions(ISessionFactoryImplementor sfi) { _sfi = sfi; + helper = new SessionFactoryHelper(_sfi); _collectionPropertyMappingByRole = new NullableDictionary<string, IPropertyMapping>(); } @@ -251,7 +253,7 @@ /// <returns>The defined persister for this class, or null if none found.</returns> private static IQueryable FindQueryableUsingImports(ISessionFactoryImplementor sfi, string className) { - return SessionFactoryHelper.FindQueryableUsingImports(sfi, className); + return new SessionFactoryHelper(sfi).FindQueryableUsingImports(className); } /// <summary> @@ -261,7 +263,7 @@ /// <returns>The defined persister for this entity, or null if none found.</returns> private IEntityPersister FindEntityPersisterByName(string name) { - return SessionFactoryHelper.FindEntityPersisterUsingImports(_sfi, name); + return helper.FindEntityPersisterUsingImports(name); } /// <summary> Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -537,7 +537,7 @@ internal IQueryable GetPersisterUsingImports(string className) { - return SessionFactoryHelper.FindQueryableUsingImports(Factory, className); + return helper.FindQueryableUsingImports(className); } internal IQueryable GetPersister(string clazz) @@ -1320,7 +1320,7 @@ return result; } - public static string[] ConcreteQueries(string query, ISessionFactoryImplementor factory) + public string[] ConcreteQueries(string query, ISessionFactoryImplementor factory) { // TODO H3.2 check if the QuerySplitter can do the work (this method is not present in H3.2) @@ -1374,7 +1374,7 @@ ((last != null && beforeClassTokens.Contains(last)) && (next == null || !notAfterClassTokens.Contains(next))) || PathExpressionParser.EntityClass.Equals(last)) { - System.Type clazz = SessionFactoryHelper.GetImportedClass(factory, token); + System.Type clazz = helper.GetImportedClass(token); if (clazz != null) { string[] implementors = factory.GetImplementors(clazz.FullName); Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/SelectParser.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/SelectParser.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/SelectParser.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -35,6 +35,7 @@ public void Token(string token, QueryTranslator q) { + SessionFactoryHelper helper = new SessionFactoryHelper(q.Factory); string lctoken = token.ToLowerInvariant(); if (first) @@ -55,7 +56,7 @@ if (afterNew) { afterNew = false; - holderClass = SessionFactoryHelper.GetImportedClass(q.Factory, token); + holderClass = helper.GetImportedClass(token); if (holderClass == null) { throw new QueryException("class not found: " + token); Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/WhereParser.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -463,6 +463,7 @@ private void DoToken(string token, QueryTranslator q) { + SessionFactoryHelper helper = new SessionFactoryHelper(q.Factory); if (q.IsName(StringHelper.Root(token))) //path expression { DoPathExpression(q.Unalias(token), q); @@ -508,7 +509,7 @@ { fieldName = StringHelper.Unqualify(token); string typeName = StringHelper.Qualifier(token); - importedType = SessionFactoryHelper.GetImportedClass(q.Factory, typeName); + importedType = helper.GetImportedClass(typeName); } if (indexOfDot > -1 && importedType != null && Modified: trunk/nhibernate/src/NHibernate/Hql/QuerySplitter.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/QuerySplitter.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Hql/QuerySplitter.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -46,6 +46,8 @@ //TODO: this is one of the ugliest and most fragile pieces of code in Hibernate.... + SessionFactoryHelper helper = new SessionFactoryHelper(factory); + string[] tokens = StringHelper.Split(StringHelper.WhiteSpace + "(),", query, true); if (tokens.Length == 0) { @@ -95,7 +97,7 @@ (next == null || !notAfterClassTokens.Contains(next))) || PathExpressionParser.EntityClass.Equals(last)) { - System.Type clazz = SessionFactoryHelper.GetImportedClass(factory, token); + System.Type clazz = helper.GetImportedClass(token); if (clazz != null) { string[] implementors = factory.GetImplementors(clazz.FullName); Modified: trunk/nhibernate/src/NHibernate/Hql/Util/SessionFactoryHelper.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Util/SessionFactoryHelper.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Hql/Util/SessionFactoryHelper.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -1,4 +1,8 @@ +using System; +using System.Collections.Generic; using NHibernate.Engine; +using NHibernate.Hql.Ast.ANTLR; +using NHibernate.Persister.Collection; using NHibernate.Persister.Entity; using NHibernate.Util; @@ -9,13 +13,22 @@ /// </summary> public class SessionFactoryHelper { - public static IQueryable FindQueryableUsingImports(ISessionFactoryImplementor sfi, string className) + private readonly ISessionFactoryImplementor sfi; + private readonly IDictionary<string,CollectionPropertyMapping> collectionPropertyMappingByRole = + new Dictionary<string,CollectionPropertyMapping>(); + + public SessionFactoryHelper(ISessionFactoryImplementor sfi) { - return FindEntityPersisterUsingImports(sfi, className) as IQueryable; + this.sfi = sfi; } - public static IEntityPersister FindEntityPersisterUsingImports(ISessionFactoryImplementor sfi, string className) + public IQueryable FindQueryableUsingImports(string className) { + return FindEntityPersisterUsingImports(className) as IQueryable; + } + + public IEntityPersister FindEntityPersisterUsingImports(string className) + { // NH : short cut if (string.IsNullOrEmpty(className)) { @@ -61,8 +74,75 @@ return TypeNameParser.Parse(assemblyQualifiedName).Type; } - public static System.Type GetImportedClass(ISessionFactoryImplementor sfi, string className) + + + /// <summary> + /// Locate the collection persister by the collection role. + /// </summary> + /// <param name="role">The collection role name.</param> + /// <returns>The defined CollectionPersister for this collection role, or null.</returns> + public IQueryableCollection GetCollectionPersister(String role) { + try + { + return (IQueryableCollection)sfi.GetCollectionPersister(role); + } + catch (InvalidCastException cce) + { + throw new QueryException("collection is not queryable: " + role); + } + catch (Exception e) + { + throw new QueryException("collection not found: " + role); + } + } + + /// <summary> + /// Locate the persister by class or entity name, requiring that such a persister + /// exists + /// </summary> + /// <param name="name">The class or entity name</param> + /// <returns>The defined persister for this entity</returns> + public IEntityPersister RequireClassPersister(String name) + { + IEntityPersister cp = FindEntityPersisterByName(name); + if (cp == null) + { + throw new QuerySyntaxException(name + " is not mapped"); + } + + return cp; + } + + /// <summary> + /// Locate the persister by class or entity name. + /// </summary> + /// <param name="name">The class or entity name</param> + /// <returns>The defined persister for this entity, or null if none found.</returns> + private IEntityPersister FindEntityPersisterByName(String name) + { + // First, try to get the persister using the given name directly. + try + { + return sfi.GetEntityPersister(name); + } + catch (MappingException ignore) + { + // unable to locate it using this name + } + + // If that didn't work, try using the 'import' name. + String importedClassName = sfi.GetImportedClassName(name); + if (importedClassName == null) + { + return null; + } + return sfi.GetEntityPersister(importedClassName); + } + + + public System.Type GetImportedClass(string className) + { string importedName = sfi.GetImportedClassName(className); if (importedName == null) @@ -73,5 +153,49 @@ // NH Different implementation: our sessionFactory.Imports hold AssemblyQualifiedName return System.Type.GetType(importedName, false); } + + + /// <summary> + /// Retreive a PropertyMapping describing the given collection role. + /// </summary> + /// <param name="role">The collection role for whcih to retrieve the property mapping.</param> + /// <returns>The property mapping.</returns> + public IPropertyMapping GetCollectionPropertyMapping(String role) + { + return collectionPropertyMappingByRole[role]; + } + + + /* Locate the collection persister by the collection role, requiring that + * such a persister exist. + * + * @param role The collection role name. + * @return The defined CollectionPersister for this collection role. + * @throws QueryException Indicates that the collection persister could not be found. + */ + public IQueryableCollection RequireQueryableCollection(String role) + { + try + { + IQueryableCollection queryableCollection = (IQueryableCollection)sfi + .GetCollectionPersister(role); + if (queryableCollection != null) + { + collectionPropertyMappingByRole.Add(role, + new CollectionPropertyMapping(queryableCollection)); + } + return queryableCollection; + } + catch (InvalidCastException) + { + throw new QueryException( + "collection role is not queryable: " + role); + } + catch (Exception) + { + throw new QueryException("collection role not found: " + + role); + } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Id/IdentifierGeneratorFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Id/IdentifierGeneratorFactory.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Id/IdentifierGeneratorFactory.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -215,7 +215,7 @@ } catch (Exception e) { - throw new MappingException("could not instantiate id generator", e); + throw new MappingException("could not instantiate id generator: " + strategy, e); } } Modified: trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Impl/SessionFactoryImpl.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -1172,6 +1172,7 @@ } #region NHibernate specific + public string TryGetGuessEntityName(System.Type implementor) { string result; @@ -1179,6 +1180,16 @@ return result; } + public string Name + { + get { return name; } + } + + public string Uuid + { + get { return uuid; } + } + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Impl/SessionFactoryObjectFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionFactoryObjectFactory.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Impl/SessionFactoryObjectFactory.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -17,17 +17,11 @@ /// you are serializing in the same AppDomain then there will be no problem because the uid will /// be in this object. /// </para> - /// <para> - /// TODO: verify that the AppDomain statements are correct. - /// </para> /// </remarks> public static class SessionFactoryObjectFactory { - // to stop this class from being unloaded - this is a comment - // from h2.0.3 - is this applicable to .net also??? private static readonly ILog log; - // in h2.0.3 these use a class called "FastHashMap" private static readonly IDictionary<string, ISessionFactory> Instances = new Dictionary<string, ISessionFactory>(); private static readonly IDictionary<string, ISessionFactory> NamedInstances = new Dictionary<string, ISessionFactory>(); Modified: trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Impl/SessionImpl.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -228,7 +228,8 @@ if (log.IsDebugEnabled) { - log.Debug(string.Format("[session-id={0}] opened session at timestamp:{1}", SessionId, timestamp)); + log.DebugFormat("[session-id={0}] opened session at timestamp: {1}, for session factory: [{2}/{3}]", + SessionId, timestamp, factory.Name, factory.Uuid); } CheckAndUpdateSessionStatus(); Copied: trunk/nhibernate/src/NHibernate/Loader/Criteria/ComponentCollectionCriteriaInfoProvider.cs (from rev 4715, branches/2.1.x/nhibernate/src/NHibernate/Loader/Criteria/ComponentCollectionCriteriaInfoProvider.cs) =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/ComponentCollectionCriteriaInfoProvider.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/ComponentCollectionCriteriaInfoProvider.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using NHibernate.Persister.Collection; +using NHibernate.Persister.Entity; +using NHibernate.Type; + +namespace NHibernate.Loader.Criteria +{ + public class ComponentCollectionCriteriaInfoProvider : ICriteriaInfoProvider + { + private readonly IQueryableCollection persister; + private readonly IDictionary<String, IType> subTypes = new Dictionary<string, IType>(); + + public ComponentCollectionCriteriaInfoProvider(IQueryableCollection persister) + { + this.persister = persister; + if (!persister.ElementType.IsComponentType) + { + throw new ArgumentException("persister for role " + persister.Role + " is not a collection-of-component"); + } + + var componentType = (ComponentType)persister.ElementType; + var names = componentType.PropertyNames; + var types = componentType.Subtypes; + + for (var i = 0; i < names.Length; i++) + { + subTypes.Add(names[i], types[i]); + } + + } + + public String Name + { + get + { + return persister.Role; + } + } + + public string[] Spaces + { + get + { + return persister.CollectionSpaces; + } + } + + public IPropertyMapping PropertyMapping + { + get + { + return persister; + } + } + + public IType GetType(String relativePath) + { + // TODO: can a component have a nested component? then we may need to do something more here... + if (relativePath.IndexOf('.') >= 0) + throw new ArgumentException("dotted paths not handled (yet?!) for collection-of-component"); + + IType type; + + if (subTypes.TryGetValue(relativePath, out type) == false) + throw new ArgumentException("property " + relativePath + " not found in component of collection " + Name); + + return type; + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -1,6 +1,8 @@ using System.Collections.Generic; using Iesi.Collections.Generic; +using log4net; using NHibernate.Engine; +using NHibernate.Persister.Collection; using NHibernate.Persister.Entity; using NHibernate.SqlCommand; using NHibernate.Type; @@ -25,6 +27,8 @@ private readonly string[] userAliases; private readonly IList<string> userAliasList = new List<string>(); + private static readonly ILog logger = LogManager.GetLogger(typeof (CriteriaJoinWalker)); + public CriteriaJoinWalker(IOuterJoinLoadable persister, CriteriaQueryTranslator translator, ISessionFactoryImplementor factory, ICriteria criteria, string rootEntityName, IDictionary<string, IFilter> enabledFilters) @@ -126,8 +130,15 @@ protected override string GenerateTableAlias(int n, string path, IJoinable joinable) { - if (joinable.ConsumesEntityAlias()) + bool shouldCreateUserAlias = joinable.ConsumesEntityAlias(); + if(shouldCreateUserAlias == false && joinable.IsCollection) { + var elementType = ((ICollectionPersister)joinable).ElementType; + if (elementType != null) + shouldCreateUserAlias = elementType.IsComponentType; + } + if (shouldCreateUserAlias) + { ICriteria subcriteria = translator.GetCriteria(path); string sqlAlias = subcriteria == null ? null : translator.GetSQLAlias(subcriteria); if (sqlAlias != null) @@ -135,10 +146,8 @@ userAliasList.Add(subcriteria.Alias); //alias may be null return sqlAlias; //EARLY EXIT } - else - { - userAliasList.Add(null); - } + + userAliasList.Add(null); } return base.GenerateTableAlias(n + translator.SQLAliasCount, path, joinable); } Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaQueryTranslator.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text; using Iesi.Collections.Generic; +using log4net; using NHibernate.Criterion; using NHibernate.Engine; using NHibernate.Hql.Util; @@ -24,9 +25,14 @@ private readonly CriteriaImpl rootCriteria; private readonly string rootEntityName; private readonly string rootSQLAlias; - private readonly int aliasCount = 0; + private const int aliasCount = 0; - private readonly IDictionary<ICriteria, string> criteriaEntityNames = new LinkedHashMap<ICriteria, string>(); + private readonly IDictionary<ICriteria, ICriteriaInfoProvider> criteriaInfoMap = + new Dictionary<ICriteria, ICriteriaInfoProvider>(); + + private readonly IDictionary<String, ICriteriaInfoProvider> nameCriteriaInfoMap = + new Dictionary<string, ICriteriaInfoProvider>(); + private readonly ISet<ICollectionPersister> criteriaCollectionPersisters = new HashedSet<ICollectionPersister>(); private readonly IDictionary<ICriteria, string> criteriaSQLAliasMap = new Dictionary<ICriteria, string>(); @@ -36,23 +42,26 @@ private readonly ISessionFactoryImplementor sessionFactory; private int indexForAlias = 0; + private static readonly ILog logger = LogManager.GetLogger(typeof(CriteriaQueryTranslator)); private readonly List<TypedValue> usedTypedValues = new List<TypedValue>(); + private SessionFactoryHelper helper; public CriteriaQueryTranslator(ISessionFactoryImplementor factory, CriteriaImpl criteria, string rootEntityName, - string rootSQLAlias, ICriteriaQuery outerQuery) + string rootSQLAlias, ICriteriaQuery outerQuery) : this(factory, criteria, rootEntityName, rootSQLAlias) { outerQueryTranslator = outerQuery; } public CriteriaQueryTranslator(ISessionFactoryImplementor factory, CriteriaImpl criteria, string rootEntityName, - string rootSQLAlias) + string rootSQLAlias) { rootCriteria = criteria; this.rootEntityName = rootEntityName; sessionFactory = factory; this.rootSQLAlias = rootSQLAlias; + helper = new SessionFactoryHelper(factory); CreateAliasCriteriaMap(); CreateAssociationPathCriteriaMap(); @@ -62,7 +71,7 @@ } [CLSCompliant(false)] // TODO: Why does this cause a problem in 1.1 - public string RootSQLAlias + public string RootSQLAlias { get { return rootSQLAlias; } } @@ -71,9 +80,9 @@ { ISet<string> result = new HashedSet<string>(); - foreach (string entityName in criteriaEntityNames.Values) + foreach (ICriteriaInfoProvider info in criteriaInfoMap.Values) { - result.AddAll(Factory.GetEntityPersister(entityName).QuerySpaces); + result.AddAll(info.Spaces); } foreach (ICollectionPersister collectionPersister in criteriaCollectionPersisters) @@ -131,7 +140,7 @@ return new QueryParameters(typeArray, valueArray, lockModes, selection, rootCriteria.Cacheable, rootCriteria.CacheRegion, - rootCriteria.Comment, rootCriteria.LookupByNaturalKey, rootCriteria.ResultTransformer); + rootCriteria.Comment, rootCriteria.LookupByNaturalKey, rootCriteria.ResultTransformer); } public SqlString GetGroupBy() @@ -140,7 +149,7 @@ { return rootCriteria.Projection.ToGroupSqlString(rootCriteria.ProjectionCriteria, this, - new CollectionHelper.EmptyMapClass<string, IFilter>()); + new CollectionHelper.EmptyMapClass<string, IFilter>()); } else { @@ -245,6 +254,7 @@ { ICriteria result; associationPathCriteriaMap.TryGetValue(path, out result); + logger.DebugFormat("getCriteria for path={0} crit={1}", path, result); return result; } @@ -330,33 +340,119 @@ else { // otherwise, recurse - return GetWholeAssociationPath((CriteriaImpl.Subcriteria) parent) + '.' + path; + return GetWholeAssociationPath((CriteriaImpl.Subcriteria)parent) + '.' + path; } } private void CreateCriteriaEntityNameMap() { - criteriaEntityNames[rootCriteria] = rootEntityName; + // initialize the rootProvider first + ICriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider((IQueryable)sessionFactory.GetEntityPersister(rootEntityName)); + criteriaInfoMap.Add(rootCriteria, rootProvider); + nameCriteriaInfoMap.Add(rootProvider.Name, rootProvider); + foreach (KeyValuePair<string, ICriteria> me in associationPathCriteriaMap) { - criteriaEntityNames[me.Value] = GetPathEntityName(me.Key); + ICriteriaInfoProvider info = GetPathInfo(me.Key); + criteriaInfoMap.Add(me.Value, info); + nameCriteriaInfoMap[info.Name] = info; } } - private string GetPathEntityName(string path) + + private void CreateCriteriaCollectionPersisters() { - IQueryable persister = (IQueryable) sessionFactory.GetEntityPersister(rootEntityName); + foreach (KeyValuePair<string, ICriteria> me in associationPathCriteriaMap) + { + IJoinable joinable = GetPathJoinable(me.Key); + if (joinable != null && joinable.IsCollection) + { + criteriaCollectionPersisters.Add((ICollectionPersister)joinable); + } + } + } + + private IJoinable GetPathJoinable(string path) + { + IJoinable last = (IJoinable)Factory.GetEntityPersister(rootEntityName); + IPropertyMapping lastEntity = (IPropertyMapping)last; + + string componentPath = ""; + StringTokenizer tokens = new StringTokenizer(path, ".", false); + foreach (string token in tokens) + { + componentPath += token; + IType type = lastEntity.ToType(componentPath); + if (type.IsAssociationType) + { + if(type.IsCollectionType) + { + // ignore joinables for composite collections + var collectionType = (CollectionType)type; + var persister = Factory.GetCollectionPersister(collectionType.Role); + if(persister.ElementType.IsEntityType==false) + return null; + } + IAssociationType atype = (IAssociationType)type; + + last = atype.GetAssociatedJoinable(Factory); + lastEntity = (IPropertyMapping)Factory.GetEntityPersister(atype.GetAssociatedEntityName(Factory)); + componentPath = ""; + } + else if (type.IsComponentType) + { + componentPath += '.'; + } + else + { + throw new QueryException("not an association: " + componentPath); + } + } + return last; + } + + private ICriteriaInfoProvider GetPathInfo(string path) + { + StringTokenizer tokens = new StringTokenizer(path, ".", false); string componentPath = string.Empty; + + // start with the 'rootProvider' + ICriteriaInfoProvider provider; + if (nameCriteriaInfoMap.TryGetValue(rootEntityName, out provider) == false) + throw new ArgumentException("Could not find ICriteriaInfoProvider for: " + path); + + foreach (string token in tokens) { componentPath += token; - IType type = persister.ToType(componentPath); + logger.DebugFormat("searching for {0}", componentPath); + IType type = provider.GetType(componentPath); if (type.IsAssociationType) { - IAssociationType atype = (IAssociationType) type; - persister = (IQueryable) sessionFactory.GetEntityPersister(atype.GetAssociatedEntityName(sessionFactory)); + // CollectionTypes are always also AssociationTypes - but there's not always an associated entity... + IAssociationType atype = (IAssociationType)type; + + CollectionType ctype = type.IsCollectionType ? (CollectionType)type : null; + IType elementType = (ctype != null) ? ctype.GetElementType(sessionFactory) : null; + // is the association a collection of components or value-types? (i.e a colloction of valued types?) + if (ctype != null && elementType.IsComponentType) + { + provider = new ComponentCollectionCriteriaInfoProvider(helper.GetCollectionPersister(ctype.Role)); + } + else if (ctype != null && !elementType.IsEntityType) + { + provider = new ScalarCollectionCriteriaInfoProvider(helper, ctype.Role); + } + else + { + provider = new EntityCriteriaInfoProvider((IQueryable)sessionFactory.GetEntityPersister( + atype.GetAssociatedEntityName( + sessionFactory) + )); + } + componentPath = string.Empty; } else if (type.IsComponentType) @@ -368,22 +464,27 @@ throw new QueryException("not an association: " + componentPath); } } - return persister.EntityName; + + logger.DebugFormat("returning entity name={0} for path={1} class={2}", + provider.Name, path, provider.GetType().Name); + return provider; } private void CreateCriteriaSQLAliasMap() { int i = 0; - foreach (KeyValuePair<ICriteria, string> me in criteriaEntityNames) + foreach (KeyValuePair<ICriteria, ICriteriaInfoProvider> me in criteriaInfoMap) { ICriteria crit = me.Key; string alias = crit.Alias; if (alias == null) { - alias = me.Value; // the entity name + alias = me.Value.Name; // the entity name } criteriaSQLAliasMap[crit] = StringHelper.GenerateAlias(alias, i++); + logger.DebugFormat("put criteria={0} alias={1}", + crit, criteriaSQLAliasMap[crit]); } criteriaSQLAliasMap[rootCriteria] = rootSQLAlias; } @@ -395,14 +496,17 @@ public string GetSQLAlias(ICriteria criteria) { - return criteriaSQLAliasMap[criteria]; + String alias = criteriaSQLAliasMap[criteria]; + logger.DebugFormat("returning alias={0} for criteria={1}", alias, criteria); + return alias; } public string GetEntityName(ICriteria criteria) { - string result; - criteriaEntityNames.TryGetValue(criteria, out result); - return result; + ICriteriaInfoProvider result; + if(criteriaInfoMap.TryGetValue(criteria, out result)==false) + throw new ArgumentException("Could not find a matching criteria info provider to: " + criteria); + return result.Name; } public string GetColumn(ICriteria criteria, string propertyName) @@ -442,18 +546,18 @@ public string[] GetIdentifierColumns(ICriteria subcriteria) { - string[] idcols = ((ILoadable) GetPropertyMapping(GetEntityName(subcriteria))).IdentifierColumnNames; + string[] idcols = ((ILoadable)GetPropertyMapping(GetEntityName(subcriteria))).IdentifierColumnNames; return StringHelper.Qualify(GetSQLAlias(subcriteria), idcols); } public IType GetIdentifierType(ICriteria subcriteria) { - return ((ILoadable) GetPropertyMapping(GetEntityName(subcriteria))).IdentifierType; + return ((ILoadable)GetPropertyMapping(GetEntityName(subcriteria))).IdentifierType; } public TypedValue GetTypedIdentifierValue(ICriteria subcriteria, object value) { - ILoadable loadable = (ILoadable) GetPropertyMapping(GetEntityName(subcriteria)); + ILoadable loadable = (ILoadable)GetPropertyMapping(GetEntityName(subcriteria)); return new TypedValue(loadable.IdentifierType, value, EntityMode.Poco); } @@ -518,8 +622,8 @@ // Detect discriminator values... if (value is System.Type) { - System.Type entityClass = (System.Type) value; - IQueryable q = SessionFactoryHelper.FindQueryableUsingImports(sessionFactory, entityClass.FullName); + System.Type entityClass = (System.Type)value; + IQueryable q = helper.FindQueryableUsingImports(entityClass.FullName); if (q != null) { @@ -533,7 +637,10 @@ private IPropertyMapping GetPropertyMapping(string entityName) { - return (IPropertyMapping) sessionFactory.GetEntityPersister(entityName); + ICriteriaInfoProvider info ; + if (nameCriteriaInfoMap.TryGetValue(entityName, out info)==false) + throw new InvalidOperationException("Could not find criteria info provider for: " + entityName); + return info.PropertyMapping; } public string GetEntityName(ICriteria subcriteria, string propertyName) @@ -600,49 +707,7 @@ } } - private void CreateCriteriaCollectionPersisters() - { - foreach (KeyValuePair<string, ICriteria> me in associationPathCriteriaMap) - { - IJoinable joinable = GetPathJoinable(me.Key); - if (joinable.IsCollection) - { - criteriaCollectionPersisters.Add((ICollectionPersister) joinable); - } - } - } - private IJoinable GetPathJoinable(string path) - { - IJoinable last = (IJoinable) Factory.GetEntityPersister(rootEntityName); - IPropertyMapping lastEntity = (IPropertyMapping) last; - - string componentPath = ""; - - StringTokenizer tokens = new StringTokenizer(path, ".", false); - foreach (string token in tokens) - { - componentPath += token; - IType type = lastEntity.ToType(componentPath); - if (type.IsAssociationType) - { - IAssociationType atype = (IAssociationType) type; - last = atype.GetAssociatedJoinable(Factory); - lastEntity = (IPropertyMapping) Factory.GetEntityPersister(atype.GetAssociatedEntityName(Factory)); - componentPath = ""; - } - else if (type.IsComponentType) - { - componentPath += '.'; - } - else - { - throw new QueryException("not an association: " + componentPath); - } - } - return last; - } - public SqlString GetHavingCondition(IDictionary<string, IFilter> enabledFilters) { SqlStringBuilder condition = new SqlStringBuilder(30); Copied: trunk/nhibernate/src/NHibernate/Loader/Criteria/EntityCriteriaInfoProvider.cs (from rev 4715, branches/2.1.x/nhibernate/src/NHibernate/Loader/Criteria/EntityCriteriaInfoProvider.cs) =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/EntityCriteriaInfoProvider.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/EntityCriteriaInfoProvider.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -0,0 +1,45 @@ +using System; +using NHibernate.Persister.Entity; +using NHibernate.Type; + +namespace NHibernate.Loader.Criteria +{ + public class EntityCriteriaInfoProvider : ICriteriaInfoProvider + { + readonly IQueryable persister; + + public EntityCriteriaInfoProvider(IQueryable persister) + { + this.persister = persister; + } + + public String Name + { + get + { + return persister.EntityName; + } + } + + public string[] Spaces + { + get + { + return persister.QuerySpaces; + } + } + + public IPropertyMapping PropertyMapping + { + get + { + return persister; + } + } + + public IType GetType(String relativePath) + { + return persister.ToType(relativePath); + } + } +} \ No newline at end of file Copied: trunk/nhibernate/src/NHibernate/Loader/Criteria/ICriteriaInfoProvider.cs (from rev 4715, branches/2.1.x/nhibernate/src/NHibernate/Loader/Criteria/ICriteriaInfoProvider.cs) =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/ICriteriaInfoProvider.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/ICriteriaInfoProvider.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -0,0 +1,14 @@ +using System; +using NHibernate.Persister.Entity; +using NHibernate.Type; + +namespace NHibernate.Loader.Criteria +{ + public interface ICriteriaInfoProvider + { + string Name { get; } + string[] Spaces { get; } + IPropertyMapping PropertyMapping { get; } + IType GetType(String relativePath); + } +} \ No newline at end of file Copied: trunk/nhibernate/src/NHibernate/Loader/Criteria/ScalarCollectionCriteriaInfoProvider.cs (from rev 4715, branches/2.1.x/nhibernate/src/NHibernate/Loader/Criteria/ScalarCollectionCriteriaInfoProvider.cs) =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Criteria/ScalarCollectionCriteriaInfoProvider.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Loader/Criteria/ScalarCollectionCriteriaInfoProvider.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -0,0 +1,52 @@ +using System; +using NHibernate.Hql.Util; +using NHibernate.Persister.Collection; +using NHibernate.Persister.Entity; +using NHibernate.Type; + +namespace NHibernate.Loader.Criteria +{ + public class ScalarCollectionCriteriaInfoProvider : ICriteriaInfoProvider + { + private readonly String role; + private readonly IQueryableCollection persister; + private readonly SessionFactoryHelper helper; + public ScalarCollectionCriteriaInfoProvider(SessionFactoryHelper helper, String role) + { + this.role = role; + this.helper = helper; + this.persister = helper.RequireQueryableCollection(role); + } + + public String Name + { + get + { + return role; + } + } + + public string[] Spaces + { + get + { + return persister.CollectionSpaces; + } + } + + public IPropertyMapping PropertyMapping + { + get + { + return helper.GetCollectionPropertyMapping(role); + } + } + + public IType GetType(String relativePath) + { + //not sure what things are going to be passed here, how about 'id', maybe 'index' or 'key' or 'elements' ??? + return PropertyMapping.ToType(relativePath); + } + + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -575,7 +575,9 @@ if (enabledFilters.Count > 0) { var manyToOneFilterFragment = oj.Joinable.FilterFragment(oj.RHSAlias, enabledFilters); - outerjoin.AddCondition(manyToOneFilterFragment); + var joinClauseDoesNotContainsFilterAlready = outerjoin.ToFromFragmentString.IndexOfCaseInsensitive(manyToOneFilterFragment) == -1; + if(joinClauseDoesNotContainsFilterAlready) + outerjoin.AddCondition(manyToOneFilterFragment); } } last = oj; @@ -781,7 +783,6 @@ else { SqlStringBuilder buf = new SqlStringBuilder(associations.Count * 3); - buf.Add(StringHelper.CommaSpace); int entityAliasCount = 0; int collectionAliasCount = 0; @@ -802,16 +803,16 @@ joinable.SelectFragment(next == null ? null : next.Joinable, next == null ? null : next.RHSAlias, join.RHSAlias, entitySuffix, collectionSuffix, join.JoinType == JoinType.LeftOuterJoin); - buf.Add(selectFragment); - + if (selectFragment.Trim().Length > 0) + { + buf.Add(StringHelper.CommaSpace) + .Add(selectFragment); + } if (joinable.ConsumesEntityAlias()) entityAliasCount++; if (joinable.ConsumesCollectionAlias() && join.JoinType == JoinType.LeftOuterJoin) collectionAliasCount++; - - if (i < associations.Count - 1 && selectFragment.Trim().Length > 0) - buf.Add(StringHelper.CommaSpace); } return buf.ToSqlString().ToString(); Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -13,6 +13,7 @@ using NHibernate.Engine; using NHibernate.Event; using NHibernate.Exceptions; +using NHibernate.Hql.Util; using NHibernate.Impl; using NHibernate.Persister.Collection; using NHibernate.Persister.Entity; @@ -48,10 +49,12 @@ private readonly ISessionFactoryImplementor factory; private ColumnNameCache columnNameCache; + protected SessionFactoryHelper helper; public Loader(ISessionFactoryImplementor factory) { this.factory = factory; + helper = new SessionFactoryHelper(factory); } /// <summary> Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-09-16 10:34:39 UTC (rev 4717) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-09-16 10:53:14 UTC (rev 4718) @@ -587,6 +587,10 @@ <Compile Include="Linq\ProjectionEvaluator.cs" /> <Compile Include="Linq\QueryModelVisitor.cs" /> <Compile Include="Linq\ResultTransformer.cs" /> + <Compile Include="Loader\Criteria\ComponentCollectionCriteriaInfoProvider.cs" /> + <Compile Include="Loader\Criteria\EntityCriteriaInfoProvider.cs" /> + <Compile Include="Loader\Criteria\ICriteriaInfoProvider.cs" /> + <Compile Include="Loader\Criteria\ScalarCollectionCriteriaInfoProvider.cs" /> <Compile Include="Param\AbstractExplicitParameterSpecification.cs" /> <Compile Include="Param\AggregatedIndexCollectionSelectorParameterSpecifications.cs" /> <Compile Include="Param\CollectionFilterKeyParameterSpecification.cs" /> Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Employee.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Employee.cs 2009-09-16 01:57:36 UTC (rev 4715) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Employee.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace NHibernate.Test.NHSpecificTest.CriteriaQueryOnComponentCollection -{ - public class Employee - { - public virtual int Id { get; set; } - public virtual ICollection<Money> Amounts { get; set; } - public virtual ICollection<ManagedEmployee> ManagedEmployees { get; set; } - } - - public class ManagedEmployee - { - public virtual Employee Employee { get; set; } - public virtual string Position { get; set; } - } -} Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Employee.cs (from rev 4715, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Employee.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Employee.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Employee.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NHibernate.Test.NHSpecificTest.CriteriaQueryOnComponentCollection +{ + public class Employee + { + public virtual int Id { get; set; } + public virtual ICollection<Money> Amounts { get; set; } + public virtual ICollection<ManagedEmployee> ManagedEmployees { get; set; } + } + + public class ManagedEmployee + { + public virtual Employee Employee { get; set; } + public virtual string Position { get; set; } + } +} Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Fixture.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Fixture.cs 2009-09-16 01:57:36 UTC (rev 4715) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Fixture.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -1,118 +0,0 @@ -using System.Collections; -using Iesi.Collections.Generic; -using NHibernate.Cfg; -using NHibernate.Criterion; -using NHibernate.Transform; -using NUnit.Framework; - -namespace NHibernate.Test.NHSpecificTest.CriteriaQueryOnComponentCollection -{ - [TestFixture] - public class Fixture : TestCase - { - protected override void Configure(Configuration configuration) - { - configuration.SetProperty(Environment.FormatSql, "false"); - } - - protected override void OnSetUp() - { - using (var s = sessions.OpenSession()) - using (s.BeginTransaction()) - { - var parent = new Employee - { - Id = 2, - }; - var emp = new Employee - { - Id = 1, - Amounts = new HashedSet<Money> - { - new Money {Amount = 9, Currency = "USD"}, - new Money {Amount = 3, Currency = "EUR"}, - }, - ManagedEmployees = new HashedSet<ManagedEmployee> - { - new ManagedEmployee - { - Position = "parent", - Employee = parent - } - } - }; - s.Save(parent); - s.Save(emp); - - s.Transaction.Commit(); - } - } - - protected override void OnTearDown() - { - using (var s = sessions.OpenSession()) - using(s.BeginTransaction()) - { - s.Delete("from System.Object"); - - s.Transaction.Commit(); - } - } - - [Test] - public void CanQueryByCriteriaOnSetOfCompositeElement() - { - using(var s = sessions.OpenSession()) - { - var list = s.CreateCriteria<Employee>() - .CreateCriteria("ManagedEmployees") - .Add(Restrictions.Eq("Position", "parent")) - .SetResultTransformer(new RootEntityResultTransformer()) - .List(); - Assert.IsNotEmpty(list); - } - } - - [Test] - public void CanQueryByCriteriaOnSetOfElement() - { - using (var s = sessions.OpenSession()) - { - var list = s.CreateCriteria<Employee>() - .CreateCriteria("Amounts") - .Add(Restrictions.Gt("Amount", 5m)) - .SetResultTransformer(new RootEntityResultTransformer()) - .List(); - Assert.IsNotEmpty(list); - } - } - - [Test] - public void CanQueryByCriteriaOnSetOfCompositeElement_UsingDetachedCriteria() - { - using (var s = sessions.OpenSession()) - { - var list = s.CreateCriteria<Employee>() - .Add(Subqueries.PropertyIn("id", - DetachedCriteria.For<Employee>() - .SetProjection(Projections.Id()) - .CreateCriteria("Amounts") - .Add(Restrictions.Gt("Amount", 5m)))) - .List(); - Assert.IsNotEmpty(list); - } - } - - - protected override IList Mappings - { - get { return new [] { "NHSpecificTest.CriteriaQueryOnComponentCollection.Mappings.hbm.xml" }; } - } - - protected override string MappingsAssembly - { - get { return "NHibernate.Test"; } - } - - } -} Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Fixture.cs (from rev 4715, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Fixture.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Fixture.cs 2009-09-16 10:53:14 UTC (rev 4718) @@ -0,0 +1,118 @@ +using System.Collections; +using Iesi.Collections.Generic; +using NHibernate.Cfg; +using NHibernate.Criterion; +using NHibernate.Transform; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.CriteriaQueryOnComponentCollection +{ + [TestFixture] + public class Fixture : TestCase + { + protected override void Configure(Configuration configuration) + { + configuration.SetProperty(Environment.FormatSql, "false"); + } + + protected override void OnSetUp() + { + using (var s = sessions.OpenSession()) + using (s.BeginTransaction()) + { + var parent = new Employee + { + Id = 2, + }; + var emp = new Employee + { + Id = 1, + Amounts = new HashedSet<Money> + { + new Money {Amount = 9, Currency = "USD"}, + new Money {Amount = 3, Currency = "EUR"}, + }, + ManagedEmployees = new HashedSet<ManagedEmployee> + { + new ManagedEmployee + { + Position = "parent", + Employee = parent + } + } + }; + s.Save(parent); + s.Save(emp); + + s.Transaction.Commit(); + } + } + + protected override void OnTearDown() + { + using (var s = sessions.OpenSession()) + using(s.BeginTransaction()) + { + s.Delete("from System.Object"); + + s.Transaction.Commit(); + } + } + + [Test] + public void CanQueryByCriteriaOnSetOfCompositeElement() + { + using(var s = sessions.OpenSession()) + { + var list = s.CreateCriteria<Employee>() + .CreateCriteria("ManagedEmployees") + .Add(Restrictions.Eq("Position", "parent")) + .SetResultTransformer(new RootEntityResultTransformer()) + .List(); + Assert.IsNotEmpty(list); + } + } + + [Test] + public void CanQueryByCriteriaOnSetOfElement() + { + using (var s = sessions.OpenSession()) + { + var list = s.CreateCriteria<Employee>() + .CreateCriteria("Amounts") + .Add(Restrictions.Gt("Amount", 5m)) + .SetResultTransformer(new RootEntityResultTransformer()) + .List(); + Assert.IsNotEmpty(list); + } + } + + [Test] + public void CanQueryByCriteriaOnSetOfCompositeElement_UsingDetachedCriteria() + { + using (var s = sessions.OpenSession()) + { + var list = s.CreateCriteria<Employee>() + .Add(Subqueries.PropertyIn("id", + DetachedCriteria.For<Employee>() + .SetProjection(Projections.Id()) + .CreateCriteria("Amounts") + .Add(Restrictions.Gt("Amount", 5m)))) + .List(); + Assert.IsNotEmpty(list); + } + } + + + protected override IList Mappings + { + get { return new [] { "NHSpecificTest.CriteriaQueryOnComponentCollection.Mappings.hbm.xml" }; } + } + + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + } +} Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Mappings.hbm.xml =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Mappings.hbm.xml 2009-09-16 01:57:36 UTC (rev 4715) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Mappings.hbm.xml 2009-09-16 10:53:14 UTC (rev 4718) @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" - namespace="NHibernate.Test.NHSpecificTest.CriteriaQueryOnComponentCollection" - assembly="NHibernate.Test"> - - <class name="Employee" table="Employees" lazy="false"> - <id name="Id" type="Int32"> - <generator class="assigned" /> - </id> - - <set name="Amounts" table="Amounts"> - <key column="EmployeeId"/> - <composite-element class="Money"> - <property name="Amount" type="Decimal" not-null="true"/> - <property name="Currency" type="String" not-null="true"/> - </composite-element> - </set> - - <set name="ManagedEmployees" table="ManagedEmployees"> - <key column="EmployeeId"/> - <composite-element class="ManagedEmployee"> - <property name="Position" type="string" not-null="true"/> - <many-to-one name="Employee" class="Employee"/> - </composite-element> - </set> - - </class> -</hibernate-mapping> Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Mappings.hbm.xml (from rev 4715, branches/2.1.x/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Mappings.hbm.xml) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/CriteriaQueryOnComponentCollection/Mappings.hbm.xml 2009-09-16 10:53:14 UTC (rev 4718) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.CriteriaQueryOnComponentCollection" + assembly="NHibernate.Test"> + + <class name="Employee" table="Employees" lazy="false"> + <id name="Id" type="Int32"> + <generator class="assigned" /> + </id> + + <set name="Amounts" table="Amounts"> + <key column="EmployeeId"/> + <composite-element class="Money"> + <property name="Amount" type="Decimal" not-null="true"/> + <property name="Currency" type="String" not-null="true"/> + </composite-element> + </set> + + <set name="ManagedEmployees" table="ManagedEmployees"> + <key column="EmployeeId"/> + <composite-element class="ManagedEmployee"> + <property name="Position" type="string" not-null="true"/> + <many-to-one name="Employee" class="Employee"/> + </composite-element> + </set> + + </class> +</hibernate-mapping> Deleted: trunk/nhibernat... [truncated message content] |
From: <aye...@us...> - 2009-09-16 10:34:48
|
Revision: 4717 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4717&view=rev Author: ayenderahien Date: 2009-09-16 10:34:39 +0000 (Wed, 16 Sep 2009) Log Message: ----------- Removing reference to NH Prof appender dll Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-16 02:11:15 UTC (rev 4716) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-09-16 10:34:39 UTC (rev 4717) @@ -46,10 +46,6 @@ <SpecificVersion>False</SpecificVersion> <HintPath>..\..\lib\net\2.0\Antlr3.Runtime.dll</HintPath> </Reference> - <Reference Include="HibernatingRhinos.NHibernate.Profiler.Appender, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0774796e73ebf640, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\..\Hibernating.Rhinos\NHibernate.Profiler\HibernatingRhinos.NHibernate.Profiler.Appender\bin\Debug\HibernatingRhinos.NHibernate.Profiler.Appender.dll</HintPath> - </Reference> <Reference Include="Iesi.Collections, Version=1.0.0.1, Culture=neutral, PublicKeyToken=154fdcb44c4484fc"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\lib\net\2.0\Iesi.Collections.dll</HintPath> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |