本文整理汇总了Java中com.google.appengine.api.datastore.PreparedQuery.asQueryResultIterator方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedQuery.asQueryResultIterator方法的具体用法?Java PreparedQuery.asQueryResultIterator怎么用?Java PreparedQuery.asQueryResultIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.datastore.PreparedQuery
的用法示例。
在下文中一共展示了PreparedQuery.asQueryResultIterator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listBooks
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Override
public Result<Book> listBooks(String startCursorString) {
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(10); // Only show 10 at a time
if (startCursorString != null && !startCursorString.equals("")) {
fetchOptions.startCursor(Cursor.fromWebSafeString(startCursorString)); // Where we left off
}
Query query = new Query(BOOK_KIND) // We only care about Books
.addSort(Book.TITLE, SortDirection.ASCENDING); // Use default Index "title"
PreparedQuery preparedQuery = datastore.prepare(query);
QueryResultIterator<Entity> results = preparedQuery.asQueryResultIterator(fetchOptions);
List<Book> resultBooks = entitiesToBooks(results); // Retrieve and convert Entities
Cursor cursor = results.getCursor(); // Where to start next time
if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor
String cursorString = cursor.toWebSafeString(); // Cursors are WebSafe
return new Result<>(resultBooks, cursorString);
} else {
return new Result<>(resultBooks);
}
}
示例2: listBooksByUser
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Override
public Result<Book> listBooksByUser(String userId, String startCursorString) {
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(10); // Only show 10 at a time
if (startCursorString != null && !startCursorString.equals("")) {
fetchOptions.startCursor(Cursor.fromWebSafeString(startCursorString)); // Where we left off
}
Query query = new Query(BOOK_KIND) // We only care about Books
// Only for this user
.setFilter(new Query.FilterPredicate(
Book.CREATED_BY_ID, Query.FilterOperator.EQUAL, userId))
// a custom datastore index is required since you are filtering by one property
// but ordering by another
.addSort(Book.TITLE, SortDirection.ASCENDING);
PreparedQuery preparedQuery = datastore.prepare(query);
QueryResultIterator<Entity> results = preparedQuery.asQueryResultIterator(fetchOptions);
List<Book> resultBooks = entitiesToBooks(results); // Retrieve and convert Entities
Cursor cursor = results.getCursor(); // Where to start next time
if (cursor != null && resultBooks.size() == 10) { // Are we paging? Save Cursor
String cursorString = cursor.toWebSafeString(); // Cursors are WebSafe
return new Result<>(resultBooks, cursorString);
} else {
return new Result<>(resultBooks);
}
}
示例3: testCursor
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@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());
}
示例4: testIndexListFromIterator
import com.google.appengine.api.datastore.PreparedQuery; //导入方法依赖的package包/类
@Test
public void testIndexListFromIterator() throws Exception {
Entity parent = createTestEntityWithUniqueMethodNameKey("Person", "testKeysOnly");
Key key = parent.getKey();
Entity tom = createEntity("Person", key)
.withProperty("name", "Tom")
.withProperty("surname", "Foe")
.store();
Query query = new Query("Person")
.setAncestor(key)
.setKeysOnly();
PreparedQuery preparedQuery = service.prepare(query);
QueryResultIterator<Entity> iter = preparedQuery.asQueryResultIterator();
List<Index> indexes = iter.getIndexList();
if (indexes != null) {
// TODO -- something useful
System.out.println("indexes = " + indexes);
}
}