// Get the CustomTargetingService.
CustomTargetingServiceInterface customTargetingService =
dfpServices.get(session, CustomTargetingServiceInterface.class);
// Create a statement to get custom targeting keys.
StatementBuilder statementBuilder = new StatementBuilder()
.where("WHERE id = :id")
.orderBy("id ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
.withBindVariableValue("id", customTargetingKeyId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get custom targeting keys by statement.
CustomTargetingKeyPage page =
customTargetingService.getCustomTargetingKeysByStatement(
statementBuilder.toStatement());
if (page.getResults() != null) {
CustomTargetingKey[] customTargetingKeys = page.getResults();
totalResultSetSize = page.getTotalResultSetSize();
// Update each local custom targeting key object by changing its display
// name.
for (CustomTargetingKey customTargetingKey : customTargetingKeys) {
if (customTargetingKey.getDisplayName() == null) {
customTargetingKey.setDisplayName(customTargetingKey.getName());
}
customTargetingKey.setDisplayName(
customTargetingKey.getDisplayName() + " (Deprecated)");
}
// Update the custom targeting keys on the server.
customTargetingKeys =
customTargetingService.updateCustomTargetingKeys(customTargetingKeys);
for (CustomTargetingKey updatedCustomTargetingKey : customTargetingKeys) {
System.out.printf("Custom targeting key with ID \"%d\", name \"%s\", and display name "
+ "\"%s\" was updated.\n", updatedCustomTargetingKey.getId(),
updatedCustomTargetingKey.getName(), updatedCustomTargetingKey.getDisplayName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
}