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 br...@apache.org on 2003/11/01 21:45:12 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/core PersistenceBrokerImpl.java

brj         2003/11/01 12:45:12

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
  Log:
  refactoring using new method getAllConcreteExtentClasses of ClassDescriptor
  
  Revision  Changes    Path
  1.43      +31 -82    db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- PersistenceBrokerImpl.java	31 Oct 2003 09:40:55 -0000	1.42
  +++ PersistenceBrokerImpl.java	1 Nov 2003 20:45:12 -0000	1.43
  @@ -1758,25 +1758,33 @@
           {
               // 1. try to retrieve skalar fields from directly mapped table columns
               newObj = dbAccess.materializeObject(cld, oid);
  -
  -            if (newObj != null && oid.getObjectsRealClass() == null)
  -            {
  -                cld = descriptorRepository.getDescriptorFor(newObj.getClass());
  -                oid.setObjectsRealClass(newObj.getClass());
  -            }
  -
           }
   
           // if we did not find the object yet AND if the cld represents an Extent,
           // we can lookup all tables of the extent classes:
           if (newObj == null && cld.isExtent())
           {
  -            newObj = getExtentDBObject(oid, cld);
  +            Iterator extents = cld.getAllConcreteExtentClasses().iterator();
  +            
  +            while (extents.hasNext())
  +            {
  +                ClassDescriptor extCld = getClassDescriptor((Class)extents.next());
  +                newObj = dbAccess.materializeObject(extCld, oid);
  +                if (newObj != null)
  +                {
  +                    break;
  +                }
  +            }            
           }
   
           // loading references is useful only when the Object could be found in db:
           if (newObj != null)
           {
  +            if (oid.getObjectsRealClass() == null)
  +            {
  +                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
  @@ -1785,12 +1793,8 @@
               {
                   // cache object immediately , so that references
                   // can be established from referenced Objects back to this Object
  +                
                   objectCache.cache(oid, newObj);
  -                /*
  -                arminw:
  -                LoadedOnjectsRegistry moved to odmg-layer
  -                */
  -                // LoadedObjectsRegistry.register(newObj);
   
                   /*
                    * Chris Lewington: can cause problems with multiple objects
  @@ -1805,7 +1809,7 @@
                    * To be safe, get the descriptor of the retrieved object
                    * BEFORE resolving refs
                    */
  -                ClassDescriptor newObjCld = descriptorRepository.getDescriptorFor(newObj.getClass());
  +                ClassDescriptor newObjCld = getClassDescriptor(newObj.getClass());
                   // don't force loading of references:
                   final boolean unforced = false;
   
  @@ -1820,59 +1824,6 @@
       }
   
       /**
  -     * Method to work down the class hierarchy until a concrete object is found.
  -     * Used mainly by getDBObject. by Chris Lewington
  -     *
  -     * @param oid - OID of the object to check
  -     * @param cld - the Class Descriptor of the class to be checked
  -     * (will be either an interface or abstract class)
  -     * @return Object - the concrete object found,
  -     * or null if none are found
  -     */
  -    private Object getExtentDBObject(Identity oid, ClassDescriptor cld)
  -    {
  -        Object newObj = null;
  -        Vector extentClasses = new Vector();
  -
  -        //detailed debug info...
  -        if (logger.isDebugEnabled())
  -        {
  -            logger.debug("getExtentDBObject called....");
  -            logger.debug("class: " + cld.getClassOfObject().getName());
  -            logger.debug("object ID: " + oid.toString());
  -            logger.debug("class " + cld.getClassOfObject().getName() + " is abstract -getting subclasses...");
  -        }
  -        extentClasses = cld.getExtentClasses();
  -
  -        // search the subclasses (recurse if necessary via getDBObject)
  -        // until we find a concrete match
  -        for (int i = 0; i < extentClasses.size(); i++)
  -        {
  -            //make sure the class descriptor we finish with matches a
  -            //subclass, not the abstract one..
  -            cld = descriptorRepository.getDescriptorFor((Class) extentClasses.get(i));
  -            logger.debug("subclass: " + cld.getClassOfObject().getName());
  -
  -            //try and get an object - set the OID class to be the extent
  -            //class and search again..
  -            oid.setObjectsRealClass(cld.getClassOfObject());
  -            newObj = getDBObject(oid);
  -
  -            if (newObj != null)
  -            {
  -                if (oid.getObjectsRealClass() == null)
  -                {
  -                    oid.setObjectsRealClass(newObj.getClass());
  -                }
  -                //done so jump out
  -                break;
  -            }
  -        }
  -
  -        return newObj;
  -    }
  -
  -    /**
        * returns an Iterator that iterates Objects of class c if calling the .next()
        * method. The Elements returned come from a SELECT ... WHERE Statement
        * that is defined by the Query query.
  @@ -2553,42 +2504,40 @@
               // no extents just use the plain vanilla RsIterator
               if(logger.isDebugEnabled()) logger.debug("Creating RsIterator for class ["+cld.getClassNameOfObject()+"]");
   
  -            RsIterator it = factory.createRsIterator(query, cld, this);
  -            return it;
  +            return factory.createRsIterator(query, cld, this);
           }
   
  +        
           if(logger.isDebugEnabled()) logger.debug("Creating ChainingIterator for class ["+cld.getClassNameOfObject()+"]");
   
           ChainingIterator chainingIter = new ChainingIterator();
  -        Vector extentClasses = cld.getExtentClasses();
  -        Class ec = null;
   
           // BRJ: add base class iterator
           if (!cld.isInterface())
           {
               if(logger.isDebugEnabled()) logger.debug("Adding RsIterator for class ["+cld.getClassNameOfObject()+"] to ChainingIterator");
  -            RsIterator it = factory.createRsIterator(query, cld, this);
  -            chainingIter.addIterator(it);
  +
  +            chainingIter.addIterator(factory.createRsIterator(query, cld, this));
           }
   
  -        for (int i = 0; i < extentClasses.size(); i++)
  +        Iterator extentClasses = cld.getAllConcreteExtentClasses().iterator();
  +
  +        while (extentClasses.hasNext())
           {
  -            ec = (Class) extentClasses.get(i);
  -            cld = getClassDescriptor(ec);
  +            Class ec = (Class) extentClasses.next();
  +            ClassDescriptor extCld = getClassDescriptor(ec);
   
               // read same table only once
  -            if (!cld.isInterface() && chainingIter.containsIteratorForTable(cld.getFullTableName()))
  +            if (chainingIter.containsIteratorForTable(extCld.getFullTableName()))
               {
  -                if(logger.isDebugEnabled()) logger.debug("Skipping class ["+cld.getClassNameOfObject()+"]");
  +                if(logger.isDebugEnabled()) logger.debug("Skipping class ["+extCld.getClassNameOfObject()+"]");
               }
               else
               {    
                   if(logger.isDebugEnabled()) logger.debug("Adding RsIterator of class ["+ec+"] to ChainingIterator");
   
                   // add the iterator to the chaining iterator.
  -                // BRJ: look for multilevel hierarchies
  -                OJBIterator it = getRsIteratorFromQuery(query, cld, factory);
  -                chainingIter.addIterator(it);
  +                chainingIter.addIterator(factory.createRsIterator(query, extCld, this));
               }
           }
           
  
  
  

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