Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.PreparedQuery


  private static final ReadServiceImpl readService = new ReadServiceImpl();
  private ReportMetaData[] metaData;

  @Override
  public Map<Integer, Double> getAnnuallyOfferingVolumes() {
    final PreparedQuery pq = db.prepare(new Query(Offering.class.getSimpleName()));
    final ListQueryResult r = copy.entitiesToDtoArray(Offering.class.getSimpleName(), pq.countEntities(withDefaults()), pq.asIterable(withDefaults()), false);
    return new OfferingReports().getAnnuallyOfferingVolumes(r.getResults());
  }
View Full Code Here


  private static Entity findDeviceByRegId(String regId) {
    Filter filter =
        new FilterPredicate(DEVICE_REG_ID_PROPERTY, FilterOperator.EQUAL, regId);
    Query query = new Query(DEVICE_TYPE).setFilter(filter);
    PreparedQuery preparedQuery = datastore.prepare(query);
    List<Entity> entities = preparedQuery.asList(DEFAULT_FETCH_OPTIONS);
    Entity entity = null;
    if (!entities.isEmpty()) {
      entity = entities.get(0);
    }
    int size = entities.size();
View Full Code Here

  }

  public List<Entity> queryAll(final String kind, final Key rootJobKey) {
    Query query = new Query(kind);
    query.setFilter(new FilterPredicate(ROOT_JOB_KEY_PROPERTY, EQUAL, rootJobKey));
    final PreparedQuery preparedQuery = dataStore.prepare(query);
    final FetchOptions options = FetchOptions.Builder.withChunkSize(500);
    return tryFiveTimes(new Operation<List<Entity>>("queryFullPipeline") {
      @Override
      public List<Entity> call() {
        return preparedQuery.asList(options);
      }
    });
  }
View Full Code Here

    Query query = new Query(JobRecord.DATA_STORE_KIND);
    Filter filter = classFilter == null || classFilter.isEmpty() ? new FilterPredicate(
        ROOT_JOB_DISPLAY_NAME, GREATER_THAN, null)
        : new FilterPredicate(ROOT_JOB_DISPLAY_NAME, EQUAL, classFilter);
    query.setFilter(filter);
    final PreparedQuery preparedQuery = dataStore.prepare(query);
    final FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();
    if (limit > 0) {
      fetchOptions.limit(limit + 1);
    }
    if (cursor != null) {
      fetchOptions.startCursor(Cursor.fromWebSafeString(cursor));
    }
    return tryFiveTimes(
        new Operation<Pair<? extends Iterable<JobRecord>, String>>("queryRootPipelines") {
          @Override
          public Pair<? extends Iterable<JobRecord>, String> call() {
            QueryResultIterator<Entity> entities =
                preparedQuery.asQueryResultIterable(fetchOptions).iterator();
            Cursor dsCursor = null;
            List<JobRecord> roots = new LinkedList<>();
            while (entities.hasNext()) {
              if (limit > 0 && roots.size() >= limit) {
                dsCursor = entities.getCursor();
View Full Code Here

  public Set<String> getRootPipelinesDisplayName() {
    Query query = new Query(JobRecord.DATA_STORE_KIND);
    query.addProjection(
        new PropertyProjection(JobRecord.ROOT_JOB_DISPLAY_NAME, String.class));
    query.setDistinct(true);
    final PreparedQuery preparedQuery = dataStore.prepare(query);
    return tryFiveTimes(new Operation<Set<String>>("getRootPipelinesDisplayName") {
      @Override
      public Set<String> call() {
        Set<String> pipelines = new LinkedHashSet<>();
        for (Entity entity : preparedQuery.asIterable()) {
          pipelines.add((String) entity.getProperty(JobRecord.ROOT_JOB_DISPLAY_NAME));
        }
        return pipelines;
      }
    });
View Full Code Here

  private void deleteAll(final String kind, final Key rootJobKey) {
    logger.info("Deleting all " + kind + " with rootJobKey=" + rootJobKey);
    final int chunkSize = 100;
    final FetchOptions fetchOptions = FetchOptions.Builder.withChunkSize(chunkSize);
    final PreparedQuery preparedQuery = dataStore.prepare(new Query(kind).setKeysOnly().setFilter(
        new FilterPredicate(ROOT_JOB_KEY_PROPERTY, EQUAL, rootJobKey)));
    tryFiveTimes(new Operation<Void>("delete") {
      @Override
      public Void call() {
        Iterator<Entity> iter = preparedQuery.asIterator(fetchOptions);
        while (iter.hasNext()) {
          ArrayList<Key> keys = new ArrayList<>(chunkSize);
          for (int i = 0; i < chunkSize && iter.hasNext(); i++) {
            keys.add(iter.next().getKey());
          }
View Full Code Here

  }

  private Entity findByUsername(String username) {
    Query query = new Query(userStoreKind);
    query.addFilter("username", Query.FilterOperator.EQUAL, username);
    PreparedQuery preparedQuery = datastoreService.prepare(query);
    return preparedQuery.asSingleEntity();
  }
View Full Code Here

      if (null != this.lastUpdate) {
        Long now = new Date().getTime();
        query.addFilter("timestamp", FilterOperator.GREATER_THAN_OR_EQUAL, (now - (MAX_CLOCK_SKEW)));
      }
     
      PreparedQuery pq = asyncDatastoreService.prepare(query);
      Iterator<Entity> it = pq.asIterator();
     
      while (it.hasNext()) {
        Entity entity = it.next();
       
        @SuppressWarnings("unchecked")
View Full Code Here

     * @param qry
     *            the query
     * @return entities as list
     */
    protected List<Entity> asEntityList(DatastoreService ds, Query qry) {
        PreparedQuery pq =
            txSet ? DatastoreUtil.prepare(ds, tx, qry) : DatastoreUtil.prepare(
                ds,
                qry);
        return DatastoreUtil.asList(pq, fetchOptions);
    }
View Full Code Here

     *
     * @return entities as query result list
     */
    protected QueryResultList<Entity> asQueryResultEntityList() {
        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        PreparedQuery pq =
            txSet ? DatastoreUtil.prepare(ds, tx, query) : DatastoreUtil
                .prepare(ds, query);
        return DatastoreUtil.asQueryResultList(pq, fetchOptions);
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.PreparedQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.