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 2004/06/04 01:46:08 UTC

cvs commit: db-ojb/src/test/org/apache/ojb OJB.properties

arminw      2004/06/03 16:46:08

  Modified:    forrest/src/documentation/content/xdocs/docu
                        advanced-technique.xml
               forrest/src/documentation/content/xdocs site.xml
               src/test/org/apache/ojb OJB.properties
  Log:
  add/update RowReader section
  
  Revision  Changes    Path
  1.8       +70 -27    db-ojb/forrest/src/documentation/content/xdocs/docu/advanced-technique.xml
  
  Index: advanced-technique.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/forrest/src/documentation/content/xdocs/docu/advanced-technique.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- advanced-technique.xml	12 May 2004 00:47:35 -0000	1.7
  +++ advanced-technique.xml	3 Jun 2004 23:46:08 -0000	1.8
  @@ -1021,21 +1021,50 @@
               </warning>
           </section>
   
  +
           <anchor id="using-rowreader"/>
           <section>
               <title>Using Rowreader</title>
               <p>
  -                RowReaders provide a Callback mechanism that allows to interact
  -                with the OJB load mechanism. To understand how to use them we must
  -                know some of the details of the load mechanism.
  +                RowReaders provide a callback mechanism that allows to interact
  +                with the OJB load mechanism. All implementation classes have to implement
  +                <link href="ext:api/row-reader">interface <code>RowReader</code></link>.
               </p>
               <p>
  +                You can specify the <code>RowReader</code> implementation in
  +            </p>
  +            <ul>
  +                <li>
  +                    the <link href="ext:ojb.properties"><code>OJB.properties</code></link> file to set
  +                    the standard used <code>RowReader</code> implementation
  +                </li>
  +            </ul>
  +            <source><![CDATA[
  +#-------------------------------------------------------------------------------
  +# RowReader
  +#-------------------------------------------------------------------------------
  +# Set the standard RowReader implementation. It is also possible to specify the
  +# RowReader on class-descriptor level.
  +RowReaderDefaultClass=org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl]]></source>
  +            <ul>
  +                <li>
  +                    within the <link href="site:repository/class-descriptor">class-descriptor</link>
  +                    to set the <code>RowReader</code> for a specific class.
  +                </li>
  +            </ul>
  +            <p>
  +                RowReader setting on <em>class-descriptor</em> level will override the standard
  +                reader set in <code>OJB.properties</code> file. If neither a RowReader was set in
  +                OJB.properties file nor in class-descriptor was set, OJB use an default implementation.
  +            </p>
  +            <p>
  +                To understand how to use them we must know some of the details of the load mechanism.
                   To materialize objects from a rdbms OJB uses RsIterators, that are
                   essentially wrappers to JDBC ResultSets. RsIterators are constructed
                   from queries against the Database.
               </p>
               <p>
  -                The
  +                The method
                   <code>RsIterator.next()</code> is used to materialize the next object from
                   the underlying ResultSet. This method first checks if the underlying
                   ResultSet is not yet exhausted and then delegates the construction of
  @@ -1045,19 +1074,19 @@
               <source><![CDATA[
   protected Object getObjectFromResultSet() throws PersistenceBrokerException
   {
  -    if (itemProxyClass != null)
  +    if (getItemProxyClass() != null)
       {
           // provide m_row with primary key data of current row
  -        m_mif.getRowReader().
  -            readPkValuesFrom(m_rsAndStmt.m_rs, m_mif, m_row);
  +        getQueryObject().getClassDescriptor().getRowReader()
  +                    .readPkValuesFrom(getRsAndStmt().m_rs, getRow());
           // assert: m_row is filled with primary key values from db
           return getProxyFromResultSet();
       }
       else
       {
           // 0. provide m_row with data of current row
  -        m_mif.getRowReader().
  -            readObjectArrayFrom(m_rsAndStmt.m_rs, m_mif, m_row);
  +        getQueryObject().getClassDescriptor().getRowReader()
  +                    .readObjectArrayFrom(getRsAndStmt().m_rs, getRow());
           // assert: m_row is filled from db
   
           // 1.read Identity
  @@ -1065,31 +1094,45 @@
           Object result = null;
   
           // 2. check if Object is in cache. if so return cached version.
  -        result = cache.lookup(oid);
  +        result = getCache().lookup(oid);
           if (result == null)
           {
               // 3. If Object is not in cache
  -            // materialize Object with primitive
  -            // attributes filled from current row
  -            result = m_mif.getRowReader().readObjectFrom(m_row, m_mif);
  +            // materialize Object with primitive attributes filled from
  +            // current row
  +            result = getQueryObject().getClassDescriptor()
  +                                        .getRowReader().readObjectFrom(getRow());
               // result may still be null!
               if (result != null)
               {
  -                cache.cache(oid, result);
  -                // fill reference and collection attributes
  -                ClassDescriptor cld = m_mif.getRepository().
  -                                getDescriptorFor(result.getClass());
  -                m_broker.retrieveReferences(result, cld);
  -                m_broker.retrieveCollections(result, cld);
  +                synchronized (result)
  +                {
  +                    getCache().enableMaterializationCache();
  +                    getCache().cache(oid, result);
  +                    // fill reference and collection attributes
  +                    ClassDescriptor cld = getQueryObject().getClassDescriptor()
  +                            .getRepository().getDescriptorFor(result.getClass());
  +                    // don't force loading of reference
  +                    final boolean unforced = false;
  +                    // Maps ReferenceDescriptors to HashSets of owners
  +                    getBroker().getReferenceBroker().retrieveReferences(result, cld, unforced);
  +                    getBroker().getReferenceBroker().retrieveCollections(result, cld, unforced);
  +                    getCache().disableMaterializationCache();
  +                }
               }
           }
  -        else
  +        else // Object is in cache
           {
  -            ClassDescriptor cld = m_mif.getRepository().
  -                                getDescriptorFor(result.getClass());
  -            m_broker.refreshRelationships(result, cld);
  +            ClassDescriptor cld = getQueryObject().getClassDescriptor()
  +                        .getRepository().getDescriptorFor(result.getClass());
  +            // if refresh is required, update the cache instance from the db
  +            if (cld.isAlwaysRefresh())
  +            {
  +                getQueryObject().getClassDescriptor()
  +                                    .getRowReader().refreshObject(result, getRow());
  +            }
  +            getBroker().refreshRelationships(result, cld);
           }
  -
           return result;
       }
   }]]></source>
  @@ -1100,8 +1143,8 @@
                   <br/>
                   The RowReader to be used for a Class can be configured in the XML
                   repository with the attribute
  -                <code>row-reader</code>.
  -                If no RowReader is specified, the RowReaderDefaultImpl is used. The
  +                <link href="site:repository/class-descriptor"><code>row-reader</code></link>.
  +                If no RowReader is specified, the standard <code>RowReader</code> is used. The
                   method
                   <code>readObjectArrayFrom(...)</code> of this class looks like follows:
               </p>
  
  
  
  1.16      +2 -1      db-ojb/forrest/src/documentation/content/xdocs/site.xml
  
  Index: site.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/forrest/src/documentation/content/xdocs/site.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- site.xml	14 May 2004 21:32:14 -0000	1.15
  +++ site.xml	3 Jun 2004 23:46:08 -0000	1.16
  @@ -186,6 +186,7 @@
               <class-descriptor href="org/apache/ojb/broker/metadata/ClassDescriptor.html"/>
               <descriptor-repository href="org/apache/ojb/broker/metadata/DescriptorRepository.html"/>
               <connection-repository href="org/apache/ojb/broker/metadata/ConnectionRepository.html"/>
  +            <row-reader href="org/apache/ojb/broker/accesslayer/RowReader.html"/>
           </api>
           <ojb>
               <wiki-page href="http://wiki.apache.org/db-ojb"/>
  
  
  
  1.70      +8 -1      db-ojb/src/test/org/apache/ojb/OJB.properties
  
  Index: OJB.properties
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/OJB.properties,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- OJB.properties	1 Jun 2004 21:42:21 -0000	1.69
  +++ OJB.properties	3 Jun 2004 23:46:08 -0000	1.70
  @@ -205,6 +205,13 @@
   #
   #
   #----------------------------------------------------------------------------------------
  +# RowReader
  +#----------------------------------------------------------------------------------------
  +# Set the standard RowReader implementation. It is also possible to specify the
  +# RowReader on class-descriptor level.
  +RowReaderDefaultClass=org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl
  +#
  +#----------------------------------------------------------------------------------------
   # Object cache
   #----------------------------------------------------------------------------------------
   # The ObjectCacheClass entry tells OJB which concrete ObjectCache
  
  
  

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