当前位置: 首页>>代码示例>>Java>>正文


Java PreparedQuery.asQueryResultIterator方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:21,代码来源:DatastoreDao.java

示例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);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:26,代码来源:DatastoreDao.java

示例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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:23,代码来源:QueryResultTest.java

示例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);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:23,代码来源:QueryResultTest.java


注:本文中的com.google.appengine.api.datastore.PreparedQuery.asQueryResultIterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。