Package org.kissweb.database
Class Cursor
java.lang.Object
org.kissweb.database.Cursor
- All Implemented Interfaces:
AutoCloseable
Instances of this class represent a row into a result set. If a single table is selected from, rows may be updated
or deleted via these facilities.
It is important to understand that this class represents a Kiss Cursor and not a true database cursor! When queries occur, Kiss downloads all the records in the result set either in memory or a local disk file and then closes any database cursor. The advantage of this approach is that there is never a problem with multiple database cursors being open simultaneously or nested in code (which often causes database performance issues or interference). However, from the application's perspective, a Kiss Cursor works just like a database cursor and has all the same functionality.
A new cursor is created with the following code:
where
It is important to understand that this class represents a Kiss Cursor and not a true database cursor! When queries occur, Kiss downloads all the records in the result set either in memory or a local disk file and then closes any database cursor. The advantage of this approach is that there is never a problem with multiple database cursors being open simultaneously or nested in code (which often causes database performance issues or interference). However, from the application's perspective, a Kiss Cursor works just like a database cursor and has all the same functionality.
A new cursor is created with the following code:
Cursor cursor = cmd.query("select .....
where
cmd is an instance of Command.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the entire cursor.fetchAll()Read in all of the records and close the cursor.org.json.JSONArrayThis method does the same thing asfetchAllexcept that it return a JSON array representing all of the records.fetchOne()Read in a single record and close the read cursor (no more records can be read).org.json.JSONObjectThis method works exactly likefetchOneexcept that it return a JSON object representing the record.org.json.JSONObjectfetchOneJSON(org.json.JSONObject obj) This method works likefetchOneexcept that it adds the record columns to an existing JSON object passed in.Get the value of a column as anObject.byte[]getByteArray(String cname) Return thebyte[]value of the named column.Return theCharactervalue of the named column.intgetDateAsInt(String cname) Return the date in an int formatted as YYYYMMDD for the named column.getDateOnly(String cname) Return thejava.util.Datevalue of the named column.getDateTime(String cname) Return thejava.util.Datevalue of the named column.longgetDateTimeMS(String cname) Return the date/time value as the number of milliseconds since 1970 UTC.Return theDoublevalue of the named column.Return theFloatvalue of the named column.Return theIntegervalue of the named column.Return theLongvalue of the named column.Returns theRecordinstance representing the current row.Return theShortvalue of the named column.Return theStringvalue of the named column.Returns the name of the table associated with the select associated with this cursor.longReturn thelongvalue of the named column.booleanisNext()This method advances the row pointer and returnstrueif there is a next record.next()This method is used to advance the row pointer first and then return the (next)Recordinstance representing the next row.Set the value of a column in the current record.setDateOnly(String name, int dat) Set the date portion of the Date only (no time info) value of a column in the record.setDateOnly(String name, Date val) Set the date portion of the Date only (no time info) value of a column in the record.setDateTime(String name, long val) Set the date and time value of a column in the record.setDateTime(String name, Date val) Set the date and time value of a column in the record.Set the time value in millisecondslongsize()Returns the number of records in the cursor.
-
Method Details
-
getTableName
Returns the name of the table associated with the select associated with this cursor.- Returns:
-
getRecord
Returns theRecordinstance representing the current row. This method does not advance the row pointer. -
isNext
This method advances the row pointer and returnstrueif there is a next record.- Returns:
- Throws:
SQLExceptionException- See Also:
-
next
This method is used to advance the row pointer first and then return the (next)Recordinstance representing the next row. If there are no more records,nullis returned and the cursor is closed.- Returns:
- Throws:
SQLExceptionException- See Also:
-
fetchOne
Read in a single record and close the read cursor (no more records can be read). The record read can be updated or deleted.nullis returned if there is no record.- Returns:
- the Record or null if none
- Throws:
SQLExceptionException
-
fetchOneJSON
This method works exactly likefetchOneexcept that it return a JSON object representing the record.nullis returned if there is no record.- Returns:
- the JSON object or
nullif none - Throws:
SQLExceptionException- See Also:
-
fetchOneJSON
This method works likefetchOneexcept that it adds the record columns to an existing JSON object passed in.- Parameters:
obj-- Returns:
- the JSON object passed in
- Throws:
SQLExceptionException
-
fetchAll
Read in all of the records and close the cursor. Records can be updated or deleted. If no records are found, an empty list is returned.- Returns:
- Throws:
SQLExceptionException
-
fetchAllJSON
This method does the same thing asfetchAllexcept that it return a JSON array representing all of the records.- Returns:
- Throws:
SQLExceptionException- See Also:
-
close
Close the entire cursor. No more read, edit, or deletes. Since this class implement AutoCloseable, this method is rarely needed.- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException
-
set
Set the value of a column in the current record. This method should not be used with dates or times.- Parameters:
name- the column nameval- the value to set. Can be any type.- Returns:
- See Also:
-
setDateOnly
Set the date portion of the Date only (no time info) value of a column in the record.- Parameters:
name- the column nameval- the value to set.- Returns:
- See Also:
-
setTime
Set the time value in milliseconds- Parameters:
name- the column namedat- the value to set in milliseconds- Returns:
- See Also:
-
setDateOnly
Set the date portion of the Date only (no time info) value of a column in the record.- Parameters:
name- the column namedat- the value to set. Format is YYYYMMDD- Returns:
- See Also:
-
setDateTime
Set the date and time value of a column in the record.- Parameters:
name- the column nameval- the value to set.- Returns:
- See Also:
-
setDateTime
Set the date and time value of a column in the record.- Parameters:
name- the column nameval- the number of milliseconds since 1970 UTC- Returns:
- See Also:
-
get
Get the value of a column as anObject. Other methods that get expected types are typically used over this method.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getShort
Return theShortvalue of the named column. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getInt
Return theIntegervalue of the named column. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getLong
Return theLongvalue of the named column. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getFloat
Return theFloatvalue of the named column. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getDouble
Return theDoublevalue of the named column. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getDateOnly
Return thejava.util.Datevalue of the named column. That is a date without a time. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getDateAsInt
Return the date in an int formatted as YYYYMMDD for the named column. A0is returned onnullvalued columns.- Parameters:
cname-- Returns:
- date format YYYYMMDD
- Throws:
SQLException- See Also:
-
getDateTime
Return thejava.util.Datevalue of the named column. Date and time information. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getDateTimeMS
Return the date/time value as the number of milliseconds since 1970 UTC. A0is returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getTime
Return thelongvalue of the named column. Only time information is returned. A0is returned onnullvalued columns.- Parameters:
cname-- Returns:
- time in milliseconds
- Throws:
SQLException- See Also:
-
getString
Return theStringvalue of the named column. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getChar
Return theCharactervalue of the named column. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
getByteArray
Return thebyte[]value of the named column. Anullis returned onnullvalued columns.- Parameters:
cname-- Returns:
- Throws:
SQLException- See Also:
-
size
public long size()Returns the number of records in the cursor.- Returns:
-