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 2006/10/31 19:49:53 UTC

svn commit: r469607 - in /ibatis/trunk/cs/mapper: ./ IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/ IBatisNet.DataMapper/ IBatisNet.DataMapper/MappedStatements/

Author: gbayon
Date: Tue Oct 31 10:49:52 2006
New Revision: 469607

URL: http://svn.apache.org/viewvc?view=rev&rev=469607
Log:
Fix for IBATISNET-192

Removed:
    ibatis/trunk/cs/mapper/DataMapper.sln
Modified:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/StatementTest.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Delegates.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ISqlMapper.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/StatementTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/StatementTest.cs?view=diff&rev=469607&r1=469606&r2=469607
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/StatementTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/StatementTest.cs Tue Oct 31 10:49:52 2006
@@ -530,6 +530,89 @@
         }
 
         #endregion
+
+        #region QueryForDictionary
+        /// <summary>
+        /// Test ExecuteQueryForDictionary 
+        /// </summary>
+        [Test]
+        public void TestExecuteQueryForDictionary()
+        {
+            IDictionary<string, Account> map = sqlMap.QueryForDictionary<string, Account>("GetAllAccountsViaResultClass", null, "FirstName");
+
+            Assert.AreEqual(5, map.Count);
+            AssertAccount1(map["Joe"]);
+
+            Assert.AreEqual(1, map["Joe"].Id);
+            Assert.AreEqual(2, map["Averel"].Id);
+            Assert.AreEqual(3, map["William"].Id);
+            Assert.AreEqual(4, map["Jack"].Id);
+            Assert.AreEqual(5, map["Gilles"].Id);
+        }
+
+        /// <summary>
+        /// Test ExecuteQueryForDictionary With Cache.
+        /// </summary>
+        [Test]
+        public void TestExecuteQueryQueryForDictionaryWithCache()
+        {
+            IDictionary<string, Account> map = sqlMap.QueryForDictionary<string, Account>("GetAllAccountsCache", null, "FirstName");
+
+            int firstId = HashCodeProvider.GetIdentityHashCode(map);
+
+            Assert.AreEqual(5, map.Count);
+            AssertAccount1(map["Joe"]);
+
+            Assert.AreEqual(1, map["Joe"].Id);
+            Assert.AreEqual(2, map["Averel"].Id);
+            Assert.AreEqual(3, map["William"].Id);
+            Assert.AreEqual(4, map["Jack"].Id);
+            Assert.AreEqual(5, map["Gilles"].Id);
+
+            map = sqlMap.QueryForDictionary<string, Account>("GetAllAccountsCache", null, "FirstName");
+
+            int secondId = HashCodeProvider.GetIdentityHashCode(map);
+
+            Assert.AreEqual(firstId, secondId);
+        }
+
+        /// <summary>
+        /// Test ExecuteQueryForMap : Hashtable.
+        /// </summary>
+        /// <remarks>
+        /// If the keyProperty is an integer, you must acces the map
+        /// by map[integer] and not by map["integer"]
+        /// </remarks>
+        [Test]
+        public void TestExecuteQueryForDictionary2()
+        {
+            IDictionary<string, Order> map = sqlMap.QueryForDictionary<string, Order>("GetAllOrderWithLineItems", null, "PostalCode");
+
+            Assert.AreEqual(11, map.Count);
+            Order order = map["T4H 9G4"];
+
+            Assert.AreEqual(2, order.LineItemsIList.Count);
+        }
+
+        /// <summary>
+        /// Test ExecuteQueryForMap with value property :
+        /// "FirstName" as key, "EmailAddress" as value
+        /// </summary>
+        [Test]
+        public void TestExecuteQueryForDictionaryWithValueProperty()
+        {
+            IDictionary<string, string> map = sqlMap.QueryForDictionary<string, string>("GetAllAccountsViaResultClass", null, "FirstName", "EmailAddress");
+
+            Assert.AreEqual(5, map.Count);
+
+            Assert.AreEqual("Joe.Dalton@somewhere.com", map["Joe"]);
+            Assert.AreEqual("Averel.Dalton@somewhere.com", map["Averel"]);
+            Assert.IsNull(map["William"]);
+            Assert.AreEqual("Jack.Dalton@somewhere.com", map["Jack"]);
+            Assert.AreEqual("gilles.bayon@nospam.org", map["Gilles"]);
+        }
+
+        #endregion
     }
 }
 

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt?view=diff&rev=469607&r1=469606&r2=469607
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt Tue Oct 31 10:49:52 2006
@@ -9,6 +9,7 @@
 - IBATISNET-184 : Invalid support for public/protected field in result property
  
 Improvements/Changes
+- IBATISNET-192 : Add support for IDictionary<K, V> QueryForDictionary<K, V>(...)
 - IBATISNET-185 : Allow custom ISessionStore
 - IBATISNET-181 : Allow mapping of multiple result sets
 - IBATISNET-180 : Extends use of ISqlMapper in DataMapper + allow use of a custom ISqlMapper

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Delegates.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Delegates.cs?view=diff&rev=469607&r1=469606&r2=469607
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Delegates.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Delegates.cs Tue Oct 31 10:49:52 2006
@@ -32,9 +32,6 @@
 
 namespace IBatisNet.DataMapper
 {
-    //public class Delegates
-    //{
-    //}
     
     /// <summary>
     /// A delegate called once per row in the QueryWithRowDelegate method
@@ -52,6 +49,15 @@
     /// <param name="parameterObject">The optional parameter object passed into the QueryWithRowDelegate method.</param>
     /// <param name="list">The IList that will be returned to the caller.</param>
     public delegate void RowDelegate<T>(object obj, object parameterObject, IList<T> list);
+
+    /// <summary>
+    /// A delegate called once per row in the QueryForMapWithRowDelegate method
+    /// </summary>
+    /// <param name="key"></param>
+    /// <param name="value"></param>
+    /// <param name="parameterObject">The optional parameter object passed into the QueryForMapWithRowDelegate method.</param>
+    /// <param name="dictionary">The IDictionary that will be returned to the caller.</param>
+    public delegate void DictionaryRowDelegate<K, V>(K key, V value, object parameterObject, IDictionary<K, V> dictionary);
 #endif
 
     /// <summary>

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ISqlMapper.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ISqlMapper.cs?view=diff&rev=469607&r1=469606&r2=469607
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ISqlMapper.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ISqlMapper.cs Tue Oct 31 10:49:52 2006
@@ -364,6 +364,7 @@
         /// <returns>A List of result objects.</returns>
         IList QueryForList(string statementName, object parameterObject, int skipResults, int maxResults);
 
+
         /// <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 entire result object.
@@ -373,7 +374,7 @@
         /// <param name="keyProperty">The property of the result object to be used as the key.</param>
         /// <returns>A IDictionary (Hashtable) of object containing the rows keyed by keyProperty.</returns>
         IDictionary QueryForMap(string statementName, object parameterObject, string keyProperty);
-
+        
         /// <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
@@ -386,7 +387,7 @@
         /// <returns>A IDictionary (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>
         IDictionary QueryForMap(string statementName, object parameterObject, string keyProperty, string valueProperty);
-
+       
         /// <summary>
         /// Runs a query with a custom object that gets a chance to deal 
         /// with each row as it is processed.
@@ -476,6 +477,46 @@
 
 #if dotnet2
 
+        /// <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="statementName">The name of the sql statement to execute.</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 IDictionary 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>
+        IDictionary<K, V> QueryForDictionary<K, V>(string statementName, object parameterObject, string keyProperty, string valueProperty);
+
+        
+        /// <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 entire result object.
+        /// </summary>
+        /// <param name="statementName">The name of the sql statement to execute.</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>
+        /// <returns>A IDictionary of object containing the rows keyed by keyProperty.</returns>
+        IDictionary<K, V> QueryForDictionary<K, V>(string statementName, object parameterObject, string keyProperty);
+
+        /// <summary>
+        /// Runs a query with a custom object that gets a chance to deal 
+        /// with each row as it is processed.
+        /// <p/>
+        ///  The parameter object is generally used to supply the input
+        /// data for the WHERE clause parameter(s) of the SELECT statement.
+        /// </summary>
+        /// <param name="statementName">The name of the sql statement to execute.</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"A delegate called once per row in the QueryForDictionary method></param>
+        /// <returns>A IDictionary (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>
+        IDictionary<K, V> QueryForDictionary<K, V>(string statementName, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate<K, V> rowDelegate);
+                
         /// <summary>
         /// Executes a Sql SELECT statement that returns a single object of the type of the
         /// resultObject parameter.

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs?view=diff&rev=469607&r1=469606&r2=469607
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs Tue Oct 31 10:49:52 2006
@@ -137,9 +137,67 @@
 			return map;
 		}
 
-		
-		
-		/// <summary>
+        #region ExecuteQueryForMap .NET 2.0
+        #if dotnet2	  
+	    
+        /// <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<K, V> ExecuteQueryForDictionary<K, V>(IDalSession session, object parameterObject, string keyProperty, string valueProperty)
+        {
+            IDictionary<K, V> map = new Dictionary<K, V>();
+            RequestScope request = this.Statement.Sql.GetRequestScope(this, parameterObject, session);
+
+            _mappedStatement.PreparedCommand.Create(request, session, this.Statement, parameterObject);
+
+            CacheKey cacheKey = this.GetCacheKey(request);
+            cacheKey.Update("ExecuteQueryForMap");
+            if (keyProperty != null)
+            {
+                cacheKey.Update(keyProperty);
+            }
+            if (valueProperty != null)
+            {
+                cacheKey.Update(valueProperty);
+            }
+
+            map = this.Statement.CacheModel[cacheKey] as IDictionary<K, V>;
+            if (map == null)
+            {
+                map = _mappedStatement.RunQueryForDictionary<K, V>(request, session, parameterObject, keyProperty, valueProperty, null);
+                this.Statement.CacheModel[cacheKey] = map;
+            }
+
+            return map;
+        }
+
+        /// <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<K, V> ExecuteQueryForDictionary<K, V>(IDalSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate<K, V> rowDelegate)
+        {
+            return _mappedStatement.ExecuteQueryForDictionary<K, V>(session, parameterObject, keyProperty, valueProperty, rowDelegate);
+        }
+        #endif
+        #endregion
+        
+	    /// <summary>
 		/// Execute an update statement. Also used for delete statement.
 		/// Return the number of row effected.
 		/// </summary>

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs?view=diff&rev=469607&r1=469606&r2=469607
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/IMappedStatement.cs Tue Oct 31 10:49:52 2006
@@ -113,6 +113,38 @@
 
 		#endregion
 
+        #region ExecuteQueryForMap .NET 2.0
+#if dotnet2
+        /// <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 IDictionary 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<K, V> ExecuteQueryForDictionary<K, V>(IDalSession session, object parameterObject, string keyProperty, string valueProperty);
+
+        /// <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">A delegate called once per row in the QueryForDictionary method</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<K, V> ExecuteQueryForDictionary<K, V>(IDalSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate<K, V> rowDelegate);
+
+
+#endif
+        #endregion
+
 		#region ExecuteUpdate
 
 		/// <summary>
@@ -287,5 +319,7 @@
         IList<T> ExecuteQueryForRowDelegate<T>(IDalSession session, object parameterObject, RowDelegate<T> rowDelegate);
 #endif
         #endregion
+	    
+	    
     }
 }

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs?view=diff&rev=469607&r1=469606&r2=469607
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs Tue Oct 31 10:49:52 2006
@@ -929,17 +929,14 @@
         ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
         public virtual IDictionary ExecuteQueryForMap(IDalSession session, object parameterObject, string keyProperty, string valueProperty)
         {
-            IDictionary map = new Hashtable();
             RequestScope request = _statement.Sql.GetRequestScope(this, parameterObject, session);
 
             _preparedCommand.Create(request, session, this.Statement, parameterObject);
 
-            map = RunQueryForMap(request, session, parameterObject, keyProperty, valueProperty, null);
-
-            return map;
+            return RunQueryForMap(request, session, parameterObject, keyProperty, valueProperty, null);
         }
 
-
+       
         /// <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
@@ -950,7 +947,7 @@
         /// <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>
+        /// <param name="rowDelegate">A delegate called once per row in the QueryForMapWithRowDelegate method</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>
         internal IDictionary RunQueryForMap(RequestScope request,
@@ -1012,7 +1009,133 @@
 
         }
 
+#if dotnet2
+        /// <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 IDictionary 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 virtual IDictionary<K, V> ExecuteQueryForDictionary<K, V>(IDalSession session, object parameterObject, string keyProperty, string valueProperty)
+        {
+            RequestScope request = _statement.Sql.GetRequestScope(this, parameterObject, session);
+
+            _preparedCommand.Create(request, session, this.Statement, parameterObject);
+
+            return RunQueryForDictionary<K, V>(request, session, parameterObject, keyProperty, valueProperty, null);
+
+        }
+
+        /// <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">A delegate called once per row in the QueryForDictionary method</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 virtual IDictionary<K, V> ExecuteQueryForDictionary<K, V>(IDalSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate<K, V> rowDelegate)
+        {
+            RequestScope request = _statement.Sql.GetRequestScope(this, parameterObject, session);
+
+            if (rowDelegate == null)
+            {
+                throw new DataMapperException("A null DictionaryRowDelegate was passed to QueryForDictionary.");
+            }
+
+            _preparedCommand.Create(request, session, this.Statement, parameterObject);
+
+            return RunQueryForDictionary<K, V>(request, session, parameterObject, keyProperty, valueProperty, rowDelegate);
+        }
+
+        /// <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="request">The request scope.</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="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">A delegate called once per row in the QueryForMapWithRowDelegate method</param>
+        /// <returns>A IDictionary 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>
+        internal IDictionary<K, V> RunQueryForDictionary<K, V>(RequestScope request,
+            IDalSession session,
+            object parameterObject,
+            string keyProperty,
+            string valueProperty,
+            DictionaryRowDelegate<K, V> rowDelegate)
+        {
+            IDictionary<K, V> map = new Dictionary<K, V>();
+
+            using (IDbCommand command = request.IDbCommand)
+            {
+                IDataReader reader = command.ExecuteReader();
+                try
+                {
 
+                    if (rowDelegate == null)
+                    {
+                        while (reader.Read())
+                        {
+                            object obj = _resultStrategy.Process(request, ref reader, null);
+                            K key = (K)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
+                            V value = default(V);
+                            if (valueProperty != null)
+                            {
+                                value = (V)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
+                            }
+                            else
+                            {
+                                value = (V)obj;
+                            }
+                            map.Add(key, value);
+                        }
+                    }
+                    else
+                    {
+                        while (reader.Read())
+                        {
+                            object obj = _resultStrategy.Process(request, ref reader, null);
+                            K key = (K)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
+                            V value = default(V);
+                            if (valueProperty != null)
+                            {
+                                value = (V)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
+                            }
+                            else
+                            {
+                                value = (V)obj;
+                            }
+                            rowDelegate(key, value, parameterObject, map);
+                        }
+                    }
+                }
+                catch
+                {
+                    throw;
+                }
+                finally
+                {
+                    reader.Close();
+                    reader.Dispose();
+                }
+            }
+            return map;
+
+        }
+#endif
+        
         #endregion
 
 

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs?view=diff&rev=469607&r1=469606&r2=469607
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs Tue Oct 31 10:49:52 2006
@@ -900,6 +900,112 @@
         
         #region QueryForList .NET 2.0
 #if dotnet2
+	    
+	            /// <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="statementName">The name of the sql statement to execute.</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 IDictionary 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 IDictionary<K, V> QueryForDictionary<K, V>(string statementName, object parameterObject, string keyProperty, string valueProperty)
+        {
+            bool isSessionLocal = false;
+            IDalSession session = _sessionStore.LocalSession;
+            IDictionary<K, V> map = null;
+
+            if (session == null)
+            {
+                session = CreateSqlMapSession();
+                session.OpenConnection();
+                isSessionLocal = true;
+            }
+
+            try
+            {
+                IMappedStatement statement = GetMappedStatement(statementName);
+                map = statement.ExecuteQueryForDictionary<K, V>(session, parameterObject, keyProperty, valueProperty);
+            }
+            catch
+            {
+                throw;
+            }
+            finally
+            {
+                if (isSessionLocal)
+                {
+                    session.CloseConnection();
+                }
+            }
+
+            return map;
+        }
+	    
+	    /// <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 entire result object.
+        /// </summary>
+        /// <param name="statementName">The name of the sql statement to execute.</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>
+        /// <returns>A IDictionary of object containing the rows keyed by keyProperty.</returns>
+        public IDictionary<K, V> QueryForDictionary<K, V>(string statementName, object parameterObject, string keyProperty)
+        {
+            return QueryForDictionary<K, V>(statementName, parameterObject, keyProperty, null);
+        }
+
+        /// <summary>
+        /// Runs a query with a custom object that gets a chance to deal 
+        /// with each row as it is processed.
+        /// <p/>
+        ///  The parameter object is generally used to supply the input
+        /// data for the WHERE clause parameter(s) of the SELECT statement.
+        /// </summary>
+        /// <param name="statementName">The name of the sql statement to execute.</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"A delegate called once per row in the QueryForDictionary method></param>
+        /// <returns>A IDictionary (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 IDictionary<K, V> QueryForDictionary<K, V>(string statementName, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate<K, V> rowDelegate)
+        {
+            bool isSessionLocal = false;
+            IDalSession session = _sessionStore.LocalSession;
+            IDictionary<K, V> map = null;
+
+            if (session == null)
+            {
+                session = CreateSqlMapSession();
+                session.OpenConnection();
+                isSessionLocal = true;
+            }
+
+            try
+            {
+                IMappedStatement statement = GetMappedStatement(statementName);
+                map = statement.ExecuteQueryForDictionary<K, V>(session, parameterObject, keyProperty, valueProperty, rowDelegate);
+            }
+            catch
+            {
+                throw;
+            }
+            finally
+            {
+                if (isSessionLocal)
+                {
+                    session.CloseConnection();
+                }
+            }
+
+            return map;
+        }
+	    
+	    
         /// <summary>
         /// Executes a Sql SELECT statement that returns data to populate
         /// a number of result objects.