You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2005/07/26 21:04:31 UTC

svn commit: r225374 - in /ibatis/trunk/cs/mapper: IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ IBatisNet.DataMapper/ IBatisNet.DataMapper/Configuration/ IBatisNet.DataMapper/Configuration/Cache/ IBatisNet.DataMapper/Configuration/Statements/ IBatisNet....

Author: gbayon
Date: Tue Jul 26 12:04:10 2005
New Revision: 225374

URL: http://svn.apache.org/viewcvs?rev=225374&view=rev
Log:
- Improved Caching process

Added:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
Modified:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheModel.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/LazyLoadList.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/InsertMappedStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/UpdateMappedStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs

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=225374&r1=225373&r2=225374&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 Tue Jul 26 12:04:10 2005
@@ -246,7 +246,7 @@
 			{
 				try 
 				{
-					MappedStatement statement = _sqlMap.GetMappedStatement( _statementName );
+					IMappedStatement statement = _sqlMap.GetMappedStatement( _statementName );
 					IDalSession session = new SqlMapSession(sqlMap.DataSource);
 					session.OpenConnection();
 					IList list = statement.ExecuteQueryForList(session, null);

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=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheModel.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Cache/CacheModel.cs Tue Jul 26 12:04:10 2005
@@ -210,7 +210,7 @@
 		/// Event listener
 		/// </summary>
 		/// <param name="mappedStatement">A MappedStatement on which we listen ExecuteEventArgs event.</param>
-		public void RegisterTriggerStatement(MappedStatement mappedStatement)
+		public void RegisterTriggerStatement(IMappedStatement mappedStatement)
 		{
 			mappedStatement.Execute +=new ExecuteEventHandler(FlushHandler);
 		}

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=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs Tue Jul 26 12:04:10 2005
@@ -822,7 +822,7 @@
 				{
 					_configScope.ErrorContext.Activity = "Set CacheModel to statement";
 
-					MappedStatement mappedStatement = (MappedStatement)entry.Value;
+					IMappedStatement mappedStatement = (IMappedStatement)entry.Value;
 					if (mappedStatement.Statement.CacheModelName.Length >0)
 					{
 						_configScope.ErrorContext.MoreInfo = "statement : "+mappedStatement.Statement.Id;
@@ -1075,8 +1075,6 @@
 				_configScope.ErrorContext.MoreInfo = "loading select tag";
 				_configScope.NodeContext = xmlNode; // A select node
 
-				MappedStatement mappedStatement = null;
-
 				select = (Select) serializer.Deserialize(new XmlNodeReader(xmlNode));
 				select.CacheModelName = ApplyNamespace( select.CacheModelName );
 				select.ParameterMapName = ApplyNamespace( select.ParameterMapName );
@@ -1101,9 +1099,14 @@
 				}
 
 				// Build MappedStatement
-				mappedStatement = new SelectMappedStatement( _configScope.SqlMapper, select);
+				MappedStatement mappedStatement = new SelectMappedStatement( _configScope.SqlMapper, select);
+				IMappedStatement mapStatement = mappedStatement;
+				if (select.CacheModelName != null && select.CacheModelName.Length> 0 && _configScope.IsCacheModelsEnabled)
+				{
+					mapStatement = new CachingStatement( mappedStatement);
+				}
 
-				_configScope.SqlMapper.AddMappedStatement(mappedStatement.Name, mappedStatement);
+				_configScope.SqlMapper.AddMappedStatement(mappedStatement.Name, mapStatement);
 			}
 			#endregion
 
@@ -1307,7 +1310,7 @@
 							statementName = ApplyNamespace( statementName ); 
 						}
 
-						MappedStatement mappedStatement = _configScope.SqlMapper.GetMappedStatement(statementName);
+						IMappedStatement mappedStatement = _configScope.SqlMapper.GetMappedStatement(statementName);
 
 						cacheModel.RegisterTriggerStatement(mappedStatement);
 					}

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs?rev=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/SelectKey.cs Tue Jul 26 12:04:10 2005
@@ -116,7 +116,7 @@
 			if (PropertyName.Length > 0)
 			{
 				// Id is equal to the parent <select> node's "id" attribute
-				MappedStatement insert = configurationScope.SqlMapper.GetMappedStatement(Id);
+				IMappedStatement insert = configurationScope.SqlMapper.GetMappedStatement(Id);
 
 				Type insertParameterClass = insert.Statement.ParameterClass;
 

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=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj Tue Jul 26 12:04:10 2005
@@ -596,6 +596,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "MappedStatements\CachingStatement.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "MappedStatements\DeleteMappedStatement.cs"
                     SubType = "Code"
                     BuildAction = "Compile"

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/LazyLoadList.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/LazyLoadList.cs?rev=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/LazyLoadList.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/LazyLoadList.cs Tue Jul 26 12:04:10 2005
@@ -51,7 +51,7 @@
 		private object _target = null;
 		private string _propertyName= string.Empty;
 		private DataSource _dataSource;
-		private MappedStatement _mappedSatement;
+		private IMappedStatement _mappedSatement;
 		private bool _loaded = false;
 		private IList _innerList = null;
 		private object _loadLock = new object();
@@ -80,7 +80,7 @@
 		/// <param name="param">The parameter object used to build the list</param>
 		/// <param name="propertyName">The property's name which been proxified.</param>
 		/// <param name="target">The target object which contains the property proxydied.</param>
-		internal LazyLoadList(DataSource dataSource, MappedStatement mappedSatement, object param, object target,string propertyName)
+		internal LazyLoadList(DataSource dataSource, IMappedStatement mappedSatement, object param, object target,string propertyName)
 		{
 			_param = param;
 			_mappedSatement = mappedSatement;
@@ -100,7 +100,7 @@
 		/// <param name="propertyName">The property's name which been proxified.</param>
 		/// <param name="target">The target object which contains the property proxydied.</param>
 		/// <returns>A proxy</returns>
-		internal static IList NewInstance(DataSource dataSource, MappedStatement mappedSatement, object param, object target,string propertyName)
+		internal static IList NewInstance(DataSource dataSource, IMappedStatement mappedSatement, object param, object target,string propertyName)
 		{
 			object proxList = null;
 			IInterceptor handler = new LazyLoadList(dataSource, mappedSatement, param, target, propertyName);

Added: 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=225374&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs Tue Jul 26 12:04:10 2005
@@ -0,0 +1,333 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ * 
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *  
+ * 
+ * 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
+
+#region Using
+
+using System.Collections;
+using IBatisNet.Common;
+using IBatisNet.DataMapper.Commands;
+using IBatisNet.DataMapper.Configuration.Cache;
+using IBatisNet.DataMapper.Configuration.Statements;
+using IBatisNet.DataMapper.Scope;
+using IBatisNet.DataMapper.MappedStatements;
+
+#endregion 
+
+namespace IBatisNet.DataMapper.MappedStatements
+{
+	/// <summary>
+	/// Summary description for CachingStatement.
+	/// </summary>
+	public class CachingStatement : IMappedStatement
+	{
+		private MappedStatement _mappedStatement =null;
+
+		/// <summary>
+		/// Event launch on exceute query
+		/// </summary>
+		public event ExecuteEventHandler Execute;
+
+		/// <summary>
+		/// Constructor
+		/// </summary>
+		/// <param name="statement"></param>
+		public CachingStatement(MappedStatement statement) 
+		{
+			_mappedStatement = statement;
+		}
+
+		#region IMappedStatement Members
+
+		/// <summary>
+		/// The IPreparedCommand to use
+		/// </summary>
+		public IPreparedCommand PreparedCommand
+		{
+			get { return _mappedStatement.PreparedCommand; }
+		}
+
+		/// <summary>
+		/// Name used to identify the MappedStatement amongst the others.
+		/// This the name of the SQL statment by default.
+		/// </summary>
+		public string Name
+		{
+			get { return _mappedStatement.Name; }
+		}
+
+		/// <summary>
+		/// The SQL statment used by this MappedStatement
+		/// </summary>
+		public IStatement Statement
+		{
+			get { return _mappedStatement.Statement; }
+		}
+
+		/// <summary>
+		/// The SqlMap used by this MappedStatement
+		/// </summary>
+		public SqlMapper SqlMap
+		{
+			get {return _mappedStatement.SqlMap; }
+		}
+
+		/// <summary>
+		/// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
+		/// in the keyProperty parameter.  The value at each key will be the value of the property specified
+		/// in the valueProperty parameter.  If valueProperty is null, the entire result object will be entered.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
+		/// <param name="keyProperty">The property of the result object to be used as the key. </param>
+		/// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+		/// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
+		///<exception cref="IBatisNet.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+		public IDictionary ExecuteQueryForMap(IDalSession session, object parameterObject, string keyProperty, string valueProperty)
+		{
+			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);
+				}
+
+				map = (IDictionary)this.Statement.CacheModel[key];
+				if (map == null) 
+				{
+					map = _mappedStatement.RunQueryForMap( request, session, parameterObject, keyProperty, valueProperty, null );
+					this.Statement.CacheModel[key] = map;
+				}
+
+			return map;
+		}
+
+		
+		
+		/// <summary>
+		/// Execute an update statement. Also used for delete statement.
+		/// Return the number of row effected.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <returns>The number of row effected.</returns>
+		public int ExecuteUpdate(IDalSession session, object parameterObject)
+		{
+			return _mappedStatement.ExecuteUpdate(session, parameterObject);
+		}
+
+		/// <summary>
+		/// Execute an insert statement. Fill the parameter object with 
+		/// the ouput parameters if any, also could return the insert generated key
+		/// </summary>
+		/// <param name="session">The session</param>
+		/// <param name="parameterObject">The parameter object used to fill the statement.</param>
+		/// <returns>Can return the insert generated key.</returns>
+		public object ExecuteInsert(IDalSession session, object parameterObject)
+		{
+			return _mappedStatement.ExecuteInsert(session, parameterObject);
+		}
+
+
+		/// <summary>
+		/// Executes the SQL and and fill a strongly typed collection.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <param name="resultObject">A strongly typed collection of result objects.</param>
+		public void ExecuteQueryForList(IDalSession session, object parameterObject, IList resultObject)
+		{
+			_mappedStatement.ExecuteQueryForList(session, parameterObject, resultObject);
+		}
+
+		/// <summary>
+		/// Executes the SQL and retuns a subset of the rows selected.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <param name="skipResults">The number of rows to skip over.</param>
+		/// <param name="maxResults">The maximum number of rows to return.</param>
+		/// <returns>A List of result objects.</returns>
+		public IList ExecuteQueryForList(IDalSession session, object parameterObject, int skipResults, int maxResults)
+		{
+			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);
+			}
+
+			list = (IList)this.Statement.CacheModel[key];
+			if (list == null) 
+			{
+				list = _mappedStatement.RunQueryForList(request, session, parameterObject, skipResults, maxResults, null);
+				this.Statement.CacheModel[key] = list;
+			}
+
+			return list;
+		}
+
+		
+		/// <summary>
+		/// Executes the SQL and retuns all rows selected. This is exactly the same as
+		/// calling ExecuteQueryForList(session, parameterObject, NO_SKIPPED_RESULTS, NO_MAXIMUM_RESULTS).
+		/// </summary>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <returns>A List of result objects.</returns>
+		public IList ExecuteQueryForList(IDalSession session, object parameterObject)
+		{
+			return this.ExecuteQueryForList( session, parameterObject, MappedStatement.NO_SKIPPED_RESULTS, MappedStatement.NO_MAXIMUM_RESULTS);
+		}
+
+		/// <summary>
+		/// Executes an SQL statement that returns a single row as an Object.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <returns>The object</returns>
+		public object ExecuteQueryForObject(IDalSession session, object parameterObject)
+		{
+			return this.ExecuteQueryForObject(session, parameterObject, null);
+		}
+
+		/// <summary>
+		/// Executes an SQL statement that returns a single row as an Object of the type of
+		/// the resultObject passed in as a parameter.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <param name="resultObject">The result object.</param>
+		/// <returns>The object</returns>
+		public object ExecuteQueryForObject(IDalSession session, object parameterObject, object resultObject)
+		{
+			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);
+			}
+
+			obj = this.Statement.CacheModel[key];
+			// check if this query has alreay been run 
+			if (obj == CacheModel.NULL_OBJECT) 
+			{ 
+				// convert the marker object back into a null value 
+				obj = null; 
+			} 
+			else if (obj == null) 
+			{
+				obj = _mappedStatement.RunQueryForObject(request, session, parameterObject, resultObject);
+				this.Statement.CacheModel[key] = obj;
+			}
+
+			return obj;
+		}
+
+		
+		/// <summary>
+		/// Runs a query with a custom object that gets a chance 
+		/// to deal with each row as it is processed.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <param name="rowDelegate"></param>
+		public IList ExecuteQueryForRowDelegate(IDalSession session, object parameterObject, SqlMapper.RowDelegate rowDelegate)
+		{
+			return _mappedStatement.ExecuteQueryForRowDelegate(session, parameterObject, rowDelegate);
+		}
+
+		/// <summary>
+		/// Runs a query with a custom object that gets a chance 
+		/// to deal with each row as it is processed.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
+		/// <param name="keyProperty">The property of the result object to be used as the key. </param>
+		/// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+		/// <param name="rowDelegate"></param>
+		/// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
+		/// <exception cref="IBatisNet.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+		public IDictionary ExecuteQueryForMapWithRowDelegate(IDalSession session, object parameterObject, string keyProperty, string valueProperty, SqlMapper.DictionaryRowDelegate rowDelegate)
+		{
+			return _mappedStatement.ExecuteQueryForMapWithRowDelegate(session, parameterObject, keyProperty, valueProperty, rowDelegate);
+		}
+
+		#endregion
+	}
+}

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs?rev=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs Tue Jul 26 12:04:10 2005
@@ -45,6 +45,16 @@
 	/// </summary>
 	public interface IMappedStatement
 	{
+
+		#region Event
+
+		/// <summary>
+		/// Event launch on exceute query
+		/// </summary>
+		event ExecuteEventHandler Execute;
+
+		#endregion 
+
 		#region Properties
 
 		/// <summary>
@@ -85,13 +95,16 @@
 		#region ExecuteQueryForMap
 
 		/// <summary>
-		/// 
-		/// </summary>
-		/// <param name="session"></param>
-		/// <param name="parameterObject"></param>
-		/// <param name="keyProperty"></param>
-		/// <param name="valueProperty"></param>
-		/// <returns></returns>
+		/// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
+		/// in the keyProperty parameter.  The value at each key will be the value of the property specified
+		/// in the valueProperty parameter.  If valueProperty is null, the entire result object will be entered.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
+		/// <param name="keyProperty">The property of the result object to be used as the key. </param>
+		/// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+		/// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
+		///<exception cref="IBatisNet.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
 		IDictionary ExecuteQueryForMap( IDalSession session, object parameterObject, string keyProperty, string valueProperty );
 
 		#endregion
@@ -99,11 +112,12 @@
 		#region ExecuteUpdate
 
 		/// <summary>
-		/// 
+		/// Execute an update statement. Also used for delete statement.
+		/// Return the number of row effected.
 		/// </summary>
-		/// <param name="session"></param>
-		/// <param name="parameterObject"></param>
-		/// <returns></returns>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <returns>The number of row effected.</returns>
 		int ExecuteUpdate(IDalSession session, object parameterObject );
 
 		#endregion
@@ -111,11 +125,12 @@
 		#region ExecuteInsert
 
 		/// <summary>
-		/// 
+		/// Execute an insert statement. Fill the parameter object with 
+		/// the ouput parameters if any, also could return the insert generated key
 		/// </summary>
-		/// <param name="session"></param>
-		/// <param name="parameterObject"></param>
-		/// <returns></returns>
+		/// <param name="session">The session</param>
+		/// <param name="parameterObject">The parameter object used to fill the statement.</param>
+		/// <returns>Can return the insert generated key.</returns>
 		object ExecuteInsert(IDalSession session, object parameterObject );
 
 		#endregion
@@ -123,29 +138,30 @@
 		#region ExecuteQueryForList
 
 		/// <summary>
-		/// 
+		/// Executes the SQL and and fill a strongly typed collection.
 		/// </summary>
-		/// <param name="session"></param>
-		/// <param name="parameterObject"></param>
-		/// <param name="resultObject"></param>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <param name="resultObject">A strongly typed collection of result objects.</param>
 		void ExecuteQueryForList(IDalSession session, object parameterObject, IList resultObject );
 
 		/// <summary>
-		/// 
+		/// Executes the SQL and retuns a subset of the rows selected.
 		/// </summary>
-		/// <param name="session"></param>
-		/// <param name="parameterObject"></param>
-		/// <param name="skipResults"></param>
-		/// <param name="maxResults"></param>
-		/// <returns></returns>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <param name="skipResults">The number of rows to skip over.</param>
+		/// <param name="maxResults">The maximum number of rows to return.</param>
+		/// <returns>A List of result objects.</returns>
 		IList ExecuteQueryForList( IDalSession session, object parameterObject, int skipResults, int maxResults );
 
 		/// <summary>
-		/// 
+		/// Executes the SQL and retuns all rows selected. This is exactly the same as
+		/// calling ExecuteQueryForList(session, parameterObject, NO_SKIPPED_RESULTS, NO_MAXIMUM_RESULTS).
 		/// </summary>
-		/// <param name="session"></param>
-		/// <param name="parameterObject"></param>
-		/// <returns></returns>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <returns>A List of result objects.</returns>
 		IList ExecuteQueryForList( IDalSession session, object parameterObject );
 
 		#endregion
@@ -153,20 +169,21 @@
 		#region ExecuteForObject
 
 		/// <summary>
-		/// 
+		/// Executes an SQL statement that returns a single row as an Object.
 		/// </summary>
-		/// <param name="session"></param>
-		/// <param name="parameterObject"></param>
-		/// <returns></returns>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <returns>The object</returns>
 		object ExecuteQueryForObject( IDalSession session, object parameterObject );
 
 		/// <summary>
-		/// 
+		/// Executes an SQL statement that returns a single row as an Object of the type of
+		/// the resultObject passed in as a parameter.
 		/// </summary>
-		/// <param name="session"></param>
-		/// <param name="parameterObject"></param>
-		/// <param name="resultObject"></param>
-		/// <returns></returns>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <param name="resultObject">The result object.</param>
+		/// <returns>The object</returns>
 		object ExecuteQueryForObject( IDalSession session, object parameterObject, object resultObject );
 
 		#endregion
@@ -174,11 +191,12 @@
 		#region Delegate
 
 		/// <summary>
-		/// 
+		/// Runs a query with a custom object that gets a chance 
+		/// to deal with each row as it is processed.
 		/// </summary>
-		/// <param name="session"></param>
-		/// <param name="parameterObject"></param>
-		/// <param name="rowDelegate"></param>
+		/// <param name="session">The session used to execute the statement.</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
+		/// <param name="rowDelegate"></param>param>
 		/// <returns></returns>
 		IList ExecuteQueryForRowDelegate( IDalSession session, object parameterObject, SqlMapper.RowDelegate rowDelegate );
 

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/InsertMappedStatement.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/InsertMappedStatement.cs?rev=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/InsertMappedStatement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/InsertMappedStatement.cs Tue Jul 26 12:04:10 2005
@@ -118,6 +118,8 @@
 
 		#endregion
 
+		#region Delegate
+
 		/// <summary>
 		/// 
 		/// </summary>
@@ -129,6 +131,23 @@
 		{
 			throw new DataMapperException("Insert statements cannot be executed as a query for row delegate.");
 		}
+
+		/// <summary>
+		/// Runs a query with a custom object that gets a chance 
+		/// to deal with each row as it is processed.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
+		/// <param name="keyProperty">The property of the result object to be used as the key. </param>
+		/// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+		/// <param name="rowDelegate"></param>
+		/// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
+		///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+		public override IDictionary ExecuteQueryForMapWithRowDelegate( IDalSession session, object parameterObject, string keyProperty, string valueProperty, SqlMapper.DictionaryRowDelegate rowDelegate )
+		{
+			throw new DataMapperException("Insert statements cannot be executed as a query for row delegate.");
+		}
+		#endregion 
 
 		#region ExecuteForObject
 

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=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs Tue Jul 26 12:04:10 2005
@@ -54,7 +54,7 @@
 	public class MappedStatement : IMappedStatement
 	{
 		/// <summary>
-		/// 
+		/// Event launch on exceute query
 		/// </summary>
 		public event ExecuteEventHandler Execute;
 
@@ -80,7 +80,7 @@
 		private class PostBindind
 		{
 			#region Fields
-			private MappedStatement _statement = null;
+			private IMappedStatement _statement = null;
 			private ResultProperty _property = null;
 			private object _target = null;
 			private object _keys = null;
@@ -91,7 +91,7 @@
 			/// <summary>
 			/// 
 			/// </summary>
-			public MappedStatement Statement
+			public IMappedStatement Statement
 			{
 				set { _statement = value; }
 				get { return _statement; }
@@ -141,9 +141,9 @@
 		#region Fields 
 
 		// Magic number used to set the the maximum number of rows returned to 'all'. 
-		private const int NO_MAXIMUM_RESULTS = -1;
+		internal const int NO_MAXIMUM_RESULTS = -1;
 		// Magic number used to set the the number of rows skipped to 'none'. 
-		private const int NO_SKIPPED_RESULTS = -1;
+		internal const int NO_SKIPPED_RESULTS = -1;
 
 		private static readonly ILog _logger = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType );
 
@@ -391,48 +391,8 @@
 			object obj = null;
 			RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
 
-			if (_statement.CacheModel == null) 
-			{
-				obj = RunQueryForObject(request, session, parameterObject, resultObject);
-			}
-			else
-			{
-				CacheKey key = null;
-				if (_statement.ParameterMap != null) 
-				{
-					key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name, 
-						request.PreparedStatement.PreparedSql,
-						parameterObject, 
-						request.ParameterMap.GetPropertyNameArray(), 
-						NO_SKIPPED_RESULTS, 
-						NO_MAXIMUM_RESULTS, 
-						CacheKeyType.Object);
-				} 
-				else 
-				{
-					key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name, 
-						request.PreparedStatement.PreparedSql,
-						parameterObject, 
-						new string[0], 
-						NO_SKIPPED_RESULTS, 
-						NO_MAXIMUM_RESULTS, 
-						CacheKeyType.Object);
-				}
-
-				obj = _statement.CacheModel[key];
-				// check if this query has alreay been run 
-				if (obj == CacheModel.NULL_OBJECT) 
-				{ 
-					// convert the marker object back into a null value 
-					obj = null; 
-				} 
-				else if (obj == null) 
-				{
-					obj = RunQueryForObject(request, session, parameterObject, resultObject);
-					_statement.CacheModel[key] = obj;
-				}
-			}
-
+			obj = RunQueryForObject(request, session, parameterObject, resultObject);
+			
 			return obj;
 		}
 
@@ -446,7 +406,7 @@
 		/// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
 		/// <param name="resultObject">The result object.</param>
 		/// <returns>The object</returns>
-		private object RunQueryForObject(RequestScope request, IDalSession session, object parameterObject, object resultObject )
+		internal object RunQueryForObject(RequestScope request, IDalSession session, object parameterObject, object resultObject )
 		{
 			object result = resultObject;
 			
@@ -546,42 +506,8 @@
 			IList list = null;
 			RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
 
-			if (_statement.CacheModel == null) 
-			{
-				list = RunQueryForList(request, session, parameterObject, skipResults, maxResults, null);
-			}
-			else
-			{
-				CacheKey key = null;
-				if (_statement.ParameterMap != null) 
-				{
-					key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name, 
-						request.PreparedStatement.PreparedSql, 
-						parameterObject, 
-						request.ParameterMap.GetPropertyNameArray(), 
-						skipResults, 
-						maxResults, 
-						CacheKeyType.List);
-				} 
-				else 
-				{
-					key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name, 
-						request.PreparedStatement.PreparedSql,  
-						parameterObject, 
-						new string[0], 
-						skipResults, 
-						maxResults, 
-						CacheKeyType.List);
-				}
-
-				list = (IList)_statement.CacheModel[key];
-				if (list == null) 
-				{
-					list = RunQueryForList(request, session, parameterObject, skipResults, maxResults, null);
-					_statement.CacheModel[key] = list;
-				}
-			}
-
+			list = RunQueryForList(request, session, parameterObject, skipResults, maxResults, null);
+			
 			return list;
 		}
 
@@ -596,7 +522,7 @@
 		/// <param name="maxResults">The maximum number of rows to return.</param>
 		/// <param name="rowDelegate"></param>
 		/// <returns>A List of result objects.</returns>
-		private IList RunQueryForList(RequestScope request, IDalSession session, object parameterObject, int skipResults, int maxResults,  SqlMapper.RowDelegate rowDelegate)
+		internal IList RunQueryForList(RequestScope request, IDalSession session, object parameterObject, int skipResults, int maxResults,  SqlMapper.RowDelegate rowDelegate)
 		{
 			IList list = null;
 			
@@ -739,7 +665,7 @@
 
 			if (selectKeyStatement != null && !selectKeyStatement.isAfter)
 			{
-				MappedStatement mappedStatement = _sqlMap.GetMappedStatement( selectKeyStatement.Id );
+				IMappedStatement mappedStatement = _sqlMap.GetMappedStatement( selectKeyStatement.Id );
 				generatedKey = mappedStatement.ExecuteQueryForObject(session, parameterObject);
 
 				ObjectProbe.SetPropertyValue(parameterObject, selectKeyStatement.PropertyName, generatedKey);
@@ -765,7 +691,7 @@
 			
 				if (selectKeyStatement != null && selectKeyStatement.isAfter)
 				{
-					MappedStatement mappedStatement = _sqlMap.GetMappedStatement( selectKeyStatement.Id );
+					IMappedStatement mappedStatement = _sqlMap.GetMappedStatement( selectKeyStatement.Id );
 					generatedKey = mappedStatement.ExecuteQueryForObject(session, parameterObject);
 
 					ObjectProbe.SetPropertyValue(parameterObject, selectKeyStatement.PropertyName, generatedKey);
@@ -801,42 +727,8 @@
 			IDictionary map = new Hashtable();
 			RequestScope request = _statement.Sql.GetRequestScope(parameterObject, session);;
 
-			if (_statement.CacheModel == null) 
-			{
-				map = RunQueryForMap(request, session, parameterObject, keyProperty, valueProperty, null );
-			}
-			else
-			{
-				CacheKey key = null;
-				if (_statement.ParameterMap != null) 
-				{
-					key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name, 
-						request.PreparedStatement.PreparedSql, 
-						parameterObject, 
-						request.ParameterMap.GetPropertyNameArray(), 
-						NO_SKIPPED_RESULTS, 
-						NO_MAXIMUM_RESULTS, 
-						CacheKeyType.Map);
-				} 
-				else 
-				{
-					key = new CacheKey(_sqlMap.TypeHandlerFactory, this.Name, 
-						request.PreparedStatement.PreparedSql,  
-						parameterObject, 
-						new string[0], 
-						NO_SKIPPED_RESULTS, 
-						NO_MAXIMUM_RESULTS, 
-						CacheKeyType.Map);
-				}
-
-				map = (IDictionary)_statement.CacheModel[key];
-				if (map == null) 
-				{
-					map = RunQueryForMap( request, session, parameterObject, keyProperty, valueProperty, null );
-					_statement.CacheModel[key] = map;
-				}
-			}
-
+			map = RunQueryForMap(request, session, parameterObject, keyProperty, valueProperty, null );
+			
 			return map;
 		}
 
@@ -854,7 +746,7 @@
 		/// <param name="rowDelegate"></param>
 		/// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
 		///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
-		private IDictionary RunQueryForMap( RequestScope request, 
+		internal IDictionary RunQueryForMap( RequestScope request, 
 			IDalSession session, 
 			object parameterObject, 
 			string keyProperty, 
@@ -1014,7 +906,7 @@
 			else //'select' ResultProperty 
 			{
 				// Get the select statement
-				MappedStatement queryStatement = _sqlMap.GetMappedStatement(selectStatement);
+				IMappedStatement queryStatement = _sqlMap.GetMappedStatement(selectStatement);
 				string paramString = mapping.ColumnName;
 				object keys = null;
 				bool wasNull = false;

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/UpdateMappedStatement.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/UpdateMappedStatement.cs?rev=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/UpdateMappedStatement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/UpdateMappedStatement.cs Tue Jul 26 12:04:10 2005
@@ -78,7 +78,6 @@
 
 		#endregion
 
-
 		#region ExecuteQueryForList
 
 		/// <summary>
@@ -118,6 +117,8 @@
 
 		#endregion
 
+		#region Delegate
+
 		/// <summary>
 		/// 
 		/// </summary>
@@ -127,10 +128,26 @@
 		/// <returns></returns>
 		public override IList ExecuteQueryForRowDelegate( IDalSession session, object parameterObject, SqlMapper.RowDelegate rowDelegate )
 		{
-			throw new DataMapperException("Update statements cannot be executed as a query for row delegate.");
+			throw new DataMapperException("Update statement cannot be executed as a query for row delegate.");
+		}
+
+		/// <summary>
+		/// Runs a query with a custom object that gets a chance 
+		/// to deal with each row as it is processed.
+		/// </summary>
+		/// <param name="session">The session used to execute the statement</param>
+		/// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
+		/// <param name="keyProperty">The property of the result object to be used as the key. </param>
+		/// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
+		/// <param name="rowDelegate"></param>
+		/// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
+		///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
+		public override IDictionary ExecuteQueryForMapWithRowDelegate( IDalSession session, object parameterObject, string keyProperty, string valueProperty, SqlMapper.DictionaryRowDelegate rowDelegate )
+		{
+			throw new DataMapperException("Update statement cannot be executed as a query for row delegate.");
 		}
+		#endregion 
 
-		
 		#region ExecuteForObject
 
 		/// <summary>

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs?rev=225374&r1=225373&r2=225374&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs Tue Jul 26 12:04:10 2005
@@ -1100,13 +1100,13 @@
 		/// </summary>
 		/// <param name="name"> The name of the statement</param>
 		/// <returns> The MappedStatement</returns>
-		public MappedStatement GetMappedStatement(string name) 
+		public IMappedStatement GetMappedStatement(string name) 
 		{
 			if (_mappedStatements.Contains(name) == false) 
 			{
 				throw new DataMapperException("This SQL map does not contain a MappedStatement named " + name);
 			}
-			return (MappedStatement) _mappedStatements[name];
+			return (IMappedStatement) _mappedStatements[name];
 		}
 
 		/// <summary>
@@ -1114,7 +1114,7 @@
 		/// </summary>
 		/// <param name="key"> The key name</param>
 		/// <param name="mappedStatement">The statement to add</param>
-		internal void AddMappedStatement(string key, MappedStatement mappedStatement) 
+		internal void AddMappedStatement(string key, IMappedStatement mappedStatement) 
 		{
 			if (_mappedStatements.Contains(key) == true) 
 			{