This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes Generate tree from csv file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generate tree from csv file" Watch "Generate tree from csv file" New topic
Author

Generate tree from csv file

Paul Monique
Greenhorn

Joined: Jul 16, 2010
Posts: 24
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!


Asterisk-java, JSF, Primefaces, JEE & Glassfish.

Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1050
    
  10

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

Joined: Mar 17, 2011
Posts: 7716
    
  20

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

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Paul Monique
Greenhorn

Joined: Jul 16, 2010
Posts: 24
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
Ranch Hand

Joined: Aug 27, 2012
Posts: 1050
    
  10

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

Joined: Jul 16, 2010
Posts: 24
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!
 
wood burning stoves
 
subject: Generate tree from csv file