Author: gbayon
Date: Wed Oct 24 11:12:44 2007
New Revision: 587946
URL: http://svn.apache.org/viewvc?rev=587946&view=rev
Log:
- Refix IBATISNET-242
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml?rev=587946&r1=587945&r2=587946&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
Wed Oct 24 11:12:44 2007
@@ -308,7 +308,7 @@
<select id="GetNoAccountWithCache"
parameterClass="Integer"
-
resultMap="account-hashtable-result"
+
resultMap="account-result-nullable-email"
cacheModel="account-cache">
select *
from Accounts
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs?rev=587946&r1=587945&r2=587946&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
Wed Oct 24 11:12:44 2007
@@ -54,12 +54,30 @@
/// Cache error with QueryForObject<T>
/// </summary>
[Test]
- public void TestJIRA242()
+ public void TestJIRA242WithNoCache()
{
Account account =
sqlMap.QueryForObject<Account>("GetNoAccountWithCache", -99);
account = sqlMap.QueryForObject<Account>("GetNoAccountWithCache",
-99);
Assert.IsNull(account);
+ }
+
+ /// <summary>
+ /// Cache error with QueryForObject<T> with object in cache
+ /// </summary>
+ [Test]
+ public void TestJIRA242WithCache()
+ {
+ Account account1 =
sqlMap.QueryForObject<Account>("GetNoAccountWithCache", 1);
+ AssertAccount1(account1);
+ int firstId = HashCodeProvider.GetIdentityHashCode(account1);
+
+ Account account2 =
sqlMap.QueryForObject<Account>("GetNoAccountWithCache", 1);
+ AssertAccount1(account2);
+
+ int secondId = HashCodeProvider.GetIdentityHashCode(account2);
+
+ Assert.AreEqual(firstId, secondId);
}
/// <summary>
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs?rev=587946&r1=587945&r2=587946&view=diff
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
(original)
+++
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
Wed Oct 24 11:12:44 2007
@@ -410,9 +410,13 @@
CacheKey cacheKey = this.GetCacheKey(request);
cacheKey.Update("ExecuteQueryForObject");
- //obj = (T)this.Statement.CacheModel[cacheKey];
+ object cacheObjet = this.Statement.CacheModel[cacheKey];
// check if this query has alreay been run
- if (Statement.CacheModel[cacheKey] == CacheModel.NULL_OBJECT)
+ if (cacheObjet is T)
+ {
+ obj = (T)cacheObjet;
+ }
+ else if (cacheObjet == CacheModel.NULL_OBJECT)
{
// convert the marker object back into a null value
obj = default(T);