ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gba...@apache.org
Subject svn commit: r378778 - in /ibatis/trunk/cs/mapper: IBatisNet.DataMapper.Test/ IBatisNet.DataMapper.Test/Domain/ IBatisNet.DataMapper.Test/Maps/Access/OleDb/ IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/ IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/ IBatisNet...
Date Sat, 18 Feb 2006 21:18:12 GMT
Author: gbayon
Date: Sat Feb 18 13:18:09 2006
New Revision: 378778

URL: http://svn.apache.org/viewcvs?rev=378778&view=rev
Log:
- Added support for readOnly & serialize attribut on CacheModel (à la Java)

Added:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/CacheModelTest.cs
Modified:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/LineItem.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Order.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Access/OleDb/Account.xml
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Account.xml
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/Account.xml
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/ByteFx/Account.xml
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/MySql/Account.xml
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/ODP/Account.xml
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/OracleClient/Account.xml
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheModel.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs Sat Feb 18 13:18:09
2006
@@ -5,6 +5,7 @@
 	/// <summary>
 	/// Description résumée de Account.
 	/// </summary>
+	[Serializable]
 	public class Account
 	{
 		private int _id;

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/LineItem.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/LineItem.cs?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/LineItem.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/LineItem.cs Sat Feb 18 13:18:09
2006
@@ -8,6 +8,7 @@
 	/// <summary>
 	/// Description résumée de LineItem.
 	/// </summary>
+	[Serializable]
 	public class LineItem
 	{
 		private int _id;

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Order.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Order.cs?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Order.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Order.cs Sat Feb 18 13:18:09 2006
@@ -9,6 +9,7 @@
 	/// <summary>
 	/// Description résumée de Order.
 	/// </summary>
+	[Serializable]
 	public class Order
 	{
 		private int _id;

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj Sat
Feb 18 13:18:09 2006
@@ -767,6 +767,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "NUnit\SqlMapTests\CacheController\CacheModelTest.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "NUnit\SqlMapTests\CacheController\FifoCacheControllerTest.cs"
                     SubType = "Code"
                     BuildAction = "Compile"

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Access/OleDb/Account.xml
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Access/OleDb/Account.xml?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Access/OleDb/Account.xml (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Access/OleDb/Account.xml Sat Feb
18 13:18:09 2006
@@ -11,12 +11,10 @@
 			<property name="Type" value="Weak"/>
 		</cacheModel>
 		
-		<!-- <cacheModel name="account-cache" implementation="LRU" >
+		<cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
 			<flushInterval hours="24"/>
 			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
-			<flushOnExecute statement="UpdateAccountViaParameterMap"/>
-			<property name="CacheSize" value="50"/>
-		</cacheModel> -->
+		</cacheModel>
 		
     </cacheModels>
        
@@ -102,8 +100,13 @@
 			from Accounts
 			order by Account_ID
 		</select>
-		
-  	<select id="SelectWithProperty"
+
+		<select id="GetRWCachedAccountsViaResultMap"
+				resultMap="account-result"
+				cacheModel="rw-account-cache" extends="GetCachedAccountsViaResultMap">
+		</select>
+				
+  		<select id="SelectWithProperty"
 					resultMap="account-result">
 			select *
 			from Accounts

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Account.xml
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Account.xml?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Account.xml (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Account.xml Sat Feb 18
13:18:09 2006
@@ -11,12 +11,10 @@
 			<property name="Type" value="Weak"/>
 		</cacheModel>
 		
-		<!-- <cacheModel id="account-cache" implementation="LRU" >
+		<cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
 			<flushInterval hours="24"/>
 			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
-			<flushOnExecute statement="UpdateAccountViaParameterMap"/>
-			<property id="CacheSize" value="50"/>
-		</cacheModel> -->
+		</cacheModel>
 		
     </cacheModels>
        
@@ -107,6 +105,11 @@
 			select *
 			from Accounts
 			order by Account_ID
+		</select>
+  
+  		<select id="GetRWCachedAccountsViaResultMap"
+				resultMap="account-result"
+				cacheModel="rw-account-cache" extends="GetCachedAccountsViaResultMap">
 		</select>
   
     	<select id="GetNoAccountWithCache"

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/Account.xml
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/Account.xml?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/Account.xml (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/Account.xml Sat Feb
18 13:18:09 2006
@@ -11,12 +11,10 @@
 			<property name="Type" value="Weak"/>
 		</cacheModel>
 		
-		<!-- <cacheModel name="account-cache" implementation="LRU" >
+		<cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
 			<flushInterval hours="24"/>
 			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
-			<flushOnExecute statement="UpdateAccountViaParameterMap"/>
-			<property name="CacheSize" value="50"/>
-		</cacheModel> -->
+		</cacheModel>
 		
     </cacheModels>
  
@@ -116,6 +114,11 @@
 			order by Account_ID
 		</select>
 
+		<select id="GetRWCachedAccountsViaResultMap"
+				resultMap="account-result"
+				cacheModel="rw-account-cache" extends="GetCachedAccountsViaResultMap">
+		</select>
+		
   		<select id="GetNoAccountWithCache"
 						parameterClass="Integer"
 						resultMap="account-hashtable-result"

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml?rev=378778&r1=378777&r2=378778&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 Sat
Feb 18 13:18:09 2006
@@ -57,6 +57,11 @@
 			<property name="Type" value="Weak"/>
 		</cacheModel>
 		
+		<cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
+			<flushInterval hours="24"/>
+			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
+		</cacheModel>
+  
 		<!-- <cacheModel name="account-cache" implementation="LRU" >
 			<flushInterval hours="24"/>
 			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
@@ -135,6 +140,11 @@
 			select *
 			from Accounts
 			order by Account_ID
+		</select>
+  
+		<select id="GetRWCachedAccountsViaResultMap"
+				resultMap="account-result"
+				cacheModel="rw-account-cache" extends="GetCachedAccountsViaResultMap">
 		</select>
   
   		<select id="GetNoAccountWithCache"

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/ByteFx/Account.xml
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/ByteFx/Account.xml?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/ByteFx/Account.xml (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/ByteFx/Account.xml Sat Feb
18 13:18:09 2006
@@ -54,14 +54,10 @@
 			<property name="Type" value="Weak"/>
 		</cacheModel>
 		
-		<!-- 
-		<cacheModel name="account-cache" implementation="LRU" >
+		<cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
 			<flushInterval hours="24"/>
 			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
-			<flushOnExecute statement="UpdateAccountViaParameterMap"/>
-			<property name="CacheSize" value="50"/>
-		</cacheModel> 
-		-->
+		</cacheModel>
 		
     </cacheModels>
        
@@ -162,6 +158,11 @@
 			order by Account_ID
 		</select>
 
+		<select id="GetRWCachedAccountsViaResultMap"
+				resultMap="account-result"
+				cacheModel="rw-account-cache" extends="GetCachedAccountsViaResultMap">
+		</select>
+		
     	<select id="GetNoAccountWithCache"
 						parameterClass="Integer"
 						resultMap="account-hashtable-result"

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/MySql/Account.xml
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/MySql/Account.xml?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/MySql/Account.xml (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MySql/MySql/Account.xml Sat Feb
18 13:18:09 2006
@@ -54,14 +54,10 @@
 			<property name="Type" value="Weak"/>
 		</cacheModel>
 		
-		<!--
-		<cacheModel name="account-cache" implementation="LRU" >
+		<cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
 			<flushInterval hours="24"/>
 			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
-			<flushOnExecute statement="UpdateAccountViaParameterMap"/>
-			<property name="CacheSize" value="50"/>
 		</cacheModel>
-		-->
 		
     </cacheModels>
        
@@ -161,7 +157,12 @@
 			from Accounts
 			order by Account_ID
 		</select>
-
+		
+		<select id="GetRWCachedAccountsViaResultMap"
+				resultMap="account-result"
+				cacheModel="rw-account-cache" extends="GetCachedAccountsViaResultMap">
+		</select>
+		
     	<select id="GetNoAccountWithCache"
 						parameterClass="Integer"
 						resultMap="account-hashtable-result"

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/ODP/Account.xml
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/ODP/Account.xml?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/ODP/Account.xml (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/ODP/Account.xml Sat Feb 18
13:18:09 2006
@@ -55,14 +55,10 @@
 			<property name="Type" value="Weak"/>
 		</cacheModel>
 		
-		<!--
-		<cacheModel name="account-cache" implementation="LRU" >
+		<cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
 			<flushInterval hours="24"/>
 			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
-			<flushOnExecute statement="UpdateAccountViaParameterMap"/>
-			<property name="CacheSize" value="50"/>
 		</cacheModel>
-		-->
 		
     </cacheModels>
     
@@ -161,7 +157,12 @@
 			from Accounts
 			order by Account_ID
 		</select>
-		
+
+		<select id="GetRWCachedAccountsViaResultMap"
+				resultMap="account-result"
+				cacheModel="rw-account-cache" extends="GetCachedAccountsViaResultMap">
+		</select>
+				
   		<select id="GetNoAccountWithCache"
 						parameterClass="Integer"
 						resultMap="account-hashtable-result"

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/OracleClient/Account.xml
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/OracleClient/Account.xml?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/OracleClient/Account.xml
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/Oracle/OracleClient/Account.xml
Sat Feb 18 13:18:09 2006
@@ -54,12 +54,10 @@
 			<property name="Type" value="Weak"/>
 		</cacheModel>
 		
-		<!-- <cacheModel name="account-cache" implementation="LRU" >
+		<cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
 			<flushInterval hours="24"/>
 			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
-			<flushOnExecute statement="UpdateAccountViaParameterMap"/>
-			<property name="CacheSize" value="50"/>
-		</cacheModel> -->
+		</cacheModel>
 		
     </cacheModels>
        
@@ -158,7 +156,12 @@
 			from Accounts
 			order by Account_ID
 		</select>
-  
+ 
+ 		<select id="GetRWCachedAccountsViaResultMap"
+				resultMap="account-result"
+				cacheModel="rw-account-cache" extends="GetCachedAccountsViaResultMap">
+		</select>
+		 
   		<select id="GetNoAccountWithCache"
 						parameterClass="Integer"
 						resultMap="account-hashtable-result"

Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/CacheModelTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/CacheModelTest.cs?rev=378778&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/CacheModelTest.cs
(added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheController/CacheModelTest.cs
Sat Feb 18 13:18:09 2006
@@ -0,0 +1,106 @@
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using IBatisNet.Common.Utilities;
+using IBatisNet.DataMapper.Configuration.Cache;
+using IBatisNet.DataMapper.Configuration.Cache.Lru;
+using NUnit.Framework;
+
+using IBatisNet.DataMapper.Test.Domain;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.CacheController
+{
+	/// <summary>
+	/// Summary description for CacheKeyTest.
+	/// </summary>
+	[TestFixture]
+	public class CacheModelTest
+	{
+		[Test]
+		/// <summary>
+		/// Returns reference to same instance of cached object
+		/// </summary>
+		public void TestReturnInstanceOfCachedOject()
+		{
+			ICacheController cacheController = new LruCacheController();
+			IDictionary props = new HybridDictionary();
+			props.Add("CacheSize", "1");
+			cacheController.Configure(props);
+
+			FlushInterval interval = new FlushInterval();
+			interval.Hours = 1;
+			interval.Initialize();
+
+			CacheModel cacheModel = new CacheModel();
+			cacheModel.FlushInterval = interval;
+			cacheModel.CacheController = cacheController;
+			cacheModel.IsReadOnly = true;
+			cacheModel.IsSerializable = false;
+
+			Order order = new Order(); 
+			order.CardNumber = "CardNumber";
+			order.Date = DateTime.Now;
+			order.LineItems = new ArrayList();
+			LineItem item = new LineItem();
+			item.Code = "Code1";
+			order.LineItems.Add( item );
+			item = new LineItem();
+			item.Code = "Code2";
+			order.LineItems.Add( item );
+
+			CacheKey key = new CacheKey();
+			key.Update(order);
+
+			int firstId = HashCodeProvider.GetIdentityHashCode(order);
+			cacheModel[ key ] = order;
+
+			Order order2 = cacheModel[ key ] as Order;
+			int secondId = HashCodeProvider.GetIdentityHashCode(order2);
+			Assert.AreEqual(firstId, secondId, "hasCode different");
+		}
+
+		[Test]
+		/// <summary>
+		/// Returns copy of cached object
+		/// </summary>
+		public void TestReturnCopyOfCachedOject()
+		{
+			ICacheController cacheController = new LruCacheController();
+			IDictionary props = new HybridDictionary();
+			props.Add("CacheSize", "1");
+			cacheController.Configure(props);
+
+			FlushInterval interval = new FlushInterval();
+			interval.Hours = 1;
+			interval.Initialize();
+
+			CacheModel cacheModel = new CacheModel();
+			cacheModel.FlushInterval = interval;
+			cacheModel.CacheController = cacheController;
+			cacheModel.IsReadOnly = false;
+			cacheModel.IsSerializable = true;
+
+			Order order = new Order(); 
+			order.CardNumber = "CardNumber";
+			order.Date = DateTime.Now;
+			order.LineItems = new ArrayList();
+			LineItem item = new LineItem();
+			item.Code = "Code1";
+			order.LineItems.Add( item );
+			item = new LineItem();
+			item.Code = "Code2";
+			order.LineItems.Add( item );
+
+			CacheKey key = new CacheKey();
+			key.Update(order);
+
+			int firstId = HashCodeProvider.GetIdentityHashCode(order);
+			cacheModel[ key ] = order;
+
+			Order order2 = cacheModel[ key ] as Order;
+			int secondId = HashCodeProvider.GetIdentityHashCode(order2);
+			Assert.AreNotEqual(firstId, secondId, "hasCode equal");
+
+		}
+	}
+}

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs?rev=378778&r1=378777&r2=378778&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 Sat Feb
18 13:18:09 2006
@@ -128,18 +128,17 @@
 		[Test]
 		public void TestMappedStatementQueryWithThreadedCache() 
 		{
-			Hashtable results1 = new Hashtable();
-			Hashtable results2 = new Hashtable();
+			Hashtable results = new Hashtable();
 
-			TestCacheThread.StartThread(sqlMap, results1, "GetCachedAccountsViaResultMap");
-			int firstId = (int) results1["id"];
+			TestCacheThread.StartThread(sqlMap, results, "GetCachedAccountsViaResultMap");
+			int firstId = (int) results["id"];
 
-			TestCacheThread.StartThread(sqlMap, results2, "GetCachedAccountsViaResultMap");
-			int secondId = (int) results2["id"];
+			TestCacheThread.StartThread(sqlMap, results, "GetCachedAccountsViaResultMap");
+			int secondId = (int) results["id"];
 
 			Assert.AreEqual(firstId, secondId);
 
-			IList list = (IList) results1["list"];
+			IList list = (IList) results["list"];
 
 			Account account = (Account) list[1];
 			account.EmailAddress = "new.toto@somewhere.com";
@@ -152,6 +151,34 @@
 			Assert.IsTrue(firstId != thirdId);
 		}
 
+		/// <summary>
+		/// Test MappedStatement Query With Threaded Read Write Cache
+		/// </summary>
+		[Test]
+		public void TestMappedStatementQueryWithThreadedReadWriteCache()
+		{
+			Hashtable results = new Hashtable();
+
+			TestCacheThread.StartThread(sqlMap, results, "GetRWCachedAccountsViaResultMap");
+			int firstId = (int) results["id"];
+
+			TestCacheThread.StartThread(sqlMap, results, "GetRWCachedAccountsViaResultMap");
+			int secondId = (int) results["id"];
+
+			Assert.AreNotEqual(firstId, secondId);
+
+			IList list = (IList) results["list"];
+
+			Account account = (Account) list[1];
+			account.EmailAddress = "new.toto@somewhere.com";
+			sqlMap.Update("UpdateAccountViaInlineParameters", account);
+
+			list = sqlMap.QueryForList("GetCachedAccountsViaResultMap", null);
+
+			int thirdId = HashCodeProvider.GetIdentityHashCode(list);
+
+			Assert.AreNotEqual(firstId, thirdId);
+		}
 
 		/// <summary>
 		/// Test Cache Null Object
@@ -307,8 +334,8 @@
 					list = statement.ExecuteQueryForList(session, null);
 					int secondId = HashCodeProvider.GetIdentityHashCode(list);
 
-					_results.Add("id", secondId );
-					_results.Add("list", list);
+					_results["id"] = secondId ;
+					_results["list"] = list;
 					session.CloseConnection();
 				} 
 				catch (Exception e) 

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt Sat Feb 18 13:18:09 2006
@@ -3,6 +3,7 @@
 ------------------------------
 1.4 - XX/XX/XXX
 ------------------------------
+- Added support for readOnly & serialize attribut on CacheModel
 - Added Support for .NET V2 and Generic
 	
 	public T QueryForObject<T>(string statementName, object parameterObject);

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheModel.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheModel.cs?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheModel.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheModel.cs Sat Feb
18 13:18:09 2006
@@ -29,8 +29,10 @@
 using System;
 using System.Collections;
 using System.Collections.Specialized;
+using System.IO;
 using System.Reflection;
 using System.Runtime.CompilerServices;
+using System.Runtime.Serialization.Formatters.Binary;
 using System.Xml.Serialization;
 using IBatisNet.Common.Exceptions;
 using IBatisNet.Common.Logging;
@@ -88,9 +90,9 @@
 		[NonSerialized]
 		private string _implementation = string.Empty;
 		[NonSerialized]
-		private bool _readOnly = false;
+		private bool _isReadOnly = true;
 		[NonSerialized]
-		private bool _serialize = false;
+		private bool _isSerializable = false;
 
 		#endregion
 
@@ -128,6 +130,14 @@
 		}
 
 		/// <summary>
+		/// Set the cache controller
+		/// </summary>
+		public ICacheController CacheController
+		{
+			set{ _controller =value; }	
+		}
+
+		/// <summary>
 		/// Set or get the flushInterval (in Ticks)
 		/// </summary>
 		[XmlElement("flushInterval",typeof(FlushInterval))]
@@ -136,6 +146,35 @@
 			get { return _flushInterval; }
 			set { _flushInterval = value; }
 		}
+
+		/// <summary>
+		/// Specifie how the cache content should be returned.
+		/// If true a deep copy is returned.
+		/// </summary>
+		/// <remarks>
+		/// Combinaison
+		/// IsReadOnly=true/IsSerializable=false : Returned instance of cached object
+		/// IsReadOnly=false/IsSerializable=true : Returned coopy of cached object
+		/// </remarks>
+		public bool IsSerializable
+		{
+			get { return _isSerializable; }
+			set { _isSerializable = value; }
+		}
+
+		/// <summary>
+		/// Determines if the cache will be used as a read-only cache.
+		/// Tells the cache model that is allowed to pass back a reference to the object
+		/// existing in the cache.
+		/// </summary>
+		/// <remarks>
+		/// The IsReadOnly properties works in conjonction with the IsSerializable propertie.
+		/// </remarks>
+		public bool IsReadOnly
+		{
+			get { return _isReadOnly; }
+			set { _isReadOnly = value; }
+		}
 		#endregion
 
 		#region Constructor (s) / Destructor
@@ -258,6 +297,23 @@
 					value = _controller[key];
 				}
 
+				if(_isSerializable && !_isReadOnly &&
+					(value != NULL_OBJECT && value != null))
+				{
+					try
+					{
+						MemoryStream stream = new MemoryStream((byte[]) value);
+						stream.Position = 0;
+						BinaryFormatter formatter = new BinaryFormatter();
+						value = formatter.Deserialize( stream );
+					}
+					catch(Exception ex)
+					{
+						throw new IBatisNetException("Error caching serializable object.  Be sure you're not
attempting to use " +
+							"a serialized cache for an object that may be taking advantage of lazy loading.  Cause:
"+ex.Message, ex);
+					}
+				}
+
 				lock(_statLock) 
 				{
 					_requests++;
@@ -270,7 +326,21 @@
 			}
 			set
 			{
-				if (null == value) value = NULL_OBJECT;
+				if (null == value) {value = NULL_OBJECT;}
+				if(_isSerializable && !_isReadOnly && value != NULL_OBJECT)
+				{
+					try
+					{
+						MemoryStream stream = new MemoryStream();
+						BinaryFormatter formatter = new BinaryFormatter();
+						formatter.Serialize(stream, value);
+						value = stream.ToArray();
+					}
+					catch(Exception ex)
+					{
+						throw new IBatisNetException("Error caching serializable object. Cause: "+ex.Message,
ex);
+					}
+				}
 				_controller[key] = value;
 			}
 		}

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs
Sat Feb 18 13:18:09 2006
@@ -54,6 +54,8 @@
 			model.Id = NodeUtils.GetStringAttribute(prop, "id");
 			model.Implementation = NodeUtils.GetStringAttribute(prop, "implementation");
 			model.Implementation = configScope.SqlMapper.TypeHandlerFactory.GetTypeAlias(model.Implementation).Class.AssemblyQualifiedName;
+			model.IsReadOnly = NodeUtils.GetBooleanAttribute(prop, "readOnly", true);
+			model.IsSerializable = NodeUtils.GetBooleanAttribute(prop, "serialize", false);
 
 			for(int i=0;i<node.ChildNodes.Count;i++)
 			{

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs Sat Feb
18 13:18:09 2006
@@ -446,6 +446,11 @@
 			cacheKey.Update(_mappedStatement.SqlMap.DataSource.ConnectionString);
 			cacheKey.Update(request.IDbCommand.CommandText);
 
+			CacheModel cacheModel = _mappedStatement.Statement.CacheModel;
+			if (!cacheModel.IsReadOnly && !cacheModel.IsSerializable) 
+			{
+				cacheKey.Update(request);
+			}
 			return cacheKey;
 		}
 	}

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs?rev=378778&r1=378777&r2=378778&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs Sat Feb 18 13:18:09
2006
@@ -28,6 +28,7 @@
 
 using System.Collections;
 using System.Data;
+using System.Runtime.CompilerServices;
 using IBatisNet.DataMapper.Configuration.ParameterMapping;
 using IBatisNet.DataMapper.Configuration.ResultMapping;
 using IBatisNet.DataMapper.Configuration.Statements;
@@ -50,20 +51,10 @@
 		private IDbCommand _command = null;
 		private Queue _properties = new Queue();
 		bool _rowDataFound= false;
-
+		private static long _nextId = 0;
+		private long _id = 0;
 		#endregion
 	
-		#region Constructors
-
-		/// <summary>
-		/// Default constructor
-		/// </summary>
-		public RequestScope()
-		{
-			_errorContext = new ErrorContext();
-		}
-		#endregion 
-
 		#region Properties
 
 		/// <summary>
@@ -132,8 +123,45 @@
 		}
 		#endregion
 
+		#region Constructors
+
+		/// <summary>
+		/// Default constructor
+		/// </summary>
+		public RequestScope()
+		{
+			_errorContext = new ErrorContext();
+			 _id = GetNextId();
+		}
+		#endregion 
+
 		#region Method
 
+		/// <summary>
+		/// Check if the specify object is equal to the current object.
+		/// </summary>
+		/// <param name="obj"></param>
+		/// <returns></returns>
+		public override bool Equals(object obj)
+		{
+			if (this == obj) {return true;}
+			if (!(obj is RequestScope)) {return false;}
+
+			RequestScope scope = (RequestScope) obj;
+
+			if (_id != scope._id) return false;
+
+			return true;
+		}
+
+		/// <summary>
+		/// Get the HashCode for this RequestScope
+		/// </summary>
+		/// <returns></returns>
+		public override int GetHashCode() 
+		{
+			 return (int) (_id ^ (_id >> 32));
+		}
 
 		/// <summary>
 		/// Check if the ResultMap is well set, process case of subMap resultMap.
@@ -145,6 +173,15 @@
 			return _resultMap.ResolveSubMap(dataReader);
 		}
 
+		/// <summary>
+		/// Method to get a unique ID
+		/// </summary>
+		/// <returns>The new ID</returns>
+		[MethodImpl(MethodImplOptions.Synchronized)]
+		public static long GetNextId() 
+		{
+			return _nextId++;
+		}
 		#endregion
 	}
 }



Mime
View raw message