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/05/05 20:55:26 UTC
svn commit: r168385 -
/incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/dotnet.xml
/incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/working.xml
/incubator/ibatis/trunk/cs/docs/doc.build
Author: gbayon
Date: Thu May 5 11:55:26 2005
New Revision: 168385
URL: http://svn.apache.org/viewcvs?rev=168385&view=rev
Log:
- Updated doc for Inheritance and setting validateSqlMap
Modified:
incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/dotnet.xml
incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/working.xml
incubator/ibatis/trunk/cs/docs/doc.build
Modified: incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/dotnet.xml
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/dotnet.xml?rev=168385&r1=168384&r2=168385&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/dotnet.xml (original)
+++ incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/dotnet.xml Thu May 5 11:55:26 2005
@@ -259,6 +259,7 @@
<settings>
<setting useFullyQualifiedStatementNames="false"/>
<setting cacheModelsEnabled="true"/>
+ <setting validateSqlMap="false"/>
</settings>
<database>
@@ -412,6 +413,13 @@
the combination of the sqlMap namesource and the statement id.
For example:
<methodname>queryForObject(âNamespace.statement.Idâ);</methodname></para><programlisting>Example: useStatementNamespaces=âfalseâ
+Default: false (disabled)</programlisting></entry>
+ </row>
+ <row>
+ <entry><emphasis>validateSqlMap </emphasis></entry>
+
+ <entry><para>This setting globally enables or disables the validation of mapping files against the SqlMapConfig.xsd schema. This can come in handy
+ for debugging.</para><programlisting>Example: validateSqlMap=âfalseâ
Default: false (disabled)</programlisting></entry>
</row>
</tbody>
Modified: incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/working.xml
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/working.xml?rev=168385&r1=168384&r2=168385&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/working.xml (original)
+++ incubator/ibatis/trunk/cs/docs/dataMapperGuide/src/en/working.xml Thu May 5 11:55:26 2005
@@ -1294,7 +1294,14 @@
/>
<result ... .../>
<result ... .../>
-
+ <emphasis role="comment"> // Inheritance support</emphasis>
+ <discriminator column="<emphasis role="blue">column.name</emphasis>"
+ [formula="<emphasis role="blue">typeAlias</emphasis>"]
+ />
+ <subMap value="<emphasis role="blue">discriminator.value</emphasis>"
+ resultMapping="<emphasis role="blue">resultMap.name</emphasis>"
+ />
+ <subMap .../>
</resultMap>
</programlisting></para>
</example>In Example 3.21, the [brackets] indicate optional attributes.
@@ -1367,7 +1374,7 @@
<sect2>
<title><result> Elements</title>
- <para>Sections 3.5.* describe the <resultMap> attributes.</para>
+ <para>This section describe the <resultMap> attributes.</para>
<sect3>
<title>property</title>
@@ -1479,6 +1486,174 @@
property mappings/relationships is discussed later in this
document.</para>
</sect3>
+ </sect2>
+
+ <sect2>
+ <title>Inheritance Mapping</title>
+
+ <para>iBATIS DataMapper support for implementing object-oriented inheritance (subclassing) your object model.
+ There are several implementation options for mapping entity classes and subclasses to database tables:<itemizedlist>
+ <listitem>
+ table per class hierarchy
+ </listitem>
+
+ <listitem>
+ table per subclass
+ </listitem>
+
+ <listitem>
+ table per concrete class
+ </listitem>
+
+ </itemizedlist></para>
+
+ <para>You can use the most efficient mapping strategies from a SQL and query performance perspective.
+
+ The Sql result must define one/some column(s) in your result that will serve to identify which resultMap should be used to map the table row.
+ In most case, you will use one column value to identify which resultMap.<example>
+ <title>One column disciminator usage</title>
+
+<programlisting>
+<emphasis role="comment">// .NET class</emphasis>
+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 class Book : Document
+{
+ private int _pageNumber = -1;
+
+ public int PageNumber
+ {
+ get { return _pageNumber; }
+ set { _pageNumber = value; }
+ }
+}
+
+public class Newspaper : Document
+{
+ private string _city = string.Empty;
+
+ public string City
+ {
+ get { return _city; }
+ set { _city = value; }
+ }
+}</programlisting>
+
+<programlisting>
+<emphasis role="comment">// Database table document</emphasis>
+CREATE TABLE [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
+)
+</programlisting>
+<programlisting>
+<emphasis role="comment">// Document mapping file</emphasis>
+<resultMap <emphasis role="blue">id="document"</emphasis> class="Document">
+ <result property="Id" column="Document_ID"/>
+ <result property="Title" column="Document_Title"/>
+ <emphasis role="blue"><discriminator column="Document_Type"/>
+ <subMap value="Book" resultMapping="book"/>
+ <subMap value="Newspaper" resultMapping="newspaper"/></emphasis>
+</resultMap>
+
+<id="book" class="Book" <emphasis role="blue">extends="document"</emphasis>>
+ <property="PageNumber" column="Document_PageNumber"/>
+</resultMap>
+
+<id="newspaper" class="Newspaper" <emphasis role="blue">extends="document"</emphasis>>
+ <property="City" column="Document_City"/>
+</resultMap>
+
+<select id="GetAllDocument" resultMap="document">
+select
+ *
+from Documents
+order by Document_Type, Document_Id
+</select>
+</programlisting>
+ </example>
+ Based on the "Document_Type" column value, iBATIS DataMapper will use the resultMap named "Document" or "Book" or "Newspaper".
+ When you not specify a forumla attribute in the discriminator the comparaison with column value is based on string equivalence.
+
+ If you want a more complex comparaison (discrimination on multiple column, with a formula...), you can use the formula attribute to specify a comparaison method.
+ A formula attribute is a <emphasis role="alias">typeAlias</emphasis> to a class which implements the <emphasis role="blue">IDiscriminatorFormula</emphasis> interface.
+<example>
+ <title>IDiscriminatorFormula interface</title>
+ <programlisting>
+public interface IDiscriminatorFormula
+{
+ /// <summary>
+ /// Calulate the discriminator value
+ /// from the IDataReader fields
+ /// </summary>
+ /// <param name="dataReader">An IDataReader</param>
+ /// <returns>Return the discriminator value</returns>
+ string GetDiscriminatorValue(IDataReader dataReader);
+}
+</programlisting>
+</example><example>
+ <title>Example of IDiscriminatorFormula interface implemantation</title>
+ <programlisting>
+public class MyFormula : IDiscriminatorFormula
+{
+
+ #region IDiscriminatorFormula Members
+
+ public string GetDiscriminatorValue(IDataReader dataReader)
+ {
+ string type = dataReader.GetString(dataReader.GetOrdinal("Document_Type"));
+
+ if (type=="Monograph" || type=="Book")
+ {
+ return "Book";
+ }
+ else if (type=="Tabloid" || type=="Broadsheet" || type=="Newspaper")
+ {
+ return "Newspaper";
+ }
+ else
+ {
+ return "Document";
+ }
+ }
+
+ #endregion
+}
+</programlisting>
+</example>
+<example>
+ <title>Complex disciminator usage with formula</title>
+<programlisting>
+<resultMap id="document-custom-formula" class="Document">
+ <result property="Id" column="Document_ID"/<
+ <result property="Title" column="Document_Title"/<
+ <discriminator <emphasis role="blue">formula="MyFormula"</emphasis> /<
+ <subMap value="Book" resultMapping="book" /<
+ <subMap value="Newspaper" resultMapping="newspaper" /<
+</resultMap/<
+</programlisting>
+ </example>
+ </para>
+
</sect2>
<sect2>
Modified: incubator/ibatis/trunk/cs/docs/doc.build
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/docs/doc.build?rev=168385&r1=168384&r2=168385&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/docs/doc.build (original)
+++ incubator/ibatis/trunk/cs/docs/doc.build Thu May 5 11:55:26 2005
@@ -191,8 +191,8 @@
<delete file="${xml.src.dir}/xsd-config.xml" failonerror="false"/>
<delete file="${xml.src.dir}/xsd-sqlMap.xml" failonerror="false"/>
- <loadfile property="doc.config.schema" file="${src.dir}/IBatisNet.Schemas/SqlMapConfig.xsd" />
- <loadfile property="doc.sqlMap.schema" file="${src.dir}/IBatisNet.Schemas/SqlMap.xsd" />
+ <loadfile property="doc.config.schema" file="${src.dir}/IBatisNet.DataMapper/SqlMapConfig.xsd" />
+ <loadfile property="doc.sqlMap.schema" file="${src.dir}/IBatisNet.DataMapper/SqlMap.xsd" />
<copy file="${xml.src.dir}/xsd-config-template.xml" tofile="${xml.src.dir}/xsd-config.xml" >
<filterchain>