• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generate tree from csv file

 
Paul Monique
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i'd been searching everywhere for this sort of question to get an idea about how to resolve it, found a couple but is not quite what i need (Here and Here).
i have this .csv file
A;B;C
A;B;D
A;B;E;F
A;B;F;B
H;I
H;I;J

getting something like this

and im trying to convert this into a tree to insert it into the DB, the object is something like this:


any ideas about what can do about it? any help would be apreciated, been going at it for 2 days with all sort of uncomplete solutions,

Thanks!
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What freedom do you have on how the tree is stored in the database? If none at all then what format is expected by the database but if you are free to do anything then why not just store the CSV text in a BLOB or CLOB ?
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Monique wrote:any ideas about what can do about it? any help would be apreciated, been going at it for 2 days with all sort of uncomplete solutions,

Well, the first thing to me would seem to be to construct a tree. It would appear to be an N-tree, so why not start out with something like aand work from there? You'll probably want something like an addBranch() method and something for finding specific Nodes given a path. And once you've got the structure, you should be in a better position to deal with the database.

Winston
 
Paul Monique
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for both replies!! i figure it out with the help of a coworker, here is the pseudocode


i Hope it helps someone
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see how that code helps with the DB side of "im trying to convert this into a tree to insert it into the DB" .
 
Paul Monique
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh on the createNode,GetIdNodeWithoutfather and GetIdNodeWithfather methods i do the db stuff in there (just create the object with the parent, using jpa find,create basic stuff ), thanks again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic