【发布时间】:2014-08-28 13:24:53
【问题描述】:
我是 Ormlite 集成的新手,但设法让它在一个学习项目(Android 应用程序)上运行
我面临的问题是性能+概念问题。
我正在使用 Jackson 获取 Center 对象列表,然后使用 ORMLite 将所有内容保存到 DB 中。
我的 Center 对象有两个 ForeignCollectionField ,我的注释是正确的,通过上面的代码,我可以得到这个中心可以处理的废物的正确“连接”以及它自己的中心的性质。
我可以使用 sqlite 编辑器检查我的数据库,看起来不错。
问题是用 4000 个对象填充数据库大约需要 800 万,这有点长。
这是我的 asyncTask 中使用的部分代码(此代码运行良好)
Center[] c = new Center[0];
//fill c with Center objects from jackson OK
assert pCenterDao != null;
for(final Center center : c) {
try {
pCenterDao.create(center);
for (CenterTypesItem typesItem : center.getCenterTypesCollection()) {
CenterTypesItem centerTypesItem = new CenterTypesItem(typesItem.getId(),center);
pCenterTypesItemDao.createOrUpdate(centerTypesItem);
}
for (CenterWastesItem wastesItem : center.getWastesCollection()) {
CenterWastesItem centerWasteItem = new CenterWastesItem(wastesItem.getId(),center);
pCenterWastesItemDao.createOrUpdate(centerWasteItem);
}
count = pCenterDao.countOf();
publishProgress(count, Long.valueOf(c.length));
} catch (SQLException e) {
e.printStackTrace();
result = false ;
}
if (isCancelled()){
result = false ;
break;
}
}
如您所见,我在一个主 FOR 循环中有两个 FOR 循环(不是很聪明),您能告诉我如何优化和纠正这个问题吗? @格雷请帮忙:) 谢谢
【问题讨论】: