0

I have some data in database in parent child relation, where my table is actually representing a forest of tree data structure. enter image description here

And the table structure is like:

row1  parent: null
row2  parent:row1
row3  parent:row2
row4  parent:row1

Now when I am loading this data from DB to my data structure by JDBC, then what I am doing now is:

1. load all row where parent is null [load all the root of trees]
2. Then for each child of each root load the child in a recursive manner.
3. But here all the trees are loaded one by one.

What I want to do, spawn a thread for each tree, thus all the trees can be loaded concurrently. Any framework I can use with JDBC for the same, or any suggestion, help please.

Arpan Das
  • 1,015
  • 3
  • 24
  • 57

2 Answers2

0

you can use the hibernate framework for manipulating(create,delete,insert,update..) data in any database,It's very flexible for data manipulation

Guruprasad N
  • 85
  • 3
  • 10
  • I think I am unble to describe my problem to you. I have hibernate integrated with my application, but hibernate will only provide caching once the data is loaded, that I can achieve by jdbc also using ehcahe/ any other cache mechanism. But my question is loading data concurrently from DB where each thread is loading a Tree, and I already have hibernate / spring-data-jpa for create,delete,insert,update. – Arpan Das May 13 '15 at 10:09
0

Whilst this does not directly answer your exact question, I would encourage you to review your data structure. You have used the Adjacency List Model which, whist simple to implement initially, opens a whole ugly can of worms when it comes to querying.

There are other models to consider, such as Nested Set Model, for which querying of trees and sub-trees is much easier.

Both are explained well in this article: Managing Hierarchical Data in MySQL

Although the article is RDBMS vendor specific, if could easily be adjusted to suit your system.

NickJ
  • 9,380
  • 9
  • 51
  • 74
  • Thanks a lot, I am checking the article provided by you. – Arpan Das May 13 '15 at 10:15
  • I liked it so much, The fetch is great, The query is complex but it will reduce the complexity in my java code, although I have not check the logic to set lft and rght while inserting a data but hope that works well as defined in the article. – Arpan Das May 13 '15 at 10:48