我正在开发一个应用程序作为学习,我使用Parse(parse.com)作为数据源.
我正在解析我的类的所有对象并保存到具有Parse的本地商店.以下执行下载之一的代码段:
public void noticia_getOrUpdate(boolean isUpdate) throws ParseException {
ParseQuery query = new ParseQuery(Noticia.class);
query.orderByDescending("createdAt");
List 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”).我可以下载并存储所有现场数据存储,但无法使用以下代码进行恢复:
public static byte[] NoticiaMidiaRelation(Noticia noticia) {
try {
ParseRelation 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”查询,他会搜索服务器并正确地提供文件,但不想再追求它,因为如上所述,已经有相同的图像存储在本地数据存储中.
另一种方法是获得媒体ID之间的关系,之后执行搜索比较本地商店中的ObjectId,但我认为属性“父”没有办法.但如果有的话,可以用作解决方案.