I want to implement a Generic Tree in java and i want to use a single table for the same.where the structure of the table is as below.
public class MyTreeNode {
private int id;
private int parentId;
private MyTreeNode parent;
private List<MyTreeNode> childNodes;
// further fields..
}
NAME OF TABLE IS **TREE_TABLE**
PK_ID | PARENT
---------- |----------
1 | null
2 | 1
3 | 1
4 | 2
Meaning, the nodes with PK_ID 2 and 3 have node 1 as parent, 4 has 2 as parent, and 1 has no parent (null).
how to implement this in Java code.Any sample code if you have for this or if you can share the code,Please Share it across.
Requirement: Access the above table from underlyng SQL server database and rebuild the tree structure such that the relationship between Parent and Child are set.
Regards Deepak