Author: gbayon
Date: Tue Mar 14 13:07:25 2006
New Revision: 385889
URL: http://svn.apache.org/viewcvs?rev=385889&view=rev
Log:
- Updated unit test for IpropertyAccessor
- Added factory for IpropertyAccessor object
Added:
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs (with
props)
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/PropertyAccessorFactory.cs
(with props)
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj
ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ReflectionPropertyAccessor.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Perf/PerformanceTest.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Account.cs Tue Mar 14
13:07:25 2006
@@ -16,62 +16,32 @@
public int Id
{
- get
- {
- return _id;
- }
- set
- {
- _id = value;
- }
+ get { return _id; }
+ set { _id = value; }
}
public string FirstName
{
- get
- {
- return _firstName;
- }
- set
- {
- _firstName = value;
- }
+ get { return _firstName; }
+ set { _firstName = value; }
}
public string LastName
{
- get
- {
- return _lastName;
- }
- set
- {
- _lastName = value;
- }
+ get { return _lastName; }
+ set { _lastName = value; }
}
public string EmailAddress
{
- get
- {
- return _emailAddress;
- }
- set
- {
- _emailAddress = value;
- }
+ get { return _emailAddress; }
+ set { _emailAddress = value; }
}
public int[] Ids
{
- get
- {
- return _ids;
- }
- set
- {
- _ids = value;
- }
+ get { return _ids; }
+ set { _ids = value; }
}
}
}
Added: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs?rev=385889&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs Tue Mar 14
13:07:25 2006
@@ -0,0 +1,118 @@
+using System;
+
+namespace IBatisNet.Common.Test.Domain
+{
+ /// <summary>
+ /// Summary description for Property.
+ /// </summary>
+ public class Property
+ {
+ private string _string = string.Empty;
+ private int _int = int.MinValue;
+ private DateTime _dateTime = DateTime.MinValue;
+ private decimal _decimal = decimal.MinValue;
+ private sbyte _sbyte = sbyte.MinValue;
+ private byte _byte = byte.MinValue;
+ private char _char = char.MinValue;
+ private short _short = short.MinValue;
+ private ushort _ushort = ushort.MinValue;
+ private uint _uint = uint.MinValue;
+ private long _long = long.MinValue;
+ private ulong _ulong = ulong.MinValue;
+ private bool _bool = false;
+ private double _double = double.MinValue;
+ private float _float = float.MinValue;
+
+ public string String
+ {
+ get { return _string; }
+ set { _string = value; }
+ }
+
+ public int Int
+ {
+ get { return _int; }
+ set { _int = value; }
+ }
+
+ public DateTime DateTime
+ {
+ get { return _dateTime; }
+ set { _dateTime = value; }
+ }
+
+ public decimal Decimal
+ {
+ get { return _decimal; }
+ set { _decimal = value; }
+ }
+
+ public sbyte SByte
+ {
+ get { return _sbyte; }
+ set { _sbyte = value; }
+ }
+
+ public byte Byte
+ {
+ get { return _byte; }
+ set { _byte = value; }
+ }
+
+ public char Char
+ {
+ get { return _char; }
+ set { _char = value; }
+ }
+
+ public short Short
+ {
+ get { return _short; }
+ set { _short = value; }
+ }
+
+ public ushort UShort
+ {
+ get { return _ushort; }
+ set { _ushort = value; }
+ }
+
+ public uint UInt
+ {
+ get { return _uint; }
+ set { _uint = value; }
+ }
+
+ public long Long
+ {
+ get { return _long; }
+ set { _long = value; }
+ }
+
+ public ulong ULong
+ {
+ get { return _ulong; }
+ set { _ulong = value; }
+ }
+
+ public bool Bool
+ {
+ get { return _bool; }
+ set { _bool = value; }
+ }
+
+ public double Double
+ {
+ get { return _double; }
+ set { _double = value; }
+ }
+
+ public float Float
+ {
+ get { return _float; }
+ set { _float = value; }
+ }
+
+
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj
Tue Mar 14 13:07:25 2006
@@ -103,6 +103,7 @@
<Compile Include="Domain\Account.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Domain\Property.cs" />
<Compile Include="Domain\Simple.cs" />
<Compile Include="NUnit\CommonTests\ConfigWatcher\ConfigWatcherTest.cs">
<SubType>Code</SubType>
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj
Tue Mar 14 13:07:25 2006
@@ -212,6 +212,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Domain\Property.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Domain\Simple.cs"
SubType = "Code"
BuildAction = "Compile"
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
Tue Mar 14 13:07:25 2006
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using IBatisNet.Common.Test.Domain;
+using IBatisNet.Common.Utilities;
using IBatisNet.Common.Utilities.Objects;
using NUnit.Framework;
@@ -30,6 +31,36 @@
#endregion
+ /// <summary>
+ /// Test PropertyAccessorFactory
+ /// </summary>
+ [Test]
+ public void TestPropertyAccessorFactory()
+ {
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor1 =
factory.CreatePropertyAccessor(typeof(Property), "Int");
+ IPropertyAccessor propertyAccessor2 =
factory.CreatePropertyAccessor(typeof(Property), "Int");
+
+
Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(propertyAccessor1),
HashCodeProvider.GetIdentityHashCode(propertyAccessor2) );
+ }
+
+ /// <summary>
+ /// Test multiple PropertyAccessorFactory
+ /// </summary>
+ [Test]
+ public void TestMultiplePropertyAccessorFactory()
+ {
+ Property prop = new Property();
+ PropertyAccessorFactory factory1 = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor1 =
factory1.CreatePropertyAccessor(typeof(Property), "Int");
+
+ PropertyAccessorFactory factory2 = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor2 =
factory2.CreatePropertyAccessor(typeof(Property), "Int");
+
+ Assert.AreEqual(int.MinValue,
propertyAccessor1.Get(prop));
+ Assert.AreEqual(int.MinValue,
propertyAccessor2.Get(prop));
+ }
+
/// <summary>
/// Test integer property access performance
/// </summary>
@@ -37,8 +68,8 @@
public void TestGetIntegerPerformance()
{
const int TEST_ITERATIONS = 1000000;
- Account account = new Account();
- int test = -1;
+ Property prop = new Property();
+ int test = -1;
Timer timer = new Timer();
#region Direct access (fastest)
@@ -49,8 +80,8 @@
for (int i = 0; i < TEST_ITERATIONS; i++)
{
test = -1;
- test = account.Id;
- Assert.AreEqual(0, test);
+ test = prop.Int;
+ Assert.AreEqual(int.MinValue, test);
}
timer.Stop();
double directAccessDuration = 1000000 * (timer.Duration
/ (double)TEST_ITERATIONS);
@@ -60,13 +91,14 @@
GC.Collect();
GC.WaitForPendingFinalizers();
- IPropertyAccessor propertyAccessor =
ILPropertyAccessor.CreatePropertyAccessor(typeof(Account), "Id");
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "Int");
timer.Start();
for (int i = 0; i < TEST_ITERATIONS; i++)
{
test = -1;
- test = (int)propertyAccessor.Get(account);
- Assert.AreEqual(0, test);
+ test = (int)propertyAccessor.Get(prop);
+ Assert.AreEqual(int.MinValue, test);
}
timer.Stop();
double propertyAccessorDuration = 1000000 *
(timer.Duration / (double)TEST_ITERATIONS);
@@ -77,14 +109,14 @@
GC.Collect();
GC.WaitForPendingFinalizers();
- ReflectionInfo reflectionInfo =
ReflectionInfo.GetInstance(account.GetType());
+ ReflectionInfo reflectionInfo =
ReflectionInfo.GetInstance(prop.GetType());
timer.Start();
for (int i = 0; i < TEST_ITERATIONS; i++)
{
test = -1;
- PropertyInfo propertyInfo =
reflectionInfo.GetGetter("Id");
- test = (int)propertyInfo.GetValue(account,
null);
- Assert.AreEqual(0, test);
+ PropertyInfo propertyInfo =
reflectionInfo.GetGetter("Int");
+ test = (int)propertyInfo.GetValue(prop, null);
+ Assert.AreEqual(int.MinValue, test);
}
timer.Stop();
double reflectionInfoDuration = 1000000 *
(timer.Duration / (double)TEST_ITERATIONS);
@@ -95,14 +127,14 @@
GC.Collect();
GC.WaitForPendingFinalizers();
- Type type = account.GetType();
+ Type type = prop.GetType();
timer.Start();
for (int i = 0; i < TEST_ITERATIONS; i++)
{
test = -1;
- PropertyInfo propertyInfo =
type.GetProperty("Id", BindingFlags.Public | BindingFlags.SetProperty |
BindingFlags.Instance);
- test = (int)propertyInfo.GetValue(account,
null);
- Assert.AreEqual(0, test);
+ PropertyInfo propertyInfo =
type.GetProperty("Int", BindingFlags.Public | BindingFlags.SetProperty |
BindingFlags.Instance);
+ test = (int)propertyInfo.GetValue(prop, null);
+ Assert.AreEqual(int.MinValue, test);
}
timer.Stop();
double reflectionDuration = 1000000 * (timer.Duration /
(double)TEST_ITERATIONS);
@@ -117,10 +149,10 @@
for (int i = 0; i < TEST_ITERATIONS; i++)
{
test = -1;
- test = (int)type.InvokeMember("Id",
+ test = (int)type.InvokeMember("Int",
BindingFlags.Public |
BindingFlags.GetProperty | BindingFlags.Instance,
- null, account, null);
- Assert.AreEqual(0, test);
+ null, prop, null);
+ Assert.AreEqual(int.MinValue, test);
}
timer.Stop();
double reflectionInvokeMemberDuration = 1000000 *
(timer.Duration / (double)TEST_ITERATIONS);
@@ -136,6 +168,7 @@
Console.WriteLine("Reflection: \t\t\t{0} Ratio: {1}",
reflectionDuration.ToString("F3"), reflectionRatio.ToString("F3"));
}
+
/// <summary>
/// Test the performance of getting an integer property.
/// </summary>
@@ -143,8 +176,8 @@
public void TestSetIntegerPerformance()
{
const int TEST_ITERATIONS = 1000000;
- Account account = new Account();
- int value = 123;
+ Property prop = new Property();
+ int value = 123;
Timer timer = new Timer();
#region Direct access (fastest)
@@ -154,7 +187,7 @@
timer.Start();
for (int i = 0; i < TEST_ITERATIONS; i++)
{
- account.Id = value;
+ prop.Int = value;
}
timer.Stop();
double directAccessDuration = 1000000 * (timer.Duration /
(double)TEST_ITERATIONS);
@@ -164,11 +197,12 @@
GC.Collect();
GC.WaitForPendingFinalizers();
- IPropertyAccessor propertyAccessor =
ILPropertyAccessor.CreatePropertyAccessor(typeof(Account), "Id");
- timer.Start();
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "Int");
+ timer.Start();
for (int i = 0; i < TEST_ITERATIONS; i++)
{
- propertyAccessor.Set(account, value);
+ propertyAccessor.Set(prop, value);
}
timer.Stop();
double propertyAccessorDuration = 1000000 * (timer.Duration /
(double)TEST_ITERATIONS);
@@ -179,13 +213,13 @@
GC.Collect();
GC.WaitForPendingFinalizers();
- Type type = account.GetType();
+ Type type = prop.GetType();
ReflectionInfo reflectionInfo =
ReflectionInfo.GetInstance(type);
timer.Start();
for (int i = 0; i < TEST_ITERATIONS; i++)
{
- PropertyInfo propertyInfo =
reflectionInfo.GetSetter("Id");
- propertyInfo.SetValue(account, value, null);
+ PropertyInfo propertyInfo =
reflectionInfo.GetSetter("Int");
+ propertyInfo.SetValue(prop, value, null);
}
timer.Stop();
double reflectionInfoDuration = 1000000 * (timer.Duration /
(double)TEST_ITERATIONS);
@@ -199,8 +233,8 @@
timer.Start();
for (int i = 0; i < TEST_ITERATIONS; i++)
{
- PropertyInfo propertyInfo =
type.GetProperty("Id", BindingFlags.Public | BindingFlags.SetProperty |
BindingFlags.Instance);
- propertyInfo.SetValue(account, value, null);
+ PropertyInfo propertyInfo =
type.GetProperty("Int", BindingFlags.Public | BindingFlags.SetProperty |
BindingFlags.Instance);
+ propertyInfo.SetValue(prop, value, null);
}
timer.Stop();
double reflectionDuration = 1000000 * (timer.Duration /
(double)TEST_ITERATIONS);
@@ -214,9 +248,9 @@
timer.Start();
for (int i = 0; i < TEST_ITERATIONS; i++)
{
- type.InvokeMember("Id",
+ type.InvokeMember("Int",
BindingFlags.Public | BindingFlags.SetProperty |
BindingFlags.Instance,
- null, account, new object[] { value });
+ null, prop, new object[] { value });
}
timer.Stop();
double reflectionInvokeMemberDuration = 1000000 * (timer.Duration
/ (double)TEST_ITERATIONS);
@@ -232,19 +266,153 @@
Console.WriteLine("Reflection: \t\t\t{0} Ratio: {1}",
reflectionDuration.ToString("F3"), reflectionRatio.ToString("F3"));
}
+
/// <summary>
/// Test the performance of getting an integer property.
/// </summary>
[Test]
public void TestSetNullOnIntegerProperty()
{
- Account account = new Account();
- account.Id = -99;
+ Property prop = new Property();
+ prop.Int = -99;
// Property accessor
- IPropertyAccessor propertyAccessor =
ILPropertyAccessor.CreatePropertyAccessor(typeof(Account), "Id");
- propertyAccessor.Set(account, null);
- Assert.IsTrue(account.Id == 0);
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "Int");
+ propertyAccessor.Set(prop, null);
+ Assert.AreEqual(0, prop.Int);
}
+
+ /// <summary>
+ /// Test setting an integer property.
+ /// </summary>
+ [Test]
+ public void TestSetInteger()
+ {
+ Property prop = new Property();
+ prop.Int = -99;
+
+ // Property accessor
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "Int");
+ int test = 57;
+ propertyAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Int);
+ }
+
+ /// <summary>
+ /// Test getting an integer property.
+ /// </summary>
+ [Test]
+ public void TestGetInteger()
+ {
+ int test = -99;
+ Property prop = new Property();
+ prop.Int = test;
+
+ // Property accessor
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "Int");
+ Assert.AreEqual(test, propertyAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test the performance of getting an Long property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnLongProperty()
+ {
+ Property prop = new Property();
+ prop.Long = 78945566664213223;
+
+ // Property accessor
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "Long");
+ propertyAccessor.Set(prop, null);
+ Assert.AreEqual((long)0, prop.Long);
+ }
+
+ /// <summary>
+ /// Test setting an Long property.
+ /// </summary>
+ [Test]
+ public void TestSetLong()
+ {
+ Property prop = new Property();
+ prop.Long = 78945566664213223;
+
+ // Property accessor
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "Long");
+ long test = 123456789987456;
+ propertyAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Long);
+ }
+
+ /// <summary>
+ /// Test getting an long property.
+ /// </summary>
+ [Test]
+ public void TestGetLong()
+ {
+ long test = 78945566664213223;
+ Property prop = new Property();
+ prop.Long = test;
+
+ // Property accessor
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "Long");
+ Assert.AreEqual(test, propertyAccessor.Get(prop));
+ }
+
+
+ /// <summary>
+ /// Test the performance of getting an sbyte property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnSbyteProperty()
+ {
+ Property prop = new Property();
+ prop.SByte = 78;
+
+ // Property accessor
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "SByte");
+ propertyAccessor.Set(prop, null);
+ Assert.AreEqual((sbyte)0, prop.SByte);
+ }
+
+ /// <summary>
+ /// Test setting an sbyte property.
+ /// </summary>
+ [Test]
+ public void TestSetSbyte()
+ {
+ Property prop = new Property();
+ prop.SByte = 78;
+
+ // Property accessor
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "SByte");
+ sbyte test = 19;
+ propertyAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.SByte);
+ }
+
+ /// <summary>
+ /// Test getting an sbyte property.
+ /// </summary>
+ [Test]
+ public void TestGetSbyte()
+ {
+ sbyte test = 78;
+ Property prop = new Property();
+ prop.SByte = test;
+
+ // Property accessor
+ PropertyAccessorFactory factory = new
PropertyAccessorFactory(true);
+ IPropertyAccessor propertyAccessor =
factory.CreatePropertyAccessor(typeof(Property), "SByte");
+ Assert.AreEqual(test, propertyAccessor.Get(prop));
+ }
}
}
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj Tue
Mar 14 13:07:25 2006
@@ -204,6 +204,7 @@
<Compile Include="Utilities\Objects\ObjectProbe.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Utilities\Objects\PropertyAccessorFactory.cs" />
<Compile Include="Utilities\Objects\ReflectionInfo.cs">
<SubType>Code</SubType>
</Compile>
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj Tue Mar 14
13:07:25 2006
@@ -350,6 +350,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Utilities\Objects\PropertyAccessorFactory.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Utilities\Objects\ReflectionInfo.cs"
SubType = "Code"
BuildAction = "Compile"
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/EmitObjectFactory.cs
Tue Mar 14 13:07:25 2006
@@ -38,7 +38,6 @@
private FactoryBuilder _factoryBuilder = null;
private object _padlock = new object();
-
/// <summary>
///
/// </summary>
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ILPropertyAccessor.cs
Tue Mar 14 13:07:25 2006
@@ -42,32 +42,34 @@
private string _propertyName = string.Empty;
private Type _propertyType = null;
private IPropertyAccessor _emittedPropertyAccessor = null;
- private static IDictionary _typeToOpcode = new HybridDictionary();
- private static AssemblyBuilder _assemblyBuilder = null;
- private static ModuleBuilder _moduleBuilder = null;
- private static IDictionary _cachedIPropertyAccessor = new
HybridDictionary();
+ private AssemblyBuilder _assemblyBuilder = null;
+ private ModuleBuilder _moduleBuilder = null;
+
+ private static IDictionary _typeToOpcode = new
HybridDictionary();
private static IDictionary _defaultValueType = new HybridDictionary();
/// <summary>
/// Static constructor
/// "Initialize a private hashtable with type-opCode pairs
- /// so we dont have to write a long if/else statement when outputting
msil"
/// </summary>
static ILPropertyAccessor()
{
- _defaultValueType[typeof(sbyte)] = 0;
- _defaultValueType[typeof(byte)] = 0;
- _defaultValueType[typeof(char)] = '\0';
- _defaultValueType[typeof(short)] = 0;
- _defaultValueType[typeof(ushort)] = 0;
- _defaultValueType[typeof(int)] = 0;
- _defaultValueType[typeof(uint)] = 0;
+ _defaultValueType[typeof(sbyte)] = (sbyte)0;
+ _defaultValueType[typeof(byte)] = (byte)0;
+ _defaultValueType[typeof(char)] = (char)'\0';
+ _defaultValueType[typeof(short)] = (short)0;
+ _defaultValueType[typeof(ushort)] = (ushort)0;
+ _defaultValueType[typeof(int)] = (int)0;
+ _defaultValueType[typeof(uint)] = (uint)0;
_defaultValueType[typeof(long)] = 0L;
_defaultValueType[typeof(ulong)] = 0L;
_defaultValueType[typeof(bool)] = false;
_defaultValueType[typeof(double)] = 0.0D;
_defaultValueType[typeof(float)] = 0.0F;
- // _defaultValueType[typeof(decimal)] = 0.0M;
+ _defaultValueType[typeof(decimal)] = 0.0M;
+// _defaultValueType[typeof(DateTime)] = 0.0M;
+// _defaultValueType[typeof(Guid)] = 0.0M;
+// _defaultValueType[typeof(TimeSpan)] = 0.0M;
_typeToOpcode[typeof(sbyte)] = OpCodes.Ldind_I1;
_typeToOpcode[typeof(byte)] = OpCodes.Ldind_U1;
@@ -81,48 +83,20 @@
_typeToOpcode[typeof(bool)] = OpCodes.Ldind_I1;
_typeToOpcode[typeof(double)] = OpCodes.Ldind_R8;
_typeToOpcode[typeof(float)] = OpCodes.Ldind_R4;
-
- AssemblyName assemblyName = new AssemblyName();
- assemblyName.Name = "iBATIS.FastPropertyAccessor";
-
- // Create a new assembly with one module
- _assemblyBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName,
AssemblyBuilderAccess.Run);
- _moduleBuilder =
_assemblyBuilder.DefineDynamicModule(assemblyName.Name + ".dll");
}
-
- /// <summary>
- /// Generate the IPropertyAccessor object
- /// </summary>
- /// <param name="targetType">Target object type.</param>
- /// <param name="propertyName">Property name.</param>
- /// <returns>null if the generation fail</returns>
- public static IPropertyAccessor CreatePropertyAccessor(Type
targetType, string propertyName)
- {
- string key = targetType.FullName+propertyName;
- lock (_assemblyBuilder)
- {
- if (_cachedIPropertyAccessor.Contains(key))
- {
- return (IPropertyAccessor)_cachedIPropertyAccessor[key];
- }
- else
- {
- IPropertyAccessor propertyAccessor = new
ILPropertyAccessor(targetType, propertyName);
- _cachedIPropertyAccessor[key] = propertyAccessor;
- return propertyAccessor;
- }
- }
- }
-
-
+
/// <summary>
/// Creates a new IL property accessor.
/// </summary>
/// <param name="targetType">Target object type.</param>
/// <param name="propertyName">Property name.</param>
- private ILPropertyAccessor(Type targetType, string propertyName)
+ /// <param name="assemblyBuilder"></param>
+ /// <param name="moduleBuilder"></param>
+ public ILPropertyAccessor(Type targetType, string propertyName,
AssemblyBuilder assemblyBuilder, ModuleBuilder moduleBuilder)
{
+ this._assemblyBuilder = assemblyBuilder;
+ this._moduleBuilder = moduleBuilder;
this._targetType = targetType;
this._propertyName = propertyName;
@@ -173,24 +147,6 @@
/// <summary>
- /// The Type of object this property accessor was
- /// created for.
- /// </summary>
- public Type TargetType
- {
- get { return this._targetType; }
- }
-
- /// <summary>
- /// The Type of the Property being accessed.
- /// </summary>
- public Type PropertyType
- {
- get { return this._propertyType; }
- }
-
-
- /// <summary>
/// This method generates creates a new assembly containing
/// the Type that will provide dynamic access.
/// </summary>
@@ -199,7 +155,7 @@
// Create the assembly and an instance of the property
accessor class.
EmitType();
- _emittedPropertyAccessor =
_assemblyBuilder.CreateInstance("PropertyAccessorFor" + _propertyName) as
IPropertyAccessor;
+ _emittedPropertyAccessor =
_assemblyBuilder.CreateInstance("PropertyAccessorFor" + _targetType.FullName +
_propertyName) as IPropertyAccessor;
if(_emittedPropertyAccessor == null)
{
@@ -212,8 +168,8 @@
/// </summary>
private void EmitType()
{
- // Define a public class named "Property" in the
assembly.
- TypeBuilder typeBuilder =
_moduleBuilder.DefineType("PropertyAccessorFor" + _propertyName,
TypeAttributes.Public);
+ // Define a public class named "Property..." in the
assembly.
+ TypeBuilder typeBuilder =
_moduleBuilder.DefineType("PropertyAccessorFor" + _targetType.FullName +
_propertyName, TypeAttributes.Public);
// Mark the class as implementing IPropertyAccessor.
typeBuilder.AddInterfaceImplementation(typeof(IPropertyAccessor));
@@ -261,11 +217,10 @@
// Define a method for the set operation.
Type[] setParamTypes = new Type[] {typeof(object),
typeof(object)};
- Type setReturnType = null;
MethodBuilder setMethod =
typeBuilder.DefineMethod("Set",
MethodAttributes.Public |
MethodAttributes.Virtual,
- setReturnType,
+ null,
setParamTypes);
// From the method, get an ILGenerator. This is used to
@@ -280,12 +235,10 @@
setIL.DeclareLocal(paramType);
setIL.Emit(OpCodes.Ldarg_1);
//Load the first argument
//(target object)
-
setIL.Emit(OpCodes.Castclass,
this._targetType); //Cast to the source type
setIL.Emit(OpCodes.Ldarg_2);
//Load the second argument
//(value object)
-
if(paramType.IsValueType)
{
setIL.Emit(OpCodes.Unbox, paramType);
//Unbox it
@@ -311,7 +264,6 @@
{
setIL.ThrowException(typeof(MissingMethodException));
}
-
setIL.Emit(OpCodes.Ret);
// Load the type
Added:
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/PropertyAccessorFactory.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/PropertyAccessorFactory.cs?rev=385889&view=auto
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/PropertyAccessorFactory.cs
(added)
+++
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/PropertyAccessorFactory.cs
Tue Mar 14 13:07:25 2006
@@ -0,0 +1,111 @@
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Reflection;
+using System.Reflection.Emit;
+
+namespace IBatisNet.Common.Utilities.Objects
+{
+ /// <summary>
+ /// Summary description for PropertyAccessorFactory.
+ /// </summary>
+ public class PropertyAccessorFactory
+ {
+ private IDictionary _cachedIPropertyAccessor = new
HybridDictionary();
+ private delegate IPropertyAccessor CreateIPropertyAccessor(Type
targetType, string propertyName);
+ private CreateIPropertyAccessor _createPropertyAccessor;
+ private AssemblyBuilder _assemblyBuilder = null;
+ private ModuleBuilder _moduleBuilder = null;
+ private object _padlock = new object();
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="allowCodeGeneration"></param>
+ public PropertyAccessorFactory(bool allowCodeGeneration)
+ {
+ if (allowCodeGeneration)
+ {
+ AssemblyName assemblyName = new AssemblyName();
+ assemblyName.Name =
"iBATIS.FastPropertyAccessor"+HashCodeProvider.GetIdentityHashCode(this).ToString();
+
+ // Create a new assembly with one module
+ _assemblyBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName,
AssemblyBuilderAccess.Run);
+ _moduleBuilder =
_assemblyBuilder.DefineDynamicModule(assemblyName.Name + ".dll");
+
+ // Detect runtime environment and create the
appropriate factory
+ if (Environment.Version.Major >= 2)
+ {
+ // To Do : a custom factory for .NET V2
+ // optimize with DynamicMethod or
Delegate.CreateDelegate
+ _createPropertyAccessor = new
CreateIPropertyAccessor(CreateILPropertyAccessor);
+
+ }
+ else
+ {
+ _createPropertyAccessor = new
CreateIPropertyAccessor(CreateILPropertyAccessor);
+ }
+ }
+ else
+ {
+ _createPropertyAccessor = new
CreateIPropertyAccessor(CreateReflectionPropertyAccessor);
+ }
+
+ }
+
+ /// <summary>
+ /// Generate an IPropertyAccessor object
+ /// </summary>
+ /// <param name="targetType">Target object type.</param>
+ /// <param name="propertyName">Property name.</param>
+ /// <returns>null if the generation fail</returns>
+ public IPropertyAccessor CreatePropertyAccessor(Type
targetType, string propertyName)
+ {
+ string key = targetType.FullName+propertyName;
+
+ if (_cachedIPropertyAccessor.Contains(key))
+ {
+ return
(IPropertyAccessor)_cachedIPropertyAccessor[key];
+ }
+ else
+ {
+ IPropertyAccessor propertyAccessor = null;
+ lock (_padlock)
+ {
+ if
(!_cachedIPropertyAccessor.Contains(key))
+ {
+ propertyAccessor =
_createPropertyAccessor(targetType, propertyName);
+ _cachedIPropertyAccessor[key] =
propertyAccessor;
+ }
+ else
+ {
+ propertyAccessor =
(IPropertyAccessor)_cachedIPropertyAccessor[key];
+ }
+ }
+ return propertyAccessor;
+ }
+ }
+
+ /// <summary>
+ /// Generate a ILPropertyAccessor object
+ /// </summary>
+ /// <param name="targetType">Target object type.</param>
+ /// <param name="propertyName">Property name.</param>
+ /// <returns>null if the generation fail</returns>
+ private IPropertyAccessor CreateILPropertyAccessor(Type
targetType, string propertyName)
+ {
+ return new ILPropertyAccessor(targetType,
propertyName, _assemblyBuilder, _moduleBuilder);
+ }
+
+ /// <summary>
+ /// Generate a ReflectionPropertyAccessor object
+ /// </summary>
+ /// <param name="targetType">Target object type.</param>
+ /// <param name="propertyName">Property name.</param>
+ /// <returns>null if the generation fail</returns>
+ private IPropertyAccessor CreateReflectionPropertyAccessor(Type
targetType, string propertyName)
+ {
+ return new ReflectionPropertyAccessor(targetType,
propertyName);
+ }
+ }
+}
Propchange:
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/PropertyAccessorFactory.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/PropertyAccessorFactory.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ReflectionPropertyAccessor.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ReflectionPropertyAccessor.cs?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ReflectionPropertyAccessor.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ReflectionPropertyAccessor.cs
Tue Mar 14 13:07:25 2006
@@ -34,6 +34,16 @@
/// </summary>
public class ReflectionPropertyAccessor : IPropertyAccessor
{
+
+ /// <summary>
+ /// Creates a new Reflection property accessor.
+ /// </summary>
+ /// <param name="targetType">Target object type.</param>
+ /// <param name="propertyName">Property name.</param>
+ public ReflectionPropertyAccessor(Type targetType, string
propertyName)
+ {
+ }
+
/// <summary>
/// Gets the value stored in the property for
/// the specified target.
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Perf/PerformanceTest.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Perf/PerformanceTest.cs?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Perf/PerformanceTest.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Perf/PerformanceTest.cs
Tue Mar 14 13:07:25 2006
@@ -375,6 +375,9 @@
double ibatis = 0;
double adonet = 0;
+ IDbConnection _connection =
sqlMap.DataSource.DbProvider.CreateConnection();
+ _connection.ConnectionString = sqlMap.DataSource.ConnectionString;
+
for (int n = 2; n < 4000; n *= 2)
{
Simple[] simples = new Simple[n];
@@ -390,8 +393,6 @@
Ibatis(simples, n, "h0");
sqlMap.CloseConnection();
- IDbConnection _connection =
sqlMap.DataSource.DbProvider.CreateConnection();
- _connection.ConnectionString =
sqlMap.DataSource.ConnectionString;
_connection.Open();
DirectAdoNet(_connection, simples, n, "j0");
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/providers.config
Tue Mar 14 13:07:25 2006
@@ -37,7 +37,7 @@
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
- allowPreparingCommands="true"
+ allowPreparingCommands="false"
parameterPrefix="@"
/>
<provider
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?rev=385889&r1=385888&r2=385889&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
Tue Mar 14 13:07:25 2006
@@ -651,7 +651,7 @@
Reset();
// To do, analyse config file to set allowCodeGeneration on object
factory
- _configScope.SqlMapper = new SqlMapper( new
ObjectFactory(false), new TypeHandlerFactory() );
+ _configScope.SqlMapper = new SqlMapper( new
ObjectFactory(true), new TypeHandlerFactory() );
#region Cache Alias