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/query AbstractQueryImpl.java
Date Wed, 26 Nov 2003 17:33:09 GMT
brj         2003/11/26 09:33:09

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        PagingIterator.java
               src/java/org/apache/ojb/broker/query AbstractQueryImpl.java
  Log:
  support paging with 'undefined' endAt-index
  
  Revision  Changes    Path
  1.5       +108 -86   db-ojb/src/java/org/apache/ojb/broker/accesslayer/PagingIterator.java
  
  Index: PagingIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/PagingIterator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PagingIterator.java	23 Nov 2003 09:50:44 -0000	1.4
  +++ PagingIterator.java	26 Nov 2003 17:33:09 -0000	1.5
  @@ -1,69 +1,61 @@
   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 java.sql.SQLException;
  +
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.query.Query;
   
   /**
  - * PagingIterator is wrapper around an OJBIterator to support 
  - * startAt endAt positions. The PagingIterator returns rows including startAt
  - * and including endAt.
  + * PagingIterator is wrapper around an OJBIterator to support startAt endAt
  + * positions. The PagingIterator returns rows <b>including</b> startAt 
  + * and <b>including</b> endAt.
    * 
    * startAt = 1, endAt = 11 returns rows 1 to 11 if available
  - *
  + * if endAt == Query.NO_END_AT_INDEX endAt is set to the last available row
  + * 
    * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
  @@ -76,36 +68,57 @@
       private int m_rowLimit;
       private int m_fullSize;
       private int m_currentCursorPosition;
  -    
  +
       /**
  -     * 
  +     * Constructor 
  +     * @param anIterator wrapped Iterator
  +     * @param startAt (first row is 1)
  +     * @param endAt (Query.NO_END_AT_INDEX stands for all available rows) 
        */
       public PagingIterator(OJBIterator anIterator, int startAt, int endAt)
       {
           super();
  -        
  -        if (startAt > endAt)
  +
  +        if (endAt != Query.NO_START_AT_INDEX && startAt > endAt)
           {
               throw new PersistenceBrokerException("startAt must be less than endAt.");
           }
  -        
  +
           m_iterator = anIterator;
           m_fullSize = m_iterator.size();
  +
  +        if (startAt == Query.NO_START_AT_INDEX)
  +        {
  +            m_startAt = 1;
  +        }
  +        else
  +        {
  +            m_startAt = startAt;
  +        }
  +
  +        if (endAt == Query.NO_END_AT_INDEX)
  +        {
  +            m_endAt = m_fullSize;
  +        }
  +        else
  +        {
  +            m_endAt = Math.min(endAt, m_fullSize);
  +        }
           
  -        m_startAt = startAt;
  -        m_endAt = Math.min(endAt, m_fullSize);        
           m_rowLimit = Math.max(0, m_endAt - m_startAt + 1);
           m_currentCursorPosition = m_startAt - 1;
  -        
  +
           m_iterator.absolute(m_currentCursorPosition);
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.ojb.broker.accesslayer.OJBIterator#size()
  -     */
  +    /*
  +	 * (non-Javadoc)
  +	 * 
  +	 * @see org.apache.ojb.broker.accesslayer.OJBIterator#size()
  +	 */
       public int size() throws PersistenceBrokerException
       {
  -        if (m_fullSize < m_rowLimit )
  +        if (m_fullSize < m_rowLimit)
           {
               return m_fullSize;
           }
  @@ -115,42 +128,49 @@
           }
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.ojb.broker.accesslayer.OJBIterator#absolute(int)
  -     */
  +    /*
  +	 * (non-Javadoc)
  +	 * 
  +	 * @see org.apache.ojb.broker.accesslayer.OJBIterator#absolute(int)
  +	 */
       public boolean absolute(int row) throws PersistenceBrokerException
       {
           return m_iterator.absolute(m_startAt + row);
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.ojb.broker.accesslayer.OJBIterator#relative(int)
  -     */
  +    /*
  +	 * (non-Javadoc)
  +	 * 
  +	 * @see org.apache.ojb.broker.accesslayer.OJBIterator#relative(int)
  +	 */
       public boolean relative(int row) throws SQLException
       {
           return m_iterator.relative(row);
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.ojb.broker.accesslayer.OJBIterator#releaseDbResources()
  -     */
  +    /*
  +	 * (non-Javadoc)
  +	 * 
  +	 * @see org.apache.ojb.broker.accesslayer.OJBIterator#releaseDbResources()
  +	 */
       public void releaseDbResources()
       {
           m_iterator.releaseDbResources();
       }
   
       /**
  -     * remove is not supported 
  -     */
  +	 * remove is not supported
  +	 */
       public void remove()
       {
           throw new UnsupportedOperationException("remove not supported by PagingIterator");
       }
   
  -    
  -    /* (non-Javadoc)
  -     * @see java.util.Iterator#hasNext()
  -     */
  +    /*
  +	 * (non-Javadoc)
  +	 * 
  +	 * @see java.util.Iterator#hasNext()
  +	 */
       public boolean hasNext()
       {
           if (m_currentCursorPosition < m_endAt)
  @@ -162,12 +182,14 @@
               releaseDbResources();
               return false;
           }
  -            
  +
       }
   
  -    /* (non-Javadoc)
  -     * @see java.util.Iterator#next()
  -     */
  +    /*
  +	 * (non-Javadoc)
  +	 * 
  +	 * @see java.util.Iterator#next()
  +	 */
       public Object next()
       {
           m_currentCursorPosition++;
  
  
  
  1.11      +2 -2      db-ojb/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java
  
  Index: AbstractQueryImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AbstractQueryImpl.java	20 Nov 2003 19:30:23 -0000	1.10
  +++ AbstractQueryImpl.java	26 Nov 2003 17:33:09 -0000	1.11
  @@ -199,7 +199,7 @@
       public boolean usePaging()
       {
           return getEndAtIndex() > NO_END_AT_INDEX
  -            && getStartAtIndex() > NO_START_AT_INDEX;
  +            || getStartAtIndex() > NO_START_AT_INDEX;
       }
       
   }
  
  
  

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