我正在使用 ORMLite 来管理包含数据收集应用程序的查找值列表的数据库表。这些查找值会定期从远程服务器更新。但是,我希望能够在创建或更新记录时将数据保留在特定列中,因为我想存储与每个查找值关联的使用计数(特定于设备)。这是我更新记录的方式:
//build list of new records
final List<BaseLookup> rows = new ArrayList<BaseLookup>();
for (int i = 0; i < jsonRows.length(); i++) {
JSONObject jsonRow = jsonRows.getJSONObject(i);
//parse jsonRow into a new BaseLookup object and add to rows
...
}
//add the new records
dao.callBatchTasks(new Callable<Void>() {
public Void call() throws Exception {
for (BaseLookup row : rows) {
//this is where I'd like to preserve the existing
//value (if any) of the "usageCount" column
Dao.CreateOrUpdateStatus result = dao.createOrUpdate(row);
}
return null;
}
});
我考虑过尝试在循环中单独获取和合并每条记录,但这似乎表现不佳(有些表是几千条记录)。有没有更简单或更综合的方法来实现这一点?