// Get all activity group IDs.
List<Integer> activityGroupIds = getAllActivityGroupIds(user);
// Create a statement to get all activities for an activity group.
String filterStatementString = "WHERE activityGroupId = :activityGroupId LIMIT 500 OFFSET ";
StatementBuilder statementBuilder = new StatementBuilder(filterStatementString);
int totalResultsCounter = 0;
for (Integer activityGroupId : activityGroupIds) {
// Set defaults for page.
ActivityPage page = new ActivityPage();
int offset = 0;
// Default for total result set size and offset.
int totalResultSetSize = 0;
// Set the activity group ID to select from.
statementBuilder.putValue("activityGroupId", activityGroupId);
do {
// Create a statement to get all activities from an activity group.
statementBuilder.setQuery(filterStatementString + offset);
// Get activities by statement.
page = activityService.getActivitiesByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
for (Activity activity : page.getResults()) {
System.out.printf(