db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb repository_junit_odmg.xml
Date Tue, 10 May 2005 19:08:55 GMT
arminw      2005/05/10 12:08:55

  Modified:    src/java/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        ClassDescriptor.java
               src/java/org/apache/ojb/broker/util Tag: OJB_1_0_RELEASE
                        BrokerHelper.java
               src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        ObjectEnvelope.java ObjectEnvelopeOrdering.java
                        ObjectEnvelopeTable.java TransactionImpl.java
               src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        InheritanceMultipleTableTest.java
               src/test/org/apache/ojb Tag: OJB_1_0_RELEASE
                        repository_junit_odmg.xml
  Log:
  - fix problems with multiple joined table inheritance (super-reference) and odmg-api
  - fix OJB-25
  - add new methods in ClassDescriptor to handle super-reference inheritence with odmg-api
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.88.2.16 +92 -2     db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.88.2.15
  retrieving revision 1.88.2.16
  diff -u -r1.88.2.15 -r1.88.2.16
  --- ClassDescriptor.java	7 May 2005 16:43:06 -0000	1.88.2.15
  +++ ClassDescriptor.java	10 May 2005 19:08:54 -0000	1.88.2.16
  @@ -33,7 +33,6 @@
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.lang.builder.ToStringStyle;
   import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.locking.IsolationLevels;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.accesslayer.RowReader;
   import org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl;
  @@ -41,6 +40,7 @@
   import org.apache.ojb.broker.accesslayer.StatementsForClassIF;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
  +import org.apache.ojb.broker.locking.IsolationLevels;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.SqlHelper;
  @@ -2195,4 +2195,94 @@
            }
           return useIdentityColumn == 1;
        }
  +
  +    /**
  +     * Returns all defined {@link ObjectReferenceDescriptor}.
  +     *
  +     * @param withInherited If <em>true</em> inherited super class references
will be included.
  +     */
  +    public List getObjectReferenceDescriptors(boolean withInherited)
  +    {
  +        if(withInherited && getSuperClassDescriptor() != null)
  +        {
  +            List result = new ArrayList(m_ObjectReferenceDescriptors);
  +            result.addAll(getSuperClassDescriptor().getObjectReferenceDescriptors(true));
  +            return result;
  +        }
  +        else
  +        {
  +            return m_ObjectReferenceDescriptors;
  +        }
  +    }
  +
  +    /**
  +     * Returns all defined {@link CollectionDescriptor} for
  +     * this class descriptor.
  +     *
  +     * @param withInherited If <em>true</em> inherited super class references
will be included.
  +     */
  +    public List getCollectionDescriptors(boolean withInherited)
  +    {
  +        if(withInherited && getSuperClassDescriptor() != null)
  +        {
  +            List result = new ArrayList(m_CollectionDescriptors);
  +            result.addAll(getSuperClassDescriptor().getCollectionDescriptors(true));
  +            return result;
  +        }
  +        else
  +        {
  +            return m_CollectionDescriptors;
  +        }
  +    }
  +
  +    /**
  +     * Return an array of all {@link FieldDescriptor} for this represented class, if
  +     * parameter <em>withInherited</em> is <em>true</em> all inherited
descriptor
  +     * of declared super classes are included.
  +     *
  +     * @param withInherited If <em>true</em> inherited super class fields will
be included.
  +     */
  +    public FieldDescriptor[] getFieldDescriptor(boolean withInherited)
  +    {
  +        if(withInherited && getSuperClassDescriptor() != null)
  +        {
  +            FieldDescriptor[] superFlds = getSuperClassDescriptor().getFieldDescriptorNonPk(true);
  +            if(m_FieldDescriptions == null)
  +            {
  +                m_FieldDescriptions = new FieldDescriptor[0];
  +            }
  +            FieldDescriptor[] result = new FieldDescriptor[m_FieldDescriptions.length +
superFlds.length];
  +            System.arraycopy(m_FieldDescriptions, 0, result, 0, m_FieldDescriptions.length);
  +            System.arraycopy(superFlds, 0, result, m_FieldDescriptions.length, superFlds.length);
  +            // System.out.println("all fields: " + ArrayUtils.toString(result));
  +            return result;
  +        }
  +        else
  +        {
  +            return m_FieldDescriptions;
  +        }
  +    }
  +
  +    /**
  +     * Return an array of NON-PK {@link FieldDescriptor}, if parameter <em>withInherited</em>
  +     * is <em>true</em> all inherited descriptor of declared super classes
are included.
  +     *
  +     * @param withInherited If <em>true</em> inherited super class fields will
be included.
  +     */
  +    public FieldDescriptor[] getFieldDescriptorNonPk(boolean withInherited)
  +    {
  +        if(withInherited && getSuperClassDescriptor() != null)
  +        {
  +            FieldDescriptor[] flds = getNonPkFields();
  +            FieldDescriptor[] superFlds = getSuperClassDescriptor().getFieldDescriptorNonPk(true);
  +            FieldDescriptor[] result = new FieldDescriptor[flds.length + superFlds.length];
  +            System.arraycopy(flds, 0, result, 0, flds.length);
  +            System.arraycopy(superFlds, 0, result, flds.length, superFlds.length);
  +            return result;
  +        }
  +        else
  +        {
  +            return getNonPkFields();
  +        }
  +    }
   }
  
  
  
  No                   revision
  No                   revision
  1.57.2.16 +38 -3     db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.57.2.15
  retrieving revision 1.57.2.16
  diff -u -r1.57.2.15 -r1.57.2.16
  --- BrokerHelper.java	9 May 2005 14:26:55 -0000	1.57.2.15
  +++ BrokerHelper.java	10 May 2005 19:08:54 -0000	1.57.2.16
  @@ -876,7 +876,17 @@
   
       private void linkOrUnlinkOneToOne(boolean doLink, Object obj, ObjectReferenceDescriptor
ord, boolean insert)
       {
  -        ClassDescriptor cld = m_broker.getDescriptorRepository().getDescriptorFor(ProxyHelper.getRealClass(obj));
  +        /*
  +        arminw: we need the class-descriptor where the reference is declared, thus we ask
the
  +        reference-descriptor for this, instead of using the class-descriptor of the specified
  +        object. If the reference was declared within an interface (should never happen)
we
  +        only can use the descriptor of the real class.
  +        */
  +        ClassDescriptor cld = ord.getClassDescriptor();
  +        if(cld.isInterface())
  +        {
  +            cld = m_broker.getDescriptorRepository().getDescriptorFor(ProxyHelper.getRealClass(obj));
  +        }
   
           if (doLink)
           {
  @@ -887,7 +897,7 @@
               m_broker.unlinkFK(obj, cld, ord);
               // in 1:1 relation we have to set relation to null
               ord.getPersistentField().set(obj, null);
  -        }        
  +        }
       }
   
       /**
  @@ -1049,6 +1059,31 @@
       }
   
   //    /**
  +//     * Use this method to extract the {@link org.apache.ojb.broker.metadata.ClassDescriptor}
where
  +//     * the {@link org.apache.ojb.broker.metadata.ObjectReferenceDescriptor reference}
is declared.
  +//     * It's possible that the reference is declared in a super-class.
  +//     * @param broker
  +//     * @param reference
  +//     * @param source
  +//     * @return
  +//     */
  +//    public static ClassDescriptor extractDescriptorForReference(PersistenceBroker broker,
ObjectReferenceDescriptor reference, Object source)
  +//    {
  +//        /*
  +//        arminw: we need the class-descriptor where the reference is declared, thus we
ask the
  +//        reference-descriptor for this, instead of using the class-descriptor of the specified
  +//        object. If the reference was declared within an interface (should never happen)
we
  +//        only can use the descriptor of the real class.
  +//        */
  +//        ClassDescriptor cld = reference.getClassDescriptor();
  +//        if(cld.isInterface())
  +//        {
  +//            cld = broker.getDescriptorRepository().getDescriptorFor(ProxyHelper.getRealClass(source));
  +//        }
  +//        return cld;
  +//    }
  +
  +//    /**
   //     * Returns a {@link java.util.List} instance of the specified object in method argument,
   //     * in which the argument must be of type {@link java.util.Collection}, array or
   //     * {@link org.apache.ojb.broker.ManageableCollection}.
  
  
  
  No                   revision
  No                   revision
  1.32.2.14 +5 -5      db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java
  
  Index: ObjectEnvelope.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java,v
  retrieving revision 1.32.2.13
  retrieving revision 1.32.2.14
  diff -u -r1.32.2.13 -r1.32.2.14
  --- ObjectEnvelope.java	7 May 2005 16:20:59 -0000	1.32.2.13
  +++ ObjectEnvelope.java	10 May 2005 19:08:54 -0000	1.32.2.14
  @@ -307,7 +307,7 @@
            * marked "dirty", otherwise attaching or detaching a 1:1 referenced object will
            * not be updated in ODMG.
            */
  -        Iterator iter = mif.getObjectReferenceDescriptors().iterator();
  +        Iterator iter = mif.getObjectReferenceDescriptors(true).iterator();
           ObjectReferenceDescriptor rds = null;
           while(iter.hasNext())
           {
  @@ -352,7 +352,7 @@
               if object was serialized and anonymous FK are used in the main object, the
FK
               values are null, we have to refresh (re-assign) this values before building
field images
               */
  -            if(handler == null && referenceObject != null && BrokerHelper.hasAnonymousKeyReference(mif,
rds))
  +            if(handler == null && referenceObject != null && BrokerHelper.hasAnonymousKeyReference(rds.getClassDescriptor(),
rds))
               {
                   getBroker().serviceBrokerHelper().link(myObj, rds, false);
               }
  @@ -366,9 +366,9 @@
   
           /**
            * MBAIRD
  -         * 2. register all fields of object that aren't collections or references
  +         * 2. register all fields of object (with inherited fields) that aren't collections
or references
            */
  -        FieldDescriptor[] fieldDescs = mif.getFieldDescriptions();
  +        FieldDescriptor[] fieldDescs = mif.getFieldDescriptor(true);
           for(int i = 0; i < fieldDescs.length; i++)
           {
               FieldDescriptor fld = fieldDescs[i];
  @@ -389,7 +389,7 @@
            * 3. now let's register the collection descriptors
            * How do we handle proxied collections and collections of proxies
            */
  -        Iterator collections = mif.getCollectionDescriptors().iterator();
  +        Iterator collections = mif.getCollectionDescriptors(true).iterator();
           CollectionDescriptor cds = null;
           while(collections.hasNext())
           {
  
  
  
  1.1.2.5   +3 -3      db-ojb/src/java/org/apache/ojb/odmg/Attic/ObjectEnvelopeOrdering.java
  
  Index: ObjectEnvelopeOrdering.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/Attic/ObjectEnvelopeOrdering.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- ObjectEnvelopeOrdering.java	3 May 2005 17:09:04 -0000	1.1.2.4
  +++ ObjectEnvelopeOrdering.java	10 May 2005 19:08:54 -0000	1.1.2.5
  @@ -251,13 +251,13 @@
       private void addEdgesForVertex(Vertex vertex)
       {
           ClassDescriptor cld = vertex.getEnvelope().getClassDescriptor();
  -        Iterator rdsIter = cld.getObjectReferenceDescriptors().iterator();
  +        Iterator rdsIter = cld.getObjectReferenceDescriptors(true).iterator();
           while (rdsIter.hasNext())
           {
               ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) rdsIter.next();
               addObjectReferenceEdges(vertex, rds);
           }
  -        Iterator cdsIter = cld.getCollectionDescriptors().iterator();
  +        Iterator cdsIter = cld.getCollectionDescriptors(true).iterator();
           while (cdsIter.hasNext())
           {
               CollectionDescriptor cds = (CollectionDescriptor) cdsIter.next();
  
  
  
  1.32.2.19 +4 -4      db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java
  
  Index: ObjectEnvelopeTable.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java,v
  retrieving revision 1.32.2.18
  retrieving revision 1.32.2.19
  diff -u -r1.32.2.18 -r1.32.2.19
  --- ObjectEnvelopeTable.java	3 May 2005 17:09:04 -0000	1.32.2.18
  +++ ObjectEnvelopeTable.java	10 May 2005 19:08:54 -0000	1.32.2.19
  @@ -551,10 +551,10 @@
   
           ClassDescriptor cld = getTransaction().getBroker().getClassDescriptor(mod.getObject().getClass());
   
  -        List refs = cld.getObjectReferenceDescriptors();
  +        List refs = cld.getObjectReferenceDescriptors(true);
           cascadeInsertSingleReferences(mod, refs, alreadyPrepared);
   
  -        List colls = cld.getCollectionDescriptors();
  +        List colls = cld.getCollectionDescriptors(true);
           cascadeInsertCollectionReferences(mod, colls, alreadyPrepared);
       }
   
  @@ -712,10 +712,10 @@
   
           ClassDescriptor cld = getTransaction().getBroker().getClassDescriptor(mod.getObject().getClass());
   
  -        List refs = cld.getObjectReferenceDescriptors();
  +        List refs = cld.getObjectReferenceDescriptors(true);
           cascadeDeleteSingleReferences(mod, refs, alreadyPrepared);
   
  -        List colls = cld.getCollectionDescriptors();
  +        List colls = cld.getCollectionDescriptors(true);
           cascadeDeleteCollectionReferences(mod, colls, alreadyPrepared);
       }
   
  
  
  
  1.59.2.16 +5 -5      db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java
  
  Index: TransactionImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/TransactionImpl.java,v
  retrieving revision 1.59.2.15
  retrieving revision 1.59.2.16
  diff -u -r1.59.2.15 -r1.59.2.16
  --- TransactionImpl.java	3 May 2005 17:09:04 -0000	1.59.2.15
  +++ TransactionImpl.java	10 May 2005 19:08:54 -0000	1.59.2.16
  @@ -930,7 +930,7 @@
       {
           if (implicitLocking)
           {
  -            Iterator i = cld.getObjectReferenceDescriptors().iterator();
  +            Iterator i = cld.getObjectReferenceDescriptors(true).iterator();
               while (i.hasNext())
               {
                   ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) i.next();
  @@ -952,7 +952,7 @@
       {
           if (implicitLocking)
           {
  -            Iterator i = cld.getCollectionDescriptors().iterator();
  +            Iterator i = cld.getCollectionDescriptors(true).iterator();
               while (i.hasNext())
               {
                   CollectionDescriptor cds = (CollectionDescriptor) i.next();
  @@ -1314,13 +1314,13 @@
       {
           ClassDescriptor cld = getBroker().getClassDescriptor(target);
           Boolean result = doCascade ? Boolean.TRUE : Boolean.FALSE;
  -        List singleRefs = cld.getObjectReferenceDescriptors();
  +        List singleRefs = cld.getObjectReferenceDescriptors(true);
           for(int i = 0; i < singleRefs.size(); i++)
           {
               Object o = singleRefs.get(i);
               runtimeCascadeDeleteMap.put(o, result);
           }
  -        List collectionRefs = cld.getCollectionDescriptors();
  +        List collectionRefs = cld.getCollectionDescriptors(true);
           for(int i = 0; i < collectionRefs.size(); i++)
           {
               Object o =  collectionRefs.get(i);
  
  
  
  No                   revision
  No                   revision
  1.1.2.6   +283 -22   db-ojb/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java
  
  Index: InheritanceMultipleTableTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/InheritanceMultipleTableTest.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- InheritanceMultipleTableTest.java	22 Apr 2005 16:42:22 -0000	1.1.2.5
  +++ InheritanceMultipleTableTest.java	10 May 2005 19:08:54 -0000	1.1.2.6
  @@ -17,6 +17,16 @@
   
   /**
    * Test inheritance using multiple tables.
  + * <p/>
  + * Inner test classes:<br/>
  + * AddressIF<--Address<br/>
  + * Employee<--Executive<--Manager
  + *<p/>
  + * m:n relation between Employee and Address
  + * 1:1 relation from Employee to Address
  + * 1:n relation from Employee to Address
  + * 1:1 relation from Executive to Manager
  + * 1:n relation from Manager to Executive
    *
    * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
    * @version $Id$
  @@ -28,6 +38,134 @@
           junit.textui.TestRunner.main(new String[]{InheritanceMultipleTableTest.class.getName()});
       }
   
  +    public void testQueryUsingReference_1() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testQueryUsingReference_1" + timestamp;
  +
  +        Manager m_1 = new Manager(id_2, name + "_manager_1");
  +        m_1.setDepartment("m_1");
  +        Address a_1 = new Address("snob allee");
  +        m_1.setAddress(a_1);
  +
  +
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        database.makePersistent(m_1);
  +        tx.commit();
  +
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create("select objects from " + Manager.class.getName() + " where name like
$1 and address.street like $2");
  +        query.bind(name + "%");
  +        query.bind("snob allee");
  +        Collection result = (Collection) query.execute();
  +        tx.commit();
  +
  +        assertEquals(1, result.size());
  +        Manager retManager = (Manager) result.iterator().next();
  +        assertNotNull(retManager);
  +        assertEquals(name + "_manager_1", retManager.getName());
  +        assertNotNull(retManager.getAddress());
  +        assertEquals("snob allee", retManager.getAddress().getStreet());
  +
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        tx.lock(m_1, Transaction.WRITE);
  +        m_1.setName(m_1.getName() + "_updated");
  +        tx.commit();
  +    }
  +
  +    public void testQueryUsingReference_2() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testQueryUsingReference_2" + timestamp;
  +
  +        Manager manager = new Manager(id_2, name + "_manager_1");
  +        manager.setDepartment("manager");
  +        Address addressManager = new Address("snob allee 1");
  +        Address addressManagerOld = new Address("snob allee 2");
  +        Address address3 = new Address("snob allee 3");
  +        Address address4 = new Address("snob allee 4");
  +        manager.setAddress(addressManager);
  +        manager.addOldAddress(addressManagerOld);
  +        manager.addCarrel(address3);
  +        manager.addCarrel(address4);
  +
  +
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        database.makePersistent(manager);
  +        tx.commit();
  +
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create("select objects from " + Manager.class.getName() + " where name like
$1 and addressManager.street like $2");
  +        query.bind(name + "%");
  +        query.bind("snob allee");
  +        Collection result = (Collection) query.execute();
  +        tx.commit();
  +
  +        assertEquals(1, result.size());
  +        Manager retManager = (Manager) result.iterator().next();
  +        assertNotNull(retManager);
  +        assertEquals(name + "_manager_1", retManager.getName());
  +        assertNotNull(retManager.getAddress());
  +        assertEquals("snob allee", retManager.getAddress().getStreet());
  +
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        tx.lock(manager, Transaction.WRITE);
  +        manager.setName(manager.getName() + "_updated");
  +        tx.commit();
  +    }
  +
  +    public void testQuery_3() throws Exception
  +    {
  +        if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple
joined tables only" +
  +                " return base class type instances, same thing with queries against a base
type"))
  +        {
  +            return;
  +        }
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testInsert" + timestamp;
  +        Manager m_3 = new Manager(id_2, name + "_manager_3");
  +        m_3.setDepartment("none");
  +
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        database.makePersistent(m_3);
  +        tx.commit();
  +
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create("select objects from " + Manager.class.getName() + " where name like
$1");
  +        query.bind(name + "%");
  +        List newManagers = new ArrayList((Collection) query.execute());
  +        tx.commit();
  +        assertEquals(1, newManagers.size());
  +
  +        Manager new_m = (Manager) newManagers.get(0);
  +        assertNotNull(new_m.getId());
  +        assertNotNull(new_m.getId_2());
  +        assertEquals(m_3.getName(), new_m.getName());
  +        assertEquals(m_3.getDepartment(), new_m.getDepartment());
  +
  +        tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        database.deletePersistent(m_3);
  +        tx.commit();
  +    }
  +
       public void testQuery_2() throws Exception
       {
           if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple
joined tables only" +
  @@ -483,6 +621,7 @@
           long timestamp = System.currentTimeMillis();
           Long id_2 = new Long(timestamp);
           String name = "testInsert" + timestamp;
  +
           Employee em1 = new Employee(id_2, name);
           Executive ex1 = new Executive(id_2, name, "department_1", null);
           Executive ex2 = new Executive(id_2, name, "department_2", null);
  @@ -491,6 +630,8 @@
           list.add(ex2);
           Manager m1 = new Manager(id_2, name);
           m1.setExecutives(list);
  +        ex1.setManager(m1);
  +        ex2.setManager(m1);
   
           TransactionExt tx = (TransactionExt) odmg.newTransaction();
           tx.begin();
  @@ -499,9 +640,9 @@
           tx.commit();
   
           tx.begin();
  -        Identity m1_oid = new Identity(m1, tx.getBroker());
  -        Identity ex1_oid = new Identity(ex1, tx.getBroker());
  -        Identity em1_oid = new Identity(em1, tx.getBroker());
  +        Identity m1_oid = tx.getBroker().serviceIdentity().buildIdentity(m1);
  +        Identity ex1_oid = tx.getBroker().serviceIdentity().buildIdentity(ex1);
  +        Identity em1_oid = tx.getBroker().serviceIdentity().buildIdentity(em1);
   
           tx.getBroker().clearCache();
   
  @@ -564,9 +705,9 @@
           tx.commit();
   
           tx.begin();
  -        Identity m1_oid = new Identity(m1, tx.getBroker());
  -        Identity ex1_oid = new Identity(ex1, tx.getBroker());
  -        Identity em1_oid = new Identity(em1, tx.getBroker());
  +        Identity m1_oid = tx.getBroker().serviceIdentity().buildIdentity(m1);
  +        Identity ex1_oid = tx.getBroker().serviceIdentity().buildIdentity(ex1);
  +        Identity em1_oid = tx.getBroker().serviceIdentity().buildIdentity(em1);
   
           tx.getBroker().clearCache();
   
  @@ -581,11 +722,11 @@
           tx.lock(newEm1, Transaction.WRITE);
           tx.lock(newEx1, Transaction.WRITE);
           tx.lock(newM1, Transaction.WRITE);
  -        newEm1.setName("**updated_" + name);
  -        newM1.setName("**updated_" + name);
  +        newEm1.setName("**updated_employee_" + name);
  +        newM1.setName("**updated_manager1_" + name);
           newM1.setDepartment("**new");
  -        ((Executive) newM1.getExecutives().get(0)).setName("**updated_" + name);
  -        ((Executive) newM1.getExecutives().get(1)).setName("**updated_" + name);
  +        ((Executive) newM1.getExecutives().get(0)).setName("**updated_executive1_" + name);
  +        ((Executive) newM1.getExecutives().get(1)).setName("**updated_executive2_" + name);
           tx.commit();
   
           //*************************************
  @@ -598,7 +739,6 @@
           //*************************************
   
           assertEquals(newEm1, em1);
  -        assertEquals(newEx1, ex1);
           assertEquals(newM1, m1);
           assertEquals(2, m1.getExecutives().size());
       }
  @@ -628,9 +768,9 @@
           tx.commit();
   
           tx.begin();
  -        Identity m1_oid = new Identity(m1, tx.getBroker());
  -        Identity ex1_oid = new Identity(ex1, tx.getBroker());
  -        Identity em1_oid = new Identity(em1, tx.getBroker());
  +        Identity m1_oid = tx.getBroker().serviceIdentity().buildIdentity(m1);
  +        Identity ex1_oid = tx.getBroker().serviceIdentity().buildIdentity(ex1);
  +        Identity em1_oid = tx.getBroker().serviceIdentity().buildIdentity(em1);
   
           tx.getBroker().clearCache();
   
  @@ -668,7 +808,7 @@
       //************************************************************
       public static class Manager extends Executive
       {
  -        private List executives;
  +        private List executives = new ArrayList();
   
           public Manager()
           {
  @@ -679,6 +819,17 @@
               super(id_2, name, null, null);
           }
   
  +        public boolean equals(Object obj)
  +        {
  +            if (!(obj instanceof Manager))
  +            {
  +                return false;
  +            }
  +            Manager other = (Manager) obj;
  +            return new EqualsBuilder().append(getExecutives(), other.getExecutives())
  +                    .isEquals() && super.equals(obj);
  +        }
  +
           public List getExecutives()
           {
               return executives;
  @@ -733,9 +884,12 @@
                   return false;
               }
               Executive ex = (Executive) obj;
  -            return new EqualsBuilder().append(getId(), ex.getId())
  -                    .append(getName(), ex.getName())
  -                    .append(getDepartment(), ex.getDepartment()).isEquals();
  +            return new EqualsBuilder()
  +                    // avoid endless loop with Manager 1:n relation
  +                    .append((getManager() != null ? getManager().getId(): null), (ex.getManager()
!= null ? ex.getManager().getId() : null))
  +                    .append((getManager() != null ? getManager().getId_2(): null), (ex.getManager()
!= null ? ex.getManager().getId_2() : null))
  +                    .append(getDepartment(), ex.getDepartment())
  +                    .isEquals() && super.equals(obj);
           }
       }
   
  @@ -745,6 +899,8 @@
           private Long id_2;
           private String name;
           private AddressIF address;
  +        private List oldAddresses = new ArrayList();
  +        private List carrels = new ArrayList();
   
           public Employee()
           {
  @@ -776,6 +932,16 @@
               this.id = id;
           }
   
  +        public void addOldAddress(AddressIF address)
  +        {
  +            if(oldAddresses == null)
  +            {
  +                oldAddresses = new ArrayList();
  +            }
  +            oldAddresses.add(address);
  +        }
  +
  +
           public AddressIF getAddress()
           {
               return address;
  @@ -796,6 +962,35 @@
               this.name = name;
           }
   
  +        public List getOldAddresses()
  +        {
  +            return oldAddresses;
  +        }
  +
  +        public void setOldAddresses(List oldAddresses)
  +        {
  +            this.oldAddresses = oldAddresses;
  +        }
  +
  +        public void addCarrel(Address address)
  +        {
  +            if(carrels == null)
  +            {
  +                carrels = new ArrayList();
  +            }
  +            carrels.add(address);
  +        }
  +
  +        public List getCarrels()
  +        {
  +            return carrels;
  +        }
  +
  +        public void setCarrels(List carrels)
  +        {
  +            this.carrels = carrels;
  +        }
  +
           public boolean equals(Object obj)
           {
               if (!(obj instanceof Employee))
  @@ -807,6 +1002,10 @@
                       .append(getId(), em.getId())
                       .append(getId_2(), em.getId_2())
                       .append(getName(), em.getName())
  +                    // avoid endless loop with Address
  +                    .append((getAddress() != null ? getAddress().getId() : null), (em.getAddress()
!= null ? em.getAddress().getId() : null))
  +                    .append(getOldAddresses(), em.getOldAddresses())
  +                    .append(getCarrels(), em.getCarrels())
                       .isEquals();
           }
   
  @@ -820,6 +1019,9 @@
       {
           private Integer id;
           private String street;
  +        private List employees = new ArrayList();
  +        private Integer fkEmployee1;
  +        private Long fkEmployee2;
   
           public Address()
           {
  @@ -830,6 +1032,22 @@
               this.street = street;
           }
   
  +        public boolean equals(Object obj)
  +        {
  +            if (!(obj instanceof AddressIF))
  +            {
  +                return false;
  +            }
  +            AddressIF other = (AddressIF) obj;
  +            return new EqualsBuilder()
  +                    .append(getId(), other.getId())
  +                    .append(getStreet(), other.getStreet())
  +                    .append(getEmployees(), other.getEmployees())
  +                    .append(getFkEmployee1(), other.getFkEmployee1())
  +                    .append(getFkEmployee2(), other.getFkEmployee2())
  +                    .isEquals();
  +        }
  +
           public Integer getId()
           {
               return id;
  @@ -849,16 +1067,59 @@
           {
               this.street = street;
           }
  +
  +        public Integer getFkEmployee1()
  +        {
  +            return fkEmployee1;
  +        }
  +
  +        public void setFkEmployee1(Integer fkEmployee1)
  +        {
  +            this.fkEmployee1 = fkEmployee1;
  +        }
  +
  +        public Long getFkEmployee2()
  +        {
  +            return fkEmployee2;
  +        }
  +
  +        public void setFkEmployee2(Long fkEmployee2)
  +        {
  +            this.fkEmployee2 = fkEmployee2;
  +        }
  +
  +        public void addEmployee(Employee emp)
  +        {
  +            if(employees == null)
  +            {
  +                employees = new ArrayList();
  +            }
  +            employees.add(emp);
  +        }
  +
  +        public List getEmployees()
  +        {
  +            return employees;
  +        }
  +
  +        public void setEmployees(List employees)
  +        {
  +            this.employees = employees;
  +        }
       }
   
       public static interface AddressIF
       {
           public Integer getId();
  -
           public void setId(Integer id);
  -
           public String getStreet();
  -
           public void setStreet(String street);
  +
  +        public List getEmployees();
  +        public void setEmployees(List employees);
  +        public Integer getFkEmployee1();
  +        public void setFkEmployee1(Integer id);
  +        public Long getFkEmployee2();
  +        public void setFkEmployee2(Long id);
       }
   }
  
  
  
  No                   revision
  No                   revision
  1.13.2.13 +55 -2     db-ojb/src/test/org/apache/ojb/repository_junit_odmg.xml
  
  Index: repository_junit_odmg.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_odmg.xml,v
  retrieving revision 1.13.2.12
  retrieving revision 1.13.2.13
  diff -u -r1.13.2.12 -r1.13.2.13
  --- repository_junit_odmg.xml	9 May 2005 14:26:55 -0000	1.13.2.12
  +++ repository_junit_odmg.xml	10 May 2005 19:08:55 -0000	1.13.2.13
  @@ -1409,6 +1409,32 @@
           >
           <foreignkey field-ref="fkAddress"/>
       </reference-descriptor>
  +
  +    <collection-descriptor
  +        name="oldAddresses"
  +        element-class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Address"
  +        proxy="false"
  +        auto-retrieve="true"
  +        auto-update="none"
  +        auto-delete="none"
  +        >
  +        <inverse-foreignkey field-ref="fkEmployee1"/>
  +        <inverse-foreignkey field-ref="fkEmployee2"/>
  +    </collection-descriptor>
  +
  +    <collection-descriptor
  +        name="carrels"
  +        element-class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Address"
  +        indirection-table="INHERITANCE_EMPLOYEE_ADDRESS"
  +        proxy="false"
  +        auto-retrieve="true"
  +        auto-update="none"
  +        auto-delete="none"
  +        >
  +        <fk-pointing-to-this-class column="EMPLOYEE_ID_1"/>
  +        <fk-pointing-to-this-class column="EMPLOYEE_ID_2"/>
  +        <fk-pointing-to-element-class column="ADDRESS_ID"/>
  +    </collection-descriptor>
   </class-descriptor>
   
   <class-descriptor
  @@ -1494,7 +1520,7 @@
       <collection-descriptor
           name="executives"
           element-class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Executive"
  -        proxy="true"
  +        proxy="false"
           auto-retrieve="true"
           auto-update="none"
           auto-delete="none"
  @@ -1521,9 +1547,36 @@
           column="STREET"
           jdbc-type="VARCHAR"
           />
  +
  +    <field-descriptor
  +        name="fkEmployee1"
  +        column="FK_EMPLOYEE_1"
  +        jdbc-type="INTEGER"
  +        />
  +    <field-descriptor
  +        name="fkEmployee2"
  +        column="FK_EMPLOYEE_2"
  +        jdbc-type="BIGINT"
  +        />
  +
  +    <collection-descriptor
  +        name="employees"
  +        element-class-ref="org.apache.ojb.odmg.InheritanceMultipleTableTest$Employee"
  +        indirection-table="INHERITANCE_EMPLOYEE_ADDRESS"
  +        proxy="false"
  +        auto-retrieve="true"
  +        auto-update="none"
  +        auto-delete="none"
  +        >
  +        <fk-pointing-to-this-class column="ADDRESS_ID"/>
  +        <fk-pointing-to-element-class column="EMPLOYEE_ID_1"/>
  +        <fk-pointing-to-element-class column="EMPLOYEE_ID_2"/>
  +    </collection-descriptor>
   </class-descriptor>
   
   
  +
  +
   <class-descriptor
       class="org.apache.ojb.odmg.shared.Project"
       table="PROJECT"
  
  
  

---------------------------------------------------------------------
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