Query query = new Query(JobRecord.DATA_STORE_KIND);
Filter filter = classFilter == null || classFilter.isEmpty() ? new FilterPredicate(
ROOT_JOB_DISPLAY_NAME, GREATER_THAN, null)
: new FilterPredicate(ROOT_JOB_DISPLAY_NAME, EQUAL, classFilter);
query.setFilter(filter);
final PreparedQuery preparedQuery = dataStore.prepare(query);
final FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();
if (limit > 0) {
fetchOptions.limit(limit + 1);
}
if (cursor != null) {
fetchOptions.startCursor(Cursor.fromWebSafeString(cursor));
}
return tryFiveTimes(
new Operation<Pair<? extends Iterable<JobRecord>, String>>("queryRootPipelines") {
@Override
public Pair<? extends Iterable<JobRecord>, String> call() {
QueryResultIterator<Entity> entities =
preparedQuery.asQueryResultIterable(fetchOptions).iterator();
Cursor dsCursor = null;
List<JobRecord> roots = new LinkedList<>();
while (entities.hasNext()) {
if (limit > 0 && roots.size() >= limit) {
dsCursor = entities.getCursor();