Author: gbayon
Date: Thu Dec  1 12:32:59 2005
New Revision: 351464

URL: http://svn.apache.org/viewcvs?rev=351464&view=rev
Log:
IBATISNET-118
 
fix in progress, need some cleaning

Added:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheKey.cs
Modified:
    ibatis/trunk/cs/mapper/IBatisNet.Common/Transaction/TransactionScope.cs
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/DBHelperParameterCache.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ThreadTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommand.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Transaction/TransactionScope.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Transaction/TransactionScope.cs?rev=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Transaction/TransactionScope.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Transaction/TransactionScope.cs Thu 
Dec  1 12:32:59 2005
@@ -349,7 +349,7 @@
                /// Implementation of IDisposable so that this class 
                /// can be used with C#'s using statement.
                /// </summary>
-               void IDisposable.Dispose()
+               public void Dispose()
                {
                        Close();
                }

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/DBHelperParameterCache.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/DBHelperParameterCache.cs?rev=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/DBHelperParameterCache.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/DBHelperParameterCache.cs 
Thu Dec  1 12:32:59 2005
@@ -27,9 +27,7 @@
 using System;
 using System.Collections;
 using System.Data;
-using System.Data.Common;
 using System.Reflection;
-
 using IBatisNet.Common.Exceptions;
 
 namespace IBatisNet.Common.Utilities
@@ -54,17 +52,17 @@
                /// <summary>
                /// Resolve at run time the appropriate set of Parameters for a 
stored procedure
                /// </summary>
-               /// <param name="session">a valid session</param>
+               /// <param name="dataSource">a valid dataSource</param>
                /// <param name="spName">the name of the stored 
procedure</param>
                /// <param name="includeReturnValueParameter">whether or not to 
include their return value parameter</param>
                /// <returns></returns>
-               private static IDataParameter[] 
DiscoverSpParameterSet(IDalSession session, string spName, bool 
includeReturnValueParameter)
+               private static IDataParameter[] 
DiscoverSpParameterSet(DataSource dataSource, string spName, bool 
includeReturnValueParameter)
                {
-                       using (IDbConnection connection = 
session.DataSource.Provider.GetConnection())
+                       using (IDbConnection connection = 
dataSource.Provider.GetConnection())
                        {
-                               connection.ConnectionString = 
session.DataSource.ConnectionString;
+                               connection.ConnectionString = 
dataSource.ConnectionString;
                                connection.Open();
-                               return 
InternalDiscoverSpParameterSet(session.DataSource.Provider, connection, spName, 
includeReturnValueParameter);
+                               return 
InternalDiscoverSpParameterSet(dataSource.Provider, connection, spName, 
includeReturnValueParameter);
                        }               
                }
 
@@ -122,7 +120,7 @@
                        try
                        {
                                
commandBuilderType.InvokeMember("DeriveParameters",
-                                       BindingFlags.Public | 
BindingFlags.InvokeMethod | BindingFlags.Static, null, null,
+                                                               
BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Static, null, 
null,
                                        new object[] {command});
                        }
                        catch(Exception ex)
@@ -207,12 +205,12 @@
                /// <remarks>
                /// This method will query the database for this information, 
and then store it in a cache for future requests.
                /// </remarks>
-               /// <param name="session">a valid session</param>
+               /// <param name="dataSource">a valid dataSource</param>
                /// <param name="spName">the name of the stored 
procedure</param>
                /// <returns>an array of IDataParameters</returns>
-               public static IDataParameter[] GetSpParameterSet(IDalSession 
session, string spName)
+               public static IDataParameter[] GetSpParameterSet(DataSource 
dataSource, string spName)
                {
-                       return GetSpParameterSet(session, spName, false);
+                       return GetSpParameterSet(dataSource, spName, false);
                }
 
                /// <summary>
@@ -221,14 +219,14 @@
                /// <remarks>
                /// This method will query the database for this information, 
and then store it in a cache for future requests.
                /// </remarks>
-               /// <param name="session">a valid csession</param>
+               /// <param name="dataSource">a valid dataSource</param>
                /// <param name="spName">the name of the stored 
procedure</param>
                /// <param name="includeReturnValueParameter">a bool value 
indicating whether the return value parameter should be included in the 
results</param>
                /// <returns>an array of IDataParameters</returns>
-               public static IDataParameter[] GetSpParameterSet(IDalSession 
session
+               public static IDataParameter[] GetSpParameterSet(DataSource 
dataSource
                        , string spName, bool includeReturnValueParameter)
                {
-                       string hashKey = session.DataSource.ConnectionString + 
":" + spName + (includeReturnValueParameter ? ":include ReturnValue 
Parameter":"");
+                       string hashKey = dataSource.ConnectionString + ":" + 
spName + (includeReturnValueParameter ? ":include ReturnValue Parameter":"");
 
                        IDataParameter[] cachedParameters;
                        
@@ -236,7 +234,7 @@
 
                        if (cachedParameters == null)
                        {
-                               _paramCache[hashKey] = 
DiscoverSpParameterSet(session, spName, includeReturnValueParameter);
+                               _paramCache[hashKey] = 
DiscoverSpParameterSet(dataSource, spName, includeReturnValueParameter);
                                cachedParameters = (IDataParameter[]) 
_paramCache[hashKey];
                        }
                        

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs?rev=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
 Thu Dec  1 12:32:59 2005
@@ -1,4 +1,5 @@
-using IBatisNet.DataMapper;
+
+using Cache = IBatisNet.DataMapper.Configuration.Cache;
 using IBatisNet.DataMapper.TypeHandlers;
 using NUnit.Framework;
 
@@ -30,8 +31,15 @@
                        TypeHandlerFactory factory = new TypeHandlerFactory();
 
                        // Two cache keys are equal except for the parameter.
-                       CacheKey key = new CacheKey(factory, "STATEMENT", 
"SQL", new TestClass(firstLong), new string[] {"AProperty"}, 0, 0, 
CacheKeyType.Object);
-                       CacheKey aDifferentKey = new CacheKey(factory, 
"STATEMENT", "SQL", new TestClass(secondLong), new string[] {"AProperty"}, 0, 
0, CacheKeyType.Object);
+                       Cache.CacheKey key = new Cache.CacheKey();
+                       TestClass clazz = new TestClass(firstLong);
+
+                       key.Update(clazz.AProperty);
+
+                       Cache.CacheKey aDifferentKey = new Cache.CacheKey();
+                       clazz = new TestClass(secondLong);
+
+                       key.Update(clazz.AProperty);
 
                        Assert.IsFalse(aDifferentKey.Equals(key)); // should 
not be 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=351464&r1=351463&r2=351464&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 
Thu Dec  1 12:32:59 2005
@@ -25,7 +25,7 @@
                /// SetUp
                /// </summary>
                [SetUp] 
-               public void Init() 
+               public void SetUp() 
                {
                        InitScript( sqlMap.DataSource, ScriptDirectory + 
"account-init.sql" );
                        InitScript( sqlMap.DataSource, ScriptDirectory + 
"account-procedure.sql", false );
@@ -35,7 +35,7 @@
                /// TearDown
                /// </summary>
                [TearDown] 
-               public void Dispose()
+               public void TearDown()
                { /* ... */ } 
 
                #endregion

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ThreadTest.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ThreadTest.cs?rev=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ThreadTest.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ThreadTest.cs
 Thu Dec  1 12:32:59 2005
@@ -76,6 +76,8 @@
                        {
                                Assert.IsFalse(sqlMap.IsSessionStarted);
 
+                               Console.WriteLine("Begin Thread : " + 
Thread.CurrentThread.GetHashCode());
+
                                Account account = (Account) 
sqlMap.QueryForObject("GetAccountViaColumnIndex", 1);
                                
                                Assert.IsFalse(sqlMap.IsSessionStarted);
@@ -83,6 +85,8 @@
                                Assert.AreEqual(1, account.Id, "account.Id");
                                Assert.AreEqual("Joe", account.FirstName, 
"account.FirstName");
                                Assert.AreEqual("Dalton", account.LastName, 
"account.LastName");
+
+                               Console.WriteLine("End Thread : " + 
Thread.CurrentThread.GetHashCode());
                        }
                }
 

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs?rev=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs 
Thu Dec  1 12:32:59 2005
@@ -64,21 +64,19 @@
                /// The parameter object that will fill the sql parameter
                /// </param>
                /// <returns>An IDbCommand with all the IDataParameter 
filled.</returns>
-               public IDbCommand Create(RequestScope request, IDalSession 
session, IStatement statement, object parameterObject )
+               public void Create(RequestScope request, IDalSession session, 
IStatement statement, object parameterObject )
                {
                        // the IDbConnection & the IDbTransaction are assign in 
the CreateCommand 
-                       IDbCommand command = 
session.CreateCommand(statement.CommandType);
+                       request.IDbCommand = 
session.CreateCommand(statement.CommandType);
                        
-                       command.CommandText = 
request.PreparedStatement.PreparedSql;
+                       request.IDbCommand.CommandText = 
request.PreparedStatement.PreparedSql;
 
                        if (_logger.IsDebugEnabled)
                        {
-                               _logger.Debug("Statement Id: [" + statement.Id 
+ "] PreparedStatement : [" + command.CommandText + "]");
+                               _logger.Debug("Statement Id: [" + statement.Id 
+ "] PreparedStatement : [" + request.IDbCommand.CommandText + "]");
                        }
 
-                       ApplyParameterMap( session, command, request, 
statement, parameterObject  );
-
-                       return command;
+                       ApplyParameterMap( session, request.IDbCommand, 
request, statement, parameterObject  );
                }
 
 

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommand.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommand.cs?rev=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommand.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommand.cs 
Thu Dec  1 12:32:59 2005
@@ -51,6 +51,6 @@
                /// The parameter object that will fill the sql parameter
                /// </param>
                /// <returns>An IDbCommand with all the IDataParameter 
filled.</returns>
-               IDbCommand Create (RequestScope request, IDalSession session, 
IStatement statement, object parameterObject );
+               void Create (RequestScope request, IDalSession session, 
IStatement statement, object parameterObject );
        }
 }

Added: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheKey.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheKey.cs?rev=351464&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheKey.cs 
(added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheKey.cs 
Thu Dec  1 12:32:59 2005
@@ -0,0 +1,151 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ * 
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2005 - iBATIS Team
+ *  
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ 
********************************************************************************/
+#endregion
+
+using System.Collections;
+using System.Text;
+
+namespace IBatisNet.DataMapper.Configuration.Cache
+{
+       /// <summary>
+       ///  Hash value generator for cache keys
+       /// </summary>
+       public class CacheKey
+       {
+               private const int DEFAULT_MULTIPLYER = 37;
+               private const int DEFAULT_HASHCODE = 17;
+
+               private int _multiplier = DEFAULT_MULTIPLYER;
+               private int _hashCode = DEFAULT_HASHCODE;
+               private long _checksum = long.MinValue;
+               private int _count = 0;
+               private IList _paramList = new ArrayList();
+
+               /// <summary>
+               /// Default constructor
+               /// </summary>
+               public CacheKey()
+               {
+                       _hashCode = DEFAULT_HASHCODE;
+                       _multiplier = DEFAULT_MULTIPLYER;
+                       _count = 0;
+               }
+
+               /// <summary>
+               /// Constructor that supplies an initial hashcode
+               /// </summary>
+               /// <param name="initialNonZeroOddNumber">the hashcode to 
use</param>
+               public CacheKey(int initialNonZeroOddNumber) 
+               {
+                       _hashCode = initialNonZeroOddNumber;
+                       _multiplier = DEFAULT_MULTIPLYER;
+                       _count = 0;
+               }
+
+               /// <summary>
+               /// Constructor that supplies an initial hashcode and multiplier
+               /// </summary>
+               /// <param name="initialNonZeroOddNumber">the hashcode to 
use</param>
+               /// <param name="multiplierNonZeroOddNumber">the multiplier to 
use</param>
+               public CacheKey(int initialNonZeroOddNumber, int 
multiplierNonZeroOddNumber) 
+               {
+                       _hashCode = initialNonZeroOddNumber;
+                       _multiplier = multiplierNonZeroOddNumber;
+                       _count = 0;
+               }
+
+               /// <summary>
+               /// Updates this object with new information based on an object
+               /// </summary>
+               /// <param name="obj">the object</param>
+               /// <returns>the cachekey</returns>
+               public CacheKey Update(object obj) 
+               {
+                       int baseHashCode = obj.GetHashCode();
+
+                       _count++;
+                       _checksum += baseHashCode;
+                       baseHashCode *= _count;
+
+                       _hashCode = _multiplier * _hashCode + baseHashCode;
+
+                       _paramList.Add(obj);
+
+                       return this;
+               }
+
+               /// <summary>
+               /// 
+               /// </summary>
+               /// <param name="obj"></param>
+               /// <returns></returns>
+               public override bool Equals(object obj) 
+               {
+                       if (this == obj) return true;
+                       if (!(obj is CacheKey)) return false;
+
+                       CacheKey cacheKey = (CacheKey) obj;
+
+                       if (_hashCode != cacheKey._hashCode) return false;
+                       if (_checksum != cacheKey._checksum) return false;
+                       if (_count != cacheKey._count) return false;
+
+                       for (int i=0; i < _paramList.Count; i++) 
+                       {
+                               object thisParam = _paramList[i];
+                               object thatParam = cacheKey._paramList[i];
+                               if(thisParam == null) 
+                               {
+                                       if (thatParam != null) return false;
+                               } 
+                               else 
+                               {
+                                       if (!thisParam.Equals(thatParam)) 
return false;
+                               }
+                       }
+
+                       return true;
+               }
+
+               /// <summary>
+               /// Get the HashCode for this CacheKey
+               /// </summary>
+               /// <returns></returns>
+               public override int GetHashCode() 
+               {
+                       return _hashCode;
+               }
+
+               /// <summary>
+               /// ToString implementation.
+               /// </summary>
+               /// <returns>A string that give the CacheKey HashCode.</returns>
+               public override string ToString() 
+               {
+                       return new 
StringBuilder().Append(_hashCode).Append('|').Append(_checksum).ToString();
+               }
+
+       }
+}

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs?rev=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/PreparedStatementFactory.cs
 Thu Dec  1 12:32:59 2005
@@ -170,7 +170,7 @@
                {
                        // pull the parameters for this stored procedure from 
the parameter cache 
                        // (or discover them & populate the cache)
-                       IDataParameter[] commandParameters = 
DBHelperParameterCache.GetSpParameterSet(session, _commandText);
+                       IDataParameter[] commandParameters = 
DBHelperParameterCache.GetSpParameterSet(session.DataSource, _commandText);
                        
                        int start = 
session.DataSource.Provider.ParameterPrefix.Length;
                        foreach(IDataParameter dataParameter in 
commandParameters)

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj?rev=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj Thu 
Dec  1 12:32:59 2005
@@ -216,6 +216,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "Configuration\Cache\CacheKey.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "Configuration\Cache\CacheModel.cs"
                     SubType = "Code"
                     BuildAction = "Compile"

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=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
 Thu Dec  1 12:32:59 2005
@@ -29,9 +29,11 @@
 using IBatisNet.Common;
 using IBatisNet.DataMapper.Commands;
 using IBatisNet.DataMapper.Configuration.Cache;
+using IBatisNet.DataMapper.Configuration.ParameterMapping;
 using IBatisNet.DataMapper.Configuration.Statements;
 using IBatisNet.DataMapper.Scope;
 using IBatisNet.DataMapper.MappedStatements;
+using Cache = IBatisNet.DataMapper.Configuration.Cache;
 
 #endregion 
 
@@ -125,34 +127,41 @@
                        IDictionary map = new Hashtable();
                        RequestScope request = 
this.Statement.Sql.GetRequestScope(parameterObject, session);;
 
-                               CacheKey key = null;
-                               if (this.Statement.ParameterMap != null) 
-                               {
-                                       key = new 
CacheKey(this.SqlMap.TypeHandlerFactory, this.Name, 
-                                               
request.PreparedStatement.PreparedSql, 
-                                               parameterObject, 
-                                               
request.ParameterMap.GetPropertyNameArray(), 
-                                               
MappedStatement.NO_SKIPPED_RESULTS, 
-                                               
MappedStatement.NO_MAXIMUM_RESULTS, 
-                                               CacheKeyType.Map);
-                               } 
-                               else 
-                               {
-                                       key = new 
CacheKey(this.SqlMap.TypeHandlerFactory, this.Name, 
-                                               
request.PreparedStatement.PreparedSql,  
-                                               parameterObject, 
-                                               new string[0], 
-                                               
MappedStatement.NO_SKIPPED_RESULTS, 
-                                               
MappedStatement.NO_MAXIMUM_RESULTS, 
-                                               CacheKeyType.Map);
-                               }
+                       _mappedStatement.PreparedCommand.Create( request, 
session, this.Statement, parameterObject );
 
-                               map = 
(IDictionary)this.Statement.CacheModel[key];
-                               if (map == null) 
-                               {
-                                       map = _mappedStatement.RunQueryForMap( 
request, session, parameterObject, keyProperty, valueProperty, null );
-                                       this.Statement.CacheModel[key] = map;
-                               }
+                       Cache.CacheKey cacheKey = this.GetCacheKey(request);
+                       cacheKey.Update("ExecuteQueryForMap");
+                       cacheKey.Update(keyProperty);
+                       cacheKey.Update(valueProperty);
+
+//                     CacheKey key = null;
+//                     if (this.Statement.ParameterMap != null) 
+//                     {
+//                             key = new 
CacheKey(this.SqlMap.TypeHandlerFactory, this.Name, 
+//                                     request.PreparedStatement.PreparedSql, 
+//                                     parameterObject, 
+//                                     
request.ParameterMap.GetPropertyNameArray(), 
+//                                     MappedStatement.NO_SKIPPED_RESULTS, 
+//                                     MappedStatement.NO_MAXIMUM_RESULTS, 
+//                                     CacheKeyType.Map);
+//                     } 
+//                     else 
+//                     {
+//                             key = new 
CacheKey(this.SqlMap.TypeHandlerFactory, this.Name, 
+//                                     request.PreparedStatement.PreparedSql,  
+//                                     parameterObject, 
+//                                     new string[0], 
+//                                     MappedStatement.NO_SKIPPED_RESULTS, 
+//                                     MappedStatement.NO_MAXIMUM_RESULTS, 
+//                                     CacheKeyType.Map);
+//                     }
+
+                       map = this.Statement.CacheModel[cacheKey] as 
IDictionary;
+                       if (map == null) 
+                       {
+                               map = _mappedStatement.RunQueryForMap( request, 
session, parameterObject, keyProperty, valueProperty, null );
+                               this.Statement.CacheModel[cacheKey] = map;
+                       }
 
                        return map;
                }
@@ -208,33 +217,18 @@
                        IList list = null;
                        RequestScope request = 
this.Statement.Sql.GetRequestScope(parameterObject, session);;
 
-                       CacheKey key = null;
-                       if (this.Statement.ParameterMap != null) 
-                       {
-                               key = new 
CacheKey(this.SqlMap.TypeHandlerFactory, this.Name, 
-                                       request.PreparedStatement.PreparedSql, 
-                                       parameterObject, 
-                                       
request.ParameterMap.GetPropertyNameArray(), 
-                                       skipResults, 
-                                       maxResults, 
-                                       CacheKeyType.List);
-                       } 
-                       else 
-                       {
-                               key = new 
CacheKey(this.SqlMap.TypeHandlerFactory, this.Name, 
-                                       request.PreparedStatement.PreparedSql,  
-                                       parameterObject, 
-                                       new string[0], 
-                                       skipResults, 
-                                       maxResults, 
-                                       CacheKeyType.List);
-                       }
+                       _mappedStatement.PreparedCommand.Create( request, 
session, this.Statement, parameterObject );
+
+                       Cache.CacheKey cacheKey = this.GetCacheKey(request);
+                       cacheKey.Update("ExecuteQueryForList");
+                       cacheKey.Update(skipResults);
+                       cacheKey.Update(maxResults);
 
-                       list = (IList)this.Statement.CacheModel[key];
+                       list = this.Statement.CacheModel[cacheKey] as IList;
                        if (list == null) 
                        {
                                list = 
_mappedStatement.RunQueryForList(request, session, parameterObject, 
skipResults, maxResults, null);
-                               this.Statement.CacheModel[key] = list;
+                               this.Statement.CacheModel[cacheKey] = list;
                        }
 
                        return list;
@@ -277,29 +271,12 @@
                        object obj = null;
                        RequestScope request = 
this.Statement.Sql.GetRequestScope(parameterObject, session);;
 
-                       CacheKey key = null;
-                       if (this.Statement.ParameterMap != null) 
-                       {
-                               key = new 
CacheKey(this.SqlMap.TypeHandlerFactory, this.Name, 
-                                       request.PreparedStatement.PreparedSql,
-                                       parameterObject, 
-                                       
request.ParameterMap.GetPropertyNameArray(), 
-                                       MappedStatement.NO_SKIPPED_RESULTS, 
-                                       MappedStatement.NO_MAXIMUM_RESULTS, 
-                                       CacheKeyType.Object);
-                       } 
-                       else 
-                       {
-                               key = new 
CacheKey(this.SqlMap.TypeHandlerFactory, this.Name, 
-                                       request.PreparedStatement.PreparedSql,
-                                       parameterObject, 
-                                       new string[0], 
-                                       MappedStatement.NO_SKIPPED_RESULTS, 
-                                       MappedStatement.NO_MAXIMUM_RESULTS, 
-                                       CacheKeyType.Object);
-                       }
+                       _mappedStatement.PreparedCommand.Create( request, 
session, this.Statement, parameterObject );
+
+                       Cache.CacheKey cacheKey = this.GetCacheKey(request);
+                       cacheKey.Update("ExecuteQueryForObject");
 
-                       obj = this.Statement.CacheModel[key];
+                       obj = this.Statement.CacheModel[cacheKey];
                        // check if this query has alreay been run 
                        if (obj == CacheModel.NULL_OBJECT) 
                        { 
@@ -309,7 +286,7 @@
                        else if (obj == null) 
                        {
                                obj = 
_mappedStatement.RunQueryForObject(request, session, parameterObject, 
resultObject);
-                               this.Statement.CacheModel[key] = obj;
+                               this.Statement.CacheModel[cacheKey] = obj;
                        }
 
                        return obj;
@@ -345,5 +322,26 @@
                }
 
                #endregion
+
+               private Cache.CacheKey GetCacheKey(RequestScope request) 
+               {
+                       Cache.CacheKey cacheKey = new Cache.CacheKey();
+                       for (int i = 0; i < 
request.IDbCommand.Parameters.Count; i++) 
+                       {
+                               if (request.IDbCommand.Parameters[i] != null) 
+                               {
+                                       
cacheKey.Update(request.IDbCommand.Parameters[i]);
+                               }
+                       }
+                       
+                       // cf BaseStatement public CacheKey getCacheKey(
+                       // cf SqMapExecutor  public int hashCode()
+
+                       cacheKey.Update(_mappedStatement.Name);
+                       
cacheKey.Update(_mappedStatement.SqlMap.DataSource.ConnectionString);
+                       cacheKey.Update(request.IDbCommand.CommandText);
+
+                       return cacheKey;
+               }
        }
 }

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs?rev=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs 
Thu Dec  1 12:32:59 2005
@@ -201,7 +201,7 @@
                {
                        _sqlMap = sqlMap;
                        _statement = statement;
-                       _preparedCommand = 
PreparedCommandFactory.GetPreparedCommand(sqlMap.UseEmbedStatementParams);
+                       _preparedCommand = 
PreparedCommandFactory.GetPreparedCommand( false );
                }
                #endregion
 
@@ -429,6 +429,8 @@
                        object obj = null;
                        RequestScope request = 
_statement.Sql.GetRequestScope(parameterObject, session);;
 
+                       _preparedCommand.Create( request, session, 
this.Statement, parameterObject );
+
                        obj = RunQueryForObject(request, session, 
parameterObject, resultObject);
                        
                        return obj;
@@ -448,7 +450,7 @@
                {
                        object result = resultObject;
                        
-                       using ( IDbCommand command = _preparedCommand.Create( 
request, session, this.Statement, parameterObject ) )
+                       using ( IDbCommand command = request.IDbCommand )
                        {
                                using ( IDataReader reader = 
command.ExecuteReader() )
                                {                               
@@ -488,6 +490,8 @@
                {
                        RequestScope request = 
_statement.Sql.GetRequestScope(parameterObject, session);;
 
+                       _preparedCommand.Create( request, session, 
this.Statement, parameterObject );
+
                        if (rowDelegate == null) 
                        {
                                throw new DataMapperException("A null 
RowDelegate was passed to QueryForRowDelegate.");
@@ -516,6 +520,8 @@
                                throw new DataMapperException("A null 
DictionaryRowDelegate was passed to QueryForMapWithRowDelegate.");
                        }
                        
+                       _preparedCommand.Create(request, session, 
this.Statement, parameterObject);
+
                        return RunQueryForMap(request, session, 
parameterObject, keyProperty, valueProperty, rowDelegate);
                }
 
@@ -546,6 +552,8 @@
                        IList list = null;
                        RequestScope request = 
_statement.Sql.GetRequestScope(parameterObject, session);;
 
+                       _preparedCommand.Create( request, session, 
this.Statement, parameterObject );
+
                        list = RunQueryForList(request, session, 
parameterObject, skipResults, maxResults, null);
                        
                        return list;
@@ -566,7 +574,7 @@
                {
                        IList list = null;
                        
-                       using ( IDbCommand command = _preparedCommand.Create( 
request, session, this.Statement, parameterObject ) )
+                       using ( IDbCommand command = request.IDbCommand )
                        {
                                if (_statement.ListClass == null)
                                {
@@ -633,8 +641,9 @@
                {
                        RequestScope request = 
_statement.Sql.GetRequestScope(parameterObject, session);;
 
-                       //using ( IDbCommand command = 
CreatePreparedCommand(request, session, parameterObject ) )
-                       using ( IDbCommand command = _preparedCommand.Create( 
request, session, this.Statement, parameterObject ) )
+                       _preparedCommand.Create( request, session, 
this.Statement, parameterObject );
+
+                       using ( IDbCommand command = request.IDbCommand )
                        {
                                using ( IDataReader reader = 
command.ExecuteReader() )
                                {                       
@@ -669,8 +678,9 @@
                        int rows = 0; // the number of rows affected
                        RequestScope request = 
_statement.Sql.GetRequestScope(parameterObject, session);;
 
-                       //using (IDbCommand command = 
CreatePreparedCommand(request, session, parameterObject ))                
-                       using ( IDbCommand command = _preparedCommand.Create( 
request, session, this.Statement, parameterObject ) )
+                       _preparedCommand.Create( request, session, 
this.Statement, parameterObject );
+       
+                       using ( IDbCommand command = request.IDbCommand )
                        {
                                rows = command.ExecuteNonQuery();
 
@@ -711,7 +721,8 @@
                                ObjectProbe.SetPropertyValue(parameterObject, 
selectKeyStatement.PropertyName, generatedKey);
                        }
 
-                       using ( IDbCommand command = _preparedCommand.Create( 
request, session, this.Statement, parameterObject ) )
+                       _preparedCommand.Create( request, session, 
this.Statement, parameterObject );
+                       using ( IDbCommand command = request.IDbCommand)
                        {
                                if (_statement is Insert)
                                {
@@ -764,7 +775,9 @@
                public virtual IDictionary ExecuteQueryForMap( IDalSession 
session, object parameterObject, string keyProperty, string valueProperty )
                {
                        IDictionary map = new Hashtable();
-                       RequestScope request = 
_statement.Sql.GetRequestScope(parameterObject, session);;
+                       RequestScope request = 
_statement.Sql.GetRequestScope(parameterObject, session);
+
+                       _preparedCommand.Create(request, session, 
this.Statement, parameterObject);
 
                        map = RunQueryForMap(request, session, parameterObject, 
keyProperty, valueProperty, null );
                        
@@ -790,11 +803,11 @@
                        object parameterObject, 
                        string keyProperty, 
                        string valueProperty, 
-                                                    
SqlMapper.DictionaryRowDelegate rowDelegate  )
+                   SqlMapper.DictionaryRowDelegate rowDelegate  )
                {
                        IDictionary map = new Hashtable();
 
-                       using (IDbCommand command = 
_preparedCommand.Create(request, session, this.Statement, parameterObject))
+                       using (IDbCommand command = request.IDbCommand)
                        {
                                using (IDataReader reader = 
command.ExecuteReader())
                                {

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=351464&r1=351463&r2=351464&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs Thu Dec  
1 12:32:59 2005
@@ -47,6 +47,7 @@
                private ParameterMap _parameterMap = null;
                private ResultMap _resultMap = null;
                private PreparedStatement _preparedStatement = null;
+               private IDbCommand _command = null;
                private Queue _properties = new Queue();
                bool _rowDataFound= false;
 
@@ -64,6 +65,15 @@
                #endregion 
 
                #region Properties
+
+               /// <summary>
+               ///  The IDbCommand to execute
+               /// </summary>
+               public IDbCommand IDbCommand
+               {
+                       set { _command = value; }
+                       get { return _command; }
+               }
 
                /// <summary>
                ///  Indicate if the statement have find data


Reply via email to