FetchOptions options = FetchOptions.Builder.withOffset(0); options = FetchOptions.Builder.withOffset(offset);
@Test public void testOffsetMultiple() { List<Entity> results = executeQuery(withDefaults()); assertEquals(5, results.size()); assertEquals(asList(foo1, foo2, foo3, foo4, foo5), results); List<Entity> results2 = executeQuery(withOffset(1)); assertEquals(4, results2.size()); assertEquals(asList(foo2, foo3, foo4, foo5), results2); List<Entity> results3 = executeQuery(withDefaults()); assertEquals(5, results3.size()); assertEquals(asList(foo1, foo2, foo3, foo4, foo5), results3); }
@Test public void testOffset() { List<Entity> results = executeQuery(withOffset(3)); assertEquals(asList(foo4, foo5), results); }
opts = withOffset(offset);
@Test public void testOffsetAndLimit() { List<Entity> results = executeQuery(withOffset(1).limit(1)); assertEquals(asList(foo2), results); }
@Test @InSequence(3) public void testStep3ListWithOption() { FetchOptions foList = FetchOptions.Builder.withLimit(limit); Query q = new Query(kindName, rootKey); List<Entity> eData = service.prepare(q).asList(foList); assertEquals(limit, eData.size()); foList = FetchOptions.Builder.withOffset(offset); eData = service.prepare(q).asList(foList); assertEquals(bigCount - offset, eData.size()); }
/** * Executes the specified query within the specified transaction without an * offset qualification. * * @param transaction The transaction in which the specified query is * executed. * @param query The query to be executed. * @return The query result as {@code List} view. */ public List<Entity> query(Transaction transaction, Query query) { return query(transaction, query, FetchOptions.Builder.withOffset(0)); }
/** * Executes the specified query without an offset qualification. * * @param paramQuery The query to be executed. * @return The query result as {@code List} view. */ public List<Entity> query(Query query) { return query(query, FetchOptions.Builder.withOffset(0)); }
@Test @InSequence(5) public void testStep5IteratorWithOption() { FetchOptions foIterator = FetchOptions.Builder.withLimit(limit); Query q = new Query(kindName, rootKey); Iterator<Entity> eData = service.prepare(q).asIterator(foIterator); assertEquals(limit, getSize(eData)); foIterator = FetchOptions.Builder.withOffset(offset); eData = service.prepare(q).asIterator(foIterator); assertEquals(bigCount - offset, getSize(eData)); }
@Test @InSequence(7) public void testStep7IterableWithOption() { FetchOptions foIterable = FetchOptions.Builder.withLimit(limit); Query q = new Query(kindName, rootKey); Iterator<Entity> eData = service.prepare(q).asIterator(fo.limit(limit)); assertEquals(limit, getSize(eData)); foIterable = FetchOptions.Builder.withOffset(offset); eData = service.prepare(q).asIterator(foIterable); assertEquals(bigCount - offset, getSize(eData)); }
@Test public void testOffsetWithIterator() { Iterable<Entity> results2 = executeQueryForIterable(withOffset(1)); int count = 0; //noinspection UnusedDeclaration for (Entity e : results2) { count++; } assertEquals(4, count); }