从表-Parse.com获取所有记录

时间:2014-09-23 14:46:43

标签: android parse-platform

我在一张桌子上有大约13000条记录(HashTag -classname)。我想在一个查询中检索所有这些。但是解析只允许每个查询1000个。任何其他方式获得所有记录..

 ParseQuery<ParseObject> query = ParseQuery.getQuery("HashTag");
 query.whereExists("Tag"); query.orderByAscending("Type"); query.setLimit(1000);
 query.findInBackground(new FindCallback<ParseObject>() {

                                @Override
                                public void done(List<ParseObject> list,
                                        ParseException e) {
                                    // TODO Auto-generated method stub
                                    if (e == null)
                                    {
                                        if (list.size() > 0) {
                                            for (int i = 0; i < list.size(); i++) {
                                                ParseObject p = list.get(i);
                                                String tagid = p.getString("Tag");
                                                String Type = p.getString("Type");
                                                class2 c2 = new class2();
                                                c2.type = "" + Type;
                                                c2.tag = "" + tagid;
                                                listClass2.add(c2);



                                            }

                                        }

3 个答案:

答案 0 :(得分:2)

//Declare  a global variable for storing the complete data
private static List<ParseObject>allObjects;
allObjects=new ArrayList<ParseObject>();
ParseQuery<ParseObject>query3=ParseQuery.getQuery("HashTag");
query3.whereExists("Tag");
query3.setLimit(1000);
query3.findInBackground(getallobjects());
int limit=1000;
int skip=0;
//callback method:
private FindCallback<ParseObject>getallobjects(){  
    return new FindCallback<ParseObject>(){
        @Override
        public void done(List<ParseObject>list,ParseException e){
            allObjects.addAll(list);
            if(list.size()==limit){
                skip=skip+limit;
                ParseQuery<ParseObject>query=ParseQuery.getQuery("HashTag");
                query.setSkip(skip);
                query.setLimit(limit);
                query.findInBackground(getallobjects());
            }else{
                //you have full data in allobjects
                for(int i=0;i<allObjects.size();i++){}
            }
        }}}

答案 1 :(得分:1)

当然,您可以在同一个表上运行多个查询,每次查询的skip属性增加1000:

  1. 通过query.count()获取记录总数,并使用它来设置“跳过”变量
  2. 为每1000条记录运行一个新查询,相应地更新您的skip属性
  3. 每次查询返回时正常处理记录
  4. 这样的事情:

        ParseQuery<ParseObject> query = ParseQuery.getQuery("HashTag");
        query.whereExists("Tag");
        query.countInBackground(new CountCallback() {
            public void done(int count, ParseException e) {
            if (e == null) {
                  // The count request succeeded. Run the query multiple times using the query count
              int numQueries = Math.ceil(count / 1000); //Gives you how many queries to run
              for(int skipNum = 0; l < numQueries; l++){
                 ParseQuery<ParseObject> query = ParseQuery.getQuery("HashTag");
                 query.whereExists("Tag"); query.orderByAscending("Type"); 
                 query.setLimit(skipNum * 1000);
                 query.findInBackground(new FindCallback<ParseObject>() {
                    //Run your query as normal here
    
                 }
              }
            } else {
              // The request failed
            }
          }
    

答案 2 :(得分:0)

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("TestObject");
            query.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> list, ParseException e) {
                    for(ParseObject p : list){

                        Log.d("--", (String) p.get("foo")+p.getCreatedAt());
                    }
                }
            });