3 Replies Latest reply on Oct 12, 2007 9:44 AM by Yurii Kartsev

    Recursive Tree Adaptor: inits each node for 4 times

    Yurii Kartsev Apprentice

      Good afternoon.

      I've got to say, that I have NO problems with this component, just saw strange logs and thought it will be useful for you to see it.

      When I've remade your demo example(with file paths) for my DB Table, named "AllTree", I've found out that each node's children are checked for 4 times.

      I'll explain. AllTree table has important fields: itemId and itemRef. itemRef is reference to itemId. Right now the data from this table can be viewed as:

      - Anketa
      - Upravlenie
      --- Filial Petricani
      ----- Sklad 1
      ----- Sklad 2
      --- Filial Muncesti
      ----- Sklad 1
      ----- Sklad 2



      So, having this is my methods of DepartmentTreeNode:

      public class DepartmentTreeNode
      {
       private AllTree departmentAllTree;
       private static DepartmentTreeNode[] CHILDREN_ABSENT = new DepartmentTreeNode[0];
       private DepartmentTreeNode[] children;
       private String name;
      
       public DepartmentTreeNode(AllTree departmentAllTree)
       {
       this.departmentAllTree = departmentAllTree;
       this.name = departmentAllTree.getName();
      
      System.out.println("========= DepartmentTreeNode Constructor finished, name = " + this.name);
       }
      
      
       public synchronized DepartmentTreeNode[] getNodes()
       {
      System.out.println("===== getting nodes of " + this.name);
      
       if (children == null)
       {
      System.out.println("=== children is null, preparing...");
      
       List<AllTree> childrenAllTreeList = this.getAllTreesByParent(departmentAllTree);
      
       if (childrenAllTreeList != null)
       {
      System.out.println("=== childrenAllTreeList is NOT null");
      
       children = new DepartmentTreeNode[childrenAllTreeList.size()];
      
       int i = 0;
       for(AllTree dep: childrenAllTreeList)
       {
      System.out.println("== next child, name = " + dep.getName());
      
       children[ i ] = new DepartmentTreeNode(dep);
       i++;
       }
       }
       else
       {
      System.out.println("=== childrenAllTreeList IS NULL!!");
      
       children = CHILDREN_ABSENT;
       }
       }
      
      System.out.println("===== return...");
      
       return children;
       }
      
      
       public String toString()
       {
       return this.name;
       }
      
      ...
      
      }



      When I open my application in the web browser, my AS writes this log:
      ============ getDepartmentsTreeRoots from AMBEAN:
       ========= DepartmentTreeNode Constructor finished, name = Company Structure
       ===== getting nodes of Company Structure
       === children is null, preparing...
       === childrenAllTreeList is NOT null
       == next child, name = Anketa
       ========= DepartmentTreeNode Constructor finished, name = Anketa
       == next child, name = Upravlenie
       ========= DepartmentTreeNode Constructor finished, name = Upravlenie
       ===== return...
       ============ getDepartmentsTreeRoots from AMBEAN:
       ===== getting nodes of Anketa
       === children is null, preparing...
       === childrenAllTreeList is NOT null
       ===== return...
       ===== getting nodes of Anketa
       ===== return...
       ===== getting nodes of Anketa
       ===== return...
       ===== getting nodes of Anketa
       ===== return...
       ============ getDepartmentsTreeRoots from AMBEAN:
       ===== getting nodes of Upravlenie
       === children is null, preparing...
       === childrenAllTreeList is NOT null
       == next child, name = Filial Muncesti
       ========= DepartmentTreeNode Constructor finished, name = Filial Muncesti
       == next child, name = Filial Petricani
       ========= DepartmentTreeNode Constructor finished, name = Filial Petricani
       ===== return...
       ===== getting nodes of Upravlenie
       ===== return...
       ===== getting nodes of Upravlenie
       ===== return...
       ===== getting nodes of Upravlenie
       ===== return...
       ===== getting nodes of Upravlenie
       ===== return...
       ===== getting nodes of Filial Muncesti
       === children is null, preparing...
       === childrenAllTreeList is NOT null
       == next child, name = Sklad 1
       ========= DepartmentTreeNode Constructor finished, name = Sklad 1
       == next child, name = Sklad 2
       ========= DepartmentTreeNode Constructor finished, name = Sklad 2
       ===== return...
       ===== getting nodes of Filial Muncesti
       ===== return...
       ===== getting nodes of Filial Muncesti
       ===== return...
       ===== getting nodes of Filial Muncesti
       ===== return...
       ===== getting nodes of Filial Muncesti
       ===== return...
       ===== getting nodes of Sklad 1
       === children is null, preparing...
       === childrenAllTreeList is NOT null
       ===== return...
       ===== getting nodes of Sklad 1
       ===== return...
       ===== getting nodes of Sklad 1
       ===== return...
       ===== getting nodes of Sklad 1
       ===== return...
       ===== getting nodes of Filial Muncesti
       ===== return...
       ===== getting nodes of Sklad 2
       === children is null, preparing...
       === childrenAllTreeList is NOT null
       ===== return...
       ===== getting nodes of Sklad 2
       ===== return...
       ===== getting nodes of Sklad 2
       ===== return...
       ===== getting nodes of Sklad 2
       ===== return...
       ===== getting nodes of Upravlenie
       ===== return...
       ===== getting nodes of Filial Petricani
       === children is null, preparing...
       === childrenAllTreeList is NOT null
       == next child, name = Sklad 1
       ========= DepartmentTreeNode Constructor finished, name = Sklad 1
       == next child, name = Sklad 2
       ========= DepartmentTreeNode Constructor finished, name = Sklad 2
       ===== return...
       ===== getting nodes of Filial Petricani
       ===== return...
       ===== getting nodes of Filial Petricani
       ===== return...
       ===== getting nodes of Filial Petricani
       ===== return...
       ===== getting nodes of Filial Petricani
       ===== return...
       ===== getting nodes of Sklad 1
       === children is null, preparing...
       === childrenAllTreeList is NOT null
       ===== return...
       ===== getting nodes of Sklad 1
       ===== return...
       ===== getting nodes of Sklad 1
       ===== return...
       ===== getting nodes of Sklad 1
       ===== return...
       ===== getting nodes of Filial Petricani
       ===== return...
       ===== getting nodes of Sklad 2
       === children is null, preparing...
       === childrenAllTreeList is NOT null
       ===== return...
       ===== getting nodes of Sklad 2
       ===== return...
       ===== getting nodes of Sklad 2
       ===== return...
       ===== getting nodes of Sklad 2
       ===== return...



      Words "getDepartmentsTreeRoots from AMBEAN" are logged when tree nodes getter is invoked from the managed bean. It's code is just as demo has:
      public synchronized DepartmentTreeNode[] getDepartmentsTreeRoots()
       {
      System.out.println("============ getDepartmentsTreeRoots from AMBEAN:");
      
       if (departmentsTreeRoots == null)
       {
       departmentsTreeRoots = new DepartmentTreeNode(allTreeListMan.getDepartmentTypeLevel0()).getNodes();
       }
      
       return departmentsTreeRoots;
       }




      So the question is - is it right to see getNodes method invocation for each of node, for four times?

      Thanks for your reply.