Android Greendao:插入、更新、删除语法,最佳实践
我在这里问过类似的问题,但没有得到满意的回答,因此请理解我的担忧:Android Greendao:插入、更新、删除语法,最佳实践,android,greendao,Android,Greendao,我在这里问过类似的问题,但没有得到满意的回答,因此请理解我的担忧: 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-
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, 我有多个任务要做,如下所示:
TABLE : TARGET
FIELDS: TARGET_ID
TARGET_NAME
EMPLOYEE_ID
在DaoExampleGenerator中使用以下代码:以下是我为我发布的问题所做的工作:
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.
1。tDao.insertoreplaceintx(tArrayList);
其中,tArrayList是目标对象的ArrayList。
2.要使用target_ID删除目标,我将在中加载所有目标
ArrayList然后检查每个目标对象的目标ID。如果
目标_ID匹配,然后我使用,**tDao.delete(t)**
3.为此,我也执行与(2)相同的操作,加载所有目标,然后进行匹配
目标_名称,如果匹配,则将其添加到列表中。
有谁能告诉我实现上述问题陈述的最佳方法吗。
使用绿道?你现在所做的似乎是你问题的唯一答案。。。
据我所知,greenDao中没有一种方法可以按条件获取行或按条件删除单个行。。。只有通过ID(Long).才能构建删除查询。俗话说: 删除查询 批量删除不会删除单个实体,而是删除所有实体 符合一些标准。要执行批量删除,请创建 QueryBuilder,调用其buildDelete方法,并执行返回的 删除查询。API的这一部分将来可能会更改,例如。 可以添加方便的方法等。请记住,批量删除 当前不影响标识范围内的实体,例如,您可以 “复活”已删除的实体(如果它们以前已被缓存并且 通过其ID(加载方法)访问。考虑清除身份 如果这可能会导致您的用例出现问题,那么现在就考虑一下
这个问题毫无意义。@MitchWheat你能告诉我你到底明白什么吗。这样我就可以向你解释我的问题了。
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.