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 Link icon

  • Method Details Link icon

    • getTableDefinition Link icon

      public EmptyTableDefinition getTableDefinition()
    • getCurrentConnection Link icon

      public PamConnection getCurrentConnection()
    • setCurrentConnection Link icon

      public void setCurrentConnection(PamConnection currentConnection)
    • getSelectString Link icon

      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 Link icon

      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 Link icon

      public String getUpdateString(SQLTypes sqlTypes)
    • getInsertString Link icon

      public String getInsertString(SQLTypes sqlTypes)
    • getSelectString Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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

      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 Link icon

      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 Link icon

      public void closeCursors()
    • openReadOnlyCursor Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      public abstract boolean closeScrollableCursor()
      Close the scrollable cursor.
      Returns:
      true if no exception.
    • updateDatabase Link icon

      public abstract boolean updateDatabase()
      Push everything down onto the database
      Returns:
      true if no errors or exceptions.
    • absolute Link icon

      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 Link icon

      public abstract void afterLast()
    • beforeFirst Link icon

      public abstract void beforeFirst()
    • close Link icon

      public abstract void close()
    • deleteRow Link icon

      public abstract void deleteRow()
    • findColumn Link icon

      public abstract int findColumn(String columnLabel)
    • first Link icon

      public abstract boolean first()
    • getRow Link icon

      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 Link icon

      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 Link icon

      public abstract Object getObject(int columnIndex)
    • getBoolean Link icon

      public abstract boolean getBoolean(int columnIndex)
    • getByte Link icon

      public abstract byte getByte(int columnIndex)
    • getDate Link icon

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

      public abstract Date getDate(int columnIndex)
    • getDouble Link icon

      public abstract double getDouble(int columnIndex)
    • getFloat Link icon

      public abstract float getFloat(int columnIndex)
    • getInt Link icon

      public abstract int getInt(int columnIndex)
    • getLong Link icon

      public abstract long getLong(int columnIndex)
    • getRowId Link icon

      public abstract RowId getRowId(int columnIndex)
    • getString Link icon

      public abstract String getString(int columnIndex)
    • getTime Link icon

      public abstract Time getTime(int columnIndex)
    • getTimestampMillis Link icon

      public abstract Long getTimestampMillis(int columnIndex)
    • isAfterLast Link icon

      public abstract boolean isAfterLast()
    • isBeforeFirst Link icon

      public abstract boolean isBeforeFirst()
    • isClosed Link icon

      public abstract boolean isClosed()
    • isFirst Link icon

      public abstract boolean isFirst()
    • isLast Link icon

      public abstract boolean isLast()
    • last Link icon

      public abstract boolean last()
    • moveToCurrentRow Link icon

      public abstract void moveToCurrentRow()
    • moveToInsertRow Link icon

      public abstract void moveToInsertRow()
    • insertRow Link icon

      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 Link icon

      public abstract boolean next()
    • previous Link icon

      public abstract boolean previous()
    • refreshRow Link icon

      public abstract void refreshRow()
    • rowDeleted Link icon

      public abstract boolean rowDeleted()
    • rowInserted Link icon

      public abstract boolean rowInserted()
    • rowUpdated Link icon

      public abstract boolean rowUpdated()
    • updateObject Link icon

      public abstract void updateObject(int columnIndex, Object x) throws SQLException
      Throws:
      SQLException
    • updateBoolean Link icon

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

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

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

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

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

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

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

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

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