sqlj.runtime.ref
Class ScrollableResultSetIterImpl

java.lang.Object
  |
  +--sqlj.runtime.ref.ResultSetIterImpl
        |
        +--sqlj.runtime.ref.ScrollableResultSetIterImpl

public class ScrollableResultSetIterImpl
extends ResultSetIterImpl
implements Scrollable

The result set iter(ator) impl(ementation) class implements the functionality of both a positioned iterator, and a named iterator. However, it does not directly implement either of these interfaces. Rather, the translator will generate iterator classes which subclass this class and implement only the iterator interface that they were declared to implement (thus avoiding iterators which appear to be both positional and named).

This class is used internally by the reference translator code generation. It is expected that clients will not directly reference this class.

See Also:
ScrollableResultSetIterImpl, PositionedIterator, NamedIterator, ForUpdate, Scrollable

Fields inherited from class sqlj.runtime.ref.ResultSetIterImpl
resultSet
 
Constructor Summary
ScrollableResultSetIterImpl(sqlj.runtime.profile.RTResultSet rs)
          Creates a new scrollable result set iter impl object that uses data found in the passed result set.
ScrollableResultSetIterImpl(sqlj.runtime.profile.RTResultSet rs, int numColumns)
          Creates a new result set iter impl object that uses data found in the passed result set.
 
Method Summary
 boolean absolute(int row)
          Moves the iterator object to the given row number in the result set.
 void afterLast()
          Moves the iterator object to the end of the result set, just after the last row.
 void beforeFirst()
          Moves the iterator object to the front of the result set, just before the first row.
 boolean first()
          Moves the iterator object to the first row in the result set.
 int getFetchDirection()
          Retrieves the direction for fetching rows from database tables for this iterator object.
 boolean isAfterLast()
          Indicates whether the iterator object is after the last row in the result set.
 boolean isBeforeFirst()
          Indicates whether the iterator object is before the first row in the result set.
 boolean isFirst()
          Indicates whether the iterator object is on the first row of the result set.
 boolean isLast()
          Indicates whether the iterator object is on the last row of the result set.
 boolean last()
          Moves the iterator object to the last row in the result set.
 boolean previous()
          Moves the iterator object to the previous row in the result set.
 boolean relative(int rows)
          Moves the iterator object a relative number of rows, either positive or negative.
 void setFetchDirection(int direction)
          Gives the SQLJ runtime a hint as to the direction in which rows of this iterator object are processed.
 
Methods inherited from class sqlj.runtime.ref.ResultSetIterImpl
checkColumns, clearWarnings, close, endFetch, finalize, findColumn, getCursorName, getFetchSize, getResultSet, getSensitivity, getWarnings, isClosed, next, setFetchSize
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScrollableResultSetIterImpl

public ScrollableResultSetIterImpl(sqlj.runtime.profile.RTResultSet rs)
Creates a new scrollable result set iter impl object that uses data found in the passed result set.

ScrollableResultSetIterImpl

public ScrollableResultSetIterImpl(sqlj.runtime.profile.RTResultSet rs,
                                   int numColumns)
                            throws java.sql.SQLException
Creates a new result set iter impl object that uses data found in the passed result set. Verifies that the passed result set contains the same number of columns as is passed in the numColumns parameter.

Note: If a SQLException is raised by the constructor, the passed result set is automatically closed.

Parameters:
rs - the underlying result set
numColumns - the expected number of columns in the result set
Throws:
java.sql.SQLException - if the result set does not contain the expected number of columns
See Also:
ResultSetIterImpl.checkColumns(sqlj.runtime.profile.RTResultSet, int)
Method Detail

absolute

public boolean absolute(int row)
                 throws java.sql.SQLException
Moves the iterator object to the given row number in the result set.

If the row number is positive, the iterator object moves to the given row number with respect to the beginning of the result set. The first row is row 1, the second is row 2, and so on.

If the given row number is negative, the iterator object moves to an absolute row position with respect to the end of the result set. For example, calling absolute(-1) positions the iterator object on the last row, absolute(-2) indicates the next-to-last row, and so on.

An attempt to position the iterator object beyond the first/last row in the result set leaves the iterator object before/after the first/last row, respectively.

Note: Calling absolute(1) is the same as calling first(). Calling absolute(-1) is the same as calling last().

Specified by:
absolute in interface Scrollable
Returns:
true if the iterator object is on the result set; false otherwise
Throws:
java.sql.SQLException - if a database access error occurs or row is 0

afterLast

public void afterLast()
               throws java.sql.SQLException
Moves the iterator object to the end of the result set, just after the last row. Has no effect if the result set contains no rows.
Specified by:
afterLast in interface Scrollable
Throws:
java.sql.SQLException - if a database access error occurs

beforeFirst

public void beforeFirst()
                 throws java.sql.SQLException
Moves the iterator object to the front of the result set, just before the first row. Has no effect if the result set contains no rows.
Specified by:
beforeFirst in interface Scrollable
Throws:
java.sql.SQLException - if a database access error occurs

first

public boolean first()
              throws java.sql.SQLException
Moves the iterator object to the first row in the result set.
Specified by:
first in interface Scrollable
Returns:
true if the iterator object is on a valid row; false if there are no rows in the result set
Throws:
java.sql.SQLException - if a database access error occurs

getFetchDirection

public int getFetchDirection()
                      throws java.sql.SQLException
Retrieves the direction for fetching rows from database tables for this iterator object. If this iterator object has not set a fetch direction by calling the method setFetchDirection, the return value is implementation-specific.
Specified by:
getFetchDirection in interface Scrollable
Returns:
the fetch direction for this iterator object.
Throws:
java.sql.SQLException - if a database access error occurs.

isAfterLast

public boolean isAfterLast()
                    throws java.sql.SQLException
Indicates whether the iterator object is after the last row in the result set.
Specified by:
isAfterLast in interface Scrollable
Returns:
true if the iterator object is after the last row, false otherwise. Returns false when the result set contains no rows.
Throws:
java.sql.SQLException - if a database access error occurs

isBeforeFirst

public boolean isBeforeFirst()
                      throws java.sql.SQLException
Indicates whether the iterator object is before the first row in the result set.
Specified by:
isBeforeFirst in interface Scrollable
Returns:
true if the iterator object is before the first row, false otherwise. Returns false when the result set contains no rows.
Throws:
java.sq1l.SQLException - if a database access error occurs

isFirst

public boolean isFirst()
                throws java.sql.SQLException
Indicates whether the iterator object is on the first row of the result set.
Specified by:
isFirst in interface Scrollable
Returns:
true if the iterator object is on the first row, false otherwise.
Throws:
java.sql.SQLException - - if a database access error occurs

isLast

public boolean isLast()
               throws java.sql.SQLException
Indicates whether the iterator object is on the last row of the result set.

Note: Calling the method isLast may be expensive because the SQLJ driver might need to fetch ahead one row in order to determine whether the current row is the last row in the result set.

Specified by:
isLast in interface Scrollable
Returns:
true if the iterator object is on the last row, false otherwise.
Throws:
java.sql.SQLException - if a database access error occurs

last

public boolean last()
             throws java.sql.SQLException
Moves the iterator object to the last row in the result set.
Specified by:
last in interface Scrollable
Returns:
true if the iterator object is on a valid row; false if there are no rows in the result set
Throws:
java.sql.SQLException - if a database access error occurs.

previous

public boolean previous()
                 throws java.sql.SQLException
Moves the iterator object to the previous row in the result set.
Specified by:
previous in interface Scrollable
Returns:
true if the iterator object is on a valid row; false if it is off the result set
Throws:
java.sql.SQLException - if a database access error occurs

relative

public boolean relative(int rows)
                 throws java.sql.SQLException
Moves the iterator object a relative number of rows, either positive or negative. Attempting to move beyond the first/last row in the result set positions the iterator object before/after the first/last row. Calling relative(0) is valid, but does not change the iterator object position.
Specified by:
relative in interface Scrollable
Returns:
true if the iterator object is on a row; false otherwise
Throws:
java.sql.SQLException - if a database access error occurs, or there is no current row.

setFetchDirection

public void setFetchDirection(int direction)
                       throws java.sql.SQLException
Gives the SQLJ runtime a hint as to the direction in which rows of this iterator object are processed. The default value is sqlj.runtime.ResultSetIterator.FETCH_FORWARD.
Specified by:
setFetchDirection in interface Scrollable
Parameters:
direction - the initial direction for processing rows.
Throws:
java.sql.SQLException - if a database access error occurs, or the or the given direction is not one of ResultSetIterator.FETCH_FORWARD, ResultSetIterator.FETCH_REVERSE, or ResultSetIterator.FETCH_UNKNOWN.