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/23 10:29:27 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer SqlBasedRsIterator.java RsIterator.java

brj         2003/11/23 01:29:27

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        SqlBasedRsIterator.java RsIterator.java
  Log:
  fixed countedSize()
  
  Revision  Changes    Path
  1.20      +1 -47     db-ojb/src/java/org/apache/ojb/broker/accesslayer/SqlBasedRsIterator.java
  
  Index: SqlBasedRsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/SqlBasedRsIterator.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SqlBasedRsIterator.java	14 Nov 2003 18:16:46 -0000	1.19
  +++ SqlBasedRsIterator.java	23 Nov 2003 09:29:27 -0000	1.20
  @@ -57,9 +57,6 @@
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.core.PersistenceBrokerImpl;
  -import org.apache.ojb.broker.query.Query;
  -
  -import java.sql.SQLException;
   
   /**
    * RsIterator based on SQL-Statement
  @@ -104,48 +101,5 @@
               return m_broker.getObjectByIdentity(oid);
           }
   
  -    }
  -
  -    /**
  -     * Answer the counted size
  -     * @return int
  -     */
  -    protected int countedSize() throws PersistenceBrokerException
  -    {
  -        String countSql = "";
  -        ResultSetAndStatement rsStmt;
  -        int count = 0;
  -
  -        int fromPos = queryObject.getSQLBasedQuery().toUpperCase().indexOf(" FROM ");
  -        if (fromPos >= 0)
  -        {
  -            countSql = "select count(*)" + queryObject.getSQLBasedQuery().substring(fromPos);
  -        }
  -
  -        // BRJ: cut before ORDER BY
  -        int orderPos = countSql.toUpperCase().indexOf(" ORDER BY ");
  -        if (orderPos >= 0)
  -        {
  -            countSql = countSql.substring(0, orderPos);
  -        }
  -
  -        rsStmt = m_broker.serviceJdbcAccess().executeSQL(
  -                countSql, queryObject.getClassDescriptor(), Query.NOT_SCROLLABLE);
  -        try
  -        {
  -            if (rsStmt.m_rs.next())
  -            {
  -                count = rsStmt.m_rs.getInt(1);
  -            }
  -        }
  -        catch (SQLException e)
  -        {
  -            throw new PersistenceBrokerException(e);
  -        }
  -        finally
  -        {
  -            rsStmt.close();
  -        }
  -        return count;
       }
   }
  
  
  
  1.48      +219 -240  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.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- RsIterator.java	14 Nov 2003 18:16:46 -0000	1.47
  +++ RsIterator.java	23 Nov 2003 09:29:27 -0000	1.48
  @@ -1,57 +1,46 @@
   package org.apache.ojb.broker.accesslayer;
   
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  +/*
  + * ==================================================================== The
  + * Apache Software License, Version 1.1
  + * 
  + * Copyright (c) 2001 The Apache Software Foundation. All rights reserved.
  + * 
    * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowledgment may appear in the software itself,
  - *    if and wherever such third-party acknowledgments normally appear.
  - *
  - * 4. The names "Apache" and "Apache Software Foundation" and
  - *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
  - *    prior written permission of the Apache Software Foundation.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  + * modification, are permitted provided that the following conditions are met:
  + *  1. Redistributions of source code must retain the above copyright notice,
  + * this list of conditions and the following disclaimer.
  + *  2. Redistributions in binary form must reproduce the above copyright
  + * notice, this list of conditions and the following disclaimer in the
  + * documentation and/or other materials provided with the distribution.
  + *  3. The end-user documentation included with the redistribution, if any,
  + * must include the following acknowledgment: "This product includes software
  + * developed by the Apache Software Foundation (http://www.apache.org/)."
  + * Alternately, this acknowledgment may appear in the software itself, if and
  + * wherever such third-party acknowledgments normally appear.
  + *  4. The names "Apache" and "Apache Software Foundation" and "Apache
  + * ObjectRelationalBridge" must not be used to endorse or promote products
  + * derived from this software without prior written permission. For written
  + * permission, please contact apache@apache.org.
  + *  5. Products derived from this software may not be called "Apache", "Apache
  + * ObjectRelationalBridge", nor may "Apache" appear in their name, without
  + * prior written permission of the Apache Software Foundation.
  + * 
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  + * 
  + * This software consists of voluntary contributions made by many individuals
  + * on behalf of the Apache Software Foundation. For more information on the
  + * Apache Software Foundation, please see <http://www.apache.org/> .
    */
   
   import org.apache.ojb.broker.Identity;
  @@ -80,20 +69,18 @@
   
   /**
    * RsIterator can be used to iterate over a jdbc ResultSet to retrieve
  - * persistent objects step-by-step and not all at once.
  - * In fact the PersistenceBroker::getCollectionByQuery(...) method
  - * uses a RsIterator internally to build up a Collection of objects
  - *
  - * NOTE: this code uses features that only JDBC 2.0 compliant Drivers
  - * support. It will NOT work with JDBC 1.0 Drivers (e.g. SUN's JdbcOdbcDriver)
  - * If you are forced to use such a driver, you can use code from
  - * the 0.1.30 release.
  - *
  - * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
  - * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
  - * 			- added the support for extents mapped to single table
  - * 			- added the .size functionality
  - * 			- added cursor control
  + * persistent objects step-by-step and not all at once. In fact the
  + * PersistenceBroker::getCollectionByQuery(...) method uses a RsIterator
  + * internally to build up a Collection of objects
  + * 
  + * NOTE: this code uses features that only JDBC 2.0 compliant Drivers support.
  + * It will NOT work with JDBC 1.0 Drivers (e.g. SUN's JdbcOdbcDriver) If you
  + * are forced to use such a driver, you can use code from the 0.1.30 release.
  + * 
  + * @author <a href="mailto:thma@apache.org">Thomas Mahler <a>
  + * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird <a>- added the
  + *         support for extents mapped to single table - added the .size
  + *         functionality - added cursor control
    * @version $Id$
    */
   public class RsIterator implements OJBIterator
  @@ -101,77 +88,77 @@
       protected Logger logger = LoggerFactory.getLogger(this.getClass());
   
       /*
  -    arminw:
  -    to improve performance we only use this instance to fire events
  -    and set the target object on every use
  -    TODO: Find a better solution
  -    */
  +	 * arminw: to improve performance we only use this instance to fire events
  +	 * and set the target object on every use TODO: Find a better solution
  +	 */
       protected PBLifeCycleEvent afterLookupEvent;
   
       protected ObjectCache cache;
   
       /**
  -     * reference to the PersistenceBroker
  -     */
  +	 * reference to the PersistenceBroker
  +	 */
       protected PersistenceBrokerImpl m_broker;
   
       /**
  -     * the underlying resultset
  -     */
  +	 * the underlying resultset
  +	 */
       protected ResultSetAndStatement m_rsAndStmt;
   
       /**
  -     * the underlying query object
  -     */
  +	 * the underlying query object
  +	 */
       protected org.apache.ojb.broker.accesslayer.RsQueryObject queryObject;
   
       /**
  -     * the proxy class to be used or null
  -     */
  +	 * the proxy class to be used or null
  +	 */
       protected Class itemProxyClass;
   
       /**
  -     * the top-level class of the item objects
  -     */
  +	 * the top-level class of the item objects
  +	 */
       private Class itemTopLevelClass = null;
   
       /**
  -     * this container holds the values of the current ro during materialisation
  -     */
  +	 * this container holds the values of the current ro during materialisation
  +	 */
       protected Map m_row = null;
   
       /**
  -     * flag that indicates wether hasNext on m_rs has allready been called
  -     */
  +	 * flag that indicates wether hasNext on m_rs has allready been called
  +	 */
       protected boolean hasCalledCheck = false;
   
       /**
  -     * prefetch relationship:
  -     * inBatchedMode true prevents releasing of DbResources
  -     * IN_LIMIT defines the max number of values of sql (IN) , -1 for no limits
  -     */
  +	 * prefetch relationship: inBatchedMode true prevents releasing of
  +	 * DbResources IN_LIMIT defines the max number of values of sql (IN) , -1
  +	 * for no limits
  +	 */
       protected boolean inBatchedMode = false;
   
       /**
  -     * return value of the previously called hasNext from m_rs
  -     */
  +	 * return value of the previously called hasNext from m_rs
  +	 */
       protected boolean hasNext = false;
   
       private boolean advancedJDBCSupport = false;
       private boolean JDBCSupportAssessed = false;
       private int m_current_row = 0;
       /**
  -     * Tracks whether or not the resources that are used by this
  -     * class have been released.
  -     */
  +	 * Tracks whether or not the resources that are used by this class have
  +	 * been released.
  +	 */
       private boolean resourcesAreReleased = false;
   
       /**
  -     * RsIterator constructor.
  -     *
  -     * @param queryObject query object
  -     * @param broker the broker we should use.
  -     */
  +	 * RsIterator constructor.
  +	 * 
  +	 * @param queryObject
  +	 *            query object
  +	 * @param broker
  +	 *            the broker we should use.
  +	 */
       public RsIterator(RsQueryObject queryObject, PersistenceBrokerImpl broker)
       {
           cache = broker.serviceObjectCache();
  @@ -180,8 +167,7 @@
           this.queryObject = queryObject;
   
           Class classToPrefetch = broker.getClassToPrefetch();
  -        if ((classToPrefetch != null)
  -                && classToPrefetch.isAssignableFrom(queryObject.getClassDescriptor().getClassOfObject()))
  +        if ((classToPrefetch != null) && classToPrefetch.isAssignableFrom(queryObject.getClassDescriptor().getClassOfObject()))
           {
               itemProxyClass = null;
           }
  @@ -191,19 +177,17 @@
           }
   
           /*
  -        arminw:
  -        to improve performance we only use this instance to fire events
  -        and set the target object on every use
  -        TODO: Find a better solution
  -        */
  +		 * arminw: to improve performance we only use this instance to fire
  +		 * events and set the target object on every use TODO: Find a better
  +		 * solution
  +		 */
           afterLookupEvent = new PBLifeCycleEvent(m_broker, PBLifeCycleEvent.Type.AFTER_LOOKUP);
   
           m_rsAndStmt = queryObject.performQuery(broker.serviceJdbcAccess());
           /*
  -        TODO:
  -        how does prefetchRelationships handle QueryBySQL instances?
  -        Is it ok to pass query object?
  -        */
  +		 * TODO: how does prefetchRelationships handle QueryBySQL instances? Is
  +		 * it ok to pass query object?
  +		 */
           prefetchRelationships(queryObject.getQuery());
           if (logger.isDebugEnabled())
           {
  @@ -221,9 +205,9 @@
       }
   
       /**
  -     * returns true if there are still more rows in the underlying ResultSet.
  -     * Returns false if ResultSet is exhausted.
  -     */
  +	 * returns true if there are still more rows in the underlying ResultSet.
  +	 * Returns false if ResultSet is exhausted.
  +	 */
       public synchronized boolean hasNext()
       {
           try
  @@ -242,14 +226,15 @@
           {
               hasNext = false;
           }
  -        if (logger.isDebugEnabled()) logger.debug("hasNext() -> " + hasNext);
  +        if (logger.isDebugEnabled())
  +            logger.debug("hasNext() -> " + hasNext);
           return hasNext;
       }
   
       /**
  -     * moves to the next row of the underlying ResultSet and
  -     * returns the corresponding Object materialized from this row.
  -     */
  +	 * moves to the next row of the underlying ResultSet and returns the
  +	 * corresponding Object materialized from this row.
  +	 */
       public synchronized Object next() throws NoSuchElementException
       {
           try
  @@ -264,7 +249,8 @@
                   Object obj = getObjectFromResultSet();
                   m_current_row++;
   
  -                // Invoke events on PersistenceBrokerAware instances and listeners
  +                // Invoke events on PersistenceBrokerAware instances and
  +				// listeners
                   // set target object
                   afterLookupEvent.setTarget(obj);
                   m_broker.fireBrokerEvent(afterLookupEvent);
  @@ -283,16 +269,16 @@
       }
   
       /**
  -     * removing is not supported
  -     */
  +	 * removing is not supported
  +	 */
       public void remove()
       {
           throw new UnsupportedOperationException("removing not supported by RsIterator");
       }
   
       /**
  -     * read all objects of this iterator. objects will be placed in cache
  -     */
  +	 * read all objects of this iterator. objects will be placed in cache
  +	 */
       private Collection getOwnerObjects()
       {
           Collection owners = new Vector();
  @@ -304,9 +290,9 @@
       }
   
       /**
  -     * prefetch defined relationships
  -     * requires JDBC level 2.0, does not work with Arrays
  -     */
  +	 * prefetch defined relationships requires JDBC level 2.0, does not work
  +	 * with Arrays
  +	 */
       private void prefetchRelationships(Query query)
       {
           List prefetchedRel;
  @@ -314,9 +300,7 @@
           String relName;
           RelationshipPrefetcher[] prefetchers;
   
  -        if (query == null ||
  -                query.getPrefetchedRelationships() == null ||
  -                query.getPrefetchedRelationships().isEmpty())
  +        if (query == null || query.getPrefetchedRelationships() == null || query.getPrefetchedRelationships().isEmpty())
           {
               return;
           }
  @@ -337,8 +321,8 @@
           for (int i = 0; i < prefetchedRel.size(); i++)
           {
               relName = (String) prefetchedRel.get(i);
  -            prefetchers[i] = RelationshipPrefetcherFactory.createRelationshipPrefetcher(
  -                    m_broker, queryObject.getClassDescriptor(), relName);
  +            prefetchers[i] =
  +                RelationshipPrefetcherFactory.createRelationshipPrefetcher(m_broker, queryObject.getClassDescriptor(), relName);
               prefetchers[i].prepareRelationshipSettings();
           }
   
  @@ -372,8 +356,8 @@
       }
   
       /**
  -     * returns an Identity object representing the current resultset row
  -     */
  +	 * returns an Identity object representing the current resultset row
  +	 */
       protected Identity getIdentityFromResultSet() throws PersistenceBrokerException
       {
           // fill primary key values from Resultset
  @@ -392,23 +376,22 @@
       }
   
       /**
  -     * returns a fully materialized Object from the current row of the
  -     * underlying resultset.
  -     * Works as follows:
  -     * - read Identity from the primary key values of current row
  -     * - check if Object is in cache
  -     * - return cached object or read it from current row and put it in cache
  -     */
  +	 * returns a fully materialized Object from the current row of the
  +	 * underlying resultset. Works as follows: - read Identity from the primary
  +	 * key values of current row - check if Object is in cache - return cached
  +	 * object or read it from current row and put it in cache
  +	 */
       protected Object getObjectFromResultSet() throws PersistenceBrokerException
       {
           /**
  -         * MBAIRD
  -         * if a proxy is to be used, return a proxy instance and dont perfom a full materialization.
  -         * NOTE: Potential problem here with multi-mapped table. The itemProxyClass is for the m_cld
  -         * classdescriptor. The object you are materializing might not be of that type, it could be
  -         * a subclass. We should get the concrete class type out of the resultset then check the proxy
  -         * from that. itemProxyClass should NOT be a member variable.
  -         */
  +		 * MBAIRD if a proxy is to be used, return a proxy instance and dont
  +		 * perfom a full materialization. NOTE: Potential problem here with
  +		 * multi-mapped table. The itemProxyClass is for the m_cld
  +		 * classdescriptor. The object you are materializing might not be of
  +		 * that type, it could be a subclass. We should get the concrete class
  +		 * type out of the resultset then check the proxy from that.
  +		 * itemProxyClass should NOT be a member variable.
  +		 */
   
           if (itemProxyClass != null)
           {
  @@ -432,29 +415,31 @@
               if (result == null)
               {
                   // 3. If Object is not in cache
  -                // materialize Object with primitive attributes filled from current row
  +                // materialize Object with primitive attributes filled from
  +				// current row
                   result = queryObject.getClassDescriptor().getRowReader().readObjectFrom(m_row);
                   // result may still be null!
                   if (result != null)
                   {
                       /*
  -                     * synchronize on result so the ODMG-layer can take a snapshot only of
  -                     * fully cached (i.e. with all references + collections) objects
  -                     */
  +					 * synchronize on result so the ODMG-layer can take a
  +					 * snapshot only of fully cached (i.e. with all references +
  +					 * collections) objects
  +					 */
                       synchronized (result)
                       {
                           cache.cache(oid, result);
                           /*
  -                        arminw:
  -                        move LoadedObjectsRegistry to odmg-layer
  -                        */
  +						 * arminw: move LoadedObjectsRegistry to odmg-layer
  +						 */
                           // LoadedObjectsRegistry.register(result);
                           /**
  -                         * MBAIRD
  -                         * if you have multiple classes mapped to a table, and you query on the base class
  -                         * you could get back NON base class objects, so we shouldn't pass m_cld, but rather
  -                         * the class descriptor for the actual class.
  -                         */
  +						 * MBAIRD if you have multiple classes mapped to a
  +						 * table, and you query on the base class you could get
  +						 * back NON base class objects, so we shouldn't pass
  +						 * m_cld, but rather the class descriptor for the
  +						 * actual class.
  +						 */
                           // fill reference and collection attributes
                           ClassDescriptor cld = queryObject.getClassDescriptor().getRepository().getDescriptorFor(result.getClass());
                           // don't force loading of reference
  @@ -466,12 +451,13 @@
                   }
               }
               else // Object is in cache
  -            {
  +                {
                   ClassDescriptor cld = queryObject.getClassDescriptor().getRepository().getDescriptorFor(result.getClass());
  -                // if refresh is required, update the cache instance from the db
  +                // if refresh is required, update the cache instance from the
  +				// db
                   if (cld.isAlwaysRefresh())
                   {
  -                	queryObject.getClassDescriptor().getRowReader().refreshObject(result, m_row);
  +                    queryObject.getClassDescriptor().getRowReader().refreshObject(result, m_row);
                   }
                   m_broker.refreshRelationships(result, cld);
               }
  @@ -480,14 +466,14 @@
           }
       }
   
  -
       /**
  -     * Reads primary key information from current RS row and generates a
  -     *
  -     * corresponding Identity, and returns a proxy from the Identity.
  -     *
  -     * @throws PersistenceBrokerException if there was an error creating the proxy class
  -     */
  +	 * Reads primary key information from current RS row and generates a
  +	 * 
  +	 * corresponding Identity, and returns a proxy from the Identity.
  +	 * 
  +	 * @throws PersistenceBrokerException
  +	 *             if there was an error creating the proxy class
  +	 */
       protected Object getProxyFromResultSet() throws PersistenceBrokerException
       {
           // 1. get Identity of current row:
  @@ -498,11 +484,12 @@
       }
   
       /**
  -     * with a new batch of JDBC 3.0 drivers coming out we can't just check for
  -     * begins with 2, we need to check the actual version and see if it's greater
  -     * than or equal to 2
  -     * @return
  -     */
  +	 * with a new batch of JDBC 3.0 drivers coming out we can't just check for
  +	 * begins with 2, we need to check the actual version and see if it's
  +	 * greater than or equal to 2
  +	 * 
  +	 * @return
  +	 */
       private boolean supportsAdvancedJDBCCursorControl()
       {
           if (!JDBCSupportAssessed)
  @@ -515,46 +502,29 @@
       }
   
       /**
  -     * Answer the counted size
  -     * @return int
  -     */
  +	 * Answer the counted size
  +	 * 
  +	 * @return int
  +	 */
       protected int countedSize() throws PersistenceBrokerException
       {
  -        /*
  -        TODO: PB.getCount(..) should handle QueryBySQL instances too
  -        */
  -        if(queryObject.getQuery() instanceof QueryBySQL)
  -        {
  -            return countedSizeBySQL();
  -        }
  -        else
  -        {
  -            return m_broker.getCount(queryObject.getQuery());
  -        }
  -    }
  -
  -    protected int countedSizeBySQL() throws PersistenceBrokerException
  -    {
  -        String countSql = ((QueryBySQL)queryObject.getQuery()).getSql();
  -
  +        Query countQuery = m_broker.serviceBrokerHelper().getCountQuery(queryObject.getQuery());
           ResultSetAndStatement rsStmt;
  +        ClassDescriptor cld = queryObject.getClassDescriptor();
           int count = 0;
   
  -        int fromPos = countSql.toUpperCase().indexOf(" FROM ");
  -        if (fromPos >= 0)
  +        // BRJ: do not use broker.getCount() because it's extent-aware
  +        // the count we need here must not include extents !   
  +        if (countQuery instanceof QueryBySQL)
           {
  -            countSql = "select count(*)" + countSql.substring(fromPos);
  +            String countSql = ((QueryBySQL) countQuery).getSql();
  +            rsStmt = m_broker.serviceJdbcAccess().executeSQL(countSql, cld, Query.NOT_SCROLLABLE);
           }
  -
  -        // BRJ: cut before ORDER BY
  -        int orderPos = countSql.toUpperCase().indexOf(" ORDER BY ");
  -        if (orderPos >= 0)
  +        else
           {
  -            countSql = countSql.substring(0, orderPos);
  +            rsStmt = m_broker.serviceJdbcAccess().executeQuery(countQuery, cld);
           }
   
  -        rsStmt = m_broker.serviceJdbcAccess().executeSQL(
  -                countSql, queryObject.getClassDescriptor(), Query.NOT_SCROLLABLE);
           try
           {
               if (rsStmt.m_rs.next())
  @@ -570,13 +540,14 @@
           {
               rsStmt.close();
           }
  +        
           return count;
       }
   
       /**
  -     *
  -     * @return the size of the iterator, aka the number of rows in this iterator.
  -     */
  +	 * @return the size of the iterator, aka the number of rows in this
  +	 *         iterator.
  +	 */
       public int size() throws PersistenceBrokerException
       {
           int retval = 0; // default size is 0;
  @@ -589,24 +560,26 @@
           {
           }
           if (!supportsAdvancedJDBCCursorControl()
  -                || m_broker.serviceConnectionManager().getSupportedPlatform().useCountForResultsetSize()
  -                || forwardOnly)
  +            || m_broker.serviceConnectionManager().getSupportedPlatform().useCountForResultsetSize()
  +            || forwardOnly)
           {
               /**
  -             * MBAIRD: doesn't support the .last .getRow method, use the .getCount on the
  -             * persistenceBroker which executes a count(*) query.
  -             */
  -            if (logger.isDebugEnabled()) logger.debug("Executing count(*) to get size()");
  +			 * MBAIRD: doesn't support the .last .getRow method, use the
  +			 * .getCount on the persistenceBroker which executes a count(*)
  +			 * query.
  +			 */
  +            if (logger.isDebugEnabled())
  +                logger.debug("Executing count(*) to get size()");
               retval = countedSize();
           }
           else
           {
               /**
  -             * Use the .last .getRow method of finding size.
  -             * The reason for supplying an alternative method is effeciency,
  -             * some driver/db combos are a lot more efficient at just moving the cursor
  -             * and returning the row in a real (not -1) number.
  -             */
  +			 * Use the .last .getRow method of finding size. The reason for
  +			 * supplying an alternative method is effeciency, some driver/db
  +			 * combos are a lot more efficient at just moving the cursor and
  +			 * returning the row in a real (not -1) number.
  +			 */
               int whereIAm = 1; // first
               try
               {
  @@ -641,11 +614,14 @@
       }
   
       /**
  -     * Moves the cursor to the given row number in the iterator.
  -     * If the row number is positive, the cursor moves to the given row number with
  -     * respect to the beginning of the iterator. The first row is row 1, the second is row 2, and so on.
  -     * @param row the row to move to in this iterator, by absolute number
  -     */
  +	 * Moves the cursor to the given row number in the iterator. If the row
  +	 * number is positive, the cursor moves to the given row number with
  +	 * respect to the beginning of the iterator. The first row is row 1, the
  +	 * second is row 2, and so on.
  +	 * 
  +	 * @param row
  +	 *            the row to move to in this iterator, by absolute number
  +	 */
       public boolean absolute(int row) throws PersistenceBrokerException
       {
           boolean retval = false;
  @@ -696,18 +672,22 @@
               }
               else
               {
  -                logger.info("Your driver does not support advanced JDBC Functionality, you cannot call absolute() with a position < current");
  +                logger.info(
  +                    "Your driver does not support advanced JDBC Functionality, you cannot call absolute() with a position < current");
               }
           }
           return retval;
       }
   
       /**
  -     * Moves the cursor a relative number of rows, either positive or negative. Attempting to move beyond the first/last
  -     * row in the iterator positions the cursor before/after the the first/last row. Calling relative(0) is valid,
  -     * but does not change the cursor position.
  -     * @param row the row to move to in this iterator, by relative number
  -     */
  +	 * Moves the cursor a relative number of rows, either positive or negative.
  +	 * Attempting to move beyond the first/last row in the iterator positions
  +	 * the cursor before/after the the first/last row. Calling relative(0) is
  +	 * valid, but does not change the cursor position.
  +	 * 
  +	 * @param row
  +	 *            the row to move to in this iterator, by relative number
  +	 */
       public boolean relative(int row) throws SQLException
       {
           boolean retval = false;
  @@ -741,14 +721,14 @@
       }
   
       /**
  -     * Release all internally used Database resources of the iterator.
  -     * Clients must call this methods explicitely if the iterator is not
  -     * exhausted by the client application. If the Iterator is exhauseted
  -     * this method will be called implicitely.
  -     */
  +	 * Release all internally used Database resources of the iterator. Clients
  +	 * must call this methods explicitely if the iterator is not exhausted by
  +	 * the client application. If the Iterator is exhauseted this method will
  +	 * be called implicitely.
  +	 */
       public void releaseDbResources()
       {
  -        if (!inBatchedMode)     // resources are reused in batched mode
  +        if (!inBatchedMode) // resources are reused in batched mode
           {
               // If we haven't released resources yet, then do so.
               if (!this.resourcesAreReleased)
  @@ -760,8 +740,8 @@
       }
   
       /**
  -     * Return the DescriptorRepository
  -     */
  +	 * Return the DescriptorRepository
  +	 */
       protected DescriptorRepository getDescriptorRepository()
       {
           return m_broker.getDescriptorRepository();
  @@ -773,8 +753,8 @@
       }
   
       /**
  -     * safety just in case someone leaks.
  -     */
  +	 * safety just in case someone leaks.
  +	 */
       protected void finalize()
       {
           releaseDbResources();
  @@ -786,11 +766,10 @@
       }
   
       /**
  -     * @return Returns the cld.
  -     */
  +	 * @return Returns the cld.
  +	 */
       public ClassDescriptor getClassDescriptor()
       {
           return queryObject.getClassDescriptor();
       }
   }
  -
  
  
  

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