Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.DatastoreService.prepare()


    Query q = new Query(kind, parentEntity.getKey());
    DatastoreServiceConfig config = getStoreManager().getDefaultDatastoreServiceConfigForReads();
    DatastoreService datastoreService = DatastoreServiceFactoryInternal.getDatastoreService(config);
    // We have to pull back all children because the datastore does not let us filter ancestors by
    // depth and an indirect child could come back before a direct child.  eg: a/b/c,  a/c
    for (Entity e : datastoreService.prepare(q).asIterable()) {
      if (parentEntity.getKey().equals(e.getKey().getParent())) {
        return EntityUtils.entityToPojo(e, childCmd, clr, ec, false, ec.getFetchPlan());
        // We are potentially ignoring data errors where there is more than one
        // direct child for the one to one.  Unfortunately, in order to detect
        // this we need to read all the way to the end of the Iterable and that
View Full Code Here


    // create an entity just to capture the name of the index property
    Entity entity = new Entity(kind);
    orderMapping.setObject(ec, entity, new int[] {1}, oldIndex);
    String indexProp = entity.getProperties().keySet().iterator().next();
    q.addFilter(indexProp, Query.FilterOperator.GREATER_THAN_OR_EQUAL, oldIndex);
    for (Entity shiftMe : service.prepare(service.getCurrentTransaction(null), q).asIterable()) {
      Long pos = (Long) shiftMe.getProperty(indexProp);
      shiftMe.setProperty(indexProp, pos + amount);
      EntityUtils.putEntityIntoDatastore(ec, shiftMe);
    }
    return null;
View Full Code Here

      @Override
      public Object apply(Entity from) {
        return EntityUtils.entityToPojo(from, elementCmd, clr, ec, false, ec.getFetchPlan());
      }
    };
    return new LazyResult(ds.prepare(q).asIterable(), func, true).listIterator();
  }

  @Override
  public int size(ObjectProvider op) {
    if (storeMgr.storageVersionAtLeast(StorageVersion.READ_OWNED_CHILD_KEYS_FROM_PARENTS) && !indexedList) {
View Full Code Here

      // create an entity just to capture the name of the index property
      Entity entity = new Entity(kind);
      orderMapping.setObject(ec, entity, new int[] {1}, index);
      String indexProp = entity.getProperties().keySet().iterator().next();
      q.addFilter(indexProp, Query.FilterOperator.GREATER_THAN, index);
      for (Entity shiftMe : service.prepare(service.getCurrentTransaction(null), q).asIterable()) {
        Long pos = (Long) shiftMe.getProperty(indexProp);
        shiftMe.setProperty(indexProp, pos - 1);
        EntityUtils.putEntityIntoDatastore(ec, shiftMe);
      }
    }
View Full Code Here

      q.addSort(Entity.KEY_RESERVED_PROPERTY, Query.SortDirection.DESCENDING);
      DatastoreServiceConfig config = storeMgr.getDefaultDatastoreServiceConfigForReads();
      DatastoreService service = DatastoreServiceFactoryInternal.getDatastoreService(config);
      int[] indices = new int[keys.size()];
      int index = 0;
      for (Entity e : service.prepare(service.getCurrentTransaction(null), q).asIterable()) {
        if (keySet.contains(e.getKey())) {
          Long indexVal = (Long) orderMapping.getObject(ec, e, new int[1]);
          if (indexVal == null) {
            throw new NucleusDataStoreException("Null index value");
          }
View Full Code Here

          !(Boolean)extensions.get(DatastoreManager.QUERYEXT_EXCLUDE_FROM_TXN)) {
        // If this is an ancestor query, execute it in the current transaction
        txn = qd.primaryDatastoreQuery.getAncestor() != null ? ds.getCurrentTransaction(null) : null;
      }

      PreparedQuery preparedQuery = ds.prepare(txn, qd.primaryDatastoreQuery);
      FetchOptions opts = buildFetchOptions(query.getRangeFromIncl(), query.getRangeToExcl());

      if (NucleusLogger.DATASTORE_NATIVE.isDebugEnabled()) {
        NucleusLogger.DATASTORE_NATIVE.debug("Executing query in datastore for " + query.toString());
      }
View Full Code Here

        req.setAttribute("signoutUrl", userService.createLogoutURL("/"));
        req.setAttribute("isUserAdmin", userService.isUserAdmin());

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        Query q = new Query("ChatUser").addSort("jid");
        PreparedQuery pq = datastore.prepare(q);
        List<Entity> results = pq.asList(FetchOptions.Builder.withLimit(100));
        req.setAttribute("chatUsers", results);
        req.setAttribute("hasChatUsers", !results.isEmpty());

        req.setAttribute("status", getStatusEntity());
View Full Code Here

            // and a query cursor.  (Unlike sendMessage(),
            // sendPresence() only accepts one JID at a time.)
            Query q = new Query("ChatUser").addFilter("is_subscribed",
                                                      Query.FilterOperator.EQUAL,
                                                      true);
            PreparedQuery pq = datastore.prepare(q);
            for (Entity e : pq.asIterable()) {
                String recipJidStr = (String)(e.getProperty("jid"));
                JID recipJid = new JID(recipJidStr);
                xmpp.sendPresence(recipJid,
                                  ((Boolean)statusEntity.getProperty("presence_available")) ?
View Full Code Here

        } else if (command.equals("clear_users")) {
            // This actually deletes only 1,000 users.  A scalable
            // solution would use task queues and query cursors to
            // iterate over and delete all entities.
            Query q = new Query("ChatUser").setKeysOnly();
            PreparedQuery pq = datastore.prepare(q);
            List<Entity> entityList = pq.asList(FetchOptions.Builder.withLimit(1000));
            List<Key> keyList = new ArrayList();
            for (Entity e : entityList) {
                keyList.add(e.getKey());
            }
View Full Code Here

            long count = (Long) messageBoard.getProperty("count");
            resp.getWriter().println("<p>Latest messages posted to " +
                                     boardName + " (" + count + " total):</p>");

            Query q = new Query("Message", boardKey);
            PreparedQuery pq = ds.prepare(q);
            for (Entity result : pq.asIterable()) {
                resp.getWriter().println(
                    "<h3>"
                    + escapeHtmlChars((String) result.getProperty("message_title"))
                    + "</h3></p>"
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.