本文整理汇总了Java中com.google.appengine.api.datastore.QueryResultIterator类的典型用法代码示例。如果您正苦于以下问题:Java QueryResultIterator类的具体用法?Java QueryResultIterator怎么用?Java QueryResultIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryResultIterator类属于com.google.appengine.api.datastore包,在下文中一共展示了QueryResultIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteAll
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
/**
* Delete all entities in batches of {@value BATCH_SIZE}.
*
* @return number of entities deleted
*/
public long deleteAll() {
Query<E> query = ofy().load().type(entityType).limit(BATCH_SIZE);
QueryResultIterator<Key<E>> iterator = query.keys().iterator();
List<Key<E>> keysToDelete = new ArrayList<>();
long numDeleted = 0;
while (iterator.hasNext()) {
Key<E> key = iterator.next();
keysToDelete.add(key);
if (!iterator.hasNext()) {
deleteByKey(fromKeys.from(keysToDelete));
numDeleted += keysToDelete.size();
keysToDelete.clear();
iterator = query.startAt(iterator.getCursor()).keys().iterator();
}
}
return numDeleted;
}
示例2: list
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
/**
* List all entities.
*
* @param cursor used for pagination to determine which page to return
* @param limit the maximum number of entries to return
* @return a response that encapsulates the result list and the next page token/cursor
*/
@ApiMethod(
name = "list",
path = "user",
httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<User> list(@Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
limit = limit == null ? DEFAULT_LIST_LIMIT : limit;
Query<User> query = ofy().load().type(User.class).limit(limit);
if (cursor != null) {
query = query.startAt(Cursor.fromWebSafeString(cursor));
}
QueryResultIterator<User> queryIterator = query.iterator();
List<User> userList = new ArrayList<User>(limit);
while (queryIterator.hasNext()) {
userList.add(queryIterator.next());
}
return CollectionResponse.<User>builder().setItems(userList).setNextPageToken(queryIterator.getCursor().toWebSafeString()).build();
}
示例3: list
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
/**
* List all entities.
*
* @param cursor used for pagination to determine which page to return
* @param limit the maximum number of entries to return
* @return a response that encapsulates the result list and the next page token/cursor
*/
@ApiMethod(
name = "list",
path = "joke",
httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<Joke> list(@Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
Integer limitParam = limit == null ? DEFAULT_LIST_LIMIT : limit;
Query<Joke> query = ofy().load().type(Joke.class).limit(limitParam);
if (cursor != null) {
query = query.startAt(Cursor.fromWebSafeString(cursor));
}
QueryResultIterator<Joke> queryIterator = query.iterator();
List<Joke> jokeList = new ArrayList<>(limitParam);
while (queryIterator.hasNext()) {
jokeList.add(queryIterator.next());
}
return CollectionResponse.<Joke>builder().setItems(jokeList).setNextPageToken(queryIterator.getCursor().toWebSafeString()).build();
}
示例4: list
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
/**
* List all entities.
*
* @param cursor used for pagination to determine which page to return
* @param limit the maximum number of entries to return
* @return a response that encapsulates the result list and the next page token/cursor
*/
@ApiMethod(
name = "list",
path = "orders",
httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<Orders> list(@Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
limit = limit == null ? DEFAULT_LIST_LIMIT : limit;
Query<Orders> query = ofy().load().type(Orders.class).limit(limit);
if (cursor != null) {
query = query.startAt(Cursor.fromWebSafeString(cursor));
}
QueryResultIterator<Orders> queryIterator = query.iterator();
List<Orders> ordersList = new ArrayList<Orders>(limit);
while (queryIterator.hasNext()) {
ordersList.add(queryIterator.next());
}
return CollectionResponse.<Orders>builder().setItems(ordersList).setNextPageToken(queryIterator.getCursor().toWebSafeString()).build();
}
示例5: list
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
/**
* List all entities.
*
* @param cursor used for pagination to determine which page to return
* @param limit the maximum number of entries to return
* @return a response that encapsulates the result list and the next page token/cursor
*/
@ApiMethod(
name = "list",
path = "users",
httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<Users> list(@Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) {
limit = limit == null ? DEFAULT_LIST_LIMIT : limit;
Query<Users> query = ofy().load().type(Users.class).limit(limit);
if (cursor != null) {
query = query.startAt(Cursor.fromWebSafeString(cursor));
}
QueryResultIterator<Users> queryIterator = query.iterator();
List<Users> usersList = new ArrayList<Users>(limit);
while (queryIterator.hasNext()) {
usersList.add(queryIterator.next());
}
return CollectionResponse.<Users>builder().setItems(usersList).setNextPageToken(queryIterator.getCursor().toWebSafeString()).build();
}
示例6: listBooks
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的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);
}
}
示例7: listBooksByUser
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的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);
}
}
示例8: getByProperty
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
/**
* Convenience method to get all objects matching a single property
*
* @param propName
* @param propValue
* @return T matching Object
* @throws TooManyResultsException
*/
public T getByProperty(String propName, Object propValue)
throws TooManyResultsException
{
QueryResultIterator<T> fetch = ofy().load().type(clazz)
.filter(propName, propValue)
.limit(2).iterator();
if (!fetch.hasNext())
{
return null;
}
T obj = fetch.next();
if (fetch.hasNext())
{
throw new TooManyResultsException(fetch.toString()
+ " returned too many results");
}
return obj;
}
示例9: getPseudoFromJid
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
public static String getPseudoFromJid(String p_jid)
{
if( p_jid == null )
{
return "???";
}
String jid = p_jid.split("/")[0];
Query<EbAccount> query = dao().query( EbAccount.class ).filter( "m_jabberId", jid );
QueryResultIterator<EbAccount> it = query.iterator();
if( !it.hasNext() )
{
// we could remove the end of jid @...
// but in this case someone can use a jid in the form of <existingPseudo>@anydomain
// to fool players !
return jid;
}
return it.next().getPseudo();
}
示例10: testCursor
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的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());
}
示例11: testIndexListFromIterator
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的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);
}
}
示例12: run
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
public void run(long cutOffTimeMillis) {
int updatedProfileCount = 0;
QueryResultIterator<VolunteerProfile> profileIterator = VolunteerProfile.withExpiredAppointments(
cutOffTimeMillis, CHUNK_SIZE);
List<VolunteerProfile> updatedProfiles = new ArrayList<VolunteerProfile>(CHUNK_SIZE);
while (profileIterator.hasNext() && hasTimeRemaining()) {
for (int i = 0; i < CHUNK_SIZE && profileIterator.hasNext(); i++) {
VolunteerProfile nextProfile = profileIterator.next();
nextProfile.removeExpiredAppointments(cutOffTimeMillis);
updatedProfiles.add(nextProfile);
updatedProfileCount++;
}
OfyService.ofy().put(updatedProfiles);
updatedProfiles.clear();
}
logger.info(String.format("Updated schedules for %d profiles", updatedProfileCount));
if (profileIterator.hasNext()) {
isTerminatedEarly = true;
logger.warning("Terminating early due to request timeout");
}
}
示例13: testFindingVolunteerWithOldAppointment
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
@Test
public void testFindingVolunteerWithOldAppointment() {
localServiceTestHelper.setUp();
VolunteerProfile volunteerProfile = new VolunteerProfile();
volunteerProfile.setUserId("1");
DateTime startTime = dateTime("2013-06-01T20:00:00-03:00");
DateTime endTime = dateTime("2013-06-01T20:30:00-03:00");
DateTime cutoffTime = dateTime("2013-06-02T00:00:00-03:00");
volunteerProfile.addAppointmentTime(getRideRequest(), startTime, endTime);
Objectify ofy = OfyService.ofy();
ofy.put(volunteerProfile);
QueryResultIterator<VolunteerProfile> volunteerProfileIterator = VolunteerProfile
.withExpiredAppointments(cutoffTime.getMillis(), 100);
List<VolunteerProfile> volunteerProfiles = CollectionUtils.listOfIterator(volunteerProfileIterator);
assertEquals(Arrays.asList(volunteerProfile), volunteerProfiles);
localServiceTestHelper.tearDown();
}
示例14: testFindingVolunteerWithoutOldAppointments
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
@Test
public void testFindingVolunteerWithoutOldAppointments() {
localServiceTestHelper.setUp();
VolunteerProfile volunteerProfile = new VolunteerProfile();
volunteerProfile.setUserId("1");
DateTime startTime = dateTime("2013-06-01T20:00:00-03:00");
DateTime endTime = dateTime("2013-06-01T20:30:00-03:00");
DateTime cutoffTime = dateTime("2013-05-30T00:00:00-03:00");
volunteerProfile.addAppointmentTime(getRideRequest(), startTime, endTime);
Objectify ofy = OfyService.ofy();
ofy.put(volunteerProfile);
QueryResultIterator<VolunteerProfile> volunteerProfileIterator = VolunteerProfile
.withExpiredAppointments(cutoffTime.getMillis(), 100);
List<VolunteerProfile> volunteerProfiles = CollectionUtils.listOfIterator(volunteerProfileIterator);
assertTrue(volunteerProfiles.isEmpty());
localServiceTestHelper.tearDown();
}
示例15: listAllForQuery
import com.google.appengine.api.datastore.QueryResultIterator; //导入依赖的package包/类
public List<E> listAllForQuery(Query<E> query) {
QueryResultIterator<E> iterator = query.iterator();
List<E> entities = new ArrayList<>();
while (iterator.hasNext()) {
entities.add(iterator.next());
if (!iterator.hasNext()) {
iterator = query.startAt(iterator.getCursor()).iterator();
}
}
return entities;
}