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/15 20:50:33 UTC

svn commit: r508110 - in /ibatis/trunk/cs/mapper: IBatisNet.DataMapper.Test/ IBatisNet.DataMapper.Test/Domain/ IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/ IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ IBatisNet.DataMapper.Test/Scripts/MSSQL/ IBatisN...

Author: gbayon
Date: Thu Feb 15 11:50:32 2007
New Revision: 508110

URL: http://svn.apache.org/viewvc?view=rev&rev=508110
Log:
- Fixedn IBATISNET-206, invalid result when mixing groupBy and inheritance

Modified:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/user-init.sql
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs?view=diff&rev=508110&r1=508109&r2=508110
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Account.cs Thu Feb 15 11:50:32 2007
@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 
 namespace IBatisNet.DataMapper.Test.Domain
 {
@@ -17,7 +18,23 @@
 		private bool _cartOption = false;
 	    private Document _document = null;
 
-		public Account()
+        #if dotnet2
+        protected IList<Document> documents = new List<Document>();
+
+        public IList<Document> Documents
+        {
+            get { return documents; }
+        }
+        #else
+        protected IList documents = new List();
+
+        public IListDocuments
+        {
+            get { return documents; }
+        }
+        #endif
+
+        public Account()
 		{}
 
         public Account(int identifiant, string firstName, string lastName)

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs?view=diff&rev=508110&r1=508109&r2=508110
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/User.cs Thu Feb 15 11:50:32 2007
@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 
 namespace IBatisNet.DataMapper.Test.Domain
 {
@@ -7,46 +8,25 @@
 	/// </summary>
 	public class User
 	{
-		private string id;
-		private string userName;
-		private string password;
-		private string emailAddress;
-		private DateTime lastLogon;
+        protected Nullable<int> id = null;
+        protected string name;
+	    protected IList<Document> documents = new List<Document>();
+
+        public IList<Document> Documents
+        {
+            get { return documents; }
+        }
 
-
-		public User()
-		{
-		}
-
-		public string Id 
+        public Nullable<int> Id 
 		{
 			get { return id; }
-			set { id = value; }
-		}
-
-		public string UserName 
-		{
-			get { return userName; }
-			set { userName = value; }
-		}
-
-		public string Password 
-		{
-			get { return password; }
-			set { password = value; }
 		}
 
-		public string EmailAddress 
+		public string Name 
 		{
-			get { return emailAddress; }
-			set { emailAddress = value; }
+            get { return name; }
 		}
 
-		public DateTime LastLogon 
-		{
-			get { return lastLogon; }
-			set { lastLogon = value; }
-		}
 
 	}
 }

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?view=diff&rev=508110&r1=508109&r2=508110
==============================================================================
--- 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 Thu Feb 15 11:50:32 2007
@@ -78,7 +78,7 @@
       <Name>log4net</Name>
       <HintPath>..\External-Bin\Net\1.1\log4net.dll</HintPath>
     </Reference>
-    <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+    <Reference Include="nunit.framework, Version=2.2.9.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
     <Reference Include="System">
       <Name>System</Name>
     </Reference>

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml?view=diff&rev=508110&r1=508109&r2=508110
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml Thu Feb 15 11:50:32 2007
@@ -148,15 +148,36 @@
 			<result property="LastName"     column="Account_LastName"/>
 			<result property="EmailAddress" column="Account_Email"/>
 		</resultMap>
-		
-	</resultMaps>
-	
-	<!-- =============================================
+
+    <resultMap id="account-groupby"  class="Account" groupBy="id">
+      <result property="id"           column="Account_ID"/>
+      <result property="FirstName"    column="Account_FirstName"/>
+      <result property="documents" resultMapping="Document.document"/>
+    </resultMap>
+
+  </resultMaps>
+
+  <!-- =============================================
         MAPPED STATEMENTS - w/Inline Parameters
     ============================================= 
     -->
-	<statements>
+  <statements>
 
+    <select id="JIRA206"
+       resultMap="account-groupby">
+      SELECT
+      Accounts.Account_ID,
+      Account_FirstName,
+      Document_ID,
+      Document_City,
+      Document_PageNumber,
+      Document_Type,
+      Document_Title
+      FROM         Accounts LEFT OUTER JOIN
+      Documents ON Accounts.Account_ID = Documents.Account_Id
+      Order by Accounts.Account_ID
+    </select>
+    
     <select id="GetMultipleResultMapAccount"
 				resultMap="account-result, account-result">
       select

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs?view=diff&rev=508110&r1=508109&r2=508110
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs Thu Feb 15 11:50:32 2007
@@ -23,6 +23,7 @@
         protected override void SetUpFixture()
         {
             base.SetUpFixture();
+
             InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-drop.sql");
             InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-schema.sql");
             InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-init.sql");
@@ -179,5 +180,31 @@
             Assert.AreEqual(1, order.LineItemsIList.Count);
             Assert.IsNull(order.Account);
         }
+
+#if dotnet2
+        /// <summary>
+        /// Test GroupBy With use of Inheritance
+        /// </summary>
+        [Test]
+        public void GroupByWithInheritance()
+        {
+            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-drop.sql");
+            InitScript(sqlMap.DataSource, ScriptDirectory + "account-init.sql");
+            InitScript(sqlMap.DataSource, ScriptDirectory + "documents-init.sql");
+
+            IList<Account> list = sqlMap.QueryForList<Account>("JIRA206", null);
+            
+            Assert.AreEqual(5, list.Count);
+            Assert.AreEqual(0, list[0].Documents.Count);
+            Assert.AreEqual(2, list[1].Documents.Count);
+            Assert.AreEqual(1, list[2].Documents.Count);
+            Assert.AreEqual(0, list[3].Documents.Count);
+            Assert.AreEqual(2, list[4].Documents.Count);
+
+            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-drop.sql");
+            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-schema.sql");
+            InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-init.sql");
+        }
+#endif
     }
 }

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs?view=diff&rev=508110&r1=508109&r2=508110
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs Thu Feb 15 11:50:32 2007
@@ -137,13 +137,13 @@
         [Test]
         public void TestJIRA175()
 	    {
-            Account account = sqlMap.QueryForObject("JIRA175", 5) as Account;
-            Assert.AreEqual(5, account.Id, "account.Id");
-            Assert.AreEqual("Gilles", account.FirstName, "account.FirstName");
+            Account account = sqlMap.QueryForObject("JIRA175", 3) as Account;
+            Assert.AreEqual(3, account.Id, "account.Id");
+            Assert.AreEqual("William", account.FirstName, "account.FirstName");
 	        
             Book book = account.Document as Book;
             Assert.IsNotNull(book);
-            AssertBook(book, 1, "The World of Null-A", 55);
+            AssertBook(book, 3, "Lord of the Rings", 3587);
 	    }
 	    
 		#endregion 

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql?view=diff&rev=508110&r1=508109&r2=508110
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql Thu Feb 15 11:50:32 2007
@@ -28,8 +28,8 @@
 -- Creating Test Data 
 
 INSERT INTO [dbo].[Documents] VALUES (1, 'The World of Null-A', 'Book', 55, null, 5);
-INSERT INTO [dbo].[Documents] VALUES (2, 'Le Progres de Lyon', 'Newspaper', null , 'Lyon', NULL);
-INSERT INTO [dbo].[Documents] VALUES (3, 'Lord of the Rings', 'Book', 3587, null, NULL);
-INSERT INTO [dbo].[Documents] VALUES (4, 'Le Canard enchaine', 'Tabloid', null , 'Paris', NULL);
-INSERT INTO [dbo].[Documents] VALUES (5, 'Le Monde', 'Broadsheet', null , 'Paris', NULL);
-INSERT INTO [dbo].[Documents] VALUES (6, 'Foundation', 'Monograph', 557, null, NULL);
+INSERT INTO [dbo].[Documents] VALUES (2, 'Le Progres de Lyon', 'Newspaper', null , 'Lyon', 2);
+INSERT INTO [dbo].[Documents] VALUES (3, 'Lord of the Rings', 'Book', 3587, null, 3);
+INSERT INTO [dbo].[Documents] VALUES (4, 'Le Canard enchaine', 'Tabloid', null , 'Paris', 2);
+INSERT INTO [dbo].[Documents] VALUES (5, 'Le Monde', 'Broadsheet', null , 'Paris', 5);
+INSERT INTO [dbo].[Documents] VALUES (6, 'Foundation', 'Monograph', 557, null, 6);

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/user-init.sql
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/user-init.sql?view=diff&rev=508110&r1=508109&r2=508110
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/user-init.sql (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/user-init.sql Thu Feb 15 11:50:32 2007
@@ -1,6 +1,6 @@
 -- Creating Table
 
-use [NHibernate]
+use [IBatisNet]
 
 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Users]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 BEGIN
@@ -8,10 +8,16 @@
 END
 
 CREATE TABLE [dbo].[Users] (
-  LogonID nvarchar(20) NOT NULL default '0',
-  Name nvarchar(40) default NULL,
-  Password nvarchar(20) default NULL,
-  EmailAddress nvarchar(40) default NULL,
-  LastLogon datetime default NULL,
-  PRIMARY KEY  (LogonID)
+  [User_ID] [int] NOT NULL ,
+  [Name] [varchar] (32)  NOT NULL
+  PRIMARY KEY  (User_ID)
 )
+
+-- Creating Test Data
+
+INSERT INTO [dbo].[Users] VALUES(1,'Joe');
+INSERT INTO [dbo].[Users] VALUES(2,'Averel');
+INSERT INTO [dbo].[Users] VALUES(3,'William');
+INSERT INTO [dbo].[Users] VALUES(4,'Jack');
+INSERT INTO [dbo].[Users] VALUES(5,'Gilles');
+

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=508110&r1=508109&r2=508110
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs Thu Feb 15 11:50:32 2007
@@ -247,10 +247,6 @@
 		{
 			try
 			{
-				if (_className == "NCategory")
-				{
-					Console.Write("");
-				}
 				_class = configScope.SqlMapper.TypeHandlerFactory.GetType(_className);
 				_dataExchange = _dataExchangeFactory.GetDataExchangeForClass(_class);
 
@@ -441,16 +437,24 @@
 			{	
 				ResultProperty mapping = _discriminator.ResultProperty;
 				object dataBaseValue = mapping.GetDataBaseValue( dataReader );
-				subMap = _discriminator.GetSubMap( dataBaseValue.ToString() );
 
-				if (subMap == null) 
-				{
-					subMap = this;
-				} 
-				else if (subMap != this) 
-				{
-					subMap = subMap.ResolveSubMap(dataReader);
-				}
+                if (dataBaseValue!=null)
+                {
+				    subMap = _discriminator.GetSubMap( dataBaseValue.ToString() );
+
+				    if (subMap == null) 
+				    {
+					    subMap = this;
+				    } 
+				    else if (subMap != this) 
+				    {
+					    subMap = subMap.ResolveSubMap(dataReader);
+				    }                    
+                }
+                else
+                {
+                    subMap = null;
+                }
 			}
 			return subMap;
 		}

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=508110&r1=508109&r2=508110
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/GroupByStrategy.cs Thu Feb 15 11:50:32 2007
@@ -98,42 +98,46 @@
             object result = null;
             IResultMap propertyRresultMap = mapping.NestedResultMap.ResolveSubMap(reader);
 
-            if (propertyRresultMap.GroupByProperties.Count>0)
+            if (propertyRresultMap!=null)
             {
-                 string uniqueKey = GetUniqueKey(propertyRresultMap, request, reader);
-                // Gets the [key, result object] already build
-                IDictionary buildObjects = request.GetUniqueKeys(propertyRresultMap);
-                if (buildObjects != null && buildObjects.Contains(uniqueKey))
+                if (propertyRresultMap.GroupByProperties.Count>0)
                 {
-                    // Unique key is already known, so get the existing result object and process additional results.
-                    result = buildObjects[uniqueKey];
-                    // process resulMapping attribute wich point to a groupBy attribute
-                    for (int index = 0; index < propertyRresultMap.Properties.Count; index++)
+                     string uniqueKey = GetUniqueKey(propertyRresultMap, request, reader);
+                    // Gets the [key, result object] already build
+                    IDictionary buildObjects = request.GetUniqueKeys(propertyRresultMap);
+                    if (buildObjects != null && buildObjects.Contains(uniqueKey))
                     {
-                        ResultProperty resultProperty = propertyRresultMap.Properties[index];
-                        if (resultProperty.PropertyStrategy is PropertStrategy.GroupByStrategy)
+                        // 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.PropertyStrategy.Set(request, propertyRresultMap, resultProperty, ref result, reader, null);
+                            ResultProperty resultProperty = propertyRresultMap.Properties[index];
+                            if (resultProperty.PropertyStrategy is PropertStrategy.GroupByStrategy)
+                            {
+                                resultProperty.PropertyStrategy.Set(request, propertyRresultMap, resultProperty, ref result, reader, null);
+                            }
                         }
+                        result = SKIP;
                     }
-                    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;
+                    }               
                 }
-                else if (uniqueKey == null || buildObjects == null || !buildObjects.Contains(uniqueKey))
+                else // Last resultMap have no groupBy attribute
                 {
                     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))
             {