db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r392792 - in /db/ojb/trunk/src: java/org/apache/ojb/broker/accesslayer/ java/org/apache/ojb/broker/core/ java/org/apache/ojb/broker/metadata/ java/org/apache/ojb/broker/util/ schema/ test/org/apache/ojb/ test/org/apache/ojb/broker/
Date Sun, 09 Apr 2006 17:52:43 GMT
Author: tomdz
Date: Sun Apr  9 10:52:40 2006
New Revision: 392792

URL: http://svn.apache.org/viewcvs?rev=392792&view=rev
Log:
Small fix for OJB-48
Added test case for OJB-48

Added:
    db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest2.java
Modified:
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/CreationDescriptor.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/ClassHelper.java
    db/ojb/trunk/src/schema/ojbtest-schema.xml
    db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest.java
    db/ojb/trunk/src/test/org/apache/ojb/repository_junit.xml

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java?rev=392792&r1=392791&r2=392792&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java Sun Apr  9 10:52:40
2006
@@ -441,11 +441,10 @@
                          */
                         // fill reference and collection attributes
                         ClassDescriptor cld = getBroker().getClassDescriptor(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);
+                        getBroker().getReferenceBroker().retrieveReferences(result, cld,
false);
+                        getBroker().getReferenceBroker().retrieveCollections(result, cld,
false);
 
                         getCache().disableMaterializationCache();
                     }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java?rev=392792&r1=392791&r2=392792&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java Sun Apr  9
10:52:40 2006
@@ -16,6 +16,7 @@
  */
 
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -1453,11 +1454,7 @@
                                              outerClassRef.getForeignKeyFieldDescriptors(classDesc),
                                              rowForInnerObj);
 
-            // TODO: this doGetObjectByIdentity call might lead to problems when the outer
-            //       objects references its inner object;
-            //       solution: put a unmaterialized proxy for the inner object into
-            //       the materializion cache prior to getting the outer object
-            outerObj = doGetObjectByIdentity(outerId);
+            outerObj = doGetObjectByIdentity(outerId, true);
 
         }
         // there might be non-persistent outer classes in-between which we simply
@@ -1524,16 +1521,26 @@
      */
     public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException
     {
+        retrieveAllReferences(pInstance, true);
+    }
+
+    /**
+     * Retrieve all References (also Collection-attributes) of a given instance.
+     * Loading is forced, even if the collection- and reference-descriptors differ.
+     * @param pInstance the persistent instance to work with
+     */
+    private void retrieveAllReferences(Object obj, boolean force) throws PersistenceBrokerException
+    {
         if (logger.isDebugEnabled())
         {
-        	logger.debug("Manually retrieving all references for object " + serviceIdentity().buildIdentity(pInstance));
+            logger.debug("Manually retrieving all references for object " + serviceIdentity().buildIdentity(obj));
         }
-        ClassDescriptor cld = getClassDescriptor(pInstance.getClass());
+        ClassDescriptor cld = getClassDescriptor(obj.getClass());
         try
         {
             serviceSessionCache().enableMaterializationCache();
             // to avoid problems with circular references, locally cache the current object
instance
-            Identity oid = serviceIdentity().buildIdentity(pInstance);
+            Identity oid = serviceIdentity().buildIdentity(obj);
             /*
             if the object wasn't in session cache, put it only to materialization cache
             to avoid problems with object state detection (insert/update),
@@ -1541,11 +1548,11 @@
             */
             if(serviceSessionCache().lookup(oid, SessionCache.LEVEL_SESSION) == null)
             {
-                serviceSessionCache().cache(oid, pInstance, SessionCache.TYPE_UNKNOWN, SessionCache.LEVEL_MATERIALIZE);
+                serviceSessionCache().cache(oid, obj, SessionCache.TYPE_UNKNOWN, SessionCache.LEVEL_MATERIALIZE);
             }
             // force loading of references
-            referencesBroker.retrieveReferences(pInstance, cld, true);
-            referencesBroker.retrieveCollections(pInstance, cld, true);
+            referencesBroker.retrieveReferences(obj, cld, force);
+            referencesBroker.retrieveCollections(obj, cld, force);
             serviceSessionCache().disableMaterializationCache();
         }
         catch(RuntimeException e)
@@ -1753,11 +1760,12 @@
      * object by it's identity from the database, as well as caching the
      * object
      *
-     * @param oid The {@link org.apache.ojb.broker.Identity} of the object to for
+     * @param oid               The {@link org.apache.ojb.broker.Identity} of the object
+     * @param loadRelationships Whether to load the relationships
      * @return A new object read from the database or <em>null</em> if not found
      * @throws ClassNotPersistenceCapableException
      */
-    private Object getDBObject(Identity oid) throws ClassNotPersistenceCapableException
+    private Object getDBObject(Identity oid, boolean loadRelationships) throws ClassNotPersistenceCapableException
     {
         Class c = oid.getObjectsRealClass();
 
@@ -1778,53 +1786,59 @@
                 oid.setObjectsRealClass(newObj.getClass());
             }
 
-            /*
-             * synchronize on newObj so the ODMG-layer can take a snapshot only of
-             * fully cached (i.e. with all references + collections) objects
-             */
-            synchronized (newObj)
+            if (loadRelationships)
             {
-                serviceSessionCache().enableMaterializationCache();
-                try
-                {
-                    // cache object immediately , so that references
-                    // can be established from referenced Objects back to this Object
-                    serviceSessionCache().cache(oid, newObj, SessionCache.TYPE_NEW_MATERIALIZED,
SessionCache.LEVEL_DEEP);
-
-                    /*
-                     * Chris Lewington: can cause problems with multiple objects
-                     * mapped to one table, as follows:
-                     *
-                     * if the class searched on does not match the retrieved
-                     * class, eg a search on an OID retrieves a row but it could
-                     * be a different class (OJB gets all column values),
-                     * then trying to resolve references will fail as the object
-                     * will not match the Class Descriptor.
-                     *
-                     * To be safe, get the descriptor of the retrieved object
-                     * BEFORE resolving refs
-                     */
-                    ClassDescriptor newObjCld = getClassDescriptor(newObj.getClass());
-                    // don't force loading of references:
-                    final boolean unforced = false;
-
-                    // 2. retrieve non-skalar fields that contain objects retrievable from
other tables
-                    referencesBroker.retrieveReferences(newObj, newObjCld, unforced);
-                    // 3. retrieve collection fields from foreign-key related tables:
-                    referencesBroker.retrieveCollections(newObj, newObjCld, unforced);
-                    serviceSessionCache().disableMaterializationCache();
-                }
-                catch(RuntimeException e)
-                {
-                    serviceSessionCache().clearMaterializationCache();
-                    throw e;
-                }
+                readRelationships(newObj, oid);
             }
         }
 
         return newObj;
     }
 
+    private void readRelationships(Object obj, Identity oid)
+    {
+        /*
+         * synchronize on newObj so the ODMG-layer can take a snapshot only of
+         * fully cached (i.e. with all references + collections) objects
+         */
+        synchronized (obj)
+        {
+            serviceSessionCache().enableMaterializationCache();
+            try
+            {
+                // cache object immediately , so that references
+                // can be established from referenced Objects back to this Object
+                serviceSessionCache().cache(oid, obj, SessionCache.TYPE_NEW_MATERIALIZED,
SessionCache.LEVEL_DEEP);
+
+                /*
+                 * Chris Lewington: can cause problems with multiple objects
+                 * mapped to one table, as follows:
+                 *
+                 * if the class searched on does not match the retrieved
+                 * class, eg a search on an OID retrieves a row but it could
+                 * be a different class (OJB gets all column values),
+                 * then trying to resolve references will fail as the object
+                 * will not match the Class Descriptor.
+                 *
+                 * To be safe, get the descriptor of the retrieved object
+                 * BEFORE resolving refs
+                 */
+                ClassDescriptor objCld = getClassDescriptor(obj.getClass());
+
+                // 2. retrieve non-skalar fields that contain objects retrievable from other
tables
+                referencesBroker.retrieveReferences(obj, objCld, false);
+                // 3. retrieve collection fields from foreign-key related tables:
+                referencesBroker.retrieveCollections(obj, objCld, false);
+                serviceSessionCache().disableMaterializationCache();
+            }
+            catch (RuntimeException ex)
+            {
+                serviceSessionCache().clearMaterializationCache();
+                throw ex;
+            }
+        }
+    }
+    
     /**
      * returns an Iterator that iterates Objects of class c if calling the .next()
      * method. The Elements returned come from a SELECT ... WHERE Statement
@@ -1876,14 +1890,27 @@
     }
 
     /**
-     * Internal used method to retrieve object based on Identity.
+     * Internal method to retrieve an object based on its identity.
      *
-     * @param id
-     * @return
-     * @throws PersistenceBrokerException
+     * @param id The identity of the object
+     * @return The object
+     * @throws PersistenceBrokerException If an error occured while retrieving the object
      */
     public Object doGetObjectByIdentity(Identity id) throws PersistenceBrokerException
     {
+        return doGetObjectByIdentity(id, true);
+    }
+
+    /**
+     * Internal method to retrieve an object based on its identity.
+     *
+     * @param id                The identity of the object
+     * @param loadRelationships Whether to load the relationships
+     * @return The object
+     * @throws PersistenceBrokerException If an error occured while retrieving the object
+     */
+    public Object doGetObjectByIdentity(Identity id, boolean loadRelationships) throws PersistenceBrokerException
+    {
         if (logger.isDebugEnabled()) logger.debug("getObjectByIdentity " + id);
 
         // check if object is present in ObjectCache:
@@ -1891,7 +1918,7 @@
         // only perform a db lookup if necessary (object not cached yet)
         if (obj == null)
         {
-            obj = getDBObject(id);
+            obj = getDBObject(id, loadRelationships);
         }
         else
         {

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/CreationDescriptor.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/CreationDescriptor.java?rev=392792&r1=392791&r2=392792&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/CreationDescriptor.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/CreationDescriptor.java Sun Apr 
9 10:52:40 2006
@@ -174,7 +174,7 @@
             }
             else
             {
-                Constructor[] constructors = targetClass.getConstructors();
+                Constructor[] constructors = targetClass.getDeclaredConstructors();
     
                 for (int idx = 0; idx < constructors.length; idx++)
                 {

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/util/ClassHelper.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/util/ClassHelper.java?rev=392792&r1=392791&r2=392792&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/util/ClassHelper.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/util/ClassHelper.java Sun Apr  9 10:52:40
2006
@@ -150,7 +150,7 @@
     }
 
     /**
-     * Determines the encllsing class for static and non-static inner classes.
+     * Determines the enclosing class for static and non-static inner classes.
      * 
      * @param clazz The class
      * @return The enclosing class or <code>null</code> if the given class is
not an inner class

Modified: db/ojb/trunk/src/schema/ojbtest-schema.xml
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/schema/ojbtest-schema.xml?rev=392792&r1=392791&r2=392792&view=diff
==============================================================================
--- db/ojb/trunk/src/schema/ojbtest-schema.xml (original)
+++ db/ojb/trunk/src/schema/ojbtest-schema.xml Sun Apr  9 10:52:40 2006
@@ -1889,4 +1889,58 @@
   <table name="Ownable2">
     <column name="id" required="true" primaryKey="true" type="INTEGER"/>
   </table>
+
+  <table name="DeepInnerClass">
+      <column name="id"
+              javaName="id"
+              type="INTEGER"
+              primaryKey="true"
+              required="true"
+      />
+      <column name="text"
+              javaName="text"
+              type="VARCHAR"
+              size="254"
+      />
+      <column name="innerId"
+              javaName="innerId"
+              type="INTEGER"
+      />
+      <foreign-key foreignTable="InnerClass2">
+          <reference local="innerId" foreign="id"/>
+      </foreign-key>
+  </table>
+  <table name="InnerClass2">
+      <column name="id"
+              javaName="id"
+              type="INTEGER"
+              primaryKey="true"
+              required="true"
+      />
+      <column name="text"
+              javaName="text"
+              type="VARCHAR"
+              size="254"
+      />
+      <column name="outerId"
+              javaName="outerId"
+              type="INTEGER"
+      />
+      <foreign-key foreignTable="OuterClass2">
+          <reference local="outerId" foreign="id"/>
+      </foreign-key>
+  </table>
+  <table name="OuterClass2">
+      <column name="id"
+              javaName="id"
+              type="INTEGER"
+              primaryKey="true"
+              required="true"
+      />
+      <column name="text"
+              javaName="text"
+              type="VARCHAR"
+              size="254"
+      />
+  </table>
 </database>

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest.java?rev=392792&r1=392791&r2=392792&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest.java Sun Apr  9 10:52:40 2006
@@ -1,6 +1,6 @@
 package org.apache.ojb.broker;
 
-/* Copyright 2002-2004 The Apache Software Foundation
+/* Copyright 2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@
     /**
      * Tests persistence of a simple inner-outer class model.
      */
-    public void _testSimpleModel()
+    public void testSimpleModel()
     {
         OuterClass            outer = new OuterClass();
         OuterClass.InnerClass inner = outer.new InnerClass();

Added: db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest2.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest2.java?rev=392792&view=auto
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest2.java (added)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/InnerClassTest2.java Sun Apr  9 10:52:40 2006
@@ -0,0 +1,400 @@
+package org.apache.ojb.broker;
+
+/* Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ojb.broker.query.Criteria;
+import org.apache.ojb.broker.query.QueryByCriteriaImpl;
+import org.apache.ojb.junit.PBTestCase;
+
+/**
+ * Additional inner class tests related to issue OJB-48.
+ */
+public class InnerClassTest2 extends PBTestCase
+{
+    public static void main(String[] args)
+    {
+        String[] arr = { InnerClassTest2.class.getName() };
+
+        junit.textui.TestRunner.main(arr);
+    }
+
+    private static final String OUTER_TEXT = "ocTest";
+    private static final String INNER_TEXT = "icTest";
+    private static final String DEEP_TEXT  = "dicTest";
+
+    public void setUp() throws Exception
+    {
+        super.setUp();
+    }
+
+    public void testStoreAndQuery() throws Exception
+    {
+        // Creating data
+        OuterClass2                            oc  = new OuterClass2();
+        OuterClass2.InnerClass2                ic  = oc.new InnerClass2();
+        OuterClass2.InnerClass2.DeepInnerClass dic = ic.new DeepInnerClass();
+
+        oc.setText(OUTER_TEXT);
+        ic.setText(INNER_TEXT);
+        dic.setText(DEEP_TEXT);
+
+        broker.beginTransaction();
+        broker.store(ic);
+        broker.store(dic);
+        broker.commitTransaction();
+
+        oc  = null;
+        ic  = null;
+        dic = null;
+        broker.clearCache();
+
+        Criteria crit = new Criteria();
+
+        crit.addColumnEqualTo("text", OUTER_TEXT);
+
+        QueryByCriteriaImpl query = new QueryByCriteriaImpl(OuterClass2.class, crit);
+
+        oc = (OuterClass2)broker.getObjectByQuery(query);
+
+        assertEquals(OUTER_TEXT, oc.getText());
+        assertEquals(1, oc.getInnerClasses().size());
+        ic = (OuterClass2.InnerClass2)oc.getInnerClasses().get(0);
+        assertEquals(INNER_TEXT, ic.getText());
+        assertEquals(1, ic.getDeepInnerClasses().size());
+        dic = (OuterClass2.InnerClass2.DeepInnerClass)ic.getDeepInnerClasses().get(0);
+        assertEquals(DEEP_TEXT, dic.getText());
+        
+        oc  = null;
+        ic  = null;
+        dic = null;
+        broker.clearCache();
+
+        crit = new Criteria();
+        crit.addColumnEqualTo("text", INNER_TEXT);
+        query = new QueryByCriteriaImpl(OuterClass2.InnerClass2.class, crit);
+
+        ic = (OuterClass2.InnerClass2)broker.getObjectByQuery(query);
+
+        assertEquals(INNER_TEXT, ic.getText());
+        assertEquals(1, ic.getDeepInnerClasses().size());
+
+        oc = (OuterClass2)ic.getClass().getDeclaredField("this$0").get(ic);
+        assertEquals(OUTER_TEXT, oc.getText());
+        assertEquals(1, oc.getInnerClasses().size());
+        assertEquals(ic, oc.getInnerClasses().get(0));
+        dic = (OuterClass2.InnerClass2.DeepInnerClass)ic.getDeepInnerClasses().get(0);
+        assertEquals(DEEP_TEXT, dic.getText());
+
+        oc  = null;
+        ic  = null;
+        dic = null;
+        broker.clearCache();
+
+        crit = new Criteria();
+        crit.addColumnEqualTo("text", DEEP_TEXT);
+        query = new QueryByCriteriaImpl(OuterClass2.InnerClass2.DeepInnerClass.class, crit);
+
+        dic = (OuterClass2.InnerClass2.DeepInnerClass)broker.getObjectByQuery(query);
+
+        assertEquals(DEEP_TEXT, dic.getText());
+
+        ic = (OuterClass2.InnerClass2)dic.getClass().getDeclaredField("this$1").get(dic);
+        oc = (OuterClass2)ic.getClass().getDeclaredField("this$0").get(ic);
+        assertEquals(OUTER_TEXT, oc.getText());
+        assertEquals(1, oc.getInnerClasses().size());
+        assertEquals(ic, oc.getInnerClasses().get(0));
+        assertEquals(INNER_TEXT, ic.getText());
+        assertEquals(1, ic.getDeepInnerClasses().size());
+        assertEquals(dic, ic.getDeepInnerClasses().get(0));
+    }
+
+    public void testIdentity() throws Exception
+    {
+        // Creating data
+        OuterClass2                           oc   = new OuterClass2();
+        OuterClass2.InnerClass2                ic1  = oc.new InnerClass2();
+        OuterClass2.InnerClass2                ic2  = oc.new InnerClass2();
+        OuterClass2.InnerClass2.DeepInnerClass dic1 = ic1.new DeepInnerClass();
+        OuterClass2.InnerClass2.DeepInnerClass dic2 = ic2.new DeepInnerClass();
+        OuterClass2.InnerClass2.DeepInnerClass dic3 = ic2.new DeepInnerClass();
+
+        oc.setText(OUTER_TEXT);
+        ic1.setText(INNER_TEXT + " 1");
+        ic2.setText(INNER_TEXT + " 2");
+        dic1.setText(DEEP_TEXT + " 1");
+        dic2.setText(DEEP_TEXT + " 2");
+        dic3.setText(DEEP_TEXT + " 3");
+
+        broker.beginTransaction();
+        broker.store(dic1);
+        broker.store(dic2);
+        broker.store(dic3);
+        broker.commitTransaction();
+
+        Identity idOc   = broker.serviceIdentity().buildIdentity(oc);
+        Identity idIc1  = broker.serviceIdentity().buildIdentity(ic1);
+        Identity idIc2  = broker.serviceIdentity().buildIdentity(ic2);
+        Identity idDic1 = broker.serviceIdentity().buildIdentity(dic1);
+        Identity idDic2 = broker.serviceIdentity().buildIdentity(dic2);
+        Identity idDic3 = broker.serviceIdentity().buildIdentity(dic3);
+        
+        oc   = null;
+        ic1  = null;
+        ic2  = null;
+        dic1 = null;
+        dic2 = null;
+        dic3 = null;
+        broker.clearCache();
+
+        oc = (OuterClass2)broker.getObjectByIdentity(idOc);
+
+        assertEquals(OUTER_TEXT, oc.getText());
+        assertEquals(2, oc.getInnerClasses().size());
+        ic1 = (OuterClass2.InnerClass2)oc.getInnerClasses().get(0);
+        ic2 = (OuterClass2.InnerClass2)oc.getInnerClasses().get(1);
+        assertEquals(INNER_TEXT + " 1", ic1.getText());
+        assertEquals(INNER_TEXT + " 2", ic2.getText());
+        assertEquals(1, ic1.getDeepInnerClasses().size());
+        assertEquals(2, ic2.getDeepInnerClasses().size());
+        dic1 = (OuterClass2.InnerClass2.DeepInnerClass)ic1.getDeepInnerClasses().get(0);
+        dic2 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(0);
+        dic3 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(1);
+        assertEquals(DEEP_TEXT + " 1", dic1.getText());
+        assertEquals(DEEP_TEXT + " 2", dic2.getText());
+        assertEquals(DEEP_TEXT + " 3", dic3.getText());
+
+        oc   = null;
+        ic1  = null;
+        ic2  = null;
+        dic1 = null;
+        dic2 = null;
+        dic3 = null;
+        broker.clearCache();
+
+        ic1 = (OuterClass2.InnerClass2)broker.getObjectByIdentity(idIc1);
+
+        assertEquals(INNER_TEXT + " 1", ic1.getText());
+        assertEquals(1, ic1.getDeepInnerClasses().size());
+
+        oc = (OuterClass2)ic1.getClass().getDeclaredField("this$0").get(ic1);
+        assertEquals(OUTER_TEXT, oc.getText());
+        assertEquals(2, oc.getInnerClasses().size());
+        assertEquals(ic1, oc.getInnerClasses().get(0));
+        ic2 = (OuterClass2.InnerClass2)oc.getInnerClasses().get(1);
+        assertEquals(INNER_TEXT + " 2", ic2.getText());
+        dic1 = (OuterClass2.InnerClass2.DeepInnerClass)ic1.getDeepInnerClasses().get(0);
+        dic2 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(0);
+        dic3 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(1);
+        assertEquals(DEEP_TEXT + " 1", dic1.getText());
+        assertEquals(DEEP_TEXT + " 2", dic2.getText());
+        assertEquals(DEEP_TEXT + " 3", dic3.getText());
+
+        oc   = null;
+        ic1  = null;
+        ic2  = null;
+        dic1 = null;
+        dic2 = null;
+        dic3 = null;
+        broker.clearCache();
+
+        ic2 = (OuterClass2.InnerClass2)broker.getObjectByIdentity(idIc2);
+
+        assertEquals(INNER_TEXT + " 2", ic2.getText());
+        assertEquals(2, ic2.getDeepInnerClasses().size());
+
+        oc = (OuterClass2)ic2.getClass().getDeclaredField("this$0").get(ic2);
+        assertEquals(OUTER_TEXT, oc.getText());
+        assertEquals(2, oc.getInnerClasses().size());
+        assertEquals(ic2, oc.getInnerClasses().get(1));
+        ic1 = (OuterClass2.InnerClass2)oc.getInnerClasses().get(0);
+        assertEquals(INNER_TEXT + " 1", ic1.getText());
+        dic1 = (OuterClass2.InnerClass2.DeepInnerClass)ic1.getDeepInnerClasses().get(0);
+        dic2 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(0);
+        dic3 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(1);
+        assertEquals(DEEP_TEXT + " 1", dic1.getText());
+        assertEquals(DEEP_TEXT + " 2", dic2.getText());
+        assertEquals(DEEP_TEXT + " 3", dic3.getText());
+
+        oc   = null;
+        ic1  = null;
+        ic2  = null;
+        dic1 = null;
+        dic2 = null;
+        dic3 = null;
+        broker.clearCache();
+
+        dic1 = (OuterClass2.InnerClass2.DeepInnerClass)broker.getObjectByIdentity(idDic1);
+
+        assertEquals(DEEP_TEXT + " 1", dic1.getText());
+
+        ic1 = (OuterClass2.InnerClass2)dic1.getClass().getDeclaredField("this$1").get(dic1);
+        oc  = (OuterClass2)ic1.getClass().getDeclaredField("this$0").get(ic1);
+        assertEquals(OUTER_TEXT, oc.getText());
+        assertEquals(2, oc.getInnerClasses().size());
+        assertEquals(ic1, oc.getInnerClasses().get(0));
+        assertEquals(1, ic1.getDeepInnerClasses().size());
+        ic2 = (OuterClass2.InnerClass2)oc.getInnerClasses().get(1);
+        assertEquals(INNER_TEXT + " 1", ic1.getText());
+        assertEquals(INNER_TEXT + " 2", ic2.getText());
+        assertEquals(dic1, ic1.getDeepInnerClasses().get(0));
+        dic2 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(0);
+        dic3 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(1);
+        assertEquals(DEEP_TEXT + " 2", dic2.getText());
+        assertEquals(DEEP_TEXT + " 3", dic3.getText());
+
+        oc   = null;
+        ic1  = null;
+        ic2  = null;
+        dic1 = null;
+        dic2 = null;
+        dic3 = null;
+        broker.clearCache();
+
+        dic2 = (OuterClass2.InnerClass2.DeepInnerClass)broker.getObjectByIdentity(idDic2);
+
+        assertEquals(DEEP_TEXT + " 2", dic2.getText());
+
+        ic2 = (OuterClass2.InnerClass2)dic2.getClass().getDeclaredField("this$1").get(dic2);
+        oc  = (OuterClass2)ic2.getClass().getDeclaredField("this$0").get(ic2);
+        assertEquals(OUTER_TEXT, oc.getText());
+        assertEquals(2, oc.getInnerClasses().size());
+        assertEquals(ic2, oc.getInnerClasses().get(1));
+        assertEquals(2, ic2.getDeepInnerClasses().size());
+        ic1 = (OuterClass2.InnerClass2)oc.getInnerClasses().get(0);
+        assertEquals(INNER_TEXT + " 1", ic1.getText());
+        assertEquals(INNER_TEXT + " 2", ic2.getText());
+        assertEquals(dic2, ic2.getDeepInnerClasses().get(0));
+        dic1 = (OuterClass2.InnerClass2.DeepInnerClass)ic1.getDeepInnerClasses().get(0);
+        dic3 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(1);
+        assertEquals(DEEP_TEXT + " 1", dic1.getText());
+        assertEquals(DEEP_TEXT + " 3", dic3.getText());
+
+        oc   = null;
+        ic1  = null;
+        ic2  = null;
+        dic1 = null;
+        dic2 = null;
+        dic3 = null;
+        broker.clearCache();
+
+        dic3 = (OuterClass2.InnerClass2.DeepInnerClass)broker.getObjectByIdentity(idDic3);
+
+        assertEquals(DEEP_TEXT + " 3", dic3.getText());
+
+        ic2 = (OuterClass2.InnerClass2)dic3.getClass().getDeclaredField("this$1").get(dic3);
+        oc  = (OuterClass2)ic2.getClass().getDeclaredField("this$0").get(ic2);
+        assertEquals(OUTER_TEXT, oc.getText());
+        assertEquals(2, oc.getInnerClasses().size());
+        assertEquals(ic2, oc.getInnerClasses().get(1));
+        assertEquals(2, ic2.getDeepInnerClasses().size());
+        ic1 = (OuterClass2.InnerClass2)oc.getInnerClasses().get(0);
+        assertEquals(INNER_TEXT + " 1", ic1.getText());
+        assertEquals(INNER_TEXT + " 2", ic2.getText());
+        assertEquals(dic3, ic2.getDeepInnerClasses().get(1));
+        dic1 = (OuterClass2.InnerClass2.DeepInnerClass)ic1.getDeepInnerClasses().get(0);
+        dic2 = (OuterClass2.InnerClass2.DeepInnerClass)ic2.getDeepInnerClasses().get(0);
+        assertEquals(DEEP_TEXT + " 1", dic1.getText());
+        assertEquals(DEEP_TEXT + " 2", dic2.getText());
+    }
+}
+
+class OuterClass2
+{
+    private Integer id;
+    private String text;
+    private List innerClasses = new ArrayList();
+
+    OuterClass2()
+    {
+        setText("uninitialized");
+    }
+
+    public String getText()
+    {
+        return text;
+    }
+
+    public void setText(String text)
+    {
+        this.text = text;
+    }
+
+    public boolean hasInnerClass()
+    {
+        return (innerClasses != null) && !innerClasses.isEmpty();
+    }
+
+    public List getInnerClasses()
+    {
+        return innerClasses;
+    }
+
+    public void addInnerClass(InnerClass2 innerClass)
+    {
+        innerClasses.add(innerClass);
+    }
+
+    public class InnerClass2
+    {
+        private Integer id;
+        private String text;
+        private List deepInnerClasses = new ArrayList();
+
+        public InnerClass2()
+        {
+            setText("empty");
+        }
+
+        public String getText()
+        {
+            return text;
+        }
+
+        public void setText(String text)
+        {
+            this.text = text;
+        }
+
+        public boolean hasDeepInnerClass()
+        {
+            return (deepInnerClasses != null) && !deepInnerClasses.isEmpty();
+        }
+
+        public List getDeepInnerClasses()
+        {
+            return deepInnerClasses;
+        }
+
+        class DeepInnerClass
+        {
+            private Integer id;
+            private String text;
+
+            public String getText()
+            {
+                return text;
+            }
+
+            public void setText(String text)
+            {
+                this.text = text;
+            }
+        }
+    }
+}

Modified: db/ojb/trunk/src/test/org/apache/ojb/repository_junit.xml
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/test/org/apache/ojb/repository_junit.xml?rev=392792&r1=392791&r2=392792&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/repository_junit.xml (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/repository_junit.xml Sun Apr  9 10:52:40 2006
@@ -3444,4 +3444,120 @@
        >
        </field-descriptor>
     </class-descriptor>
+
+<class-descriptor
+    class="org.apache.ojb.broker.OuterClass2"
+    table="OuterClass2"
+>
+    <field-descriptor
+        name="id"
+        column="id"
+        jdbc-type="INTEGER"
+        primarykey="true"
+        autoincrement="true"
+    >
+    </field-descriptor>
+    <field-descriptor
+        name="text"
+        column="text"
+        jdbc-type="VARCHAR"
+        length="254"
+    >
+    </field-descriptor>
+    <collection-descriptor
+        name="innerClasses"
+        element-class-ref="org.apache.ojb.broker.OuterClass2$InnerClass2"
+        proxy="true"
+        auto-retrieve="true"
+        auto-update="object"
+        auto-delete="object"
+    >
+        <inverse-foreignkey field-ref="outerId"/>
+    </collection-descriptor>
+</class-descriptor>
+<class-descriptor
+    class="org.apache.ojb.broker.OuterClass2$InnerClass2"
+    table="InnerClass2"
+>
+    <field-descriptor
+        name="id"
+        column="id"
+        jdbc-type="INTEGER"
+        primarykey="true"
+        autoincrement="true"
+    >
+    </field-descriptor>
+    <field-descriptor
+        name="text"
+        column="text"
+        jdbc-type="VARCHAR"
+        length="254"
+    >
+    </field-descriptor>
+    <field-descriptor
+        name="outerId"
+        column="outerId" 
+        required="true"
+        jdbc-type="INTEGER"
+        access="anonymous"
+    >
+    </field-descriptor>
+    <reference-descriptor
+        name="OuterClass2.this"
+        class-ref="org.apache.ojb.broker.OuterClass2"
+        auto-retrieve="true"
+        auto-update="link"
+        auto-delete="link"
+    >
+        <foreignkey field-ref="outerId"/>
+    </reference-descriptor>
+    <collection-descriptor
+        name="deepInnerClasses"
+        element-class-ref="org.apache.ojb.broker.OuterClass2$InnerClass2$DeepInnerClass"
+        proxy="true"
+        auto-retrieve="true"
+        auto-update="true"
+        auto-delete="object"
+    >
+        <inverse-foreignkey field-ref="innerId"/>
+    </collection-descriptor>
+</class-descriptor>
+<class-descriptor
+    class="org.apache.ojb.broker.OuterClass2$InnerClass2$DeepInnerClass"
+    table="DeepInnerClass"
+>
+    <field-descriptor
+        name="id"
+        column="id"
+        jdbc-type="INTEGER"
+        primarykey="true"
+        autoincrement="true"
+    >
+    </field-descriptor>
+      <field-descriptor
+        name="text"
+        column="text"
+        jdbc-type="VARCHAR"
+        length="254"
+    >
+    </field-descriptor>
+   <field-descriptor
+        name="innerId"
+        column="innerId"
+        required="true"
+        jdbc-type="INTEGER"
+        access="anonymous"
+    >
+    </field-descriptor>
+    <reference-descriptor
+        name="InnerClass2.this"
+        class-ref="org.apache.ojb.broker.OuterClass2$InnerClass2"
+        auto-retrieve="true"
+        auto-update="link"
+        auto-delete="link"
+    >
+        <foreignkey field-ref="innerId"/>
+    </reference-descriptor>
+</class-descriptor>
+
 <!-- Mapping of classes used in junit tests and tutorials ends here -->



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


Mime
View raw message