velosurf.context
Class RowIterator

java.lang.Object
  |
  +--velosurf.context.RowIterator
All Implemented Interfaces:
DataAccessor, java.util.Iterator

public class RowIterator
extends java.lang.Object
implements java.util.Iterator, DataAccessor

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
protected  java.util.List mColumnNames
          Column names in sequential order
protected  Pooled mPooledStatement
          the statement
protected  Entity mResultEntity
          the resulting entity
protected  java.sql.ResultSet mResultSet
          the result set
protected static boolean sFillInstance
          whether or not all instance fields are automatically filled TODO : should depend upon some init param
 
Constructor Summary
RowIterator(Pooled inPooledStatement, java.sql.ResultSet inResultSet, Entity inResultEntity)
          Build a new RowIterator
 
Method Summary
protected  boolean dataAvailable()
          check if some data is available
 java.lang.Object get(int inCol)
          returns the value of a column specified by its order (starting at 1, as for ResultSet.get())
 java.lang.Object get(java.lang.Object inKey)
          generic getter for values of the current row.
 int getInt(int inCol)
          returns the value of a column specified by its order (starting at 1, as for ResultSet.get())
 int getInt(java.lang.Object inKey)
          returns the value of a column specified by its name
 java.lang.String getString(int inCol)
          returns the value of a column specified by its order (starting at 1, as for ResultSet.get())
 java.lang.String getString(java.lang.Object inKey)
          returns the value of a column specified by its name
 boolean hasNext()
          Returns true if the iteration has more elements.
 java.lang.Object 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, registerNatives, toString, wait, wait, wait
 

Field Detail

mPooledStatement

protected Pooled mPooledStatement
the statement

mResultSet

protected java.sql.ResultSet mResultSet
the result set

mResultEntity

protected Entity mResultEntity
the resulting entity

mColumnNames

protected java.util.List mColumnNames
Column names in sequential order

sFillInstance

protected static boolean sFillInstance
whether or not all instance fields are automatically filled TODO : should depend upon some init param
Constructor Detail

RowIterator

public RowIterator(Pooled inPooledStatement,
                   java.sql.ResultSet inResultSet,
                   Entity inResultEntity)
Build a new RowIterator
Parameters:
inPooledStatement - the sql statement
inResultSet - the resultset
inResultEntity - 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
Returns:
true if the iterator has more elements.

next

public java.lang.Object next()
Returns the next element in the iteration.

Specified by:
next in interface java.util.Iterator
Returns:
an Instance if a resulting entity has been specified, or a reference to myself

remove

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

get

public java.lang.Object get(java.lang.Object inKey)
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 DataAccessor
Parameters:
inKey - the name of an existing column or attribute
Returns:
an entity, an attribute reference, an instance, a string or null

get

public java.lang.Object get(int inCol)
returns the value of a column specified by its order (starting at 1, as for ResultSet.get())
Parameters:
inCol - the index of the wanted column (starting at 1)
Returns:
the value of the specified column, as a String

getInt

public int getInt(java.lang.Object inKey)
returns the value of a column specified by its name
Parameters:
inKey - the name of the wanted column
Returns:
the value of the specified column, as an int

getInt

public int getInt(int inCol)
returns the value of a column specified by its order (starting at 1, as for ResultSet.get())
Parameters:
inCol - the index of the wanted column (starting at 1)
Returns:
the value of the specified column, as an int

getString

public java.lang.String getString(java.lang.Object inKey)
returns the value of a column specified by its name
Parameters:
inKey - the name of the wanted column
Returns:
the value of the specified column, as a string

getString

public java.lang.String getString(int inCol)
returns the value of a column specified by its order (starting at 1, as for ResultSet.get())
Parameters:
inCol - the index of the wanted column (starting at 1)
Returns:
the value of the specified column, as a string

dataAvailable

protected 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