Author: gbayon
Date: Sat Oct 11 14:11:54 2008
New Revision: 703732

URL: http://svn.apache.org/viewvc?rev=703732&view=rev
Log:
Fix IBATISNET-283

Modified:
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/Account.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/Fixtures/Modules/AliasModule.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/DataExchange/DotNetObjectDataExchange.cs

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/Account.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/Account.cs?rev=703732&r1=703731&r2=703732&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/Account.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/Account.cs
 Sat Oct 11 14:11:54 2008
@@ -1,15 +1,58 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 
 namespace Apache.Ibatis.DataMapper.SqlClient.Test.Domain
 {
-       /// <summary>
+    public interface IAccount
+    {
+        int Id { get; set; }
+        string FirstName { get; set; }
+        string LastName { get; set; }
+        string EmailAddress { get; set; }
+    }
+
+    public class BaseAccount: IAccount
+    {
+        private int id;
+        private string firstName;
+        private string lastName;
+        private string emailAddress;
+
+        #region IAccount Members
+
+        public int Id
+        {
+            get { return id; }
+            set { id = value; }
+        }
+
+        public string FirstName
+        {
+            get { return firstName; }
+            set { firstName = value; }
+        }
+
+        public string LastName
+        {
+            get { return lastName; }
+            set { lastName = value; }
+        }
+
+        public string EmailAddress
+        {
+            get { return emailAddress; }
+            set { emailAddress = value; }
+        }
+
+        #endregion
+    }
+
+    /// <summary>
        /// Description résumée de Account.
        /// </summary>
        [Serializable]
-       public class Account
-       {
+       public class Account : IAccount
+    {
                private int id;
                private string _firstName;
                private string _lastName;

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=703732&r1=703731&r2=703732&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
 Sat Oct 11 14:11:54 2008
@@ -45,6 +45,23 @@
 
         #region Object Query tests
 
+        /// <summary>
+        /// Test use a statement with property subtitution
+        /// (JIRA 22)
+        /// </summary>
+        [Test]
+        public void TestInterface()
+        {
+            BaseAccount account = new BaseAccount();
+
+            dataMapper.QueryForObject<IAccount>("GetInterfaceAccount", 1, 
account);
+
+            Assert.AreEqual(1, account.Id, "account.Id");
+            Assert.AreEqual("Joe", account.FirstName, "account.FirstName");
+            Assert.AreEqual("Dalton", account.LastName, "account.LastName");
+            Assert.AreEqual("[EMAIL PROTECTED]", account.EmailAddress, 
"account.EmailAddress");
+        }
+
 
         [Test]
         public void QueryForDatatable_with_resulclass_should_work()

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/AliasModule.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/AliasModule.cs?rev=703732&r1=703731&r2=703732&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/AliasModule.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/AliasModule.cs
 Sat Oct 11 14:11:54 2008
@@ -15,7 +15,7 @@
             RegisterAlias<SqlSourceWithParameter>();
             RegisterAlias<SqlSourceWithInlineParameter>();
             RegisterAlias<NVelocityDynamicEngine>();
-
+            RegisterAlias<IAccount>();
         }
     }
 }

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=703732&r1=703731&r2=703732&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
 Sat Oct 11 14:11:54 2008
@@ -501,6 +501,16 @@
                                        where Account_ID = #value#
                        ]]>
                </select>
+
+    <select id="GetInterfaceAccount" resultClass="IAccount">
+                                       select
+                                       Account_ID as Id,
+                                       Account_FirstName as FirstName,
+                                       Account_LastName as LastName,
+                                       Account_Email as EmailAddress
+                                       from Accounts
+                                       where Account_ID = #value#
+    </select>
                
                <select id="GetAccountViaInlineParameters"
                                resultMap="indexed-account-result">

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/DataExchange/DotNetObjectDataExchange.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/DataExchange/DotNetObjectDataExchange.cs?rev=703732&r1=703731&r2=703732&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/DataExchange/DotNetObjectDataExchange.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/DataExchange/DotNetObjectDataExchange.cs
 Sat Oct 11 14:11:54 2008
@@ -37,7 +37,7 @@
        public sealed class DotNetObjectDataExchange : BaseDataExchange
        {
 
-        private readonly Type _parameterClass = null;
+        private readonly Type parameterClass = null;
 
 
         /// <summary>
@@ -48,7 +48,7 @@
         public DotNetObjectDataExchange(Type parameterClass, 
DataExchangeFactory dataExchangeFactory)
             : base(dataExchangeFactory)
                {
-            _parameterClass = parameterClass;
+            this.parameterClass = parameterClass;
                }
 
                #region IDataExchange Members
@@ -60,7 +60,7 @@
                /// <param name="parameterObject"></param>
                public override object GetData(ParameterProperty mapping, 
object parameterObject)
                {
-                   if (mapping.IsComplexMemberName || 
_parameterClass!=parameterObject.GetType())
+                   if (mapping.IsComplexMemberName || 
parameterClass!=parameterObject.GetType())
                        {
                                return 
ObjectProbe.GetMemberValue(parameterObject, mapping.PropertyName,
                                        DataExchangeFactory.AccessorFactory);
@@ -77,10 +77,11 @@
                public override void SetData(ref object target, ResultProperty 
mapping, object dataBaseValue)
                {
                    Type targetType = target.GetType();
-            if ((targetType != _parameterClass)
-                && !targetType.IsSubclassOf(_parameterClass)) 
+            if ((targetType != parameterClass)
+                && !targetType.IsSubclassOf(parameterClass)
+                && !parameterClass.IsAssignableFrom(targetType))
                        {
-                throw new ArgumentException("Could not set value of type '" + 
target.GetType() + "' in property '" + mapping.PropertyName + "' of type '" + 
_parameterClass + "'");
+                throw new ArgumentException("Could not set value in class '" + 
target.GetType() + "' for property '" + mapping.PropertyName + "' of type '" + 
mapping.MemberType + "'");
                        }
                        if ( mapping.IsComplexMemberName)
                        {
@@ -94,6 +95,8 @@
                        }
                }
 
+
+
                /// <summary>
                /// Sets the value to the parameter property.
                /// </summary>
@@ -112,7 +115,7 @@
                        else
                        {
                 ISetAccessorFactory setAccessorFactory = 
DataExchangeFactory.AccessorFactory.SetAccessorFactory;
-                ISetAccessor _setAccessor = 
setAccessorFactory.CreateSetAccessor(_parameterClass, mapping.PropertyName);
+                ISetAccessor _setAccessor = 
setAccessorFactory.CreateSetAccessor(parameterClass, mapping.PropertyName);
 
                 _setAccessor.Set(target, dataBaseValue);
                        }


Reply via email to