Java中如何存储树结构?

发布于 2024-08-24 14:38:14 字数 154 浏览 2 评论 0原文

分层数据结构通常存储在关系数据库中。这种存储灵活但扁平,因此必须为每个查询构建树结构。我想将论坛帖子存储为树结构,但应该可以有效地查询,例如按日期或作者选择帖子。

我想要一个可以通过 Java 访问的开源数据库。

最好的方法是什么?沙发数据库?新4j? ...?

Hierarchical data structures are often stored in relational databases. This kind of storage is flexible but flat, so the tree structure has to be build with each query. I want to store forum posts as a tree structure, but it should be possible to query efficiently, say for example selecting posts by date or author.

I'd like to have an open source database that is accessible from Java.

What is the best way to do so? CouchDB? neo4j? ...?

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

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

发布评论

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

评论(2

香草可樂 2024-08-31 14:38:14

当我第一次遇到这个问题时,我找到了一篇很棒的文章(链接)。

简而言之:在 RDBMS 世界中,有 2 种主要的树模型存储方法:

  • 邻接列表模型
  • 嵌套集模型

When I first encountered this problem, I've found the great article (link).

In tho words: in RDBMS world there are 2 main tree model storage approaches:

  • The Adjacency List Model
  • The Nested Set Model
筱果果 2024-08-31 14:38:14

这是一篇关于 Neo4j 的精彩文章。一般来说,neo4j 看起来是您的最佳选择,因为文档数据库仍然相对平坦,并且可能会导致一些 尴尬的设置(不过仍然可行)。

Neo4j 作为一个图形数据库,应该非常适合存储树。我从未使用过它,但考虑到您的问题领域,它似乎是最好的选择(至少是首先调查的选择)。

至于“最好的方法”是什么,我认为这取决于您的实施和要求。我认为你应该针对图形数据库、文档数据库、对象数据库和关系数据库编写一个简单的测试(或不)并查看哪一个适合您要解决的问题。

Here's a great article on Neo4j. In general, it looks like neo4j is your best option since document databases are still relatively flat and can result in some awkward setup (still doable though).

Neo4j, being a graph database, should be a solid fit for storing you tree. I've never used it, but given your problem domain, it seems like the best option (at least the one to investigate first).

As far as what the "best way" is, I think that depends on your implementation and requirements. I think you should write a simple test against a graph database, a document database, an object database and a relational database (or not) and see which one fits the problem that you're trying to solve.

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