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 TypeMethodDescriptionvoid
close()
Close the entire cursor.fetchAll()
Read in all of the records and close the cursor.org.json.JSONArray
This method does the same thing asfetchAll
except 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.JSONObject
This method works exactly likefetchOne
except that it return a JSON object representing the record.org.json.JSONObject
fetchOneJSON
(org.json.JSONObject obj) This method works likefetchOne
except 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 theCharacter
value of the named column.int
getDateAsInt
(String cname) Return the date in an int formatted as YYYYMMDD for the named column.getDateOnly
(String cname) Return thejava.util.Date
value of the named column.getDateTime
(String cname) Return thejava.util.Date
value of the named column.long
getDateTimeMS
(String cname) Return the date/time value as the number of milliseconds since 1970 UTC.Return theDouble
value of the named column.Return theFloat
value of the named column.Return theInteger
value of the named column.Return theLong
value of the named column.Returns theRecord
instance representing the current row.Return theShort
value of the named column.Return theString
value of the named column.Returns the name of the table associated with the select associated with this cursor.long
Return thelong
value of the named column.boolean
isNext()
This method advances the row pointer and returnstrue
if there is a next record.next()
This method is used to advance the row pointer first and then return the (next)Record
instance 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 millisecondslong
size()
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 theRecord
instance representing the current row. This method does not advance the row pointer. -
isNext
This method advances the row pointer and returnstrue
if there is a next record.- Returns:
- Throws:
SQLException
Exception
- See Also:
-
next
This method is used to advance the row pointer first and then return the (next)Record
instance representing the next row. If there are no more records,null
is returned and the cursor is closed.- Returns:
- Throws:
SQLException
Exception
- 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.null
is returned if there is no record.- Returns:
- the Record or null if none
- Throws:
SQLException
Exception
-
fetchOneJSON
This method works exactly likefetchOne
except that it return a JSON object representing the record.null
is returned if there is no record.- Returns:
- the JSON object or
null
if none - Throws:
SQLException
Exception
- See Also:
-
fetchOneJSON
This method works likefetchOne
except that it adds the record columns to an existing JSON object passed in.- Parameters:
obj
-- Returns:
- the JSON object passed in
- Throws:
SQLException
Exception
-
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:
SQLException
Exception
-
fetchAllJSON
This method does the same thing asfetchAll
except that it return a JSON array representing all of the records.- Returns:
- Throws:
SQLException
Exception
- 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:
close
in 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 theShort
value of the named column. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getInt
Return theInteger
value of the named column. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getLong
Return theLong
value of the named column. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getFloat
Return theFloat
value of the named column. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getDouble
Return theDouble
value of the named column. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getDateOnly
Return thejava.util.Date
value of the named column. That is a date without a time. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getDateAsInt
Return the date in an int formatted as YYYYMMDD for the named column. A0
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- date format YYYYMMDD
- Throws:
SQLException
- See Also:
-
getDateTime
Return thejava.util.Date
value of the named column. Date and time information. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getDateTimeMS
Return the date/time value as the number of milliseconds since 1970 UTC. A0
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getTime
Return thelong
value of the named column. Only time information is returned. A0
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- time in milliseconds
- Throws:
SQLException
- See Also:
-
getString
Return theString
value of the named column. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getChar
Return theCharacter
value of the named column. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
getByteArray
Return thebyte[]
value of the named column. Anull
is returned onnull
valued columns.- Parameters:
cname
-- Returns:
- Throws:
SQLException
- See Also:
-
size
public long size()Returns the number of records in the cursor.- Returns:
-