ORMLiteforeigncollection - 对象搜索
我正在使用 ORMLite & SQLite 作为我的数据库,我正在开发一个 Android 应用程序。
1)我正在Foreign-Collection对象中搜索特定对象,如下所示。
Collection<PantryCheckLine> pantryCheckLinesCollection = pantryCheck.getPantryCheckLines();
Iterator iterator = pantryCheckLinesCollection.iterator();
while (iterator.hasNext()) {
pantryCheckLine = (PantryCheckLine) iterator.next();
//i'm searching for a purticular object match
}
2)或者我可以直接从相关表中查询并识别该项目。
我想问的是这两种方法中哪一种会更快?
I'm using ORMLite & SQLite as my database, and I'm working on a android app.
1) I'm searching for a particular object in the Foreign-Collection object as follows.
Collection<PantryCheckLine> pantryCheckLinesCollection = pantryCheck.getPantryCheckLines();
Iterator iterator = pantryCheckLinesCollection.iterator();
while (iterator.hasNext()) {
pantryCheckLine = (PantryCheckLine) iterator.next();
//i'm searching for a purticular object match
}
2) Or else I can directly query from the relevant table and identified the item as well.
What I'm asking is out of these two methods which one will be much faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有点取决于您的具体情况。
如果您的
ForeignCollection
是急切获取的,那么您的循环将不必执行任何数据库事务,并且对于小型集合,可能比执行查询更快。但是,如果您的集合延迟加载,那么迭代集合无论如何都会返回到数据库,因此您不妨执行精确查询。
Depends a bit on the particulars of your situation.
If your
ForeignCollection
is eager fetched then your loop will not have to do any database transactions and will, for small collections, probably be faster then doing the query.However if your collection lazy loaded then iterating through the collection will go back to the database anyway so you might as well do the precise query.