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 th...@apache.org on 2003/07/08 22:12:38 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata DescriptorRepository.java

thma        2003/07/08 13:12:38

  Modified:    src/java/org/apache/ojb/broker/metadata
                        DescriptorRepository.java
  Log:
  add Sott T. Weavers patch to support inheritance for ClassDesciptors. I think the same could be done for FieldDescriptors?
  
  Revision  Changes    Path
  1.36      +52 -2     db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
  
  Index: DescriptorRepository.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- DescriptorRepository.java	9 Apr 2003 20:28:47 -0000	1.35
  +++ DescriptorRepository.java	8 Jul 2003 20:12:38 -0000	1.36
  @@ -66,6 +66,7 @@
   
   import org.apache.commons.lang.SystemUtils;
   import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PersistenceBrokerException;
   
   /**
  @@ -298,7 +299,7 @@
        */
       public ClassDescriptor getDescriptorFor(String strClassName) throws ClassNotPersistenceCapableException
       {
  -        ClassDescriptor result = (ClassDescriptor) descriptorTable.get(strClassName);
  + 		ClassDescriptor result = discoverDescriptor(strClassName);
           if (result == null)
           {
               throw new ClassNotPersistenceCapableException(strClassName + " not found in OJB Repository");
  @@ -437,5 +438,54 @@
               return LITERAL_IL_OPTIMISTIC;
           }
           return LITERAL_IL_READ_UNCOMMITTED;
  +    }
  +    
  +    /**
  +       * Starts by looking to see if the <code>className</code> is
  +       * already mapped specifically to the descritpor repository.
  +       * If the <code>className</code> is not specifically mapped we
  +       * look at the <code>className</code>'s parent class for a mapping.
  +       * We do this until the parent class is of the type 
  +       * <code>java.lang.Object</code>.  If no mapping was found, 
  +       * <code>null</code> is returned.  Mappings successfuly discovered 
  +       * through inheritence are added to the internal table of
  +       * class descriptors to improve performance on subsequent requests  
  +       * for those classes.
  +       * 
  +       * @param className name of class whose descriptor we need to find.
  +       * @return ClassDescriptor for <code>className</code> or <code>null</code>
  +       * if no ClassDescriptor could be located.
  +       * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
  +       */
  +    protected ClassDescriptor discoverDescriptor(String className)
  +    {
  +        ClassDescriptor result = (ClassDescriptor) descriptorTable.get(className);
  +        if (result == null)
  +        {
  +            Class clazz;
  +            try
  +            {
  +                clazz = Class.forName(className);
  +            }
  +            catch (ClassNotFoundException e)
  +            {
  +                throw new OJBRuntimeException("Class, " + className + ", could not be found.", e);
  +            }
  +            Class superClass = clazz.getSuperclass();
  +            // only recurse if the superClass is a concrete object and it
  +            // is not a java.lang.Object. (boot strap condition)
  +            if (superClass != null)
  +            {
  +                result = discoverDescriptor(superClass.getName());
  +            }
  +        }
  +
  +        // record class descriptor mappings discovered by inheritence.
  +        if (result != null && !descriptorTable.containsKey(className))
  +        {
  +            descriptorTable.put(className, result);
  +        }
  +
  +        return result;
       }
   }
  
  
  

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