Interface APIResultSetCallback

  • All Known Subinterfaces:
    ReportDestination
    All Known Implementing Classes:
    CollectionCallback, 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