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: <fab...@us...> - 2009-03-29 06:27:17
|
Revision: 4165 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4165&view=rev Author: fabiomaulo Date: 2009-03-29 06:27:12 +0000 (Sun, 29 Mar 2009) Log Message: ----------- Fix NH-1718 (new feature Currency type) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj trunk/nhibernate/src/NHibernate/NHibernateUtil.cs trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Type/CurrencyType.cs trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyClass.cs trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyClass.hbm.xml trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyTypeFixture.cs Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-03-29 04:42:52 UTC (rev 4164) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-03-29 06:27:12 UTC (rev 4165) @@ -1091,6 +1091,7 @@ <Compile Include="Type\AnsiCharType.cs" /> <Compile Include="Type\AnyType.cs" /> <Compile Include="Type\AbstractCharType.cs" /> + <Compile Include="Type\CurrencyType.cs" /> <Compile Include="Type\TimeSpanType.cs" /> <Compile Include="Type\DateTime2Type.cs" /> <Compile Include="Type\ClassMetaType.cs" /> Modified: trunk/nhibernate/src/NHibernate/NHibernateUtil.cs =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernateUtil.cs 2009-03-29 04:42:52 UTC (rev 4164) +++ trunk/nhibernate/src/NHibernate/NHibernateUtil.cs 2009-03-29 06:27:12 UTC (rev 4165) @@ -141,6 +141,11 @@ public static readonly NullableType Double = new DoubleType(); /// <summary> + /// NHibernate Currency type (System.Decimal - DbType.Currency) + /// </summary> + public static readonly NullableType Currency = new CurrencyType(); + + /// <summary> /// NHibernate Guid type. /// </summary> public static readonly NullableType Guid = new GuidType(); Added: trunk/nhibernate/src/NHibernate/Type/CurrencyType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/CurrencyType.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Type/CurrencyType.cs 2009-03-29 06:27:12 UTC (rev 4165) @@ -0,0 +1,17 @@ +using System; +using NHibernate.SqlTypes; + +namespace NHibernate.Type +{ + [Serializable] + public class CurrencyType : DecimalType + { + internal CurrencyType() : this(SqlTypeFactory.Currency) { } + internal CurrencyType(SqlType sqlType) : base(sqlType) { } + + public override string Name + { + get { return "Currency"; } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-03-29 04:42:52 UTC (rev 4164) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-03-29 06:27:12 UTC (rev 4165) @@ -95,8 +95,6 @@ //basicTypes.Add(NHibernate.Blob.Name, NHibernate.Blob); //basicTypes.Add(NHibernate.Clob.Name, NHibernate.Clob); - //basicTypes.Add(NHibernate.Currency.Name, NHibernate.Currency); - // the Timezone class .NET is not even close to the java.util.Timezone class - in // .NET all you can do is get the local Timezone - there is no "factory" method to // get a Timezone by name... @@ -145,6 +143,7 @@ typeByTypeOfName[NHibernateUtil.Ticks.Name] = NHibernateUtil.Ticks; typeByTypeOfName[NHibernateUtil.TimeSpanInt64.Name] = NHibernateUtil.TimeSpanInt64; typeByTypeOfName[NHibernateUtil.TimeSpan.Name] = NHibernateUtil.TimeSpan; + typeByTypeOfName[NHibernateUtil.Currency.Name] = NHibernateUtil.Currency; // need to do add the key "Serializable" because the hbm files will have a // type="Serializable", but the SerializableType returns the Name as @@ -162,6 +161,7 @@ typeByTypeOfName["time"] = NHibernateUtil.Time; typeByTypeOfName["timestamp"] = NHibernateUtil.Timestamp; typeByTypeOfName["decimal"] = NHibernateUtil.Decimal; + typeByTypeOfName["currency"] = NHibernateUtil.Currency; typeByTypeOfName["serializable"] = NHibernateUtil.Serializable; typeByTypeOfName["true_false"] = NHibernateUtil.TrueFalse; Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-29 04:42:52 UTC (rev 4164) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-29 06:27:12 UTC (rev 4165) @@ -1059,6 +1059,8 @@ <Compile Include="TypesTest\BooleanTypeFixture.cs" /> <Compile Include="TypesTest\ByteClass.cs" /> <Compile Include="TypesTest\ByteTypeFixture.cs" /> + <Compile Include="TypesTest\CurrencyClass.cs" /> + <Compile Include="TypesTest\CurrencyTypeFixture.cs" /> <Compile Include="TypesTest\TimeSpanClass.cs" /> <Compile Include="TypesTest\TimeSpanTypeFixture.cs" /> <Compile Include="TypesTest\TimeSpanInt64Class.cs" /> @@ -1705,6 +1707,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="TypesTest\CurrencyClass.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1635\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1688\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1700\Mappings.hbm.xml" /> Added: trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyClass.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyClass.cs 2009-03-29 06:27:12 UTC (rev 4165) @@ -0,0 +1,7 @@ +namespace NHibernate.Test.TypesTest +{ + public class CurrencyClass + { + public decimal CurrencyValue { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyClass.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyClass.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyClass.hbm.xml 2009-03-29 06:27:12 UTC (rev 4165) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.TypesTest" + default-lazy="false"> + + <class name="CurrencyClass"> + <id type="int"> + <generator class="native" /> + </id> + <property name="CurrencyValue" type="currency"/> + </class> +</hibernate-mapping> \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyTypeFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyTypeFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/TypesTest/CurrencyTypeFixture.cs 2009-03-29 06:27:12 UTC (rev 4165) @@ -0,0 +1,72 @@ +using NHibernate.Dialect; +using NHibernate.Type; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; + +namespace NHibernate.Test.TypesTest +{ + [TestFixture] + public class CurrencyTypeFixture : TypeFixtureBase + { + protected override string TypeName + { + get { return "Currency"; } + } + + [Test] + public void ShouldBeMoneyType() + { + if (!(Dialect is MsSql2000Dialect)) + { + Assert.Ignore("This test does not apply to " + Dialect); + } + var sqlType = Dialect.GetTypeName(NHibernateUtil.Currency.SqlType); + Assert.That(sqlType, Is.EqualTo("MONEY")); + } + + /// <summary> + /// Test that two decimal fields that are exactly equal are returned + /// as Equal by the DecimalType. + /// </summary> + [Test] + public void Equals() + { + const decimal lhs = 5.6435M; + const decimal rhs = 5.6435M; + + var type = (CurrencyType)NHibernateUtil.Currency; + Assert.IsTrue(type.IsEqual(lhs, rhs)); + } + + [Test] + public void ReadWrite() + { + const decimal expected = 5.6435M; + + var basic = new CurrencyClass {CurrencyValue = expected}; + ISession s = OpenSession(); + object savedId = s.Save(basic); + s.Flush(); + s.Close(); + + s = OpenSession(); + basic = s.Load<CurrencyClass>(savedId); + + Assert.AreEqual(expected, basic.CurrencyValue); + + s.Delete(basic); + s.Flush(); + s.Close(); + } + + [Test] + public void UnsavedValue() + { + var type = (CurrencyType)NHibernateUtil.Currency; + object mappedValue = type.StringToObject("0"); + Assert.AreEqual(0m, mappedValue); + Assert.IsTrue(type.IsEqual(mappedValue, 0m), "'0' in the mapping file should have been converted to a 0m"); + } + + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-29 04:42:56
|
Revision: 4164 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4164&view=rev Author: fabiomaulo Date: 2009-03-29 04:42:52 +0000 (Sun, 29 Mar 2009) Log Message: ----------- Fix NH-1635 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj trunk/nhibernate/src/NHibernate.Test/TestCase.cs Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/ForumMessage.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/ForumThread.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-03-29 04:12:21 UTC (rev 4163) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/ClassBinder.cs 2009-03-29 04:42:52 UTC (rev 4164) @@ -852,7 +852,7 @@ protected void BindManyToOne(XmlNode node, ManyToOne model, string defaultColumnName, bool isNullable) { - BindColumns(node, model, isNullable, true, defaultColumnName); + BindColumnsOrFormula(node, model, defaultColumnName, isNullable); InitOuterJoinFetchSetting(node, model); InitLaziness(node, model, true); Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/Fixture.cs 2009-03-29 04:42:52 UTC (rev 4164) @@ -0,0 +1,68 @@ +using System.Text; +using NHibernate.Tool.hbm2ddl; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; + +namespace NHibernate.Test.NHSpecificTest.NH1635 +{ + [TestFixture] + public class Fixture : BugTestCase + { + private void CreateTestContext() + { + var t1 = new ForumThread {Id = 1, Name = "Thread 1"}; + var t2 = new ForumThread {Id = 2, Name = "Thread 2"}; + var m1 = new ForumMessage {Id = 1, Name = "Thread 1: Message 1", ForumThread = t1}; + var m2 = new ForumMessage {Id = 2, Name = "Thread 1: Message 2", ForumThread = t1}; + var m3 = new ForumMessage {Id = 3, Name = "Thread 2: Message 1", ForumThread = t2}; + + t1.Messages.Add(m1); + t1.Messages.Add(m2); + t2.Messages.Add(m3); + + using (ISession session = OpenSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { + session.Save(t1); + session.Save(t2); + + transaction.Commit(); + } + } + } + + private void CleanUp() + { + using (ISession session = OpenSession()) + { + session.Delete("from ForumMessage"); + session.Delete("from ForumThread"); + session.Flush(); + } + } + + protected override void CreateSchema() + { + var script = new StringBuilder(); + new SchemaExport(cfg).Create(sl=> script.Append(sl) , true); + Assert.That(script.ToString(), Text.DoesNotContain("LatestMessage")); + } + + [Test] + public void Test() + { + CreateTestContext(); + using (ISession session = OpenSession()) + { + var thread = session.Get<ForumThread>(1); + + Assert.IsNotNull(thread.LatestMessage); + Assert.IsTrue(thread.LatestMessage.Id == 2); + + session.Flush(); + } + CleanUp(); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/ForumMessage.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/ForumMessage.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/ForumMessage.cs 2009-03-29 04:42:52 UTC (rev 4164) @@ -0,0 +1,9 @@ +namespace NHibernate.Test.NHSpecificTest.NH1635 +{ + public class ForumMessage + { + public virtual int Id { get; set; } + public virtual string Name { get; set; } + public virtual ForumThread ForumThread { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/ForumThread.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/ForumThread.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/ForumThread.cs 2009-03-29 04:42:52 UTC (rev 4164) @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace NHibernate.Test.NHSpecificTest.NH1635 +{ + public class ForumThread + { + public ForumThread() + { + Messages = new List<ForumMessage>(); + } + + public virtual int Id { get; set; } + public virtual string Name { get; set; } + public virtual IList<ForumMessage> Messages { get; set; } + public virtual ForumMessage LatestMessage { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1635/Mappings.hbm.xml 2009-03-29 04:42:52 UTC (rev 4164) @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping + xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1635"> + + + <class name="ForumThread" table="ForumThread"> + + <id name="Id" column="ForumThreadId" type="Int32"> + <generator class="assigned" /> + </id> + + <property name="Name" column="Name" type="String" length="25" not-null="true" /> + + <bag name="Messages" table="ForumMessage" inverse="true" cascade="all-delete-orphan"> + <key column="ForumThreadId" /> + <one-to-many class="ForumMessage" /> + </bag> + + <many-to-one + name="LatestMessage" + class="ForumMessage" + formula="(SELECT MAX(m.ForumMessageId) FROM ForumMessage m WHERE m.ForumThreadId = ForumThreadId)" /> + + </class> + + + <class name="ForumMessage" table="ForumMessage"> + + <id name="Id" column="ForumMessageId" type="Int32"> + <generator class="assigned" /> + </id> + + <property name="Name" column="Name" type="String" length="25" not-null="true" /> + + <many-to-one name="ForumThread" column="ForumThreadId" class="ForumThread" not-null="true" /> + + </class> + +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-29 04:12:21 UTC (rev 4163) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-29 04:42:52 UTC (rev 4164) @@ -294,6 +294,9 @@ <Compile Include="HQL\BaseFunctionFixture.cs" /> <Compile Include="NHSpecificTest\DtcFailures\DtcFailuresFixture.cs" /> <Compile Include="NHSpecificTest\DtcFailures\Person.cs" /> + <Compile Include="NHSpecificTest\NH1635\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1635\ForumMessage.cs" /> + <Compile Include="NHSpecificTest\NH1635\ForumThread.cs" /> <Compile Include="NHSpecificTest\NH1688\DomainClass.cs" /> <Compile Include="NHSpecificTest\NH1688\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1693\Fixture.cs" /> @@ -1702,6 +1705,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1635\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1688\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1700\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1693\Mappings.hbm.xml" /> Modified: trunk/nhibernate/src/NHibernate.Test/TestCase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TestCase.cs 2009-03-29 04:12:21 UTC (rev 4163) +++ trunk/nhibernate/src/NHibernate.Test/TestCase.cs 2009-03-29 04:42:52 UTC (rev 4164) @@ -196,7 +196,7 @@ ApplyCacheSettings(cfg); } - private void CreateSchema() + protected virtual void CreateSchema() { new SchemaExport(cfg).Create(OutputDdl, true); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-29 04:12:23
|
Revision: 4163 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4163&view=rev Author: fabiomaulo Date: 2009-03-29 04:12:21 +0000 (Sun, 29 Mar 2009) Log Message: ----------- Minor Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2009-03-28 22:26:18 UTC (rev 4162) +++ trunk/nhibernate/src/NHibernate/Dialect/Dialect.cs 2009-03-29 04:12:21 UTC (rev 4163) @@ -625,7 +625,7 @@ public virtual string GetAddForeignKeyConstraintString(string constraintName, string[] foreignKey, string referencedTable, string[] primaryKey, bool referencesPrimaryKey) { - StringBuilder res = new StringBuilder(30); + var res = new StringBuilder(200); res.Append(" add constraint ") .Append(constraintName) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-28 22:26:21
|
Revision: 4162 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4162&view=rev Author: fabiomaulo Date: 2009-03-28 22:26:18 +0000 (Sat, 28 Mar 2009) Log Message: ----------- Minor (only to show how you can map assigned ID) Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Mappings.hbm.xml 2009-03-28 22:24:39 UTC (rev 4161) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Mappings.hbm.xml 2009-03-28 22:26:18 UTC (rev 4162) @@ -4,9 +4,7 @@ default-lazy="false"> <class name="DomainClass"> - <id name="Id"> - <generator class="assigned" /> - </id> + <id name="Id"/> <property name="BooleanData" /> </class> </hibernate-mapping> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-28 22:24:43
|
Revision: 4161 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4161&view=rev Author: fabiomaulo Date: 2009-03-28 22:24:39 +0000 (Sat, 28 Mar 2009) Log Message: ----------- The NH-1688 was fixed in some moment in the trunk. Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/DomainClass.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Mappings.hbm.xml Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/DomainClass.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/DomainClass.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/DomainClass.cs 2009-03-28 22:24:39 UTC (rev 4161) @@ -0,0 +1,9 @@ +namespace NHibernate.Test.NHSpecificTest.NH1688 +{ + public class DomainClass + { + public int Id { get; set; } + + public bool BooleanData { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Fixture.cs 2009-03-28 22:24:39 UTC (rev 4161) @@ -0,0 +1,68 @@ +using System.Collections; +using NHibernate.Criterion; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1688 +{ + [TestFixture] + public class Fixture : BugTestCase + { + [Test] + public void UsingExpression() + { + TestAction(criteria => criteria.Add(Restrictions.Eq("alias.BooleanData", true))); + } + + [Test] + public void UsingExpressionProjection() + { + TestAction(criteria => criteria.Add(Restrictions.Eq(Projections.Property("alias.BooleanData"), true))); + } + + [Test] + public void UsingExpressionFunctionProjection() + { + TestAction(criteria => criteria.Add(Restrictions.Eq( + Projections.Conditional( + Restrictions.Eq(Projections.Property("alias.BooleanData"), true), + Projections.Property("alias.BooleanData"), + Projections.Constant(false)), + false) + )); + } + + protected override void OnSetUp() + { + base.OnSetUp(); + using (ISession session = OpenSession()) + { + var entity = new DomainClass {Id = 1, BooleanData = true}; + session.Save(entity); + session.Flush(); + } + } + + protected override void OnTearDown() + { + base.OnTearDown(); + using (ISession session = OpenSession()) + { + session.Delete("from DomainClass"); + session.Flush(); + } + } + + public void TestAction(System.Action<DetachedCriteria> action) + { + using (ISession session = OpenSession()) + { + DetachedCriteria criteria = DetachedCriteria.For<NH1679.DomainClass>("alias"); + + action.Invoke(criteria); + + IList l = criteria.GetExecutableCriteria(session).List(); + Assert.AreNotEqual(l, null); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1688/Mappings.hbm.xml 2009-03-28 22:24:39 UTC (rev 4161) @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1688" + default-lazy="false"> + + <class name="DomainClass"> + <id name="Id"> + <generator class="assigned" /> + </id> + <property name="BooleanData" /> + </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-03-28 22:10:37 UTC (rev 4160) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-28 22:24:39 UTC (rev 4161) @@ -294,6 +294,8 @@ <Compile Include="HQL\BaseFunctionFixture.cs" /> <Compile Include="NHSpecificTest\DtcFailures\DtcFailuresFixture.cs" /> <Compile Include="NHSpecificTest\DtcFailures\Person.cs" /> + <Compile Include="NHSpecificTest\NH1688\DomainClass.cs" /> + <Compile Include="NHSpecificTest\NH1688\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1693\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1693\Model.cs" /> <Compile Include="NHSpecificTest\NH1694\Fixture.cs" /> @@ -1700,6 +1702,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1688\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1700\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1693\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1710\WithColumnNode.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-28 22:10:40
|
Revision: 4160 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4160&view=rev Author: fabiomaulo Date: 2009-03-28 22:10:37 +0000 (Sat, 28 Mar 2009) Log Message: ----------- Applying change needed for AST parser based on ANTLR Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Hql/IQueryTranslator.cs trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2009-03-28 20:15:05 UTC (rev 4159) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2009-03-28 22:10:37 UTC (rev 4160) @@ -356,8 +356,13 @@ get { return returnTypes; } } - internal virtual IType[] ActualReturnTypes + public Loader.Loader Loader { + get { return this; } + } + + public virtual IType[] ActualReturnTypes + { get { return actualReturnTypes; } } Modified: trunk/nhibernate/src/NHibernate/Hql/IQueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/IQueryTranslator.cs 2009-03-28 20:15:05 UTC (rev 4159) +++ trunk/nhibernate/src/NHibernate/Hql/IQueryTranslator.cs 2009-03-28 22:10:37 UTC (rev 4160) @@ -116,5 +116,9 @@ bool ContainsCollectionFetches { get; } bool IsManipulationStatement { get; } + + Loader.Loader Loader { get; } + + IType[] ActualReturnTypes { get; } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2009-03-28 20:15:05 UTC (rev 4159) +++ trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2009-03-28 22:10:37 UTC (rev 4160) @@ -23,9 +23,9 @@ private static readonly ILog log = LogManager.GetLogger(typeof(MultiQueryImpl)); private readonly List<IQuery> queries = new List<IQuery>(); - private readonly List<QueryTranslator> translators = new List<QueryTranslator>(); + private readonly List<IQueryTranslator> translators = new List<IQueryTranslator>(); private readonly List<QueryParameters> parameters = new List<QueryParameters>(); - private IList criteriaResults; + private IList queryResults; private readonly Dictionary<string, int> criteriaResultPositions = new Dictionary<string, int>(); private string cacheRegion; private int commandTimeout = RowSelection.NoValue; @@ -360,9 +360,7 @@ try { Before(); - - criteriaResults = cacheable ? ListUsingQueryCache() : ListIgnoreQueryCache(); - return criteriaResults; + return cacheable ? ListUsingQueryCache() : ListIgnoreQueryCache(); } finally { @@ -405,9 +403,7 @@ { for (int j = 0; j < subList.Count; j++) { - object[] row = subList[j] as object[]; - if (row == null) - row = new object[] { subList[j] }; + object[] row = subList[j] as object[] ?? new[] { subList[j] }; subList[j] = holderInstantiator.Instantiate(row); } @@ -458,10 +454,10 @@ log.DebugFormat("Executing {0} queries", translators.Count); for (int i = 0; i < translators.Count; i++) { - QueryTranslator translator = Translators[i]; + IQueryTranslator translator = Translators[i]; QueryParameters parameter = Parameters[i]; ArrayList tempResults = new ArrayList(); - int entitySpan = translator.EntityPersisters.Length; + int entitySpan = translator.Loader.EntityPersisters.Length; hydratedObjects[i] = entitySpan > 0 ? new ArrayList() : null; RowSelection selection = parameter.RowSelection; int maxRows = Loader.Loader.HasMaxRows(selection) ? selection.MaxRows : int.MaxValue; @@ -470,13 +466,13 @@ Loader.Loader.Advance(reader, selection); } - LockMode[] lockModeArray = translator.GetLockModes(parameter.LockModes); + LockMode[] lockModeArray = translator.Loader.GetLockModes(parameter.LockModes); EntityKey optionalObjectKey = Loader.Loader.GetOptionalObjectKey(parameter, session); - createSubselects[i] = translator.IsSubselectLoadingEnabled; + createSubselects[i] = translator.Loader.IsSubselectLoadingEnabled; subselectResultKeys[i] = createSubselects[i] ? new List<EntityKey[]>() : null; - translator.HandleEmptyCollections(parameter.CollectionKeys, reader, session); + translator.Loader.HandleEmptyCollections(parameter.CollectionKeys, reader, session); EntityKey[] keys = new EntityKey[entitySpan]; // we can reuse it each time if (log.IsDebugEnabled) @@ -493,7 +489,7 @@ } object result = - translator.GetRowFromResultSet(reader, + translator.Loader.GetRowFromResultSet(reader, session, parameter, lockModeArray, @@ -536,14 +532,14 @@ } for (int i = 0; i < translators.Count; i++) { - QueryTranslator translator = translators[i]; + IQueryTranslator translator = translators[i]; QueryParameters parameter = parameters[i]; - translator.InitializeEntitiesAndCollections(hydratedObjects[i], reader, session, false); + translator.Loader.InitializeEntitiesAndCollections(hydratedObjects[i], reader, session, false); if (createSubselects[i]) { - translator.CreateSubselects(subselectResultKeys[i], parameter, session); + translator.Loader.CreateSubselects(subselectResultKeys[i], parameter, session); } } return results; @@ -630,23 +626,26 @@ { for (int i = 0; i < queries.Count; i++) { - QueryTranslator translator = Translators[i]; + IQueryTranslator translator = Translators[i]; QueryParameters parameter = Parameters[i]; - colIndex += parameter.BindParameters(command, translator.GetNamedParameterLocs, colIndex, session); + colIndex += parameter.BindParameters(command, translator.Loader.GetNamedParameterLocs, colIndex, session); } return colIndex; } public object GetResult(string key) { - if (criteriaResults == null) List(); + if (queryResults == null) + { + queryResults= List(); + } if (!criteriaResultPositions.ContainsKey(key)) { throw new InvalidOperationException(String.Format("The key '{0}' is unknown", key)); } - return criteriaResults[criteriaResultPositions[key]]; + return queryResults[criteriaResultPositions[key]]; } private int BindLimitParametersFirstIfNeccesary(IDbCommand command, int colIndex) @@ -685,7 +684,7 @@ List<IType[]> resultTypesList = new List<IType[]>(Translators.Count); for (int i = 0; i < Translators.Count; i++) { - QueryTranslator queryTranslator = Translators[i]; + IQueryTranslator queryTranslator = Translators[i]; querySpaces.AddAll(queryTranslator.QuerySpaces); resultTypesList.Add(queryTranslator.ActualReturnTypes); } @@ -717,7 +716,7 @@ return GetResultList(result); } - private IList<QueryTranslator> Translators + private IList<IQueryTranslator> Translators { get { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-28 20:15:11
|
Revision: 4159 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4159&view=rev Author: fabiomaulo Date: 2009-03-28 20:15:05 +0000 (Sat, 28 Mar 2009) Log Message: ----------- Fix NH-1700 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Domain.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs 2009-03-28 19:07:03 UTC (rev 4158) +++ trunk/nhibernate/src/NHibernate/Cfg/Mappings.cs 2009-03-28 20:15:05 UTC (rev 4159) @@ -315,17 +315,25 @@ public Table AddDenormalizedTable(string schema, string catalog, string name, bool isAbstract, string subselect, Table includedTable) { string key = subselect ?? dialect.Qualify(schema, catalog, name); - if (tables.ContainsKey(key)) + + Table table = new DenormalizedTable(includedTable) + { + IsAbstract = isAbstract, + Name = name, + Catalog = catalog, + Schema = schema, + Subselect = subselect + }; + + Table existing; + if (tables.TryGetValue(key, out existing)) { - throw new DuplicateMappingException("table", name); + if (existing.IsPhysicalTable) + { + throw new DuplicateMappingException("table", name); + } } - Table table = new DenormalizedTable(includedTable); - table.IsAbstract = isAbstract; - table.Name = name; - table.Catalog = catalog; - table.Schema = schema; - table.Subselect = subselect; tables[key] = table; return table; } Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Domain.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Domain.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Domain.cs 2009-03-28 20:15:05 UTC (rev 4159) @@ -0,0 +1,16 @@ +namespace NHibernate.Test.NHSpecificTest.NH1700 +{ + public class PayrollSegment + { + public virtual string Id { get; set; } + } + public class ActualPayrollSegment : PayrollSegment + { + } + public class ProjectedPayrollSegment : PayrollSegment + { + } + public class ClosedPayrollSegment : PayrollSegment + { + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Fixture.cs 2009-03-28 20:15:05 UTC (rev 4159) @@ -0,0 +1,23 @@ +using NHibernate.Cfg; +using NHibernate.Tool.hbm2ddl; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1700 +{ + [TestFixture] + public class Fixture + { + [Test] + public void ShouldNotThrowDuplicateMapping() + { + var cfg = new Configuration(); + if (TestConfigurationHelper.hibernateConfigFile != null) + cfg.Configure(TestConfigurationHelper.hibernateConfigFile); + + cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1700.Mappings.hbm.xml", GetType().Assembly); + new SchemaExport(cfg).Create(false, true); + + new SchemaExport(cfg).Drop(false, true); + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1700/Mappings.hbm.xml 2009-03-28 20:15:05 UTC (rev 4159) @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1700"> + + <class name="PayrollSegment" abstract="true" polymorphism="explicit"> + <id name="Id" column="PayrollSegmentKey"/> + <union-subclass name="ActualPayrollSegment" table="PayrollSegment"/> + <union-subclass name="ProjectedPayrollSegment" table="ProjectedPayrollSegment"/> + <union-subclass name="ClosedPayrollSegment" table="ClosedPayrollSegment"/> + </class> +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-28 19:07:03 UTC (rev 4158) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-28 20:15:05 UTC (rev 4159) @@ -297,6 +297,8 @@ <Compile Include="NHSpecificTest\NH1693\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1693\Model.cs" /> <Compile Include="NHSpecificTest\NH1694\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1700\Domain.cs" /> + <Compile Include="NHSpecificTest\NH1700\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> <Compile Include="NHSpecificTest\NH1706\KeyPropertyRefFixture.cs" /> <Compile Include="NHSpecificTest\NH1710\Fixture.cs" /> @@ -1698,6 +1700,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1700\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1693\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1710\WithColumnNode.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1710\InLine.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-28 19:07:13
|
Revision: 4158 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4158&view=rev Author: fabiomaulo Date: 2009-03-28 19:07:03 +0000 (Sat, 28 Mar 2009) Log Message: ----------- Fix NH-1693 and one more step to fix NH-1098 Thanks to Richard Brown Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs trunk/nhibernate/src/NHibernate/Loader/Loader.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1098/FilterParameterOrderFixture.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Model.cs Modified: trunk/nhibernate/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -57,58 +57,6 @@ } } - /// <summary> - /// Bind positional parameter values to the <tt>PreparedStatement</tt> - /// (these are parameters specified by a JDBC-style ?). - /// </summary> - private static int BindPositionalParameters(IDbCommand st, QueryParameters queryParameters, int start, ISessionImplementor session) - { - object[] values = queryParameters.FilteredPositionalParameterValues; - IType[] types = queryParameters.FilteredPositionalParameterTypes; - int span = 0; - for (int i = 0; i < values.Length; i++) - { - types[i].NullSafeSet(st, values[i], start + span, session); - span += types[i].GetColumnSpan(session.Factory); - } - return span; - } - - /// <summary> - /// Bind named parameters to the <tt>PreparedStatement</tt>. This has an - /// empty implementation on this superclass and should be implemented by - /// subclasses (queries) which allow named parameters. - /// </summary> - private void BindNamedParameters(IDbCommand ps, IEnumerable<KeyValuePair<string, TypedValue>> namedParams, int start, ISessionImplementor session) - { - if (namedParams != null) - { - // assumes that types are all of span 1 - int result = 0; - foreach (KeyValuePair<string, TypedValue> param in namedParams) - { - string name = param.Key; - TypedValue typedval = param.Value; - - int[] locs = GetNamedParameterLocs(name); - for (int i = 0; i < locs.Length; i++) - { - if (log.IsDebugEnabled) - { - log.Debug(string.Format("BindNamedParameters() {0} -> {1} [{2}]", typedval.Value, name, (locs[i] + start))); - } - typedval.Type.NullSafeSet(ps, typedval.Value, locs[i] + start, session); - } - result += locs.Length; - } - return; - } - else - { - return; - } - } - private void CoordinateSharedCacheCleanup(ISessionImplementor session) { BulkOperationCleanupAction action = new BulkOperationCleanupAction(session, CustomQuery.QuerySpaces); @@ -149,9 +97,12 @@ // NH Difference : set Timeout for native query ps.CommandTimeout = selection.Timeout; } - int col = 0; // NH Different (initialized to 1 in JAVA) - col += BindPositionalParameters(ps, queryParameters, col, session); - BindNamedParameters(ps, queryParameters.NamedParameters, col, session); + // NH Different behavior: + // The inital value is 0 (initialized to 1 in JAVA) + // The responsibility of parameter binding was entirely moved to QueryParameters + // to deal with positionslParameter+NamedParameter+ParameterOfFilters + + queryParameters.BindParameters(ps, GetNamedParameterLocs, 0, session); result = session.Batcher.ExecuteNonQuery(ps); } finally @@ -180,7 +131,7 @@ List<IType> paramTypeList = new List<IType>(); int span = 0; - foreach (IType type in parameters.FilteredPositionalParameterTypes) + foreach (IType type in parameters.PositionalParameterTypes) { paramTypeList.Add(type); span += type.GetColumnSpan(session.Factory); Modified: trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate/Engine/QueryParameters.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -1,5 +1,7 @@ using System; using System.Collections; +using System.Collections.Generic; +using System.Data; using log4net; using NHibernate.Hql.Classic; using NHibernate.Impl; @@ -7,7 +9,6 @@ using NHibernate.Transform; using NHibernate.Type; using NHibernate.Util; -using System.Collections.Generic; namespace NHibernate.Engine { @@ -17,45 +18,39 @@ [Serializable] public sealed class QueryParameters { - private static readonly ILog log = LogManager.GetLogger(typeof(QueryParameters)); + public delegate int[] GetNamedParameterLocations(string parameterName); + private static readonly ILog log = LogManager.GetLogger(typeof (QueryParameters)); + private IType[] _positionalParameterTypes; private object[] _positionalParameterValues; + private int[] _positionalParameterLocations; private IDictionary<string, TypedValue> _namedParameters; private IDictionary<string, LockMode> _lockModes; + private IList<IType> filteredParameterTypes; + private IList<object> filteredParameterValues; + private IList<int> filteredParameterLocations; private RowSelection _rowSelection; private bool _cacheable; private string _cacheRegion; - private bool _forceCacheRefresh; private object[] _collectionKeys; private object _optionalObject; private string _optionalEntityName; private object _optionalId; private string _comment; - private bool _naturalKeyLookup; private bool _readOnly; - private bool _callable; - private bool autoDiscoverTypes; private SqlString processedSQL; - private IType[] processedPositionalParameterTypes; - private object[] processedPositionalParameterValues; private readonly IResultTransformer _resultTransformer; // not implemented: private ScrollMode _scrollMode; - public QueryParameters() - : this(ArrayHelper.EmptyTypeArray, ArrayHelper.EmptyObjectArray) - { - } + public QueryParameters() : this(ArrayHelper.EmptyTypeArray, ArrayHelper.EmptyObjectArray) {} - public QueryParameters(IType type, object value) - : this(new IType[] { type }, new object[] { value }) - { - } + public QueryParameters(IType type, object value) : this(new[] {type}, new[] {value}) {} - public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues, - object optionalObject, string optionalEntityName, object optionalObjectId) + public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues, object optionalObject, + string optionalEntityName, object optionalObjectId) : this(positionalParameterTypes, postionalParameterValues) { _optionalObject = optionalObject; @@ -64,33 +59,31 @@ } public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues) - : this(positionalParameterTypes, postionalParameterValues, null, null, false, null, null, false, null) - { - } + : this(positionalParameterTypes, postionalParameterValues, null, null, false, null, null, false, null) {} - public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues, - object[] collectionKeys) - : this(positionalParameterTypes, postionalParameterValues, null, collectionKeys) - { - } + public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues, object[] collectionKeys) + : this(positionalParameterTypes, postionalParameterValues, null, collectionKeys) {} public QueryParameters(IType[] positionalParameterTypes, object[] postionalParameterValues, - IDictionary<string, TypedValue> namedParameters, object[] collectionKeys) - : this(positionalParameterTypes, postionalParameterValues, namedParameters, null, null, false, false, null, null, collectionKeys, null) - { - } + IDictionary<string, TypedValue> namedParameters, object[] collectionKeys) + : this( + positionalParameterTypes, postionalParameterValues, namedParameters, null, null, false, false, null, null, + collectionKeys, null) {} public QueryParameters(IType[] positionalParameterTypes, object[] positionalParameterValues, - IDictionary<string, LockMode> lockModes, RowSelection rowSelection, bool cacheable, string cacheRegion, string comment, bool isLookupByNaturalKey, IResultTransformer transformer) - : this(positionalParameterTypes, positionalParameterValues, null, lockModes, rowSelection, false, cacheable, cacheRegion, comment, null, transformer) + IDictionary<string, LockMode> lockModes, RowSelection rowSelection, bool cacheable, + string cacheRegion, string comment, bool isLookupByNaturalKey, IResultTransformer transformer) + : this( + positionalParameterTypes, positionalParameterValues, null, lockModes, rowSelection, false, cacheable, cacheRegion, + comment, null, transformer) { - _naturalKeyLookup = isLookupByNaturalKey; + NaturalKeyLookup = isLookupByNaturalKey; } public QueryParameters(IType[] positionalParameterTypes, object[] positionalParameterValues, - IDictionary<string, TypedValue> namedParameters, IDictionary<string, LockMode> lockModes, RowSelection rowSelection, - bool readOnly, bool cacheable, string cacheRegion, string comment, - object[] collectionKeys, IResultTransformer transformer) + IDictionary<string, TypedValue> namedParameters, IDictionary<string, LockMode> lockModes, + RowSelection rowSelection, bool readOnly, bool cacheable, string cacheRegion, string comment, + object[] collectionKeys, IResultTransformer transformer) { _positionalParameterTypes = positionalParameterTypes; _positionalParameterValues = positionalParameterValues; @@ -103,13 +96,21 @@ _collectionKeys = collectionKeys; _readOnly = readOnly; _resultTransformer = transformer; + + if (_positionalParameterLocations == null) + { + CreatePositionalParameterLocations(); + } } public QueryParameters(IType[] positionalParameterTypes, object[] positionalParameterValues, - IDictionary<string, TypedValue> namedParameters, IDictionary<string, LockMode> lockModes, RowSelection rowSelection, - bool readOnly, bool cacheable, string cacheRegion, string comment, object[] collectionKeys, - object optionalObject, string optionalEntityName, object optionalId, IResultTransformer transformer) - : this(positionalParameterTypes, positionalParameterValues, namedParameters, lockModes, rowSelection, readOnly, cacheable, cacheRegion, comment, collectionKeys, transformer) + IDictionary<string, TypedValue> namedParameters, IDictionary<string, LockMode> lockModes, + RowSelection rowSelection, bool readOnly, bool cacheable, string cacheRegion, string comment, + object[] collectionKeys, object optionalObject, string optionalEntityName, object optionalId, + IResultTransformer transformer) + : this( + positionalParameterTypes, positionalParameterValues, namedParameters, lockModes, rowSelection, readOnly, cacheable, + cacheRegion, comment, collectionKeys, transformer) { _optionalEntityName = optionalEntityName; _optionalId = optionalId; @@ -141,6 +142,11 @@ set { _positionalParameterTypes = value; } } + public int[] PositionalParameterLocations + { + get { return _positionalParameterLocations; } + } + /// <summary> /// Gets or sets an array of <see cref="object"/> objects that is stored at the index /// of the Parameter. @@ -171,6 +177,18 @@ set { _lockModes = value; } } + private void CreatePositionalParameterLocations() + { + if (_positionalParameterTypes != null) + { + _positionalParameterLocations = new int[_positionalParameterTypes.Length]; + for (int i = 0; i < _positionalParameterLocations.Length; i++) + { + _positionalParameterLocations[i] = i; + } + } + } + private int SafeLength(Array array) { if (array == null) @@ -183,11 +201,10 @@ /// <summary></summary> public void LogParameters(ISessionFactoryImplementor factory) { - Printer print = new Printer(factory); + var print = new Printer(factory); if (_positionalParameterValues.Length != 0) { - log.Debug("parameters: " - + print.ToString(_positionalParameterTypes, _positionalParameterValues)); + log.Debug("parameters: " + print.ToString(_positionalParameterTypes, _positionalParameterValues)); } if (_namedParameters != null) @@ -228,16 +245,12 @@ if (typesLength != valuesLength) { - throw new QueryException("Number of positional parameter types (" + typesLength + - ") does not match number of positional parameter values (" + valuesLength + ")"); + throw new QueryException("Number of positional parameter types (" + typesLength + + ") does not match number of positional parameter values (" + valuesLength + ")"); } } - public bool ForceCacheRefresh - { - get { return _forceCacheRefresh; } - set { _forceCacheRefresh = value; } - } + public bool ForceCacheRefresh { get; set; } public string OptionalEntityName { @@ -263,11 +276,7 @@ set { _collectionKeys = value; } } - public bool Callable - { - get { return _callable; } - set { _callable = value; } - } + public bool Callable { get; set; } public bool ReadOnly { @@ -277,100 +286,178 @@ /************** Filters ********************************/ + private void AdjustPostionalParameterLocations(int parameterIndex) + { + for (int i = 0; i < _positionalParameterLocations.Length; i++) + { + if (_positionalParameterLocations[i] >= parameterIndex) + { + _positionalParameterLocations[i]++; + } + } + } + public void ProcessFilters(SqlString sql, ISessionImplementor session) { + filteredParameterValues = new List<object>(); + filteredParameterTypes = new List<IType>(); + filteredParameterLocations = new List<int>(); + if (session.EnabledFilters.Count == 0 || sql.ToString().IndexOf(ParserHelper.HqlVariablePrefix) < 0) { - processedPositionalParameterValues = PositionalParameterValues; - processedPositionalParameterTypes = PositionalParameterTypes; processedSQL = sql; + return; } - else - { - Dialect.Dialect dialect = session.Factory.Dialect; - string symbols = ParserHelper.HqlSeparators + dialect.OpenQuote + dialect.CloseQuote; - SqlStringBuilder result = new SqlStringBuilder(); + Dialect.Dialect dialect = session.Factory.Dialect; + string symbols = ParserHelper.HqlSeparators + dialect.OpenQuote + dialect.CloseQuote; - List<object> parameters = new List<object>(); - List<IType> parameterTypes = new List<IType>(); - int parameterCount = 0; // keep track of the positional parameter + var result = new SqlStringBuilder(); - foreach (object part in sql.Parts) + int parameterIndex = 0; // keep track of the positional parameter + + foreach (var part in sql.Parts) + { + if (part is Parameter) { - if (part is Parameter) - { - result.AddParameter(); + result.AddParameter(); - // (?) can be a position parameter or a named parameter (already substituted by (?), - // but only the positional parameters are available at this point. Adding them in the - // order of appearance is best that can be done at this point of time, but if they - // are mixed with named parameters, the order is still wrong, because values and - // types for the named parameters are added later to the end of the list. - // see test fixture NH-1098 - if (parameterCount < PositionalParameterValues.Length) - { - parameters.Add(PositionalParameterValues[parameterCount]); - parameterTypes.Add(PositionalParameterTypes[parameterCount]); - parameterCount++; - } + // (?) can be a position parameter or a named parameter (already substituted by (?), + // but only the positional parameters are available at this point. Adding them in the + // order of appearance is best that can be done at this point of time, but if they + // are mixed with named parameters, the order is still wrong, because values and + // types for the named parameters are added later to the end of the list. + // see test fixture NH-1098 - continue; - } + parameterIndex++; + continue; + } - StringTokenizer tokenizer = new StringTokenizer((string)part, symbols, true); + var tokenizer = new StringTokenizer((string) part, symbols, true); - foreach (string token in tokenizer) + foreach (var token in tokenizer) + { + if (token.StartsWith(ParserHelper.HqlVariablePrefix)) { - if (token.StartsWith(ParserHelper.HqlVariablePrefix)) + string filterParameterName = token.Substring(1); + object value = session.GetFilterParameterValue(filterParameterName); + IType type = session.GetFilterParameterType(filterParameterName); + + // If the value is not a value of the type but a collection of values... + if (value != null && !type.ReturnedClass.IsAssignableFrom(value.GetType()) && // Added to fix NH-882 + typeof (ICollection).IsAssignableFrom(value.GetType())) { - string filterParameterName = token.Substring(1); - object value = session.GetFilterParameterValue(filterParameterName); - IType type = session.GetFilterParameterType(filterParameterName); - - // If the value is not a value of the type but a collection of values... - if (value != null && - !type.ReturnedClass.IsAssignableFrom(value.GetType()) && // Added to fix NH-882 - typeof(ICollection).IsAssignableFrom(value.GetType())) + var coll = (ICollection) value; + int i = 0; + foreach (var elementValue in coll) { - ICollection coll = (ICollection)value; - int i = 0; - foreach (object elementValue in coll) - { - i++; - int span = type.GetColumnSpan(session.Factory); - if (span > 0) - { - result.AddParameter(); - parameters.Add(elementValue); - parameterTypes.Add(type); - if (i < coll.Count) - result.Add(", "); - } - } - } - else - { + i++; int span = type.GetColumnSpan(session.Factory); if (span > 0) { result.AddParameter(); - parameters.Add(value); - parameterTypes.Add(type); + filteredParameterTypes.Add(type); + filteredParameterValues.Add(elementValue); + filteredParameterLocations.Add(parameterIndex); + AdjustPostionalParameterLocations(parameterIndex); + parameterIndex++; + if (i < coll.Count) + { + result.Add(", "); + } } } } else { - result.Add(token); + int span = type.GetColumnSpan(session.Factory); + if (span > 0) + { + result.AddParameter(); + filteredParameterTypes.Add(type); + filteredParameterValues.Add(value); + filteredParameterLocations.Add(parameterIndex); + AdjustPostionalParameterLocations(parameterIndex); + parameterIndex++; + } } } + else + { + result.Add(token); + } } + } - processedPositionalParameterValues = parameters.ToArray(); - processedPositionalParameterTypes = parameterTypes.ToArray(); - processedSQL = result.ToSqlString(); + processedSQL = result.ToSqlString(); + } + + public int BindParameters(IDbCommand command, GetNamedParameterLocations getNamedParameterLocations, int start, + ISessionImplementor session) + { + var values = new List<object>(); + var types = new List<IType>(); + var sources = new List<string>(); + + for (int i = 0; i < _positionalParameterLocations.Length; i++) + { + int location = _positionalParameterLocations[i]; + object value = _positionalParameterValues[i]; + IType type = _positionalParameterTypes[i]; + ArrayHelper.SafeSetValue(values, location, value); + ArrayHelper.SafeSetValue(types, location, type); + ArrayHelper.SafeSetValue(sources, location, "Positional" + i); } + + for (int i = 0; i < filteredParameterLocations.Count; i++) + { + int location = filteredParameterLocations[i]; + object value = filteredParameterValues[i]; + IType type = filteredParameterTypes[i]; + ArrayHelper.SafeSetValue(values, location, value); + ArrayHelper.SafeSetValue(types, location, type); + ArrayHelper.SafeSetValue(sources, location, "Filter" + i); + } + + if ((_namedParameters != null) && (_namedParameters.Count > 0)) + { + foreach (var namedParameter in _namedParameters) + { + string name = namedParameter.Key; + TypedValue typedval = namedParameter.Value; + int[] locations = getNamedParameterLocations(name); + for (int i = 0; i < locations.Length; i++) + { + int location = locations[i]; + + // can still clash with positional parameters + // could consider throwing an exception to locate problem (NH-1098) + while ((location < types.Count) && (types[location] != null)) + { + location++; + } + + ArrayHelper.SafeSetValue(values, location, typedval.Value); + ArrayHelper.SafeSetValue(types, location, typedval.Type); + ArrayHelper.SafeSetValue(sources, location, "name" + i); + } + } + } + + int span = 0; + for (int i = 0; i < values.Count; i++) + { + IType type = types[i]; + object value = values[i]; + if (log.IsDebugEnabled) + { + log.Debug(string.Format("BindParameters({0}:{1}) {2} -> [{3}]", "Named", type, value, i)); + } + type.NullSafeSet(command, value, start + span, session); + span += type.GetColumnSpan(session.Factory); + } + + return span; } public SqlString FilteredSQL @@ -378,42 +465,41 @@ get { return processedSQL; } } - public object[] FilteredPositionalParameterValues + public IList<IType> FilteredParameterTypes { - get { return processedPositionalParameterValues; } + get { return filteredParameterTypes; } } - public IType[] FilteredPositionalParameterTypes + public IList<object> FilteredParameterValues { - get { return processedPositionalParameterTypes; } + get { return filteredParameterValues; } } - public bool NaturalKeyLookup + public IList<int> FilteredParameterLocations { - get { return _naturalKeyLookup; } - set { _naturalKeyLookup = value; } + get { return filteredParameterLocations; } } + public bool NaturalKeyLookup { get; set; } + public IResultTransformer ResultTransformer { get { return _resultTransformer; } } - public bool HasAutoDiscoverScalarTypes - { - get { return autoDiscoverTypes; } - set { autoDiscoverTypes = value; } - } + public bool HasAutoDiscoverScalarTypes { get; set; } public QueryParameters CreateCopyUsing(RowSelection selection) { - QueryParameters copy = new QueryParameters(_positionalParameterTypes, _positionalParameterValues, - _namedParameters, _lockModes, selection, _readOnly, _cacheable, _cacheRegion, _comment, - _collectionKeys, _optionalObject, _optionalEntityName, _optionalId, _resultTransformer); + var copy = new QueryParameters(_positionalParameterTypes, _positionalParameterValues, _namedParameters, _lockModes, + selection, _readOnly, _cacheable, _cacheRegion, _comment, _collectionKeys, + _optionalObject, _optionalEntityName, _optionalId, _resultTransformer); + copy._positionalParameterLocations = _positionalParameterLocations; copy.processedSQL = processedSQL; - copy.processedPositionalParameterTypes = processedPositionalParameterTypes; - copy.processedPositionalParameterValues = processedPositionalParameterValues; + copy.filteredParameterTypes = filteredParameterTypes; + copy.filteredParameterValues = filteredParameterValues; + copy.filteredParameterLocations = filteredParameterLocations; return copy; } } -} +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -701,6 +701,21 @@ return o.ToArray(); } + protected override void AdjustNamedParameterLocationsForQueryParameters(QueryParameters parameters) + { + foreach (int existingParameterLocation in parameters.FilteredParameterLocations) + { + foreach (IList<int> namedParameterLocations in namedParameters.Values) + { + for (int index = 0; index < namedParameterLocations.Count; index++) + { + if (namedParameterLocations[index] == existingParameterLocation) + namedParameterLocations[index]++; + } + } + } + } + public static string ScalarName(int x, int y) { return new StringBuilder() Modified: trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -307,8 +307,7 @@ for (int i = 0; i < loaders.Count; i++) { QueryParameters parameter = parameters[i]; - colIndex += loaders[i].BindPositionalParameters(command, parameter, colIndex, session); - colIndex += loaders[i].BindNamedParameters(command, parameter.NamedParameters, colIndex, session); + colIndex += parameter.BindParameters(command, loaders[i].GetNamedParameterLocs, colIndex, session); } return colIndex; } Modified: trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -632,8 +632,7 @@ { QueryTranslator translator = Translators[i]; QueryParameters parameter = Parameters[i]; - colIndex += translator.BindPositionalParameters(command, parameter, colIndex, session); - colIndex += translator.BindNamedParameters(command, parameter.NamedParameters, colIndex, session); + colIndex += parameter.BindParameters(command, translator.GetNamedParameterLocs, colIndex, session); } return colIndex; } Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectCollectionLoader.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -28,8 +28,9 @@ } namedParameters = queryParameters.NamedParameters; - types = queryParameters.FilteredPositionalParameterTypes; - values = queryParameters.FilteredPositionalParameterValues; + // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters + types = queryParameters.PositionalParameterTypes; + values = queryParameters.PositionalParameterValues; this.namedParameterLocMap = namedParameterLocMap; } @@ -42,5 +43,23 @@ { return namedParameterLocMap[name]; } + + protected override void AdjustNamedParameterLocationsForQueryParameters(QueryParameters parameters) + { + if (namedParameterLocMap == null) + return; + + foreach (int existingParameterLocation in parameters.FilteredParameterLocations) + { + foreach (IList<int> namedParameterLocations in namedParameterLocMap.Values) + { + for (int index = 0; index < namedParameterLocations.Count; index++) + { + if (namedParameterLocations[index] >= existingParameterLocation) + namedParameterLocations[index]++; + } + } + } + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate/Loader/Collection/SubselectOneToManyLoader.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -30,8 +30,9 @@ } namedParameters = queryParameters.NamedParameters; - types = queryParameters.FilteredPositionalParameterTypes; - values = queryParameters.FilteredPositionalParameterValues; + // NH Different behavior: to deal with positionslParameter+NamedParameter+ParameterOfFilters + types = queryParameters.PositionalParameterTypes; + values = queryParameters.PositionalParameterValues; this.namedParameterLocMap = namedParameterLocMap; } @@ -44,5 +45,24 @@ { return namedParameterLocMap[name]; } + + protected override void AdjustNamedParameterLocationsForQueryParameters(QueryParameters parameters) + { + if (namedParameterLocMap == null) + return; + + foreach (int existingParameterLocation in parameters.FilteredParameterLocations) + { + foreach (IList<int> namedParameterLocations in namedParameterLocMap.Values) + { + for (int index = 0; index < namedParameterLocations.Count; index++) + { + if (namedParameterLocations[index] >= existingParameterLocation) + namedParameterLocations[index]++; + } + } + } + } + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate/Loader/Custom/CustomLoader.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -320,6 +320,30 @@ } } + protected override void AdjustNamedParameterLocationsForQueryParameters(QueryParameters parameters) + { + var existingParameterLocations = parameters.FilteredParameterLocations.GetEnumerator(); + while (existingParameterLocations.MoveNext()) + { + foreach (string name in parameters.NamedParameters.Keys) + { + object locations = namedParameterBindPoints[name]; + if (locations is int) + { + namedParameterBindPoints[name] = ((int)locations) + 1; + } + else + { + IList locationsList = (IList)locations; + for (int i = 0; i < locationsList.Count; i++) + { + locationsList[i] = ((int)locationsList[i]) + 1; + } + } + } + } + } + protected override void AutoDiscoverTypes(IDataReader rs) { MetaData metadata = new MetaData(rs); Modified: trunk/nhibernate/src/NHibernate/Loader/Loader.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate/Loader/Loader.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -1173,6 +1173,7 @@ protected virtual SqlString ProcessFilters(QueryParameters parameters, ISessionImplementor session) { parameters.ProcessFilters(SqlString, session); + AdjustNamedParameterLocationsForQueryParameters(parameters); return parameters.FilteredSQL; } @@ -1256,79 +1257,26 @@ protected internal virtual int BindParameterValues(IDbCommand statement, QueryParameters queryParameters, int startIndex, ISessionImplementor session) { - int span = 0; - span += BindPositionalParameters(statement, queryParameters, startIndex, session); - span += BindNamedParameters(statement, queryParameters.NamedParameters, startIndex + span, session); - return span; + // NH Different behavior: + // The responsibility of parameter binding was entirely moved to QueryParameters + // to deal with positionslParameter+NamedParameter+ParameterOfFilters + return queryParameters.BindParameters(statement, GetNamedParameterLocs, 0, session); } - /// <summary> - /// Bind positional parameter values to the <c>IDbCommand</c> - /// (these are parameters specified by ?). - /// </summary> - /// <param name="st">The ADO prepared statement </param> - /// <param name="queryParameters">The encapsulation of the parameter values to be bound. </param> - /// <param name="start">The position from which to start binding parameter values. </param> - /// <param name="session">The originating session. </param> - /// <returns> The number of ADO bind positions actually bound during this method execution. </returns> - protected internal virtual int BindPositionalParameters(IDbCommand st, QueryParameters queryParameters, int start, - ISessionImplementor session) + public virtual int[] GetNamedParameterLocs(string name) { - object[] values = queryParameters.FilteredPositionalParameterValues; - IType[] types = queryParameters.FilteredPositionalParameterTypes; - - int span = 0; - for (int i = 0; i < values.Length; i++) - { - types[i].NullSafeSet(st, values[i], start + span, session); - span += types[i].GetColumnSpan(session.Factory); - } - - return span; + throw new AssertionFailure("no named parameters"); } - /// <summary> - /// Bind named parameters to the <c>IDbCommand</c> - /// </summary> - /// <param name="st">The <see cref="IDbCommand"/> that contains the parameters.</param> - /// <param name="namedParams">The named parameters (key) and the values to set.</param> - /// <param name="session">The <see cref="ISession"/> this Loader is using.</param> - /// <param name="start"></param> - protected internal virtual int BindNamedParameters(IDbCommand st, IDictionary<string, TypedValue> namedParams, - int start, ISessionImplementor session) + protected virtual void AdjustNamedParameterLocationsForQueryParameters(QueryParameters parameters) { - if (namedParams != null) - { - // assumes that types are all of span 1 - int result = 0; - foreach (KeyValuePair<string, TypedValue> namedParam in namedParams) - { - string name = namedParam.Key; - TypedValue typedval = namedParam.Value; - int[] locs = GetNamedParameterLocs(name); - for (int i = 0; i < locs.Length; i++) - { - if (log.IsDebugEnabled) - { - log.Debug("BindNamedParameters() " + typedval.Value + " -> " + name + " [" + (locs[i] + start) + "]"); - } - typedval.Type.NullSafeSet(st, typedval.Value, locs[i] + start, session); - } - result += locs.Length; - } - return result; - } - else - { - return 0; - } + // if you support named parameter locations (by overriding GetNamedParameterLocs), then you might need to + // allow for the locations to be adjusted by introduced filtered parameters by overriding + // this method too. + if ((parameters.NamedParameters != null) && (parameters.NamedParameters.Keys.Count > 0)) + throw new AssertionFailure(GetType() + " must override to handle implementation of named parameter locations"); } - public virtual int[] GetNamedParameterLocs(string name) - { - throw new AssertionFailure("no named parameters"); - } - /// <summary> /// Fetch a <c>IDbCommand</c>, call <c>SetMaxRows</c> and then execute it, /// advance to the first result and return an SQL <c>IDataReader</c> @@ -1784,16 +1732,24 @@ List<IType> paramTypeList = new List<IType>(); int span = 0; - foreach (IType type in parameters.FilteredPositionalParameterTypes) + for (int index = 0; index < parameters.PositionalParameterTypes.Length; index++) { - paramTypeList.Add(type); + int location = parameters.PositionalParameterLocations[index]; + IType type = parameters.PositionalParameterTypes[index]; + ArrayHelper.SafeSetValue(paramTypeList, location, type); span += type.GetColumnSpan(Factory); } - if (parameters.NamedParameters != null && parameters.NamedParameters.Count > 0) + for (int index = 0; index < parameters.FilteredParameterTypes.Count; index++) { - int offset = paramTypeList.Count; + int location = parameters.FilteredParameterLocations[index]; + IType type = parameters.FilteredParameterTypes[index]; + ArrayHelper.SafeSetValue(paramTypeList, location, type); + span += type.GetColumnSpan(Factory); + } + if (parameters.NamedParameters != null && parameters.NamedParameters.Count > 0) + { // convert the named parameters to an array of types foreach (KeyValuePair<string, TypedValue> namedParameter in parameters.NamedParameters) { @@ -1804,7 +1760,14 @@ for (int i = 0; i < locs.Length; i++) { - ArrayHelper.SafeSetValue(paramTypeList, locs[i] + offset, typedval.Type); + int location = locs[i]; + + // can still clash with positional parameters + // could consider throwing an exception to locate problem (NH-1098) + while ((location < paramTypeList.Count) && (paramTypeList[location] != null)) + location++; + + ArrayHelper.SafeSetValue(paramTypeList, location, typedval.Type); } } } Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1098/FilterParameterOrderFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1098/FilterParameterOrderFixture.cs 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1098/FilterParameterOrderFixture.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -121,7 +121,7 @@ Assert.AreEqual( 1, result.Count ); } - [Test, Ignore( "Known issue, parameter order is wrong when named and positional parameters are mixed" )] + [Test] public void QueryWithNamedParameters() { ISession session = OpenSession(); Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Fixture.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -0,0 +1,76 @@ +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; + +namespace NHibernate.Test.NHSpecificTest.NH1693 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnTearDown() + { + using (var session = OpenSession()) + { + session.Delete("from Invoice"); + session.Flush(); + } + } + + protected override void OnSetUp() + { + using (var session = OpenSession()) + using (var tx = session.BeginTransaction()) + { + session.Save(new Invoice { Mode = "a", Num = 1, Category = 10 }); + session.Save(new Invoice { Mode = "a", Num = 2, Category = 10 }); + session.Save(new Invoice { Mode = "a", Num = 3, Category = 20 }); + session.Save(new Invoice { Mode = "a", Num = 4, Category = 10 }); + session.Save(new Invoice { Mode = "b", Num = 2, Category = 10 }); + session.Save(new Invoice { Mode = "b", Num = 3, Category = 10 }); + session.Save(new Invoice { Mode = "b", Num = 5, Category = 10 }); + + tx.Commit(); + } + } + + [Test] + public void without_filter() + { + using (var session = OpenSession()) + using (var tx = session.BeginTransaction()) + { + var q1 = + "from Invoice i where i.Mode='a' and i.Category=:cat and not exists (from Invoice i2 where i2.Mode='a' and i2.Category=:cat and i2.Num=i.Num+1)"; + var list = session.CreateQuery(q1) + .SetParameter("cat", 10) + .List<Invoice>(); + Assert.That(list, Has.Count(2)); + Assert.That(list[0].Num == 2 && list[0].Mode == "a"); + Assert.That(list[1].Num == 4 && list[1].Mode == "a"); + + tx.Commit(); + } + } + + [Test] + public void with_filter() + { + using (var session = OpenSession()) + using (var tx = session.BeginTransaction()) + { + session.EnableFilter("modeFilter").SetParameter("currentMode", "a"); + + var q1 = + "from Invoice i where i.Category=:cat and not exists (from Invoice i2 where i2.Category=:cat and i2.Num=i.Num+1)"; + var list = session.CreateQuery(q1) + .SetParameter("cat", 10) + .List<Invoice>(); + Assert.That(list, Has.Count(2)); + Assert.That(list[0].Num == 2 && list[0].Mode == "a"); + Assert.That(list[1].Num == 4 && list[1].Mode == "a"); + + tx.Commit(); + } + } + + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Mappings.hbm.xml 2009-03-28 19:07:03 UTC (rev 4158) @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1693"> + + <class name="Invoice"> + <id name="ID" type="Int32"> + <generator class="hilo" /> + </id> + <property name="Mode" type="String" /> + <property name="Num" type="Int32" /> + <property name="Category" type="Int32" /> + + <filter name="modeFilter" condition="Mode=:currentMode" /> + </class> + + <filter-def name="modeFilter"> + <filter-param name="currentMode" type="String"/> + </filter-def> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Model.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Model.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1693/Model.cs 2009-03-28 19:07:03 UTC (rev 4158) @@ -0,0 +1,10 @@ +namespace NHibernate.Test.NHSpecificTest.NH1693 +{ + public class Invoice + { + public virtual int ID { get; private set; } + public virtual string Mode { get; set; } + public virtual int Category { get; set; } + public virtual int Num { get; set; } + } +} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-28 16:35:33 UTC (rev 4157) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-28 19:07:03 UTC (rev 4158) @@ -294,6 +294,8 @@ <Compile Include="HQL\BaseFunctionFixture.cs" /> <Compile Include="NHSpecificTest\DtcFailures\DtcFailuresFixture.cs" /> <Compile Include="NHSpecificTest\DtcFailures\Person.cs" /> + <Compile Include="NHSpecificTest\NH1693\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1693\Model.cs" /> <Compile Include="NHSpecificTest\NH1694\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> <Compile Include="NHSpecificTest\NH1706\KeyPropertyRefFixture.cs" /> @@ -1696,6 +1698,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1693\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1710\WithColumnNode.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1710\InLine.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1710\Heuristic.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-28 16:35:43
|
Revision: 4157 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4157&view=rev Author: fabiomaulo Date: 2009-03-28 16:35:33 +0000 (Sat, 28 Mar 2009) Log Message: ----------- Fix NH-1712 Modified Paths: -------------- trunk/nhibernate/releasenotes.txt Modified: trunk/nhibernate/releasenotes.txt =================================================================== --- trunk/nhibernate/releasenotes.txt 2009-03-28 16:17:20 UTC (rev 4156) +++ trunk/nhibernate/releasenotes.txt 2009-03-28 16:35:33 UTC (rev 4157) @@ -20,6 +20,7 @@ ##### Breaking Changes ##### * see NH-1633 if you are using SQL native queries * see NH-1657 if you are using 'TimeSpan' NH type. + * CriteriaUtil is gone. NHibernate.Transform.Transformers now returns predefined IResultTransformer. Build 2.1.0.Alpha1 ======================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-28 16:17:31
|
Revision: 4156 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4156&view=rev Author: fabiomaulo Date: 2009-03-28 16:17:20 +0000 (Sat, 28 Mar 2009) Log Message: ----------- - Fix NH-1713 - Removed prepare_sql from our configuration in order to use the default defined in the dialect. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/Oracle8iDialect.cs trunk/nhibernate/src/NHibernate.Test/App.config trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationFixture.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Domain.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-03-28 15:28:16 UTC (rev 4155) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-03-28 16:17:20 UTC (rev 4156) @@ -131,7 +131,6 @@ RegisterKeyword("integer"); DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SqlClientDriver"; - DefaultProperties[Environment.PrepareSql] = "true"; } /// <summary></summary> Modified: trunk/nhibernate/src/NHibernate/Dialect/Oracle8iDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Oracle8iDialect.cs 2009-03-28 15:28:16 UTC (rev 4155) +++ trunk/nhibernate/src/NHibernate/Dialect/Oracle8iDialect.cs 2009-03-28 16:17:20 UTC (rev 4156) @@ -218,7 +218,6 @@ protected internal virtual void RegisterDefaultProperties() { - DefaultProperties[Environment.PrepareSql] = "false"; //DefaultProperties[Environment.DefaultBatchFetchSize] = DefaultBatchSize; It can break some test and it is a user matter // Oracle driver reports to support GetGeneratedKeys(), but they only Modified: trunk/nhibernate/src/NHibernate.Test/App.config =================================================================== --- trunk/nhibernate/src/NHibernate.Test/App.config 2009-03-28 15:28:16 UTC (rev 4155) +++ trunk/nhibernate/src/NHibernate.Test/App.config 2009-03-28 16:17:20 UTC (rev 4156) @@ -46,7 +46,6 @@ <property name="connection.provider">NHibernate.Test.DebugConnectionProvider, NHibernate.Test</property> <property name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider, NHibernate</property> <property name="cache.use_query_cache">true</property> - <property name="prepare_sql">false</property> <property name="query.startup_check">false</property> <!-- The valid strings for Isolation can be found in the documentation for the System.Data.IsolationLevel Modified: trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationFixture.cs 2009-03-28 15:28:16 UTC (rev 4155) +++ trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationFixture.cs 2009-03-28 16:17:20 UTC (rev 4156) @@ -29,7 +29,8 @@ Assert.IsTrue(cfg.Properties.ContainsKey(Environment.ShowSql)); Assert.IsTrue(cfg.Properties.ContainsKey(Environment.UseQueryCache)); - Assert.IsTrue(cfg.Properties.ContainsKey(Environment.PrepareSql)); + Assert.IsFalse(cfg.Properties.ContainsKey(Environment.PrepareSql), + "Our default conf should not include override the possible Dialect default configuration."); Assert.IsTrue(cfg.Properties.ContainsKey(Environment.Isolation)); Assert.AreEqual("true 1, false 0, yes 1, no 0", cfg.Properties[Environment.QuerySubstitutions]); Assert.AreEqual("Server=localhost;initial catalog=nhibernate;User Id=;Password=", Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Domain.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Domain.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Domain.cs 2009-03-28 16:17:20 UTC (rev 4156) @@ -0,0 +1,8 @@ +namespace NHibernate.Test.NHSpecificTest.NH1713 +{ + public class A + { + public virtual int Id { get; set; } + public virtual decimal? Amount { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Fixture.cs 2009-03-28 16:17:20 UTC (rev 4156) @@ -0,0 +1,96 @@ +using NHibernate.Cfg; +using NHibernate.Dialect; +using NHibernate.Util; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; + +namespace NHibernate.Test.NHSpecificTest.NH1713 +{ + [TestFixture, Ignore("Should be fixed in some way.")] + public class Fixture : BugTestCase + { + /* NOTE + * This test should be fixed in some way at least to support Money. + * So far it is only a demostration that using + * <property name="prepare_sql">false</property> + * we should do some additional work for INSERT+UPDATE + */ + protected override void Configure(Configuration configuration) + { + configuration.SetProperty(Environment.PrepareSql, "true"); + } + + protected override bool AppliesTo(Dialect.Dialect dialect) + { + return dialect is MsSql2000Dialect; + } + + [Test] + public void Can_Save_Money_Column() + { + Assert.That(PropertiesHelper.GetBoolean(Environment.PrepareSql, cfg.Properties, false)); + var item = new A {Amount = 2600}; + + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(item); + tx.Commit(); + } + } + + Assert.IsTrue(item.Id > 0); + + // cleanup + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + s.Delete("from A"); + tx.Commit(); + } + } + } + + [Test] + public void Can_Update_Money_Column() + { + Assert.That(PropertiesHelper.GetBoolean(Environment.PrepareSql, cfg.Properties, false)); + object savedId; + var item = new A {Amount = (decimal?) 2600.55}; + + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + savedId= s.Save(item); + tx.Commit(); + } + } + + Assert.That(item.Id, Is.GreaterThan(0)); + + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + var item2 = s.Load<A>(savedId); + item2.Amount = item2.Amount - 1.5m; + s.SaveOrUpdate(item2); + tx.Commit(); + } + } + + // cleanup + using (ISession s = OpenSession()) + { + using (ITransaction tx = s.BeginTransaction()) + { + s.Delete("from A"); + tx.Commit(); + } + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1713/Mappings.hbm.xml 2009-03-28 16:17:20 UTC (rev 4156) @@ -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.NH1713"> + + <class name="A"> + <id name="Id"> + <generator class="native" /> + </id> + <property name="Amount"> + <column name="Amount" sql-type="money"/> + </property> + </class> +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-28 15:28:16 UTC (rev 4155) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-28 16:17:20 UTC (rev 4156) @@ -298,6 +298,12 @@ <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> <Compile Include="NHSpecificTest\NH1706\KeyPropertyRefFixture.cs" /> <Compile Include="NHSpecificTest\NH1710\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1713\Domain.cs"> + <SubType>Code</SubType> + </Compile> + <Compile Include="NHSpecificTest\NH1713\Fixture.cs"> + <SubType>Code</SubType> + </Compile> <Compile Include="NHSpecificTest\NH1715\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1715\ClassA.cs" /> <Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" /> @@ -1694,6 +1700,7 @@ <EmbeddedResource Include="NHSpecificTest\NH1710\InLine.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1710\Heuristic.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1710\Defined.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH1713\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1715\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\DtcFailures\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1694\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-28 15:28:22
|
Revision: 4155 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4155&view=rev Author: fabiomaulo Date: 2009-03-28 15:28:16 +0000 (Sat, 28 Mar 2009) Log Message: ----------- Fix NH-1710 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/FirebirdDialect.cs trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs trunk/nhibernate/src/NHibernate/Dialect/Oracle8iDialect.cs trunk/nhibernate/src/NHibernate/Mapping/Column.cs trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Defined.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Heuristic.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/InLine.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/WithColumnNode.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Dialect/FirebirdDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/FirebirdDialect.cs 2009-03-25 18:35:41 UTC (rev 4154) +++ trunk/nhibernate/src/NHibernate/Dialect/FirebirdDialect.cs 2009-03-28 15:28:16 UTC (rev 4155) @@ -41,10 +41,11 @@ RegisterColumnType(DbType.Boolean, "SMALLINT"); RegisterColumnType(DbType.Byte, "SMALLINT"); RegisterColumnType(DbType.Currency, "DECIMAL(18,4)"); + RegisterColumnType(DbType.Currency, "DECIMAL($p,$s)"); RegisterColumnType(DbType.Date, "DATE"); RegisterColumnType(DbType.DateTime, "TIMESTAMP"); RegisterColumnType(DbType.Decimal, "DECIMAL(18,5)"); // NUMERIC(18,5) is equivalent to DECIMAL(18,5) - RegisterColumnType(DbType.Decimal, 18, "DECIMAL(18, $l)"); + RegisterColumnType(DbType.Decimal, 18, "DECIMAL($p, $s)"); RegisterColumnType(DbType.Double, "DOUBLE PRECISION"); RegisterColumnType(DbType.Guid, "CHAR(16) CHARACTER SET OCTETS"); RegisterColumnType(DbType.Int16, "SMALLINT"); Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-03-25 18:35:41 UTC (rev 4154) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-03-28 15:28:16 UTC (rev 4155) @@ -57,7 +57,6 @@ RegisterColumnType(DbType.Date, "DATETIME"); RegisterColumnType(DbType.DateTime, "DATETIME"); RegisterColumnType(DbType.Decimal, "DECIMAL(19,5)"); - RegisterColumnType(DbType.Decimal, 19, "DECIMAL(19, $l)"); RegisterColumnType(DbType.Decimal, 19, "DECIMAL($p, $s)"); RegisterColumnType(DbType.Double, "DOUBLE PRECISION"); //synonym for FLOAT(53) RegisterColumnType(DbType.Guid, "UNIQUEIDENTIFIER"); Modified: trunk/nhibernate/src/NHibernate/Dialect/Oracle8iDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Oracle8iDialect.cs 2009-03-25 18:35:41 UTC (rev 4154) +++ trunk/nhibernate/src/NHibernate/Dialect/Oracle8iDialect.cs 2009-03-28 15:28:16 UTC (rev 4155) @@ -109,9 +109,7 @@ RegisterColumnType(DbType.Single, "FLOAT(24)"); RegisterColumnType(DbType.Double, "DOUBLE PRECISION"); RegisterColumnType(DbType.Double, 19, "NUMBER($p,$s)"); - RegisterColumnType(DbType.Double, 19, "NUMBER(19, $l)"); RegisterColumnType(DbType.Decimal, "NUMBER(19,5)"); - RegisterColumnType(DbType.Decimal, 19, "NUMBER(19, $l)"); RegisterColumnType(DbType.Decimal, 19, "NUMBER($p,$s)"); } Modified: trunk/nhibernate/src/NHibernate/Mapping/Column.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/Column.cs 2009-03-25 18:35:41 UTC (rev 4154) +++ trunk/nhibernate/src/NHibernate/Mapping/Column.cs 2009-03-28 15:28:16 UTC (rev 4155) @@ -211,7 +211,10 @@ private string GetDialectTypeName(Dialect.Dialect dialect, IMapping mapping) { if (IsCaracteristicsDefined()) - return dialect.GetTypeName(GetSqlTypeCode(mapping), Length, Precision, Scale); + { + // NH-1070 (the size should be 0 if the precision is defined) + return dialect.GetTypeName(GetSqlTypeCode(mapping), (!IsPrecisionDefined()) ? Length:0, Precision, Scale); + } else return dialect.GetTypeName(GetSqlTypeCode(mapping)); } @@ -414,6 +417,11 @@ return length.HasValue || precision.HasValue || scale.HasValue; } + private bool IsPrecisionDefined() + { + return precision.HasValue || scale.HasValue; + } + #region ICloneable Members /// <summary> Shallow copy, the value is not copied</summary> public object Clone() Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-03-25 18:35:41 UTC (rev 4154) +++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-03-28 15:28:16 UTC (rev 4155) @@ -156,11 +156,12 @@ // be created. RegisterType(typeof(Object), NHibernateUtil.Object, "object"); - // These are in here for Hibernate mapping compatibility + // These are in here because needed to NO override default CLR types and be available in mappings typeByTypeOfName["int"] = NHibernateUtil.Int32; typeByTypeOfName["date"] = NHibernateUtil.Date; typeByTypeOfName["time"] = NHibernateUtil.Time; typeByTypeOfName["timestamp"] = NHibernateUtil.Timestamp; + typeByTypeOfName["decimal"] = NHibernateUtil.Decimal; typeByTypeOfName["serializable"] = NHibernateUtil.Serializable; typeByTypeOfName["true_false"] = NHibernateUtil.TrueFalse; Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Defined.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Defined.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Defined.hbm.xml 2009-03-28 15:28:16 UTC (rev 4155) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1710"> + + <class name="A"> + <id type="int"> + <generator class="native" /> + </id> + <property name="Amount" type="decimal" precision="5" scale="2"/> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Fixture.cs 2009-03-28 15:28:16 UTC (rev 4155) @@ -0,0 +1,93 @@ +using System.Text; +using NHibernate.Cfg; +using NHibernate.Engine; +using NHibernate.Tool.hbm2ddl; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; + +namespace NHibernate.Test.NHSpecificTest.NH1710 +{ + public class A + { + public virtual decimal? Amount { get; set; } + } + + public abstract class BaseFixture + { + protected const string TestNameSpace = "NHibernate.Test.NHSpecificTest.NH1710."; + protected Configuration cfg; + protected ISessionFactoryImplementor factory; + private string expectedExportString; + + [TestFixtureSetUp] + public void Config() + { + cfg = new Configuration(); + if (TestConfigurationHelper.hibernateConfigFile != null) + cfg.Configure(TestConfigurationHelper.hibernateConfigFile); + + cfg.AddResource(GetResourceFullName(), GetType().Assembly); + + factory = (ISessionFactoryImplementor)cfg.BuildSessionFactory(); + + expectedExportString = GetDialect().GetTypeName(NHibernateUtil.Decimal.SqlType, 0, 5, 2); + } + + [Test] + public void NotIgnorePrecisionScaleInSchemaExport() + { + var script = new StringBuilder(); + new SchemaExport(cfg).Create(sl => script.AppendLine(sl), true); + Assert.That(script.ToString(), Text.Contains(expectedExportString)); + new SchemaExport(cfg).Drop(false, true); + } + + private Dialect.Dialect GetDialect() + { + return Dialect.Dialect.GetDialect(cfg.Properties); + } + + protected abstract string GetResourceName(); + + private string GetResourceFullName() + { + return TestNameSpace + GetResourceName(); + } + } + + [TestFixture] + public class FixtureWithExplicitDefinedType : BaseFixture + { + protected override string GetResourceName() + { + return "Heuristic.hbm.xml"; + } + } + + [TestFixture] + public class FixtureWithHeuristicDefinedType : BaseFixture + { + protected override string GetResourceName() + { + return "Defined.hbm.xml"; + } + } + + [TestFixture] + public class FixtureWithInLineDefinedType : BaseFixture + { + protected override string GetResourceName() + { + return "InLine.hbm.xml"; + } + } + + [TestFixture] + public class FixtureWithColumnNode : BaseFixture + { + protected override string GetResourceName() + { + return "WithColumnNode.hbm.xml"; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Heuristic.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Heuristic.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/Heuristic.hbm.xml 2009-03-28 15:28:16 UTC (rev 4155) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1710"> + + <class name="A"> + <id type="int"> + <generator class="native" /> + </id> + <property name="Amount" precision="5" scale="2"/> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/InLine.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/InLine.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/InLine.hbm.xml 2009-03-28 15:28:16 UTC (rev 4155) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1710"> + + <class name="A"> + <id type="int"> + <generator class="native" /> + </id> + <property name="Amount" type="Decimal(5,2)"/> + </class> + +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/WithColumnNode.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/WithColumnNode.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1710/WithColumnNode.hbm.xml 2009-03-28 15:28:16 UTC (rev 4155) @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1710"> + + <class name="A"> + <id type="int"> + <generator class="native" /> + </id> + <property name="Amount"> + <column name="Amount" precision="5" scale="2"/> + </property> + </class> + +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-25 18:35:41 UTC (rev 4154) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-28 15:28:16 UTC (rev 4155) @@ -297,6 +297,7 @@ <Compile Include="NHSpecificTest\NH1694\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> <Compile Include="NHSpecificTest\NH1706\KeyPropertyRefFixture.cs" /> + <Compile Include="NHSpecificTest\NH1710\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1715\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1715\ClassA.cs" /> <Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" /> @@ -1689,6 +1690,10 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1710\WithColumnNode.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH1710\InLine.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH1710\Heuristic.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\NH1710\Defined.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1715\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\DtcFailures\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1694\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-03-25 18:36:44
|
Revision: 4154 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4154&view=rev Author: darioquintana Date: 2009-03-25 18:35:41 +0000 (Wed, 25 Mar 2009) Log Message: ----------- NH-1715 partially applied, because the duration < 0 hours or > 24 hours shouldn't be handle with "TimeSpan" NHibernate type. Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/ClassA.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/Mappings.hbm.xml Modified: trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs 2009-03-24 11:56:15 UTC (rev 4153) +++ trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs 2009-03-25 18:35:41 UTC (rev 4154) @@ -32,9 +32,8 @@ object value = rs[index]; if(value is TimeSpan) return (TimeSpan)value; - - DateTime time = (DateTime)rs[index]; - return new TimeSpan(Convert.ToInt64(time.Ticks)); + + return ((DateTime)value).Subtract(BaseDateValue); } catch (Exception ex) { @@ -50,8 +49,7 @@ if (value is TimeSpan) //For those dialects where DbType.Time means TimeSpan. return (TimeSpan)value; - DateTime time = (DateTime)rs[name]; - return new TimeSpan(Convert.ToInt64(time.Ticks)); + return ((DateTime)value).Subtract(BaseDateValue); } catch (Exception ex) { Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/ClassA.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/ClassA.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/ClassA.cs 2009-03-25 18:35:41 UTC (rev 4154) @@ -0,0 +1,10 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH1715 +{ + public class ClassA + { + public virtual int Id { get; set; } + public virtual TimeSpan Time { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/Fixture.cs 2009-03-25 18:35:41 UTC (rev 4154) @@ -0,0 +1,55 @@ +using System; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1715 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override void OnTearDown() + { + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Delete("from ClassA"); + tx.Commit(); + } + } + + [Test] + public void TimeSpanLargerThan2h() + { + var time = new TimeSpan(0, 2, 1, 0); + var entity = new ClassA {Time = time}; + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(entity); + tx.Commit(); + } + + using (ISession s = OpenSession()) + { + Assert.AreEqual(time, s.Get<ClassA>(entity.Id).Time); + } + } + + [Test] + public void VerifyDaysShouldBeZeroInSmallTimeSpan() + { + var time = new TimeSpan(1, 0, 0); + var entity = new ClassA {Time = time}; + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(entity); + tx.Commit(); + } + + using (ISession s = OpenSession()) + { + Assert.AreEqual(0, s.Get<ClassA>(entity.Id).Time.Days); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1715/Mappings.hbm.xml 2009-03-25 18:35:41 UTC (rev 4154) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8" ?> + +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.NH1715" + assembly="NHibernate.Test"> + + <class name="ClassA"> + <id name="Id"> + <generator class="native"/> + </id> + <property name="Time" type="TimeSpan"/> + </class> + +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-24 11:56:15 UTC (rev 4153) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-25 18:35:41 UTC (rev 4154) @@ -297,6 +297,8 @@ <Compile Include="NHSpecificTest\NH1694\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> <Compile Include="NHSpecificTest\NH1706\KeyPropertyRefFixture.cs" /> + <Compile Include="NHSpecificTest\NH1715\Fixture.cs" /> + <Compile Include="NHSpecificTest\NH1715\ClassA.cs" /> <Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" /> <Compile Include="HQL\HQLFunctions.cs" /> <Compile Include="HQL\Human.cs" /> @@ -1687,6 +1689,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1715\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\DtcFailures\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1694\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1706\Mappings.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Clinton B. <ha...@ad...> - 2009-03-25 08:33:44
|
<http://cid-dc420f0e0a08d413.spaces.live.com/blog/cns!DC420F0E0A08D413!104.entry> Grim jokes of the critical veterans but the retreating that girl has she is a remarkably nice girl, said same persuasion was common to us all. A panic in his vicarage, which was only a larger laborer's rose to his feet, bowing, and i rose also. M.. |
From: <aye...@us...> - 2009-03-24 11:56:33
|
Revision: 4153 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4153&view=rev Author: ayenderahien Date: 2009-03-24 11:56:15 +0000 (Tue, 24 Mar 2009) Log Message: ----------- enhancing test case error reporting adding passing test for NH-1709, but I don't think it reproduces the error well Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs trunk/nhibernate/src/NHibernate.Test/TestCase.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs 2009-03-24 11:27:18 UTC (rev 4152) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs 2009-03-24 11:56:15 UTC (rev 4153) @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Threading; @@ -57,6 +58,31 @@ } [Test] + public void Can_roll_back_transaction() + { + var tx = new TransactionScope(); + using (var s = sessions.OpenSession()) + { + new ForceEscalationToDistributedTx(true);//will rollback tx + s.Save(new Person + { + CreatedAt = DateTime.Today + }); + + tx.Complete(); + } + try + { + tx.Dispose(); + Assert.Fail("Expected tx abort"); + } + catch (TransactionAbortedException) + { + //expected + } + } + + [Test] public void CanDeleteItemInDtc() { object id; @@ -87,17 +113,28 @@ public class ForceEscalationToDistributedTx : IEnlistmentNotification { + private readonly bool shouldRollBack; private readonly int thread; - public ForceEscalationToDistributedTx() + + public ForceEscalationToDistributedTx(bool shouldRollBack) { + this.shouldRollBack = shouldRollBack; thread = Thread.CurrentThread.ManagedThreadId; System.Transactions.Transaction.Current.EnlistDurable(Guid.NewGuid(), this, EnlistmentOptions.None); } + public ForceEscalationToDistributedTx():this(false) + { + + } + public void Prepare(PreparingEnlistment preparingEnlistment) { Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId); - preparingEnlistment.Prepared(); + if (shouldRollBack) + preparingEnlistment.ForceRollback(); + else + preparingEnlistment.Prepared(); } public void Commit(Enlistment enlistment) Modified: trunk/nhibernate/src/NHibernate.Test/TestCase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/TestCase.cs 2009-03-24 11:27:18 UTC (rev 4152) +++ trunk/nhibernate/src/NHibernate.Test/TestCase.cs 2009-03-24 11:56:15 UTC (rev 4153) @@ -123,7 +123,8 @@ if (fail) { - Assert.Fail("Test didn't clean up after itself"); + Assert.Fail("Test didn't clean up after itself. session closed: " + wasClosed + " database cleaned: "+ wasCleaned + + " connection closed: " + wereConnectionsClosed); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2009-03-24 11:27:28
|
Revision: 4152 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4152&view=rev Author: ayenderahien Date: 2009-03-24 11:27:18 +0000 (Tue, 24 Mar 2009) Log Message: ----------- cloning and disposing of the ambient transaction, instead of using the current one. This protects us from bugs in the framework that dispose the transaction early. Fixed NH-1676 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-03-24 10:59:04 UTC (rev 4151) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-03-24 11:27:18 UTC (rev 4152) @@ -190,6 +190,15 @@ protected internal void SetClosed() { + try + { + if (ambientTransation != null) + ambientTransation.Dispose(); + } + catch (Exception) + { + //ignore + } closed = true; } @@ -310,7 +319,7 @@ return; if (System.Transactions.Transaction.Current==null) return; - ambientTransation = System.Transactions.Transaction.Current; + ambientTransation = System.Transactions.Transaction.Current.Clone(); logger.DebugFormat("enlisted into DTC transaction: {0}", ambientTransation.IsolationLevel); AfterTransactionBegin(null); ambientTransation.TransactionCompleted += delegate(object sender, TransactionEventArgs e) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2009-03-24 10:59:06
|
Revision: 4151 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4151&view=rev Author: ayenderahien Date: 2009-03-24 10:59:04 +0000 (Tue, 24 Mar 2009) Log Message: ----------- implementing a fix to flush during prepared event in escalated DTC tx Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-03-22 17:56:16 UTC (rev 4150) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-03-24 10:59:04 UTC (rev 4151) @@ -260,14 +260,19 @@ { try { - BeforeTransactionCompletion(null); - if (FlushMode != FlushMode.Never) + using(var tx = new TransactionScope(ambientTransation)) { - using (ConnectionManager.FlushingFromDtcTransaction) - Flush(); - } - preparingEnlistment.Prepared(); - logger.Debug("prepared for DTC transaction"); + BeforeTransactionCompletion(null); + if (FlushMode != FlushMode.Never) + { + using (ConnectionManager.FlushingFromDtcTransaction) + Flush(); + } + logger.Debug("prepared for DTC transaction"); + + tx.Complete(); + } + preparingEnlistment.Prepared(); } catch (Exception exception) { @@ -315,7 +320,7 @@ if (shouldCloseSessionOnDtcTransactionCompleted) Dispose(true); }; - ambientTransation.EnlistVolatile(this, EnlistmentOptions.None); + ambientTransation.EnlistVolatile(this, EnlistmentOptions.EnlistDuringPrepareRequired); } protected abstract void Dispose(bool disposing); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Raether A. <obj...@dc...> - 2009-03-24 00:25:46
|
<http://cid-4691121c206789a4.spaces.live.com/blog/cns!4691121C206789A4!104.entry> Pip and emma. Patrick and julia simmons are the of you to the stable, and order hither a horse received us with his usual smiling courtesy. He committed. Peter lord breathed a sigh of exasperation. It) the generous, though melancholy envy of an. |
From: <aye...@us...> - 2009-03-22 17:56:22
|
Revision: 4150 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4150&view=rev Author: ayenderahien Date: 2009-03-22 17:56:16 +0000 (Sun, 22 Mar 2009) Log Message: ----------- Renaming file to match class name. Adding ignored failing test Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs 2009-03-22 17:56:16 UTC (rev 4150) @@ -0,0 +1,119 @@ +using System; +using System.Data; +using System.Data.SqlClient; +using System.Threading; +using System.Transactions; +using NHibernate.Criterion; +using NHibernate.Dialect; +using NHibernate.Exceptions; +using NHibernate.Impl; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.DtcFailures +{ + using System.Collections; + + [TestFixture] + public class DtcFailuresFixture : TestCase + { + + protected override IList Mappings + { + get { return new string[] { "NHSpecificTest.DtcFailures.Mappings.hbm.xml" }; } + } + + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + [Test] + public void WillNotCrashOnDtcPrepareFailure() + { + var tx = new TransactionScope(); + using (var s = sessions.OpenSession()) + { + s.Save(new Person + { + CreatedAt = DateTime.MinValue // will cause SQL date failure + }); + } + + new ForceEscalationToDistributedTx(); + + tx.Complete(); + try + { + tx.Dispose(); + Assert.Fail("Expected failure"); + } + catch (AssertionException) + { + throw; + } + catch (Exception) + { + } + } + + [Test] + public void CanDeleteItemInDtc() + { + object id; + using (var tx = new TransactionScope()) + using (var s = sessions.OpenSession()) + { + id = s.Save(new Person + { + CreatedAt = DateTime.Today + }); + + new ForceEscalationToDistributedTx(); + + tx.Complete(); + } + + using (var tx = new TransactionScope()) + using (var s = sessions.OpenSession()) + { + new ForceEscalationToDistributedTx(); + + s.Delete(s.Get<Person>(id)); + + tx.Complete(); + } + + } + + public class ForceEscalationToDistributedTx : IEnlistmentNotification + { + private readonly int thread; + public ForceEscalationToDistributedTx() + { + thread = Thread.CurrentThread.ManagedThreadId; + System.Transactions.Transaction.Current.EnlistDurable(Guid.NewGuid(), this, EnlistmentOptions.None); + } + + public void Prepare(PreparingEnlistment preparingEnlistment) + { + Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId); + preparingEnlistment.Prepared(); + } + + public void Commit(Enlistment enlistment) + { + enlistment.Done(); + } + + public void Rollback(Enlistment enlistment) + { + enlistment.Done(); + } + + public void InDoubt(Enlistment enlistment) + { + enlistment.Done(); + } + } + } +} Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs 2009-03-22 14:21:03 UTC (rev 4149) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs 2009-03-22 17:56:16 UTC (rev 4150) @@ -1,90 +0,0 @@ -using System; -using System.Data; -using System.Data.SqlClient; -using System.Threading; -using System.Transactions; -using NHibernate.Criterion; -using NHibernate.Dialect; -using NHibernate.Exceptions; -using NHibernate.Impl; -using NUnit.Framework; - -namespace NHibernate.Test.NHSpecificTest.DtcFailures -{ - using System.Collections; - - [TestFixture] - public class DtcFailuresFixture : TestCase - { - - protected override IList Mappings - { - get { return new string[] { "NHSpecificTest.DtcFailures.Mappings.hbm.xml" }; } - } - - protected override string MappingsAssembly - { - get { return "NHibernate.Test"; } - } - - [Test] - public void WillNotCrashOnDtcPrepareFailure() - { - var tx = new TransactionScope(); - using (var s = sessions.OpenSession()) - { - s.Save(new Person - { - CreatedAt = DateTime.MinValue // will cause SQL date failure - }); - } - - new ForceEscalationToDistributedTx(); - - tx.Complete(); - try - { - tx.Dispose(); - Assert.Fail("Expected failure"); - } - catch (AssertionException) - { - throw; - } - catch (Exception) - { - } - } - - public class ForceEscalationToDistributedTx : IEnlistmentNotification - { - private readonly int thread; - public ForceEscalationToDistributedTx() - { - thread = Thread.CurrentThread.ManagedThreadId; - System.Transactions.Transaction.Current.EnlistDurable(Guid.NewGuid(), this, EnlistmentOptions.None); - } - - public void Prepare(PreparingEnlistment preparingEnlistment) - { - Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId); - preparingEnlistment.Prepared(); - } - - public void Commit(Enlistment enlistment) - { - enlistment.Done(); - } - - public void Rollback(Enlistment enlistment) - { - enlistment.Done(); - } - - public void InDoubt(Enlistment enlistment) - { - enlistment.Done(); - } - } - } -} Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-22 14:21:03 UTC (rev 4149) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-22 17:56:16 UTC (rev 4150) @@ -292,7 +292,7 @@ <Compile Include="GenericTest\SetGeneric\SetGenericFixture.cs" /> <Compile Include="HQL\Animal.cs" /> <Compile Include="HQL\BaseFunctionFixture.cs" /> - <Compile Include="NHSpecificTest\DtcFailures\FutureCriteriaFixture.cs" /> + <Compile Include="NHSpecificTest\DtcFailures\DtcFailuresFixture.cs" /> <Compile Include="NHSpecificTest\DtcFailures\Person.cs" /> <Compile Include="NHSpecificTest\NH1694\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aye...@us...> - 2009-03-22 14:21:08
|
Revision: 4149 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4149&view=rev Author: ayenderahien Date: 2009-03-22 14:21:03 +0000 (Sun, 22 Mar 2009) Log Message: ----------- Fixing NH-1711 - Failure of DTC transaction with multiple durable enlistment will crash the process Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs Modified: trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-03-18 16:36:27 UTC (rev 4148) +++ trunk/nhibernate/src/NHibernate/Impl/AbstractSessionImpl.cs 2009-03-22 14:21:03 UTC (rev 4149) @@ -258,14 +258,23 @@ void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment) { - BeforeTransactionCompletion(null); - if (FlushMode != FlushMode.Never) - { - using (ConnectionManager.FlushingFromDtcTransaction) - Flush(); - } - preparingEnlistment.Prepared(); - logger.Debug("prepared for DTC transaction"); + try + { + BeforeTransactionCompletion(null); + if (FlushMode != FlushMode.Never) + { + using (ConnectionManager.FlushingFromDtcTransaction) + Flush(); + } + preparingEnlistment.Prepared(); + logger.Debug("prepared for DTC transaction"); + } + catch (Exception exception) + { + logger.Error("DTC transaction prepre phase failed", exception); + preparingEnlistment.ForceRollback(exception); + + } } void IEnlistmentNotification.Commit(Enlistment enlistment) Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures ___________________________________________________________________ Added: bugtraq:url + http://jira.nhibernate.org/browse/%BUGID% Added: bugtraq:logregex + NH-\d+ Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/FutureCriteriaFixture.cs 2009-03-22 14:21:03 UTC (rev 4149) @@ -0,0 +1,90 @@ +using System; +using System.Data; +using System.Data.SqlClient; +using System.Threading; +using System.Transactions; +using NHibernate.Criterion; +using NHibernate.Dialect; +using NHibernate.Exceptions; +using NHibernate.Impl; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.DtcFailures +{ + using System.Collections; + + [TestFixture] + public class DtcFailuresFixture : TestCase + { + + protected override IList Mappings + { + get { return new string[] { "NHSpecificTest.DtcFailures.Mappings.hbm.xml" }; } + } + + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + [Test] + public void WillNotCrashOnDtcPrepareFailure() + { + var tx = new TransactionScope(); + using (var s = sessions.OpenSession()) + { + s.Save(new Person + { + CreatedAt = DateTime.MinValue // will cause SQL date failure + }); + } + + new ForceEscalationToDistributedTx(); + + tx.Complete(); + try + { + tx.Dispose(); + Assert.Fail("Expected failure"); + } + catch (AssertionException) + { + throw; + } + catch (Exception) + { + } + } + + public class ForceEscalationToDistributedTx : IEnlistmentNotification + { + private readonly int thread; + public ForceEscalationToDistributedTx() + { + thread = Thread.CurrentThread.ManagedThreadId; + System.Transactions.Transaction.Current.EnlistDurable(Guid.NewGuid(), this, EnlistmentOptions.None); + } + + public void Prepare(PreparingEnlistment preparingEnlistment) + { + Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId); + preparingEnlistment.Prepared(); + } + + public void Commit(Enlistment enlistment) + { + enlistment.Done(); + } + + public void Rollback(Enlistment enlistment) + { + enlistment.Done(); + } + + public void InDoubt(Enlistment enlistment) + { + enlistment.Done(); + } + } + } +} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Mappings.hbm.xml 2009-03-22 14:21:03 UTC (rev 4149) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.DtcFailures" + assembly="NHibernate.Test"> + + <class name="Person"> + <id name="Id"> + <generator class="hilo"/> + </id> + <property name="CreatedAt"/> + + </class> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/DtcFailures/Person.cs 2009-03-22 14:21:03 UTC (rev 4149) @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System; + +namespace NHibernate.Test.NHSpecificTest.DtcFailures +{ + public class Person + { + private int id; + + public virtual DateTime CreatedAt { get; set; } + + public virtual int Id + { + get { return id; } + set { id = value; } + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-18 16:36:27 UTC (rev 4148) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-22 14:21:03 UTC (rev 4149) @@ -292,6 +292,8 @@ <Compile Include="GenericTest\SetGeneric\SetGenericFixture.cs" /> <Compile Include="HQL\Animal.cs" /> <Compile Include="HQL\BaseFunctionFixture.cs" /> + <Compile Include="NHSpecificTest\DtcFailures\FutureCriteriaFixture.cs" /> + <Compile Include="NHSpecificTest\DtcFailures\Person.cs" /> <Compile Include="NHSpecificTest\NH1694\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> <Compile Include="NHSpecificTest\NH1706\KeyPropertyRefFixture.cs" /> @@ -1685,6 +1687,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\DtcFailures\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1694\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1706\Mappings.hbm.xml" /> <EmbeddedResource Include="Stateless\Naturalness.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-18 17:23:17
|
Revision: 4148 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4148&view=rev Author: fabiomaulo Date: 2009-03-18 16:36:27 +0000 (Wed, 18 Mar 2009) Log Message: ----------- Removed for wrong commit Removed Paths: ------------- trunk/NHibernate.Test/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-18 17:22:44
|
Revision: 4147 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4147&view=rev Author: fabiomaulo Date: 2009-03-18 16:34:39 +0000 (Wed, 18 Mar 2009) Log Message: ----------- Fix NH-1694 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/NHibernate.Test/ trunk/NHibernate.Test/NHSpecificTest/ trunk/NHibernate.Test/NHSpecificTest/NH1694/ trunk/NHibernate.Test/NHSpecificTest/NH1694/Mappings.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1694/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1694/Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1694/Mappings.hbm.xml Added: trunk/NHibernate.Test/NHSpecificTest/NH1694/Mappings.hbm.xml =================================================================== --- trunk/NHibernate.Test/NHSpecificTest/NH1694/Mappings.hbm.xml (rev 0) +++ trunk/NHibernate.Test/NHSpecificTest/NH1694/Mappings.hbm.xml 2009-03-18 16:34:39 UTC (rev 4147) @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1694"> + + <class name="User" table="Users"> + <id name="Id"> + <generator class="native"/> + </id> + <property name="OrderStatus" formula="CASE ISNULL((SELECT MIN(CONVERT(INT,ISNULL(o.Status,0))) FROM dbo.Orders o WHERE o.userid=id),-1) WHEN -1 THEN 0 WHEN 0 THEN 1 ELSE 2 END" /> + </class> + + <class name="Orders"> + <id name="Id"> + <generator class="native"/> + </id> + <property name="Status" /> + <many-to-one name="User" class="User" column="UserID" /> + </class> + +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-03-18 15:54:41 UTC (rev 4146) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs 2009-03-18 16:34:39 UTC (rev 4147) @@ -56,16 +56,9 @@ RegisterColumnType(DbType.Currency, "MONEY"); RegisterColumnType(DbType.Date, "DATETIME"); RegisterColumnType(DbType.DateTime, "DATETIME"); - // TODO: figure out if this is the good way to fix the problem - // with exporting a DECIMAL column - // NUMERIC(precision, scale) has a hardcoded precision of 19, even though it can range from 1 to 38 - // and the scale has to be 0 <= scale <= precision. - // I think how I might handle it is keep the type="Decimal(29,5)" and make them specify a - // sql-type="decimal(20,5)" if they need to do that. The Decimal parameter and ddl will get generated - // correctly with minimal work. RegisterColumnType(DbType.Decimal, "DECIMAL(19,5)"); RegisterColumnType(DbType.Decimal, 19, "DECIMAL(19, $l)"); - RegisterColumnType(DbType.Decimal, 19, "DECIMAL($p, $s)"); + RegisterColumnType(DbType.Decimal, 19, "DECIMAL($p, $s)"); RegisterColumnType(DbType.Double, "DOUBLE PRECISION"); //synonym for FLOAT(53) RegisterColumnType(DbType.Guid, "UNIQUEIDENTIFIER"); RegisterColumnType(DbType.Int16, "SMALLINT"); @@ -136,6 +129,7 @@ RegisterFunction("iif", new SQLFunctionTemplate(null, "case when ?1 then ?2 else ?3 end")); RegisterKeyword("top"); + RegisterKeyword("integer"); DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.SqlClientDriver"; DefaultProperties[Environment.PrepareSql] = "true"; Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1694/Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1694/Fixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1694/Fixture.cs 2009-03-18 16:34:39 UTC (rev 4147) @@ -0,0 +1,95 @@ +using System.Collections.Generic; +using NHibernate.Criterion; +using NHibernate.Dialect; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; + +namespace NHibernate.Test.NHSpecificTest.NH1694 +{ + [TestFixture] + public class Fixture : BugTestCase + { + protected override bool AppliesTo(Dialect.Dialect dialect) + { + return dialect is MsSql2005Dialect; + } + + private void FillDb() + { + base.OnSetUp(); + using (ISession session = OpenSession()) + { + using (ITransaction tran = session.BeginTransaction()) + { + var newUser = new User(); + var newOrder1 = new Orders {User = newUser, Status = true}; + var newOrder2 = new Orders {User = newUser, Status = true}; + + session.Save(newUser); + session.Save(newOrder1); + session.Save(newOrder2); + + newUser = new User(); + newOrder1 = new Orders {User = newUser, Status = false}; + + session.Save(newUser); + session.Save(newOrder1); + + tran.Commit(); + } + } + } + + private void Cleanup() + { + base.OnTearDown(); + using (ISession session = OpenSession()) + { + using (ITransaction tran = session.BeginTransaction()) + { + session.Delete("from Orders"); + session.Delete("from User"); + tran.Commit(); + } + } + } + + [Test] + public void CanOrderByExpressionContainingACommaInAPagedQuery() + { + FillDb(); + using (ISession session = OpenSession()) + { + using (ITransaction tran = session.BeginTransaction()) + { + ICriteria crit = session.CreateCriteria(typeof (User)); + crit.AddOrder(Order.Desc("OrderStatus")); + crit.AddOrder(Order.Asc("Id")); + crit.SetMaxResults(10); + + IList<User> list = crit.List<User>(); + + Assert.That(list.Count, Is.EqualTo(2)); + Assert.That(list[0].OrderStatus, Is.EqualTo(2)); + Assert.That(list[1].OrderStatus, Is.EqualTo(1)); + + tran.Commit(); + } + } + Cleanup(); + } + } + + public class User + { + public virtual int Id { get; set; } + public virtual int OrderStatus { get; set; } + } + + public class Orders + { + public virtual int Id { get; set; } + public virtual bool Status { get; set; } + public virtual User User { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1694/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1694/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1694/Mappings.hbm.xml 2009-03-18 16:34:39 UTC (rev 4147) @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1694"> + + <class name="User" table="Users"> + <id name="Id"> + <generator class="native"/> + </id> + <property name="OrderStatus" + formula="CASE ISNULL((SELECT MIN(CONVERT(INTEGER,ISNULL(o.Status,0))) FROM dbo.Orders o WHERE o.userid=id),-1) WHEN -1 THEN 0 WHEN 0 THEN 1 ELSE 2 END" /> + </class> + + <class name="Orders"> + <id name="Id"> + <generator class="native"/> + </id> + <property name="Status" /> + <many-to-one name="User" class="User" column="UserID" /> + </class> + +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-18 15:54:41 UTC (rev 4146) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-18 16:34:39 UTC (rev 4147) @@ -292,6 +292,7 @@ <Compile Include="GenericTest\SetGeneric\SetGenericFixture.cs" /> <Compile Include="HQL\Animal.cs" /> <Compile Include="HQL\BaseFunctionFixture.cs" /> + <Compile Include="NHSpecificTest\NH1694\Fixture.cs" /> <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> <Compile Include="NHSpecificTest\NH1706\KeyPropertyRefFixture.cs" /> <Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" /> @@ -1684,6 +1685,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1694\Mappings.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1706\Mappings.hbm.xml" /> <EmbeddedResource Include="Stateless\Naturalness.hbm.xml" /> <EmbeddedResource Include="TransformTests\Simple.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-18 15:54:49
|
Revision: 4146 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4146&view=rev Author: fabiomaulo Date: 2009-03-18 15:54:41 +0000 (Wed, 18 Mar 2009) Log Message: ----------- Fix NH-1706 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Engine/EntityKey.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/Domain.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/KeyPropertyRefFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/Mappings.hbm.xml Removed Paths: ------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityKeyFixture.cs Modified: trunk/nhibernate/src/NHibernate/Engine/EntityKey.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Engine/EntityKey.cs 2009-03-18 13:41:14 UTC (rev 4145) +++ trunk/nhibernate/src/NHibernate/Engine/EntityKey.cs 2009-03-18 15:54:41 UTC (rev 4146) @@ -41,14 +41,6 @@ if (identifier == null) throw new AssertionFailure("null identifier"); - System.Type expected = identifier.GetType(); - System.Type found = identifierType.ReturnedClass; - if (!found.IsAssignableFrom(expected)) - { - throw new ArgumentException(string.Format("Identifier type mismatch; Found:<{0}> Expected:<{1}>", found, expected), - "identifier"); - } - this.identifier = identifier; this.rootEntityName = rootEntityName; this.entityName = entityName; @@ -76,7 +68,7 @@ public override bool Equals(object other) { - EntityKey otherKey = other as EntityKey; + var otherKey = other as EntityKey; if(otherKey==null) return false; return @@ -108,10 +100,10 @@ /// <summary> /// To use in deserialization callback /// </summary> - /// <param name="factory"></param> - internal void SetSessionFactory(ISessionFactoryImplementor factory) + /// <param name="sessionFactory"></param> + internal void SetSessionFactory(ISessionFactoryImplementor sessionFactory) { - this.factory = factory; + factory = sessionFactory; hashCode = GetHashCode(); } } Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityKeyFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityKeyFixture.cs 2009-03-18 13:41:14 UTC (rev 4145) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/EntityKeyFixture.cs 2009-03-18 15:54:41 UTC (rev 4146) @@ -1,499 +0,0 @@ -using System; -using System.Collections; -using NHibernate.Cache; -using NHibernate.Cache.Entry; -using NHibernate.Engine; -using NHibernate.Id; -using NHibernate.Metadata; -using NHibernate.Persister.Entity; -using NHibernate.Tuple.Entity; -using NHibernate.Type; -using NUnit.Framework; - -namespace NHibernate.Test.NHSpecificTest -{ - - public class TestingClassPersister : IEntityPersister - { - public IType IdentifierType - { - get { return NHibernateUtil.Int32; } - } - - // NOTE: - // IdentifierType is what we need for this test. - // other properties with a sort of implementation are : - // RootEntityName, EntityName, IsBatchLoadable, Factory - - #region IEntityPersister Members - - public ISessionFactoryImplementor Factory - { - get { return null; } - } - - public string RootEntityName - { - get { return null; } - } - - public string EntityName - { - get { return null; } - } - - public EntityMetamodel EntityMetamodel - { - get { throw new NotImplementedException(); } - } - - public string[] PropertySpaces - { - get { throw new NotImplementedException(); } - } - - public string[] QuerySpaces - { - get { throw new NotImplementedException(); } - } - - public bool IsMutable - { - get { throw new NotImplementedException(); } - } - - public bool IsInherited - { - get { throw new NotImplementedException(); } - } - - public bool IsIdentifierAssignedByInsert - { - get { throw new NotImplementedException(); } - } - - #region IOptimisticCacheSource Members - - public bool IsVersioned - { - get { throw new NotImplementedException(); } - } - - bool IEntityPersister.IsVersioned - { - get { throw new NotImplementedException(); } - } - - public IVersionType VersionType - { - get { throw new NotImplementedException(); } - } - - public int VersionProperty - { - get { throw new NotImplementedException(); } - } - - public int[] NaturalIdentifierProperties - { - get { throw new NotImplementedException(); } - } - - public IIdentifierGenerator IdentifierGenerator - { - get { throw new NotImplementedException(); } - } - - public IType[] PropertyTypes - { - get { throw new NotImplementedException(); } - } - - public string[] PropertyNames - { - get { throw new NotImplementedException(); } - } - - public bool[] PropertyInsertability - { - get { throw new NotImplementedException(); } - } - - public ValueInclusion[] PropertyInsertGenerationInclusions - { - get { throw new NotImplementedException(); } - } - - public ValueInclusion[] PropertyUpdateGenerationInclusions - { - get { throw new NotImplementedException(); } - } - - public bool[] PropertyCheckability - { - get { throw new NotImplementedException(); } - } - - public bool[] PropertyNullability - { - get { throw new NotImplementedException(); } - } - - public bool[] PropertyVersionability - { - get { throw new NotImplementedException(); } - } - - public bool[] PropertyLaziness - { - get { throw new NotImplementedException(); } - } - - public CascadeStyle[] PropertyCascadeStyles - { - get { throw new NotImplementedException(); } - } - - public string IdentifierPropertyName - { - get { throw new NotImplementedException(); } - } - - public bool IsCacheInvalidationRequired - { - get { throw new NotImplementedException(); } - } - - public bool IsLazyPropertiesCacheable - { - get { throw new NotImplementedException(); } - } - - public ICacheConcurrencyStrategy Cache - { - get { throw new NotImplementedException(); } - } - - public ICacheEntryStructure CacheEntryStructure - { - get { throw new NotImplementedException(); } - } - - public IClassMetadata ClassMetadata - { - get { throw new NotImplementedException(); } - } - - public bool IsBatchLoadable - { - get { return false; } - } - - public bool IsSelectBeforeUpdateRequired - { - get { throw new NotImplementedException(); } - } - - public bool IsVersionPropertyGenerated - { - get { throw new NotImplementedException(); } - } - - public void PostInstantiate() - { - throw new NotImplementedException(); - } - - public bool IsSubclassEntityName(string entityName) - { - throw new NotImplementedException(); - } - - public bool HasProxy - { - get { throw new NotImplementedException(); } - } - - public bool HasCollections - { - get { throw new NotImplementedException(); } - } - - public bool HasMutableProperties - { - get { throw new NotImplementedException(); } - } - - public bool HasSubselectLoadableCollections - { - get { throw new NotImplementedException(); } - } - - public bool HasCascades - { - get { throw new NotImplementedException(); } - } - - public IType GetPropertyType(string propertyName) - { - throw new NotImplementedException(); - } - - public int[] FindDirty(object[] currentState, object[] previousState, object entity, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public int[] FindModified(object[] old, object[] current, object entity, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public bool HasIdentifierProperty - { - get { throw new NotImplementedException(); } - } - - public bool CanExtractIdOutOfEntity - { - get { throw new NotImplementedException(); } - } - - public bool HasNaturalIdentifier - { - get { throw new NotImplementedException(); } - } - - public object[] GetNaturalIdentifierSnapshot(object id, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public bool HasLazyProperties - { - get { throw new NotImplementedException(); } - } - - public object Load(object id, object optionalObject, LockMode lockMode, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public void Lock(object id, object version, object obj, LockMode lockMode, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public void Insert(object id, object[] fields, object obj, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public object Insert(object[] fields, object obj, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public void Delete(object id, object version, object obj, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public void Update(object id, object[] fields, int[] dirtyFields, bool hasDirtyCollection, object[] oldFields, - object oldVersion, object obj, object rowId, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public bool[] PropertyUpdateability - { - get { throw new NotImplementedException(); } - } - - public bool HasCache - { - get { throw new NotImplementedException(); } - } - - public object[] GetDatabaseSnapshot(object id, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public object GetCurrentVersion(object id, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public object ForceVersionIncrement(object id, object currentVersion, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public EntityMode? GuessEntityMode(object obj) - { - throw new NotImplementedException(); - } - - public bool IsInstrumented(EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public bool HasInsertGeneratedProperties - { - get { throw new NotImplementedException(); } - } - - public bool HasUpdateGeneratedProperties - { - get { throw new NotImplementedException(); } - } - - public void AfterInitialize(object entity, bool lazyPropertiesAreUnfetched, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public void AfterReassociate(object entity, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public object CreateProxy(object id, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public bool? IsTransient(object obj, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public object[] GetPropertyValuesToInsert(object obj, IDictionary mergeMap, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public void ProcessInsertGeneratedProperties(object id, object entity, object[] state, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public void ProcessUpdateGeneratedProperties(object id, object entity, object[] state, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public System.Type GetMappedClass(EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public bool ImplementsLifecycle(EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public bool ImplementsValidatable(EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public System.Type GetConcreteProxyClass(EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public void SetPropertyValues(object obj, object[] values, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public void SetPropertyValue(object obj, int i, object value, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public object[] GetPropertyValues(object obj, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public object GetPropertyValue(object obj, int i, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public object GetPropertyValue(object obj, string name, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public object GetIdentifier(object obj, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public void SetIdentifier(object obj, object id, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public object GetVersion(object obj, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public object Instantiate(object id, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public bool IsInstance(object entity, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public bool HasUninitializedLazyProperties(object obj, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public void ResetIdentifier(object entity, object currentId, object currentVersion, EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public IEntityPersister GetSubclassEntityPersister(object instance, ISessionFactoryImplementor factory, - EntityMode entityMode) - { - throw new NotImplementedException(); - } - - public bool? IsUnsavedVersion(object version) - { - throw new NotImplementedException(); - } - - #endregion - - public IComparer VersionComparator - { - get { throw new NotImplementedException(); } - } - - #endregion - } - - [TestFixture] - public class EntityKeyFixture - { - [Test, ExpectedException(typeof(ArgumentException))] - public void CreateWithWrongTypeOfId() - { - IEntityPersister persister = new TestingClassPersister(); - EntityKey key = new EntityKey(1L, persister, EntityMode.Poco); - } - } -} Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/Domain.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/Domain.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/Domain.cs 2009-03-18 15:54:41 UTC (rev 4146) @@ -0,0 +1,28 @@ +using Iesi.Collections; + +namespace NHibernate.Test.NHSpecificTest.NH1706 +{ + public class A + { + public A() + { + Items = new HashedSet(); + } + public int Id { get; set; } + + public string ExtraIdA { get; set; } + + public string Name { get; set; } + + public virtual ISet Items { get; set; } + } + + public class B + { + public virtual int Id { get; set; } + + public virtual string Name { get; set; } + + public virtual string ExtraIdB { get; set; } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/KeyPropertyRefFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/KeyPropertyRefFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/KeyPropertyRefFixture.cs 2009-03-18 15:54:41 UTC (rev 4146) @@ -0,0 +1,42 @@ +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH1706 +{ + [TestFixture] + public class KeyPropertyRefFixture : BugTestCase + { + [Test] + public void PropertyRefUsesOtherColumn() + { + const string ExtraId = "extra"; + + var a = new A { Name = "First", ExtraIdA = ExtraId }; + + var b = new B { Name = "Second", ExtraIdB = ExtraId }; + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(a); + s.Save(b); + tx.Commit(); + } + + using (ISession s = OpenSession()) + { + var newA = s.Get<A>(a.Id); + + Assert.AreEqual(1, newA.Items.Count); + } + + // cleanup + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Delete("from B"); + s.Delete("from A"); + tx.Commit(); + } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/Mappings.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/Mappings.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1706/Mappings.hbm.xml 2009-03-18 15:54:41 UTC (rev 4146) @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.NHSpecificTest.NH1706"> + + <class name="A" lazy="false"> + <id name="Id"> + <generator class="native" /> + </id> + <property name="Name"/> + <property name="ExtraIdA"/> + <set name="Items" lazy="true"> + <key column="ExtraIdb" property-ref="ExtraIdA" /> + <one-to-many class="B" /> + </set> + </class> + + <class name="B"> + <id name="Id"> + <generator class="native" /> + </id> + <property name="Name"/> + <property name="ExtraIdB"/> + </class> +</hibernate-mapping> Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-18 13:41:14 UTC (rev 4145) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-18 15:54:41 UTC (rev 4146) @@ -292,6 +292,8 @@ <Compile Include="GenericTest\SetGeneric\SetGenericFixture.cs" /> <Compile Include="HQL\Animal.cs" /> <Compile Include="HQL\BaseFunctionFixture.cs" /> + <Compile Include="NHSpecificTest\NH1706\Domain.cs" /> + <Compile Include="NHSpecificTest\NH1706\KeyPropertyRefFixture.cs" /> <Compile Include="NHSpecificTest\NH645\HQLFunctionFixture.cs" /> <Compile Include="HQL\HQLFunctions.cs" /> <Compile Include="HQL\Human.cs" /> @@ -668,7 +670,6 @@ <Compile Include="NHSpecificTest\Docs\ExampleParentChild\UpdateFixture.cs" /> <Compile Include="NHSpecificTest\Docs\PersistentClasses\Cat.cs" /> <Compile Include="NHSpecificTest\EmptyMappingsFixture.cs" /> - <Compile Include="NHSpecificTest\EntityKeyFixture.cs" /> <Compile Include="NHSpecificTest\GetSetHelperFixture.cs" /> <Compile Include="NHSpecificTest\GetTest.cs" /> <Compile Include="NHSpecificTest\LazyLoadBugTest.cs" /> @@ -1683,6 +1684,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="NHSpecificTest\NH1706\Mappings.hbm.xml" /> <EmbeddedResource Include="Stateless\Naturalness.hbm.xml" /> <EmbeddedResource Include="TransformTests\Simple.hbm.xml" /> <EmbeddedResource Include="VersionTest\Db\MsSQL\ComplexVersioned.hbm.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Bambace A. <aci...@ye...> - 2009-03-18 15:02:56
|
Bigger thing, even moree pleasure http://cid-420e698b2790defb.spaces.live.com/blog/cns!420E698B2790DEFB!106.entry He is, after all, a man of very few words as to moved when public opinion moved, later still continued his former question, a faint voiceafter a tantalizing her, exclaiming, my poor dear, you are awfully frogsmade dish of marrow ibid. Made dish of rice. |
From: <fab...@us...> - 2009-03-18 14:22:41
|
Revision: 4144 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4144&view=rev Author: fabiomaulo Date: 2009-03-18 13:30:33 +0000 (Wed, 18 Mar 2009) Log Message: ----------- Test to study the StatelessSession behavior in "more complicated" scenario. Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/Stateless/Naturalness.cs trunk/nhibernate/src/NHibernate.Test/Stateless/Naturalness.hbm.xml trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessWithRelationsFixture.cs Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-17 19:16:01 UTC (rev 4143) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-03-18 13:30:33 UTC (rev 4144) @@ -948,6 +948,8 @@ <Compile Include="SqlTest\Custom\CustomStoredProcSupportTest.cs" /> <Compile Include="SqlTest\Custom\MySQL\MySQLTest.cs" /> <Compile Include="SqlTest\Custom\Oracle\OracleCustomSQLFixture.cs" /> + <Compile Include="Stateless\Naturalness.cs" /> + <Compile Include="Stateless\StatelessWithRelationsFixture.cs" /> <Compile Include="Tools\hbm2ddl\SchemaExportTests\WithColumnTag.cs" /> <Compile Include="Tools\hbm2ddl\SchemaExportTests\WithColumnTagFixture.cs" /> <Compile Include="Tools\hbm2ddl\SchemaUpdate\MigrationFixture.cs" /> @@ -1681,6 +1683,7 @@ <EmbeddedResource Include="Cascade\JobBatch.hbm.xml" /> <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> + <EmbeddedResource Include="Stateless\Naturalness.hbm.xml" /> <EmbeddedResource Include="TransformTests\Simple.hbm.xml" /> <EmbeddedResource Include="VersionTest\Db\MsSQL\ComplexVersioned.hbm.xml" /> <EmbeddedResource Include="Tools\hbm2ddl\SchemaExportTests\WithColumnTag.hbm.xml" /> Added: trunk/nhibernate/src/NHibernate.Test/Stateless/Naturalness.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Stateless/Naturalness.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Stateless/Naturalness.cs 2009-03-18 13:30:33 UTC (rev 4144) @@ -0,0 +1,37 @@ +using System; +using Iesi.Collections.Generic; + +namespace NHibernate.Test.Stateless +{ + public abstract class Animal + { + public virtual int Id { get; private set; } + public virtual string Description { get; set; } + } + + public class Reptile: Animal + { + public virtual float BodyTemperature { get; set; } + } + + public class Human : Animal + { + public virtual string Name { get; set; } + public virtual string NickName { get; set; } + public virtual DateTime Birthdate { get; set; } + } + + public class Family<T> where T: Animal + { + private ISet<T> childs; + + public virtual int Id { get; private set; } + public virtual T Father { get; set; } + public virtual T Mother { get; set; } + public virtual ISet<T> Childs + { + get { return childs; } + set { childs = value; } + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate.Test/Stateless/Naturalness.hbm.xml =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Stateless/Naturalness.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Stateless/Naturalness.hbm.xml 2009-03-18 13:30:33 UTC (rev 4144) @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + assembly="NHibernate.Test" + namespace="NHibernate.Test.Stateless" + default-access="backfield" + default-lazy="false"> + + <class name="Animal" abstract="true"> + <id name="Id"> + <generator class="hilo"/> + </id> + <discriminator column="kind"/> + <property name="Description"/> + + <subclass name="Reptile"> + <property name="BodyTemperature"/> + </subclass> + + <subclass name="Human"> + <property name="Name"/> + <property name="NickName"/> + <property name="Birthdate" type="Date"/> + </subclass> + </class> + + <class name="Family`1[[Reptile]]" entity-name="ReptilesFamily" + table="Families" discriminator-value="Reptile" where="familyKind = 'Reptile'"> + <id name="Id"> + <generator class="hilo"/> + </id> + <discriminator column="familyKind"/> + <many-to-one name="Father" class="Reptile" cascade="all"/> + <many-to-one name="Mother" class="Reptile" cascade="all"/> + <set name="Childs" cascade="all" access="property"> + <key column="familyId"/> + <one-to-many class="Reptile"/> + </set> + </class> + + <class name="Family`1[[Human]]" entity-name="HumanFamily" + table="Families" discriminator-value="Human" where="familyKind = 'Human'"> + <id name="Id"> + <generator class="hilo"/> + </id> + <discriminator column="familyKind"/> + <many-to-one name="Father" class="Human" cascade="all"/> + <many-to-one name="Mother" class="Human" cascade="all"/> + <set name="Childs" cascade="all" access="property"> + <key column="familyId"/> + <one-to-many class="Human"/> + </set> + </class> +</hibernate-mapping> Added: trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessWithRelationsFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessWithRelationsFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/Stateless/StatelessWithRelationsFixture.cs 2009-03-18 13:30:33 UTC (rev 4144) @@ -0,0 +1,91 @@ +using System.Collections; +using Iesi.Collections.Generic; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; +using System.Collections.Generic; + +namespace NHibernate.Test.Stateless +{ + [TestFixture] + public class StatelessWithRelationsFixture : TestCase + { + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override IList Mappings + { + get { return new[] { "Stateless.Naturalness.hbm.xml" }; } + } + + [Test] + public void ShouldWorkLoadingComplexEntities() + { + const string crocodileFather = "Crocodile father"; + const string crocodileMother = "Crocodile mother"; + + using (ISession s = sessions.OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + var rf = new Reptile { Description = crocodileFather }; + var rm = new Reptile { Description = crocodileMother }; + var rc1 = new Reptile { Description = "Crocodile" }; + var rc2 = new Reptile { Description = "Crocodile" }; + var rfamily = new Family<Reptile> + { + Father = rf, + Mother = rm, + Childs = new HashedSet<Reptile> { rc1, rc2 } + }; + s.Save("ReptilesFamily", rfamily); + tx.Commit(); + } + + const string humanFather = "Fred"; + const string humanMother = "Wilma"; + using (ISession s = sessions.OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + var hf = new Human { Description = "Flinstone", Name = humanFather }; + var hm = new Human { Description = "Flinstone", Name = humanMother }; + var hc1 = new Human { Description = "Flinstone", Name = "Pebbles" }; + var hfamily = new Family<Human> + { + Father = hf, + Mother = hm, + Childs = new HashedSet<Human> { hc1 } + }; + s.Save("HumanFamily", hfamily); + tx.Commit(); + } + + using (IStatelessSession s = sessions.OpenStatelessSession()) + using (ITransaction tx = s.BeginTransaction()) + { + IList<Family<Human>> hf = s.CreateQuery("from HumanFamily").List<Family<Human>>(); + Assert.That(hf.Count, Is.EqualTo(1)); + Assert.That(hf[0].Father.Name, Is.EqualTo(humanFather)); + Assert.That(hf[0].Mother.Name, Is.EqualTo(humanMother)); + Assert.That(hf[0].Childs, Is.Null, "Collections should be ignored by stateless session."); + + IList<Family<Reptile>> rf = s.CreateQuery("from ReptilesFamily").List<Family<Reptile>>(); + Assert.That(rf.Count, Is.EqualTo(1)); + Assert.That(rf[0].Father.Description, Is.EqualTo(crocodileFather)); + Assert.That(rf[0].Mother.Description, Is.EqualTo(crocodileMother)); + Assert.That(rf[0].Childs, Is.Null, "Collections should be ignored by stateless session."); + + tx.Commit(); + } + + using (ISession s = sessions.OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Delete("from HumanFamily"); + s.Delete("from ReptilesFamily"); + tx.Commit(); + } + } + + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2009-03-18 13:41:57
|
Revision: 4145 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4145&view=rev Author: fabiomaulo Date: 2009-03-18 13:41:14 +0000 (Wed, 18 Mar 2009) Log Message: ----------- Fix NH-1708 (Schema metadata for MsSQL ce) by Sushant Khurana Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/MsSqlCeDialect.cs trunk/nhibernate/src/NHibernate/NHibernate.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Dialect/Schema/MsSqlCeMetaData.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSqlCeDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSqlCeDialect.cs 2009-03-18 13:30:33 UTC (rev 4144) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSqlCeDialect.cs 2009-03-18 13:41:14 UTC (rev 4145) @@ -1,6 +1,6 @@ -using System; using System.Data; -using NHibernate.SqlCommand; +using System.Data.Common; +using NHibernate.Dialect.Schema; using Environment=NHibernate.Cfg.Environment; namespace NHibernate.Dialect @@ -92,5 +92,10 @@ { get { return false; } } + + public override IDataBaseSchema GetDataBaseSchema(DbConnection connection) + { + return new MsSqlCeDataBaseSchema(connection); + } } } \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Dialect/Schema/MsSqlCeMetaData.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/Schema/MsSqlCeMetaData.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Dialect/Schema/MsSqlCeMetaData.cs 2009-03-18 13:41:14 UTC (rev 4145) @@ -0,0 +1,96 @@ +using System; +using System.Data; +using System.Data.Common; + +namespace NHibernate.Dialect.Schema +{ + public class MsSqlCeDataBaseSchema: AbstractDataBaseSchema + { + public MsSqlCeDataBaseSchema(DbConnection connection) : base(connection) {} + + public override ITableMetadata GetTableMetadata(DataRow rs, bool extras) + { + return new MsSqlCeTableMetadata(rs, this, extras); + } + } + + public class MsSqlCeTableMetadata: AbstractTableMetadata + { + public MsSqlCeTableMetadata(DataRow rs, IDataBaseSchema meta, bool extras) : base(rs, meta, extras) { } + + protected override void ParseTableInfo(DataRow rs) + { + Catalog = Convert.ToString(rs["TABLE_CATALOG"]); + Schema = Convert.ToString(rs["TABLE_SCHEMA"]); + if (string.IsNullOrEmpty(Catalog)) Catalog = null; + if (string.IsNullOrEmpty(Schema)) Schema = null; + Name = Convert.ToString(rs["TABLE_NAME"]); + } + + protected override string GetConstraintName(DataRow rs) + { + return Convert.ToString(rs["CONSTRAINT_NAME"]); + } + + protected override string GetColumnName(DataRow rs) + { + return Convert.ToString(rs["COLUMN_NAME"]); + } + + protected override string GetIndexName(DataRow rs) + { + return Convert.ToString(rs["INDEX_NAME"]); + } + + protected override IColumnMetadata GetColumnMetadata(DataRow rs) + { + return new MsSqlCeColumnMetadata(rs); + } + + protected override IForeignKeyMetadata GetForeignKeyMetadata(DataRow rs) + { + return new MsSqlCeForeignKeyMetadata(rs); + } + + protected override IIndexMetadata GetIndexMetadata(DataRow rs) + { + return new MsSqlCeIndexMetadata(rs); + } + } + + public class MsSqlCeColumnMetadata : AbstractColumnMetaData + { + public MsSqlCeColumnMetadata(DataRow rs) : base(rs) + { + Name = Convert.ToString(rs["COLUMN_NAME"]); + + object aValue = rs["CHARACTER_MAXIMUM_LENGTH"]; + if (aValue != DBNull.Value) + ColumnSize = Convert.ToInt32(aValue); + + aValue = rs["NUMERIC_PRECISION"]; + if (aValue != DBNull.Value) + NumericalPrecision = Convert.ToInt32(aValue); + + Nullable = Convert.ToString(rs["IS_NULLABLE"]); + TypeName = Convert.ToString(rs["DATA_TYPE"]); + } + } + + public class MsSqlCeIndexMetadata: AbstractIndexMetadata + { + public MsSqlCeIndexMetadata(DataRow rs) : base(rs) + { + Name = Convert.ToString(rs["INDEX_NAME"]); + } + } + + public class MsSqlCeForeignKeyMetadata : AbstractForeignKeyMetadata + { + public MsSqlCeForeignKeyMetadata(DataRow rs) + : base(rs) + { + Name = Convert.ToString(rs["CONSTRAINT_NAME"]); + } + } +} Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-03-18 13:30:33 UTC (rev 4144) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-03-18 13:41:14 UTC (rev 4145) @@ -454,6 +454,7 @@ <Compile Include="Dialect\Oracle8iDialect.cs" /> <Compile Include="Dialect\Oracle9iDialect.cs" /> <Compile Include="Dialect\OracleLiteDialect.cs" /> + <Compile Include="Dialect\Schema\MsSqlCeMetaData.cs" /> <Compile Include="Dialect\Schema\MySQLMetaData.cs" /> <Compile Include="Dialect\Schema\SQLiteMetaData.cs" /> <Compile Include="Dialect\Schema\SybaseAnywhereMetaData.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |