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/11/02 21:46:15 UTC

svn commit: r470514 [2/2] - in /ibatis/trunk/cs/mapper: ./ IBatisNet.Common/Utilities/ IBatisNet.DataMapper.Test/ IBatisNet.DataMapper.Test/Domain/ IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ IBatisNet.D...

Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs?view=auto&rev=470514
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs Thu Nov  2 12:46:13 2006
@@ -0,0 +1,74 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 374175 $
+ * $LastChangedDate$
+ * $LastChangedBy$
+ * 
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2006/2005 - The Apache Software Foundation
+ *  
+ * 
+ * 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.Data;
+using IBatisNet.DataMapper.Configuration.ResultMapping;
+using IBatisNet.DataMapper.Scope;
+
+namespace IBatisNet.DataMapper.MappedStatements.ResultStrategy
+{
+    /// <summary>
+    /// Delegates on the <see cref="ResultMapStrategy"/>  or on the 
+    /// <see cref="GroupByStrategy"/> implementation if a grouBy attribute is specify on the resultMap tag.
+    /// </summary>
+    public sealed class MapStrategy : IResultStrategy
+    {
+        private static IResultStrategy _resultMapStrategy = null;
+        private static IResultStrategy _groupByStrategy = null;
+
+        /// <summary>
+        /// Initializes the <see cref="MapStrategy"/> class.
+        /// </summary>
+        static MapStrategy()
+        {
+            _resultMapStrategy = new ResultMapStrategy();
+            _groupByStrategy = new GroupByStrategy();
+        }
+        
+        #region IResultStrategy Members
+
+        /// <summary>
+        /// Processes the specified <see cref="IDataReader"/>.
+        /// </summary>
+        /// <param name="request">The request.</param>
+        /// <param name="reader">The reader.</param>
+        /// <param name="resultObject">The result object.</param>
+        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
+        {
+            IResultMap resultMap = request.CurrentResultMap.ResolveSubMap(reader);
+
+            if (resultMap.GroupByProperties.Count>0)
+            {
+                return _groupByStrategy.Process(request, ref reader, resultObject);
+            }
+            else
+            {
+                return _resultMapStrategy.Process(request, ref reader, resultObject);
+            }
+        }
+
+        #endregion
+    }
+}

Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
------------------------------------------------------------------------------
    svn:keywords = Id LastChangedDate LastChangedBy

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultStrategyFactory.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultStrategyFactory.cs?view=diff&rev=470514&r1=470513&r2=470514
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultStrategyFactory.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ResultStrategy/ResultStrategyFactory.cs Thu Nov  2 12:46:13 2006
@@ -34,7 +34,7 @@
     public sealed class ResultStrategyFactory
     {
         private static IResultStrategy _resultClassStrategy = null;
-        private static IResultStrategy _resultMapStrategy = null;
+        private static IResultStrategy _mapStrategy = null;
         private static IResultStrategy _objectStrategy = null;
 
         /// <summary>
@@ -42,7 +42,7 @@
         /// </summary>
         static ResultStrategyFactory()
         {
-            _resultMapStrategy = new ResultMapStrategy();
+            _mapStrategy = new MapStrategy();
             _resultClassStrategy = new ResultClassStrategy();
             _objectStrategy = new ObjectStrategy();
         }
@@ -54,12 +54,12 @@
         /// <returns>The <see cref="IResultStrategy"/></returns>
         public static IResultStrategy Get(IStatement statement)
         {
-            // If there's an ResultMap, use it
+            // If there's an IResultMap, use it
             if (statement.ResultsMap.Count > 0)
             {
                 if (statement.ResultsMap[0] is ResultMap)
                 {
-                    return _resultMapStrategy; 
+                    return _mapStrategy; 
                 }
                 else // it is an AutoResultMap
                 {

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Proxy/LazyListGeneric.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Proxy/LazyListGeneric.cs?view=diff&rev=470514&r1=470513&r2=470514
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Proxy/LazyListGeneric.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Proxy/LazyListGeneric.cs Thu Nov  2 12:46:13 2006
@@ -25,7 +25,6 @@
 
 using System;
 using System.Collections.Generic;
-using System.Text;
 using System.Collections;
 using System.Reflection;
 
@@ -57,7 +56,7 @@
         #endregion
 
         /// <summary>
-        /// Initializes a new instance of the <see cref="T:LazyListGeneric&lt;T&gt;"/> class.
+        /// Initializes a new instance of the <see cref="LazyListGeneric<T>"/> class.
         /// </summary>
         /// <param name="mappedSatement">The mapped satement.</param>
         /// <param name="param">The param.</param>
@@ -147,7 +146,7 @@
         }
 
         /// <summary>
-        /// Gets or sets the <see cref="T:T"/> at the specified index.
+        /// Gets or sets the <see cref="T"/> at the specified index.
         /// </summary>
         /// <value></value>
         public T this[int index]
@@ -159,7 +158,7 @@
             }
             set
             {
-                Load("IndexOf");
+                Load("this");
                 _list[index] = value;
             }
         }
@@ -262,7 +261,7 @@
         /// Returns an enumerator that iterates through the collection.
         /// </summary>
         /// <returns>
-        /// A <see cref="T:System.Collections.Generic.IEnumerator`1"></see> that can be used to iterate through the collection.
+        /// A <see cref="System.Collections.Generic.IEnumerator`1"></see> that can be used to iterate through the collection.
         /// </returns>
         public IEnumerator<T> GetEnumerator()
         {
@@ -278,7 +277,7 @@
         /// Returns an enumerator that iterates through a collection.
         /// </summary>
         /// <returns>
-        /// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
+        /// An <see cref="System.Collections.IEnumerator"></see> object that can be used to iterate through the collection.
         /// </returns>
         IEnumerator IEnumerable.GetEnumerator()
         {
@@ -397,13 +396,14 @@
         }
 
         /// <summary>
-        /// Gets or sets the <see cref="T:Object"/> at the specified index.
+        /// Gets or sets the <see cref="Object"/> at the specified index.
         /// </summary>
         /// <value></value>
         object IList.this[int index]
         {
             get
             {
+                Load("this");
                 return this[index];
             }
             set
@@ -418,14 +418,14 @@
         #region ICollection Members
 
         /// <summary>
-        /// Copies the elements of the <see cref="T:System.Collections.ICollection"></see> to an <see cref="T:System.Array"></see>, starting at a particular <see cref="T:System.Array"></see> index.
+        /// Copies the elements of the <see cref="System.Collections.ICollection"></see> to an <see cref="System.Array"></see>, starting at a particular <see cref="T:System.Array"></see> index.
         /// </summary>
         /// <param name="array">The one-dimensional <see cref="T:System.Array"></see> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"></see>. The <see cref="T:System.Array"></see> must have zero-based indexing.</param>
         /// <param name="index">The zero-based index in array at which copying begins.</param>
         /// <exception cref="T:System.ArgumentNullException">array is null. </exception>
         /// <exception cref="T:System.ArgumentOutOfRangeException">index is less than zero. </exception>
         /// <exception cref="T:System.ArgumentException">array is multidimensional.-or- index is equal to or greater than the length of array.-or- The number of elements in the source <see cref="T:System.Collections.ICollection"></see> is greater than the available space from index to the end of the destination array. </exception>
-        /// <exception cref="T:System.InvalidCastException">The type of the source <see cref="T:System.Collections.ICollection"></see> cannot be cast automatically to the type of the destination array. </exception>
+        /// <exception cref="T:System.InvalidCastException">The type of the source <see cref="System.Collections.ICollection"></see> cannot be cast automatically to the type of the destination array. </exception>
         void ICollection.CopyTo(Array array, int index)
         {
             Load("CopyTo");
@@ -433,17 +433,17 @@
         }
 
         /// <summary>
-        /// Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"></see>.
+        /// Gets the number of elements contained in the <see cref="System.Collections.Generic.ICollection`1"></see>.
         /// </summary>
         /// <value></value>
-        /// <returns>The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</returns>
+        /// <returns>The number of elements contained in the <see cref="System.Collections.Generic.ICollection`1"></see>.</returns>
         int ICollection.Count
         {
             get { return this.Count; }
         }
 
         /// <summary>
-        /// Gets a value indicating whether access to the <see cref="T:System.Collections.ICollection"></see> is synchronized (thread safe).
+        /// Gets a value indicating whether access to the <see cref="System.Collections.ICollection"></see> is synchronized (thread safe).
         /// </summary>
         /// <value></value>
         /// <returns>true if access to the <see cref="T:System.Collections.ICollection"></see> is synchronized (thread safe); otherwise, false.</returns>
@@ -453,10 +453,10 @@
         }
 
         /// <summary>
-        /// Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"></see>.
+        /// Gets an object that can be used to synchronize access to the <see cref="System.Collections.ICollection"></see>.
         /// </summary>
         /// <value></value>
-        /// <returns>An object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"></see>.</returns>
+        /// <returns>An object that can be used to synchronize access to the <see cref="System.Collections.ICollection"></see>.</returns>
         object ICollection.SyncRoot
         {
             get { return this; }

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs?view=diff&rev=470514&r1=470513&r2=470514
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs Thu Nov  2 12:46:13 2006
@@ -45,6 +45,9 @@
     /// </summary>
     public class RequestScope : IScope
     {
+        // Used by N+1 Select solution
+        public static object SKIP = new object();
+
         #region Fields
 
         private IStatement _statement = null;
@@ -60,11 +63,45 @@
         private IDalSession _session = null;
         private IMappedStatement _mappedStatement = null;
         private int _currentResultMapIndex = -1;
+        // Used by N+1 Select solution
+        // Holds [IResultMap, IDictionary] couple where the IDictionary holds [key, result object]
+        private IDictionary  _uniqueKeys = null;
 
         #endregion
 
         #region Properties
 
+        /// <summary>
+        /// Gets the unique keys.
+        /// </summary>
+        /// <param name="map">The ResultMap.</param>
+        /// <returns>
+        /// Returns [key, result object] which holds the result objects that have  
+        /// already been build during this request with this <see cref="IResultMap"/>
+        /// </returns>
+        public IDictionary GetUniqueKeys(IResultMap map)
+        {
+            if (_uniqueKeys == null)
+            {
+                return null;
+            }
+            return (IDictionary)_uniqueKeys[map];
+        }
+
+        /// <summary>
+        /// Sets the unique keys.
+        /// </summary>
+        /// <param name="map">The map.</param>
+        /// <param name="keys">The keys.</param>
+        public void SetUniqueKeys(IResultMap map, IDictionary keys)
+        {
+            if (_uniqueKeys == null)
+            {
+                _uniqueKeys = new Hashtable();
+            }
+            _uniqueKeys.Add(map, keys);
+        }
+        
         /// <summary>
         ///  The current <see cref="IMappedStatement"/>.
         /// </summary>

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd?view=diff&rev=470514&r1=470513&r2=470514
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd Thu Nov  2 12:46:13 2006
@@ -646,6 +646,7 @@
 			<xs:attribute name="id" type="xs:string" use="required"/>
 			<xs:attribute name="class" type="xs:string" use="required"/>
 			<xs:attribute name="extends" type="xs:string"/>
+			<xs:attribute name="groupBy" type="xs:string"/>
 		</xs:complexType>
 	</xs:element>
 	<xs:element name="resultMaps">