如何在本地数据存储区中固定解析关系数据? [英] How to pin parse relation data in local data store?

查看:81
本文介绍了如何在本地数据存储区中固定解析关系数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已检索数据并存储在本地数据库中,但是在尝试从本地数据库中提取关系时,我得到一个空列表,该列表指示关系数据未固定到本地数据库.

Retrieved data and stored in local database but while trying to pull relation from the local database I get empty list which indicates that the relation data is not pinned to the local database.

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);
                        }
                    }
                });

            }
        }
    });

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

So how should I pin "relation" data to the local database ??? What is the best way to read comments which is a relation. shall I store them in local datastore or pull data in the background ??

推荐答案

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

解析本地数据存储将不适用于缓存策略.我们可以访问如下

Parse local data store will not work with cache policy. We can access relational data like below

  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();
    }
}

这篇关于如何在本地数据存储区中固定解析关系数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆