解析:如何从本地数据存储得到的关系(... fromLocalDatastore())? [英] Parse: How can I get Relation from a local data store (...fromLocalDatastore())?

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

问题描述

我开发一个应用程序,作为一个学习和我使用解析(parse.com)作为数据源。

I am developing an app to serve as a learning and I'm using Parse (parse.com) as a data source.

我进行下载我的课的所有对象的解析和保存到具有解析本地存储。执行下载下列操作之一code片断:

I am conducting download all objects of my classes in the parse and saving to a local store that has Parse. The following code snippet that performs one of downloads:

public void noticia_getOrUpdate(boolean isUpdate) throws ParseException {
        ParseQuery<Noticia> query = new ParseQuery(Noticia.class);
        query.orderByDescending("createdAt");
        List<Noticia> lNoticias = null;

        try {
            if (isUpdate) {
                lNoticias = query.whereGreaterThan("updatedAt", this.sPref.ultimaAtualizacao_noticia()).find();
                if (!lNoticias.isEmpty())
                    ParseObject.pinAllInBackground(lNoticias);
            } else {
                query.whereEqualTo("ativo", true);
                lNoticias = query.find();

                for (Noticia noticia : lNoticias) {
                    if (noticia.getUpdatedAt().getTime() > this.sPref.ultimaAtualizacao_noticia().getTime())
                        this.sPref.atualiza_noticia(noticia.getUpdatedAt());
                }

                ParseObject.pinAllInBackground(lNoticias);
                this.sPref.atualiza_isUpdate(true);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

现在的问题是,我下载我所有的类,一个是文件类型,是可以作为我的消息(Noticia)的图像文件。我可以下载并存储所有现场数据存储,但不能恢复使用以下code:

The problem is I'm downloading all my classes, one is the File type, is a file that works as an image for my news ("Noticia"). I can download and store all on-site data storage, but can not recover using the following code:

public static byte[] NoticiaMidiaRelation(Noticia noticia) {
        try {
            ParseRelation<Midia> relation = noticia.getImagem();
            Midia midia = relation.getQuery().fromLocalDatastore.whereEqualTo("ativo", true).getFirst();

            if (midia != null && midia.getFileData() != null)
                return midia.getFileData();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    return null;
}

如果退了fromLocalDatastore查询,他寻求的服务器,并正确地带来了这个文件,但不想再追究,因为正如所说,已经存储在本地数据存储相同的图像。

If retreat the "fromLocalDatastore" the query, he seeks the server and brings the file correctly, but do not want to pursue it again, because as said, already have the same image stored in the local data store.

另一个方法是将得到的关系介质ID后,对于本地存储中比较的ObjectId执行搜索,但我觉得没有办法的财产父。但是,如果有的话,可以作为一个解决方案。

Another way to do would be to get the relationship the media Id, after that perform a search for comparing ObjectId within the local store, but I think there's no way the property "parent". But if any, can be used as a solution.

推荐答案

您可以按照不文档:

在默认情况下,获取的OBJ时   等,相关ParseObjects不取

By default, when fetching an obj ect, related ParseObjects are not fetched

有变通,但他们可能不实用,因为通过我的理解,你只有一个形象在你的Notica级每的parseObject你的关系,你叫 getFirst()。在这种情况下,使用指针会是一个更好的决定,但这些默认情况下不取两种,但他们被缓存到LocalDatastore。您需要添加以下code到你的查询的获取指针的对象。

There are work arounds but they might not be practical because by what I understand, you only have one image in your relation per ParseObject in your "Notica" class as you call getFirst(). In this case, using a Pointer would be a better decision but those aren't fetched by default either BUT they are cached to the LocalDatastore. You'll need to add the following code to your query to fetch the Pointer object.

query.include("your_column_key");

这篇关于解析:如何从本地数据存储得到的关系(... fromLocalDatastore())?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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