velosurf.context
Class RowIterator

java.lang.Object
  extended by velosurf.context.RowIterator
All Implemented Interfaces:
java.util.Iterator<Instance>, RowHandler

public class RowIterator
extends java.lang.Object
implements java.util.Iterator<Instance>, RowHandler

This class is a context wrapper for ResultSets, and provides an iteration mecanism for #foreach loops, as long as getters for values of the current row.

Author:
Claude Brisson

Field Summary
(package private)  java.util.Set cachedSet
           
private  boolean isOver
          whether we reached the end
private  PooledStatement pooledStatement
          Source statement.
private  boolean prefetch
          whether we did prefetch a row
private  Entity resultEntity
          Resulting entity.
private  java.sql.ResultSet resultSet
          Wrapped result set.
 
Constructor Summary
RowIterator(PooledStatement pooledStatement, java.sql.ResultSet resultSet, Entity resultEntity)
          Build a new RowIterator.
 
Method Summary
private  boolean dataAvailable()
          Check if some data is available.
 java.lang.Object get(java.lang.Object key)
          Generic getter for values of the current row.
 java.util.List<Instance> getRows()
          Gets all the rows in a list of instances.
 java.util.List getScalars()
           
 boolean hasNext()
          Returns true if the iteration has more elements.
 java.util.List<java.lang.String> keyList()
           
 java.util.Set<java.lang.String> keySet()
          Get keys set.
 Instance next()
          Returns the next element in the iteration.
 void remove()
          not implemented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cachedSet

java.util.Set cachedSet

pooledStatement

private PooledStatement pooledStatement
Source statement.


resultSet

private java.sql.ResultSet resultSet
Wrapped result set.


resultEntity

private Entity resultEntity
Resulting entity.


prefetch

private boolean prefetch
whether we did prefetch a row


isOver

private boolean isOver
whether we reached the end

Constructor Detail

RowIterator

public RowIterator(PooledStatement pooledStatement,
                   java.sql.ResultSet resultSet,
                   Entity resultEntity)
Build a new RowIterator.

Parameters:
pooledStatement - the sql statement
resultSet - the resultset
resultEntity - the resulting entity (may be null)
Method Detail

hasNext

public boolean hasNext()
Returns true if the iteration has more elements.

Specified by:
hasNext in interface java.util.Iterator<Instance>
Returns:
true if the iterator has more elements.

next

public Instance next()
Returns the next element in the iteration.

Specified by:
next in interface java.util.Iterator<Instance>
Returns:
an Instance.

remove

public void remove()
not implemented.

Specified by:
remove in interface java.util.Iterator<Instance>

get

public java.lang.Object get(java.lang.Object key)
Generic getter for values of the current row. If no column corresponds to the specified name and a resulting entity has been specified, search among this entity's attributes. Note that this method is the only getter of RowIterator that cares about obfuscation - other specialized getters won't do any obfuscation.

Specified by:
get in interface RowHandler
Parameters:
key - the name of an existing column or attribute
Returns:
an entity, an attribute reference, an instance, a string or null

getRows

public java.util.List<Instance> getRows()
Gets all the rows in a list of instances.

Returns:
a list of all the rows

getScalars

public java.util.List getScalars()

keySet

public java.util.Set<java.lang.String> keySet()
Description copied from interface: RowHandler
Get keys set.

Specified by:
keySet in interface RowHandler
Returns:
keys set

keyList

public java.util.List<java.lang.String> keyList()

dataAvailable

private boolean dataAvailable()
                       throws java.sql.SQLException
Check if some data is available.

Returns:
true if some data is available (ie the internal ResultSet is not empty, and not before first row neither after last one)
Throws:
java.sql.SQLException - if the internal ResultSet is not happy


~ooOoo~