Package com.redwood.scheduler.api.model
Interface APIResultSetCallback
-
- All Known Subinterfaces:
ReportDestination
- All Known Implementing Classes:
CollectionCallback
,ExistsCallback
,GetCountCallBack
,InternalToolResultSet
,LimitedUniqueIdListAPIResultSetCallback
,LongCallBack
,LongListCallback
,StringCallback
,UniqueIdListAPIResultSetCallback
public interface APIResultSetCallback
This interface is used to access the ResultSet of data model queries and is implemented in a number of classes listed above.
You implement the interface as outlined in the following example:
{ //Get the job id and process server id for each job that has status Killed, Canceled, Error, or Unknown //This example is for illustration purposes only. //There are easier ways of storing these values in a Map using
executeObjectQuery
, for example String query = "select j.JobId, j.ProcessServer from Job j where j.Status in ('K', 'A', 'E', 'U')"; final Map myMap = new HashMap<>(); jcsSession.executeQuery(query, null, new APIResultSetCallback() { public void start() { //This might be called multiple times in a row when database timeouts occur myMap.clear(); } public boolean callback(ResultSet rs, ObjectGetter objectGetter) throws SQLException { //ResultSet here stores only one row Long jobId = Long.valueOf(rs.getLong(1)); Long psId = Long.valueOf(rs.getLong(2)); myMap.put(jobId, psId); //Cool, we made it, return true return true; } public void finish() { // Do nothing } }); jcsOut.println(myMap.values().size()); }Important: The start may be called multiple times in case a query fails, in certain cases a retry is done. You have to make sure that you clear in start() or you may end up with undefined results (such as duplicates or invalid data).
- See Also:
executeObjectQuery
,executeQuery
-
-
Field Summary
Fields Modifier and Type Field Description static APIResultSetCallback
NULL
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
callback(ResultSet rs, ObjectGetter objectGetter)
Invoked for each result, provided that the previous invocation returnedtrue
.default void
finish()
Invoked when all results have been processed.void
start()
Invoked before processing any results.
-
-
-
Field Detail
-
NULL
static final APIResultSetCallback NULL
-
-
Method Detail
-
start
void start() throws InterruptedException
Invoked before processing any results.This is before any calls to
callback(ResultSet, ObjectGetter)
are made.Note that this may be invoked more than once under some circumstances. (Such circumstances include when the query is restarted due to underlying database errors.)
- Throws:
InterruptedException
-
callback
boolean callback(ResultSet rs, ObjectGetter objectGetter) throws SQLException, InterruptedException
Invoked for each result, provided that the previous invocation returnedtrue
.- Parameters:
rs
- the result-set to processobjectGetter
- an object-getter with can be used to convert the result-set into one (or more) objects.- Returns:
true
if this method should be invoked for the next result,false
if subsequent results are to be discarded.- Throws:
SQLException
- Exception thrown when a database-related error occursInterruptedException
-
finish
default void finish() throws InterruptedException
Invoked when all results have been processed. This is after all calls tocallback(ResultSet, ObjectGetter)
have been made.- Throws:
InterruptedException
-
-