@Override public Cursor getCursor() { return this.base.getCursor(); }
/** * Fetches entities in batches and puts them into the buffer. */ private void batchFetching() { Query<T> newQuery = this.query.limit(BUFFER_SIZE); if (this.cursor != null) { newQuery = newQuery.startAt(this.cursor); } QueryResultIterator<T> iterator = newQuery.iterator(); boolean shouldContinue = false; while (iterator.hasNext()) { shouldContinue = true; this.buffer.offer(iterator.next()); } if (shouldContinue) { this.cursor = iterator.getCursor(); } }
@Override public Cursor getCursor() { return ((QueryResultIterator<F>)this.base).getCursor(); } }
public Cursor getCursor() { return ((QueryResultIterator<Entity>) inner).getCursor(); }
cursor = iterator.getCursor(); println(String.format("Cursor Position: %s", cursor.toWebSafeString())); println(String.format("Number Of Entity Key Scanned: %d", numberOfScannedKey.get()));
/** * Extract a {@link Cursor} from the provided {@link Iterator}. The Cursor * points to the element most recently returned by the iterator. A query * that is executed using the returned Cursor will start scanning directly * after this element. * <b> * A Cursor will only be available if the Iterator was created from a query * result and the query did not have a limit set. * * @param iter The {@link Iterator} from which to extract a {@link Cursor}. * @return The {@link Cursor}, or {@code null} if no Cursor is available for * the provided cursor. */ public static Cursor getCursor(Iterator<?> iter) { if (iter instanceof LazyResult.LazyAbstractListIterator) { Iterator<?> innerIter = ((LazyResult.LazyAbstractListIterator) iter).getInnerIterator(); if (innerIter instanceof QueryResultIterator) { return ((QueryResultIterator) innerIter).getCursor(); } } return null; } }
@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(); break; } JobRecord jobRecord = new JobRecord(entities.next()); roots.add(jobRecord); } return Pair.of(roots, dsCursor == null ? null : dsCursor.toWebSafeString()); } });
public void query(long toVersion, Optional<String> startAt) { LOGGER.info("Starting initial sync query..."); Stopwatch stopwatch = Stopwatch.createStarted(); Query<FormRecordEntity> query = ofy().load().type(FormRecordEntity.class) .ancestor(FormEntity.key(formClass)) .chunk(500); if(startAt.isPresent()) { query = query.startAt(Cursor.fromWebSafeString(startAt.get())); } QueryResultIterator<FormRecordEntity> it = query.iterator(); while(it.hasNext()) { FormRecordEntity record = it.next(); if(visibilityPredicate.test(record.getRecordId())) { add(record); if(!sizeEstimator.timeAndSpaceRemaining()) { stop(it.getCursor().toWebSafeString()); break; } } } LOGGER.info("Initial sync query complete in " + stopwatch.elapsed(TimeUnit.SECONDS) + " with estimate size: " + sizeEstimator.getEstimatedSizeInBytes() + " bytes"); }
public void query(long localVersion, long toVersion, Optional<String> startAt) { LOGGER.info("Starting VersionRange query..."); Stopwatch stopwatch = Stopwatch.createStarted(); Query<FormRecordSnapshotEntity> query = ofy().load().type(FormRecordSnapshotEntity.class) .ancestor(FormEntity.key(formClass)) .filter("version >", localVersion) .chunk(500); if(startAt.isPresent()) { query = query.startAt(Cursor.fromWebSafeString(startAt.get())); } QueryResultIterator<FormRecordSnapshotEntity> it = query.iterator(); while(it.hasNext()) { FormRecordSnapshotEntity snapshot = it.next(); if(snapshot.getVersion() <= toVersion) { add(snapshot); if(!sizeEstimator.timeAndSpaceRemaining()) { stop(it.getCursor().toWebSafeString()); break; } } } LOGGER.info("VersionRange query complete in " + stopwatch.elapsed(TimeUnit.SECONDS) + " with estimate size: " + sizeEstimator.getEstimatedSizeInBytes() + " bytes"); }
items.add(listItem); Cursor cursor = dsResults.getCursor(); String nextMarker = null; if (items.size() == maxResults && cursor != null) {
@Test public void testReverse() { Query query = new Query(kindName, rootKey); query.addSort(Entity.KEY_RESERVED_PROPERTY); QueryResultIterator<Entity> iter = service.prepare(query).asQueryResultIterator(); Entity e1 = iter.next(); Entity e2 = iter.next(); Cursor cursor = iter.getCursor(); //reverse query = query.reverse(); cursor = cursor.reverse(); iter = service.prepare(query).asQueryResultIterator(FetchOptions.Builder.withStartCursor(cursor)); Assert.assertEquals(e2, iter.next()); Assert.assertEquals(e1, iter.next()); }
@Test public void testCursor() throws Exception { Entity parent = createTestEntityWithUniqueMethodNameKey("Person", "testKeysOnly"); Key key = parent.getKey(); Entity john = createEntity("Person", key) .withProperty("name", "John") .withProperty("surname", "Doe") .store(); Query query = new Query("Person") .setAncestor(key) .setKeysOnly(); PreparedQuery preparedQuery = service.prepare(query); QueryResultIterator<Entity> iter = preparedQuery.asQueryResultIterator(); Assert.assertNotNull(iter.next()); Cursor cursor = iter.getCursor(); iter = service.prepare(query).asQueryResultIterator(FetchOptions.Builder.withStartCursor(cursor)); Assert.assertFalse(iter.hasNext()); }