private static final String GEO_TARGET_TYPE = "City";
public static void runExample(DfpServices dfpServices, DfpSession session, String type)
throws Exception {
// Get the PublisherQueryLanguageService.
PublisherQueryLanguageServiceInterface pqlService =
dfpServices.get(session, PublisherQueryLanguageServiceInterface.class);
// Create statement to select all targetable cities.
StatementBuilder statementBuilder = new StatementBuilder()
.select("Id, Name, CanonicalParentId, ParentIds, CountryCode")
.from("Geo_Target")
.where("Type = :type and Targetable = true")
.orderBy("CountryCode ASC, Name ASC")
.offset(0)
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
.withBindVariableValue("type", type);
// Default for result sets.
ResultSet combinedResultSet = null;
ResultSet resultSet;
int i = 0;
do {
// Get all cities.
resultSet = pqlService.select(statementBuilder.toStatement());
// Combine result sets with previous ones.
combinedResultSet = combinedResultSet == null
? resultSet
: Pql.combineResultSets(combinedResultSet, resultSet);