|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.ojb.broker.accesslayer.RsIterator
public class RsIterator
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: OJB is very strict in handling RsIterator instances. RsIterator is
bound very closely to the used PersistenceBroker
instance.
Thus if you do a
- PersistenceBroker.close()
- PersistenceBroker.commitTransaction()
- PersistenceBroker.abortTransaction()
call, the current RsIterator instance resources will be cleaned up automatic
and invalidate current instance.
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.
Nested Class Summary | |
---|---|
static class |
RsIterator.ResourceClosedException
|
static class |
RsIterator.ResourceNotClosedException
|
static class |
RsIterator.ResourceWrapper
Wraps a RsIterator instance as WeakReference . |
Field Summary | |
---|---|
private boolean |
advancedJDBCSupport
|
private PBLifeCycleEvent |
afterLookupEvent
|
private boolean |
autoRelease
Flag that indicates if the automatic resource cleanup should be done or not. |
private boolean |
disableLifeCycleEvents
if true do not fire PBLifeCycleEvent. |
private boolean |
hasNext
return value of the previously called hasNext from m_rs |
private static String |
INFO_MSG
|
private boolean |
JDBCSupportAssessed
|
protected Logger |
logger
|
private PersistenceBrokerImpl |
m_broker
reference to the PersistenceBroker |
private MaterializationCache |
m_cache
|
private int |
m_current_row
|
private boolean |
m_hasCalledCheck
flag that indicates wether hasNext on m_rs has allready been called |
private boolean |
m_inBatchedMode
prefetch relationship: inBatchedMode true prevents releasing of DbResources IN_LIMIT defines the max number of values of sql (IN) , -1 for no limits |
private Class |
m_itemProxyClass
the proxy class to be used or null |
private Class |
m_itemTopLevelClass
the top-level class of the item objects |
private RsQueryObject |
m_queryObject
the underlying query object |
private Map |
m_row
this container holds the values of the current ro during materialisation |
private ResultSetAndStatement |
m_rsAndStmt
the underlying resultset |
private RsIterator.ResourceWrapper |
resourceListener
|
private boolean |
resourcesAreReleased
Tracks whether or not the resources that are used by this class have been released. |
Constructor Summary | |
---|---|
RsIterator(RsQueryObject queryObject,
PersistenceBrokerImpl broker)
RsIterator constructor. |
Method Summary | |
---|---|
boolean |
absolute(int row)
Moves the cursor to the given row number in the iterator. |
private boolean |
absoluteAdvanced(int row)
absolute for advancedJDBCSupport |
private boolean |
absoluteBasic(int row)
absolute for basicJDBCSupport |
protected void |
autoReleaseDbResources()
Internally used by this class to close used resources as soon as possible. |
protected int |
countedSize()
Answer the counted size |
void |
disableLifeCycleEvents()
Do not fire any PBLifeCycleEvent when reading next item. |
protected void |
finalize()
safety just in case someone leaks. |
int |
fullSize()
|
protected PBLifeCycleEvent |
getAfterLookupEvent()
|
protected PersistenceBrokerInternal |
getBroker()
|
protected MaterializationCache |
getCache()
|
ClassDescriptor |
getClassDescriptor()
|
protected JdbcConnectionDescriptor |
getConnectionDescriptor()
|
protected DescriptorRepository |
getDescriptorRepository()
Return the DescriptorRepository |
protected boolean |
getHasNext()
|
protected Identity |
getIdentityFromResultSet()
returns an Identity object representing the current resultset row |
protected Class |
getItemProxyClass()
|
protected Object |
getObjectFromResultSet()
returns a fully materialized Object from the current row of the underlying resultset. |
private Collection |
getOwnerObjects()
read all objects of this iterator. |
protected Object |
getProxyFromResultSet()
Reads primary key information from current RS row and generates a corresponding Identity, and returns a proxy from the Identity. |
protected RsQueryObject |
getQueryObject()
|
protected Map |
getRow()
|
protected ResultSetAndStatement |
getRsAndStmt()
|
protected Class |
getTopLevelClass()
|
boolean |
hasNext()
returns true if there are still more rows in the underlying ResultSet. |
protected boolean |
isHasCalledCheck()
|
protected boolean |
isInBatchedMode()
|
Object |
next()
moves to the next row of the underlying ResultSet and returns the corresponding Object materialized from this row. |
private void |
prefetchRelationships(Query query)
prefetch defined relationships requires JDBC level 2.0, does not work with Arrays |
boolean |
relative(int row)
Moves the cursor a relative number of rows, either positive or negative. |
(package private) void |
release(boolean removeResourceListener)
|
void |
releaseDbResources()
Release all internally used Database resources of the iterator. |
void |
remove()
removing is not supported |
protected void |
setAfterLookupEvent(PBLifeCycleEvent afterLookupEvent)
|
void |
setAutoRelease(boolean autoRelease)
Allows user to switch off/on automatic resource cleanup. |
protected void |
setBroker(PersistenceBrokerImpl broker)
|
protected void |
setCache(MaterializationCache cache)
|
protected void |
setHasCalledCheck(boolean hasCalledCheck)
|
protected void |
setHasNext(boolean hasNext)
|
protected void |
setInBatchedMode(boolean inBatchedMode)
|
protected void |
setItemProxyClass(Class itemProxyClass)
|
protected void |
setQueryObject(RsQueryObject queryObject)
|
protected void |
setRow(Map row)
|
protected void |
setRsAndStmt(ResultSetAndStatement rsAndStmt)
|
int |
size()
|
private boolean |
supportsAdvancedJDBCCursorControl()
with a new batch of JDBC 3.0 drivers coming out we can't just check for begins with 2, we need to check the actual version and see if it's greater than or equal to 2. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Logger logger
private static final String INFO_MSG
private PBLifeCycleEvent afterLookupEvent
private MaterializationCache m_cache
private PersistenceBrokerImpl m_broker
private ResultSetAndStatement m_rsAndStmt
private RsQueryObject m_queryObject
private Class m_itemProxyClass
private Class m_itemTopLevelClass
private Map m_row
private boolean m_hasCalledCheck
private boolean m_inBatchedMode
private boolean hasNext
private boolean advancedJDBCSupport
private boolean JDBCSupportAssessed
private int m_current_row
private boolean resourcesAreReleased
private boolean autoRelease
private RsIterator.ResourceWrapper resourceListener
private boolean disableLifeCycleEvents
Constructor Detail |
---|
public RsIterator(RsQueryObject queryObject, PersistenceBrokerImpl broker)
queryObject
- query objectbroker
- the broker we should use.Method Detail |
---|
protected Class getTopLevelClass()
public boolean hasNext()
hasNext
in interface Iterator
public Object next() throws NoSuchElementException
next
in interface Iterator
NoSuchElementException
public void remove()
remove
in interface Iterator
private Collection getOwnerObjects()
private void prefetchRelationships(Query query)
protected Identity getIdentityFromResultSet() throws PersistenceBrokerException
PersistenceBrokerException
protected Object getObjectFromResultSet() throws PersistenceBrokerException
PersistenceBrokerException
protected Object getProxyFromResultSet() throws PersistenceBrokerException
PersistenceBrokerException
- if there was an error creating the proxy classprivate boolean supportsAdvancedJDBCCursorControl()
protected int countedSize() throws PersistenceBrokerException
PersistenceBrokerException
public int size() throws PersistenceBrokerException
size
in interface OJBIterator
PersistenceBrokerException
public int fullSize() throws PersistenceBrokerException
fullSize
in interface OJBIterator
PersistenceBrokerException
public boolean absolute(int row) throws PersistenceBrokerException
absolute
in interface OJBIterator
row
- the row to move to in this iterator, by absolute number
PersistenceBrokerException
private boolean absoluteBasic(int row)
row
- private boolean absoluteAdvanced(int row)
row
- public boolean relative(int row) throws PersistenceBrokerException
relative
in interface OJBIterator
row
- the row to move to in this iterator, by relative number
PersistenceBrokerException
public void releaseDbResources()
releaseDbResources
in interface OJBIterator
void release(boolean removeResourceListener)
protected void autoReleaseDbResources()
public void setAutoRelease(boolean autoRelease)
releaseDbResources()
.
protected DescriptorRepository getDescriptorRepository()
protected JdbcConnectionDescriptor getConnectionDescriptor()
protected void finalize()
finalize
in class Object
public String toString()
toString
in class Object
public ClassDescriptor getClassDescriptor()
protected void setBroker(PersistenceBrokerImpl broker)
protected PersistenceBrokerInternal getBroker()
protected void setRsAndStmt(ResultSetAndStatement rsAndStmt)
protected ResultSetAndStatement getRsAndStmt()
protected void setQueryObject(RsQueryObject queryObject)
protected RsQueryObject getQueryObject()
protected void setItemProxyClass(Class itemProxyClass)
protected Class getItemProxyClass()
protected void setRow(Map row)
protected Map getRow()
protected void setCache(MaterializationCache cache)
protected MaterializationCache getCache()
protected void setAfterLookupEvent(PBLifeCycleEvent afterLookupEvent)
protected PBLifeCycleEvent getAfterLookupEvent()
protected void setHasCalledCheck(boolean hasCalledCheck)
protected boolean isHasCalledCheck()
protected void setHasNext(boolean hasNext)
protected boolean getHasNext()
protected void setInBatchedMode(boolean inBatchedMode)
protected boolean isInBatchedMode()
public void disableLifeCycleEvents()
OJBIterator
disableLifeCycleEvents
in interface OJBIterator
OJBIterator.disableLifeCycleEvents()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |