有没有一个好的方法来定义数据访问层来获取Android中的相关对象?

发布于 2024-11-27 08:27:35 字数 447 浏览 0 评论 0原文

我花了大约 4 个小时来遵循一本关于 android 的书中的示例,其中只显示了一张表的代码。我有 6 张桌子,所以我为每张桌子扩展了课程。肮脏但有效。当我决定如何访问相关对象时,问题出现了。例如,我有一个 Piece 对象,它有一个片段列表(使用将一个片段连接到另一个片段的表)。好吧,假设每个 Piece 最多可以有 15 个(平均)这些片段,并且我需要将它们作为对象(而不是索引)访问。

书中没有评论这种连接,我想出了一个很好的(但非常慢)的方法来获取这些,通过查询相关的片段索引,然后像常规片段一样获取它们(带有 getPiece(long id) 方法)。最大的问题是,加载 10 个碎片及其相关碎片大约需要 5 秒。

我想知道 Android 中的复杂对象是否已经定义了数据访问层样式。 (我已经习惯了 PHP 的 Yii 框架的方式)

你知道有什么好的实现可以相当快地获取相关对象吗?提前致谢

It took me about 4 hours to follow an example in a book about android, where they showed the code for just a table. I had 6 tables, so I extended the class for every table I had. Dirty but effective. The problem appeared when I was deciding how to access to related objects. For instance, I have a Piece object, which has a list of pieces (using a table which connects a piece to another piece). Well, suppose each Piece can have up to 15 (on average) of those pieces, and I need to access them as an object (not as an index).

This sort of connection was not commented in the book, and I came up with a good (yet really slow) way of getting these, by querying for the related pieces indexes, and then getting them just as a regular Piece (with a getPiece(long id) method). The big problem is that it takes about 5 seconds to load 10 Pieces with their related pieces.

I was wondering if there is an already defined Data Acces Layer styling for complex objects in Android. (I got used to the way Yii framework for PHP does)

Do you know any good implementation for getting related objects fairly fast? Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

臻嫒无言 2024-12-04 08:27:35

好吧,已经过去很长时间了,但我会写一下我现在使用的东西。这是 ORMLite:这不是我期望的那样,关系仍然有点痛苦,但是嘿,至少它封装了所有的过程。

Well, it's been a long time, but I'll write what I'm using right now. It's ORMLite: It's not what I expected to be, relations are still a little pain, but hey, at least it encapsulates all the procedures.

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