本文整理汇总了Java中com.google.appengine.api.datastore.QueryResultIterator.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java QueryResultIterator.hasNext方法的具体用法?Java QueryResultIterator.hasNext怎么用?Java QueryResultIterator.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.datastore.QueryResultIterator
的用法示例。
在下文中一共展示了QueryResultIterator.hasNext方法的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: 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;
}
示例7: 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();
}
示例8: 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");
}
}
示例9: 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;
}
示例10: getRandomJoke
import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
/**
* @return A randomly chosen {@link Joke} object
*/
@ApiMethod(
name = "getRandomJoke",
path = "joke/random",
httpMethod = ApiMethod.HttpMethod.GET)
public Joke getRandomJoke() {
logger.info("Getting random joke");
QueryKeys<Joke> keys = ofy().load().type(Joke.class).keys();
QueryResultIterator<Key<Joke>> iterator = keys.iterator();
List<Key> keyList = new ArrayList<>();
while (iterator.hasNext())
keyList.add(iterator.next());
Key key = keyList.get(random.nextInt(keyList.size() - 1));
return (Joke) ofy().load().key(key).now();
}
示例11: listQuote
import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
@ApiMethod(name = "listUsers")
public CollectionResponse<Users> listQuote(@Nullable @com.google.api.server.spi.config.Named("cursor") String cursorString,
@Nullable @com.google.api.server.spi.config.Named("count") Integer count) {
Query<Users> query = ofy().load().type(Users.class);
if (count != null) query.limit(count);
if (cursorString != null && cursorString != "") {
query = query.startAt(Cursor.fromWebSafeString(cursorString));
}
List<Users> records = new ArrayList<Users>();
QueryResultIterator<Users> iterator = query.iterator();
int num = 0;
while (iterator.hasNext()) {
records.add(iterator.next());
if (count != null) {
num++;
if (num == count) break;
}
}
//Find the next cursor
if (cursorString != null && cursorString != "") {
Cursor cursor = iterator.getCursor();
if (cursor != null) {
cursorString = cursor.toWebSafeString();
}
}
return CollectionResponse.<Users>builder().setItems(records).setNextPageToken(cursorString).build();
}
示例12: orderlist
import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
@ApiMethod(
name = "orderlist",
httpMethod = ApiMethod.HttpMethod.GET)
public List<Orders> orderlist(@javax.annotation.Nullable @Named("cursor") String cursor){
Query<Orders> query = ofy().load().type(Orders.class).limit(1000);
if (cursor != null)
query = query.startAt(Cursor.fromWebSafeString(cursor));
QueryResultIterator<Orders> queryIterator = query.iterator();
List<Orders> ordersList = new ArrayList<Orders>(1000);
while (queryIterator.hasNext()) {
ordersList.add(queryIterator.next());
}
return ordersList;
}
示例13: merge
import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
private String merge(String cursorString) {
Query<UserAnswer> query = ofy().load().type(UserAnswer.class).limit(1000);
List<UserAnswer> toSaveList = new ArrayList<UserAnswer>();
if (cursorString != null) {
query = query.startAt(Cursor.fromWebSafeString(cursorString));
}
boolean cont = false;
QueryResultIterator<UserAnswer> iterator = query.iterator();
while (iterator.hasNext()) {
UserAnswer userAnswer = iterator.next();
Map<String, String> answers = userAnswer.getAnswers();
if(answers != null) {
String answer = answers.get("householdIncome");
if("$100,000-$149,999".equals(answer) || "$150,000-$199,999".equals(answer) ||
"$200,000-$249,999".equals(answer) || "$300,000 or more".equals(answer)) {
answers.put("householdIncome", "$100,000 or more");
toSaveList.add(userAnswer);
}
}
cont = true;
}
if(toSaveList.size() > 0) {
ofy().save().entities(toSaveList).now();
logger.info(String.format("Merged %d answers", toSaveList.size()));
}
if(cont) {
Cursor cursor = iterator.getCursor();
return cursor.toWebSafeString();
} else {
return null;
}
}
示例14: approve
import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
private String approve(String cursorString) {
Query<UserAnswer> query = ofy().load().type(UserAnswer.class).limit(30);
if (cursorString != null) {
query = query.startAt(Cursor.fromWebSafeString(cursorString));
}
boolean cont = false;
QueryResultIterator<UserAnswer> iterator = query.iterator();
while (iterator.hasNext()) {
UserAnswer userAnswer = iterator.next();
try {
List<Assignment> assignments = getAssignmentsForHITService.getAssignments(true, userAnswer.getHitId());
for(Assignment assignment: assignments) {
approveAssignmentService.approveAssignment(true, assignment.getAssignmentId());
}
} catch (MturkException e) {
logger.log(Level.WARNING, e.getMessage());
}
cont = true;
}
if(cont) {
Cursor cursor = iterator.getCursor();
return cursor.toWebSafeString();
} else {
return null;
}
}
示例15: dispose
import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
private String dispose(String cursorString) {
Calendar endCal = Calendar.getInstance();
endCal.setTime(new Date());
endCal.set(Calendar.HOUR_OF_DAY, 0);
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.SECOND, 0);
Calendar startCal = Calendar.getInstance();
startCal.setTime(endCal.getTime());
startCal.add(Calendar.DAY_OF_MONTH, -1);
Query<UserAnswer> query = ofy().load().type(UserAnswer.class)
.filter("date >=", startCal.getTime()).filter("date <", endCal.getTime()).limit(30);
if (cursorString != null) {
query = query.startAt(Cursor.fromWebSafeString(cursorString));
}
boolean cont = false;
QueryResultIterator<UserAnswer> iterator = query.iterator();
while (iterator.hasNext()) {
UserAnswer userAnswer = iterator.next();
try {
disposeHITService.disposeHIT(true, userAnswer.getHitId());
logger.log(Level.INFO, String.format("Disposed HIT %s", userAnswer.getHitId()));
} catch (MturkException e) {
logger.log(Level.WARNING, e.getMessage());
}
cont = true;
}
if(cont) {
Cursor cursor = iterator.getCursor();
return cursor.toWebSafeString();
} else {
return null;
}
}