Author: gbayon
Date: Thu Jun 12 10:55:57 2008
New Revision: 667183

URL: http://svn.apache.org/viewvc?rev=667183&view=rev
Log:
Refactor IBATISNET-272

Added:
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataRowStrategy.cs
      - copied, changed from r666779, 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataTableStrategy.cs
Removed:
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataTableStrategy.cs
Modified:
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/BaseStatementDeSerializer.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/ResultMapDeSerializer.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/ResultClassStrategy.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultProperty.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/TypeHandlers/TypeHandlerFactory.cs

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs
 Thu Jun 12 10:55:57 2008
@@ -131,13 +131,17 @@
                public const string HashtableAlias3 = "hashmap";
 
         /// <summary>
-        /// The alias around the 'DataTable' type.
+        /// The alias around the 'DataRow' type.
         /// </summary>
-        public const string DataTableAlias1 = "datatable";
+        public const string DataRowAlias1 = "datarow";
         /// <summary>
-        /// Another alias around the 'DataTable' type.
+        /// Another alias around the 'DataRow' type.
         /// </summary>
-        public const string DataTableAlias2 = "data";
+        public const string DataRowAlias2 = "data";
+        /// <summary>
+        /// Another alias around the 'DataRow' type.
+        /// </summary>
+        public const string DataRowAlias3 = "row";
 
                /// <summary>
                /// The alias around the 'short' type.
@@ -348,8 +352,9 @@
         static TypeRegistry()
                {
                        // Initialize a dictionary with some fully qualifiaed 
name 
-            types[DataTableAlias1] = typeof(DataTable);
-            types[DataTableAlias2] = typeof(DataTable);
+            types[DataRowAlias1] = typeof(DataRow);
+            types[DataRowAlias2] = typeof(DataRow);
+            types[DataRowAlias2] = typeof(DataRow);
 
                        types[ArrayListAlias1] = typeof (ArrayList);
                        types[ArrayListAlias2] = typeof (ArrayList);

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
 Thu Jun 12 10:55:57 2008
@@ -50,7 +50,6 @@
         public void QueryForDatatable_with_resulclass_should_work()
         {
             DataTable dataTable = 
dataMapper.QueryForDataTable("SimpleAccountDataTable", 1);
-
             DataRow[] currentRows = dataTable.Select(null, null, 
DataViewRowState.CurrentRows);
 
             //if (currentRows.Length < 1)

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
 Thu Jun 12 10:55:57 2008
@@ -31,8 +31,8 @@
        
        <resultMaps>
 
-    <resultMap id="Account-result-DataTable" class="dataTable">
-      <result property="Id"           column="Account_ID"/>
+    <resultMap id="Account-result-DataRow" class="dataRow">
+      <result property="Id" type="int"           column="Account_ID"/>
       <result property="FirstName"    column="Account_FirstName"/>
     </resultMap>
     
@@ -146,7 +146,7 @@
   <statements>
 
     <!-- Query for DataTable -->
-    <select id="SimpleAccountDataTableViaResultMap" parameterClass="int" 
resultMap="Account-result-DataTable">
+    <select id="SimpleAccountDataTableViaResultMap" parameterClass="int" 
resultMap="Account-result-DataRow">
       select *
       from Accounts
     </select>

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj
 Thu Jun 12 10:55:57 2008
@@ -120,7 +120,7 @@
     <Compile Include="Configuration\Module\ResultMapModuleBuilder.cs" />
     <Compile Include="Configuration\Module\TypeAliasModuleBuilder.cs" />
     <Compile Include="Configuration\Module\TypeHandlerModuleBuilder.cs" />
-    <Compile Include="MappedStatements\ResultStrategy\DataTableStrategy.cs" />
+    <Compile Include="MappedStatements\ResultStrategy\DataRowStrategy.cs" />
     <Compile Include="Session\DataMapperLocalSessionScope.cs" />
     <Compile Include="IMapperFactory.cs" />
     <Compile 
Include="Configuration\Interpreters\Config\AbstractInterpreter.cs" />

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/BaseStatementDeSerializer.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/BaseStatementDeSerializer.cs?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/BaseStatementDeSerializer.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/BaseStatementDeSerializer.cs
 Thu Jun 12 10:55:57 2008
@@ -26,6 +26,7 @@
 #region Using
 
 using System;
+using System.Data;
 using Apache.Ibatis.Common.Configuration;
 using Apache.Ibatis.Common.Utilities.Objects;
 using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
@@ -106,7 +107,7 @@
                     resultClass = 
modelStore.DataExchangeFactory.TypeHandlerFactory.GetType(classNames[i].Trim());
                     IFactory resultClassFactory = null;
                     if (Type.GetTypeCode(resultClass) == TypeCode.Object &&
-                        (resultClass.IsValueType == false))
+                        (resultClass.IsValueType == false) && resultClass != 
typeof(DataRow))
                     {
                         resultClassFactory = 
modelStore.DataExchangeFactory.ObjectFactory.CreateFactory(resultClass, 
Type.EmptyTypes);
                     }

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/ResultMapDeSerializer.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/ResultMapDeSerializer.cs?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/ResultMapDeSerializer.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/ResultMapDeSerializer.cs
 Thu Jun 12 10:55:57 2008
@@ -35,6 +35,7 @@
 using Apache.Ibatis.DataMapper.DataExchange;
 using Apache.Ibatis.DataMapper.Exceptions;
 using Apache.Ibatis.DataMapper.Model.ResultMapping;
+using System.Data;
 
 #endregion 
 
@@ -118,7 +119,7 @@
             }
             else
             {
-                if (!dataExchangeFactory.TypeHandlerFactory.IsSimpleType(type))
+                if (!dataExchangeFactory.TypeHandlerFactory.IsSimpleType(type) 
&& type!=typeof(DataRow))
                 {
                     factory = 
dataExchangeFactory.ObjectFactory.CreateFactory(type, Type.EmptyTypes);
                 }

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/MappedStatement.cs
 Thu Jun 12 10:55:57 2008
@@ -38,6 +38,7 @@
 using Apache.Ibatis.DataMapper.Model;
 using Apache.Ibatis.DataMapper.Model.Events;
 using Apache.Ibatis.DataMapper.Model.ParameterMapping;
+using Apache.Ibatis.DataMapper.Model.ResultMapping;
 using Apache.Ibatis.DataMapper.Model.Statements;
 using Apache.Ibatis.DataMapper.MappedStatements.ResultStrategy;
 using Apache.Ibatis.DataMapper.Scope;
@@ -1038,7 +1039,7 @@
         /// <returns></returns>
         internal DataTable RunQueryForForDataTable(RequestScope request, 
ISession session, object parameterObject)
         {
-            DataTable dataTable = null;
+            DataTable dataTable = new DataTable("DataTable"); ;
 
             using (IDbCommand command = request.IDbCommand)
             {
@@ -1049,7 +1050,9 @@
                     // Get Results
                     while (reader.Read())
                     {
-                        dataTable = (DataTable)resultStrategy.Process(request, 
ref reader, dataTable);
+                        DataRow dataRow = dataTable.NewRow();
+                        dataTable.Rows.Add(dataRow);
+                        resultStrategy.Process(request, ref reader, dataRow);
                     }
                 }
                 finally

Copied: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataRowStrategy.cs
 (from r666779, 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataTableStrategy.cs)
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataRowStrategy.cs?p2=ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataRowStrategy.cs&p1=ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataTableStrategy.cs&r1=666779&r2=667183&rev=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataTableStrategy.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/DataRowStrategy.cs
 Thu Jun 12 10:55:57 2008
@@ -34,9 +34,9 @@
     /// <summary>
     /// <see cref="IResultStrategy"/> implementation when 
     /// a 'resultClass' attribute is specified and
-    /// the type of the result object is <see cref="DataTable"/>.
+    /// the type of the result object is <see cref="DataRow"/>.
     /// </summary>
-    public class DataTableStrategy : IResultStrategy
+    public class DataRowStrategy : IResultStrategy
     {
         #region IResultStrategy Members
 
@@ -50,11 +50,13 @@
         public object Process(RequestScope request, ref IDataReader reader, 
object resultObject)
         {
             IResultMap resultMap = 
request.CurrentResultMap.ResolveSubMap(reader);
-            DataTable dataTable = resultObject as DataTable;
-
-            if (dataTable == null)
+            DataRow dataRow = (DataRow)resultObject;
+            DataTable dataTable = dataRow.Table;
+            
+            if (dataTable.Columns.Count==0)
             {
-                dataTable = new DataTable(resultMap.Id);
+                // Builds and adss the columns
+                dataTable.TableName = resultMap.Id;
                 if (resultMap is AutoResultMap)
                 {
                     for (int index = 0; index < reader.FieldCount; index++)
@@ -76,19 +78,31 @@
                         DataColumn column = new DataColumn();
                         if (property.CLRType.Length > 0)
                         {
-                            column.DataType = property.MemberType;
+                            column.DataType = 
request.DataExchangeFactory.TypeHandlerFactory.GetType(property.CLRType);
+                        }
+                        else
+                        {
+                            object value = property.GetDataBaseValue(reader);
+                            if (value == null)
+                            {
+                                int columnIndex = 
reader.GetOrdinal(property.ColumnName);
+                                column.DataType = 
reader.GetFieldType(columnIndex);
+                            }  
+                            else
+                            {
+                                column.DataType = value.GetType();
+                            }
                         }
-                        //column.DataType = 
reader.GetFieldType(reader.GetOrdinal(property.PropertyName));
                         column.ColumnName = property.PropertyName;
+
                         dataTable.Columns.Add(column);
                     }
                 }
             }
 
-            DataRow row = null;
+           
             if (resultMap is AutoResultMap)
             {
-                row = dataTable.NewRow();
                 for (int index = 0; index < reader.FieldCount; index++)
                 {
                     string propertyName = reader.GetName(index);
@@ -106,7 +120,7 @@
                         string.Empty,
                         null,
                         string.Empty,
-                        typeof(DataTable),
+                        typeof(DataRow),
                         request.DataExchangeFactory,
                         typeHandler);
 
@@ -115,22 +129,11 @@
                     {
                         value = DBNull.Value;
                     }
-                    row[property.PropertyName] = value;
+                    dataRow[property.PropertyName] = value;
                 }
             }
             else
             {
-                // We must set the DataType before adding any data to the 
DataTable
-                for (int index = 0; index < resultMap.Properties.Count; 
index++)
-                {
-                    ResultProperty property = resultMap.Properties[index];
-                    object value = property.GetDataBaseValue(reader);
-                    if (value != null && property.CLRType.Length == 0)
-                    {
-                        dataTable.Columns[property.PropertyName].DataType = 
value.GetType();
-                    }
-                }
-                row = dataTable.NewRow();
                 for (int index = 0; index < resultMap.Properties.Count; 
index++)
                 {
                     ResultProperty property = resultMap.Properties[index];
@@ -139,13 +142,11 @@
                     {
                         value = DBNull.Value;
                     }
-                    row[property.PropertyName] = value;
-
+                    dataRow[property.PropertyName] = value;
                 }
             }
-            dataTable.Rows.Add(row);
 
-            return dataTable;
+            return null;
         }
 
         #endregion

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/MapStrategy.cs
 Thu Jun 12 10:55:57 2008
@@ -48,7 +48,7 @@
             resultMapStrategy = new ResultMapStrategy();
             groupByStrategy = new GroupByStrategy();
             cirularStrategy = new CirularStrategy();
-            dataTableStrategy = new DataTableStrategy();
+            dataTableStrategy = new DataRowStrategy();
         }
         
         #region IResultStrategy Members
@@ -71,7 +71,7 @@
             {
                 return cirularStrategy.Process(request, ref reader, 
resultObject);
             }
-            else if (typeof(DataTable).IsAssignableFrom(resultMap.Class))
+            else if (typeof(DataRow).IsAssignableFrom(resultMap.Class))
             {
                 return dataTableStrategy.Process(request, ref reader, 
resultObject);
             }

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/ResultClassStrategy.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/ResultClassStrategy.cs?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/ResultClassStrategy.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/ResultStrategy/ResultClassStrategy.cs
 Thu Jun 12 10:55:57 2008
@@ -50,7 +50,7 @@
                        dictionaryStrategy = new DictionaryStrategy();
                        listStrategy = new ListStrategy();
                        autoMapStrategy = new AutoMapStrategy();
-            dataTableStrategy = new DataTableStrategy();
+            dataTableStrategy = new DataRowStrategy();
 
                }
 
@@ -78,7 +78,7 @@
                        {
                 return listStrategy.Process(request, ref reader, resultObject);
                        }
-            else if 
(typeof(DataTable).IsAssignableFrom(request.CurrentResultMap.Class))
+            else if 
(typeof(DataRow).IsAssignableFrom(request.CurrentResultMap.Class))
             {
                 return dataTableStrategy.Process(request, ref reader, 
resultObject);
             }

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultProperty.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultProperty.cs?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultProperty.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultProperty.cs
 Thu Jun 12 10:55:57 2008
@@ -396,7 +396,7 @@
             if ( propertyName.Length>0 && 
                                 propertyName != "value" && 
                                
!typeof(IDictionary).IsAssignableFrom(resultClass)&&
-                !typeof(DataTable).IsAssignableFrom(resultClass)) 
+                !typeof(DataRow).IsAssignableFrom(resultClass)) 
                        {   
                 #region SetAccessor
                 if (!isComplexMemberName)

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/TypeHandlers/TypeHandlerFactory.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/TypeHandlers/TypeHandlerFactory.cs?rev=667183&r1=667182&r2=667183&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/TypeHandlers/TypeHandlerFactory.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/TypeHandlers/TypeHandlerFactory.cs
 Thu Jun 12 10:55:57 2008
@@ -357,7 +357,7 @@
             {
                 handler = GetUnkownTypeHandler();
             }
-            else if (typeof(IDictionary).IsAssignableFrom(classType) || 
typeof(DataTable).IsAssignableFrom(classType))
+            else if (typeof(IDictionary).IsAssignableFrom(classType) || 
typeof(DataRow).IsAssignableFrom(classType))
             {
                 // IDictionary or DataTable
                 if (memberType == null || memberType.Length == 0)
@@ -432,7 +432,7 @@
             {
                 handler = GetUnkownTypeHandler();
             }
-            else if (typeof(IDictionary).IsAssignableFrom(argumentType) || 
typeof(DataTable).IsAssignableFrom(argumentType))
+            else if (typeof(IDictionary).IsAssignableFrom(argumentType) || 
typeof(DataRow).IsAssignableFrom(argumentType))
             {
                 // IDictionary or 
                 if (clrType == null || clrType.Length == 0)


Reply via email to