generalDatabase.pamCursor
Class PamCursor

java.lang.Object
  extended by generalDatabase.pamCursor.PamCursor
Direct Known Subclasses:
NonScrollablePamCursor, ScrollablePamCursor

public abstract class PamCursor
extends java.lang.Object

Class to generate Cursors for databases which can directly support scrollable cursors and ones which cannot.

This will directly implement a lot of the functions of the ResultSet interface, but not all of them - life is too short. It will however use the same names and behave in the same way.

Author:
Doug Gillespie
See Also:
NonScrollablePamCursor, ScrollablePamCursor

Field Summary
private  java.sql.Connection currentConnection
           
private  java.sql.PreparedStatement preparedInsertStatement
           
private  java.sql.PreparedStatement preparedUpdateStatement
           
private  EmptyTableDefinition tableDefinition
           
 
Constructor Summary
PamCursor(EmptyTableDefinition tableDefinition)
           
 
Method Summary
abstract  boolean absolute(int row)
          Go t0 an absolute row number
abstract  void afterLast()
           
abstract  void beforeFirst()
           
abstract  void close()
           
private  void closeCursors()
           
abstract  boolean closeScrollableCursor()
          Close the scrollable cursor.
abstract  void deleteRow()
           
protected  void finalize()
           
abstract  int findColumn(java.lang.String columnLabel)
           
abstract  boolean first()
           
abstract  boolean getBoolean(int columnIndex)
           
abstract  byte getByte(int columnIndex)
           
 java.sql.Connection getCurrentConnection()
           
abstract  java.sql.Date getDate(int columnIndex)
           
abstract  java.sql.Date getDate(int columnIndex, java.util.Calendar cal)
           
abstract  double getDouble(int columnIndex)
           
abstract  float getFloat(int columnIndex)
           
 java.lang.String getInsertString()
           
abstract  int getInt(int columnIndex)
           
(package private) abstract  int getLastDatabaseIndex(java.sql.Connection connection, java.sql.PreparedStatement preparedInsertStatement)
          Gets called from ImmediateInsert to get the last database index using a couple of alternate methods.
abstract  long getLong(int columnIndex)
           
abstract  java.lang.Object getObject(int columnIndex)
           
abstract  int getRow()
          Retrieves the current row number.
abstract  java.sql.RowId getRowId(int columnIndex)
           
 java.lang.String getSelectString(boolean includeKeys, boolean includeCounters, boolean orderById)
          Generate a standard SQL select string for everything in the table.
 java.lang.String getSelectString(boolean includeKeys, boolean includeCounters, java.lang.String clause)
          Generate an SQL select string with an optional clause which may include WHERE and ORDER
abstract  java.lang.String getString(int columnIndex)
           
 EmptyTableDefinition getTableDefinition()
           
abstract  java.sql.Time getTime(int columnIndex)
           
abstract  java.sql.Timestamp getTimestamp(int columnIndex)
           
 java.lang.String getUpdateString()
           
 int immediateInsert(java.sql.Connection connection)
          Do an immediate insert of data which should already have been put into the data objects of the table definition.
 boolean immediateUpdate(java.sql.Connection connection)
          Do an immediate update of a single item which already has it's data in the table definition fields.
abstract  int insertRow(boolean getIndex)
          Insert row statement
abstract  boolean isAfterLast()
           
abstract  boolean isBeforeFirst()
           
abstract  boolean isClosed()
           
abstract  boolean isFirst()
           
abstract  boolean isLast()
           
abstract  boolean last()
           
 void moveDataToCursor(boolean includeCounters)
          Move data from the table definition down to the cursor
 void moveDataToTableDef(boolean includeCounters)
          Move data from the cursor to the table definition
abstract  void moveToCurrentRow()
           
abstract  void moveToInsertRow()
           
abstract  boolean next()
           
 boolean openInsertCursor(java.sql.Connection connection)
          Open a cursor for inserting data using a non-scrollable cursor.
 java.sql.ResultSet openReadOnlyCursor(java.sql.Connection connection, java.lang.String clause)
           
abstract  boolean openScrollableCursor(java.sql.Connection connection, boolean includeKeys, boolean includeCounters, java.lang.String clause)
          Open a scrollable cursor
private  boolean prepareUpdateStatement(java.sql.Connection connection)
          Prepare a prepared update statement for the cursor which can be reused so long as the connection doesn't change.
abstract  boolean previous()
           
abstract  void refreshRow()
           
abstract  boolean rowDeleted()
           
abstract  boolean rowInserted()
           
abstract  boolean rowUpdated()
           
 void setCurrentConnection(java.sql.Connection currentConnection)
           
abstract  void updateBoolean(int columnIndex, boolean x)
           
abstract  void updateByte(int columnIndex, byte x)
           
abstract  boolean updateDatabase()
          Push everything down onto the database
abstract  void updateInt(int columnIndex, int x)
           
abstract  void updateLong(int columnIndex, long x)
           
abstract  void updateNull(int columnIndex)
           
abstract  void updateObject(int columnIndex, java.lang.Object x)
           
abstract  void updateRow()
           
abstract  void updateShort(int columnIndex, short x)
           
abstract  void updateString(int columnIndex, java.lang.String x)
           
abstract  void updateTimestamp(int columnIndex, java.sql.Timestamp x)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableDefinition

private EmptyTableDefinition tableDefinition

currentConnection

private java.sql.Connection currentConnection

preparedInsertStatement

private java.sql.PreparedStatement preparedInsertStatement

preparedUpdateStatement

private java.sql.PreparedStatement preparedUpdateStatement
Constructor Detail

PamCursor

public PamCursor(EmptyTableDefinition tableDefinition)
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getTableDefinition

public EmptyTableDefinition getTableDefinition()

getCurrentConnection

public java.sql.Connection getCurrentConnection()

setCurrentConnection

public void setCurrentConnection(java.sql.Connection currentConnection)

getSelectString

public java.lang.String getSelectString(boolean includeKeys,
                                        boolean includeCounters,
                                        boolean orderById)
Generate a standard SQL select string for everything in the table.

No ordering of selecting at this stage.

Parameters:
includeKeys - include items which are primary keys (i.e. the index)
includeCounters - include items which are counters
orderById - add a standard ORDER BY Id at the end of the string
Returns:
SQL string

getUpdateString

public java.lang.String getUpdateString()

getInsertString

public java.lang.String getInsertString()

getSelectString

public java.lang.String getSelectString(boolean includeKeys,
                                        boolean includeCounters,
                                        java.lang.String clause)
Generate an SQL select string with an optional clause which may include WHERE and ORDER

Parameters:
includeKeys - include items which are primary keys (i.e. the index)
includeCounters - include items which are counters
clause - WHERE ... and ORDER BY clause.
Returns:
SQL string

openInsertCursor

public boolean openInsertCursor(java.sql.Connection connection)
Open a cursor for inserting data using a non-scrollable cursor.

These are generally faster than scrollable cursors, so this is in the abstract super class PamCursor. Should for any reason someone convince me that it's better done in a different way for some databases, this function can be easily overridden.

One thing which is more database specific is the way in which index material are retrieved for different database types.

Parameters:
connection - Database connection
includeCounters - include counters in query
Returns:
true if cursor created sucessfully.

moveDataToCursor

public void moveDataToCursor(boolean includeCounters)
                      throws java.sql.SQLException
Move data from the table definition down to the cursor

Parameters:
includeCounters - counters are included in the query
Throws:
java.sql.SQLException

moveDataToTableDef

public void moveDataToTableDef(boolean includeCounters)
                        throws java.sql.SQLException
Move data from the cursor to the table definition

Parameters:
includeCounters - include counter data
Throws:
java.sql.SQLException

immediateInsert

public int immediateInsert(java.sql.Connection connection)
Do an immediate insert of data which should already have been put into the data objects of the table definition.

Primarily used in real time data collection, called from SQLLogging.

Parameters:
connection - Database connection
Returns:
the new database Index number

prepareUpdateStatement

private boolean prepareUpdateStatement(java.sql.Connection connection)
Prepare a prepared update statement for the cursor which can be reused so long as the connection doesn't change.

Parameters:
connection - database connection
Returns:
true if all seems OK

immediateUpdate

public boolean immediateUpdate(java.sql.Connection connection)
Do an immediate update of a single item which already has it's data in the table definition fields.

Use a single parameterised cursor statement.

Parameters:
connection -
Returns:
true if successful.

getLastDatabaseIndex

abstract int getLastDatabaseIndex(java.sql.Connection connection,
                                  java.sql.PreparedStatement preparedInsertStatement)
Gets called from ImmediateInsert to get the last database index using a couple of alternate methods.

Parameters:
connection -
preparedInsertStatement -
Returns:

closeCursors

private void closeCursors()

openReadOnlyCursor

public java.sql.ResultSet openReadOnlyCursor(java.sql.Connection connection,
                                             java.lang.String clause)

openScrollableCursor

public abstract boolean openScrollableCursor(java.sql.Connection connection,
                                             boolean includeKeys,
                                             boolean includeCounters,
                                             java.lang.String clause)
Open a scrollable cursor

Parameters:
connection - database connection
includeKeys - include keys
includeCounters - inlcude counters
clause - selection and ordering clause.
Returns:
true if successfully opened.

closeScrollableCursor

public abstract boolean closeScrollableCursor()
Close the scrollable cursor.

Returns:
true if no exception.

updateDatabase

public abstract boolean updateDatabase()
Push everything down onto the database

Returns:
true if no errors or exceptions.

absolute

public abstract boolean absolute(int row)
Go t0 an absolute row number

Note that row numbers are 1 indexed.

Parameters:
row - Row number
Returns:
true if the row is accessed.

afterLast

public abstract void afterLast()

beforeFirst

public abstract void beforeFirst()

close

public abstract void close()

deleteRow

public abstract void deleteRow()

findColumn

public abstract int findColumn(java.lang.String columnLabel)

first

public abstract boolean first()

getRow

public abstract int getRow()
                    throws java.sql.SQLException
Retrieves the current row number. The first row is number 1, the second number 2, and so on.

Returns:
the current Row number or 0 if there is no current row
Throws:
java.sql.SQLException - if a database error occurs

getObject

public abstract java.lang.Object getObject(int columnIndex)

getBoolean

public abstract boolean getBoolean(int columnIndex)

getByte

public abstract byte getByte(int columnIndex)

getDate

public abstract java.sql.Date getDate(int columnIndex,
                                      java.util.Calendar cal)

getDate

public abstract java.sql.Date getDate(int columnIndex)

getDouble

public abstract double getDouble(int columnIndex)

getFloat

public abstract float getFloat(int columnIndex)

getInt

public abstract int getInt(int columnIndex)

getLong

public abstract long getLong(int columnIndex)

getRowId

public abstract java.sql.RowId getRowId(int columnIndex)

getString

public abstract java.lang.String getString(int columnIndex)

getTime

public abstract java.sql.Time getTime(int columnIndex)

getTimestamp

public abstract java.sql.Timestamp getTimestamp(int columnIndex)

isAfterLast

public abstract boolean isAfterLast()

isBeforeFirst

public abstract boolean isBeforeFirst()

isClosed

public abstract boolean isClosed()

isFirst

public abstract boolean isFirst()

isLast

public abstract boolean isLast()

last

public abstract boolean last()

moveToCurrentRow

public abstract void moveToCurrentRow()

moveToInsertRow

public abstract void moveToInsertRow()

insertRow

public abstract int insertRow(boolean getIndex)
Insert row statement

Parameters:
getIndex - set true if you want to return the new database index. Otherwise 0 will be returned.
Returns:
return the database iD for the newly inserted item, -1 for an error or 0 if no index requested.

next

public abstract boolean next()

previous

public abstract boolean previous()

refreshRow

public abstract void refreshRow()

rowDeleted

public abstract boolean rowDeleted()

rowInserted

public abstract boolean rowInserted()

rowUpdated

public abstract boolean rowUpdated()

updateObject

public abstract void updateObject(int columnIndex,
                                  java.lang.Object x)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

updateBoolean

public abstract void updateBoolean(int columnIndex,
                                   boolean x)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

updateByte

public abstract void updateByte(int columnIndex,
                                byte x)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

updateInt

public abstract void updateInt(int columnIndex,
                               int x)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

updateLong

public abstract void updateLong(int columnIndex,
                                long x)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

updateNull

public abstract void updateNull(int columnIndex)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

updateRow

public abstract void updateRow()
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

updateString

public abstract void updateString(int columnIndex,
                                  java.lang.String x)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

updateShort

public abstract void updateShort(int columnIndex,
                                 short x)
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

updateTimestamp

public abstract void updateTimestamp(int columnIndex,
                                     java.sql.Timestamp x)
                              throws java.sql.SQLException
Throws:
java.sql.SQLException