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/accesslayer RsIterator.java ChainingIterator.java
Date Thu, 23 Oct 2003 19:17:28 GMT
brj         2003/10/23 12:17:28

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/accesslayer RsIterator.java
                        ChainingIterator.java
  Log:
  prevent multiple selection of the same extent
  
  Revision  Changes    Path
  1.39      +20 -17    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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- PersistenceBrokerImpl.java	15 Oct 2003 15:41:10 -0000	1.38
  +++ PersistenceBrokerImpl.java	23 Oct 2003 19:17:27 -0000	1.39
  @@ -2410,11 +2410,10 @@
       private OJBIterator getRsIteratorFromQuery(Query query, ClassDescriptor cld, RsIteratorFactory
factory, HashMap retrievalTasks)
           throws PersistenceBrokerException
       {
  -        RsIterator it;
  -
           if (query instanceof QueryBySQL)
           {
               if(logger.isDebugEnabled()) logger.debug("Creating SQL-RsIterator for class
["+cld.getClassNameOfObject()+"]");
  +
               String sql = ((QueryBySQL) query).getSql();
               return factory.createRsIterator(sql, cld, this);
           }
  @@ -2423,15 +2422,15 @@
           {
               // no extents just use the plain vanilla RsIterator
               if(logger.isDebugEnabled()) logger.debug("Creating RsIterator for class ["+cld.getClassNameOfObject()+"]");
  -            it = factory.createRsIterator(query, cld, this);
  +
  +            RsIterator it = factory.createRsIterator(query, cld, this);
               it.setRetrievalTasks(retrievalTasks);
               return it;
           }
   
  -        OJBIterator iter = null;
  -        String lastUsedTable = cld.getFullTableName();
           if(logger.isDebugEnabled()) logger.debug("Creating ChainingIterator for class ["+cld.getClassNameOfObject()+"]");
  -        iter = new ChainingIterator();
  +
  +        ChainingIterator chainingIter = new ChainingIterator();
           Vector extentClasses = cld.getExtentClasses();
           Class ec = null;
   
  @@ -2439,9 +2438,10 @@
           if (!cld.isInterface())
           {
               if(logger.isDebugEnabled()) logger.debug("Adding RsIterator for class ["+cld.getClassNameOfObject()+"]
to ChainingIterator");
  -            it = factory.createRsIterator(query, cld, this);
  +
  +            RsIterator it = factory.createRsIterator(query, cld, this);
               it.setRetrievalTasks(retrievalTasks);
  -            ((ChainingIterator) iter).addIterator(it);
  +            chainingIter.addIterator(it);
           }
   
           for (int i = 0; i < extentClasses.size(); i++)
  @@ -2450,19 +2450,22 @@
               cld = getClassDescriptor(ec);
   
               // read same table only once
  -            if (!cld.isInterface() && cld.getFullTableName().equals(lastUsedTable))
  +            if (!cld.isInterface() && chainingIter.containsIteratorForTable(cld.getFullTableName()))
               {
                   if(logger.isDebugEnabled()) logger.debug("Skipping class ["+cld.getClassNameOfObject()+"]");
  -                continue;
               }
  -            lastUsedTable = cld.getFullTableName();
  -
  -            // add the iterator to the chaining iterator.
  -            // BRJ: look for multilevel hierarchies
  -            if(logger.isDebugEnabled()) logger.debug("Adding RsIterator of class ["+ec+"]
to ChainingIterator");
  -            ((ChainingIterator) iter).addIterator(getRsIteratorFromQuery(query, cld, factory,
retrievalTasks));
  +            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, retrievalTasks);
  +                chainingIter.addIterator(it);
  +            }
           }
  -        return iter;
  +        
  +        return chainingIter;
       }
   
   
  
  
  
  1.44      +15 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- RsIterator.java	31 Aug 2003 00:15:03 -0000	1.43
  +++ RsIterator.java	23 Oct 2003 19:17:28 -0000	1.44
  @@ -732,5 +732,19 @@
       {
           releaseDbResources();
       }
  +    
  +    public String toString()
  +    {
  +        return super.toString() + "\n" + m_cld.toString();
  +    }
  +    
  +    /**
  +     * @return Returns the cld.
  +     */
  +    public ClassDescriptor getClassDescriptor()
  +    {
  +        return m_cld;
  +    }
  +
   }
   
  
  
  
  1.7       +35 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/ChainingIterator.java
  
  Index: ChainingIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ChainingIterator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ChainingIterator.java	14 Oct 2002 18:17:48 -0000	1.6
  +++ ChainingIterator.java	23 Oct 2003 19:17:28 -0000	1.7
  @@ -57,6 +57,7 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  +
   import org.apache.ojb.broker.PersistenceBrokerException;
   
   
  @@ -396,4 +397,37 @@
       	
       	return retval;
       }
  +    
  +    /**
  +     * Answer true if an Iterator for a Table is already available
  +     * @param aTable
  +     * @return
  +     */
  +    public boolean containsIteratorForTable(String aTable)
  +    {
  +        boolean result = false;
  +        
  +        if (m_rsIterators != null)
  +        {
  +            for (int i=0; i < m_rsIterators.size(); i++)
  +            {
  +                OJBIterator it = (OJBIterator)m_rsIterators.get(i);
  +                if (it instanceof RsIterator)
  +                {
  +                    if (((RsIterator)it).getClassDescriptor().getFullTableName().equals(aTable))
  +                    {
  +                        result = true;
  +                        break;
  +                    }
  +                }
  +                else if (it instanceof ChainingIterator)
  +                {
  +                    result = ((ChainingIterator)it).containsIteratorForTable(aTable); 
  +                }
  +            }
  +        }
  +        
  +        return result;
  +    }
  +    
   }
  
  
  

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