我正在开发一个应用程序作为学习,我使用Parse(parse.com)作为数据源。
我正在解析我的类的所有对象并保存到具有Parse的本地商店。以下代码片段执行下载之一:
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();
}
}
问题是我下载了所有课程,一个是文件类型,是一个用作我的新闻图像的文件(&#34; Noticia&#34;)。我可以下载并存储所有现场数据存储,但无法使用以下代码恢复:
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;
}
如果退出&#34; fromLocalDatastore&#34;查询,他寻找服务器并正确地带来文件,但不想再追求它,因为如上所述,已经有相同的图像存储在本地数据存储中。
另一种方法是将关系称为媒体ID,之后执行搜索以比较本地商店中的ObjectId,但我认为该属性&#34; parent&#34; 。但如果有的话,可以用作解决方案。
答案 0 :(得分:0)
你不能根据文件:
默认情况下,在获取obj时 等,不提取相关的ParseObjects
有解决方法,但它们可能不实用,因为根据我的理解,你的关系中每个ParseObject只有一个图像在你的&#34; Notica&#34;在您致电<h1 style="float:left;">Some Text</h1>
<div style="float:right; width:100px; height:50px; background:#CCC;"></div>
<div style="clear:both;"></div>
时上课。在这种情况下,使用Pointer将是一个更好的决定,但默认情况下不会提取它们,但它们被缓存到LocalDatastore。您需要将以下代码添加到查询以获取Pointer对象。
getFirst()