|
From: <fab...@us...> - 2009-06-14 17:35:29
|
Revision: 4465
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4465&view=rev
Author: fabiomaulo
Date: 2009-06-14 17:35:23 +0000 (Sun, 14 Jun 2009)
Log Message:
-----------
- Refactoring SqlTypeFactory
- Added BinaryBlob to SqlTypeFactory
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/SqlTypes/BinaryBlobSqlType.cs
trunk/nhibernate/src/NHibernate/SqlTypes/SqlTypeFactory.cs
trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/SqlTest/SqlTypeFactoryFixture.cs
Modified: trunk/nhibernate/src/NHibernate/SqlTypes/BinaryBlobSqlType.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/SqlTypes/BinaryBlobSqlType.cs 2009-06-14 16:43:55 UTC (rev 4464)
+++ trunk/nhibernate/src/NHibernate/SqlTypes/BinaryBlobSqlType.cs 2009-06-14 17:35:23 UTC (rev 4465)
@@ -23,11 +23,7 @@
[Serializable]
public class BinaryBlobSqlType : BinarySqlType
{
- /// <summary>
- /// Initializes a new instance of the <see cref="BinaryBlobSqlType"/> class.
- /// </summary>
- public BinaryBlobSqlType() : base()
- {
- }
+ public BinaryBlobSqlType(int length) : base(length) {}
+ public BinaryBlobSqlType() {}
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/SqlTypes/SqlTypeFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/SqlTypes/SqlTypeFactory.cs 2009-06-14 16:43:55 UTC (rev 4464)
+++ trunk/nhibernate/src/NHibernate/SqlTypes/SqlTypeFactory.cs 2009-06-14 17:35:23 UTC (rev 4465)
@@ -52,6 +52,18 @@
return (T) result;
}
+ private static SqlType GetTypeWithPrecision(DbType dbType, byte precision, byte scale)
+ {
+ string key = GetKeyForPrecisionScaleBased(dbType.ToString(), precision, scale);
+ SqlType result;
+ if (!SqlTypes.TryGetValue(key, out result))
+ {
+ result = new SqlType(dbType, precision, scale);
+ SqlTypes.Add(key, result);
+ }
+ return result;
+ }
+
public static AnsiStringSqlType GetAnsiString(int length)
{
return GetTypeWithLen<AnsiStringSqlType>(length, l => new AnsiStringSqlType(l));
@@ -62,14 +74,19 @@
return GetTypeWithLen<BinarySqlType>(length, l => new BinarySqlType(l));
}
+ public static BinaryBlobSqlType GetBinaryBlob(int length)
+ {
+ return GetTypeWithLen<BinaryBlobSqlType>(length, l => new BinaryBlobSqlType(l));
+ }
+
public static StringSqlType GetString(int length)
{
return GetTypeWithLen<StringSqlType>(length, l => new StringSqlType(l));
}
- public static SqlType GetDecimal(byte precision, byte scale)
+ public static SqlType GetSqlType(DbType dbType, byte precision, byte scale)
{
- return new SqlType(DbType.Decimal, precision, scale);
+ return GetTypeWithPrecision(dbType, precision, scale);
}
private static string GetKeyForLengthBased(string name, int length)
Modified: trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-14 16:43:55 UTC (rev 4464)
+++ trunk/nhibernate/src/NHibernate/Type/TypeFactory.cs 2009-06-14 17:35:23 UTC (rev 4465)
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Data;
using System.Globalization;
using System.Reflection;
using NHibernate.Bytecode;
@@ -522,7 +523,7 @@
IType returnType;
if (!typeByTypeOfName.TryGetValue(key, out returnType))
{
- returnType = new DecimalType(SqlTypeFactory.GetDecimal(precision, scale));
+ returnType = new DecimalType(SqlTypeFactory.GetSqlType(DbType.Decimal, precision, scale));
AddToTypeOfNameWithPrecision(key, returnType);
}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-14 16:43:55 UTC (rev 4464)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-06-14 17:35:23 UTC (rev 4465)
@@ -1161,6 +1161,7 @@
<Compile Include="SqlTest\Custom\CustomStoredProcSupportTest.cs" />
<Compile Include="SqlTest\Custom\MySQL\MySQLTest.cs" />
<Compile Include="SqlTest\Custom\Oracle\OracleCustomSQLFixture.cs" />
+ <Compile Include="SqlTest\SqlTypeFactoryFixture.cs" />
<Compile Include="Stateless\Naturalness.cs" />
<Compile Include="Stateless\StatelessWithRelationsFixture.cs" />
<Compile Include="Tools\hbm2ddl\SchemaExportTests\WithColumnTag.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/SqlTest/SqlTypeFactoryFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/SqlTest/SqlTypeFactoryFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/SqlTest/SqlTypeFactoryFixture.cs 2009-06-14 17:35:23 UTC (rev 4465)
@@ -0,0 +1,20 @@
+using System.Data;
+using NHibernate.SqlTypes;
+using NUnit.Framework;
+
+namespace NHibernate.Test.SqlTest
+{
+ [TestFixture]
+ public class SqlTypeFactoryFixture
+ {
+ [Test]
+ [Description("Should cache constructed types")]
+ public void GetSqlTypeWithPrecisionScale()
+ {
+ var st = SqlTypeFactory.GetSqlType(DbType.Decimal, 10, 2);
+ Assert.That(st, Is.SameAs(SqlTypeFactory.GetSqlType(DbType.Decimal, 10, 2)));
+ Assert.That(st, Is.Not.SameAs(SqlTypeFactory.GetSqlType(DbType.Decimal, 10, 1)));
+ Assert.That(st, Is.Not.SameAs(SqlTypeFactory.GetSqlType(DbType.Double, 10, 2)));
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|