コード例 #1
0
 public List<Entry<String, Entity>> scan(
     String start, String end, int max, SortDirection direction, boolean keysOnly) {
   Preconditions.checkNotNull(start);
   Preconditions.checkNotNull(end);
   Preconditions.checkArgument(max > -1);
   if (max == 0) {
     return Lists.newArrayList();
   }
   Query query = new Query(kind);
   query.addFilter(
       "__key__", FilterOperator.GREATER_THAN_OR_EQUAL, KeyFactory.createKey(kind, escape(start)));
   query.addFilter("__key__", FilterOperator.LESS_THAN, KeyFactory.createKey(kind, escape(end)));
   query.addSort("__key__", direction);
   if (keysOnly) {
     query.setKeysOnly();
   }
   PreparedQuery preparedQuery = service.prepare(query);
   List<Entry<String, Entity>> result = Lists.newArrayList();
   for (Entity entity : preparedQuery.asIterable(FetchOptions.Builder.withLimit(max))) {
     if (keysOnly) {
       result.add(Maps.immutableEntry(unescape(entity.getKey().getName()), (Entity) null));
     } else {
       result.add(Maps.immutableEntry(unescape(entity.getKey().getName()), entity));
     }
   }
   return result;
 }
コード例 #2
0
  /** Busca en la base de datos la cuenta y la activa - */
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    try {
      String activateID = req.getParameter("activateID");
      resp.setContentType("text/plain");

      Transaction txn = datastore.beginTransaction();

      Query q = new Query("Account");
      q.addFilter("tempRId", Query.FilterOperator.EQUAL, activateID);
      q.addFilter("isActivated", Query.FilterOperator.EQUAL, false);
      List<Entity> pq = datastore.prepare(q).asList(withLimit(1));
      if (pq.isEmpty()) {
        String dire = "http://mentoriasetsit.appspot.com?action=errorActivation";
        resp.sendRedirect(dire);

      } else {
        Date dateOfCreation = (Date) pq.get(0).getProperty("dateCreate");
        Date actualDate = new Date();
        // La activación expira a los dos días
        if ((actualDate.getTime() - dateOfCreation.getTime()) > 48 * 60 * 60 * 1000) {
          String dire = "http://mentoriasetsit.appspot.com?action=activationOutOfDate";
          resp.sendRedirect(dire);
        }

        pq.get(0).setProperty("isActivated", true);
        datastore.put(pq.get(0));
        txn.commit();

        String name = (String) pq.get(0).getProperty("name");
        String surname = (String) pq.get(0).getProperty("surname");
        String userName = (String) pq.get(0).getProperty("userName");
        String answer =
            "Hola "
                + name
                + " "
                + surname
                + " tu cuenta ha sido activada y tu username es: "
                + userName;
        resp.getWriter().println(answer);

        String dire = "http://mentoriasetsit.appspot.com?action=activate";
        resp.sendRedirect(dire);
      }
    } catch (Exception e) {
      LOG.warning("Exception in ActivateAccount: " + e.getMessage());
      e.printStackTrace();
    }
  }
コード例 #3
0
  @Override
  public List<DataObj> getAllDataObj(String deviceId) {
    ArrayList<DataObj> list = new ArrayList<DataObj>();
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

    // The Query interface assembles a query
    Query q = new Query("DataObj");
    q.addFilter("deviceId", Query.FilterOperator.EQUAL, deviceId);
    // q.addSort("score", SortDirection.DESCENDING);

    // PreparedQuery contains the methods for fetching query results
    // from the datastore
    PreparedQuery pq = datastore.prepare(q);

    for (Entity result : pq.asIterable()) {
      double longCord = (double) result.getProperty("longCord");
      double latCord = (double) result.getProperty("latCord");
      double value = (double) result.getProperty("value");
      long time = (Long) result.getProperty("time");

      list.add(new DataObj(deviceId, longCord, latCord, value, time));
    }

    return list;
  }
コード例 #4
0
ファイル: StringStore.java プロジェクト: askcs/dialogexample
  @SuppressWarnings("deprecation")
  public static Entity getEntity(String id) {
    Entity entity = null;
    if (syncCache.contains(id)) {
      entity = (Entity) syncCache.get(id);
    }
    if (entity == null) {
      Query q = new Query("storedString");
      //			q.setFilter(new Query.FilterPredicate("id", Query.FilterOperator.EQUAL, id));
      q.addFilter("id", Query.FilterOperator.EQUAL, id);
      PreparedQuery pq = datastore.prepare(q);
      try {
        entity = pq.asSingleEntity();
      } catch (PreparedQuery.TooManyResultsException e) {
        Iterator<Entity> iter = pq.asIterator();
        while (iter.hasNext()) {
          Entity ent = iter.next();
          if (entity == null) {
            entity = ent;
          } else {
            datastore.delete(ent.getKey());
          }
        }
      }
      if (entity != null) {
        // log.warning("store (because found in datastore) :"+id+" : "+entity.getKey());
        syncCache.put(id, entity);
      }
    }
    // log.warning("return :"+id+" : "+(entity!=null?entity.getKey():""));

    return entity;
  }
コード例 #5
0
  public String getResultado2() throws EntityNotFoundException {
    Query q = new Query("Relationship");
    UserService userService = ServiceLocator.getUserService();
    q.addFilter(
        "user", Query.FilterOperator.EQUAL, ServiceLocator.getUserService().getCurrentUser());

    StringBuffer resultado = new StringBuffer();
    Iterator<Entity> iterator = ServiceLocator.getPersistenceService().queryIterator(q);
    if (!iterator.hasNext()) {
      resultado.append("\nNo records found.");
    } else {
      while (iterator.hasNext()) {
        Entity record = iterator.next();
        resultado.append("\n" + record.getKey());

        List children = (List) record.getProperty("children");
        for (Iterator iterator2 = children.iterator(); iterator2.hasNext(); ) {
          Key k = (Key) iterator2.next();
          Entity child = ServiceLocator.getPersistenceService().load(k);
          resultado.append("\nXXXX" + child.getProperties() + "YYYY");
        }

        // String recordString = printEntity(record);
      }
    }

    return resultado.toString();
  }
コード例 #6
0
 public static Entity getWeekMeasureForDataChannel(
     DatastoreService datastore, String dataChannel) {
   Query query = new Query(Entities.EntityKind.WeekMeasures.getKindName());
   query.addFilter("DChoofdmeting", FilterOperator.EQUAL, dataChannel);
   PreparedQuery prepared = datastore.prepare(query);
   return prepared.asSingleEntity();
 }
コード例 #7
0
ファイル: Util.java プロジェクト: nimezhu/RNABrowser
 /**
  * @param kind
  * @param ancestor
  * @return
  */
 public static Iterable<Entity> listChildKeys(String kind, Key ancestor) {
   logger.log(Level.INFO, "Search entities based on parent");
   Query q = new Query(kind);
   q.setAncestor(ancestor).setKeysOnly();
   q.addFilter(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN, ancestor);
   PreparedQuery pq = datastore.prepare(q);
   return pq.asIterable();
 }
コード例 #8
0
 public Entity getEprSpectrEntityById(String loc, String id) {
   DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
   Query query = new Query(loc + EprSpectr.class.getSimpleName());
   query = query.addFilter(EprSpectr.ID, Query.FilterOperator.EQUAL, id);
   for (Entity anekEntity : datastoreService.prepare(query).asIterable()) {
     return anekEntity;
   }
   return null;
 }
コード例 #9
0
ファイル: Util.java プロジェクト: nimezhu/RNABrowser
 /**
  * * Search entities based on search criteria
  *
  * @param kind
  * @param searchBy : Searching Criteria (Property)
  * @param searchFor : Searching Value (Property Value)
  * @return List all entities of a kind from the cache or datastore (if not in cache) with the
  *     specified properties
  */
 public static Iterable<Entity> listEntities(String kind, String searchBy, String searchFor) {
   logger.log(Level.INFO, "Search entities based on search criteria");
   Query q = new Query(kind);
   if (searchFor != null && !"".equals(searchFor)) {
     q.addFilter(searchBy, FilterOperator.EQUAL, searchFor);
   }
   PreparedQuery pq = datastore.prepare(q);
   return pq.asIterable();
 }
コード例 #10
0
 @Override
 public Iterator<String> getAllEntityKeys(Class<?> entityClass, String lastKey) {
   DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
   com.google.appengine.api.datastore.Query q =
       new com.google.appengine.api.datastore.Query(entityClass.getName());
   q.setKeysOnly();
   if (lastKey != null) {
     q.addFilter("name", FilterOperator.GREATER_THAN, lastKey);
   }
   PreparedQuery pq = datastore.prepare(q);
   FetchOptions fetchOptions = FetchOptions.Builder.withOffset(0);
   return new ExtractingKeyIterable(pq.asIterator(fetchOptions));
 }
コード例 #11
0
  /** Make a new Query object that is exactly like the old. Too bad Query isn't Cloneable. */
  protected com.google.appengine.api.datastore.Query cloneRawQuery(
      com.google.appengine.api.datastore.Query orig) {
    com.google.appengine.api.datastore.Query copy =
        new com.google.appengine.api.datastore.Query(orig.getKind(), orig.getAncestor());

    for (FilterPredicate filter : orig.getFilterPredicates())
      copy.addFilter(filter.getPropertyName(), filter.getOperator(), filter.getValue());

    for (SortPredicate sort : orig.getSortPredicates())
      copy.addSort(sort.getPropertyName(), sort.getDirection());

    // This should be impossible but who knows what might happen in the future
    if (orig.isKeysOnly()) copy.setKeysOnly();

    return copy;
  }
コード例 #12
0
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    System.out.println("Frontend started!");

    ServletOutputStream os = res.getOutputStream();

    Object masterSeedObject = req.getParameter("masterSeed");
    if (masterSeedObject == null) {
      os.print("No masterSeed specified!");
      return;
    }
    int masterSeed = (Integer.parseInt(masterSeedObject.toString()));

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Query q = new Query("Decision");
    q.addFilter("masterSeed", Query.FilterOperator.EQUAL, masterSeed);
    PreparedQuery pq = datastore.prepare(q);
    ArrayList<String> clazzes = new ArrayList<String>();
    ArrayList<Float> decisions = new ArrayList<Float>();
    boolean firstTime = true;
    int index = 0;
    for (Entity entity : pq.asIterable()) {
      String[] pairs = ((Text) entity.getProperty("decision")).getValue().split("\n");
      for (String pair : pairs) {
        String[] s = pair.split(",");
        if (firstTime) {
          clazzes.add(s[0]);
          decisions.add(Float.parseFloat(s[1]));
        } else {
          decisions.set(index, Float.parseFloat(s[1]) + decisions.get(index));
        }
      }
      ++index;
      firstTime = false;
    }

    // output the data
    int length = clazzes.size();
    for (int i = 0; i < length; ++i) {
      os.print(clazzes.get(i) + "," + decisions.get(i) + "\n");
    }
    System.out.println("Frontend terminating!");
  }
コード例 #13
0
  public String getResultado() throws EntityNotFoundException {
    Query q = new Query("Person");
    UserService userService = ServiceLocator.getUserService();
    q.addFilter(
        "user", Query.FilterOperator.EQUAL, ServiceLocator.getUserService().getCurrentUser());

    StringBuffer resultado = new StringBuffer();
    Iterator<Entity> iterator = ServiceLocator.getPersistenceService().queryIterator(q);
    if (!iterator.hasNext()) {
      resultado.append("\nNo records found.");
    } else {
      while (iterator.hasNext()) {
        Entity record = iterator.next();

        resultado.append("\n" + record.getProperties());
      }
    }

    return resultado.toString();
  }
コード例 #14
0
  public static List<StorageNode> getStorageNodesInFolder(String path, Owner owner) {

    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();

    ArrayList<StorageNode> nodes = new ArrayList<StorageNode>();

    String folderPath = PathHelper.getFolderpath(path);

    // Read folders
    Query q = new Query("Folder");
    q.addFilter("path", FilterOperator.GREATER_THAN_OR_EQUAL, path);
    q.addFilter("path", FilterOperator.LESS_THAN, path + "\ufffd");
    q.addFilter("ownerId", FilterOperator.EQUAL, owner.getId());

    PreparedQuery pq = ds.prepare(q);
    List<Entity> results = pq.asList(FetchOptions.Builder.withLimit(99999));
    for (Entity e : results) {
      Folder f = new Folder();
      ReflectionHelper.setPropertiesFromEntity(Folder.class, f, e);

      log.debug("Folder compare: {} =?= {}", PathHelper.getFolderpath(f.getPath()), folderPath);
      if (PathHelper.getFolderpath(f.getPath()).equals(folderPath)) {
        nodes.add(f);
      }
    }

    // Read files
    Query q2 = new Query("File");
    q2.addFilter("path", FilterOperator.GREATER_THAN_OR_EQUAL, path);
    q2.addFilter("path", FilterOperator.LESS_THAN, path + "\ufffd");
    q2.addFilter("ownerId", FilterOperator.EQUAL, owner.getId());

    PreparedQuery pq2 = ds.prepare(q);
    List<Entity> results2 = pq2.asList(FetchOptions.Builder.withLimit(99999));
    for (Entity e : results2) {
      File f = new File();
      ReflectionHelper.setPropertiesFromEntity(File.class, f, e);

      log.debug("File compare: {} =?= {}", PathHelper.getFolderpath(f.getPath()), folderPath);
      if (PathHelper.getFolderpath(f.getPath()).equals(folderPath)) {

        nodes.add(f);
      }
    }

    return nodes;
  }
コード例 #15
0
 private Entity getBlobInfoEntityThroughQuery(String creationHandle) {
   Query query = new Query(BlobInfoFactory.KIND);
   query.addFilter(BLOB_INFO_CREATION_HANDLE_PROPERTY, Query.FilterOperator.EQUAL, creationHandle);
   return getDatastoreService().prepare(query).asSingleEntity();
 }
コード例 #16
0
ファイル: GaeSitemapSource.java プロジェクト: giago/gae-jdo
 private void addBetweenFilter(Query q, String property, Date start, Date end) {
   q.addFilter(property, FilterOperator.GREATER_THAN_OR_EQUAL, start);
   q.addFilter(property, FilterOperator.LESS_THAN_OR_EQUAL, end);
 }
コード例 #17
0
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    int index;

    DatastoreService ds;
    MemcacheService ms;

    Cookie[] cookies;
    boolean insideFlag;

    String delpw;
    String paramOffset;
    String paramSize;
    int offset;
    int size;

    Key postObjGroupKey;
    Query q;
    List<Entity> postObjList;
    PostObj postObj;

    Gson gson;
    List<String> filelinkList;

    resp.setCharacterEncoding("UTF-8");
    resp.setContentType("text/plain");

    ds = DatastoreServiceFactory.getDatastoreService();
    ms = MemcacheServiceFactory.getMemcacheService();

    insideFlag = false;
    try {
      cookies = req.getCookies();
      if (cookies.length > 0) {
        if (ms.contains(cookies[0].getValue()) == true) {
          insideFlag = true;
        }
      }
    } catch (Exception e) {
      insideFlag = false;
    }

    delpw = req.getParameter("delpw");
    if (delpw != null) {
      if (delpw.equals("") == true) {
        delpw = null;
      }
    }

    paramOffset = req.getParameter("offset");
    if (paramOffset != null) {
      offset = Integer.valueOf(paramOffset);
    } else {
      offset = 0;
    }

    paramSize = req.getParameter("size");
    if (paramSize != null) {
      size = Integer.valueOf(paramSize);
    } else {
      size = 4096;
    }

    postObjGroupKey = KeyFactory.createKey("PostObjGroup", 1L);
    q = new Query("PostObj", postObjGroupKey);
    if (delpw != null) {
      q.addFilter("delpw", FilterOperator.EQUAL, delpw);
      q.addSort("delpw");
    }
    q.addSort("posttime", SortDirection.DESCENDING);
    postObjList = ds.prepare(q).asList(FetchOptions.Builder.withOffset(offset).limit(size));

    postObj = new PostObj();
    filelinkList = new ArrayList<String>();
    for (index = 0; index < postObjList.size(); index++) {
      postObj.getDB(postObjList.get(index));
      if ((postObj.flag.equals("showgallery") == false && insideFlag == true)
          || (postObj.flag.equals("showgallery") == true && insideFlag == false)
          || delpw != null) {
        filelinkList.add(postObj.filelink);
      }
    }

    gson = new Gson();
    resp.getWriter().print(gson.toJson(filelinkList));
  }