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 2005/02/27 23:18:09 UTC
svn commit: r155646 - in
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper: ./ Configuration/
Configuration/ResultMapping/ MappedStatements/ Scope/ Test/ Test/Domain/
Test/Maps/MSSQL/SqlClient/ Test/NUnit/SqlMapTests/ Test/Scripts/MSSQL/
Test/bin/Debug/
Author: gbayon
Date: Sun Feb 27 14:18:05 2005
New Revision: 155646
URL: http://svn.apache.org/viewcvs?view=rev&rev=155646
Log:
Updated subMap (inheritance) support
Usage
<resultMap id="document" class="Document">
<result property="Id" column="Document_ID"/>
<result property="Title" column="Document_Title"/>
<discriminator column="Document_Type" [formula="CustomFormula, AssemblyName"] />
-- attribute column (not used if discriminator use a custom formula)
-- attribute formula (not required will used the DefaultFormula) calculate the discriminator value (DefaultFormula is default), else used an aliasType wich implement IDiscriminatorFormula),
<subMap value="Book" -- discriminator value
resultMapping="book" />
</resultMap>
<resultMap id="book"
class="Book"
extend="document">
...
</resultMap>
see InheritanceTest, need to add more unit test for custom formula for example
Added:
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Book.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Document.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Newspaper.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/Discriminator.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubMap.cs
- copied, changed from r155622, incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubClassMap.cs
Removed:
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubClassMap.cs
Modified:
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/DefaultFormula.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs
Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Book.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Book.cs?view=auto&rev=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Book.cs (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Book.cs Sun Feb 27 14:18:05 2005
@@ -0,0 +1,24 @@
+using System;
+
+namespace IBatisNet.DataMapper.Test.Domain
+{
+ /// <summary>
+ /// Description résumée de Book.
+ /// </summary>
+ public class Book : Document
+ {
+ private int _pageNumber = -1;
+
+ public int PageNumber
+ {
+ get
+ {
+ return _pageNumber;
+ }
+ set
+ {
+ _pageNumber = value;
+ }
+ }
+ }
+}
Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Document.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Document.cs?view=auto&rev=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Document.cs (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Document.cs Sun Feb 27 14:18:05 2005
@@ -0,0 +1,44 @@
+using System;
+
+namespace IBatisNet.DataMapper.Test.Domain
+{
+ /// <summary>
+ /// Description résumée de Document.
+ /// </summary>
+ public class Document
+ {
+ private int _id = -1;
+ private string _title = string.Empty;
+
+ public int Id
+ {
+ get
+ {
+ return _id;
+ }
+ set
+ {
+ _id = value;
+ }
+ }
+
+ public string Title
+ {
+ get
+ {
+ return _title;
+ }
+ set
+ {
+ _title = value;
+ }
+ }
+
+ public Document()
+ {
+ //
+ // TODO : ajoutez ici la logique du constructeur
+ //
+ }
+ }
+}
Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Newspaper.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Newspaper.cs?view=auto&rev=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Newspaper.cs (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/Newspaper.cs Sun Feb 27 14:18:05 2005
@@ -0,0 +1,24 @@
+using System;
+
+namespace IBatisNet.DataMapper.Test.Domain
+{
+ /// <summary>
+ /// Description résumée de Newspaper.
+ /// </summary>
+ public class Newspaper : Document
+ {
+ private string _city = string.Empty;
+
+ public string City
+ {
+ get
+ {
+ return _city;
+ }
+ set
+ {
+ _city = value;
+ }
+ }
+ }
+}
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj?view=diff&r1=155645&r2=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj Sun Feb 27 14:18:05 2005
@@ -205,6 +205,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Domain\Book.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Domain\Category.cs"
SubType = "Code"
BuildAction = "Compile"
@@ -215,6 +220,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Domain\Document.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Domain\Enumeration.cs"
SubType = "Code"
BuildAction = "Compile"
@@ -230,6 +240,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Domain\Newspaper.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Domain\Order.cs"
SubType = "Code"
BuildAction = "Compile"
@@ -362,6 +377,10 @@
BuildAction = "Content"
/>
<File
+ RelPath = "Maps\MSSQL\SqlClient\Document.xml"
+ BuildAction = "Content"
+ />
+ <File
RelPath = "Maps\MSSQL\SqlClient\DynamicAccount.xml"
BuildAction = "Content"
/>
@@ -507,6 +526,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "NUnit\SqlMapTests\InheritanceTest.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "NUnit\SqlMapTests\ParameterMapTest.cs"
SubType = "Code"
BuildAction = "Compile"
@@ -603,6 +627,10 @@
/>
<File
RelPath = "Scripts\MSSQL\DBCreation.sql"
+ BuildAction = "Content"
+ />
+ <File
+ RelPath = "Scripts\MSSQL\documents-init.sql"
BuildAction = "Content"
/>
<File
Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml?view=auto&rev=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml Sun Feb 27 14:18:05 2005
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<sqlMap namespace="Document" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="SqlMap.xsd">
+
+ <alias>
+ <typeAlias alias="Document" type="IBatisNet.DataMapper.Test.Domain.Document, IBatisNet.DataMapper.Test" />
+ <typeAlias alias="Book" type="IBatisNet.DataMapper.Test.Domain.Book, IBatisNet.DataMapper.Test" />
+ <typeAlias alias="Newspaper" type="IBatisNet.DataMapper.Test.Domain.Newspaper, IBatisNet.DataMapper.Test" />
+ </alias>
+
+ <resultMaps>
+ <resultMap id="document" class="Document">
+ <result property="Id" column="Document_ID"/>
+ <result property="Title" column="Document_Title"/>
+ <discriminator column="Document_Type" />
+ <subMap value="Book" resultMapping="book" />
+ <subMap value="Newspaper" resultMapping="newspaper" />
+ </resultMap>
+
+ <resultMap id="book" class="Book" extends="document">
+ <result property="PageNumber" column="Document_PageNumber"/>
+ </resultMap>
+
+ <resultMap id="newspaper" class="Newspaper" extends="document">
+ <result property="City" column="Document_City"/>
+ </resultMap>
+
+ </resultMaps>
+
+ <statements>
+
+ <statement id="GetAllDocument"
+ resultMap="document">
+ select
+ *
+ from Documents
+ order by Document_Type
+ </statement>
+
+ </statements>
+
+
+</sqlMap>
\ No newline at end of file
Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs?view=auto&rev=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs Sun Feb 27 14:18:05 2005
@@ -0,0 +1,70 @@
+using System;
+using System.Collections;
+using System.Configuration;
+
+using NUnit.Framework;
+
+using IBatisNet.DataMapper; //<-- To access the definition of the deleagte RowDelegate
+using IBatisNet.DataMapper.MappedStatements; //<-- To access the definition of the PageinatedList
+using IBatisNet.Common;
+using IBatisNet.Common.Exceptions;
+
+using IBatisNet.DataMapper.Test;
+using IBatisNet.DataMapper.Test.Domain;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests
+{
+ /// <summary>
+ /// Summary description for InheritanceTest.
+ /// </summary>
+ [TestFixture]
+ public class InheritanceTest: BaseTest
+ {
+
+ #region SetUp & TearDown
+
+ /// <summary>
+ /// SetUp
+ /// </summary>
+ [SetUp]
+ public void Init()
+ {
+ InitSqlMap();
+ InitScript( sqlMap.DataSource, ScriptDirectory + "documents-init.sql" );
+ }
+
+
+ /// <summary>
+ /// TearDown
+ /// </summary>
+ [TearDown]
+ public void Dispose()
+ { /* ... */ }
+
+ #endregion
+
+ /// <summary>
+ /// </summary>
+ [Test]
+ public void GetAllDocument()
+ {
+ IList list = sqlMap.QueryForList("GetAllDocument", null);
+
+ Assert.AreEqual(3, list.Count);
+ Book book = (Book) list[0];
+ Assert.AreEqual(1, book.Id);
+ Assert.AreEqual("The World of Null-A", book.Title);
+ Assert.AreEqual(55, book.PageNumber);
+
+ book = (Book) list[1];
+ Assert.AreEqual(3, book.Id);
+ Assert.AreEqual("Lord of the Rings", book.Title);
+ Assert.AreEqual(3587, book.PageNumber);
+
+ Newspaper news = (Newspaper) list[2];
+ Assert.AreEqual(2, news.Id);
+ Assert.AreEqual("Le Progres de Lyon", news.Title);
+ Assert.AreEqual("Lyon", news.City);
+ }
+ }
+}
Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql?view=auto&rev=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Scripts/MSSQL/documents-init.sql Sun Feb 27 14:18:05 2005
@@ -0,0 +1,31 @@
+-- Creating Table
+
+use [IBatisNet]
+
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Documents]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
+BEGIN
+ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_LineItems_Orders]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
+ ALTER TABLE [dbo].[LineItems] DROP CONSTRAINT FK_LineItems_Orders
+
+ drop table [dbo].[Documents]
+END
+
+CREATE TABLE [dbo].[Documents] (
+ [Document_ID] [int] NOT NULL ,
+ [Document_Title] [varchar] (32) NULL ,
+ [Document_Type] [varchar] (32) NULL ,
+ [Document_PageNumber] [int] NULL ,
+ [Document_City] [varchar] (32) NULL
+) ON [PRIMARY]
+
+ALTER TABLE [dbo].[Documents] WITH NOCHECK ADD
+ CONSTRAINT [PK_Documents] PRIMARY KEY CLUSTERED
+ (
+ [Document_ID]
+ ) ON [PRIMARY]
+
+-- Creating Test Data
+
+INSERT INTO [dbo].[Documents] VALUES (1, 'The World of Null-A', 'Book', 55, null);
+INSERT INTO [dbo].[Documents] VALUES (2, 'Le Progres de Lyon', 'Newspaper', null , 'Lyon');
+INSERT INTO [dbo].[Documents] VALUES (3, 'Lord of the Rings', 'Book', 3587, null);
\ No newline at end of file
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config?view=diff&r1=155645&r2=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/SqlMap_MSSQL_SqlClient.config Sun Feb 27 14:18:05 2005
@@ -30,6 +30,7 @@
<sqlMap resource="Maps/MSSQL/SqlClient/Enumeration.xml"/>
<sqlMap resource="Maps/MSSQL/SqlClient/Other.xml"/>
<sqlMap resource="Maps/MSSQL/SqlClient/ResultClass.xml"/>
+ <sqlMap resource="Maps/MSSQL/SqlClient/Document.xml"/>
<!-- Rem : If used as embbeded Resources, use
<sqlMap embedded="Account.xml, IBatisNet.Test"/>
-->
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?view=diff&r1=155645&r2=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs Sun Feb 27 14:18:05 2005
@@ -63,7 +63,10 @@
{
#region Constant
private const string DEFAULT_PROVIDER_NAME = "_DEFAULT_PROVIDER_NAME";
- private const string DOT = ".";
+ /// <summary>
+ /// Dot representation
+ /// </summary>
+ public const string DOT = ".";
private const string PARAMETER_TOKEN = "#";
/// <summary>
@@ -328,7 +331,7 @@
}
#endregion
- #region Load the mapping files
+ #region Load sqlMap mapping files
foreach (XmlNode xmlNode in _sqlMapConfig.SelectNodes("/sqlMapConfig/sqlMaps/sqlMap"))
{
@@ -337,19 +340,23 @@
#endregion
- #region Resolve "resulMap" attribut on ResultProperty
+ #region Resolve "resulMap" attribut on Result Property + initialize Discriminator property
foreach(DictionaryEntry entry in sqlMap.ResultMaps)
{
ResultMap resultMap = (ResultMap)entry.Value;
foreach(DictionaryEntry item in resultMap.ColumnsToPropertiesMap)
{
- ResultProperty property = (ResultProperty)item.Value;
- if(property.ResulMapName.Length >0)
+ ResultProperty result = (ResultProperty)item.Value;
+ if(result.ResulMapName.Length >0)
{
- property.ResultMap = sqlMap.GetResultMap(property.ResulMapName);
+ result.ResultMap = sqlMap.GetResultMap(result.ResulMapName);
}
}
+ if (resultMap.Discriminator != null)
+ {
+ resultMap.Discriminator.Initialize(sqlMap);
+ }
}
#endregion
@@ -1263,6 +1270,7 @@
if (sqlMap.ResultMaps.Contains( sqlMapName + DOT + id ) == false)
{
resultMap = (ResultMap) serializer.Deserialize(new XmlNodeReader(resultMapNode));
+ resultMap.SqlMapName = sqlMapName;
resultMap.Initialize( sqlMap, resultMapNode);
resultMap.Id = sqlMapName + DOT + resultMap.Id;
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/DefaultFormula.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/DefaultFormula.cs?view=diff&r1=155645&r2=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/DefaultFormula.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/DefaultFormula.cs Sun Feb 27 14:18:05 2005
@@ -46,6 +46,8 @@
#endregion
+ #region Constructor
+
/// <summary>
/// Constructor
/// </summary>
@@ -54,6 +56,8 @@
{
_discriminatorColumn = discriminatorColumn;
}
+ #endregion
+
#region IDiscriminatorFormula members
/// <summary>
Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/Discriminator.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/Discriminator.cs?view=auto&rev=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/Discriminator.cs (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/Discriminator.cs Sun Feb 27 14:18:05 2005
@@ -0,0 +1,173 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ * Author : Gilles Bayon
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Apache Fondation
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ********************************************************************************/
+#endregion
+
+#region Using
+using System;
+using System.Data;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Reflection;
+using System.Xml;
+using System.Xml.Serialization;
+
+using IBatisNet.Common.Exceptions;
+
+#endregion
+
+namespace IBatisNet.DataMapper.Configuration.ResultMapping
+{
+ /// <summary>
+ /// Summary description for Discriminator.
+ /// </summary>
+ [Serializable]
+ [XmlRoot("discriminator")]
+ public class Discriminator
+ {
+
+ #region Fields
+ [NonSerialized]
+ private string _discriminatorColumn = string.Empty;
+ [NonSerialized]
+ private IDiscriminatorFormula _formula = null;
+ /// <summary>
+ /// (discriminatorValue (string), ResulMap)
+ /// </summary>
+ [NonSerialized]
+ private HybridDictionary _resultMaps = null;
+ /// <summary>
+ /// The subMaps name who used this discriminator
+ /// </summary>
+ [NonSerialized]
+ private ArrayList _subMaps = null;
+ [NonSerialized]
+ private string _formulaClassName = string.Empty;//typeof(DefaultFormula).FullName;
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Column Name
+ /// </summary>
+ [XmlAttribute("formula")]
+ public string FormulaClassName
+ {
+ get { return _formulaClassName; }
+ set { _formulaClassName = value; }
+ }
+
+ /// <summary>
+ /// Column Name
+ /// </summary>
+ [XmlAttribute("column")]
+ public string DiscriminatorColumn
+ {
+ get { return _discriminatorColumn; }
+ set { _discriminatorColumn = value; }
+ }
+
+ /// <summary>
+ /// A formula to calculate the discriminator value to use
+ /// </summary>
+ [XmlIgnoreAttribute]
+ public IDiscriminatorFormula Formula
+ {
+ get
+ {
+ return _formula;
+ }
+ set
+ {
+ _formula = value;
+ }
+ }
+ #endregion
+
+ #region Constructor
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ public Discriminator()
+ {
+ _resultMaps = new HybridDictionary();
+ _subMaps = new ArrayList();
+ }
+ #endregion
+
+ #region Methods
+
+ /// <summary>
+ /// Initialize the Discriminator
+ /// </summary>
+ /// <param name="sqlMap"></param>
+ public void Initialize(SqlMapper sqlMap)
+ {
+ // Set the formula
+ if (_formulaClassName.Length == 0)
+ {
+ _formula = new DefaultFormula(_discriminatorColumn);
+ }
+ else
+ {
+ Type formulaType = sqlMap.GetType(_formulaClassName);
+ _formula = Activator.CreateInstance(formulaType) as IDiscriminatorFormula;
+ }
+
+ // Set the ResultMaps
+ for(int index=0; index<_subMaps.Count; index++)
+ {
+ SubMap subMap = _subMaps[index] as SubMap;
+ _resultMaps.Add(subMap.DiscriminatorValue, sqlMap.GetResultMap( subMap.ResulMapName ) );
+ }
+ }
+
+ /// <summary>
+ /// Add a subMap that the discrimator must treat
+ /// </summary>
+ /// <param name="subMap">A subMap</param>
+ public void Add(SubMap subMap)
+ {
+ _subMaps.Add(subMap);
+ }
+
+ /// <summary>
+ /// Find the SubMap to use.
+ /// </summary>
+ /// <param name="dataReader">A IDataReader which contains result values</param>
+ /// <returns>The find ResultMap</returns>
+ public ResultMap GetResultMap(IDataReader dataReader)
+ {
+ // récupérer le resultmap correspondant
+ // 1/ récupérer la valeur de la colonne (en string)
+ // 2/ récupérer
+ string discriminatorValue = _formula.GetDiscriminatorValue(dataReader);
+ return _resultMaps[discriminatorValue] as ResultMap;
+ }
+ #endregion
+
+
+ }
+}
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs?view=diff&r1=155645&r2=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs Sun Feb 27 14:18:05 2005
@@ -57,13 +57,50 @@
[NonSerialized]
private string _extendMap = string.Empty;
[NonSerialized]
- private Type _class;
+ private Type _class = null;
//(columnName, property)
[NonSerialized]
- private Hashtable _columnsToPropertiesMap = new Hashtable();
+ private Hashtable _columnsToPropertiesMap = new Hashtable();
+ [NonSerialized]
+ private Discriminator _discriminator = null;
+ [NonSerialized]
+ private string _sqlMapName = string.Empty;
#endregion
#region Properties
+
+ /// <summary>
+ /// The sqlMap name parent
+ /// </summary>
+ [XmlIgnoreAttribute]
+ public string SqlMapName
+ {
+ get
+ {
+ return _sqlMapName;
+ }
+ set
+ {
+ _sqlMapName = value;
+ }
+ }
+
+ /// <summary>
+ /// The discriminator used to choose the good SubMap
+ /// </summary>
+ [XmlIgnoreAttribute]
+ public Discriminator Discriminator
+ {
+ get
+ {
+ return _discriminator;
+ }
+ set
+ {
+ _discriminator = value;
+ }
+ }
+
/// <summary>
/// The collection of result properties.
/// </summary>
@@ -152,8 +189,8 @@
{
_class = sqlMap.GetType(_className);
- // Load the properties
- GetProperties(node);
+ // Load the child node
+ GetChildNode(node);
}
catch(Exception e)
{
@@ -165,13 +202,16 @@
/// <summary>
- /// Get the result properties from the xmNode.
+ /// Get the result properties and the subMap properties.
/// </summary>
/// <param name="node">An xmlNode.</param>
- private void GetProperties(XmlNode node)
+ private void GetChildNode(XmlNode node)
{
XmlSerializer serializer = null;
ResultProperty property = null;
+ SubMap subMap = null;
+
+ #region Load the Result Properties
serializer = new XmlSerializer(typeof(ResultProperty));
foreach ( XmlNode resultNode in node.SelectNodes("result") )
@@ -188,6 +228,28 @@
this.AddResultPropery( property );
}
+ #endregion
+
+ #region Load the Discriminator Property
+
+ serializer = new XmlSerializer(typeof(Discriminator));
+ XmlNode discriminatorNode = node.SelectSingleNode("discriminator");
+ if (discriminatorNode != null)
+ {
+ this.Discriminator = (Discriminator) serializer.Deserialize(new XmlNodeReader(discriminatorNode));
+ }
+ #endregion
+
+ #region Load the SubMap Properties
+
+ serializer = new XmlSerializer(typeof(SubMap));
+ foreach ( XmlNode resultNode in node.SelectNodes("subMap") )
+ {
+ subMap = (SubMap) serializer.Deserialize(new XmlNodeReader(resultNode));
+ subMap.ResulMapName = this.SqlMapName + DomSqlMapBuilder.DOT + subMap.ResulMapName;
+ this.Discriminator.Add( subMap );
+ }
+ #endregion
}
#endregion
Copied: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubMap.cs (from r155622, incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubClassMap.cs)
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubMap.cs?view=diff&rev=155646&p1=incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubClassMap.cs&r1=155622&p2=incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubMap.cs&r2=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubClassMap.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/SubMap.cs Sun Feb 27 14:18:05 2005
@@ -40,80 +40,81 @@
namespace IBatisNet.DataMapper.Configuration.ResultMapping
{
/// <summary>
- /// Summary description for SubClassMap.
+ /// Summary description for SubMap.
/// </summary>
[Serializable]
+ [XmlRoot("subMap")]
public class SubMap
{
+ // <resultMap id="document" class="Document">
+ // <result property="Id" column="Document_ID"/>
+ // <result property="Title" column="Document_Title"/>
+ // <discriminator column="Document_Type" [formula="CustomFormula, AssemblyName"] />
+ // -- attribute column (not used if discriminator use a custom formula)
+ // -- attribute formula (not required will used the DefaultFormula) calculate the discriminator value (DefaultFormula is default), else used an aliasType wich implement IDiscriminatorFormula),
+ // <subMap value="Book" -- discriminator value
+ // resultMapping="book" />
+ // </resultMap>
+ //
+ // <resultMap
+ // id="book"
+ // class="Book"
+ // extend="document">
+ // ...
+ // </resultMap>
#region Fields
-
- /// <summary>
- /// (discriminatorValue (string), ResulMap)
- /// </summary>
- private HybridDictionary _resultMaps = null;
- private IDiscriminatorFormula _formula = null;
- private string _discriminatorColumn = string.Empty;
-
+ [NonSerialized]
+ private string _discriminatorValue = string.Empty;
+ [NonSerialized]
+ private string _resulMapName = string.Empty;
+ [NonSerialized]
+ private ResultMap _resulMap = null;
#endregion
+ #region Properties
+
/// <summary>
- /// A formula to calculate the discriminator value to use
+ /// Discriminator value
/// </summary>
- public IDiscriminatorFormula Formula
+ [XmlAttribute("value")]
+ public string DiscriminatorValue
{
- get
- {
- return _formula;
- }
- set
- {
- _formula = value;
- }
+ get { return _discriminatorValue; }
+ set { _discriminatorValue = value; }
}
/// <summary>
- /// Constructor
+ /// The name of the ResultMap used if the column value is = to the Discriminator Value
/// </summary>
- public SubMap(string discriminatorColumn)
+ [XmlAttribute("resultMapping")]
+ public string ResulMapName
{
- _formula = new DefaultFormula(discriminatorColumn);
- _discriminatorColumn = discriminatorColumn;
- _resultMaps = new HybridDictionary();
+ get { return _resulMapName; }
+ set { _resulMapName = value; }
}
/// <summary>
- /// Add a subclass resultMap
+ /// The resultMap used if the column value is = to the Discriminator Value
/// </summary>
- /// <param name="discriminatorValue">The discriminator Value which identify the ResultMap</param>
- /// <param name="resultMap">The corresponding ResultMap</param>
- public void Add(string discriminatorValue, ResultMap resultMap)
+ [XmlIgnoreAttribute]
+ public ResultMap ResultMap
{
- _resultMaps.Add(discriminatorValue, resultMap);
+ get { return _resulMap; }
+ set { _resulMap = value; }
}
-// <resultMap name="document" class="Document">
-// <result property="Id" column="Document_ID"/>
-// <result property="Title" column="Document_Title"/>
-// <subMap column="Document_Type"
-// value="Book" -- discriminator value
-// formula="DefaultFormula, iBatisNet.DataMapper" -- discriminator type (DefaultFormula is default), else used an aliasType wich implement IDiscriminatorFormula)
-// resultMap="bookResultMap"
-// />
-// </resultMap>
+ #endregion
+
+ #region Constructor
/// <summary>
- /// Find the ResultMap to use.
+ /// Constructor
/// </summary>
- /// <param name="dataReader">A IDataReader which contains result values</param>
- /// <returns>The find ResultMap</returns>
- public ResultMap GetResultMap(IDataReader dataReader)
+ public SubMap()
{
- // récupérer le resultmap correspondant
- // 1/ récupérer la valeur de la colonne (en string)
- // 2/ récupérer
- string discriminatorValue = _formula.GetDiscriminatorValue(dataReader);
- return _resultMaps[discriminatorValue] as ResultMap;
}
+ #endregion
+
}
}
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj?view=diff&r1=155645&r2=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj Sun Feb 27 14:18:05 2005
@@ -233,6 +233,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Configuration\ResultMapping\Discriminator.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Configuration\ResultMapping\IDiscriminatorFormula.cs"
SubType = "Code"
BuildAction = "Compile"
@@ -248,7 +253,7 @@
BuildAction = "Compile"
/>
<File
- RelPath = "Configuration\ResultMapping\SubClassMap.cs"
+ RelPath = "Configuration\ResultMapping\SubMap.cs"
SubType = "Code"
BuildAction = "Compile"
/>
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs?view=diff&r1=155645&r2=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs Sun Feb 27 14:18:05 2005
@@ -362,6 +362,8 @@
{
object outObject = resultObject;
+ request.CheckResultMap(reader);
+
// If there's an ResultMap, use it
if (request.ResultMap != null)
{
@@ -414,6 +416,7 @@
}
}
+ request.Reset();
return outObject;
}
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs?view=diff&r1=155645&r2=155646
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs Sun Feb 27 14:18:05 2005
@@ -24,8 +24,9 @@
********************************************************************************/
#endregion
-#region Imports
+#region Using
using System;
+using System.Data;
using System.Collections;
using IBatisNet.DataMapper.Configuration.ParameterMapping;
@@ -44,6 +45,7 @@
private ParameterMap _parameterMap = null;
private ResultMap _resultMap = null;
+ private ResultMap _oldResultMap = null;
private PreparedStatement _preparedStatement = null;
private Queue _properties = new Queue();
@@ -87,6 +89,27 @@
set { _preparedStatement = value; }
}
#endregion
+
+ /// <summary>
+ /// Check if the ResultMap is well set, process case of subMap resultMap
+ /// </summary>
+ /// <param name="dataReader">The current IDataReader</param>
+ public void CheckResultMap(IDataReader dataReader)
+ {
+ _oldResultMap = _resultMap;
+ if (_resultMap != null && _resultMap.Discriminator != null)
+ {
+ _resultMap = _resultMap.Discriminator.GetResultMap(dataReader);
+ }
+ }
+
+ /// <summary>
+ /// Reset
+ /// </summary>
+ public void Reset()
+ {
+ _resultMap = _oldResultMap;
+ }
}
}