Class PamCursor
- Direct Known Subclasses:
NonScrollablePamCursor
,ScrollablePamCursor
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
absolute
(int row) Go t0 an absolute row numberabstract void
abstract void
abstract void
close()
void
abstract boolean
Close the scrollable cursor.abstract void
executeReadOnlyStatement
(PamConnection connection, String sqlString) Executes the passed SQL statement as read-onlyabstract int
findColumn
(String columnLabel) abstract boolean
first()
abstract boolean
getBoolean
(int columnIndex) abstract byte
getByte
(int columnIndex) abstract Date
getDate
(int columnIndex) abstract Date
abstract double
getDouble
(int columnIndex) abstract float
getFloat
(int columnIndex) getInsertString
(SQLTypes sqlTypes) abstract int
getInt
(int columnIndex) abstract long
getLong
(int columnIndex) abstract Object
getObject
(int columnIndex) abstract int
getRow()
Retrieves the current row number.abstract RowId
getRowId
(int columnIndex) getSelectString
(SQLTypes sqlTypes, boolean includeKeys, boolean includeCounters, boolean orderById) Generate a standard SQL select string for everything in the table.getSelectString
(SQLTypes sqlTypes, boolean includeKeys, boolean includeCounters, String clause) Generate an SQL select string with an optional clause which may include WHERE and ORDERgetSelectString
(SQLTypes sqlTypes, String stmt) Generate a standard SQL select string using the passed statement.abstract String
getString
(int columnIndex) abstract Time
getTime
(int columnIndex) abstract Long
getTimestampMillis
(int columnIndex) getUpdateString
(SQLTypes sqlTypes) long
Get the UTC time from the cursor data.int
immediateInsert
(PamConnection connection) Do an immediate insert of data which should already have been put into the data objects of the table definition.boolean
immediateUpdate
(PamConnection 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 statementabstract boolean
abstract boolean
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 cursorvoid
moveDataToTableDef
(boolean includeCounters) Move data from the cursor to the table definitionabstract void
abstract void
abstract boolean
next()
boolean
openInsertCursor
(PamConnection connection) Open a cursor for inserting data using a non-scrollable cursor.openReadOnlyCursor
(PamConnection connection, String clause) Reads all columns from the table, using the optional passed clauseopenReadOnlyCursorWithStatement
(PamConnection connection, String stmt) Executes an SQL statement passed.abstract boolean
openScrollableCursor
(PamConnection connection, boolean includeKeys, boolean includeCounters, String clause) Open a scrollable cursorabstract boolean
previous()
abstract void
abstract boolean
abstract boolean
abstract boolean
void
setCurrentConnection
(PamConnection currentConnection) abstract void
updateBoolean
(int columnIndex, boolean x) abstract void
updateByte
(int columnIndex, byte x) abstract boolean
Push everything down onto the databaseabstract void
updateInt
(int columnIndex, int x) abstract void
updateLong
(int columnIndex, long x) abstract void
updateNull
(int columnIndex) abstract void
updateObject
(int columnIndex, Object x) abstract void
abstract void
updateShort
(int columnIndex, short x) abstract void
updateString
(int columnIndex, String x) abstract void
updateTimestamp
(int columnIndex, Timestamp x)
-
Constructor Details
-
PamCursor
-
-
Method Details
-
getTableDefinition
-
getCurrentConnection
-
setCurrentConnection
-
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 countersorderById
- add a standard ORDER BY Id at the end of the string- Returns:
- SQL string
-
getSelectString
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
-
getInsertString
-
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 countersclause
- WHERE ... and ORDER BY clause.- Returns:
- SQL string
-
openInsertCursor
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 connectionincludeCounters
- include counters in query- Returns:
- true if cursor created sucessfully.
-
moveDataToCursor
Move data from the table definition down to the cursor- Parameters:
includeCounters
- counters are included in the query- Throws:
SQLException
-
moveDataToTableDef
Move data from the cursor to the table definition- Parameters:
includeCounters
- include counter data- Throws:
SQLException
-
immediateInsert
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
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
Reads all columns from the table, using the optional passed clause- Parameters:
connection
- Connection to the databaseclause
- WHERE ... and ORDER BY clause.- Returns:
-
openReadOnlyCursorWithStatement
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 databasestmt
- the SQL statement to execute- Returns:
-
executeReadOnlyStatement
Executes the passed SQL statement as read-only- Parameters:
connection
- Connection to the databasesqlString
- 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 connectionincludeKeys
- include keysincludeCounters
- inlcude countersclause
- 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 numberNote 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
-
first
public abstract boolean first() -
getRow
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
-
getBoolean
public abstract boolean getBoolean(int columnIndex) -
getByte
public abstract byte getByte(int columnIndex) -
getDate
-
getDate
-
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
-
getString
-
getTime
-
getTimestampMillis
-
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
- Throws:
SQLException
-
updateBoolean
- Throws:
SQLException
-
updateByte
- Throws:
SQLException
-
updateInt
- Throws:
SQLException
-
updateLong
- Throws:
SQLException
-
updateNull
- Throws:
SQLException
-
updateRow
- Throws:
SQLException
-
updateString
- Throws:
SQLException
-
updateShort
- Throws:
SQLException
-
updateTimestamp
- Throws:
SQLException
-