} else { println("Start from cursor position: " + cursorPosition); cursor = Cursor.fromWebSafeString(cursorPosition); println(String.format("Cursor Position: %s", cursor.toWebSafeString())); println(String.format("Number Of Entity Key Scanned: %d", numberOfScannedKey.get())); println(String.format("Number Of Entity affected: %d", numberOfAffectedEntities.get()));
//Find the next cursor Cursor cursor = iterator.getCursor(); if (cursor != null) { cursorString = cursor.toWebSafeString(); }
public static Cursor instantiate(SerializationStreamReader streamReader) throws SerializationException { return Cursor.fromWebSafeString(streamReader.readString()); }
@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()); }
String cursorString = cursor.toWebSafeString(); // Send cursor around as string // Query q = the same query that produced the cursor; Cursor cursor = Cursor.fromWebSafeString(cursorString); Map<String, Object> extensionMap = new HashMap<String, Object>(); extensionMap.put(JDOCursorHelper.CURSOR_EXTENSION, cursor); q.setExtensions(extensionMap); q.setRange(0, 20); //note, the same range; //the query should cover everything you expect to load. q.execute();
private QueryResultList<Entity> getNamespaces() { FetchOptions fetchOptions = FetchOptions.Builder.withDefaults(); fetchOptions.limit(BATCH_SIZE); if (cursor != null) { fetchOptions.startCursor(Cursor.fromWebSafeString(cursor)); } Query q = new Query(NAMESPACE_METADATA_KIND); q.setKeysOnly(); return datastore.prepare(q).asQueryResultList(fetchOptions); }
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 static void serialize(SerializationStreamWriter streamWriter, Cursor instance) throws SerializationException { streamWriter.writeString(instance.toWebSafeString()); } }
private FetchOptions configureFetchOptions(QueryBuilder<?> builder) { FetchOptions fetchOptions = FetchOptions.Builder.withDefaults(); if (builder.getLimit() != null) { fetchOptions.limit(builder.getLimit()); } if (builder.getCursor() != null) { fetchOptions.startCursor(Cursor.fromWebSafeString(builder.getCursor())); } return fetchOptions; }
@Test public void testEndFetch() { int onePage = total - 30; Query query = new Query(kindName, rootKey); // fetch first page Cursor cursor = checkPage(query, null, null, onePage, onePage, null, null); Cursor decodedCursor = Cursor.fromWebSafeString(cursor.toWebSafeString()); // fetch next page, get remaining after 1st page. checkPage(query, decodedCursor, null, onePage, total - onePage, null, null); }
cursor = JPACursorHelper.getCursor(execute); if (cursor != null) cursorString = cursor.toWebSafeString();
fetchOptions.startCursor(Cursor.fromWebSafeString(cursor));
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"); }
cursor = JPACursorHelper.getCursor(execute); if (cursor != null) cursorString = cursor.toWebSafeString();
cursor = Cursor.fromWebSafeString((String) obj);
@Test public void testEndCursor() { int limit = total / testDat.length; Query query = new Query(kindName, rootKey); query.addSort("name", Query.SortDirection.ASCENDING); // fetch 1st page Cursor cursor = checkPage(query, null, null, limit, limit, testDat[0], testDat[0]); Cursor decodedCursor = Cursor.fromWebSafeString(cursor.toWebSafeString()); // fetch 1st page again since using decodedCursor as end cursor checkPage(query, null, decodedCursor, limit, limit, testDat[0], testDat[0]); }
cursor = JPACursorHelper.getCursor(execute); if (cursor != null) cursorString = cursor.toWebSafeString();
query.cursor = Cursor.fromWebSafeString(cursorNode.getTextValue());
@Test public void testFilter() { int onePage = 5; String filterData = "ff"; Query query = new Query(kindName, rootKey); query.setFilter(new FilterPredicate("name", Query.FilterOperator.EQUAL, filterData)); // fetch first page Cursor cursor = checkPage(query, null, null, onePage, onePage, filterData, filterData); Cursor decodedCursor = Cursor.fromWebSafeString(cursor.toWebSafeString()); // fetch next page checkPage(query, decodedCursor, null, onePage, onePage, filterData, filterData); }
private void setCursor(QueryBuilder<?> builder, QueryResultList<Entity> queryResult) { if (queryResult.getCursor() != null) { builder.setCursor(queryResult.getCursor().toWebSafeString()); } }