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 to...@apache.org on 2004/12/08 22:56:19 UTC

cvs commit: db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/howtos howto-use-ojb-with-springframework.xml

tomdz       2004/12/08 13:56:19

  Modified:    src/doc/forrest/src/documentation/content/xdocs site.xml
               src/doc/forrest/src/documentation skinconf.xml
               src/doc/forrest/src/documentation/content/xdocs/docu/howtos
                        howto-use-ojb-with-springframework.xml
  Log:
  Fixed and integrated spring-howto
  
  Revision  Changes    Path
  1.10      +6 -1      db-ojb/src/doc/forrest/src/documentation/content/xdocs/site.xml
  
  Index: site.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/content/xdocs/site.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- site.xml	4 Dec 2004 12:08:33 -0000	1.9
  +++ site.xml	8 Dec 2004 21:56:14 -0000	1.10
  @@ -172,6 +172,7 @@
               <use-lobs label="Use Oracle LOB's" href="howto-use-lobs.html" description=""/>
               <clustering label="Work in clustered environment" href="howto-work-with-clustering.html" description=""/>
               <stored-procedures label="Work with Stored Procedures" href="howto-work-with-stored-procedures.html" description=""/>
  +            <ojb-with-springframework label="Using OJB with the Springframework" href="howto-use-ojb-with-springframework.html" description=""/>
           </howto>
   
           <testing label="Testing" href="testing/" tab="testing">
  @@ -319,5 +320,9 @@
           <nees href="http://www.nees.org/"/>
           <ojb-net href="http://ojb-net.sourceforge.net/"/>
           <yourkit href="http://www.yourkit.com/" />
  +        <spring href="http://www.springframework.org">
  +            <localDataSourceConnectionFactory href="docs/api/org/springframework/orm/ojb/support/LocalDataSourceConnectionFactory.html"/>
  +        </spring>
  +        <dbuint href="http://dbunit.sourceforge.net"/>
       </external-refs>
   </site>
  
  
  
  1.4       +3 -0      db-ojb/src/doc/forrest/src/documentation/skinconf.xml
  
  Index: skinconf.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/skinconf.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- skinconf.xml	1 Oct 2004 13:16:38 -0000	1.3
  +++ skinconf.xml	8 Dec 2004 21:56:14 -0000	1.4
  @@ -151,6 +151,9 @@
           in the class attribute of a <p> node.
           e.g. <p class="quote"/>
       -->
  +    p { 
  +      line-height: 1.4
  +    }
       p.quote {
         margin-left: 2em;
         padding: .5em;
  
  
  
  1.2       +135 -118  db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/howtos/howto-use-ojb-with-springframework.xml
  
  Index: howto-use-ojb-with-springframework.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/howtos/howto-use-ojb-with-springframework.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- howto-use-ojb-with-springframework.xml	21 Nov 2004 17:29:30 -0000	1.1
  +++ howto-use-ojb-with-springframework.xml	8 Dec 2004 21:56:17 -0000	1.2
  @@ -31,15 +31,15 @@
               <section>
                   <title>Introduction</title>
                   <p>
  -                You can spent the good part of a day working out the ins and outs of the
  -                    <a href="http://springframework.org/">Springframework</a> and
  -                    <a href="http://db.apache.org/ojb/">OJB</a>.  There is a fail level of handicap involved
  -                    while you up to speed with the Springframework, but once it's done and working,
  -                    you will realize how simple it really is.
  +                You can spend the good part of a day working out the ins and outs of the
  +                <link href="ext:spring">Springframework</link> and <link href="site:ojb">OJB</link>.
  +                There is a fair level of complexity involved while you come up to speed with the Springframework,
  +                but once it's done and working, you will realize how simple it really is.
                   </p>
                   <p>
                   Here are some thoughts on how to setup the initial hooks between OJB and Spring,
  -                and how to make it work for your needs.</p>
  +                and how to make it work for your needs.
  +                </p>
                   <p>
                     This tutorial will:
                   </p>
  @@ -62,10 +62,11 @@
                   </p>
                   <p>
                       For some help, setting up and running OJB in the traditional way
  -                    <a href="http://db.apache.org/ojb/docu/index.html">can be found here</a>.
  +                    <link href="site:documentation/index">can be found here</link>.
                       I highly recommend for anyone to take a look
  -                    <a href="http://db.apache.org/ojb/docu/guides/xdoclet-module.html">at the xdoclet tutorial</a>
  -                    it will make your life much much easier in the long run in understanding OJB.  I wish the xdoclet support existed when I started using OJB.
  +                    <link href="site:documentation/guides/xdoclet-module">at the xdoclet tutorial</link>
  +                    it will make your life much much easier in the long run in understanding OJB.
  +                    I wish the xdoclet support existed when I started using OJB.
                   </p>
               </section>
   
  @@ -80,39 +81,52 @@
                   </p>
                   <p>
                   Traditionally with OJB you'd have 2 main files to deal with:
  -                    <ul>
  -                        <li>1- repository.xml - contains ojb's internal schema, your schema, and jdbc connection details.</li>
  -                        <li>2- OJB.properties - contains various settings to allow ojb to find repository.xml, Collection, Pooling, and other settings to specify OJB's behavior.</li>
  -                    </ul>
  +                </p>
  +                <ol>
  +                    <li>repository.xml - contains ojb's internal schema, your schema, and jdbc connection details.</li>
  +                    <li>OJB.properties - contains various settings to allow ojb to find repository.xml, Collection,
  +                                         Pooling, and other settings to specify OJB's behavior.</li>
  +                </ol>
  +                <p>
                   With the Springframework approach this list grows a little.
                   </p>
  +            </section>
  +            <section>
                   <title>First Things First - Setup OJB</title>
                   <p>
                       Setup the OJB files where they need to go.  There is a specific set of files OJB and Springframework need
                       to have to operate properly together.
  -                    <i>Note: This information can also be pulled together from looking at the PetClinic Sample project in the
  -                    Springframework distribution.</i>
                   </p>
  +                <note>
  +                    This information can also be pulled together from looking at the PetClinic Sample project in the
  +                    Springframework distribution.
  +                </note>
                   <p>
                       In your OJB distribution generate, or find the existing set of the following files,
                       and place them in your &lt;web-root&gt;/WEB-INF directory:
  -                    <ul>
  -                        <li>repository.xml</li>
  -                        <li>OJB.properties</li>
  -                        <li>OJB-logging.properties</li>
  -                        <li>repository_internal.xml</li>
  -                    </ul>
  +                </p>
  +                <ul>
  +                    <li>repository.xml</li>
  +                    <li>OJB.properties</li>
  +                    <li>OJB-logging.properties</li>
  +                    <li>repository_internal.xml</li>
  +                </ul>
  +                <p>
                       Fetch the following libraries, you can find them in the &lt;ojb-root&gt;/lib directory, and
                       place them in your &lt;web-root&gt;/WEB-INF/lib directory.
  -                    <ul>
  -                        <li>db-ojb-1.0.1.jar</li>
  -                        <li>commons-dbcp-1.1.jar</li>
  -                        <li>commons-lang-2.0.jar</li>
  -                        <li>commons-pool-1.1.jar</li>
  -                    </ul>
  +                </p>
  +                <ul>
  +                    <li>db-ojb-1.0.1.jar</li>
  +                    <li>commons-dbcp-1.1.jar</li>
  +                    <li>commons-lang-2.0.jar</li>
  +                    <li>commons-pool-1.1.jar</li>
  +                </ul>
  +                <p>
                       This concludes the piece of setting up the OJB part of the files in the right locations.
                       You'll still need to edit the OJB.properties and respository.xml later.
                   </p>
  +            </section>
  +            <section>
                   <title>Setup The Spring Framework's applicationContext.xml</title>
                   <p>
                       The Springframework piece which sets things up to communicate with OJB is fairly simple.
  @@ -127,57 +141,52 @@
                   <p>
                       The first entry will serve to resolve property value pairs in a file called jdbc.init,
                       as specified in the first block of XML.  We'll create the property file shortly.
  -                    <br></br>
  -                    <code>
  -                        &lt;!-- Configurer that replaces ${...} placeholders with values from a properties file --&gt;
  -                        &lt;!-- (in this case, OJB-related settings for the dataSource definition below) --&gt;
  -                        &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
  -                        &lt;property name="location">&lt;value>/WEB-INF/jdbc.properties&lt;/value&gt;&lt;/property&gt;
  -                        &lt;/bean&gt;
  -                        &lt;!-- Local DataSource that works in any environment --&gt;
  -                        &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
  -                        &lt;property name="driverClassName">&lt;value>${jdbc.driverClassName}&lt;/value&gt;&lt;/property&gt;
  -                        &lt;property name="url"&gt;&lt;value>${jdbc.url}&lt;/value&gt;&lt;/property&gt;
  -                        &lt;property name="username"&gt;&lt;value>${jdbc.username}&lt;/value&gt;&lt;/property&gt;
  -                        &lt;property name="password"&gt;&lt;value&gt;${jdbc.password}&lt;/value&gt;&lt;/property&gt;
  -                        &lt;/bean&gt;
  -                    </code>
                   </p>
  +                <source><![CDATA[
  +<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
  +<!-- (in this case, OJB-related settings for the dataSource definition below) -->
  +<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  +    <property name="location"><value>/WEB-INF/jdbc.properties</value></property>
  +</bean>
  +<!-- Local DataSource that works in any environment -->
  +<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  +    <property name="driverClassName"><value>${jdbc.driverClassName}</value></property>
  +    <property name="url"><value>${jdbc.url}</value></property>
  +    <property name="username"><value>${jdbc.username}</value></property>
  +    <property name="password"><value>${jdbc.password}</value></property>
  +</bean>]]></source>
                   <p>
                       The next block informs the Springframework which beans you intent to use when you're instantiating
                       OJB and its transactions.
  -                    <br></br>
  -                    <code>
  -                        &lt;!-- Transaction manager --&gt;
  -                        &lt;!-- OJB configurer that allows to use LocalDataSourceConnectionFactory in OJB.properties --&gt;
  -                        &lt;bean id="ojbConfigurer" class="org.springframework.orm.ojb.support.LocalOjbConfigurer"/&gt;
  -                        <br></br>
  -                        &lt;!-- Transaction manager for a single OJB PersistenceBroker (alternative to JTA) --&gt;
  -                        &lt;bean id="transactionManager" class="org.springframework.orm.ojb.PersistenceBrokerTransactionManager"/&gt;
  -                    </code>
  -                    <br></br>
  +                </p>
  +                <source><![CDATA[
  +<!-- Transaction manager -->
  +<!-- OJB configurer that allows to use LocalDataSourceConnectionFactory in OJB.properties -->
  +<bean id="ojbConfigurer" class="org.springframework.orm.ojb.support.LocalOjbConfigurer"/>
  +
  +<!-- Transaction manager for a single OJB PersistenceBroker (alternative to JTA) -->
  +<bean id="transactionManager" class="org.springframework.orm.ojb.PersistenceBrokerTransactionManager"/>]]></source>
  +                <p>
                       That's all you need to change in the applicationContext.xml in order to get things hooked into your
                       bean, and getting your beans to make the proper calls.  An example of what this would look like
                       in your code is:
  -                    <br></br>
  -                    <code>
  -                        &lt;bean id="userManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;
  -                        <b>&lt;property name="transactionManager"&gt;
  -                            &lt;ref local="transactionManager"/&gt;
  -                            &lt;/property&gt;</b>
  -                        &lt;property name="target"&gt;
  -                        &lt;ref local="userManagerTarget"/&gt;
  -                        &lt;/property&gt;
  -                        &lt;property name="transactionAttributes"&gt;
  -                        &lt;props&gt;
  -                        &lt;prop key="save*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
  -                        &lt;prop key="remove*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
  -                        &lt;prop key="*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt;
  -                        &lt;/props&gt;
  -                        &lt;/property&gt;
  -                        &lt;/bean&gt;
  -                    </code>
                   </p>
  +                <source><![CDATA[
  +<bean id="userManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  +    <property name="transactionManager">
  +        <ref local="transactionManager"/>
  +    </property>
  +    <property name="target">
  +        <ref local="userManagerTarget"/>
  +    </property>
  +    <property name="transactionAttributes">
  +        <props>
  +            <prop key="save*">PROPAGATION_REQUIRED</prop>
  +            <prop key="remove*">PROPAGATION_REQUIRED</prop>
  +            <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
  +        </props&gt;
  +    </property&gt;
  +</bean>]]></source>
                   <p>
                       Now onto the jdbc.properties file.  This file will allow you to simply setup the database
                       information in one location and share it across implementations.  This case is particularly usefule
  @@ -187,14 +196,13 @@
                   <p>
                       Create a jdbc.properties file and put the following in it, remembering to replace the right values
                       for your username, password and database:
  -                    <br></br>
  -                    <code>
  -                    jdbc.driverClassName=org.postgresql.Driver
  -                    jdbc.url=jdbc:postgresql:myDB
  -                    jdbc.username=myUser
  -                    jdbc.password=myPassword
  -                    </code>
  -                    <br></br>
  +                </p>
  +                <source><![CDATA[
  +jdbc.driverClassName=org.postgresql.Driver
  +jdbc.url=jdbc:postgresql:myDB
  +jdbc.username=myUser
  +jdbc.password=myPassword]]></source>
  +                <p>
                       That's it, there is no OJB specific information which needs to go in here.  If you were using
                       Hibernate you'd add a hibernate.dialect=... entry for your own DB in the file and you'd be done.
                   </p>
  @@ -211,28 +219,37 @@
                   <p>
                       In Respository.xml add the following block of xml for your jdbc-connection-descritor entry,
                       notice how the jcd-alias is called dataSource to match the applicationContext.xml entry:
  -                    <br></br>
  -                    <code>
  -                        &lt;jdbc-connection-descriptor jcd-alias="dataSource" default-connection="true" platform="PostgreSQL" jdbc-level="3.0" useAutoCommit="1"&gt;
  -                        &lt;connection-pool maxActive="10" maxIdle="2" maxWait="3" validationQuery="" logAbandoned="true" removeAbandoned="true" removeAbandonedTimeout="8"/&gt;
  -                        &lt;sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl"&gt;
  -                        &lt;attribute attribute-name="grabSize" attribute-value="5"/&gt;
  -                        &lt;attribute attribute-name="autoNaming" attribute-value="true"/&gt;
  -                        &lt;attribute attribute-name="globalSequenceId" attribute-value="false"/&gt;
  -                        &lt;attribute attribute-name="globalSequenceStart" attribute-value="1"/&gt;
  -                        &lt;/sequence-manager&gt;
  -                        &lt;/jdbc-connection-descriptor&gt;
  -                    </code>
                   </p>
  +                <source><![CDATA[
  +<jdbc-connection-descriptor jcd-alias="dataSource"
  +                            default-connection="true"
  +                            platform="PostgreSQL"
  +                            jdbc-level="3.0"
  +                            useAutoCommit="1">
  +    <connection-pool maxActive="10"
  +                     maxIdle="2"
  +                     maxWait="3"
  +                     validationQuery=""
  +                     logAbandoned="true"
  +                     removeAbandoned="true"
  +                     removeAbandonedTimeout="8"/>
  +    <sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl">
  +        <attribute attribute-name="grabSize"            attribute-value="5"/>
  +        <attribute attribute-name="autoNaming"          attribute-value="true"/>
  +        <attribute attribute-name="globalSequenceId"    attribute-value="false"/>
  +        <attribute attribute-name="globalSequenceStart" attribute-value="1"/>
  +    </sequence-manager>
  +</jdbc-connection-descriptor>]]></source>
  +            </section>
  +            <section>
  +                <title>A word of caution:</title>
                   <p>
  -                    <b>Now a word of caution:</b>
  -                    <i> I'm using the SequenceManagerHighLowImpl, but the PetClinic is
  +                    I'm using the SequenceManagerHighLowImpl, but the PetClinic is
                       using SequenceManagerNativeImpl.  The IDs generated by that implementation was returning negative
                       numbers before a record was inserted, according to OJB documentation this is because there needs
                       to be some kind of ID generated before the insert because we don't know what the ID is going to be
                       in the DB, especially since not all DBs have a Sequence like Oracle and Postgresql.  If you use
  -                    something like
  -                        <a href="http://dbunit.sourceforge.net/">db-unit</a> to do your tests, the
  +                    something like <link href="ext:dbuint">db-unit</link> to do your tests, the
                       SequenceManagerNativeImpl will make it more difficult for you, since it will pose a bit of a
                       challenge to figure out which ID to select against in the DB once an object is added, for example.
                       I found that in general the SequenceManagerHighLowImpl to work best for all DBs, since OJB takes
  @@ -242,45 +259,45 @@
                       why they chose to use SequenceManagerNativeImpl, it is perhaps because that implementation doesn't
                       require adding the extra OJB table required for the SequenceManagerHighLowImpl, and it works for
                       their purpose.
  -                    </i>
                   </p>
                   <p>
                       On to editing the OJB.properties file.  There are 2 entries which need to be looked at in here:
  -                    <ul>
  -                        <li>ConnectionFactoryClass value</li>
  -                        <li>ObjectCacheClass value</li>
  -                    </ul>
  -                    The ConnectionFactoryClass entry.
  -                    <br></br>
  +                </p>
  +                <ul>
  +                    <li>ConnectionFactoryClass value</li>
  +                    <li>ObjectCacheClass value</li>
  +                </ul>
  +            </section>
  +            <section>
  +                <title>The ConnectionFactoryClass entry</title>
  +                <p>
                       Find the line in your OJB.properties file which starts with ConnectionFactoryClass, comment the
                       current ConnectionFactoryClass and add this:
  -                    <br></br>
  -                    <code>
  -                        ConnectionFactoryClass=org.springframework.orm.ojb.support.LocalDataSourceConnectionFactory
  -                    </code>
  +                </p>
  +                <source><![CDATA[
  +ConnectionFactoryClass=org.springframework.orm.ojb.support.LocalDataSourceConnectionFactory]]></source>
  +                <p>
                       This will let OJB to delegate to the Springframework with a has factory for Spring-managed
                       DataSource beans.  For more information on this look at
  -                    <a href="http://www.springframework.org/docs/api/org/springframework/orm/ojb/support/LocalDataSourceConnectionFactory.html">the Springframework API</a>
  -                    <br></br>
  -                    The ObjectCacheClass entry.
  -                    <br></br>
  +                    <link href="ext:spring/localDataSourceConnectionFactory">the Springframework API</link>
  +                </p>
  +            </section>
  +            <section>
  +                <title>The ObjectCacheClass entry</title>
  +                <p>
                       Find the line in your OJB.properties file which starts with ObjectCacheClass, comment the currently
                       used Implementation and uncomment this one:
  -                    <br></br>
  -                    <code>
  -                        ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl
  -                    </code>
                   </p>
  +                <source><![CDATA[
  +ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl]]></source>
                   <p>
                       Believe it or not, that's it.  Add your beans and start working with Springframeowork.
                       I won't go into a tutorial about how to do that, there are many sources out there to do it.
                       The one thing I will say to help you out is that generally adding a bean to use with OJB is
                       brainless, here is an example entry from an applicationContext.xml:
  -                    <br></br>
  -                    <code>
  -                        &lt;bean id="ojbUserDAO" name="userDAO" class="com.codepuccino.mesquite.dao.ojb.OJBUserDAO"/&gt;
  -                    </code>
                   </p>
  +                <source><![CDATA[
  +<bean id="ojbUserDAO" name="userDAO" class="com.codepuccino.mesquite.dao.ojb.OJBUserDAO"/>]]></source>
               </section>
           </section>
       </body>
  
  
  

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