Author: gbayon
Date: Sun Jul 23 01:45:34 2006
New Revision: 424689

URL: http://svn.apache.org/viewvc?rev=424689&view=rev
Log:
Fixed IBATISNET-174
Fixed IBATISNET-173

Modified:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Order.xml
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ConstructorTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ArgumentStrategy/ResultMapStrategy.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Order.xml
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Order.xml?rev=424689&r1=424688&r2=424689&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Order.xml 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Order.xml 
Sun Jul 23 01:45:34 2006
@@ -17,7 +17,7 @@
                <resultMap id="order-result-constructor1"  class="Order" >
                        <constructor>
                                <argument argumentName="id"              
column="Order_ID"/>
-                               <argument argumentName="account" 
column="Account_ID" resultMapping="Account.account-result-nullable-email" />
+                               <argument argumentName="account" 
resultMapping="Account.account-result-nullable-email" />
                        </constructor>
                        <result property="Date"       column="Order_Date"/>
                        <result property="CardExpiry" 
column="Order_CardExpiry"/>
@@ -122,6 +122,21 @@
       <result property="PostalCode" column="Order_PostalCode"/>
     </resultMap>
     
+    <resultMap id="order-result-constructor8"  class="Order" >
+               <constructor>
+                       <argument argumentName="id"              
column="Order_ID"/>
+                       <argument argumentName="account" 
resultMapping="Account.account-result-constructor" />
+               </constructor>
+               <result property="Date"       column="Order_Date"/>
+               <result property="CardExpiry" column="Order_CardExpiry"/>
+               <result property="CardType"   column="Order_CardType"/>
+               <result property="CardNumber" column="Order_CardNumber"/>
+               <result property="Street"     column="Order_Street"/>
+               <result property="City"       column="Order_City"/>
+               <result property="Province"   column="Order_Province"/>
+               <result property="PostalCode" column="Order_PostalCode"/>
+       </resultMap> 
+               
     <resultMap id="credit-card-result" class="string">
                        <result property="value" column="Order_CardNumber"/>
                </resultMap>
@@ -354,6 +369,19 @@
                        <result property="Account"      
resultMapping="Account.account-result-nullable-email" />
                </resultMap>
                
+               <resultMap id="order-joined-with-account-constructor" 
class="Order">
+                       <result property="Id"         column="Order_ID"/>
+                       <result property="Date"       column="Order_Date" 
nullValue="01/01/0001 00:00:00"/>
+                       <result property="CardExpiry" 
column="Order_CardExpiry"/>
+                       <result property="CardType"   column="Order_CardType"/>
+                       <result property="CardNumber" 
column="Order_CardNumber"/>
+                       <result property="Street"     column="Order_Street"/>
+                       <result property="City"       column="Order_City"/>
+                       <result property="Province"   column="Order_Province"/>
+                       <result property="PostalCode" 
column="Order_PostalCode"/>
+                       <result property="Account"      
resultMapping="Account.account-result-constructor" />
+               </resultMap>
+               
        </resultMaps>  
        
        <statements>
@@ -716,6 +744,36 @@
       select * from Orders where Order_ID = #value#
     </statement>
     
+    <select id="GetOrderConstructor8"
+               parameterClass="Integer"
+               resultMap="order-result-constructor8">
+               select 
+                       Order_ID, 
+                       Order_Date, 
+                       Order_CardExpiry, 
+                       Order_CardType,
+                       Order_CardNumber, 
+                       Order_Street, 
+                       Order_City, 
+                       Order_Province, 
+                       Order_PostalCode,
+                       acc.Account_ID,
+                       acc.Account_FirstName,
+                       acc.Account_LastName,
+                       acc.Account_Email,
+                       acc.Account_Banner_Option,
+                       acc.Account_Cart_Option
+               from Orders as ord
+               LEFT OUTER JOIN Accounts as acc on acc.Account_ID = 
ord.Account_ID
+               where Order_ID = #value#
+       </select>
+       
+       <select id="GetOrderConstructor9" 
+               extends="GetOrderConstructor8"
+               parameterClass="Integer"
+               resultMap="order-joined-with-account-constructor">
+       </select>
+               
   </statements>
 
        <parameterMaps>   

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=424689&r1=424688&r2=424689&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
 Sun Jul 23 01:45:34 2006
@@ -111,6 +111,34 @@
 
                        Assert.IsNull(order.Account);
                }
+
+               /// <summary>
+               /// Test constructor with an argument using a resultMapping 
where
+               /// - the resulMap argument use another constructor
+               /// - all second constructor arguments are null.
+               /// </remarks>
+               [Test]
+               public void TestJIRA173()
+               {
+                       Order order = 
sqlMap.QueryForObject("GetOrderConstructor8",11) as Order;
+
+                       Assert.IsTrue(order.Id == 11);
+                       Assert.IsNull(order.Account);
+               }
+
+               /// <summary>
+               /// Test resultMap with a result property using another 
resultMap and where
+               /// - the result property resultMap use a constructor
+               /// - all the constructor arguments are null.
+               /// </remarks>
+               [Test]
+               public void TestJIRA174()
+               {
+                       Order order = 
sqlMap.QueryForObject("GetOrderConstructor9",11) as Order;
+
+                       Assert.IsTrue(order.Id == 11);
+                       Assert.IsNull(order.Account);
+               }
                
                /// <summary>
                /// Test constructor with select attribute on argument

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ArgumentStrategy/ResultMapStrategy.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ArgumentStrategy/ResultMapStrategy.cs?rev=424689&r1=424688&r2=424689&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ArgumentStrategy/ResultMapStrategy.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ArgumentStrategy/ResultMapStrategy.cs
 Sun Jul 23 01:45:34 2006
@@ -50,22 +50,34 @@
                        ResultProperty mapping, ref IDataReader reader, object 
keys)
                {
                        object[] parameters = null;
+                       bool isParameterFound = false;
+
                        if (mapping.NestedResultMap.Parameters.Count >0)
                        {
-                               parameters = new 
object[resultMap.Parameters.Count];
+                               parameters = new 
object[mapping.NestedResultMap.Parameters.Count];
                                // Fill parameters array
                                for(int index=0; index< 
mapping.NestedResultMap.Parameters.Count; index++)
                                {
                                        ResultProperty property = 
mapping.NestedResultMap.Parameters[index];
                                        parameters[index] = 
property.GetDataBaseValue( reader );
                                        request.IsRowDataFound = 
request.IsRowDataFound || (parameters[index] != null);
+                                       isParameterFound = isParameterFound || 
(parameters[index] != null);
                                }
                        }
 
-                       object obj = 
mapping.NestedResultMap.CreateInstanceOfResult(parameters);
-                       if (FillObjectWithReaderAndResultMap(request, reader, 
mapping.NestedResultMap, obj) == false)
+                       object obj = null;
+                       // If I have a constructor tag and all argumments 
values are null, the obj is null
+                       if (mapping.NestedResultMap.Parameters.Count >0 && 
isParameterFound==false)
                        {
                                obj = null;
+                       }
+                       else
+                       {
+                               obj = 
mapping.NestedResultMap.CreateInstanceOfResult(parameters);
+                               if (FillObjectWithReaderAndResultMap(request, 
reader, mapping.NestedResultMap, obj) == false)
+                               {
+                                       obj = null;
+                               }
                        }
 
                        return obj;

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?rev=424689&r1=424688&r2=424689&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs
 Sun Jul 23 01:45:34 2006
@@ -53,24 +53,36 @@
                {
                        // Creates object
                        object[] parameters = null;
+                       bool isParameterFound = false;
+
                        if (mapping.NestedResultMap.Parameters.Count >0)
                        {
-                               parameters = new 
object[resultMap.Parameters.Count];
+                               parameters = new 
object[mapping.NestedResultMap.Parameters.Count];
                                // Fill parameters array
                                for(int index=0; index< 
mapping.NestedResultMap.Parameters.Count; index++)
                                {
                                        ResultProperty resultProperty = 
mapping.NestedResultMap.Parameters[index];
-                                       parameters[index] = 
resultProperty.ArgumentStrategy.GetValue(request, resultMap, resultProperty, 
ref reader, null);
+                                       parameters[index] = 
resultProperty.ArgumentStrategy.GetValue(request, mapping.NestedResultMap, 
resultProperty, ref reader, null);
                                        request.IsRowDataFound = 
request.IsRowDataFound || (parameters[index] != null);
+                                       isParameterFound = isParameterFound || 
(parameters[index] != null);
                                }
                        }
 
-                       object obj = 
mapping.NestedResultMap.CreateInstanceOfResult(parameters);
-                       
-                       // Fills properties on the new object
-                       if (this.FillObjectWithReaderAndResultMap(request, 
reader, mapping.NestedResultMap, obj) == false)
+                       object obj = null;
+                       // If I have a constructor tag and all argumments 
values are null, the obj is null
+                       if (mapping.NestedResultMap.Parameters.Count >0 && 
isParameterFound==false)
                        {
                                obj = null;
+                       }
+                       else
+                       {
+                               obj = 
mapping.NestedResultMap.CreateInstanceOfResult(parameters);
+                               
+                               // Fills properties on the new object
+                               if 
(this.FillObjectWithReaderAndResultMap(request, reader, 
mapping.NestedResultMap, obj) == false)
+                               {
+                                       obj = null;
+                               }                               
                        }
 
                        // Sets created object on the property


Reply via email to