ojb.broker.accesslayer
Class RsIterator

java.lang.Object
  |
  +--ojb.broker.accesslayer.RsIterator
All Implemented Interfaces:
java.util.Iterator
Direct Known Subclasses:
ReportQueryRsIterator, SqlBasedRsIterator

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

RsIterator can be used to iterate over a jdbc ResultSet to retrieve persistent objects step-by-step and not all at once. In fact the PersistenceBroker::getCollectionByQuery(...) method uses a RsIterator internally to build up a Collection of objects NOTE: this code uses features that only JDBC 2.0 compliant Drivers support. It will NOT work with JDBC 1.0 Drivers (e.g. SUN's JdbcOdbcDriver) If you are forced to use such a driver, you can use code from the 0.1.30 release.

Author:
Thomas Mahler

Field Summary
protected static ObjectCache cache
           
protected  boolean hasCalledCheck
           
protected  boolean hasNext
           
protected  java.lang.Class itemProxyClass
          the proxy class to be used or null
protected  Logger logger
           
protected  PersistenceBrokerImpl m_broker
          reference to the PersistenceBroker
protected  ClassDescriptor m_mif
          the classdescriptor providing the mapping information
protected  java.lang.Object[] m_row
          this container holds the values of the current ro during materialisation
protected  java.sql.ResultSet m_rs
          the underlying resultset
 
Constructor Summary
protected RsIterator()
           
  RsIterator(Query query, ClassDescriptor mif, PersistenceBrokerImpl broker)
          RsIterator constructor.
 
Method Summary
protected  java.lang.Class getExtentClass()
           
protected  Identity getIdentityFromResultSet()
          returns an Identity object representing the current resultset row
protected  java.lang.Object getObjectFromResultSet()
          returns a fully materialized Object from the current row of the underlying resultset.
protected  java.lang.Object getProxyFromResultSet()
          Reads primary key information from current RS row and generates a corresponding Identity, and returns a proxy from the Identity.
 boolean hasNext()
          returns true if there are still more rows in the underlying ResultSet.
 java.lang.Object next()
          moves to the next row of the underlying ResultSet and returns the corresponding Object materialized from this row.
 void releaseDbResources()
          Release all internally used Database resources of the iterator.
 void remove()
          removing is not supported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected Logger logger

cache

protected static ObjectCache cache

m_broker

protected PersistenceBrokerImpl m_broker
reference to the PersistenceBroker


m_rs

protected java.sql.ResultSet m_rs
the underlying resultset


m_mif

protected ClassDescriptor m_mif
the classdescriptor providing the mapping information


itemProxyClass

protected java.lang.Class itemProxyClass
the proxy class to be used or null


m_row

protected java.lang.Object[] m_row
this container holds the values of the current ro during materialisation


hasCalledCheck

protected boolean hasCalledCheck

hasNext

protected boolean hasNext
Constructor Detail

RsIterator

protected RsIterator()

RsIterator

public RsIterator(Query query,
                  ClassDescriptor mif,
                  PersistenceBrokerImpl broker)
RsIterator constructor.

Parameters:
mif - ojb.broker.metadata.ClassDescriptor
Method Detail

getExtentClass

protected java.lang.Class getExtentClass()

hasNext

public boolean hasNext()
returns true if there are still more rows in the underlying ResultSet. Returns false if ResultSet is exhausted.

Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
                      throws java.util.NoSuchElementException
moves to the next row of the underlying ResultSet and returns the corresponding Object materialized from this row.

Specified by:
next in interface java.util.Iterator
java.util.NoSuchElementException

remove

public void remove()
removing is not supported

Specified by:
remove in interface java.util.Iterator

getIdentityFromResultSet

protected Identity getIdentityFromResultSet()
                                     throws PersistenceBrokerException
returns an Identity object representing the current resultset row

PersistenceBrokerException

getObjectFromResultSet

protected java.lang.Object getObjectFromResultSet()
                                           throws PersistenceBrokerException
returns a fully materialized Object from the current row of the underlying resultset. Works as follows: - read Identity from the primary key values of current row - check if Object is in cache - return cached object or read it from current row and put it in cache

PersistenceBrokerException

getProxyFromResultSet

protected java.lang.Object getProxyFromResultSet()
                                          throws PersistenceBrokerException
Reads primary key information from current RS row and generates a corresponding Identity, and returns a proxy from the Identity.

PersistenceBrokerException

releaseDbResources

public void releaseDbResources()
Release all internally used Database resources of the iterator. Clients must call this methods explicitely if the iterator is not exhausted by the client application. If the Iterator is exhauseted this method will be called implicitely.



Authors: Thomas Mahler and others. (C) 2000, 2001.
All rights reserved. Published under the Gnu Public License.
http://objectbridge.sourceforge.net
Version: 0.8.375, 2002-04-04