basically mongodb stores each node userobject(NodePro) with parentId.
This class recursively builds a Jtree from querying all the children of a given parentId.
The problem is I have to wait up to 5 minutes for the entire tree to load when dealing with hundreds or thousands of nodes of a single tree.
Is there a way to speed this up significantly? currently even dealing with under hundred nodes, it will take a long time for the tree to become complete.
public class BuildTree {
public BuildTree(DefaultMutableTreeNode treeNode){
DefaultMutableTreeNode aParentNode = treeNode;
try {
processChildren(aParentNode);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void processChildren(DefaultMutableTreeNode parentNode) throws Exception{
NodePro np = (NodePro) parentNode.getUserObject();
List<NodePro> nodelist = NodeDAO.getInstance().getChildrenOfParent(np.getId().toString());
if (nodelist.isEmpty()){
System.out.println("empty");
return;
}else{
for (int i=0; i< nodelist.size(); i++)
{
NodePro childnode = nodelist.get(i);
DefaultMutableTreeNode child = new DefaultMutableTreeNode(childnode);
TreeModel.getInstance().insertNodeInto(child,parentNode,TreeModel.getInstance().getChildCount(parentNode));
DefaultMutableTreeNode parent = (DefaultMutableTreeNode)
TreeModel.getInstance().getChild(parentNode, i);
processChildren(parent);
}
return;
}
}