如何解析本地数据存储中的关系数据?

时间:2015-09-22 11:26:10

标签: android parse-platform

检索数据并存储在本地数据库中,但在尝试从本地数据库中提取关系时,我得到空列表,表明关系数据未固定到本地数据库。

public void retrieveThreadListStoreInDB()
{
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads");
    query.include("postedBy");
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> list, ParseException e) {
            if(e == null)
            {
                // Query is successful now lets load data from parse
                ParseObject.pinAllInBackground((List<ParseObject>) list, new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if(e == null)
                        {
                            if(!isFinishing())
                            {
                                // TODO : Notify to refresh data
                            }
                        }
                        else
                        {
                            Log.d("DEBUG","ERROR PINNING DATA WITH EXCEPTION : "+e);
                        }
                    }
                });

            }
        }
    });
  

那么我应该如何将“关系”数据固定到本地数据库?   阅读作为关系的评论的最佳方式是什么。我应该将它们存储在本地数据存储区中还是在后台提取数据?

1 个答案:

答案 0 :(得分:-1)

确保在应用程序类Parse.enableLocalDatastore(getApplicationContext());

中启用了LocalDatastore存储

解析本地数据存储不适用于缓存策略。我们可以访问下面的关系数据

  private void getParseData() {
    if (parseObjectId != null) {
        mApp.show_PDialog(context, "Loading..");
        ParseQuery<ParseObject> parseQuery = new ParseQuery<>("Profile");
        parseQuery.getInBackground(parseObjectId, new GetCallback<ParseObject>() {
            @Override
            public void done(ParseObject parseObject, ParseException e) {
                if (e == null) {
                    try {
                        newName = parseObject.getString("name");
                        newGender = parseObject.getString("gender");
                        newDOB.setTime(parseObject.getDate("dob"));
                        newTOB.setTime(parseObject.getDate("tob"));
                        newCurrentLocation = parseObject.getParseObject("currentLocation");
                        newPOB = parseObject.getParseObject("placeOfBirth");

                        if (newName != null) {
                            displayName.setText(newName);
                        }
                        if (newGender != null) {
                            gender.setText(newGender);
                        }
                        if (newDOB != null) {
                            DateFormat df = new SimpleDateFormat("MMM dd, yyyy", Locale.getDefault());
                            df.setTimeZone(TimeZone.getTimeZone("UTC"));
                            String subdateStr = df.format(newDOB.getTime());
                            datePicker.setText(subdateStr);
                        }
                        if (newTOB != null) {
                            DateFormat df = new SimpleDateFormat("hh:mm a", Locale.getDefault());
                            df.setTimeZone(TimeZone.getTimeZone("UTC"));
                            String subdateStr = df.format(newTOB.getTime());
                            timepicker.setText(subdateStr);
                        }
                        if (newPOB != null) {
                            placeOfBirth.setText(newPOB.fetchIfNeeded().getString("name")
                                    + ", " + newPOB.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newPOB.getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name"));
                        }
                        if (newCurrentLocation != null) {
                            currentLocation.setText(newCurrentLocation.fetchIfNeeded().getString("name")
                                    + ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name") + ", " + newCurrentLocation.fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getParseObject("Parent").fetchIfNeeded().getString("name"));
                        }
                    } catch (ParseException e1) {
                        e1.printStackTrace();
                    }
                } else {
                    e.printStackTrace();
                }
                mApp.dialog.dismiss();
            }
        });
    } else {
        getActivity().finish();
    }
}