org.apache.ojb.broker.accesslayer
Class ChainingIterator

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

public class ChainingIterator
extends Object
implements OJBIterator

Version:
$Id: ChainingIterator.java,v 1.1 2007-08-24 22:17:30 ewestfal Exp $
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.

Field Summary
private  boolean disableLifeCycleEvents
          if true do not fire PBLifeCycleEvent.
private  OJBIterator m_activeIterator
           
private  int m_activeIteratorIndex
          The following are used to maintain an index of where the cursor is in the array of rsiterators.
private  int m_currentCursorPosition
           
private  int m_fullSize
           
private  List m_rsIterators
           
 
Constructor Summary
ChainingIterator()
          Constructor for ChainingIterator.
ChainingIterator(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(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.
 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()
           
private  boolean setNextIterator()
          Convenience routine to move to the next iterator if needed.
 int size()
          Calculates the size of all the iterators.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_rsIterators

private List m_rsIterators

m_activeIterator

private OJBIterator m_activeIterator

m_activeIteratorIndex

private int m_activeIteratorIndex
The following are used to maintain an index of where the cursor is in the array of rsiterators. We do this because we can't find the position through the interface, and we need the position in order to support the relative(x) calls


m_fullSize

private int m_fullSize

m_currentCursorPosition

private int m_currentCursorPosition

disableLifeCycleEvents

private boolean disableLifeCycleEvents
if true do not fire PBLifeCycleEvent.

Constructor Detail

ChainingIterator

public ChainingIterator()
Constructor for ChainingIterator.


ChainingIterator

public ChainingIterator(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 Iterator
Returns:
true if one of the contained iterators past the current position has a next.

next

public 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 Iterator
Returns:
the next object in the iterator.

remove

public void remove()
Specified by:
remove in interface Iterator

setNextIterator

private boolean setNextIterator()
Convenience routine to move to the next iterator if needed.

Returns:
true if the iterator is changed, false if no changes.

containsIteratorForTable

public boolean containsIteratorForTable(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()


Copyright © 2007-2011 The Kuali Foundation. All Rights Reserved.