org.apache.ojb.broker.accesslayer
Class ChainingIterator

java.lang.Object
  extended by org.apache.ojb.broker.accesslayer.ChainingIterator
All Implemented Interfaces:
java.util.Iterator, OJBIterator

public class ChainingIterator
extends java.lang.Object
implements OJBIterator

Version:
$Id: ChainingIterator.java 365232 2005-12-21 22:36:07Z tomdz $
Author:
matthew.baird (mattbaird@yahoo.com) The ChainingIterator is an extent aware Iterator. How the ChainingIterator works: The ChainedIterator holds a collection of RsIterators for each queried Interface-based extent. The RsIterator is able to load objects that are non-interface extents, mapped to the same table. The ChainingIterator cannot return sorted results as the iterator is a collection of query results across different tables.

Constructor Summary
ChainingIterator()
          Constructor for ChainingIterator.
ChainingIterator(java.util.List iterators)
          Constructor for ChainingIterator.
 
Method Summary
 boolean absolute(int row)
          the absolute and relative calls are the trickiest parts.
 void addIterator(OJBIterator iterator)
          use this method to construct the ChainingIterator iterator by iterator.
 boolean containsIteratorForTable(java.lang.String aTable)
          Answer true if an Iterator for a Table is already available
 void disableLifeCycleEvents()
          Do not fire any PBLifeCycleEvent when reading next item.
 int fullSize()
           
 boolean hasNext()
          check the list of iterators to see if we have a next element.
 java.lang.Object next()
          first checks to make sure we aren't at the end of the list of iterators, positions the cursor appropriately, then retrieves next object in active iterator.
 boolean relative(int row)
          Moves the cursor a relative number of rows.
 void releaseDbResources()
          delegate to each contained OJBIterator and release its resources.
 void remove()
           
 int size()
          Calculates the size of all the iterators.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChainingIterator

public ChainingIterator()
Constructor for ChainingIterator.


ChainingIterator

public ChainingIterator(java.util.List iterators)
Constructor for ChainingIterator.

Method Detail

addIterator

public void addIterator(OJBIterator iterator)
use this method to construct the ChainingIterator iterator by iterator.


size

public int size()
         throws PersistenceBrokerException
Calculates the size of all the iterators. Caches it for fast lookups in the future. iterators shouldn't change size after the queries have been executed so caching is safe (assumption, should check).

Specified by:
size in interface OJBIterator
Returns:
the combined size of all the iterators for all extents.
Throws:
PersistenceBrokerException

fullSize

public int fullSize()
             throws PersistenceBrokerException
Specified by:
fullSize in interface OJBIterator
Returns:
the unlimited size of the iterator, fullSize() may differ from size() for PagingIterator
Throws:
PersistenceBrokerException

absolute

public boolean absolute(int row)
                 throws PersistenceBrokerException
the absolute and relative calls are the trickiest parts. We have to move across cursor boundaries potentially. a + row value indexes from beginning of resultset a - row value indexes from the end of th resulset. Calling absolute(1) is the same as calling first(). Calling absolute(-1) is the same as calling last().

Specified by:
absolute in interface OJBIterator
Parameters:
row - the row to move to in this iterator, by absolute number
Throws:
PersistenceBrokerException

relative

public boolean relative(int row)
                 throws PersistenceBrokerException
Moves the cursor a relative number of rows. Movement can go in forward (positive) or reverse (negative). Calling relative does not "wrap" meaning if you move before first or after last you get positioned at the first or last row. Calling relative(0) does not change the cursor position. Note: Calling the method relative(1) is different from calling the method next() because is makes sense to call next() when there is no current row, for example, when the cursor is positioned before the first row or after the last row of the result set.

Specified by:
relative in interface OJBIterator
Parameters:
row - the row to move to in this iterator, by relative number
Throws:
PersistenceBrokerException

releaseDbResources

public void releaseDbResources()
delegate to each contained OJBIterator and release its resources.

Specified by:
releaseDbResources in interface OJBIterator

hasNext

public boolean hasNext()
check the list of iterators to see if we have a next element.

Specified by:
hasNext in interface java.util.Iterator
Returns:
true if one of the contained iterators past the current position has a next.

next

public java.lang.Object next()
first checks to make sure we aren't at the end of the list of iterators, positions the cursor appropriately, then retrieves next object in active iterator.

Specified by:
next in interface java.util.Iterator
Returns:
the next object in the iterator.

remove

public void remove()
Specified by:
remove in interface java.util.Iterator

containsIteratorForTable

public boolean containsIteratorForTable(java.lang.String aTable)
Answer true if an Iterator for a Table is already available

Parameters:
aTable -
Returns:

disableLifeCycleEvents

public void disableLifeCycleEvents()
Description copied from interface: OJBIterator
Do not fire any PBLifeCycleEvent when reading next item.

Specified by:
disableLifeCycleEvents in interface OJBIterator
See Also:
OJBIterator.disableLifeCycleEvents()


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30