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
    • Method Detail

      • callback

        boolean callback​(ResultSet rs,
                         ObjectGetter objectGetter)
                  throws SQLException,
                         InterruptedException
        Invoked for each result, provided that the previous invocation returned true.
        Parameters:
        rs - the result-set to process
        objectGetter - 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 occurs
        InterruptedException
      • getRowLimit

        default long getRowLimit()
        Get the row limit, or -1 for no limit. The default implementation of this method will return -1, to indicate that the results should not be limited.
        Returns:
        the row limit.