在迁移到自托管服务器之前解析数据清理

时间:2016-05-12 14:40:47

标签: java parse-platform

您好我想在迁移之前清理我的Parse表。问题是我的表有一个指向User表的表,但相关用户已被删除。 所以我想要一个可以帮助我删除这些数据的函数

提前致谢

2 个答案:

答案 0 :(得分:0)

我无法找到任何默认方法 我已经在java中为此编写了一些代码 可能对你有所帮助

public void DataCleanUp()
{
    Log.d("TaDeleted","inside");
    String[] tableCloumn={"User Pointer Column Names",""};
    String[] tableArray={"Class Names Here ",""};



        for(int i=0;i<tableArray.length;i++)
        {
            List<ParseObject> objects=null;
            ParseQuery query=new ParseQuery(tableArray[i]);
            query.setLimit(1000);
            query.include(tableCloumn[i]);
            try {
                objects= query.find();
            } catch (ParseException e) {
                e.printStackTrace();
            }

            if(objects!=null)
                if(!objects.isEmpty())
                {
                    Log.d("Table To Deleted",""+tableArray[i]);
                    for(int j=0;j<objects.size();j++)
                    {
                        if((ParseUser) objects.get(j).get(tableCloumn[i])==null)
                        {
                            try {
                                objects.get(j).delete();
                                Log.d("Deleted", "" + objects.get(j).getObjectId());
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
        }
    Toast.makeText(getApplicationContext(),"Deleted",Toast.LENGTH_SHORT).show();
}

答案 1 :(得分:0)

另一种方法可能有用

public void DataCleanUp(String userId)     {         Log.d( “TaDeleted”, “内部”);         String [] tableCloumn = {“用户指针1”,“用户指针2”..};         String [] tableArray = {“Parse class Names 1”,“Parse class Names 2”...};

    List<ParseUser> user=null;
    ParseQuery<ParseUser> query1 = ParseUser.getQuery();
    query1.whereEqualTo("objectId", userId);
    try {
          user=query1.find();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    if(user!=null)
    for(int i=0;i<tableArray.length;i++)
    {
        List<ParseObject> objects=null;
        ParseQuery query=new ParseQuery(tableArray[i]);
        //query.whereEqualTo(tableCloumn[i], user.get(0));
        query.whereEqualTo(tableCloumn[i], user.get(0));
        query.setLimit(1000);
        try {
            objects= query.find();
        } catch (ParseException e) {
            e.printStackTrace();
        }

            if(objects!=null)
                if(!objects.isEmpty())
                {
                    Log.d("Table To Deleted",""+tableArray[i]);
                    for(int j=0;j<objects.size();j++)
                    {
                        try {
                            Log.d("Deleted",""+objects.get(j).getObjectId());
                            objects.get(j).delete();
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                }
    }
    Toast.makeText(getApplicationContext(),"Deleted",Toast.LENGTH_SHORT).show();
}