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/07/23 00:59:47 UTC

cvs commit: db-ojb/src/test/org/apache/ojb/broker MultipleDBTest.java

arminw      2003/07/22 15:59:46

  Modified:    xdocs    tutorial3.xml deployment.xml
               src/test/org/apache/ojb/broker MultipleDBTest.java
  Log:
  - add new test
  - add some notes
  
  Revision  Changes    Path
  1.25      +38 -35    db-ojb/xdocs/tutorial3.xml
  
  Index: tutorial3.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/xdocs/tutorial3.xml,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- tutorial3.xml	11 Jul 2003 20:34:23 -0000	1.24
  +++ tutorial3.xml	22 Jul 2003 22:59:46 -0000	1.25
  @@ -1,4 +1,5 @@
   <?xml version="1.0"?>
  +<!-- @version $Id$ -->
   <document>
   
     <properties>
  @@ -793,11 +794,11 @@
   <p>
   Proxy classes can be used for &quot;lazy loading&quot; aka &quot;lazy
   materialization&quot;. Using Proxy classes can help you in reducing
  -unneccessary db lookups. 
  +unneccessary db lookups.
   There are two kind of proxy mechanisms available:
   <ol>
   	<li>
  -		Dynamic proxies provided by OJB. 
  +		Dynamic proxies provided by OJB.
   		They can simply be activated by setting certain switches in repository.xml.
   		This is the solution recommemded for <b>most</b> cases.
   		If your are in doubt use dynamic proxies.
  @@ -809,7 +810,7 @@
   </ol>
   As it is important to understand the mechanics of the proxy mechanism
   I highly recommend to read this section before turning to the next sections
  -"using dynamic proxies", "using a single proxy for a whole collection" and 
  +"using dynamic proxies", "using a single proxy for a whole collection" and
   "using a proxy for a reference", covering dynamic proxies.
   </p>
   <p>
  @@ -1524,7 +1525,7 @@
            jdbc-type="INTEGER"
         />
      </class-descriptor>
  -   
  +
      <class-descriptor
         class="org.apache.ojb.broker.B"
         table="B_TABLE"
  @@ -1542,26 +1543,26 @@
            column="VALUE_"
            jdbc-type="INTEGER"
         />
  -     
  -      <reference-descriptor name="super" 
  +
  +      <reference-descriptor name="super"
           class-ref="org.apache.ojb.broker.A">
           <foreignkey field-ref="id" />
  -      </reference-descriptor>  
  -  	     
  -   </class-descriptor>   
  +      </reference-descriptor>
  +
  +   </class-descriptor>
   ]]></source>
   
   As you can see from this mapping we need a special reference-descriptor
   that advises OJB to load the values for the inherited
  -attributes from class <code>A</code> by a JOIN using the 
  +attributes from class <code>A</code> by a JOIN using the
   <code>(B.id == A.id)</code> foreign key reference.<br/>
   
  -The <code>name="super"</code> is not used to address an actual 
  +The <code>name="super"</code> is not used to address an actual
   attribute of the class <code>B</code> but as a marker
   keyword defining the JOIN to the baseclass.
   </p>
   <p>
  -The above example is based on the assumption that the primary key attribute 
  +The above example is based on the assumption that the primary key attribute
   <code>B.id</code> and its underlying column <code>B_TABLE.ID</code>
   is also used as the foreign key attribute.
   <br/>
  @@ -1571,12 +1572,12 @@
   <source><![CDATA[
   public class B extends A
   {
  -    // id is the primary key 
  +    // id is the primary key
       int id;
  -    
  +
       // aID is the foreign key referencing A.id
       int aID;
  -    
  +
       // mapped to a column in B_TABLE
       int someValueFromB;
   }
  @@ -1607,15 +1608,15 @@
            column="VALUE_"
            jdbc-type="INTEGER"
         />
  -     
  -      <reference-descriptor name="super" 
  +
  +      <reference-descriptor name="super"
     	     class-ref="org.apache.ojb.broker.A">
            <foreignkey field-ref="aID" />
  -      </reference-descriptor>  
  -  	     
  -   </class-descriptor>   
  +      </reference-descriptor>
  +
  +   </class-descriptor>
   ]]></source>
  -The mapping now contains an additional field-descriptor for the 
  +The mapping now contains an additional field-descriptor for the
   <code>aID</code> attribute.<br/>
   In the <code>"super"</code> reference-descriptor the foreignkey <code>field-ref</code> attribute
   had to be changed to <code>"aID"</code>.
  @@ -1628,15 +1629,15 @@
   <source><![CDATA[
   public class B extends A
   {
  -    // id is the primary key 
  +    // id is the primary key
       int id;
  -    
  +
       // mapped to a column in B_TABLE
       int someValueFromB;
   }
   ]]></source>
   
  -We can use OJB's anonymous field feature to get everything working without the 
  +We can use OJB's anonymous field feature to get everything working without the
   <code>"aID"</code> attribute. We keep the field-descriptor for aID, but declare it as an
   anonymous field.
   We just have to add an attribute <code>access="anonymous"</code> to the field-descriptor:
  @@ -1665,13 +1666,13 @@
            column="VALUE_"
            jdbc-type="INTEGER"
         />
  -     
  -      <reference-descriptor name="super" 
  +
  +      <reference-descriptor name="super"
     	     class-ref="org.apache.ojb.broker.A">
            <foreignkey field-ref="aID" />
  -      </reference-descriptor>  
  -  	     
  -   </class-descriptor>   
  +      </reference-descriptor>
  +
  +   </class-descriptor>
   ]]></source>
   
   You can learn more about the anonymous fields feature in this <a href="howto-use-anonymous-keys.html">howto</a>.
  @@ -1895,7 +1896,7 @@
   		</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 
  +	writing code, and without any further trouble just by a few settings
   	in the repository.xml file.
   </p>
   <p>
  @@ -1909,17 +1910,17 @@
   <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:
  +The <tt>StockDetail</tt> class has the following layout:
   <source><![CDATA[
   public class StockDetail implements java.io.Serializable
   {
  @@ -1932,11 +1933,13 @@
       protected int stock;
   
       protected String unit;
  -    
  +
       ...
   }
   ]]></source>
  -
  +Only precondition to make things work is that <tt>StockDetail</tt> needs
  +a default constructor.
  +<br/>
   The nested fields semantics can simply declared by the following class-
   descriptor:
   <source><![CDATA[
  
  
  
  1.25      +2 -2      db-ojb/xdocs/deployment.xml
  
  Index: deployment.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/xdocs/deployment.xml,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- deployment.xml	3 Jul 2003 07:00:48 -0000	1.24
  +++ deployment.xml	22 Jul 2003 22:59:46 -0000	1.25
  @@ -429,7 +429,7 @@
   allowed to change autoCommit state.
   <br/>
   When using jboss >3.0 you have to set
  -<code>eager-release="true"</code> - when using other application server
  +<code>eager-release="true"</code> (only when using OJB within EJB's) - when using other application server
   <code>false</code> should be ok.
   </p>
   
  
  
  
  1.13      +33 -1     db-ojb/src/test/org/apache/ojb/broker/MultipleDBTest.java
  
  Index: MultipleDBTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MultipleDBTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- MultipleDBTest.java	2 Jun 2003 15:18:00 -0000	1.12
  +++ MultipleDBTest.java	22 Jul 2003 22:59:46 -0000	1.13
  @@ -38,7 +38,39 @@
           junit.textui.TestRunner.main(arr);
       }
   
  -    public void testPBLookup() throws Exception
  +    /**
  +     * test PB instance lookup using different
  +     * PBKey constructors + databases
  +     */
  +    public void testLookupByPBKey()
  +    {
  +        PBKey pb_1a = new PBKey(TestHelper.DEF_JCD_ALIAS);
  +        PBKey pb_1b = new PBKey(TestHelper.DEF_JCD_ALIAS, null, null);
  +        PBKey pb_1c = new PBKey(TestHelper.DEF_JCD_ALIAS, TestHelper.DEF_USER, TestHelper.DEF_PASSWORD);
  +
  +        PBKey pb_2a = new PBKey(TestHelper.FAR_AWAY_JCD_ALIAS);
  +        PBKey pb_2b = new PBKey(TestHelper.FAR_AWAY_JCD_ALIAS, null, null);
  +
  +        PersistenceBroker b1a = PersistenceBrokerFactory.createPersistenceBroker(pb_1a);
  +        PersistenceBroker b1b = PersistenceBrokerFactory.createPersistenceBroker(pb_1b);
  +        PersistenceBroker b1c = PersistenceBrokerFactory.createPersistenceBroker(pb_1c);
  +        PersistenceBroker b2a = PersistenceBrokerFactory.createPersistenceBroker(pb_2a);
  +        PersistenceBroker b2b = PersistenceBrokerFactory.createPersistenceBroker(pb_2b);
  +
  +        assertNotNull(b1a);
  +        assertNotNull(b1b);
  +        assertNotNull(b1c);
  +        assertNotNull(b2a);
  +        assertNotNull(b2b);
  +
  +        if(b1a != null) b1a.close();
  +        if(b1b != null) b1b.close();
  +        if(b1c != null) b1c.close();
  +        if(b2a != null) b2a.close();
  +        if(b2b != null) b2b.close();
  +    }
  +
  +    public void testPBLookupConnection() throws Exception
       {
           PBKey key = new PBKey(TestHelper.FAR_AWAY_JCD_ALIAS);
           PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(key);
  
  
  

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