ORMLiteforeigncollection - 对象搜索

发布于 2024-12-17 17:24:56 字数 495 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

预谋 2024-12-24 17:24:56

有点取决于您的具体情况。

  • 如果您的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文