From: <dar...@us...> - 2009-02-04 22:55:07
|
Revision: 4046 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4046&view=rev Author: darioquintana Date: 2009-02-04 22:54:43 +0000 (Wed, 04 Feb 2009) Log Message: ----------- - Add DbType.Date support to MsSql2008Dialect. - Test for DbType.Time support (not implemented yet) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/AllDates.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeAssert.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeOffSetFixture.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateFixture.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/FixtureBase.cs trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/Date.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/Time.hbm.xml trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/TimeFixture.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DatesFixtureBase.cs Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2009-02-04 22:15:23 UTC (rev 4045) +++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2009-02-04 22:54:43 UTC (rev 4046) @@ -8,6 +8,8 @@ { RegisterColumnType(DbType.DateTime2, "DATETIME2"); RegisterColumnType(DbType.DateTimeOffset, "DATETIMEOFFSET"); + RegisterColumnType(DbType.Date, "DATE"); + //RegisterColumnType(DbType.Time, "TIME"); } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/AllDates.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/AllDates.cs 2009-02-04 22:15:23 UTC (rev 4045) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/AllDates.cs 2009-02-04 22:54:43 UTC (rev 4046) @@ -11,5 +11,9 @@ public DateTime Sql_datetime2 { get; set; } public DateTimeOffset Sql_datetimeoffset { get; set; } + + public TimeSpan Sql_time { get; set; } + + public DateTime Sql_date { get; set; } } } \ No newline at end of file Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateFixture.cs (from rev 4044, trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateFixture.cs 2009-02-04 22:54:43 UTC (rev 4046) @@ -0,0 +1,23 @@ +using System; +using System.Collections; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.Dates +{ + [TestFixture] + public class DateFixture : FixtureBase + { + protected override IList Mappings + { + get { return new[] {"NHSpecificTest.Dates.Mappings.Date.hbm.xml"}; } + } + + [Test] + public void SavingAndRetrievingTest() + { + DateTime Now = DateTime.Now; + SavingAndRetrievingAction(new AllDates {Sql_date = Now}, + entity => DateTimeAssert.AreEqual(entity.Sql_date, Now, true)); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs 2009-02-04 22:15:23 UTC (rev 4045) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs 2009-02-04 22:54:43 UTC (rev 4046) @@ -5,7 +5,7 @@ namespace NHibernate.Test.NHSpecificTest.Dates { [TestFixture] - public class DateTime2Fixture : DatesFixtureBase + public class DateTime2Fixture : FixtureBase { protected override IList Mappings { Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeAssert.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeAssert.cs 2009-02-04 22:15:23 UTC (rev 4045) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeAssert.cs 2009-02-04 22:54:43 UTC (rev 4046) @@ -4,6 +4,9 @@ namespace NHibernate.Test.NHSpecificTest.Dates { + /// <summary> + /// Useful assert to work with datetimes types. + /// </summary> public class DateTimeAssert { public static void AreEqual(DateTime dt1, DateTime dt2) @@ -11,9 +14,21 @@ bool areEqual = new DateTimeType().IsEqual(dt1, dt2); if (!areEqual) - Assert.Fail(string.Format("Expected {0} but was {1}",dt1,dt2)); + Assert.Fail(string.Format("Expected {0} but was {1}", dt1, dt2)); } + public static void AreEqual(DateTime dt1, DateTime dt2, bool OnlyDatePart) + { + if (!OnlyDatePart) + throw new NotSupportedException(); + + bool areEqual = DatePartAreEqual(dt1, dt2); + + if (!areEqual) + Assert.Fail(string.Format("Expected {0} but was {1}", dt1, dt2)); + } + + public static void AreEqual(DateTimeOffset dt1, DateTimeOffset dt2) { bool areEqual = new DateTimeOffsetType().IsEqual(dt1, dt2); @@ -21,5 +36,27 @@ if (!areEqual) Assert.Fail(string.Format("Expected {0} but was {1}", dt1, dt2)); } + + /// <summary> + /// Compare only the date part. + /// </summary> + /// <returns>true if are equal, false otherwise</returns> + private static bool DatePartAreEqual(DateTime x, DateTime y) + { + if (x == y) + { + return true; + } + + DateTime date1 = x; + DateTime date2 = y; + + if (date1.Equals(date2)) + return true; + + return (date1.Year == date2.Year && + date1.Month == date2.Month && + date1.Day == date2.Day); + } } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeOffSetFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeOffSetFixture.cs 2009-02-04 22:15:23 UTC (rev 4045) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTimeOffSetFixture.cs 2009-02-04 22:54:43 UTC (rev 4046) @@ -5,7 +5,7 @@ namespace NHibernate.Test.NHSpecificTest.Dates { [TestFixture] - public class DateTimeOffSetFixture : DatesFixtureBase + public class DateTimeOffSetFixture : FixtureBase { protected override IList Mappings { Deleted: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DatesFixtureBase.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DatesFixtureBase.cs 2009-02-04 22:15:23 UTC (rev 4045) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DatesFixtureBase.cs 2009-02-04 22:54:43 UTC (rev 4046) @@ -1,51 +0,0 @@ -using System; -using System.Collections; -using NHibernate.Dialect; -using NUnit.Framework; - -namespace NHibernate.Test.NHSpecificTest.Dates -{ - [TestFixture] - public abstract class DatesFixtureBase : TestCase - { - protected abstract override IList Mappings { get; } - - protected override string MappingsAssembly - { - get { return "NHibernate.Test"; } - } - - protected override bool AppliesTo(Dialect.Dialect dialect) - { - return dialect is MsSql2008Dialect; - } - - protected void SavingAndRetrievingAction(AllDates entity, Action<AllDates> action) - { - AllDates dates = entity; - - using (ISession s = OpenSession()) - using (ITransaction tx = s.BeginTransaction()) - { - s.Save(dates); - tx.Commit(); - } - - using (ISession s = OpenSession()) - using (ITransaction tx = s.BeginTransaction()) - { - var datesRecovered = s.CreateQuery("from AllDates").UniqueResult<AllDates>(); - - action.Invoke(datesRecovered); - } - - using (ISession s = OpenSession()) - using (ITransaction tx = s.BeginTransaction()) - { - var datesRecovered = s.CreateQuery("from AllDates").UniqueResult<AllDates>(); - s.Delete(datesRecovered); - tx.Commit(); - } - } - } -} \ No newline at end of file Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/FixtureBase.cs (from rev 4044, trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DatesFixtureBase.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/FixtureBase.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/FixtureBase.cs 2009-02-04 22:54:43 UTC (rev 4046) @@ -0,0 +1,51 @@ +using System; +using System.Collections; +using NHibernate.Dialect; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.Dates +{ + [TestFixture] + public abstract class FixtureBase : TestCase + { + protected abstract override IList Mappings { get; } + + protected override string MappingsAssembly + { + get { return "NHibernate.Test"; } + } + + protected override bool AppliesTo(Dialect.Dialect dialect) + { + return dialect is MsSql2008Dialect; + } + + protected void SavingAndRetrievingAction(AllDates entity, Action<AllDates> action) + { + AllDates dates = entity; + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + s.Save(dates); + tx.Commit(); + } + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + var datesRecovered = s.CreateQuery("from AllDates").UniqueResult<AllDates>(); + + action.Invoke(datesRecovered); + } + + using (ISession s = OpenSession()) + using (ITransaction tx = s.BeginTransaction()) + { + var datesRecovered = s.CreateQuery("from AllDates").UniqueResult<AllDates>(); + s.Delete(datesRecovered); + tx.Commit(); + } + } + } +} \ No newline at end of file Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/Date.hbm.xml (from rev 4044, trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/DateTime2.hbm.xml) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/Date.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/Date.hbm.xml 2009-02-04 22:54:43 UTC (rev 4046) @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.Dates" + assembly="NHibernate.Test"> + + <class name="AllDates" lazy="false"> + + <id name="Id"> + <generator class="native"/> + </id> + + <property name="Sql_date" type="date" /> + + </class> + +</hibernate-mapping> Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/Time.hbm.xml (from rev 4044, trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/DateTimeOffset.hbm.xml) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/Time.hbm.xml (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/Mappings/Time.hbm.xml 2009-02-04 22:54:43 UTC (rev 4046) @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8" ?> +<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" + namespace="NHibernate.Test.NHSpecificTest.Dates" + assembly="NHibernate.Test"> + + <class name="AllDates" lazy="false"> + + <id name="Id"> + <generator class="native"/> + </id> + + <property name="Sql_time" type="time" /> + + </class> + +</hibernate-mapping> Copied: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/TimeFixture.cs (from rev 4044, trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/DateTime2Fixture.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/TimeFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/Dates/TimeFixture.cs 2009-02-04 22:54:43 UTC (rev 4046) @@ -0,0 +1,23 @@ +using System; +using System.Collections; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.Dates +{ + [TestFixture] + public class TimeFixture : FixtureBase + { + protected override IList Mappings + { + get { return new[] {"NHSpecificTest.Dates.Mappings.Time.hbm.xml"}; } + } + + [Test,Ignore] + public void SavingAndRetrievingTest() + { + TimeSpan Now = TimeSpan.MaxValue; + SavingAndRetrievingAction(new AllDates {Sql_time = Now}, + entity => Assert.AreEqual(entity.Sql_time, Now)); + } + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-02-04 22:15:23 UTC (rev 4045) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-02-04 22:54:43 UTC (rev 4046) @@ -383,7 +383,9 @@ <Compile Include="NHSpecificTest\BasicTimeFixture.cs" /> <Compile Include="NHSpecificTest\BugTestCase.cs" /> <Compile Include="NHSpecificTest\CollectionFixture.cs" /> - <Compile Include="NHSpecificTest\Dates\DatesFixtureBase.cs" /> + <Compile Include="NHSpecificTest\Dates\TimeFixture.cs" /> + <Compile Include="NHSpecificTest\Dates\DateFixture.cs" /> + <Compile Include="NHSpecificTest\Dates\FixtureBase.cs" /> <Compile Include="NHSpecificTest\Dates\DateTime2Fixture.cs" /> <Compile Include="NHSpecificTest\Dates\DateTimeAssert.cs" /> <Compile Include="NHSpecificTest\Futures\FutureQueryFixture.cs" /> @@ -1626,6 +1628,8 @@ <EmbeddedResource Include="Deletetransient\Person.hbm.xml" /> <Content Include="DynamicEntity\package.html" /> <EmbeddedResource Include="IdGen\NativeGuid\NativeGuidPoid.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\Dates\Mappings\Time.hbm.xml" /> + <EmbeddedResource Include="NHSpecificTest\Dates\Mappings\Date.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\Dates\Mappings\DateTimeOffset.hbm.xml" /> <EmbeddedResource Include="NHSpecificTest\NH1654\Mappings.hbm.xml" /> <EmbeddedResource Include="Pagination\DataPoint.hbm.xml" /> @@ -1746,4 +1750,4 @@ if exist "$(ProjectDir)hibernate.cfg.xml" (copy "$(ProjectDir)hibernate.cfg.xml" "hibernate.cfg.xml") copy /y "..\..\..\NHibernate.DomainModel\ABC.hbm.xml" "ABC.hbm.xml"</PostBuildEvent> </PropertyGroup> -</Project> \ No newline at end of file +</Project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |