|
From: <dar...@us...> - 2009-02-06 13:23:11
|
Revision: 4056
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4056&view=rev
Author: darioquintana
Date: 2009-02-06 13:22:50 +0000 (Fri, 06 Feb 2009)
Log Message:
-----------
Breaking change NH-1657.
- Now type="TimeSpan" maps a TimeSpan (CLR) to a DbTime.Time (DbType)
- TimeType prepared to work with TimeSpan or DateTime, depends the dialect.
- Old TimeSpanType was moved to TimeSpanInt64Type (type="TimeSpanInt64")
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate/NHibernateUtil.cs
trunk/nhibernate/src/NHibernate/Type/TimeType.cs
trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Type/TimeSpanInt64Type.cs
trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs
trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanClass.cs
trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanClass.hbm.xml
trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64Class.cs
trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64Class.hbm.xml
trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64TypeFixture.cs
trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs
trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2009-02-05 23:34:48 UTC (rev 4055)
+++ trunk/nhibernate/src/NHibernate/Dialect/MsSql2008Dialect.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -10,7 +10,7 @@
RegisterColumnType(DbType.DateTime2, "DATETIME2");
RegisterColumnType(DbType.DateTimeOffset, "DATETIMEOFFSET");
RegisterColumnType(DbType.Date, "DATE");
- //RegisterColumnType(DbType.Time, "TIME");
+ RegisterColumnType(DbType.Time, "TIME");
RegisterFunction("current_timestamp", new NoArgSQLFunction("sysdatetime", NHibernateUtil.DateTime2, true));
RegisterFunction("current_timestamp_offset", new NoArgSQLFunction("sysdatetimeoffset", NHibernateUtil.DateTimeOffset, true));
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-02-05 23:34:48 UTC (rev 4055)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-02-06 13:22:50 UTC (rev 4056)
@@ -396,7 +396,7 @@
<Compile Include="Type\StringClobType.cs" />
<Compile Include="Type\StringType.cs" />
<Compile Include="Type\TicksType.cs" />
- <Compile Include="Type\TimeSpanType.cs" />
+ <Compile Include="Type\TimeSpanInt64Type.cs" />
<Compile Include="Type\TimestampType.cs" />
<Compile Include="Type\TimeType.cs" />
<Compile Include="Type\TrueFalseType.cs" />
@@ -1084,6 +1084,7 @@
<Compile Include="Type\AnsiCharType.cs" />
<Compile Include="Type\AnyType.cs" />
<Compile Include="Type\AbstractCharType.cs" />
+ <Compile Include="Type\TimeSpanType.cs" />
<Compile Include="Type\DateTime2Type.cs" />
<Compile Include="Type\ClassMetaType.cs" />
<Compile Include="Type\CollectionType.cs" />
Modified: trunk/nhibernate/src/NHibernate/NHibernateUtil.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernateUtil.cs 2009-02-05 23:34:48 UTC (rev 4055)
+++ trunk/nhibernate/src/NHibernate/NHibernateUtil.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -211,6 +211,11 @@
public static readonly NullableType TimeSpan = new TimeSpanType();
/// <summary>
+ /// NHibernate Ticks type
+ /// </summary>
+ public static readonly NullableType TimeSpanInt64 = new TimeSpanInt64Type();
+
+ /// <summary>
/// NHibernate Timestamp type
/// </summary>
public static readonly NullableType Timestamp = new TimestampType();
Copied: trunk/nhibernate/src/NHibernate/Type/TimeSpanInt64Type.cs (from rev 4049, trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate/Type/TimeSpanInt64Type.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Type/TimeSpanInt64Type.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -0,0 +1,119 @@
+using System;
+using System.Collections;
+using System.Data;
+using NHibernate.Engine;
+using NHibernate.SqlTypes;
+using System.Collections.Generic;
+
+namespace NHibernate.Type
+{
+ /// <summary>
+ /// Maps a <see cref="System.TimeSpan" /> Property to an <see cref="DbType.Int64" /> column
+ /// </summary>
+ [Serializable]
+ public class TimeSpanInt64Type : PrimitiveType, IVersionType, ILiteralType
+ {
+ /// <summary></summary>
+ internal TimeSpanInt64Type()
+ : base(SqlTypeFactory.Int64)
+ {
+ }
+
+ /// <summary></summary>
+ public override string Name
+ {
+ get { return "TimeSpanInt64"; }
+ }
+
+ public override object Get(IDataReader rs, int index)
+ {
+ try
+ {
+ return new TimeSpan(Convert.ToInt64(rs[index]));
+ }
+ catch (Exception ex)
+ {
+ throw new FormatException(string.Format("Input string '{0}' was not in the correct format.", rs[index]), ex);
+ }
+ }
+
+ public override object Get(IDataReader rs, string name)
+ {
+ try
+ {
+ return new TimeSpan(Convert.ToInt64(rs[name]));
+ }
+ catch (Exception ex)
+ {
+ throw new FormatException(string.Format("Input string '{0}' was not in the correct format.", rs[name]), ex);
+ }
+ }
+
+ /// <summary></summary>
+ public override System.Type ReturnedClass
+ {
+ get { return typeof(TimeSpan); }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="st"></param>
+ /// <param name="value"></param>
+ /// <param name="index"></param>
+ public override void Set(IDbCommand st, object value, int index)
+ {
+ ((IDataParameter)st.Parameters[index]).Value = ((TimeSpan)value).Ticks;
+ }
+
+ public override string ToString(object val)
+ {
+ return ((TimeSpan)val).Ticks.ToString();
+ }
+
+ #region IVersionType Members
+
+ public object Next(object current, ISessionImplementor session)
+ {
+ return Seed(session);
+ }
+
+ /// <summary></summary>
+ public virtual object Seed(ISessionImplementor session)
+ {
+ return new TimeSpan(DateTime.Now.Ticks);
+ }
+
+ public object StringToObject(string xml)
+ {
+ return TimeSpan.Parse(xml);
+ }
+
+ public IComparer Comparator
+ {
+ get { return Comparer<TimeSpan>.Default; }
+ }
+
+ #endregion
+
+ public override object FromStringValue(string xml)
+ {
+ return TimeSpan.Parse(xml);
+ }
+
+ public override System.Type PrimitiveClass
+ {
+ get { return typeof(TimeSpan); }
+ }
+
+ public override object DefaultValue
+ {
+ get { return TimeSpan.Zero; }
+ }
+
+ public override string ObjectToSQLString(object value, Dialect.Dialect dialect)
+ {
+ return '\'' + ((TimeSpan)value).Ticks.ToString() + '\'';
+ }
+ }
+}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs 2009-02-05 23:34:48 UTC (rev 4055)
+++ trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -1,119 +0,0 @@
-using System;
-using System.Collections;
-using System.Data;
-using NHibernate.Engine;
-using NHibernate.SqlTypes;
-using System.Collections.Generic;
-
-namespace NHibernate.Type
-{
- /// <summary>
- /// Maps a <see cref="System.TimeSpan" /> Property to an <see cref="DbType.Int64" /> column
- /// </summary>
- [Serializable]
- public class TimeSpanType : PrimitiveType, IVersionType, ILiteralType
- {
- /// <summary></summary>
- internal TimeSpanType()
- : base(SqlTypeFactory.Int64)
- {
- }
-
- /// <summary></summary>
- public override string Name
- {
- get { return "TimeSpan"; }
- }
-
- public override object Get(IDataReader rs, int index)
- {
- try
- {
- return new TimeSpan(Convert.ToInt64(rs[index]));
- }
- catch (Exception ex)
- {
- throw new FormatException(string.Format("Input string '{0}' was not in the correct format.", rs[index]), ex);
- }
- }
-
- public override object Get(IDataReader rs, string name)
- {
- try
- {
- return new TimeSpan(Convert.ToInt64(rs[name]));
- }
- catch (Exception ex)
- {
- throw new FormatException(string.Format("Input string '{0}' was not in the correct format.", rs[name]), ex);
- }
- }
-
- /// <summary></summary>
- public override System.Type ReturnedClass
- {
- get { return typeof(TimeSpan); }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="st"></param>
- /// <param name="value"></param>
- /// <param name="index"></param>
- public override void Set(IDbCommand st, object value, int index)
- {
- ((IDataParameter)st.Parameters[index]).Value = ((TimeSpan)value).Ticks;
- }
-
- public override string ToString(object val)
- {
- return ((TimeSpan)val).Ticks.ToString();
- }
-
- #region IVersionType Members
-
- public object Next(object current, ISessionImplementor session)
- {
- return Seed(session);
- }
-
- /// <summary></summary>
- public virtual object Seed(ISessionImplementor session)
- {
- return new TimeSpan(DateTime.Now.Ticks);
- }
-
- public object StringToObject(string xml)
- {
- return TimeSpan.Parse(xml);
- }
-
- public IComparer Comparator
- {
- get { return Comparer<TimeSpan>.Default; }
- }
-
- #endregion
-
- public override object FromStringValue(string xml)
- {
- return TimeSpan.Parse(xml);
- }
-
- public override System.Type PrimitiveClass
- {
- get { return typeof(TimeSpan); }
- }
-
- public override object DefaultValue
- {
- get { return TimeSpan.Zero; }
- }
-
- public override string ObjectToSQLString(object value, Dialect.Dialect dialect)
- {
- return '\'' + ((TimeSpan)value).Ticks.ToString() + '\'';
- }
- }
-}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Type/TimeSpanType.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -0,0 +1,114 @@
+using System;
+using System.Collections;
+using System.Data;
+using NHibernate.Engine;
+using NHibernate.SqlTypes;
+using System.Collections.Generic;
+
+namespace NHibernate.Type
+{
+ /// <summary>
+ /// Maps a <see cref="System.TimeSpan" /> Property to an <see cref="DbType.Time" /> column
+ /// </summary>
+ [Serializable]
+ public class TimeSpanType : PrimitiveType, IVersionType, ILiteralType
+ {
+ private static readonly DateTime BaseDateValue = new DateTime(1753, 01, 01);
+
+ internal TimeSpanType()
+ : base(SqlTypeFactory.Time)
+ {
+ }
+
+ public override string Name
+ {
+ get { return "TimeSpan"; }
+ }
+
+ public override object Get(IDataReader rs, int index)
+ {
+ try
+ {
+ return (TimeSpan)rs[index];
+ }
+ catch (Exception ex)
+ {
+ throw new FormatException(string.Format("Input string '{0}' was not in the correct format.", rs[index]), ex);
+ }
+ }
+
+ public override object Get(IDataReader rs, string name)
+ {
+ try
+ {
+ //DateTime time = (DateTime)rs[name];
+ //return new TimeSpan(Convert.ToInt64(time.Ticks));
+ return (TimeSpan)rs[name];
+ }
+ catch (Exception ex)
+ {
+ throw new FormatException(string.Format("Input string '{0}' was not in the correct format.", rs[name]), ex);
+ }
+ }
+
+ public override void Set(IDbCommand st, object value, int index)
+ {
+ DateTime date = BaseDateValue.AddTicks(((TimeSpan)value).Ticks);
+ ((IDataParameter) st.Parameters[index]).Value = date;
+ }
+
+ public override System.Type ReturnedClass
+ {
+ get { return typeof(TimeSpan); }
+ }
+
+ public override string ToString(object val)
+ {
+ return ((TimeSpan)val).Ticks.ToString();
+ }
+
+ #region IVersionType Members
+
+ public object Next(object current, ISessionImplementor session)
+ {
+ return Seed(session);
+ }
+
+ public virtual object Seed(ISessionImplementor session)
+ {
+ return new TimeSpan(DateTime.Now.Ticks);
+ }
+
+ public object StringToObject(string xml)
+ {
+ return TimeSpan.Parse(xml);
+ }
+
+ public IComparer Comparator
+ {
+ get { return Comparer<TimeSpan>.Default; }
+ }
+
+ #endregion
+
+ public override object FromStringValue(string xml)
+ {
+ return TimeSpan.Parse(xml);
+ }
+
+ public override System.Type PrimitiveClass
+ {
+ get { return typeof(TimeSpan); }
+ }
+
+ public override object DefaultValue
+ {
+ get { return TimeSpan.Zero; }
+ }
+
+ public override string ObjectToSQLString(object value, Dialect.Dialect dialect)
+ {
+ return '\'' + ((TimeSpan)value).Ticks.ToString() + '\'';
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Type/TimeType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Type/TimeType.cs 2009-02-05 23:34:48 UTC (rev 4055)
+++ trunk/nhibernate/src/NHibernate/Type/TimeType.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -14,7 +14,7 @@
/// using this Type indicates that you don't care about the Date portion of the DateTime.
/// </para>
/// <para>
- /// A more appropriate choice to store the duration/time is the <see cref="TimeSpanType"/>.
+ /// A more appropriate choice to store the duration/time is the <see cref="TimeSpanInt64Type"/>.
/// The underlying <see cref="DbType.Time"/> tends to be handled differently by different
/// DataProviders.
/// </para>
@@ -37,6 +37,12 @@
{
try
{
+ if(rs[index] is TimeSpan) //For those dialects where DbType.Time means TimeSpan.
+ {
+ TimeSpan time = (TimeSpan) rs[index];
+ return BaseDateValue.AddTicks(time.Ticks);
+ }
+
DateTime dbValue = Convert.ToDateTime(rs[index]);
return new DateTime(1753, 01, 01, dbValue.Hour, dbValue.Minute, dbValue.Second);
}
Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-02-05 23:34:48 UTC (rev 4055)
+++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -122,6 +122,7 @@
RegisterType(typeof(SByte), NHibernateUtil.SByte, null);
RegisterType(typeof(Single), NHibernateUtil.Single, "float");
RegisterType(typeof(String), NHibernateUtil.String, "string");
+ RegisterType(typeof(TimeSpan), NHibernateUtil.TimeSpanInt64,null);
RegisterType(typeof(TimeSpan), NHibernateUtil.TimeSpan, null);
RegisterType(typeof(System.Type), NHibernateUtil.Class, "class");
@@ -142,6 +143,7 @@
typeByTypeOfName[NHibernateUtil.TrueFalse.Name] = NHibernateUtil.TrueFalse;
typeByTypeOfName[NHibernateUtil.YesNo.Name] = NHibernateUtil.YesNo;
typeByTypeOfName[NHibernateUtil.Ticks.Name] = NHibernateUtil.Ticks;
+ typeByTypeOfName[NHibernateUtil.TimeSpanInt64.Name] = NHibernateUtil.TimeSpanInt64;
typeByTypeOfName[NHibernateUtil.TimeSpan.Name] = NHibernateUtil.TimeSpan;
// need to do add the key "Serializable" because the hbm files will have a
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-02-05 23:34:48 UTC (rev 4055)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-02-06 13:22:50 UTC (rev 4056)
@@ -1004,6 +1004,9 @@
<Compile Include="TypesTest\BooleanTypeFixture.cs" />
<Compile Include="TypesTest\ByteClass.cs" />
<Compile Include="TypesTest\ByteTypeFixture.cs" />
+ <Compile Include="TypesTest\TimeSpanClass.cs" />
+ <Compile Include="TypesTest\TimeSpanTypeFixture.cs" />
+ <Compile Include="TypesTest\TimeSpanInt64Class.cs" />
<Compile Include="TypesTest\Decima2lTypeFixture.cs" />
<Compile Include="TypesTest\DateTimeTypeFixture.cs" />
<Compile Include="TypesTest\DecimalClass.cs" />
@@ -1032,7 +1035,7 @@
<Compile Include="TypesTest\StringClobTypeFixture.cs" />
<Compile Include="TypesTest\StringTypeFixture.cs" />
<Compile Include="TypesTest\TicksTypeFixture.cs" />
- <Compile Include="TypesTest\TimeSpanTypeFixture.cs" />
+ <Compile Include="TypesTest\TimeSpanInt64TypeFixture.cs" />
<Compile Include="TypesTest\TimestampTypeFixture.cs" />
<Compile Include="TypesTest\TypeFactoryFixture.cs" />
<Compile Include="TypesTest\TypeFixtureBase.cs" />
@@ -1641,6 +1644,8 @@
<EmbeddedResource Include="Deletetransient\Person.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
<EmbeddedResource Include="NHSpecificTest\NH1289\Mappings.hbm.xml" />
+ <EmbeddedResource Include="TypesTest\TimeSpanClass.hbm.xml" />
+ <EmbeddedResource Include="TypesTest\TimeSpanInt64Class.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\FileStreamSql2008\Mappings.hbm.xml" />
<EmbeddedResource Include="Generatedkeys\Seqidentity\MyEntity.hbm.xml" />
<EmbeddedResource Include="IdGen\NativeGuid\NativeGuidPoid.hbm.xml" />
Added: trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanClass.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanClass.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanClass.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -0,0 +1,10 @@
+using System;
+
+namespace NHibernate.Test.TypesTest
+{
+ public class TimeSpanClass
+ {
+ public int Id { get; set; }
+ public TimeSpan TimeSpanValue { get; set; }
+ }
+}
\ No newline at end of file
Copied: trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanClass.hbm.xml (from rev 4049, trunk/nhibernate/src/NHibernate.Test/TypesTest/StringClobClass.hbm.xml)
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanClass.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanClass.hbm.xml 2009-02-06 13:22:50 UTC (rev 4056)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
+
+ <class name="NHibernate.Test.TypesTest.TimeSpanClass, NHibernate.Test">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="TimeSpanValue" type="TimeSpan" />
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64Class.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64Class.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64Class.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -0,0 +1,10 @@
+using System;
+
+namespace NHibernate.Test.TypesTest
+{
+ public class TimeSpanInt64Class
+ {
+ public int Id { get; set; }
+ public TimeSpan TimeSpanValue { get; set; }
+ }
+}
\ No newline at end of file
Copied: trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64Class.hbm.xml (from rev 4049, trunk/nhibernate/src/NHibernate.Test/TypesTest/StringClobClass.hbm.xml)
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64Class.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64Class.hbm.xml 2009-02-06 13:22:50 UTC (rev 4056)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
+
+ <class name="NHibernate.Test.TypesTest.TimeSpanInt64Class, NHibernate.Test">
+ <id name="Id">
+ <generator class="native" />
+ </id>
+ <property name="TimeSpanValue" type="TimeSpanInt64" />
+ </class>
+
+</hibernate-mapping>
Copied: trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64TypeFixture.cs (from rev 4049, trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs)
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64TypeFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanInt64TypeFixture.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -0,0 +1,75 @@
+using System;
+using NHibernate.Type;
+using NUnit.Framework;
+
+namespace NHibernate.Test.TypesTest
+{
+ /// <summary>
+ /// Summary description for TimeSpanTypeFixture.
+ /// </summary>
+ [TestFixture]
+ public class TimeSpanInt64TypeFixture
+ {
+ [Test]
+ public void Next()
+ {
+ var type = (TimeSpanInt64Type) NHibernateUtil.TimeSpanInt64;
+ object current = new TimeSpan(DateTime.Now.Ticks - 5);
+ object next = type.Next(current, null);
+
+ Assert.IsTrue(next is TimeSpan, "Next should be TimeSpan");
+ Assert.IsTrue((TimeSpan) next > (TimeSpan) current,
+ "next should be greater than current (could be equal depending on how quickly this occurs)");
+ }
+
+ [Test]
+ public void Seed()
+ {
+ var type = (TimeSpanInt64Type) NHibernateUtil.TimeSpanInt64;
+ Assert.IsTrue(type.Seed(null) is TimeSpan, "seed should be TimeSpan");
+ }
+ }
+
+ [TestFixture]
+ public class TimeSpanInt64Fixture2 : TypeFixtureBase
+ {
+ protected override string TypeName
+ {
+ get { return "TimeSpanInt64"; }
+ }
+
+ [Test]
+ public void SavingAndRetrieving()
+ {
+ var ticks = new TimeSpan(1982);
+
+ var entity = new TimeSpanInt64Class
+ {
+ TimeSpanValue = ticks
+ };
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Save(entity);
+ tx.Commit();
+ }
+
+ TimeSpanInt64Class entityReturned;
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ entityReturned = s.CreateQuery("from TimeSpanInt64Class").UniqueResult<TimeSpanInt64Class>();
+ Assert.AreEqual(ticks, entityReturned.TimeSpanValue);
+ }
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Delete(entityReturned);
+ tx.Commit();
+ }
+ }
+ }
+}
\ No newline at end of file
Deleted: trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs 2009-02-05 23:34:48 UTC (rev 4055)
+++ trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -1,32 +0,0 @@
-using System;
-using NHibernate.Type;
-using NUnit.Framework;
-
-namespace NHibernate.Test.TypesTest
-{
- /// <summary>
- /// Summary description for TimeSpanTypeFixture.
- /// </summary>
- [TestFixture]
- public class TimeSpanTypeFixture
- {
- [Test]
- public void Next()
- {
- TimeSpanType type = (TimeSpanType) NHibernateUtil.TimeSpan;
- object current = new TimeSpan(DateTime.Now.Ticks - 5);
- object next = type.Next(current, null);
-
- Assert.IsTrue(next is TimeSpan, "Next should be TimeSpan");
- Assert.IsTrue((TimeSpan) next > (TimeSpan) current,
- "next should be greater than current (could be equal depending on how quickly this occurs)");
- }
-
- [Test]
- public void Seed()
- {
- TimeSpanType type = (TimeSpanType) NHibernateUtil.TimeSpan;
- Assert.IsTrue(type.Seed(null) is TimeSpan, "seed should be TimeSpan");
- }
- }
-}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/TypesTest/TimeSpanTypeFixture.cs 2009-02-06 13:22:50 UTC (rev 4056)
@@ -0,0 +1,75 @@
+using System;
+using NHibernate.Type;
+using NUnit.Framework;
+
+namespace NHibernate.Test.TypesTest
+{
+ /// <summary>
+ /// Summary description for TimeSpanTypeFixture.
+ /// </summary>
+ [TestFixture]
+ public class TimeSpanTypeFixture
+ {
+ [Test]
+ public void Next()
+ {
+ var type = (TimeSpanType) NHibernateUtil.TimeSpan;
+ object current = new TimeSpan(DateTime.Now.Ticks - 5);
+ object next = type.Next(current, null);
+
+ Assert.IsTrue(next is TimeSpan, "Next should be TimeSpan");
+ Assert.IsTrue((TimeSpan) next > (TimeSpan) current,
+ "next should be greater than current (could be equal depending on how quickly this occurs)");
+ }
+
+ [Test]
+ public void Seed()
+ {
+ var type = (TimeSpanType) NHibernateUtil.TimeSpan;
+ Assert.IsTrue(type.Seed(null) is TimeSpan, "seed should be TimeSpan");
+ }
+ }
+
+ [TestFixture]
+ public class TimeSpanFixture2 : TypeFixtureBase
+ {
+ protected override string TypeName
+ {
+ get { return "TimeSpan"; }
+ }
+
+ [Test]
+ public void SavingAndRetrieving()
+ {
+ var ticks = DateTime.Parse("23:59:59").TimeOfDay;
+
+ var entity = new TimeSpanClass
+ {
+ TimeSpanValue = ticks
+ };
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Save(entity);
+ tx.Commit();
+ }
+
+ TimeSpanClass entityReturned;
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ entityReturned = s.CreateQuery("from TimeSpanClass").UniqueResult<TimeSpanClass>();
+ Assert.AreEqual(ticks, entityReturned.TimeSpanValue);
+ }
+
+ using (ISession s = OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Delete(entityReturned);
+ 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.
|