Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.forum.database
Class DbBlockIterator

java.lang.Object
  extended by com.jivesoftware.forum.database.DbBlockIterator
All Implemented Interfaces:
java.util.Iterator

public class DbBlockIterator
extends java.lang.Object
implements java.util.Iterator

A class that defines the logic to iterate through an array of long unique ID's of Jive objects, and to load those objects in blocks rather than all at once or one at a time. This class operates in two modes, one which uses an array of object ids and a type id (one of the constants defined in JiveConstants, and another which uses an array of EntityDescriptors which allows the iterator to deal with lists of homogeneous types.

One feature of the class is the ability to recover from underlying modifications to the dataset in some cases. Consider the following sequence of events:

In the above example, the underlying messages in the thread were changed after the initial iterator was obtained. The logic in this class will attempt to automatically compensate for these changes by skipping over items that cannot be loaded. In the above example, that would translate to the iterator returning 5 messages instead of 8.


Constructor Summary
DbBlockIterator(EntityDescriptor[] block, CachedPreparedStatement query, int startIndex, int endIndex, int parentObjectType, long parentObjectID)
          Constructs a new DbBlockIterator.
DbBlockIterator(long[] block, CachedPreparedStatement query, int startIndex, int endIndex, int objectType, int parentObjectType, long parentObjectID)
          Constructs a new DbBlockIterator.
DbBlockIterator(long[] block, CachedPreparedStatement query, int startIndex, int endIndex, int objectType, int parentObjectType, long parentObjectID, boolean loadIDs)
          Constructs a new DbBlockIterator.
 
Method Summary
protected  long[] getBlock(int startIndex)
           
protected  java.lang.Object getElement(int index)
          Returns the element at the specified index
protected  EntityDescriptor[] getEntityBlock(int startIndex)
           
protected  java.lang.Object getNextElement()
          Returns the next element, or null if there are no more elements to return.
protected  java.lang.Object getObject(long objectID, int objectType)
           
protected  java.lang.Object getPreviousElement()
          Returns the previous element, or null if there are no more elements to return.
 boolean hasNext()
           
 boolean hasPrevious()
           
 java.util.Iterator iterator()
           
 java.lang.Object next()
           
 long nextID()
           
 java.lang.Object previous()
           
 void remove()
           
 void setIndex(long objectID)
           
 void skipElement()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbBlockIterator

public DbBlockIterator(long[] block,
                       CachedPreparedStatement query,
                       int startIndex,
                       int endIndex,
                       int objectType,
                       int parentObjectType,
                       long parentObjectID)
Constructs a new DbBlockIterator.

Parameters:
block - the array of id's to iterate through.
query - the query used to select the block.
startIndex - the starting index in the block to being iteration at.
endIndex - the endeding index in the set to end iteration at. This may or not be in the current block. If it ends after the current block, the next block will be loaded automatically as necessary.
objectType - the object type associated with this block.
parentObjectType - the object type of the parent object associated with this block.
parentObjectID - the ID of the parent object associated with this block.

DbBlockIterator

public DbBlockIterator(long[] block,
                       CachedPreparedStatement query,
                       int startIndex,
                       int endIndex,
                       int objectType,
                       int parentObjectType,
                       long parentObjectID,
                       boolean loadIDs)
Constructs a new DbBlockIterator.

Parameters:
block - the array of id's to iterate through.
query - the query used to select the block.
startIndex - the starting index in the block to being iteration at.
endIndex - the ending index in the set to end iteration at. This may or not be in the current block. If it ends after the current block, the next block will be loaded automatically as necessary.
objectType - the object type associated with this block.
parentObjectType - the object type of the parent object associated with this block.
parentObjectID - the ID of the parent object associated with this block.
loadIDs - load IDs instead of objects. This is primarily designed to be used for permission checking.

DbBlockIterator

public DbBlockIterator(EntityDescriptor[] block,
                       CachedPreparedStatement query,
                       int startIndex,
                       int endIndex,
                       int parentObjectType,
                       long parentObjectID)
Constructs a new DbBlockIterator.

Parameters:
block - the array of EntityDescriptor's to iterate through.
query - the query used to select the block.
startIndex - the starting index in the block to being iteration at.
endIndex - the ending index in the set to end iteration at. This may or not be in the current block. If it ends after the current block, the next block will be loaded automatically as necessary.
parentObjectType - the object type of the parent object associated with this block.
parentObjectID - the ID of the parent object associated with this block.
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator

hasPrevious

public boolean hasPrevious()

next

public java.lang.Object next()
                      throws java.util.NoSuchElementException
Specified by:
next in interface java.util.Iterator
Throws:
java.util.NoSuchElementException

nextID

public long nextID()

skipElement

public void skipElement()

previous

public java.lang.Object previous()

remove

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

setIndex

public void setIndex(long objectID)

iterator

public java.util.Iterator iterator()

getBlock

protected long[] getBlock(int startIndex)
                   throws java.lang.Exception
Throws:
java.lang.Exception

getEntityBlock

protected EntityDescriptor[] getEntityBlock(int startIndex)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

getNextElement

protected java.lang.Object getNextElement()
Returns the next element, or null if there are no more elements to return.

Returns:
the next element.

getPreviousElement

protected java.lang.Object getPreviousElement()
Returns the previous element, or null if there are no more elements to return.

Returns:
the previous element.

getElement

protected java.lang.Object getElement(int index)
Returns the element at the specified index

Parameters:
index - the index to get the element for
Returns:
the element or null if the index isn't valid

getObject

protected java.lang.Object getObject(long objectID,
                                     int objectType)
                              throws java.lang.Exception
Throws:
java.lang.Exception

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.