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 2004/03/08 22:08:57 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer CollectionPrefetcher.java ListProxy.java ChainingIterator.java

brj         2004/03/08 13:08:57

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        CollectionPrefetcher.java ListProxy.java
                        ChainingIterator.java
  Log:
  removed TAB character
  
  Revision  Changes    Path
  1.24      +16 -16    db-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java
  
  Index: CollectionPrefetcher.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- CollectionPrefetcher.java	6 Mar 2004 22:38:52 -0000	1.23
  +++ CollectionPrefetcher.java	8 Mar 2004 21:08:57 -0000	1.24
  @@ -79,7 +79,7 @@
   
   /**
    * Relationship Prefetcher for Collections.
  - * 
  + *
    * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
  @@ -87,21 +87,21 @@
   {
   
       /**
  -	 * Constructor for CollectionPrefetcher.
  -	 * 
  -	 * @param aBroker
  -	 * @param anOrd
  -	 */
  +     * Constructor for CollectionPrefetcher.
  +     *
  +     * @param aBroker
  +     * @param anOrd
  +     */
       public CollectionPrefetcher(PersistenceBroker aBroker, ObjectReferenceDescriptor anOrd)
       {
           super(aBroker, anOrd);
       }
   
       /**
  -	 * Build the multiple queries for one relationship because of limitation of IN(...)
  -	 * 
  -	 * @param owners Collection containing all objects of the ONE side
  -	 */
  +     * Build the multiple queries for one relationship because of limitation of IN(...)
  +     *
  +     * @param owners Collection containing all objects of the ONE side
  +     */
       protected Query[] buildPrefetchQueries(Collection owners, Collection children)
       {
           ClassDescriptor cld = getOwnerClassDescriptor();
  @@ -136,10 +136,10 @@
       }
   
       /**
  -	 * Build the query to perform a batched read get orderBy settings from CollectionDescriptor
  -	 * 
  -	 * @param ids Collection containing all identities of objects of the ONE side
  -	 */
  +     * Build the query to perform a batched read get orderBy settings from CollectionDescriptor
  +     *
  +     * @param ids Collection containing all identities of objects of the ONE side
  +     */
       protected Query buildPrefetchQuery(Collection ids)
       {
           CollectionDescriptor cds = getCollectionDescriptor();
  @@ -174,7 +174,7 @@
           for (Iterator it = owners.iterator(); it.hasNext();)
           {
               Object owner = it.next();
  -            ownerIdsToLists.put(new Identity(owner,pb), new ArrayList());
  +            ownerIdsToLists.put(new Identity(owner, pb), new ArrayList());
           }
   
           // build the children lists for the owners
  
  
  
  1.4       +110 -110  db-ojb/src/java/org/apache/ojb/broker/accesslayer/ListProxy.java
  
  Index: ListProxy.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ListProxy.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ListProxy.java	19 Jun 2003 19:58:18 -0000	1.3
  +++ ListProxy.java	8 Mar 2004 21:08:57 -0000	1.4
  @@ -66,135 +66,135 @@
   /**
    * ListProxy. <br> A placeHolder for a whole list to support deferred loading of
    * relationships. The complete relationship is loaded on request.
  - * 
  + *
    * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
    * @version $Id$
    */
   public class ListProxy extends CollectionProxy implements List
   {
   
  -	/**
  -	 * Constructor for ListProxy.
  -	 * @param aKey
  -	 * @param aQuery
  -	 */
  -	public ListProxy(PBKey aKey, Query aQuery)
  -	{
  -		this(aKey, RemovalAwareCollection.class, aQuery);
  -	}
  -
  -	/**
  -	 * Constructor for ListProxy.
  -	 * @param aKey
  -	 * @param aCollClass
  -	 * @param aQuery
  -	 */
  -	public ListProxy(PBKey aKey, Class aCollClass, Query aQuery)
  -	{
  -		super(aKey, aCollClass, aQuery);
  -	}
  -
  -	/**
  -	 * @see java.util.List#addAll(int, java.util.Collection)
  -	 */
  -	public boolean addAll(int index, Collection c)
  -	{
  -		return getListData().addAll(index, c);
  -	}
  -
  -	/**
  -	 * @see java.util.List#get(int)
  -	 */
  -	public Object get(int index)
  -	{
  -		return getListData().get(index);
  -	}
  -
  -	/**
  -	 * @see java.util.List#set(int, java.lang.Object)
  -	 */
  -	public Object set(int index, Object element)
  -	{
  -		return getListData().set(index, element);
  -	}
  -
  -	/**
  -	 * @see java.util.List#add(int, java.lang.Object)
  -	 */
  -	public void add(int index, Object element)
  -	{
  +    /**
  +     * Constructor for ListProxy.
  +     * @param aKey
  +     * @param aQuery
  +     */
  +    public ListProxy(PBKey aKey, Query aQuery)
  +    {
  +        this(aKey, RemovalAwareCollection.class, aQuery);
  +    }
  +
  +    /**
  +     * Constructor for ListProxy.
  +     * @param aKey
  +     * @param aCollClass
  +     * @param aQuery
  +     */
  +    public ListProxy(PBKey aKey, Class aCollClass, Query aQuery)
  +    {
  +        super(aKey, aCollClass, aQuery);
  +    }
  +
  +    /**
  +     * @see java.util.List#addAll(int, java.util.Collection)
  +     */
  +    public boolean addAll(int index, Collection c)
  +    {
  +        return getListData().addAll(index, c);
  +    }
  +
  +    /**
  +     * @see java.util.List#get(int)
  +     */
  +    public Object get(int index)
  +    {
  +        return getListData().get(index);
  +    }
  +
  +    /**
  +     * @see java.util.List#set(int, java.lang.Object)
  +     */
  +    public Object set(int index, Object element)
  +    {
  +        return getListData().set(index, element);
  +    }
  +
  +    /**
  +     * @see java.util.List#add(int, java.lang.Object)
  +     */
  +    public void add(int index, Object element)
  +    {
           getListData().add(index, element);
  -	}
  +    }
   
  -	/**
  -	 * @see java.util.List#remove(int)
  -	 */
  -	public Object remove(int index)
  -	{
  -		return getListData().remove(index);
  -	}
  -
  -	/**
  -	 * @see java.util.List#indexOf(java.lang.Object)
  -	 */
  -	public int indexOf(Object o)
  -	{
  -		return getListData().indexOf(o);
  -	}
  -
  -	/**
  -	 * @see java.util.List#lastIndexOf(java.lang.Object)
  -	 */
  -	public int lastIndexOf(Object o)
  -	{
  -		return getListData().lastIndexOf(o);
  -	}
  -
  -	/**
  -	 * @see java.util.List#listIterator()
  -	 */
  -	public ListIterator listIterator()
  -	{
  -		return getListData().listIterator();
  -	}
  -
  -	/**
  -	 * @see java.util.List#listIterator(int)
  -	 */
  -	public ListIterator listIterator(int index)
  -	{
  -		return getListData().listIterator(index);
  -	}
  -
  -	/**
  -	 * @see java.util.List#subList(int, int)
  -	 */
  -	public List subList(int fromIndex, int toIndex)
  -	{
  -		return getListData().subList(fromIndex, toIndex);
  -	}
  +    /**
  +     * @see java.util.List#remove(int)
  +     */
  +    public Object remove(int index)
  +    {
  +        return getListData().remove(index);
  +    }
  +
  +    /**
  +     * @see java.util.List#indexOf(java.lang.Object)
  +     */
  +    public int indexOf(Object o)
  +    {
  +        return getListData().indexOf(o);
  +    }
  +
  +    /**
  +     * @see java.util.List#lastIndexOf(java.lang.Object)
  +     */
  +    public int lastIndexOf(Object o)
  +    {
  +        return getListData().lastIndexOf(o);
  +    }
  +
  +    /**
  +     * @see java.util.List#listIterator()
  +     */
  +    public ListIterator listIterator()
  +    {
  +        return getListData().listIterator();
  +    }
  +
  +    /**
  +     * @see java.util.List#listIterator(int)
  +     */
  +    public ListIterator listIterator(int index)
  +    {
  +        return getListData().listIterator(index);
  +    }
  +
  +    /**
  +     * @see java.util.List#subList(int, int)
  +     */
  +    public List subList(int fromIndex, int toIndex)
  +    {
  +        return getListData().subList(fromIndex, toIndex);
  +    }
   
       protected List getListData()
       {
  -        return (List)super.getData();    
  +        return (List) super.getData();
       }
  -    
  -	/**
  -	 * @see org.apache.ojb.broker.accesslayer.CollectionProxy#loadData()
  -	 */
  -	protected Collection loadData() throws PersistenceBrokerException
  -	{
  +
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.CollectionProxy#loadData()
  +     */
  +    protected Collection loadData() throws PersistenceBrokerException
  +    {
           Collection result = super.loadData();
   
           if (result instanceof List)
           {
               return result;
  -        }    
  +        }
           else
           {
               throw new PersistenceBrokerException("loaded data does not implement java.util.List");
           }
  -		
  -	}
  +
  +    }
   
   }
  
  
  
  1.10      +317 -319  db-ojb/src/java/org/apache/ojb/broker/accesslayer/ChainingIterator.java
  
  Index: ChainingIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ChainingIterator.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ChainingIterator.java	17 Dec 2003 20:37:02 -0000	1.9
  +++ ChainingIterator.java	8 Mar 2004 21:08:57 -0000	1.10
  @@ -59,108 +59,106 @@
   
   import org.apache.ojb.broker.PersistenceBrokerException;
   
  -
   /**
    * @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.
  - * 
  + *
    * @version $Id$
    */
   public class ChainingIterator implements OJBIterator
   {
  -	private List m_rsIterators = new ArrayList();
  -	private OJBIterator m_activeIterator = null;
  -	
  -	/**
  -	 * 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
  -	 */
  -	private int m_activeIteratorIndex = 0;
  -	private int m_fullSize = -1;
  -	private int m_currentCursorPosition =0;
  -	
  -
  -	/**
  -	 * Constructor for ChainingIterator.
  -	 */
  -	public ChainingIterator()
  -	{
  -		super();
  -	}
  -	
  -	/**
  -	 * Constructor for ChainingIterator.
  -	 */
  -	public ChainingIterator(List iterators)
  -	{
  -		Iterator checkIterator = iterators.iterator();
  -		OJBIterator temp;
  -		
  -		/**
  -		 * validate that all items in List are iterators and
  -		 * they are not empty.
  -		 */
  -		while (checkIterator.hasNext())
  -		{
  -			temp = (OJBIterator) checkIterator.next();
  -			addIterator(temp);
  -		}
  -	}
  -	
  -	/**
  -	 * use this method to construct the ChainingIterator
  -	 * iterator by iterator.
  -	 */
  -	public void addIterator(OJBIterator iterator)
  -	{
  -		/**
  -		 * only add iterators that are not null and non-empty.
  -		 */
  -		if (iterator != null)
  -		{
  -			if (iterator.hasNext())
  -			{
  -				setNextIterator();
  -				m_rsIterators.add(iterator);
  -			}
  -		}
  -	}
  -	
  -	/**
  -	 * 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).
  -	 * @return the combined size of all the iterators for all extents.
  -	 */
  -	public int size() throws PersistenceBrokerException
  -	{
  -		if (m_fullSize == -1)
  -		{
  -			int size = 0;
  -			Iterator it = m_rsIterators.iterator();
  -			while (it.hasNext())
  -			{
  -				size += ((OJBIterator)it.next()).size();
  -			}
  -			m_fullSize = size;
  -		}
  -		return m_fullSize;
  -	}
  -	
  +    private List m_rsIterators = new ArrayList();
  +    private OJBIterator m_activeIterator = null;
  +
  +    /**
  +     * 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
  +     */
  +    private int m_activeIteratorIndex = 0;
  +    private int m_fullSize = -1;
  +    private int m_currentCursorPosition = 0;
  +
  +    /**
  +     * Constructor for ChainingIterator.
  +     */
  +    public ChainingIterator()
  +    {
  +        super();
  +    }
  +
  +    /**
  +     * Constructor for ChainingIterator.
  +     */
  +    public ChainingIterator(List iterators)
  +    {
  +        Iterator checkIterator = iterators.iterator();
  +        OJBIterator temp;
  +
  +        /**
  +         * validate that all items in List are iterators and
  +         * they are not empty.
  +         */
  +        while (checkIterator.hasNext())
  +        {
  +            temp = (OJBIterator) checkIterator.next();
  +            addIterator(temp);
  +        }
  +    }
  +
  +    /**
  +     * use this method to construct the ChainingIterator
  +     * iterator by iterator.
  +     */
  +    public void addIterator(OJBIterator iterator)
  +    {
  +        /**
  +         * only add iterators that are not null and non-empty.
  +         */
  +        if (iterator != null)
  +        {
  +            if (iterator.hasNext())
  +            {
  +                setNextIterator();
  +                m_rsIterators.add(iterator);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * 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).
  +     * @return the combined size of all the iterators for all extents.
  +     */
  +    public int size() throws PersistenceBrokerException
  +    {
  +        if (m_fullSize == -1)
  +        {
  +            int size = 0;
  +            Iterator it = m_rsIterators.iterator();
  +            while (it.hasNext())
  +            {
  +                size += ((OJBIterator) it.next()).size();
  +            }
  +            m_fullSize = size;
  +        }
  +        return m_fullSize;
  +    }
  +
       /* (non-Javadoc)
        * @see org.apache.ojb.broker.accesslayer.OJBIterator#fullSize()
        */
  @@ -168,244 +166,244 @@
       {
           return size();
       }
  -    
  -	/**
  -	 * 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().
  -	 */
  -	public boolean absolute(int row) throws PersistenceBrokerException
  -	{
  -		// 1. handle the special cases first.
  -		if (row == 0)
  -		{
  -			return true;
  -		}	
  -		
  -		if (row == 1)
  -		{
  -			m_activeIteratorIndex = 0;
  -			m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
  -			m_activeIterator.absolute(1);
  -			return true;
  -		}
  -		if (row == -1)
  -		{
  -			m_activeIteratorIndex = m_rsIterators.size();
  -			m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
  -			m_activeIterator.absolute(-1);
  -			return true;			
  -		}
  -
  -		// now do the real work.
  -		boolean movedToAbsolute = false;
  -		boolean retval = false;
  -		setNextIterator();
  -		
  -		// row is positive, so index from beginning.
  -		if (row > 0)
  -		{
  -			int sizeCount = 0;
  -			Iterator it = m_rsIterators.iterator();
  -			OJBIterator temp = null;
  -			while (it.hasNext() && !movedToAbsolute)
  -			{
  -				temp = (OJBIterator) it.next();
  -				if (temp.size() < row)
  -				{
  -					sizeCount += temp.size();
  -				}
  -				else
  -				{
  -					// move to the offset - sizecount
  -					m_currentCursorPosition = row-sizeCount;
  -					retval = temp.absolute(m_currentCursorPosition);
  -					movedToAbsolute = true;
  -				}
  -			}
  -
  -		}
  -		
  -		// row is negative, so index from end
  -		else if (row < 0)
  -		{
  -			int sizeCount = 0;
  -			OJBIterator temp = null;
  -			for (int i = m_rsIterators.size(); ((i >= 0) && !movedToAbsolute); i--)
  -			{
  -				temp = (OJBIterator) m_rsIterators.get(i);
  -				if (temp.size() < row)
  -				{
  -					sizeCount += temp.size();
  -				}
  -				else
  -				{
  -					// move to the offset - sizecount
  -					m_currentCursorPosition = row+sizeCount;
  -					retval = temp.absolute(m_currentCursorPosition);
  -					movedToAbsolute = true;
  -				}
  -			}
  -		}
  -		
  -		return retval;
  -	}
  -	
  -	/**
  -	 * 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.
  -	 */
  -	public boolean relative(int row) throws PersistenceBrokerException
  -	{
  -		if (row == 0)
  -		{
  -			return true;
  -		}	
  -			
  -		boolean movedToRelative = false;
  -		boolean retval = false;
  -		setNextIterator();
  -		
  -		if (row > 0)
  -		{
  -			// special case checking for the iterator we're currently in 
  -			// (since it isn't positioned on the boundary potentially)
  -			if (row > (m_activeIterator.size() - m_currentCursorPosition))
  -			{
  -				// the relative position lies over the border of the 
  -				// current iterator.
  -				
  -				// starting position counter should be set to whatever we have left in
  -				// active iterator.
  -				int positionCounter = m_activeIterator.size() - m_currentCursorPosition;
  -				for (int i = m_activeIteratorIndex+1; ((i < m_rsIterators.size()) && !movedToRelative); i++)
  -				{ 
  -					m_activeIteratorIndex = i;
  -	    			m_currentCursorPosition = 0;
  -					m_activeIterator = (OJBIterator)m_rsIterators.get(m_activeIteratorIndex);
  -					if (!((row-positionCounter) > m_activeIterator.size()))
  -					{
  -						// the relative position requested is within this iterator.
  -						m_currentCursorPosition = row-positionCounter;
  -						retval = m_activeIterator.relative(m_currentCursorPosition);
  -						movedToRelative = true;
  -					}
  -				}
  -			}
  -			else
  -			{
  -				// the relative position lays within the current iterator.
  -				retval = m_activeIterator.relative(row);
  -				movedToRelative = true;
  -			}
  -		}
  -		else if (row < 0)
  -		{
  -		}
  -		
  -		return retval;	
  -	}
  -	
  -	/**
  -	 * delegate to each contained OJBIterator and release
  -	 * its resources.
  -	 */
  -	public void releaseDbResources()
  -	{
  -		Iterator it = m_rsIterators.iterator();
  -		while (it.hasNext())
  -		{
  -			((OJBIterator)it.next()).releaseDbResources();
  -		}
  -	}
  -	
  -	/**
  -	 * check the list of iterators to see if we have a next element.
  -	 * @return true if one of the contained iterators past the current
  -	 * position has a next.
  -	 */
  -  	public boolean hasNext()
  -  	{
  -		setNextIterator();
  -		if (m_activeIterator == null)
  -		{
  -			return false;
  -		}
  -		else
  -		{
  -    		return m_activeIterator.hasNext();
  -		}
  -  	}
  -
  -	/**
  -	 * 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.
  -	 * @return the next object in the iterator.
  -	 */
  +
  +    /**
  +     * 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().
  +     */
  +    public boolean absolute(int row) throws PersistenceBrokerException
  +    {
  +        // 1. handle the special cases first.
  +        if (row == 0)
  +        {
  +            return true;
  +        }
  +
  +        if (row == 1)
  +        {
  +            m_activeIteratorIndex = 0;
  +            m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
  +            m_activeIterator.absolute(1);
  +            return true;
  +        }
  +        if (row == -1)
  +        {
  +            m_activeIteratorIndex = m_rsIterators.size();
  +            m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
  +            m_activeIterator.absolute(-1);
  +            return true;
  +        }
  +
  +        // now do the real work.
  +        boolean movedToAbsolute = false;
  +        boolean retval = false;
  +        setNextIterator();
  +
  +        // row is positive, so index from beginning.
  +        if (row > 0)
  +        {
  +            int sizeCount = 0;
  +            Iterator it = m_rsIterators.iterator();
  +            OJBIterator temp = null;
  +            while (it.hasNext() && !movedToAbsolute)
  +            {
  +                temp = (OJBIterator) it.next();
  +                if (temp.size() < row)
  +                {
  +                    sizeCount += temp.size();
  +                }
  +                else
  +                {
  +                    // move to the offset - sizecount
  +                    m_currentCursorPosition = row - sizeCount;
  +                    retval = temp.absolute(m_currentCursorPosition);
  +                    movedToAbsolute = true;
  +                }
  +            }
  +
  +        }
  +
  +        // row is negative, so index from end
  +        else if (row < 0)
  +        {
  +            int sizeCount = 0;
  +            OJBIterator temp = null;
  +            for (int i = m_rsIterators.size(); ((i >= 0) && !movedToAbsolute); i--)
  +            {
  +                temp = (OJBIterator) m_rsIterators.get(i);
  +                if (temp.size() < row)
  +                {
  +                    sizeCount += temp.size();
  +                }
  +                else
  +                {
  +                    // move to the offset - sizecount
  +                    m_currentCursorPosition = row + sizeCount;
  +                    retval = temp.absolute(m_currentCursorPosition);
  +                    movedToAbsolute = true;
  +                }
  +            }
  +        }
  +
  +        return retval;
  +    }
  +
  +    /**
  +     * 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.
  +     */
  +    public boolean relative(int row) throws PersistenceBrokerException
  +    {
  +        if (row == 0)
  +        {
  +            return true;
  +        }
  +
  +        boolean movedToRelative = false;
  +        boolean retval = false;
  +        setNextIterator();
  +
  +        if (row > 0)
  +        {
  +            // special case checking for the iterator we're currently in
  +            // (since it isn't positioned on the boundary potentially)
  +            if (row > (m_activeIterator.size() - m_currentCursorPosition))
  +            {
  +                // the relative position lies over the border of the
  +                // current iterator.
  +
  +                // starting position counter should be set to whatever we have left in
  +                // active iterator.
  +                int positionCounter = m_activeIterator.size() - m_currentCursorPosition;
  +                for (int i = m_activeIteratorIndex + 1; ((i < m_rsIterators.size()) && !movedToRelative); i++)
  +                {
  +                    m_activeIteratorIndex = i;
  +                    m_currentCursorPosition = 0;
  +                    m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
  +                    if (!((row - positionCounter) > m_activeIterator.size()))
  +                    {
  +                        // the relative position requested is within this iterator.
  +                        m_currentCursorPosition = row - positionCounter;
  +                        retval = m_activeIterator.relative(m_currentCursorPosition);
  +                        movedToRelative = true;
  +                    }
  +                }
  +            }
  +            else
  +            {
  +                // the relative position lays within the current iterator.
  +                retval = m_activeIterator.relative(row);
  +                movedToRelative = true;
  +            }
  +        }
  +        else if (row < 0)
  +        {
  +        }
  +
  +        return retval;
  +    }
  +
  +    /**
  +     * delegate to each contained OJBIterator and release
  +     * its resources.
  +     */
  +    public void releaseDbResources()
  +    {
  +        Iterator it = m_rsIterators.iterator();
  +        while (it.hasNext())
  +        {
  +            ((OJBIterator) it.next()).releaseDbResources();
  +        }
  +    }
  +
  +    /**
  +     * check the list of iterators to see if we have a next element.
  +     * @return true if one of the contained iterators past the current
  +     * position has a next.
  +     */
  +    public boolean hasNext()
  +    {
  +        setNextIterator();
  +        if (m_activeIterator == null)
  +        {
  +            return false;
  +        }
  +        else
  +        {
  +            return m_activeIterator.hasNext();
  +        }
  +    }
  +
  +    /**
  +     * 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.
  +     * @return the next object in the iterator.
  +     */
       public Object next()
       {
  -		setNextIterator();
  -		m_currentCursorPosition++;
  -    	return m_activeIterator.next();
  +        setNextIterator();
  +        m_currentCursorPosition++;
  +        return m_activeIterator.next();
       }
   
       public void remove()
       {
  -		setNextIterator();
  -    	m_activeIterator.remove();
  +        setNextIterator();
  +        m_activeIterator.remove();
       }
  -    
  +
       /**
        * Convenience routine to move to the next iterator if needed.
        * @return true if the iterator is changed, false if no changes.
        */
       private boolean setNextIterator()
       {
  -    	boolean retval = false;
  -    	// first, check if the activeIterator is null, and set it.
  -    	if (m_activeIterator == null)
  -    	{
  -    		if (m_rsIterators.size() > 0)
  -    		{
  -    			m_activeIteratorIndex = 0;
  -    			m_currentCursorPosition = 0;
  -    			m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
  -    		}
  -    	}
  -    	else if (!m_activeIterator.hasNext())
  -    	{
  -    		if (m_rsIterators.size() > (m_activeIteratorIndex + 1))
  -    		{
  -    			// we still have iterators in the collection, move to the
  -    			// next one, increment the counter, and set the active
  -    			// iterator.
  -    			m_activeIteratorIndex++;
  -    			m_currentCursorPosition = 0;
  -    			m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
  -    			retval = true;
  -    		}
  -    	}
  -    	
  -    	return retval;
  +        boolean retval = false;
  +        // first, check if the activeIterator is null, and set it.
  +        if (m_activeIterator == null)
  +        {
  +            if (m_rsIterators.size() > 0)
  +            {
  +                m_activeIteratorIndex = 0;
  +                m_currentCursorPosition = 0;
  +                m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
  +            }
  +        }
  +        else if (!m_activeIterator.hasNext())
  +        {
  +            if (m_rsIterators.size() > (m_activeIteratorIndex + 1))
  +            {
  +                // we still have iterators in the collection, move to the
  +                // next one, increment the counter, and set the active
  +                // iterator.
  +                m_activeIteratorIndex++;
  +                m_currentCursorPosition = 0;
  +                m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
  +                retval = true;
  +            }
  +        }
  +
  +        return retval;
       }
  -    
  +
       /**
        * Answer true if an Iterator for a Table is already available
        * @param aTable
  @@ -414,15 +412,15 @@
       public boolean containsIteratorForTable(String aTable)
       {
           boolean result = false;
  -        
  +
           if (m_rsIterators != null)
           {
  -            for (int i=0; i < m_rsIterators.size(); i++)
  +            for (int i = 0; i < m_rsIterators.size(); i++)
               {
  -                OJBIterator it = (OJBIterator)m_rsIterators.get(i);
  +                OJBIterator it = (OJBIterator) m_rsIterators.get(i);
                   if (it instanceof RsIterator)
                   {
  -                    if (((RsIterator)it).getClassDescriptor().getFullTableName().equals(aTable))
  +                    if (((RsIterator) it).getClassDescriptor().getFullTableName().equals(aTable))
                       {
                           result = true;
                           break;
  @@ -430,12 +428,12 @@
                   }
                   else if (it instanceof ChainingIterator)
                   {
  -                    result = ((ChainingIterator)it).containsIteratorForTable(aTable); 
  +                    result = ((ChainingIterator) it).containsIteratorForTable(aTable);
                   }
               }
           }
  -        
  +
           return result;
       }
  -    
  +
   }
  
  
  

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