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 ar...@apache.org on 2003/01/31 18:42:45 UTC
cvs commit: jakarta-ojb/xdocs faq.xml performance.xml
arminw 2003/01/31 09:42:45
Modified: xdocs faq.xml performance.xml
Log:
add more faq, correct document view
Revision Changes Path
1.13 +274 -11 jakarta-ojb/xdocs/faq.xml
Index: faq.xml
===================================================================
RCS file: /home/cvs/jakarta-ojb/xdocs/faq.xml,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- faq.xml 31 Jan 2003 06:56:49 -0000 1.12
+++ faq.xml 31 Jan 2003 17:42:44 -0000 1.13
@@ -4,6 +4,7 @@
<properties>
<author email="thma@apache.org">Thomas Mahler</author>
<author email="tobrien@transolutions.net">Tim O'Brien</author>
+ <author>Armin Waibel</author>
<title>ObJectRelationalBridge FAQ</title>
</properties>
@@ -16,9 +17,9 @@
<li><a href="#8">How is OJB related to ODMG and JDO?</a></li>
<li><a href="#17">What are the OJB design principals?</a></li>
<li><a href="#18">Where can I learn more about Object/Relational mapping in general?</a></li>
-
+
</ul>
-
+
<p><b>Getting started</b></p>
<ul>
<li><a href="#1">Help! I'm having problems installing and using OJB!</a></li>
@@ -26,19 +27,20 @@
<li><a href="#4">Does OJB support my RDBMS?</a></li>
<li><a href="#10">What are the OJB internal tables for?</a></li>
- </ul>
-
+ </ul>
+
<p><b>OJB APIs</b></p>
<ul>
<li><a href="#9">What are the differences between the PersistenceBroker API and the ODMG API? Which one should I use in my applications?</a></li>
<li><a href="#15">I don't like OQL, can I use the PersistenceBroker Queries within ODMG?</a></li>
<li><a href="#16">The OJB JDO implementation is not finished, how can I start using OJB?</a></li>
-
+
</ul>
-
- <p><b>Howto</b></p>
+
+ <p><b>Howto</b></p>
<ul>
<li><a href="#5">How to use OJB with my RDBMS?</a></li>
+ <li><a href="#32">What the best settings for maximal performance?</a></li>
<li><a href="#6">How to page and sort?</a></li>
<li><a href="#7">What about performance and memory usage if thousands of objects matching a query are returned as a Collection?</a></li>
<li><a href="#11">When is it helpful to use Proxy Classes?</a></li>
@@ -46,7 +48,20 @@
<li><a href="#13">How can I trace and/or profile SQL statements executed by OJB?</a></li>
<li><a href="#14">How does OJB manage foreign keys?</a></li>
<li><a href="#19">How can Collections of primitive typed elements be mapped?</a></li>
-
+
+ <li><a href="#20">How could class 'myClass' represent a collection of 'myClass' objects</a></li>
+ <li><a href="#21">Many different database user - How do they login?</a></li>
+ <li><a href="#22">How do I use multiple databases within OJB?</a></li>
+ <li><a href="#23">How does OJB handle connection pooling?</a></li>
+ <li><a href="#24">Can I directly obtain a <code>java.sql.Connection</code> within OJB?</a></li>
+ <li><a href="#25">Is it possible to perform my own sql-queries in OJB?</a></li>
+ <li><a href="#31">Start OJB without a repository file?</a></li>
+ <li><a href="#26">Connect to database at runtime?</a></li>
+ <li><a href="#27">Add new persistent objects (<code>class-descriptor</code>) at runtime?</a></li>
+ <li><a href="#28">Global metadata changes at runtime?</a></li>
+ <li><a href="#29">Per thread metadata changes at runtime?</a></li>
+ <li><a href="#30">Is it possible to use OJB within EJB's?</a></li>
+
</ul>
<subsection name="Help! I'm having problems installing and using OJB!" anchor="1">
@@ -222,7 +237,7 @@
<subsection name="What are the OJB design principals?" anchor="17">
<p>
- OJB has a "pattern driven" design.
+ OJB has a "pattern driven" design.
<a href="links.html#design">Please refer to this document for more details</a>
</p>
</subsection>
@@ -236,12 +251,12 @@
<subsection name="How can Collections of primitive typed elements be mapped?" anchor="19">
<p>
The first thing to ask is:
- How are these primitive typed elements (Strings are also treated as primitive types here)
+ How are these primitive typed elements (Strings are also treated as primitive types here)
stored in the database.<br/>
1) are they treated as ordinary domain objects and stored in a separate table?<br/>
2) are they serialized into a Varchar field?<br/>
3) are they stored as a comma separated varchar field?<br/>
- 4) is each element of the vector or array stored in a separate column?
+ 4) is each element of the vector or array stored in a separate column?
(this solution does only work for a fixed number of elements!)<br/>
<br/>
Follow these steps for solution 3):<br/>
@@ -266,6 +281,42 @@
</p>
</subsection>
+
+ <subsection name="What are the best settings for maximal performance?" anchor="32">
+ <p>
+ We don't know, that depends from the environment OJB runs (hardware, database, driver, application server, ...).
+ But there are some settings which affect the performance:
+ <ul>
+ <li>The API you use, e.g. PB-api is much faster then the ODMG-api. See <a href="#9">which API</a> for more information</li>
+ <li>PersistenceBroker pool size. See <a href="OJB.properties.txt">OJB.properties</a> for more information.</li>
+ <li>Used sequence manager implementation. See <a href="sequencemanager.html">sequence manager</a> for more information.</li>
+ <li>ConnectionFactory implementation / Connection pooling. See <a href="#23">connection pooling</a> for more information.</li>
+ <li>Use of batch mode (when supported by the DB). See <a href="repository.dtd.txt">repository.dtd</a> for more information.</li>
+ </ul>
+ </p>
+ <p>
+ To test the different settings OJB was shipped with a small performance
+ test suite, call
+ <code>bin\build.bat <font color="red">xxx</font></code> or
+ <code>bin/build.sh <font color="red">xxx</font></code> with xxx:
+ <ul>
+ <li><code>performance</code>
+ <br/>
+ This test compare the OJB api's with direct JDBC calls. To change the programm
+ parameters see <code>build.xml</code> target <code>performance</code>.
+ </li>
+ <li><code>performance2</code>
+ <br/>
+ This test checks the multi-threaded performance of OJB. To change the programm
+ parameters see <code>build.xml</code> target <code>performance2</code>. It's also
+ possible to run this test standalone, see javadocs <code>org.apache.ojb.broker.Performance2</code>
+ </li>
+ </ul>
+ See for further information <a href="performance.html">performance</a> section.
+ </p>
+ </subsection>
+
+
<subsection name="How to page and sort?" anchor="6">
<p>
Sorting can be configured by
@@ -501,6 +552,7 @@
</subsection>
+
<subsection name="How can I trace and/or profile SQL statements executed by OJB?" anchor="13">
<p>
OJB ships with out of the box support for P6Spy.
@@ -645,6 +697,217 @@
Making it work with OJB-JDO will be easy!
</p>
</subsection>
+
+<subsection name="How could class 'myClass' represent a collection of 'myClass' objects" anchor="20">
+ <p>
+ OJB can handle such recursive associations without problems.
+ <ul>
+ <li>
+ add a collection attribute 'myClasses' to the class <code>myClass</code>
+ this collection will hold the associated <code>myClass</code> objects.
+ </li>
+ <li>
+ you have to decide wether this assosciation is 1:n or m:n.
+ <br/>
+ for 1:n you just need an additional foreignkey attribute in the MY_CLASS
+ table. Of course you'll also need a matching attribute in the class <code>myClass</code>.
+ <br/>
+ For a m:n association you'll have to define a intermediary table to hold the
+ mapping entries.
+ </li>
+ <li>
+ define a <code>collection-descriptor</code> tag in the <code>class-descriptor</code>
+ of <code>myClass</code> in repository.xml.
+ Follow the steps in <A HREF="tutorial3.html">tutorial3.html</A> on 1:n and m:n.
+ </li>
+ </ul>
+ </p>
+ </subsection>
+
+
+ <subsection name="Many different database user - How do they login?" anchor="21">
+ <p>
+ There are two ways to do that. Define for each user a <code>jdbc-connection-descriptor</code>
+ (unattractive way, because we have to add each new user to repository file),
+ or let OJB handle this for you.
+ <br/>
+ For it define <b>one</b> <code>jdbc-connection-descriptor</code>,
+ now you can use the same <code>jcdAlias</code> name with different <code>User/Password</code>. OJB
+ <b>copy</b> the defined <code>jdbc-connection-descriptor</code> and replace the <code>username</code>
+ and <code>password</code> with the given <code>User/Password</code>. Keep in mind, when the
+ <code>connection-pool</code> element enables connection pooling, every user get its separate pool.
+ See <a HREF="#23">How does OJB handle connection pooling</a>.
+ </p>
+ </subsection>
+
+
+ <subsection name="How do I use multiple databases within OJB?" anchor="22">
+ <p>
+ Define for each database a <code>jdbc-connection-descriptor</code>, use the
+ different <code>jcdAlias</code> names to match the according database.
+ </p>
+ </subsection>
+
+
+ <subsection name="How does OJB handle connection pooling?" anchor="23">
+ <p>
+ OJB does connection pooling per default, expect for datasources. Datasources never will be pooled.
+ <br/>
+ Responsible for managing the connections in OJB are implementations of the
+ <code>org.apache.ojb.broker.accesslayer.ConnectionFactory.java</code>
+ interface. There are several implementations shipped with OJB called
+ <code>org.apache.ojb.broker.accesslayer.ConnectionFactoryXXXImpl.java</code>.
+ You can find among other things a none pooling implementation and a implementation
+ using jakarta-DBCP api.
+ <br/>
+ To manage the connection pooling define in your <code>jdbc-connection-descriptor</code> a
+ <code>connection-pool</code> element. Here you can specify which <code>ConnectionFactory</code> implementation
+ should be used. More info see <a HREF="repository.html">repository section</a>
+ or <a HREF="repository.dtd.txt">repository.dtd</a>.
+ </p>
+ </subsection>
+
+
+ <subsection name="Can I directly obtain a java.sql.Connection within OJB?" anchor="24">
+ <p>
+ The PB-api enabled the possibility to obtain a connection from the current
+ used <code>PersistenceBroker</code> instance:
+ <source>
+PersistenceBroker broker = PersistenceBrokerFactory.
+ createPersistenceBroker(myKey);
+broker.beginTransaction();
+// do something
+
+Connection con = broker.serviceConnectionManager().getConnection();
+// perform your connction action and do more
+
+broker.commitTransaction();
+broker.close();
+ </source>
+ Do not close or commit the connection, this will be done by OJB.
+ See ditto <a href="#25">perform sql queries</a>.
+ </p>
+ </subsection>
+
+
+ <subsection name="Is it possible to perform my own sql-queries in OJB?" anchor="25">
+ <p>
+ There are serveral ways in OJB to do that.
+ <br/>
+ If you completely want to bypass the OJB
+ query-api see <a href="#21">direct connection use</a>.
+ <br/>
+ A more elegant way is to use a <code>QueryBySQL</code> object:
+ <source>
+String sql =
+ "SELECT A.Artikel_Nr FROM Artikel A, Kategorien PG"
+ + " WHERE A.Kategorie_Nr = PG.Kategorie_Nr"
+ + " AND PG.Kategorie_Nr = 2";
+// get the QueryBySQL
+Query q2 = QueryFactory.newQuery(Article.class, sql);
+
+Iterator iter2 = broker.getIteratorByQuery(q2);
+// or
+Collection col2 = broker.getCollectionByQuery(q2);
+ </source>
+ </p>
+ </subsection>
+
+
+ <subsection name="Start OJB without a repository file?" anchor="31">
+ <p>
+ It is possible to start OJB with an 'empty' repository.xml file:
+ <source><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE descriptor-repository SYSTEM "repository.dtd">
+
+<descriptor-repository version="0.9.9" isolation-level="read-uncommitted">
+
+</descriptor-repository>
+ ]]></source>
+ Now you have to declare the <code>jdbc-connection-descriptor</code> and
+ <code>class-descriptor</code> at runtime. See <a href="#26">Connect to database at
+ runtime</a> and <a href="#27">Add a new persistent object (class-descriptor) at runtime</a>
+ for more information.
+ </p>
+ </subsection>
+
+
+
+ <subsection name="Connect to database at runtime?" anchor="26">
+ <p>
+ You could add <code>jdbc-connection-descriptors</code> at runtime, using
+ the <code>MetadataManager</code>:
+ <source>
+ConnectionRepository cr = MetadataManager.
+ getInstance().connectionRepository();
+
+JdbcConnectionDescriptor jcd = new JdbcConnectionDescriptor();
+jcd.setJcdAlias("testConnection")
+jcd.setUserName("sa");
+jcd.setPassword("sa");
+jcd.setDbAlias("aAlias");
+jcd.setDbms("aDatabase");
+// .... the other required setter
+
+// add new descriptor
+cr.addDescriptor(jcd);
+
+// Now it's possible to obtain a PB-instance
+PBKey key = new PBKey("testConnection", "sa", "sa");
+PersistenceBroker broker = PersistenceBrokerFactory.
+ createPersistenceBroker(key);
+ </source>
+ </p>
+ </subsection>
+
+
+ <subsection name="Add a new persistent object (class-descriptor) at runtime?" anchor="27">
+ <p>
+ You could add <code>class-descriptors</code> at runtime, using
+ the <code>MetadataManager</code>:
+ <source>
+DescriptorRepository dr = MetadataManager.
+ getInstance().getRepository();
+
+ClassDescriptor cld = new ClassDescriptor(dr);
+cld.setClassOfObject(A.class);
+//.... other setter
+
+// add the fields of the class
+FieldDescriptor fd = new FieldDescriptor(cld, 1);
+fd.setPersistentField(A.class, "someAField");
+cld.addFieldDescriptor(fd);
+
+// now we add the the class descriptor
+dr.setClassDescriptor(cld);
+ </source>
+ </p>
+ </subsection>
+
+
+ <subsection name="Global metadata changes at runtime?" anchor="28">
+ <p>
+ TODO
+ </p>
+ </subsection>
+
+ <subsection name="Per thread metadata changes at runtime?" anchor="29">
+ <p>
+ TODO
+ </p>
+ </subsection>
+
+ <subsection name="Is it possible to use OJB within EJB's?" anchor="30">
+ <p>
+ Yes, see <a href="deployment.html">deployment</a> instructions in the docs.
+ Additional you can find some EJB example beans in package <code>org.apache.ojb.ejb</code>
+ under <code>[jakarta-ojb]/src/ejb</code>.
+ </p>
+ </subsection>
+
+
+
</section>
</body>
</document>
1.5 +4 -2 jakarta-ojb/xdocs/performance.xml
Index: performance.xml
===================================================================
RCS file: /home/cvs/jakarta-ojb/xdocs/performance.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- performance.xml 12 Sep 2002 20:41:39 -0000 1.4
+++ performance.xml 31 Jan 2003 17:42:44 -0000 1.5
@@ -61,7 +61,8 @@
the Hypersonic SQL shipped with OJB. A typical output looks like
follows:</P>
<PRE>performance:
- [ojb] [BOOT] INFO: OJB.properties: file:/home/tom/ojb-1-0/build/test/ojb/OJB.properties
+ [ojb] [BOOT] INFO: OJB.properties:
+ file:/home/tom/ojb-1-0/build/test/ojb/OJB.properties
[ojb] .[performance] INFO:
[ojb] [performance] INFO: inserting 10000 Objects: 6374 msec
[ojb] [performance] INFO: updating 10000 Objects: 6083 msec
@@ -88,7 +89,8 @@
[ojb]
[ojb] OK (1 tests)
[ojb]
- [jdbc] [BOOT] INFO: OJB.properties: file:/home/tom/ojb-1-0/build/test/ojb/OJB.properties
+ [jdbc] [BOOT] INFO: OJB.properties:
+ file:/home/tom/ojb-1-0/build/test/ojb/OJB.properties
[jdbc] .[performance] INFO:
[jdbc] [performance] INFO: inserting 10000 Objects: 2494 msec
[jdbc] [performance] INFO: updating 10000 Objects: 3229 msec