我在这里问过类似的问题,但我没有得到任何满意的答复,所以请理解我的担忧:
1. https://stackoverflow.com/questions/14846105/insert-ot-update-using-one-of-the-field-as-key-in-greendao
2. https://stackoverflow.com/questions/14547288/best-way-to-select-row-with-following-scenario-using-greendao
我在服务器和客户端都有一个名为“TARGET”的表。
这里的服务器是 MySql,客户端是 Android。
我想将greendao用于客户端部分,我有多个任务要做,如下所示:
- 具有某些EMPLOYEE_ID的员工将在特定日期后从服务器获取所有目标,现在在客户端部分,如果存在TARGET,则应该更新它,否则插入。这是insertOrUpdate案例。
- 使用TARGET_ID删除特定目标。
- 使用TARGET_NAME获取目标列表。
关于问题的数据:
TABLE : TARGET
FIELDS: TARGET_ID
TARGET_NAME
EMPLOYEE_ID
在 DaoExampleGenerator 中使用以下代码:
使用 greenDao 在以下场景中选择行的最佳方法?
private static void addTarget(Schema schema){
Entity target = schema.addEntity("TARGET");
target.addStringProperty("TARGET_ID").primaryKey().autoincrement();
target.addStringProperty("TARGET_NAME");
target.addStringProperty("EMPLOYEE_ID");
}
以下是我为我发布的问题所做的:
1. tDao.insertOrReplaceInTx(tArrayList);
where, tArrayList is ArrayList of TARGET Object.
2. for deleting a target using TARGET_ID, i load all the targets in
ArrayList<TARGET> then check TARGET_ID of each TARGET object. If
the TARGET_ID matches then i use, **tDao.delete(t);**
3. for this also i do the same as (2), i load all the targets then match
the TARGET_NAME, If it matches then i add it to list.
谁能告诉我实现上述问题陈述的最佳方法。使用绿道?