Package com.faircom.jsonaction
Class Cursor
- Object
-
- Cursor
-
public class Cursor extends Object
Retrieves data from a query.- Continue fetching data while moreRecords is true.
- Use primaryKeyFields to get the field numbers of the fields that uniquely identify a record
- Use requestedRecordCount to troubleshoot the number of records you requested from the fetchRecords method.
- Use returnedRecordCount to troubleshoot the number of records returned from the fetchRecords method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Cursor.StartFrom
Specifies where a cursor starts: current position, before the first record, or after the last record.
-
Constructor Summary
Constructors Constructor Description Cursor(Session session, ObjectNode response)
Construct a Cursor class object from any of the getCursor* methods in DbApi.Cursor(Session session, ObjectNode response, String cursorId)
Manually construct a Cursor class object from a cursorId and a Session class object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectNode
closeCursor()
Closes the cursor and releases its resources on the server.void
fetchRecords()
Retrieves the next set of 20 records.void
fetchRecords(long recordsToFetch)
Retrieves the specified number of records forward or backward from the current cursor position.void
fetchRecords(long recordsToFetch, long recordsToSkip)
Retrieves the specified number of records forward or backward after skipping the specified number of records forward or backward.void
fetchRecords(long recordsToFetch, long recordsToSkip, Cursor.StartFrom startFrom)
Retrieves the specified number of records forward or backward after skipping the specified number of records forward or backward from the specified starting point.void
fetchRecords(long recordsToFetch, long recordsToSkip, Cursor.StartFrom startFrom, ObjectNode requestOverride)
Retrieves the specified number of records forward or backward after skipping the specified number of records forward or backward from the specified starting point.int
getChangeIdField()
Contains the field number of the field that contains the record's changeId.String
getCursorId()
Contains the cursorId that the server generates when it creates a cursor from a call to a getRecords method.ArrayNode
getData()
Contains the data retrieved by the last call to fetchRecords().JsonNode
getDebugInfo()
Contains debugging information returned by the server in response to fetchRecords().int
getFetchCount()
Contains the number of times you have called fetchRecords().List<Field>
getFields()
Contains a Fields object that describes each field returned by the cursor.int
getGetDataCount()
Contains the number of time you have called getData().List<String>
getPrimaryKeyFieldNames()
Contains a list of field numbers in the Fields object that are the primary key fields of the record.int
getRequestedRecordCount()
Contains the default number of records requested by fetchRecords().JsonNode
getRequestId()
Contains the requestId returned by the FairCom server in the response to fetchRecords().ObjectNode
getResult()
Contains the JSON object returned by the server as a Jackson JSON ObjectNode.int
getReturnedRecordCount()
Contains the number of records returned by the last call to fetchRecords().boolean
isMoreRecords()
Is false when there are no more records available for the cursor to fetch.
-
-
-
Constructor Detail
-
Cursor
public Cursor(Session session, ObjectNode response)
Construct a Cursor class object from any of the getCursor* methods in DbApi.Used by:
- getCursorFromTable()
- getCursorFromIndex()
- getCursorFromSQL()
- getCursorFromKeyRange()
- getCursorFromPartialKeyRange()
- getCursorStartingAtKey()
Example
Cursor tableCursor = dbApiUnderTest.getCursorFromTable( dbNameUnderTest, tableNameUnderTest ); tableCursor.fetchRecords(); ArrayNode dataBlock = tableCursor.getData();
- Parameters:
session
- the session to use with this cursor.response
- a response from the JSON Action API.- Since:
- 1.0
-
Cursor
public Cursor(Session session, ObjectNode response, String cursorId)
Manually construct a Cursor class object from a cursorId and a Session class object.- Parameters:
session
- the session to assign to this instance.response
- the latest response from the server.cursorId
- the cursorId to use when communicating with the server.- Since:
- 1.0
-
-
Method Detail
-
closeCursor
public ObjectNode closeCursor() throws ApiException
Closes the cursor and releases its resources on the server.- The return value is only useful for troubleshooting.
- Returns:
- Jackson ObjectNode containing the JSON response from the FairCom server.
- Throws:
ApiException
- when the request cannot be processed by the API.- Since:
- 1.0
- See Also:
- FairCom closeCursor documentation
-
fetchRecords
public void fetchRecords() throws ApiException
Retrieves the next set of 20 records.- A cursor is stateful and remembers its current position.
- Use getData() to get the records that the cursor retrieved.
- Use isMoreRecords() to determine if you need to call fetchRecords() again to retrieve more records.
- Use getFields() after calling fetchRecords() to retrieve the record's field definitions.
- Throws:
ApiException
- when the request cannot be processed by the API.- Since:
- 1.0
- See Also:
- FairCom getRecordsFromCursor documentation
-
fetchRecords
public void fetchRecords(long recordsToFetch) throws ApiException
Retrieves the specified number of records forward or backward from the current cursor position.- A cursor is stateful and remembers its current position.
- Use getData() to get the records that the cursor retrieved.
- Use isMoreRecords() to determine if you need to call fetchRecords() again to retrieve more records.
- Use getFields() after calling fetchRecords() to retrieve the record's field definitions.
- Parameters:
recordsToFetch
- is a positive or negative integer that specifies the number of records to fetch forward or backward.- Throws:
ApiException
- when the request cannot be processed by the API.- Since:
- 1.0
- See Also:
- FairCom getRecordsFromCursor documentation
-
fetchRecords
public void fetchRecords(long recordsToFetch, long recordsToSkip) throws ApiException
Retrieves the specified number of records forward or backward after skipping the specified number of records forward or backward.- A cursor is stateful and remembers its current position.
- Use getData() to get the records that the cursor retrieved.
- Use isMoreRecords() to determine if you need to call fetchRecords() again to retrieve more records.
- Use getFields() after calling fetchRecords() to retrieve the record's field definitions.
- Parameters:
recordsToFetch
- is a positive or negative integer that specifies the number of records to fetch forward or backward.recordsToSkip
- is a positive or negative integer that specifies the number of records to skip forward or backward before fetching records.- Throws:
ApiException
- when the request cannot be processed by the API.- Since:
- 1.0
- See Also:
- FairCom getRecordsFromCursor documentation
-
fetchRecords
public void fetchRecords(long recordsToFetch, long recordsToSkip, Cursor.StartFrom startFrom) throws ApiException
Retrieves the specified number of records forward or backward after skipping the specified number of records forward or backward from the specified starting point.- This method can move a cursor position to the beginning or end of the results before fetching records.
- Use getData() to get the records that the cursor retrieved.
- Use isMoreRecords() to determine if you need to call fetchRecords() again to retrieve more records.
- Use getFields() after calling fetchRecords() to retrieve the record's field definitions.
- Parameters:
recordsToFetch
- is a positive or negative integer that specifies the number of records to fetch forward or backward.recordsToSkip
- is a positive or negative integer that specifies the number of records to skip forward or backward before fetching records.startFrom
- is a Java enum that optionally specifies currentPosition, beforeFirstRecord, or afterLastRecord.- Throws:
ApiException
- when the request cannot be processed by the API.- Since:
- 1.0
- See Also:
- FairCom getRecordsFromCursor documentation
-
fetchRecords
public void fetchRecords(long recordsToFetch, long recordsToSkip, Cursor.StartFrom startFrom, ObjectNode requestOverride) throws ApiException
Retrieves the specified number of records forward or backward after skipping the specified number of records forward or backward from the specified starting point.- This method can move a cursor position to the beginning or end of the results before fetching records.
- Use getData() to get the records that the cursor retrieved.
- Use isMoreRecords() to determine if you need to call fetchRecords() again to retrieve more records.
- Use getFields() after calling fetchRecords() to retrieve the record's field definitions.
- Parameters:
recordsToFetch
- is a positive or negative integer that specifies the number of records to fetch forward or backward.recordsToSkip
- is a positive or negative integer that specifies the number of records to skip forward or backward before fetching records.startFrom
- is a Java enum that optionally specifies currentPosition, beforeFirstRecord, or afterLastRecord.requestOverride
- Add new JSON properties and/or override any property value being sent to the FairCom server. See the FairCom documentation for all options. Set to null when you do not want to override anything.- Throws:
ApiException
- when the request cannot be processed by the API.- Since:
- 1.0
- See Also:
- FairCom getRecordsFromCursor documentation
-
getData
public ArrayNode getData()
Contains the data retrieved by the last call to fetchRecords().- The Jackson ArrayNode object contains a JSON array of objects. Each object represents a record.
- You can use Jackson to map the records into POJOs.
- This property changes with each call to fetchRecords().
- Returns:
- the data returned by the last .fetchRecords() call.
- Since:
- 1.0
-
getFetchCount
public int getFetchCount()
Contains the number of times you have called fetchRecords().- It is informational and might be useful for troubleshooting.
- Returns:
- the number of time .fetchRecords() has been called.
- Since:
- 1.0
-
getGetDataCount
public int getGetDataCount()
Contains the number of time you have called getData().- It is informational and might be useful for troubleshooting.
- Returns:
- the number of time .getData() has been called.
- Since:
- 1.0
-
isMoreRecords
public boolean isMoreRecords()
Is false when there are no more records available for the cursor to fetch.- It can be true when there are no more records because a cursor only knows it has returned all records when it fails to retrieve additional records.
- In other words, the server sets isMoreRecords() to true until the cursor runs out of records.
- When a cursor is out of records, you can call fetchRecords() with a StartFrom property to reset the cursor to the beginning or end.
- Returns:
- true if the last .fetchRecords() call had not reached the end of the data.
- Since:
- 1.0
-
getRequestedRecordCount
public int getRequestedRecordCount()
Contains the default number of records requested by fetchRecords(). It defaults to 20 records.- Returns:
- the number of records requested by the last .fetchRecords() call.
- Since:
- 1.0
-
getReturnedRecordCount
public int getReturnedRecordCount()
Contains the number of records returned by the last call to fetchRecords(). This property changes with each call to fetchRecords().- Returns:
- the number of records returned from the last .fetchRecords() call.
- Since:
- 1.0
-
getFields
public List<Field> getFields()
Contains a Fields object that describes each field returned by the cursor.- Before calling getFields(), you must first call fetchRecords() to populate this information.
- Once set, this property does not change.
- Returns:
- a List of Field class objects representing the data schema.
- Since:
- 1.0
-
getPrimaryKeyFieldNames
public List<String> getPrimaryKeyFieldNames()
Contains a list of field numbers in the Fields object that are the primary key fields of the record.- Use getFields() with this list to retrieve the names of these fields.
- Typically a table has one primary key field named "id".
- A primary key uniquely identifies a record.
- Before calling getPrimaryKeyFields(), you must first call fetchRecords() to populate this information.
- Once set, this property does not change.
- Returns:
- a List of Integers representing the primaryKeyFields for the table.
- Since:
- 1.0
-
getChangeIdField
public int getChangeIdField()
Contains the field number of the field that contains the record's changeId.- Use getFields() with this number to retrieve the name of the changeId field.
- Typically a table has a changeId field named "changeId".
- The server uses the changeId field to implement optimistic record locking.
- The server stores the current transaction number in the changeId field when it inserts and updates a record.
- When you want to update a field, you must set the changeId field to its previous changeId value.
- This allows the server to verify the record has not changed since you retrieved it.
- This property does not change during the life of the cursor.
- Returns:
- an int containing the changeIdField for the table.
- Since:
- 1.0
-
getCursorId
public String getCursorId()
Contains the cursorId that the server generates when it creates a cursor from a call to a getRecords method.- This is informational in case you want to use it in your own JSON messages that you send to the server.
- This class automatically uses the cursorId to fetch records and close the cursor.
- Returns:
- a String containing the cursorId.
- Since:
- 1.0
-
getRequestId
public JsonNode getRequestId()
Contains the requestId returned by the FairCom server in the response to fetchRecords().- It is information and may be useful for troubleshooting.
- It changes with any call to fetchRecords().
- Returns:
- a JsonNode containing the requestId of the most recent API response.
- Since:
- 1.0
-
getDebugInfo
public JsonNode getDebugInfo()
Contains debugging information returned by the server in response to fetchRecords().- When the server's debugMode is set to maximum, the server returns the debugInfo property.
- This property changes with every call to fetchRecords().
- Returns:
- a JsonNode containing the debug section of the most recent API response.
- Since:
- 1.0
-
getResult
public ObjectNode getResult()
Contains the JSON object returned by the server as a Jackson JSON ObjectNode.- You can use it to retrieve additional information and troubleshoot issues.
- Returns:
- an ObjectNode containing the result section of the most recent API response.
- Since:
- 1.0
-
-