db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata ClassDescriptor.java
Date Thu, 17 Mar 2005 21:34:53 GMT
brj         2005/03/17 13:34:53

  Modified:    src/java/org/apache/ojb/broker/metadata ClassDescriptor.java
  Log:
  fix for OJB 313: also lookup collectionDescriptors in 'super'
  
  Revision  Changes    Path
  1.103     +73 -26    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.102
  retrieving revision 1.103
  diff -u -r1.102 -r1.103
  --- ClassDescriptor.java	11 Mar 2005 20:50:13 -0000	1.102
  +++ ClassDescriptor.java	17 Mar 2005 21:34:53 -0000	1.103
  @@ -232,6 +232,10 @@
       private Map m_collectionDescriptorNameMap = null;
       private Map m_objectReferenceDescriptorsNameMap = null;
   
  +    // BRJ: ClassDescriptor referenced by 'super' ObjectReferenceDescriptor
  +    private ClassDescriptor m_superCld = null;
  +    private boolean m_superCldSet = false;
  +
       //-----------------------------------------------------------------
       //-----------------------------------------------------------------
       // END of cached metadata information
  @@ -430,7 +434,7 @@
       }
   
       /**
  -     * Get an ObjectReferenceDescriptor by name	BRJ
  +     * Get an ObjectReferenceDescriptor by name BRJ
        * @param name
        * @return ObjectReferenceDescriptor or null
        */
  @@ -441,21 +445,8 @@
               return null;
           }
   
  -        if (m_objectReferenceDescriptorsNameMap == null)
  -        {
  -            HashMap nameMap = new HashMap();
  -
  -            Vector descriptors = getObjectReferenceDescriptors();
  -            for (int i = descriptors.size() - 1; i >= 0; i--)
  -            {
  -                ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) descriptors.get(i);
  -                nameMap.put(ord.getPersistentField().getName(), ord);
  -            }
  -
  -            m_objectReferenceDescriptorsNameMap = nameMap;
  -        }
  -
  -        ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) m_objectReferenceDescriptorsNameMap.get(name);
  +        ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) 
  +            getObjectReferenceDescriptorsNameMap().get(name);
           
           // 
           // BRJ: if the ReferenceDescriptor is not found
  @@ -463,20 +454,35 @@
           //
           if (ord == null)
           {
  -            ObjectReferenceDescriptor superOrd = 
  -                (ObjectReferenceDescriptor) m_objectReferenceDescriptorsNameMap.get(ObjectReferenceDescriptor.ANONYMOUS_NAME);
  -            
  -            if (superOrd != null)
  +            ClassDescriptor superCld = getSuperClassDescriptor();
  +            if (superCld != null)
               {
  -                ClassDescriptor superCld = superOrd.getItemClassDescriptor();
                   ord = superCld.getObjectReferenceDescriptorByName(name);
               }
           }
           return ord;
       }
   
  +    private Map getObjectReferenceDescriptorsNameMap()
  +    {
  +        if (m_objectReferenceDescriptorsNameMap == null)
  +        {
  +            HashMap nameMap = new HashMap();
  +
  +            Vector descriptors = getObjectReferenceDescriptors();
  +            for (int i = descriptors.size() - 1; i >= 0; i--)
  +            {
  +                ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) descriptors.get(i);
  +                nameMap.put(ord.getAttributeName(), ord);
  +            }
  +            m_objectReferenceDescriptorsNameMap = nameMap;
  +        }
  +
  +        return m_objectReferenceDescriptorsNameMap;
  +    }
  +    
       /**
  -     * Get an CollectionDescriptor by name	BRJ
  +     * Get an CollectionDescriptor by name  BRJ
        * @param name
        * @return CollectionDescriptor or null
        */
  @@ -487,6 +493,26 @@
               return null;
           }
   
  +        CollectionDescriptor cod  = (CollectionDescriptor) getCollectionDescriptorNameMap().get(name);
  +
  +        // 
  +        // BRJ: if the CollectionDescriptor is not found
  +        // look in the ClassDescriptor referenced by 'super' for it
  +        //
  +        if (cod == null)
  +        {
  +            ClassDescriptor superCld = getSuperClassDescriptor();
  +            if (superCld != null)
  +            {
  +                cod = superCld.getCollectionDescriptorByName(name);
  +            }
  +        }
  +
  +        return cod;
  +    }
  +
  +    private Map getCollectionDescriptorNameMap()
  +    {
           if (m_collectionDescriptorNameMap == null)
           {
               HashMap nameMap = new HashMap();
  @@ -495,13 +521,34 @@
               for (int i = descriptors.size() - 1; i >= 0; i--)
               {
                   CollectionDescriptor cod = (CollectionDescriptor) descriptors.get(i);
  -                nameMap.put(cod.getPersistentField().getName(), cod);
  +                nameMap.put(cod.getAttributeName(), cod);
               }
  -
               m_collectionDescriptorNameMap = nameMap;
           }
  +        
  +        return m_collectionDescriptorNameMap;
  +    }
  +
  +    /**
  +     * Answers the ClassDescriptor referenced by 'super' ObjectReferenceDescriptor.
  +     * @return ClassDescriptor or null
  +     */
  +    private ClassDescriptor getSuperClassDescriptor()
  +    {
  +        if (!m_superCldSet)
  +        {
  +            ObjectReferenceDescriptor superOrd = (ObjectReferenceDescriptor) getObjectReferenceDescriptorsNameMap()
  +                    .get(ObjectReferenceDescriptor.ANONYMOUS_NAME);
  +
  +            if (superOrd != null)
  +            {
  +                m_superCld = getRepository().getDescriptorFor(superOrd.getItemClass());
  +            }
  +
  +            m_superCldSet = true;
  +        }
   
  -        return (CollectionDescriptor) m_collectionDescriptorNameMap.get(name);
  +        return m_superCld;
       }
   
       /**
  
  
  

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