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/09/17 21:10:01 UTC
svn commit: r576561 - in /ibatis/trunk/cs/mapper: IBatisNet.DataMapper.Test/
IBatisNet.DataMapper.Test/Domain/
IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/
IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/
IBatisNet.DataMapper.Test/Scripts/MSSQL...
Author: gbayon
Date: Mon Sep 17 12:10:00 2007
New Revision: 576561
URL: http://svn.apache.org/viewvc?rev=576561&view=rev
Log:
Fix IBATISNET-243 Lists of primitives in result maps doesn't work
Added:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Coupon.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Coupons.xml
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/coupons-init.sql
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Enumeration.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/ResultMapTest.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ArgumentStrategy/ResultMapStrategy.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Coupon.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Coupon.cs?rev=576561&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Coupon.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Coupon.cs Mon Sep 17 12:10:00 2007
@@ -0,0 +1,31 @@
+
+
+using System.Collections.Generic;
+
+namespace IBatisNet.DataMapper.Test.Domain
+{
+ public class Coupon
+ {
+ private int id;
+ private string _code;
+ private IList<int> _brandIds = new List<int>();
+
+ public virtual int Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ public string Code
+ {
+ get { return _code; }
+ set { _code = value; }
+ }
+
+ public IList<int> BrandIds
+ {
+ get { return _brandIds; }
+ set { _brandIds = value; }
+ }
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Coupon.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Coupon.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Enumeration.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Enumeration.cs?rev=576561&r1=576560&r2=576561&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Enumeration.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Enumeration.cs Mon Sep 17 12:10:00 2007
@@ -2,6 +2,13 @@
namespace IBatisNet.DataMapper.Test.Domain
{
+
+ public enum ESearchProfile
+ {
+ Temp = 'T',
+ Permanent = 'P'
+ }
+
public enum Days
{
Sat=1,
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=576561&r1=576560&r2=576561&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 Mon Sep 17 12:10:00 2007
@@ -126,6 +126,7 @@
<Compile Include="Domain\Complex.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Domain\Coupon.cs" />
<Compile Include="Domain\CustomInheritance.cs">
<SubType>Code</SubType>
</Compile>
@@ -330,6 +331,7 @@
<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\Coupons.xml" />
<Content Include="Maps\MSSQL\SqlClient\Document.xml" />
<Content Include="Maps\MSSQL\SqlClient\DynamicAccount.xml" />
<Content Include="Maps\MSSQL\SqlClient\EmbedParameter.xml" />
@@ -425,6 +427,7 @@
<Content Include="Scripts\MSSQL\category-init.sql" />
<Content Include="Scripts\MSSQL\category-procedure.sql" />
<Content Include="Scripts\MSSQL\category-procedureWithReturn.sql" />
+ <Content Include="Scripts\MSSQL\coupons-init.sql" />
<Content Include="Scripts\MSSQL\DataBase.sql" />
<Content Include="Scripts\MSSQL\DBCreation.sql" />
<Content Include="Scripts\MSSQL\documents-init.sql" />
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Coupons.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Coupons.xml?rev=576561&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Coupons.xml (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Coupons.xml Mon Sep 17 12:10:00 2007
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<sqlMap namespace="Coupon"
+xmlns="http://ibatis.apache.org/mapping"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
+
+ <alias>
+ <typeAlias alias="Coupon" type="IBatisNet.DataMapper.Test.Domain.Coupon, IBatisNet.DataMapper.Test" />
+ </alias>
+
+ <!-- If the type is not specified, ADO.NET infers the
+ data provider Type of the Parameter from the Value property
+ of the Parameter object. -->
+
+ <resultMaps>
+
+ <resultMap id="ResultMapCouponV1" class="Coupon" groupBy="Id">
+ <result property="Id" column="Coupon_Id" />
+ <result property="Code" column="Coupon_Code" />
+ <result property="BrandIds" resultMapping="Coupon.ResultMapCouponBrandId" />
+ </resultMap>
+
+ <resultMap id="ResultMapCouponV2" class="Coupon" groupBy="Id">
+ <result property="Id" column="Coupon_Id" />
+ <result property="Code" column="Coupon_Code" />
+ <result property="BrandIds" column ="Coupon_Id" select="GetBrand" />
+ </resultMap>
+
+ <resultMap id="ResultMapCouponBrandId" class="int">
+ <result property="value" column="BrandId" />
+ </resultMap>
+
+
+ </resultMaps>
+
+ <statements>
+
+ <select id="GetCouponBrand" resultMap="ResultMapCouponV1">
+ SELECT
+ cou.Coupon_Id ,
+ cou.Coupon_Code,
+ cou_b.Brand_Id AS BrandId
+ FROM Coupons AS cou
+ LEFT OUTER JOIN Coupons_Brands AS cou_b
+ ON cou.Coupon_Id = cou_b.Coupon_Id
+ </select>
+
+ <select id="GetCoupons" resultMap="ResultMapCouponV2">
+ SELECT
+ Coupon_Id ,
+ Coupon_Code
+ FROM Coupons
+ </select>
+
+ <select id="GetBrand" parameterClass="int" resultClass="int">
+ SELECT
+ Brand_Id AS BrandId
+ FROM Coupons_Brands
+ Where Coupon_Id = #value#
+ </select>
+
+</statements>
+
+
+</sqlMap>
\ No newline at end of file
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/ResultMapTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/ResultMapTest.cs?rev=576561&r1=576560&r2=576561&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/ResultMapTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/ResultMapTest.cs Mon Sep 17 12:10:00 2007
@@ -6,6 +6,7 @@
using NUnit.Framework;
using IBatisNet.DataMapper.Test.Domain;
+using NUnit.Framework.SyntaxHelpers;
namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.Generics
{
@@ -37,6 +38,8 @@
InitScript(sqlMap.DataSource, ScriptDirectory + "order-init.sql");
InitScript(sqlMap.DataSource, ScriptDirectory + "line-item-init.sql");
InitScript(sqlMap.DataSource, ScriptDirectory + "enumeration-init.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory + "coupons-init.sql");
+
}
/// <summary>
@@ -49,6 +52,44 @@
#endregion
#region Result Map test
+
+ /// <summary>
+ /// Coupons
+ /// </summary>
+ [Test]
+ public void TestCoupons()
+ {
+ IList<Coupon> coupons = sqlMap.QueryForList<Coupon>("GetCouponBrand", null);
+
+ Assert.That(coupons.Count, Is.EqualTo(5));
+ Assert.That(coupons[0].BrandIds[0], Is.EqualTo(1));
+ Assert.That(coupons[0].BrandIds[1], Is.EqualTo(2));
+ Assert.That(coupons[0].BrandIds[2], Is.EqualTo(3));
+ Assert.That(coupons[1].BrandIds[0], Is.EqualTo(4));
+ Assert.That(coupons[1].BrandIds[1], Is.EqualTo(5));
+ Assert.That(coupons[2].BrandIds.Count, Is.EqualTo(0));
+ Assert.That(coupons[3].BrandIds.Count, Is.EqualTo(0));
+ Assert.That(coupons[4].BrandIds[0], Is.EqualTo(6));
+ }
+
+ /// <summary>
+ /// Coupons
+ /// </summary>
+ [Test]
+ public void TestCoupons2()
+ {
+ IList<Coupon> coupons = sqlMap.QueryForList<Coupon>("GetCoupons", null);
+
+ Assert.That(coupons.Count, Is.EqualTo(5));
+ Assert.That(coupons[0].BrandIds[0], Is.EqualTo(1));
+ Assert.That(coupons[0].BrandIds[1], Is.EqualTo(2));
+ Assert.That(coupons[0].BrandIds[2], Is.EqualTo(3));
+ Assert.That(coupons[1].BrandIds[0], Is.EqualTo(4));
+ Assert.That(coupons[1].BrandIds[1], Is.EqualTo(5));
+ Assert.That(coupons[2].BrandIds.Count, Is.EqualTo(0));
+ Assert.That(coupons[3].BrandIds.Count, Is.EqualTo(0));
+ Assert.That(coupons[4].BrandIds[0], Is.EqualTo(6));
+ }
/// <summary>
/// Test generic Ilist :
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/coupons-init.sql
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/coupons-init.sql?rev=576561&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/coupons-init.sql (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/coupons-init.sql Mon Sep 17 12:10:00 2007
@@ -0,0 +1,42 @@
+use [IBatisNet]
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Coupons]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+BEGIN
+ drop table [dbo].[Coupons]
+END
+CREATE TABLE [dbo].[Coupons] (
+ [Coupon_ID] [int] NOT NULL ,
+ [Coupon_Code] [varchar] (32) NOT NULL
+) ON [PRIMARY]
+
+ALTER TABLE [dbo].[Coupons] WITH NOCHECK ADD
+ CONSTRAINT [PK_Coupons] PRIMARY KEY CLUSTERED
+ (
+ [Coupon_ID]
+ ) ON [PRIMARY]
+
+-- Creating Test Data
+
+INSERT INTO [dbo].[Coupons] VALUES(1,'AAA' );
+INSERT INTO [dbo].[Coupons] VALUES(2,'BBB');
+INSERT INTO [dbo].[Coupons] VALUES(3,'CCC');
+INSERT INTO [dbo].[Coupons] VALUES(4,'DDD');
+INSERT INTO [dbo].[Coupons] VALUES(5,'EEE');
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Coupons_Brands]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+BEGIN
+ drop table [dbo].[Coupons_Brands]
+END
+CREATE TABLE [dbo].[Coupons_Brands] (
+ [Coupon_ID] [int] NOT NULL ,
+ [Brand_Id] [int] NOT NULL
+) ON [PRIMARY]
+
+-- Creating Test Data
+
+INSERT INTO [dbo].[Coupons_Brands] VALUES(1,1 );
+INSERT INTO [dbo].[Coupons_Brands] VALUES(1,2);
+INSERT INTO [dbo].[Coupons_Brands] VALUES(1,3);
+INSERT INTO [dbo].[Coupons_Brands] VALUES(2,4);
+INSERT INTO [dbo].[Coupons_Brands] VALUES(2,5);
+INSERT INTO [dbo].[Coupons_Brands] VALUES(5,6);
\ No newline at end of file
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=576561&r1=576560&r2=576561&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 Mon Sep 17 12:10:00 2007
@@ -55,5 +55,6 @@
<sqlMap resource="../../Maps/MSSQL/SqlClient/Simple.xml"/>
<sqlMap resource="../../Maps/MSSQL/SqlClient/ConstructorInjection.xml"/>
<sqlMap resource="../../Maps/MSSQL/SqlClient/GroupByMapping.xml"/>
+ <sqlMap resource="../../Maps/MSSQL/SqlClient/Coupons.xml"/>
</sqlMaps>
</sqlMapConfig>
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=576561&r1=576560&r2=576561&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ArgumentStrategy/ResultMapStrategy.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/ArgumentStrategy/ResultMapStrategy.cs Mon Sep 17 12:10:00 2007
@@ -75,7 +75,7 @@
else
{
obj = resultMapping.CreateInstanceOfResult(parameters);
- if (FillObjectWithReaderAndResultMap(request, reader, resultMapping, obj) == false)
+ if (FillObjectWithReaderAndResultMap(request, reader, resultMapping, ref obj) == false)
{
obj = null;
}
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=576561&r1=576560&r2=576561&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/BaseStrategy.cs Mon Sep 17 12:10:00 2007
@@ -90,8 +90,8 @@
/// <param name="resultMap">The result map.</param>
/// <param name="resultObject">The result object.</param>
/// <returns>Indicates if we have found a row.</returns>
- protected bool FillObjectWithReaderAndResultMap(RequestScope request,IDataReader reader,
- IResultMap resultMap, object resultObject)
+ protected bool FillObjectWithReaderAndResultMap(RequestScope request,IDataReader reader,
+ IResultMap resultMap, ref object resultObject)
{
bool dataFound = false;
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=576561&r1=576560&r2=576561&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/PropertStrategy/ResultMapStrategy.cs Mon Sep 17 12:10:00 2007
@@ -95,7 +95,7 @@
obj = resultMapping.CreateInstanceOfResult(parameters);
// Fills properties on the new object
- if (this.FillObjectWithReaderAndResultMap(request, reader, resultMapping, obj) == false)
+ if (this.FillObjectWithReaderAndResultMap(request, reader, resultMapping, ref obj) == false)
{
obj = null;
}