Author: gbayon
Date: Wed Jul 26 12:22:12 2006
New Revision: 425810

URL: http://svn.apache.org/viewvc?rev=425810&view=rev
Log:
Fixed for IBATISNET-176
Thanks to Peter Mills who give me a unit test

Added:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategory.cs   
(with props)
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategoryPropertyContainer.cs
   (with props)
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ConstructorInjection.xml
Modified:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConstructorTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs

Added: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategory.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategory.cs?rev=425810&view=auto
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategory.cs 
(added)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategory.cs 
Wed Jul 26 12:22:12 2006
@@ -0,0 +1,34 @@
+using System;
+
+namespace IBatisNet.DataMapper.Test.Domain 
+{
+       public class ImmutableCategory 
+       {
+
+               private int _id;
+               private string _name;
+               private Guid _guid;
+
+               public ImmutableCategory(int id, string name, Guid guid) {
+
+                       _name = name;
+                       _id = id;
+                       _guid = guid;
+               }
+               
+               public string Name {
+                       get { return _name; }
+               }
+
+               
+               public int Id {
+                       get { return _id; }
+               }
+
+               
+               public Guid Guid {
+                       get { return _guid; }
+               }
+
+       }
+}

Propchange: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategory.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategory.cs
------------------------------------------------------------------------------
    svn:keywords = Id LastChangedDate LastChangedBy

Added: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategoryPropertyContainer.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategoryPropertyContainer.cs?rev=425810&view=auto
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategoryPropertyContainer.cs
 (added)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategoryPropertyContainer.cs
 Wed Jul 26 12:22:12 2006
@@ -0,0 +1,19 @@
+
+namespace IBatisNet.DataMapper.Test.Domain {
+       
+       /// <summary>
+       /// A Container object that stores an immutable category as a property.
+       /// 
+       /// This container will be used to test constructor injection on an 
immutable category, when it's
+       /// resultmapped through a another object's constructor.
+       /// </summary>
+       public class ImmutableCategoryPropertyContainer 
+       {
+               private ImmutableCategory _immutableCategory;
+
+               public ImmutableCategory ImmutableCategory {
+                       get { return _immutableCategory; }
+                       set { _immutableCategory = value; }
+               }
+       }
+}

Propchange: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategoryPropertyContainer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/ImmutableCategoryPropertyContainer.cs
------------------------------------------------------------------------------
    svn:keywords = Id LastChangedDate LastChangedBy

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj?rev=425810&r1=425809&r2=425810&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
 Wed Jul 26 12:22:12 2006
@@ -151,6 +151,8 @@
     <Compile Include="Domain\HundredsTypeHandlerCallback.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Domain\ImmutableCategory.cs" />
+    <Compile Include="Domain\ImmutableCategoryPropertyContainer.cs" />
     <Compile Include="Domain\LineItem.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -318,6 +320,7 @@
     <Content Include="Maps\MSSQL\OleDb\ResultClass.xml" />
     <Content Include="Maps\MSSQL\SqlClient\Category.xml" />
     <Content Include="Maps\MSSQL\SqlClient\Complex.xml" />
+    <Content Include="Maps\MSSQL\SqlClient\ConstructorInjection.xml" />
     <Content Include="Maps\MSSQL\SqlClient\Document.xml" />
     <Content Include="Maps\MSSQL\SqlClient\DynamicAccount.xml" />
     <Content Include="Maps\MSSQL\SqlClient\EmbedParameter.xml" />

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj?rev=425810&r1=425809&r2=425810&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
 Wed Jul 26 12:22:12 2006
@@ -278,6 +278,16 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "Domain\ImmutableCategory.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "Domain\ImmutableCategoryPropertyContainer.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "Domain\LineItem.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
@@ -500,6 +510,10 @@
                 />
                 <File
                     RelPath = "Maps\MSSQL\SqlClient\Complex.xml"
+                    BuildAction = "Content"
+                />
+                <File
+                    RelPath = "Maps\MSSQL\SqlClient\ConstructorInjection.xml"
                     BuildAction = "Content"
                 />
                 <File

Added: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ConstructorInjection.xml
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ConstructorInjection.xml?rev=425810&view=auto
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ConstructorInjection.xml
 (added)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ConstructorInjection.xml
 Wed Jul 26 12:22:12 2006
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<sqlMap namespace="ConstructorInjection" 
+xmlns="http://ibatis.apache.org/mapping"; 
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+
+       <alias>
+               <typeAlias alias="ImmutableCategory" 
type="IBatisNet.DataMapper.Test.Domain.ImmutableCategory, 
IBatisNet.DataMapper.Test"/>
+               <typeAlias alias="ImmutableCategoryPropertyContainer" 
type="IBatisNet.DataMapper.Test.Domain.ImmutableCategoryPropertyContainer, 
IBatisNet.DataMapper.Test"/>
+       </alias>
+
+       <resultMaps>
+
+               <resultMap id="ImmutableCategory-result" 
class="ImmutableCategory">
+                       <constructor>
+                               <argument argumentName="id" 
column="Category_Id"/>
+                               <argument argumentName="name"  
column="Category_Name"/>
+                               <argument argumentName="guid" 
column="Category_Guid" nullValue="00000000-0000-0000-0000-000000000000"/>
+                       </constructor>
+               </resultMap>
+
+               <resultMap id="ImmutableCategoryPropertyContainer-result" 
class="ImmutableCategoryPropertyContainer">
+                       <result property="ImmutableCategory" 
resultMapping="ConstructorInjection.ImmutableCategory-result"/>
+               </resultMap>
+       </resultMaps >
+
+       <statements>
+
+               <select id="GetImmutableCategoryInContainer" 
parameterClass="int" resultMap="ImmutableCategoryPropertyContainer-result">
+                       select *
+                       from Categories
+                       where Category_ID = #value#
+               </select>
+    
+       </statements>
+</sqlMap>

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConstructorTest.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConstructorTest.cs?rev=425810&r1=425809&r2=425810&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConstructorTest.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConstructorTest.cs
 Wed Jul 26 12:22:12 2006
@@ -29,6 +29,7 @@
                        InitScript(sqlMap.DataSource, ScriptDirectory + 
"enumeration-init.sql");
                        InitScript(sqlMap.DataSource, ScriptDirectory + 
"other-init.sql");
             InitScript(sqlMap.DataSource, ScriptDirectory + 
"Nullable-init.sql");
+            InitScript(sqlMap.DataSource, ScriptDirectory + 
"category-init.sql");
                }
 
                /// <summary>
@@ -96,6 +97,28 @@
         }
 #endif
 
+        /// <summary>
+        /// Test constructor injection using a resultMapping where
+        /// - the resultmapping object performs *only* constructor injection.
+        /// </remarks>
+        [Test]
+        public void TestJIRA176()
+        {
+
+            Category category = new Category();
+            category.Name = "toto";
+            category.Guid = Guid.Empty;
+
+            int key = (int)sqlMap.Insert("InsertCategory", category);
+
+            ImmutableCategoryPropertyContainer categoryContainerFromDB = 
(ImmutableCategoryPropertyContainer)sqlMap.QueryForObject("GetImmutableCategoryInContainer",
 key);
+            Assert.IsNotNull(categoryContainerFromDB);
+            Assert.IsNotNull(categoryContainerFromDB.ImmutableCategory);
+            Assert.AreEqual(category.Name, 
categoryContainerFromDB.ImmutableCategory.Name);
+            Assert.AreEqual(key, categoryContainerFromDB.ImmutableCategory.Id);
+            Assert.AreEqual(category.Guid, 
categoryContainerFromDB.ImmutableCategory.Guid);
+        }
+           
                /// <summary>
                /// Test constructor with resultMapping attribute on argument
                /// </remarks>

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config?rev=425810&r1=425809&r2=425810&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config
 Wed Jul 26 12:22:12 2006
@@ -45,5 +45,6 @@
                <sqlMap 
resource="../../Maps/MSSQL/SqlClient/EmbedParameter.xml"/>
                <sqlMap resource="../../Maps/MSSQL/SqlClient/Nullable.xml"/>
                <sqlMap resource="../../Maps/MSSQL/SqlClient/Simple.xml"/>
-       </sqlMaps>
+    <sqlMap resource="../../Maps/MSSQL/SqlClient/ConstructorInjection.xml"/>
+  </sqlMaps>
 </sqlMapConfig>

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs?rev=425810&r1=425809&r2=425810&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs 
Wed Jul 26 12:22:12 2006
@@ -54,18 +54,26 @@
                                                                ResultMap 
resultMap, object resultObject)
                {
                        bool dataFound = false;
-                       
-                       // For each Property in the ResultMap, set the property 
in the object 
-                       for(int index=0; index< resultMap.Properties.Count; 
index++)
-                       {
-                               request.IsRowDataFound = false;
-                               ResultProperty property = 
resultMap.Properties[index];
-                               property.PropertyStrategy.Set(request, 
resultMap, property, ref resultObject, reader, null);
-                               dataFound = dataFound || request.IsRowDataFound;
-                       }
 
-                       request.IsRowDataFound = dataFound;
-                       return dataFound;
-               }
+            if (resultMap.Properties.Count>0)
+            {
+                           // For each Property in the ResultMap, set the 
property in the object 
+                           for(int index=0; index< resultMap.Properties.Count; 
index++)
+                           {
+                                   request.IsRowDataFound = false;
+                                   ResultProperty property = 
resultMap.Properties[index];
+                                   property.PropertyStrategy.Set(request, 
resultMap, property, ref resultObject, reader, null);
+                                   dataFound = dataFound || 
request.IsRowDataFound;
+                           }
+
+                           request.IsRowDataFound = dataFound;
+                           return dataFound;
+                   }
+                   else
+            {
+                return true;
+            }
+        }
+
        }
 }


Reply via email to