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:24 GMT
brj         2005/03/17 13:34:24

  Modified:    src/java/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        ClassDescriptor.java
  Log:
  fix for OJB 313: also lookup collectionDescriptors in 'super'
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.88.2.12 +74 -27    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.11
  retrieving revision 1.88.2.12
  diff -u -r1.88.2.11 -r1.88.2.12
  --- ClassDescriptor.java	11 Mar 2005 20:13:02 -0000	1.88.2.11
  +++ ClassDescriptor.java	17 Mar 2005 21:34:19 -0000	1.88.2.12
  @@ -258,6 +258,10 @@
       private Map m_fieldDescriptorNameMap = null;
       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;
   
       //-----------------------------------------------------------------
       //-----------------------------------------------------------------
  @@ -494,7 +498,7 @@
       }
   
       /**
  -     * Get an ObjectReferenceDescriptor by name	BRJ
  +     * Get an ObjectReferenceDescriptor by name BRJ
        * @param name
        * @return ObjectReferenceDescriptor or null
        */
  @@ -505,21 +509,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
  @@ -527,20 +518,35 @@
           //
           if (ord == null)
           {
  -            ObjectReferenceDescriptor superOrd = 
  -                (ObjectReferenceDescriptor) m_objectReferenceDescriptorsNameMap.get(AnonymousObjectReferenceDescriptor.ANONYMOUS_NAME);
  -            
  -            if (superOrd != null)
  +            ClassDescriptor superCld = getSuperClassDescriptor();
  +            if (superCld != null)
               {
  -                ClassDescriptor superCld = getRepository().getDescriptorFor(superOrd.getItemClass());
                   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
        */
  @@ -551,6 +557,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();
  @@ -559,16 +585,37 @@
               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 (CollectionDescriptor) m_collectionDescriptorNameMap.get(name);
  +        
  +        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(AnonymousObjectReferenceDescriptor.ANONYMOUS_NAME);
  +
  +            if (superOrd != null)
  +            {
  +                m_superCld = getRepository().getDescriptorFor(superOrd.getItemClass());
  +            }
  +
  +            m_superCldSet = true;
  +        }
  +
  +        return m_superCld;
  +    }
  +    
  +    /**
        * add an Extent class to the current descriptor
        * @param newExtendClass
        * @deprecated use {@link #addExtentClass(String newExtentClass)} instead
  
  
  

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