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 @@
    /&gt;
    &lt;result ... .../&gt;
    &lt;result ... .../&gt;
-
+   <emphasis role="comment"> // Inheritance support</emphasis>
+   &lt;discriminator column="<emphasis role="blue">column.name</emphasis>" 
+                     [formula="<emphasis role="blue">typeAlias</emphasis>"]
+   /&gt;
+    &lt;subMap value="<emphasis role="blue">discriminator.value</emphasis>" 
+               resultMapping="<emphasis role="blue">resultMap.name</emphasis>"
+   /&gt;
+   &lt;subMap .../&gt; 
 &lt;/resultMap&gt;
 </programlisting></para>
       </example>In Example 3.21, the [brackets] indicate optional attributes.
@@ -1367,7 +1374,7 @@
     <sect2>
       <title>&lt;result&gt; Elements</title>
 
-      <para>Sections 3.5.* describe the &lt;resultMap&gt; attributes.</para>
+      <para>This section describe the &lt;resultMap&gt; 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>
+&lt;resultMap <emphasis role="blue">id="document"</emphasis> class="Document"&gt; 
+  &lt;result property="Id" column="Document_ID"/&gt;
+  &lt;result property="Title" column="Document_Title"/&gt;
+  <emphasis role="blue">&lt;discriminator column="Document_Type"/&gt;
+  &lt;subMap value="Book" resultMapping="book"/&gt;
+  &lt;subMap value="Newspaper" resultMapping="newspaper"/&gt;</emphasis>
+&lt;/resultMap&gt;
+
+&lt;id="book" class="Book" <emphasis role="blue">extends="document"</emphasis>&gt; 
+  &lt;property="PageNumber" column="Document_PageNumber"/&gt;
+&lt;/resultMap&gt;
+
+&lt;id="newspaper" class="Newspaper"  <emphasis role="blue">extends="document"</emphasis>&gt; 
+  &lt;property="City" column="Document_City"/&gt;
+&lt;/resultMap&gt;
+
+&lt;select id="GetAllDocument" resultMap="document"&gt; 
+select 
+  *
+from Documents 
+order by Document_Type, Document_Id
+&lt;/select&gt; 
+</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
+{
+  /// &lt;summary&gt;
+  /// Calulate the discriminator value
+  /// from the IDataReader fields
+  /// &lt;/summary&gt;
+  /// &lt;param name="dataReader"&gt;An IDataReader&lt;/param&gt;
+  /// &lt;returns&gt;Return the discriminator value&lt;/returns&gt;
+  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>
+&lt;resultMap id="document-custom-formula" class="Document">
+  &lt;result property="Id" column="Document_ID"/&lt;
+  &lt;result property="Title" column="Document_Title"/&lt;
+  &lt;discriminator <emphasis role="blue">formula="MyFormula"</emphasis>  /&lt; 
+  &lt;subMap value="Book" resultMapping="book" /&lt;
+  &lt;subMap value="Newspaper" resultMapping="newspaper" /&lt;
+&lt;/resultMap/&lt;
+</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>