com.samskivert.jdbc.jora
Class Cursor<V>

java.lang.Object
  extended by com.samskivert.jdbc.jora.Cursor<V>

public class Cursor<V>
extends Object

Cursor is used for successive access to records fetched by SELECT statement. As far as records can be retrived from several derived tables (polymorphic form of select), this class can issue several requests to database. Cursor also provides methods for updating/deleting current record.


Field Summary
protected  Connection _conn
           
protected  V _currObject
           
protected  boolean _like
           
protected  FieldMask _qbeMask
           
protected  V _qbeObject
           
protected  String _query
           
protected  ResultSet _result
           
protected  Statement _stmt
           
protected  Table<V> _table
           
 
Constructor Summary
protected Cursor(Table<V> table, Connection conn, String query)
           
protected Cursor(Table<V> table, Connection conn, V obj, FieldMask mask, boolean like)
           
 
Method Summary
 void close()
          Close the Cursor, even if we haven't read all the possible objects.
 void delete()
          Delete current record pointed by cursor.
 V get()
          Returns the first element matched by this cursor or null if no elements were matched.
 V next()
          A cursor is initially positioned before its first row; the first call to next makes the first row the current row; the second call makes the second row the current row, etc.
 ArrayList<V> toArrayList()
          Store all objects returned by SELECT query into a list of Object.
 ArrayList<V> toArrayList(int maxElements)
          Extracts no more than maxElements records from database and store them into array.
 void update()
          Update current record pointed by cursor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_table

protected Table<V> _table

_conn

protected Connection _conn

_result

protected ResultSet _result

_query

protected String _query

_stmt

protected Statement _stmt

_currObject

protected V _currObject

_qbeObject

protected V _qbeObject

_qbeMask

protected FieldMask _qbeMask

_like

protected boolean _like
Constructor Detail

Cursor

protected Cursor(Table<V> table,
                 Connection conn,
                 String query)

Cursor

protected Cursor(Table<V> table,
                 Connection conn,
                 V obj,
                 FieldMask mask,
                 boolean like)
Method Detail

next

public V next()
       throws SQLException
A cursor is initially positioned before its first row; the first call to next makes the first row the current row; the second call makes the second row the current row, etc.

If an input stream from the previous row is open, it is implicitly closed. The ResultSet's warning chain is cleared when a new row is read.

Returns:
object constructed from fetched record or null if there are no more rows
Throws:
SQLException

get

public V get()
      throws SQLException
Returns the first element matched by this cursor or null if no elements were matched. Checks to ensure that no subsequent elements were matched by the query, logs a warning if there were spurious additional matches.

Throws:
SQLException

update

public void update()
            throws SQLException
Update current record pointed by cursor. This method can be called only after next() method, which returns non-null object. This objects is used to update current record fields.

If you are going to update or delete selected records, you should add "for update" clause to select statement. So parameter of jora.Table.select() statement should contain "for update" clause: record.table.Select("where name='xyz' for update");

Attention! Not all database drivers support update operation with cursor. This method will not work with such database drivers.

Throws:
SQLException

delete

public void delete()
            throws SQLException
Delete current record pointed by cursor. This method can be called only after next() method, which returns non-null object.

If you are going to update or delete selected records, you should add "for update" clause to select statement. So parameter of jora.Table.select() statement should contain "for update" clause: record.table.Select("where name='xyz' for update");

Attention! Not all database drivers support delete operation with cursor. This method will not work with such database drivers.

Throws:
SQLException

close

public void close()
           throws SQLException
Close the Cursor, even if we haven't read all the possible objects.

Throws:
SQLException

toArrayList

public ArrayList<V> toArrayList(int maxElements)
                         throws SQLException
Extracts no more than maxElements records from database and store them into array. It is possible to extract rest records by successive next() or toArray() calls. Selected objects should have now components of InputStream, Blob or Clob type, because their data will be not available after fetching next record.

Parameters:
maxElements - limitation for result array size (and also for number of fetched records)
Returns:
List with objects constructed from fetched records.
Throws:
SQLException

toArrayList

public ArrayList<V> toArrayList()
                         throws SQLException
Store all objects returned by SELECT query into a list of Object. Selected objects should have now components of InputStream, Blob or Clob type, because their data will be not available after fetching next record.

Returns:
Array with objects constructed from fetched records.
Throws:
SQLException


Copyright © 2000-2008 Michael Bayne. All Rights Reserved.