public static void runExample(
      AdManagerServices adManagerServices, AdManagerSession session, String filePath)
      throws IOException {
    PublisherQueryLanguageServiceInterface pqlService =
        adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);

    // Create statement to select recent changes. Change_History only supports ordering by
    // descending ChangeDateTime. Offset is not supported. To page, use the change ID of
    // the earliest change as a pagination token. A date time range is required
    // when querying this table.
    DateTime endDateTime = DateTime.now();
    DateTime startDateTime = endDateTime.minusDays(1);
    StatementBuilder statementBuilder =
        new StatementBuilder()
            .select("Id, ChangeDateTime, EntityId, EntityType, Operation, UserId")
            .from("Change_History")
            .where("ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime")
            .orderBy("ChangeDateTime DESC")
            .withBindVariableValue("startDateTime", DateTimes.toDateTime(startDateTime))
            .withBindVariableValue("endDateTime", DateTimes.toDateTime(endDateTime))
            .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);

    // Retrieve a small amount of changes at a time, paging through
    // until all changes have been retrieved.
    ResultSet combinedResultSet = null;
    ResultSet resultSet;
    int i = 0;

    do {
      resultSet = pqlService.select(statementBuilder.toStatement());

      // Combine result sets with previous ones.
      combinedResultSet =
          combinedResultSet == null
              ? resultSet
              : Pql.combineResultSets(combinedResultSet, resultSet);

      if (resultSet.getRows() != null && resultSet.getRows().length > 0) {
        // Get the earliest change ID in the result set.
        int numRows = resultSet.getRows().length;
        Row lastRow = resultSet.getRows(numRows - 1);
        String id = (String) Pql.getNativeValue(lastRow.getValues(0));
        System.out.printf("%d) %d changes prior to ID %s were found.%n", i++, numRows, id);

        // Use the earliest change ID in the result set to page.
        statementBuilder
            .where("Id < :id AND ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime")
            .withBindVariableValue("id", id);
      }
    } while (resultSet.getRows() != null && resultSet.getRows().length > 0);

    // Write the result set to a CSV.
    CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);

    System.out.printf("Recent changes saved to: %s%n", filePath);
  }
public static void runExample ( AdManagerServices adManagerServices , AdManagerSession session , String filePath ) throws IOException { PublisherQueryLanguageServiceInterface pqlService = adManagerServices . get ( session , PublisherQueryLanguageServiceInterface . class ) ; DateTime endDateTime = DateTime . now ( ) ; DateTime startDateTime = endDateTime . minusDays ( 1 ) ; StatementBuilder statementBuilder = new StatementBuilder ( ) . select ( "Id, ChangeDateTime, EntityId, EntityType, Operation, UserId" ) . from ( "Change_History" ) . where ( "ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime" ) . orderBy ( "ChangeDateTime DESC" ) . withBindVariableValue ( "startDateTime" , DateTimes . toDateTime ( startDateTime ) ) . withBindVariableValue ( "endDateTime" , DateTimes . toDateTime ( endDateTime ) ) . limit ( StatementBuilder . SUGGESTED_PAGE_LIMIT ) ; ResultSet combinedResultSet = null ; ResultSet resultSet ; int i = 0 ; do { resultSet = pqlService . select ( statementBuilder . toStatement ( ) ) ; combinedResultSet = combinedResultSet == null ? resultSet : Pql . combineResultSets ( combinedResultSet , resultSet ) ; if ( resultSet . getRows ( ) != null && resultSet . getRows ( ) . length > 0 ) { int numRows = resultSet . getRows ( ) . length ; Row lastRow = resultSet . getRows ( numRows - 1 ) ; String id = ( String ) Pql . getNativeValue ( lastRow . getValues ( 0 ) ) ; System . out . printf ( "%d) %d changes prior to ID %s were found.%n" , i ++ , numRows , id ) ; statementBuilder . where ( "Id < :id AND ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime" ) . withBindVariableValue ( "id" , id ) ; } } while ( resultSet . getRows ( ) != null && resultSet . getRows ( ) . length > 0 ) ; CsvFiles . writeCsv ( Pql . resultSetToStringArrayList ( combinedResultSet ) , filePath ) ; System . out . printf ( "Recent changes saved to: %s%n" , filePath ) ; }
Runs the example.

@param adManagerServices the services factory.
@param session the session.
@param filePath file path where changes will be saved.
@throws ApiException if the API request failed with one or more service errors.
@throws RemoteException if the API request failed due to other errors.
@throws IOException if unable to write the response to a file.