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 2007/02/19 19:19:05 UTC

svn commit: r509283 - in /ibatis/trunk/cs/mapper/IBatisNet.DataMapper: ./ Configuration/ResultMapping/ MappedStatements/PropertStrategy/

Author: gbayon
Date: Mon Feb 19 10:19:04 2007
New Revision: 509283

URL: http://svn.apache.org/viewvc?view=rev&rev=509283
Log:
Refactoring Discriminator support with groupby attribute

Added:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs   (with props)
Modified:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs

Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs?view=auto&rev=509283
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs Mon Feb 19 10:19:04 2007
@@ -0,0 +1,163 @@
+#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;
+using System.Collections.Specialized;
+using IBatisNet.DataMapper.DataExchange;
+
+namespace IBatisNet.DataMapper.Configuration.ResultMapping
+{
+    /// <summary>
+    /// 
+    /// </summary>
+    public class NullResultMap : IResultMap
+    {
+ 
+        #region Fields
+        [NonSerialized]
+        private StringCollection _groupByProperties = new StringCollection();
+        [NonSerialized]
+        private ResultPropertyCollection _properties = new ResultPropertyCollection();
+        [NonSerialized]
+        private ResultPropertyCollection _parameters = new ResultPropertyCollection();
+
+        #endregion
+
+        #region Properties
+
+        /// <summary>
+        /// The GroupBy Properties.
+        /// </summary>
+        public StringCollection GroupByProperties
+        {
+            get { return _groupByProperties; }
+        }
+
+        /// <summary>
+        /// Gets or sets a value indicating whether this instance is initalized.
+        /// </summary>
+        /// <value>
+        /// 	<c>true</c> if this instance is initalized; otherwise, <c>false</c>.
+        /// </value>
+        public bool IsInitalized
+        {
+            get { throw new Exception("The method or operation is not implemented."); }
+            set { throw new Exception("The method or operation is not implemented."); }
+        }
+
+        /// <summary>
+        /// The discriminator used to choose the good SubMap
+        /// </summary>
+        public Discriminator Discriminator
+        {
+            get { throw new Exception("The method or operation is not implemented."); }
+            set { throw new Exception("The method or operation is not implemented."); }
+        }
+
+        /// <summary>
+        /// The collection of ResultProperty.
+        /// </summary>
+        public ResultPropertyCollection Properties
+        {
+            get { return _properties; }
+        }
+
+        /// <summary>
+        /// The collection of constructor parameters.
+        /// </summary>
+        public ResultPropertyCollection Parameters
+        {
+            get { return _parameters; }
+        }
+
+        /// <summary>
+        /// Identifier used to identify the resultMap amongst the others.
+        /// </summary>
+        /// <example>GetProduct</example>
+        public string Id
+        {
+            get { return "NullResultMap.Id"; }
+        }
+
+        /// <summary>
+        /// Extend ResultMap attribute
+        /// </summary>
+        public string ExtendMap
+        {
+            get { throw new Exception("The method or operation is not implemented."); }
+            set { throw new Exception("The method or operation is not implemented."); }
+        }
+
+        /// <summary>
+        /// The output type class of the resultMap.
+        /// </summary>
+        public Type Class
+        {
+            get { throw new Exception("The method or operation is not implemented."); }
+        }
+
+
+        /// <summary>
+        /// Sets the IDataExchange
+        /// </summary>
+        public IDataExchange DataExchange
+        {
+            set { throw new Exception("The method or operation is not implemented."); }
+        }
+        #endregion
+
+        /// <summary>
+        /// Create an instance Of result.
+        /// </summary>
+        /// <param name="parameters">An array of values that matches the number, order and type
+        /// of the parameters for this constructor.</param>
+        /// <returns>An object.</returns>
+        public object CreateInstanceOfResult(object[] parameters)
+        {
+            return null;
+        }
+
+        /// <summary>
+        /// Set the value of an object property.
+        /// </summary>
+        /// <param name="target">The object to set the property.</param>
+        /// <param name="property">The result property to use.</param>
+        /// <param name="dataBaseValue">The database value to set.</param>
+        public void SetValueOfProperty(ref object target, ResultProperty property, object dataBaseValue)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+        /// <summary>
+        /// </summary>
+        /// <param name="dataReader"></param>
+        /// <returns></returns>
+        public IResultMap ResolveSubMap(System.Data.IDataReader dataReader)
+        {
+            throw new Exception("The method or operation is not implemented.");
+        }
+
+    }
+}

Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/NullResultMap.cs
------------------------------------------------------------------------------
    svn:keywords = Id LastChangedDate LastChangedBy

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs?view=diff&rev=509283&r1=509282&r2=509283
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs Mon Feb 19 10:19:04 2007
@@ -76,6 +76,8 @@
 		/// </summary>
 		private const string XML_SUBMAP = "subMap";
 
+        private static IResultMap _nullResultMap = null;
+
 		#region Fields
         [NonSerialized]
         private bool _isInitalized = true;
@@ -210,6 +212,8 @@
         /// <param name="groupBy">The groupBy properties</param>
         public ResultMap(ConfigurationScope configScope, string id, string className, string extendMap, string groupBy)
 		{
+            _nullResultMap = new NullResultMap();
+
             _dataExchangeFactory = configScope.DataExchangeFactory;
             _sqlMapNameSpace = configScope.SqlMapNamespace;
             if ((id == null) || (id.Length < 1))
@@ -453,7 +457,7 @@
                 }
                 else
                 {
-                    subMap = null;
+                    subMap = _nullResultMap;
                 }
 			}
 			return subMap;

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj?view=diff&rev=509283&r1=509282&r2=509283
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj Mon Feb 19 10:19:04 2007
@@ -157,6 +157,7 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="Configuration\ResultMapping\IResultMap.cs" />
+    <Compile Include="Configuration\ResultMapping\NullResultMap.cs" />
     <Compile Include="Configuration\ResultMapping\ResultMap.cs">
       <SubType>Code</SubType>
     </Compile>

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs?view=diff&rev=509283&r1=509282&r2=509283
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs Mon Feb 19 10:19:04 2007
@@ -98,45 +98,42 @@
             object result = null;
             IResultMap propertyRresultMap = mapping.NestedResultMap.ResolveSubMap(reader);
 
-            if (propertyRresultMap!=null)
+            if (propertyRresultMap.GroupByProperties.Count>0)
             {
-                if (propertyRresultMap.GroupByProperties.Count>0)
+                 string uniqueKey = GetUniqueKey(propertyRresultMap, request, reader);
+                // Gets the [key, result object] already build
+                IDictionary buildObjects = request.GetUniqueKeys(propertyRresultMap);
+                if (buildObjects != null && buildObjects.Contains(uniqueKey))
                 {
-                     string uniqueKey = GetUniqueKey(propertyRresultMap, request, reader);
-                    // Gets the [key, result object] already build
-                    IDictionary buildObjects = request.GetUniqueKeys(propertyRresultMap);
-                    if (buildObjects != null && buildObjects.Contains(uniqueKey))
+                    // Unique key is already known, so get the existing result object and process additional results.
+                    result = buildObjects[uniqueKey];
+                    // process resulMapping attribute which point to a groupBy attribute
+                    for (int index = 0; index < propertyRresultMap.Properties.Count; index++)
                     {
-                        // Unique key is already known, so get the existing result object and process additional results.
-                        result = buildObjects[uniqueKey];
-                        // process resulMapping attribute which point to a groupBy attribute
-                        for (int index = 0; index < propertyRresultMap.Properties.Count; index++)
+                        ResultProperty resultProperty = propertyRresultMap.Properties[index];
+                        if (resultProperty.PropertyStrategy is PropertStrategy.GroupByStrategy)
                         {
-                            ResultProperty resultProperty = propertyRresultMap.Properties[index];
-                            if (resultProperty.PropertyStrategy is PropertStrategy.GroupByStrategy)
-                            {
-                                resultProperty.PropertyStrategy.Set(request, propertyRresultMap, resultProperty, ref result, reader, null);
-                            }
+                            resultProperty.PropertyStrategy.Set(request, propertyRresultMap, resultProperty, ref result, reader, null);
                         }
-                        result = SKIP;
                     }
-                    else if (uniqueKey == null || buildObjects == null || !buildObjects.Contains(uniqueKey))
-                    {
-                        result = _resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
-
-                        if (buildObjects == null)
-                        {
-                            buildObjects = new Hashtable();
-                            request.SetUniqueKeys(propertyRresultMap, buildObjects);
-                        }
-                        buildObjects[uniqueKey] = result;
-                    }               
+                    result = SKIP;
                 }
-                else // Last resultMap have no groupBy attribute
+                else if (uniqueKey == null || buildObjects == null || !buildObjects.Contains(uniqueKey))
                 {
                     result = _resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
-                }                
+
+                    if (buildObjects == null)
+                    {
+                        buildObjects = new Hashtable();
+                        request.SetUniqueKeys(propertyRresultMap, buildObjects);
+                    }
+                    buildObjects[uniqueKey] = result;
+                }               
             }
+            else // Last resultMap have no groupBy attribute
+            {
+                result = _resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);
+            }                
 
             
             if ((result != null) && (result != SKIP))

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs?view=diff&rev=509283&r1=509282&r2=509283
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs Mon Feb 19 10:19:04 2007
@@ -23,7 +23,6 @@
  ********************************************************************************/
 #endregion
 
-using System;
 using System.Data;
 using IBatisNet.DataMapper.Configuration.ResultMapping;
 using IBatisNet.DataMapper.Scope;