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/19 22:13:31 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer PagingIterator.java
brj 2003/11/19 13:13:31
Added: src/java/org/apache/ojb/broker/accesslayer
PagingIterator.java
Log:
wrapper for iterators to support ojb-style paging
Revision Changes Path
1.1 db-ojb/src/java/org/apache/ojb/broker/accesslayer/PagingIterator.java
Index: PagingIterator.java
===================================================================
package org.apache.ojb.broker.accesslayer;
/* ====================================================================
* 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.
* ====================================================================
*
* 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;
/**
* PagingIterator is wrapper around an OJBIterator to support
* startAt endAt positions.
*
* @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
* @version $Id: PagingIterator.java,v 1.1 2003/11/19 21:13:31 brj Exp $
*/
public class PagingIterator implements OJBIterator
{
private final OJBIterator m_iterator;
private int m_startAt;
private int m_endAt;
private int m_rowLimit;
private int m_fullSize;
private int m_currentCursorPosition;
/**
*
*/
public PagingIterator(OJBIterator anIterator, int startAt, int endAt)
{
super();
m_iterator = anIterator;
m_fullSize = m_iterator.size();
m_startAt = startAt;
m_endAt = Math.min(endAt, m_fullSize);
m_rowLimit = 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()
*/
public int size() throws PersistenceBrokerException
{
if (m_fullSize < m_rowLimit )
{
return m_fullSize;
}
else
{
return m_rowLimit;
}
}
/* (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)
*/
public boolean relative(int row) throws SQLException
{
return m_iterator.relative(row);
}
/* (non-Javadoc)
* @see org.apache.ojb.broker.accesslayer.OJBIterator#releaseDbResources()
*/
public void releaseDbResources()
{
m_iterator.releaseDbResources();
}
/* (non-Javadoc)
* @see java.util.Iterator#remove()
*/
public void remove()
{
m_iterator.remove();
}
/* (non-Javadoc)
* @see java.util.Iterator#hasNext()
*/
public boolean hasNext()
{
return m_currentCursorPosition < m_endAt;
}
/* (non-Javadoc)
* @see java.util.Iterator#next()
*/
public Object next()
{
m_currentCursorPosition++;
return m_iterator.next();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org