You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by th...@apache.org on 2003/07/11 22:34:23 UTC
cvs commit: db-ojb/xdocs tutorial3.xml
thma 2003/07/11 13:34:23
Modified: xdocs tutorial3.xml
Log:
add documentation for nested fields
Revision Changes Path
1.24 +133 -1 db-ojb/xdocs/tutorial3.xml
Index: tutorial3.xml
===================================================================
RCS file: /home/cvs/db-ojb/xdocs/tutorial3.xml,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- tutorial3.xml 17 Jun 2003 20:49:15 -0000 1.23
+++ tutorial3.xml 11 Jul 2003 20:34:23 -0000 1.24
@@ -76,6 +76,9 @@
</ul>
</li>
<li>
+ <A HREF="#nested objects">nested objects</A>
+ </li>
+ <li>
<A HREF="#instance callbacks">instance callbacks</A>
</li>
<li>
@@ -1822,7 +1825,9 @@
Assume that for some reason we don't want to map a 1:1 association
with a foreign key relationship to a different database table but
read the associated object 'inline' from some columns of the master
- object's table.
+ object's table. This approach is also called 'nested objects'.
+ The section <a href="#nested objects">nested objects</a> contains a
+ different and much simpler approach to implement nested fields.
</p>
<p>
The class <code>org.apache.ojb.broker.ArticleWithStockDetail</code>
@@ -1873,6 +1878,133 @@
]]></source>
</subsection>
+</section>
+
+<section name="nested objects">
+<p>
+ In the last section we discussed the usage of a user written RowReader
+ to implement nested objects. This approach has several disadvantages.
+ <ol>
+ <li>
+ It's necessary to write code and to have some understanding of OJB
+ internals.
+ </li>
+ <li>
+ The user must take care that all nested fields are written back
+ to the database on store.
+ </li>
+ </ol>
+ In this section I show that nested objects can be implemented without
+ writing code, and without any further trouble just by a few settings
+ in the repository.xml file.
+</p>
+<p>
+ The class <code>org.apache.ojb.broker.ArticleWithNestedStockDetail</code>
+ has a <code>stockDetail</code>
+ attribute, holding a reference to a <code>StockDetail</code>
+ object. The class StockDetail is not declared in the XML repository as
+ a first class entity class.
+</p>
+
+<source><![CDATA[
+public class ArticleWithNestedStockDetail implements java.io.Serializable
+{
+ /**
+ * this attribute is not filled through a reference lookup
+ * but with the nested fields feature
+ */
+ protected StockDetail stockDetail;
+
+ ...
+}
+]]></source>
+
+The StockDetail class has the following layout:
+<source><![CDATA[
+public class StockDetail implements java.io.Serializable
+{
+ protected boolean isSelloutArticle;
+
+ protected int minimumStock;
+
+ protected int orderedUnits;
+
+ protected int stock;
+
+ protected String unit;
+
+ ...
+}
+]]></source>
+
+The nested fields semantics can simply declared by the following class-
+descriptor:
+<source><![CDATA[
+ <class-descriptor
+ class="org.apache.ojb.broker.ArticleWithNestedStockDetail"
+ table="Artikel"
+ >
+ <field-descriptor
+ name="articleId"
+ column="Artikel_Nr"
+ jdbc-type="INTEGER"
+ primarykey="true"
+ autoincrement="true"
+ />
+ <field-descriptor
+ name="articleName"
+ column="Artikelname"
+ jdbc-type="VARCHAR"
+ />
+ <field-descriptor
+ name="supplierId"
+ column="Lieferanten_Nr"
+ jdbc-type="INTEGER"
+ />
+ <field-descriptor
+ name="productGroupId"
+ column="Kategorie_Nr"
+ jdbc-type="INTEGER"
+ />
+ <field-descriptor
+ name="stockDetail::unit"
+ column="Liefereinheit"
+ jdbc-type="VARCHAR"
+ />
+ <field-descriptor
+ name="price"
+ column="Einzelpreis"
+ jdbc-type="FLOAT"
+ />
+ <field-descriptor
+ name="stockDetail::stock"
+ column="Lagerbestand"
+ jdbc-type="INTEGER"
+ />
+ <field-descriptor
+ name="stockDetail::orderedUnits"
+ column="BestellteEinheiten"
+ jdbc-type="INTEGER"
+ />
+ <field-descriptor
+ name="stockDetail::minimumStock"
+ column="MindestBestand"
+ jdbc-type="INTEGER"
+ />
+ <field-descriptor
+ name="stockDetail::isSelloutArticle"
+ column="Auslaufartikel"
+ jdbc-type="INTEGER"
+ conversion="org.apache.ojb.broker.accesslayer.conversions.Boolean2IntFieldConversion"
+ />
+ </class-descriptor>
+]]></source>
+<p>
+That's all!
+Just add nested fields by using <code>::</code> to specify attributes of the
+nested object.
+All aspects of storing and retrieving the nested object are managed by OJB.
+</p>
</section>
<section name="instance callbacks">
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org