velosurf.context
Class RowIterator

java.lang.Object
  extended by velosurf.context.RowIterator
All Implemented Interfaces:
java.util.Iterator, ReadOnlyMap

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

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  Pooled pooledStatement
          the statement
protected  Entity resultEntity
          the resulting entity
protected  java.sql.ResultSet resultSet
          the result set
protected  UserContext userContext
          user context
 
Constructor Summary
RowIterator(Pooled pooledStatement, java.sql.ResultSet resultSet, Entity resultEntity)
          Build a new RowIterator
 
Method Summary
protected  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 getRows()
          gets all the rows in a list of maps
 boolean hasNext()
          Returns true if the iteration has more elements.
 java.util.Set keySet()
           
 java.lang.Object next()
          Returns the next element in the iteration.
 void remove()
          not implemented.
 void setUserContext(UserContext context)
          set the localizer to be used to build instances
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pooledStatement

protected Pooled pooledStatement
the statement


resultSet

protected java.sql.ResultSet resultSet
the result set


resultEntity

protected Entity resultEntity
the resulting entity


userContext

protected UserContext userContext
user context

Constructor Detail

RowIterator

public RowIterator(Pooled 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
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 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 ReadOnlyMap
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 getRows()
gets all the rows in a list of maps

Returns:
a list of all the rows

keySet

public java.util.Set keySet()
Specified by:
keySet in interface ReadOnlyMap

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

setUserContext

public void setUserContext(UserContext context)
set the localizer to be used to build instances



~ooOoo~