db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject cvs commit: db-ojb/forrest/src/documentation/content/xdocs/docu mapping-tutorial.xml
Date Sun, 09 May 2004 11:08:50 GMT
tomdz       2004/05/09 04:08:50

  Modified:    forrest/src/documentation/content/xdocs/docu
                        mapping-tutorial.xml
  Log:
  Added proxy customization stuff
  
  Revision  Changes    Path
  1.5       +99 -29    db-ojb/forrest/src/documentation/content/xdocs/docu/mapping-tutorial.xml
  
  Index: mapping-tutorial.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/forrest/src/documentation/content/xdocs/docu/mapping-tutorial.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- mapping-tutorial.xml	4 May 2004 14:19:03 -0000	1.4
  +++ mapping-tutorial.xml	9 May 2004 11:08:50 -0000	1.5
  @@ -38,21 +38,21 @@
                        This tutorial looks at mapping a simple class with no relations:
                     </p>
                     <source><![CDATA[
  -  package org.apache.ojb.tutorials;
  +    package org.apache.ojb.tutorials;
   
  -  public class Product
  -  {
  -      /** price per item*/
  -      private Double price;
  +    public class Product
  +    {
  +        /** product name */
  +        private String name;
   
  -      /** stock of currently available items*/
  -      private Integer stock;
  +        /** price per item */
  +        private Double price;
   
  -      /** product name*/
  -      private String name;
  +        /** stock of currently available items */
  +        private Integer stock;
   
  -      /* Getters and Setters not shown for tutorial */
  -  }
  +        ...
  +    }
                     ]]></source>
                     <p>
                         This class has three fields, <code>price, stock,</code>
and <code>name</code>,
  @@ -61,8 +61,8 @@
                         artificial key primary id:
                     </p>
                     <source><![CDATA[
  -      /** Artificial primary-key */
  -      private Integer id;
  +    /** Artificial primary-key */
  +    private Integer id;
                     ]]></source>
                     <p>
                         Including the primary-key attribute in the class definition is mandatory,
  @@ -83,13 +83,13 @@
                         The DDL for such a table, for the <code>Product</code>
class might look like:
                     </p>
                     <source><![CDATA[
  -  CREATE TABLE product
  -  (
  -      id INTEGER PRIMARY KEY,
  -      name VARCHAR(100),
  -      stock INTEGER,
  -      price DOUBLE
  -  )
  +    CREATE TABLE Product
  +    (
  +        id INTEGER PRIMARY KEY,
  +        name VARCHAR(100),
  +        price DOUBLE,
  +        stock INTEGER
  +    )
                     ]]></source>
                     <p>
                         The individual field names in the database and class definition match
here,
  @@ -117,29 +117,29 @@
                         The complete mapping for the <code>Product</code> class
is as follows:
                     </p>
                     <source><![CDATA[
  -     <class-descriptor
  +    <class-descriptor
              class="org.apache.ojb.tutorials.Product"
  -           table="PRODUCT"
  -     >
  +           table="Product"
  +    >
           <field-descriptor
              name="id"
  -           column="ID"
  +           column="id"
              primarykey="true"
              autoincrement="true"
           />
           <field-descriptor
              name="name"
  -           column="NAME"
  +           column="name"
           />
           <field-descriptor
              name="price"
  -           column="PRICE"
  +           column="price"
           />
           <field-descriptor
              name="stock"
  -           column="STOCK"
  +           column="stock"
           />
  -     </class-descriptor>
  +    </class-descriptor>
                     ]]></source>
                     <p>
                         Examine the <code>class-descriptor</code> element. It
has two attributes:
  @@ -191,7 +191,77 @@
                         </li>
                     </ul>
                 </section>
  +
  +            <anchor id="xdoclet"/>
  +              <section><title>Using the XDoclet module</title>
  +                  <p>
  +                      OJB provides an XDoclet module to make generating the repository
descriptor
  +                      and the corresponding table schema easier. An XDoclet module basically
  +                      processes custom JavaDoc tags in the source code, and generates files
from
  +                      them. In the case of OJB, two types of files can be generated: the
  +                      repository descriptor (<code>repository_user.xml</code>)
and a Torque
  +                      schema which can be used to create the tables in the database. This
provides
  +                      one important benefit: the descriptor and the database schema are
much more
  +                      likely in sync with the code thus avoiding errors that are usually
hard to find.
  +                      Furthermore, the XDoclet module contains some checks that find common
mapping
  +                      errors.
  +                  </p>
  +                  <p>
  +                      In the above example, the source code for Product class with JavaDoc
tags would
  +                      look like:
  +                  </p>
  +                  <source><![CDATA[
  +    package org.apache.ojb.tutorials;
  +
  +    /**
  +     * @ojb.class
  +     */
  +    public class Product
  +    {
  +        /**
  +         * Artificial primary-key
  +         *
  +         * @ojb.field primarykey="true"
  +         *            autoincrement="ojb"
  +         */
  +        private Integer id;
  +
  +        /**
  +         * product name
  +         *
  +         * @ojb.field length="100"
  +         */
  +        private String name;
  +
  +        /**
  +         * price per item
  +         *
  +         * @ojb.field
  +         */
  +        private Double price;
  +
  +        /**
  +         * stock of currently available items
  +         *
  +         * @ojb.field
  +         */
  +        private Integer stock;
  +    }
  +                  ]]></source>
  +                  <p>
  +                      As you can see, much of the stuff that is present in the descriptor
(and the DDL)
  +                      is generated automatically by the XDoclet module, e.g. the table/column
names and
  +                      the jdbc-types. Of course, you can also specify them in the JavaDoc
tags, e.g. if
  +                      they differ from the java names.
  +                  </p>
  +                  <p>
  +                      For details on OJB's JavaDoc tags and how to generate and use the
mapping files
  +                      please see the <link href="site:xdoclet-module">OJB XDoclet
Module documentation</link>.
  +                  </p>
  +              </section>
  +
             </section>
  +
             <section><title>Advanced Topics</title>
                 <section><title>Relations</title>
                     <p>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message