如何使用java在Oracle sql中存储目录结构
我想将目录/树结构从java代码存储到后端。任何人都可以指导我哪种方式更好地将树结构存储到数据库,这里树结构不是动态结构。
I want to store Directory/tree structure to backend from java code. Any one can guide me which way is better to store tree structure to database, here tree structure is not dynamic structure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用JSON,Json对象可以作为java中的内存结构。当您需要在oracle中持久化时,将其转换为jsonString并插入到varChar2列之一中。
JASON-LIB 支持从字符串(即存储在数据库中)和反向
Json-Lib
Use JSON, Json object can be used as memory structure with-in java. When you need to persist in oracle convert it into jsonString and insert in one of the varChar2 column.
JASON-LIB supports creation of the tree structure from a String (ie, stored in the database) and the reverse
Json-Lib
我建议以复合方式存储。一父多子。
这是存储结果的最简单方法。
目录结构看起来像。
I would recomend to store in a Composite way. One Parent many childs.
This is the easiest way to store the result.
The directory structure would look like.
我同意数据库中的文件夹结构表示。
然而我对如何在 Java 中解析这个结构有点困惑。例如我有以下数据结构:
欧洲
欧洲
我有一个数据,我必须将文件与定义下的 HostC 关联起来,位置为欧洲,那么该怎么做呢?
如果我通过 Hibernate 查询整个表,我将得到如下目录结构列表:
(1,NULL,RS Root)
(3,1,Directory)
(4,1, Template)
(6,3,London)
(7 ,6,Flat Files)
(10,7,Host)
(12,10,HostA)
(13,10,HostB)
(14,10,HostTC)
所以如果我搜索 HostC 我会得到很多结果源位置(伦敦,欧洲)和类型(模板,定义)
我应该如何遍历它并获得正确的分支
I agree with the folder structure representation in DB.
However I am bit confused on how to parse this structure in Java. For example I have following data structure:
I have a data that I have to associate a file with HostC under Definition with Location as Europe, so How would that be done.
If I query whole table via Hibernate, I will get a List of Directory Struture as following:
(1,NULL,RS Root)
(3,1,Directory)
(4,1, Template)
(6,3,London)
(7,6,Flat Files)
(10,7,Host)
(12,10,HostA)
(13,10,HostB)
(14,10,HostTC)
So if I search for HostC I will get many results as per source location(London, Europe) and type(Template, Definition)
How should I traverse it and get the correct branch