Class PamCursor

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

public abstract class PamCursor extends 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:
  • Constructor Details

  • Method Details

    • getTableDefinition

      public EmptyTableDefinition getTableDefinition()
    • getCurrentConnection

      public PamConnection getCurrentConnection()
    • setCurrentConnection

      public void setCurrentConnection(PamConnection currentConnection)
    • getSelectString

      public String getSelectString(SQLTypes sqlTypes, 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
    • getSelectString

      public String getSelectString(SQLTypes sqlTypes, String stmt)
      Generate a standard SQL select string using the passed statement. Will add SELECT in front of the stmt and FROM {database name} at the end. The other getSelectString methods automatically add in all the column names. This method is useful if you only need values from a single column
      Parameters:
      sqlTypes -
      stmt - the SQL statement to execute
      Returns:
      SQL string
    • getUpdateString

      public String getUpdateString(SQLTypes sqlTypes)
    • getInsertString

      public String getInsertString(SQLTypes sqlTypes)
    • getSelectString

      public String getSelectString(SQLTypes sqlTypes, boolean includeKeys, boolean includeCounters, 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(PamConnection 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 SQLException
      Move data from the table definition down to the cursor
      Parameters:
      includeCounters - counters are included in the query
      Throws:
      SQLException
    • moveDataToTableDef

      public void moveDataToTableDef(boolean includeCounters) throws SQLException
      Move data from the cursor to the table definition
      Parameters:
      includeCounters - include counter data
      Throws:
      SQLException
    • immediateInsert

      public int immediateInsert(PamConnection 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
    • immediateUpdate

      public boolean immediateUpdate(PamConnection 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.
    • closeCursors

      public void closeCursors()
    • openReadOnlyCursor

      public ResultSet openReadOnlyCursor(PamConnection connection, String clause)
      Reads all columns from the table, using the optional passed clause
      Parameters:
      connection - Connection to the database
      clause - WHERE ... and ORDER BY clause.
      Returns:
    • openReadOnlyCursorWithStatement

      public ResultSet openReadOnlyCursorWithStatement(PamConnection connection, String stmt)
      Executes an SQL statement passed. Note that the SELECT and FROM keywords are automatically added by this method, and should not be part of the stmt variable
      Parameters:
      connection - Connection to the database
      stmt - the SQL statement to execute
      Returns:
    • executeReadOnlyStatement

      public ResultSet executeReadOnlyStatement(PamConnection connection, String sqlString)
      Executes the passed SQL statement as read-only
      Parameters:
      connection - Connection to the database
      sqlString - SQL string to execute
      Returns:
      the ResultSet of the SQL string
    • openScrollableCursor

      public abstract boolean openScrollableCursor(PamConnection connection, boolean includeKeys, boolean includeCounters, 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(String columnLabel)
    • first

      public abstract boolean first()
    • getRow

      public abstract int getRow() throws 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:
      SQLException - if a database error occurs
    • getUTCTime

      public long getUTCTime()
      Get the UTC time from the cursor data. This may not be available (e.g. because the table doesn't have it) in which case 0 will be returned, otherwise it's a useful function for searchign for data.
      Returns:
    • getObject

      public abstract Object getObject(int columnIndex)
    • getBoolean

      public abstract boolean getBoolean(int columnIndex)
    • getByte

      public abstract byte getByte(int columnIndex)
    • getDate

      public abstract Date getDate(int columnIndex, Calendar cal)
    • getDate

      public abstract 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 RowId getRowId(int columnIndex)
    • getString

      public abstract String getString(int columnIndex)
    • getTime

      public abstract Time getTime(int columnIndex)
    • getTimestampMillis

      public abstract Long getTimestampMillis(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, Object x) throws SQLException
      Throws:
      SQLException
    • updateBoolean

      public abstract void updateBoolean(int columnIndex, boolean x) throws SQLException
      Throws:
      SQLException
    • updateByte

      public abstract void updateByte(int columnIndex, byte x) throws SQLException
      Throws:
      SQLException
    • updateInt

      public abstract void updateInt(int columnIndex, int x) throws SQLException
      Throws:
      SQLException
    • updateLong

      public abstract void updateLong(int columnIndex, long x) throws SQLException
      Throws:
      SQLException
    • updateNull

      public abstract void updateNull(int columnIndex) throws SQLException
      Throws:
      SQLException
    • updateRow

      public abstract void updateRow() throws SQLException
      Throws:
      SQLException
    • updateString

      public abstract void updateString(int columnIndex, String x) throws SQLException
      Throws:
      SQLException
    • updateShort

      public abstract void updateShort(int columnIndex, short x) throws SQLException
      Throws:
      SQLException
    • updateTimestamp

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