Java中如何存储树结构?
分层数据结构通常存储在关系数据库中。这种存储灵活但扁平,因此必须为每个查询构建树结构。我想将论坛帖子存储为树结构,但应该可以有效地查询,例如按日期或作者选择帖子。
我想要一个可以通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我第一次遇到这个问题时,我找到了一篇很棒的文章(链接)。
简而言之:在 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:
这是一篇关于 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.