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


Java QueryResultIterator.next方法代码示例

本文整理汇总了Java中com.google.appengine.api.datastore.QueryResultIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java QueryResultIterator.next方法的具体用法?Java QueryResultIterator.next怎么用?Java QueryResultIterator.next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.appengine.api.datastore.QueryResultIterator的用法示例。


在下文中一共展示了QueryResultIterator.next方法的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;
}
 
开发者ID:3wks,项目名称:generator-thundr-gae-react,代码行数:23,代码来源:BaseRepository.java

示例2: 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;
}
 
开发者ID:turbomanage,项目名称:listmaker,代码行数:27,代码来源:ObjectifyDao.java

示例3: 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");
    }
}
 
开发者ID:openmash,项目名称:mashmesh,代码行数:27,代码来源:VolunteerScheduleScrubber.java

示例4: 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;
    }
}
 
开发者ID:ipeirotis,项目名称:mturk-surveys,代码行数:38,代码来源:MergeAnswersServlet.java

示例5: 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;
    }
}
 
开发者ID:ipeirotis,项目名称:mturk-surveys,代码行数:31,代码来源:ApproveAssignmentsServlet.java

示例6: 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;
    }
}
 
开发者ID:ipeirotis,项目名称:mturk-surveys,代码行数:40,代码来源:DisposeHITsServlet.java

示例7: list

import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
public CollectionResponse<UserAnswer> list(String cursorString, Integer limit) throws NoSuchAlgorithmException {
    List<UserAnswer> result = new ArrayList<UserAnswer>();
    Query<UserAnswer> query = ofy().load().type(UserAnswer.class)
            .filter("surveyId", DEMOGRAPHICS_SURVEY_ID).order("-date");

    if(cursorString != null) {
        query = query.startAt(Cursor.fromWebSafeString(cursorString));
    }

    if(limit != null) {
        query = query.limit(limit);
    }

    boolean cont = false;
    QueryResultIterator<UserAnswer> iterator = query.iterator();

    while (iterator.hasNext()) {
        UserAnswer userAnswer = iterator.next();
        String workerId = userAnswer.getWorkerId();
        if(workerId != null) {
            userAnswer.setWorkerId(MD5.crypt(workerId));
        }
        userAnswer.setIp(null);
        result.add(userAnswer);
        cont = true;
    }

    if(cont) {
        Cursor cursor = iterator.getCursor();
        return CollectionResponse.<UserAnswer> builder().setItems(result).setNextPageToken(cursor.toWebSafeString()).build();
    } else {
        return CollectionResponse.<UserAnswer> builder().setItems(result).build();
    }
}
 
开发者ID:ipeirotis,项目名称:mturk-surveys,代码行数:35,代码来源:UserAnswerService.java

示例8: testReverse

import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
@Test
public void testReverse() {
    Query query = new Query(kindName, rootKey);
    query.addSort(Entity.KEY_RESERVED_PROPERTY);
    QueryResultIterator<Entity> iter = service.prepare(query).asQueryResultIterator();
    Entity e1 = iter.next();
    Entity e2 = iter.next();
    Cursor cursor = iter.getCursor();
    //reverse
    query = query.reverse();
    cursor = cursor.reverse();
    iter = service.prepare(query).asQueryResultIterator(FetchOptions.Builder.withStartCursor(cursor));
    Assert.assertEquals(e2, iter.next());
    Assert.assertEquals(e1, iter.next());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:16,代码来源:CursorTest.java

示例9: getAllTrails

import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
/**
 * This method returns the all the trails that have been registered in the competition of MapatonCDMX
 * paginated by parameter.numberOfElements and parameter.cursor to define where to start and how many elements to get.
 * @author Rodrigo Cabrera ([email protected])
 * @since 16 / feb / 2016
 * @param parameter The object containing all the parameters for the request.
 * @return The list of trails and the cursor to be able to get the next N number of elements.
 * @throws TrailNotFoundException 
 */
public TrailListResponse getAllTrails(CursorParameter parameter) {

	logger.debug("Getting user trails...");

	ArrayList<TrailDetails> result = new ArrayList<TrailDetails>();
	Query<RegisteredTrail> query = OfyService.ofy().cache(false)
			.consistency(Consistency.STRONG).load().type(RegisteredTrail.class);
	
	query = CursorHelper.processCursor(query, parameter);
		
	QueryResultIterator<RegisteredTrail> it = query.iterator();
	while(it.hasNext()){
		RegisteredTrail t = it.next();
		result.add(new TrailDetails(t, t.getCreationDate()));
	}
	
	
	TrailListResponse theResult = new TrailListResponse(result, it.getCursor().toWebSafeString());

	// logger.debug("Getting all trails... "+result);

	return theResult;
}
 
开发者ID:LabPLC,项目名称:MapatonAPI,代码行数:33,代码来源:TrailsHandler.java

示例10: getAllValidTrails

import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
/**
 * This method returns the all the trails that have been registered in the competition of MapatonCDMX
 * paginated by parameter.numberOfElements and parameter.cursor to define where to start and how many elements to get.
 * @author Rodrigo Cabrera ([email protected])
 * @since 16 / feb / 2016
 * @param parameter The object containing all the parameters for the request.
 * @return The list of trails and the cursor to be able to get the next N number of elements.
 * @throws TrailNotFoundException 
 */
public TrailListResponse getAllValidTrails(CursorParameter parameter) {

	logger.debug("Getting user trails...");

	ArrayList<TrailDetails> result = new ArrayList<TrailDetails>();
	Query<RegisteredTrail> query = OfyService.ofy().cache(false)
			.consistency(Consistency.STRONG).load().type(RegisteredTrail.class)
			.filter("trailStatus", RegisteredTrailStatusEnum.VALID);
	
	query = CursorHelper.processCursor(query, parameter);
		
	QueryResultIterator<RegisteredTrail> it = query.iterator();
	while(it.hasNext()){
		RegisteredTrail t = it.next();
		result.add(new TrailDetails(t, t.getCreationDate()));
	}
	
	
	TrailListResponse theResult = new TrailListResponse(result, it.getCursor().toWebSafeString());

	// logger.debug("Getting all trails... "+result);

	return theResult;
}
 
开发者ID:LabPLC,项目名称:MapatonAPI,代码行数:34,代码来源:TrailsHandler.java

示例11: getAllGtfsTrails

import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
/**
 * This method returns the all the trails that have been registered in the competition of MapatonCDMX
 * paginated by parameter.numberOfElements and parameter.cursor to define where to start and how many elements to get.
 * @author Rodrigo Cabrera ([email protected])
 * @since 16 / feb / 2016
 * @param parameter The object containing all the parameters for the request.
 * @return The list of trails and the cursor to be able to get the next N number of elements.
 * @throws TrailNotFoundException 
 */
public TrailListResponse getAllGtfsTrails(CursorParameter parameter) {

	logger.debug("Getting user trails...");

	ArrayList<TrailDetails> result = new ArrayList<TrailDetails>();
	Query<RegisteredTrail> query = OfyService.ofy().cache(false)
			.consistency(Consistency.STRONG).load().type(RegisteredTrail.class)
			.filter("gtfsStatus", RegisteredTrail.GtfsStatus.VALID);
	
	query = CursorHelper.processCursor(query, parameter);
		
	QueryResultIterator<RegisteredTrail> it = query.iterator();
	while(it.hasNext()){
		RegisteredTrail t = it.next();
		result.add(new TrailDetails(t, t.getCreationDate()));
	}
	
	
	TrailListResponse theResult = new TrailListResponse(result, it.getCursor().toWebSafeString());

	// logger.debug("Getting all trails... "+result);

	return theResult;
}
 
开发者ID:LabPLC,项目名称:MapatonAPI,代码行数:34,代码来源:TrailsHandler.java

示例12: 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 = "article",
        httpMethod = ApiMethod.HttpMethod.GET)
public CollectionResponse<Article> list(@Named("cat") String category,
                                        @Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit,
                                        @Nullable @Named("from") Long from, @Nullable @Named("to") Long to,
                                        @Nullable @Named("timehash") Long timehash, @Nullable @Named("cert") String cert)
        throws ForbiddenException {
    validateRequest(timehash, cert);

    limit = (limit == null || limit <= 0) ? DEFAULT_LIST_LIMIT : limit;
    //test();
    Query<Article> query = ObjectifyService.ofy().load().type(Article.class).order("-created").limit(limit);
    if (category != null && !"".equals(category)) {
        query = query.filter("category", category);
    }
    if (from != null && to != null && 0 < from && from <= to) {
        query = query.filter("created >", new Date(from)).filter("created <", new Date(to));
    }
    if (cursor != null) {
        query = query.startAt(Cursor.fromWebSafeString(cursor));
    }
    QueryResultIterator<Article> queryIter = query.iterator();
    List<Article> articleList = new ArrayList<Article>(limit);

    // TODO Use random to choose big style
    Random random = new Random();
    boolean isFirst = true;

    while (queryIter.hasNext()) {
        Article article = queryIter.next();
        // To save data transfer
        article.setFullContent(null);
        if (isFirst || random.nextInt(8) == 0) {
            article.setStyle(1);
            isFirst = false;
        }
        articleList.add(article);
    }
    return CollectionResponse.<Article>builder().setItems(articleList).setNextPageToken(queryIter.getCursor().toWebSafeString()).build();
}
 
开发者ID:kimkha,项目名称:triethocduongpho,代码行数:50,代码来源:Article2Endpoint.java

示例13: perform

import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
@Override
public Page perform(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {
	String cursor = req.getParameter("cursor");

	Objectify ob = DefaultServlet.getObjectify();
	Query<PackageVersion> q = ob.query(PackageVersion.class);
	if (cursor != null)
		q.startCursor(Cursor.fromWebSafeString(cursor));
	q.limit(100);

	QueryResultIterator<PackageVersion> iterator = q.iterator();

	int n = 0;
	List<PackageVersion> list = new ArrayList<PackageVersion>();
	while (iterator.hasNext()) {
		PackageVersion data = iterator.next();
		list.add(data);
		n++;
	}

	ob.put(list);

	if (n == 100) {
		cursor = iterator.getCursor().toWebSafeString();
	} else {
		cursor = null;
		NWUtils.sendMailToAdmin("cursor == nul for /tasks/resave-package-version");
	}

	Queue queue = QueueFactory.getQueue("resave");
	try {
		TaskOptions to = withUrl("/tasks/resave-package-versions");
		if (cursor != null)
			to.param("cursor", cursor);

		queue.add(to);
	} catch (TaskAlreadyExistsException e) {
		NWUtils.LOG
				.warning("task /tasks/resave-package-version already exists");
	}

	resp.setStatus(200);
	return null;
}
 
开发者ID:tim-lebedkov,项目名称:npackd-gae-web,代码行数:46,代码来源:ForEachPackageVersionAction.java

示例14: perform

import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
@Override
public Page perform(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
    String cursor = req.getParameter("cursor");

    Objectify ob = DefaultServlet.getObjectify();
    Query<Package> q = ob.query(Package.class);
    if (cursor != null) {
        q.startCursor(Cursor.fromWebSafeString(cursor));
    }
    q.limit(1);

    QueryResultIterator<Package> iterator = q.iterator();
    Package data;
    if (iterator.hasNext()) {
        data = iterator.next();
    } else {
        data = null;
    }
    if (data != null) {
        Package old = data.copy();
        NWUtils.LOG.log(Level.INFO, "check-update for {0}", data.name);
        Date noUpdatesCheck = null;
        if ("0".equals(req.getHeader("X-AppEngine-TaskRetryCount"))) {
            try {
                Version v = data.findNewestVersion();
                List<PackageVersion> versions = data.getSortedVersions(ob);
                if (versions.size() > 0) {
                    PackageVersion pv = versions.get(versions.size() - 1);
                    int r = v.compare(Version.parse(pv.version));
                    if (r == 0) {
                        noUpdatesCheck = NWUtils.newDate();
                    } else if (r > 0) {
                        data.createDetectedVersion(ob, v, 0);
                    }
                }
            } catch (IOException e) {
                // ignore
            }
        }

        if (noUpdatesCheck != null || data.noUpdatesCheck != null) {
            data.noUpdatesCheck = noUpdatesCheck;
            NWUtils.savePackage(ob, old, data, false);
        }

        NWUtils.LOG.log(Level.INFO, "check-update noUpdatesCheck= {0}",
                data.noUpdatesCheck);

        cursor = iterator.getCursor().toWebSafeString();
    } else {
        cursor = null;
    }

    Queue queue = QueueFactory.getQueue("check-update");
    TaskOptions to = withUrl("/tasks/check-update");
    if (cursor != null) {
        to.param("cursor", cursor);
    }

    // 2 minutes
    to.countdownMillis(2 * 60 * 1000);

    // NWUtils.LOG.warning("adding task at cursor " + cursor);
    queue.add(to);

    resp.setStatus(200);
    return null;
}
 
开发者ID:tim-lebedkov,项目名称:npackd-gae-web,代码行数:70,代码来源:CheckUpdatesAction.java

示例15: list

import com.google.appengine.api.datastore.QueryResultIterator; //导入方法依赖的package包/类
@Override
public ListItemBatch list(String bucket, String prefix, String delimiter,
    String marker, int maxResults, long timeoutMillis) throws IOException {
  ensureInitialized();
  Query query = makeQuery(bucket);
  int prefixLength;
  if (!Strings.isNullOrEmpty(prefix)) {
    Key keyPrefix = makeKey(bucket, prefix);
    query.setFilter(new FilterPredicate(KEY_RESERVED_PROPERTY, GREATER_THAN_OR_EQUAL, keyPrefix));
    prefixLength = prefix.length();
  } else {
    prefixLength = 0;
  }
  FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();
  if (marker != null) {
    fetchOptions.startCursor(Cursor.fromWebSafeString(marker));
  }
  List<ListItem> items = new ArrayList<>(maxResults);
  Set<String> prefixes = new HashSet<>();
  QueryResultIterator<Entity> dsResults =
      datastore.prepare(query).asQueryResultIterator(fetchOptions);
  while (items.size() < maxResults && dsResults.hasNext()) {
    Entity entity = dsResults.next();
    String name = entity.getKey().getName();
    if (prefixLength > 0 && !name.startsWith(prefix)) {
      break;
    }
    if (!Strings.isNullOrEmpty(delimiter)) {
      int delimiterIdx = name.indexOf(delimiter, prefixLength);
      if (delimiterIdx > 0) {
        name = name.substring(0, delimiterIdx + 1);
        if (prefixes.add(name)) {
          items.add(new ListItem.Builder().setName(name).setDirectory(true).build());
        }
        continue;
      }
    }
    GcsFilename filename = new GcsFilename(bucket, name);
    GcsFileMetadata metadata = createGcsFileMetadata(entity, filename);
    ListItem listItem = new ListItem.Builder()
        .setName(name)
        .setLength(metadata.getLength())
        .setLastModified(metadata.getLastModified())
        .build();
    items.add(listItem);
  }
  Cursor cursor = dsResults.getCursor();
  String nextMarker = null;
  if (items.size() == maxResults && cursor != null) {
    nextMarker = cursor.toWebSafeString();
  }
  return new ListItemBatch(items, nextMarker);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:54,代码来源:LocalRawGcsService.java


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