Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.Query.addSort()


  }

  static Iterable<Entity> queryFromDatastore() {
    // メッセージを日付の降順で取得する
    Query query = new Query("Guestbook");
    query.addSort("createdAt", SortDirection.DESCENDING);
    DatastoreService datastoreService = DatastoreServiceFactory
        .getDatastoreService();
    Iterable<Entity> list = datastoreService.prepare(query).asIterable();
    return list;
  }
View Full Code Here


    writer.println("<p><input type='text' name='message' size='50'/>");
    writer.println("<input type='submit' /></p>");
    writer.println("</form></div>");
    // メッセージを日付の降順で取得する
    Query query = new Query("Guestbook");
    query.addSort("createdAt", SortDirection.DESCENDING);
    DatastoreService datastoreService = DatastoreServiceFactory
        .getDatastoreService();
    Iterable<Entity> list = datastoreService.prepare(query).asIterable();
    writer.println("<div><ul>");
    for (Entity entity : list) {
View Full Code Here

    Entity club = getClub(schoolName, clubName);
    Query tripQuery = new Query("Trip", club.getKey());
    List<Entity> finalTrips=new ArrayList<Entity>();
    tripQuery.addFilter("Year", FilterOperator.LESS_THAN_OR_EQUAL, year2);
    tripQuery.addFilter("Year", FilterOperator.GREATER_THAN_OR_EQUAL, year1);
    tripQuery.addSort("Year", SortDirection.ASCENDING)
    .addSort("Month", SortDirection.ASCENDING);
    List<Entity> trips = database.prepare(tripQuery).asList(FetchOptions.Builder.withDefaults());
    for(Entity e: trips){
      if((Integer)e.getProperty("Year")==year1){
        if((Integer)e.getProperty("Month")>=month1){
View Full Code Here

  //Returns all of the trips from the specified club
  public List<Entity> getTrips(String schoolName, String clubName) throws EntityNotFoundException{
    Entity club = getClub(schoolName, clubName);
    Query tripQuery = new Query("Trip", club.getKey());
    List<Entity> finalTrips=new ArrayList<Entity>();
    tripQuery.addSort("Year", SortDirection.ASCENDING)
    .addSort("Month", SortDirection.ASCENDING);
    finalTrips = database.prepare(tripQuery).asList(FetchOptions.Builder.withDefaults());
 
    return finalTrips;
  }
View Full Code Here

  }

  public List<UploadedImage> getRecent() {
    Query query = new Query("UploadedImage");
    query.addSort(UploadedImage.CREATED_AT, SortDirection.DESCENDING);
    FetchOptions options = FetchOptions.Builder.withLimit(25);

    ArrayList<UploadedImage> results = new ArrayList<UploadedImage>();
    for (Entity result : datastore.prepare(query).asIterable(options)) {
      UploadedImage image = fromEntity(result);
View Full Code Here

    if (endKey != null) {
      q.addFilter(KEY_RESERVED_PROPERTY, LESS_THAN, endKey);
    }

    q.addSort(KEY_RESERVED_PROPERTY);

    iterator = getDatastoreService().prepare(q).asQueryResultIterator(withChunkSize(batchSize));
  }
}
View Full Code Here

    displayComments(out, datastore);
  }

  private void displayComments(PrintWriter out, DatastoreService datastore) {
    Query query = new Query("Comment");
    query.addSort("createdAt", SortDirection.DESCENDING);

    out.println("<table>");
    out.println("<tr>");
    out.println("<th>ID</th>");
    out.println("<th>comment</th>");
View Full Code Here

    @Test
    public void testAncestorKey() {
        Key pKey = getParent().getKey();
        Query query = new Query(CHILDKIND, pKey);
        query.addSort("__key__");
        assertEquals(2, service.prepare(query)
            .countEntities(FetchOptions.Builder.withDefaults()));
        for (Entity cRec : service.prepare(query).asIterable()) {
            assertEquals(pKey, cRec.getParent());
        }
View Full Code Here

        q.setAncestor(rootKey);
        Query.Filter filter = Query.CompositeFilterOperator.and(
            new FilterPredicate("stringData", Query.FilterOperator.LESS_THAN, "qqq"),
            new FilterPredicate("stringData", Query.FilterOperator.GREATER_THAN, "mmm"));
        q.setFilter(filter);
        q.addSort("stringData", Query.SortDirection.ASCENDING);
        assertEquals(2, service.prepare(q).countEntities(fo));
        List<Entity> elist = service.prepare(q).asList(fo);
        assertEquals(Arrays.asList("abc", "xyz", "mno"), elist.get(0).getProperty("stringData"));
        assertEquals(Arrays.asList("ppp", "iii", "ddd"), elist.get(1).getProperty("stringData"));
    }
View Full Code Here

        Query.Filter filter = Query.CompositeFilterOperator.and(
            new FilterPredicate("intData1", Query.FilterOperator.LESS_THAN, 20),
            new FilterPredicate("intData1", Query.FilterOperator.GREATER_THAN, 1),
            new FilterPredicate("intData1", Query.FilterOperator.EQUAL, null));
        q.setFilter(filter);
        q.addSort("intData1", Query.SortDirection.ASCENDING);
        q.setAncestor(rootKey);
        assertEquals(1, service.prepare(q).countEntities(fo));
        List<Entity> elist = service.prepare(q).asList(fo);
        assertEquals(Arrays.asList(1L, 10L, null), elist.get(0).getProperty("intData1"));
    }
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.