示例#1
0
  /**
   * ** Returns an array of root DBFactoryTree nodes based on the specified top-level DBFactory.
   * ** @param initialFactories The root DBFactories which are traversed to create the
   * DBFactoryTree. If null ** all root DBFactories will be traversed. ** @return An array of rot
   * DBFactoryTree nodes.
   */
  public static DBFactoryTree[] getDBFactoryTree(DBFactory<? extends DBRecord> initialFactories[]) {
    Set<String> addedTables = new HashSet<String>();
    DBFactoryTree rootNode = new DBFactoryTree();

    /* start with initial factories */
    if (initialFactories != null) {
      for (int i = 0; i < initialFactories.length; i++) {
        DBFactory<? extends DBRecord> dbf = initialFactories[i];
        DBFactoryTree._traverseDBFactoryTree(0, dbf, rootNode, addedTables);
      }
    }

    /* traverse remaining DBFactories, if any */
    OrderedMap<String, DBFactory<? extends DBRecord>> dbFactMap =
        new OrderedMap<String, DBFactory<? extends DBRecord>>(DBAdmin.getTableFactoryMap());
    for (Iterator<String> i = dbFactMap.keyIterator(); i.hasNext(); ) {
      String tn = i.next();
      DBFactory<? extends DBRecord> dbFact = (DBFactory<? extends DBRecord>) dbFactMap.get(tn);
      DBFactoryTree._traverseDBFactoryTree(0, dbFact, rootNode, addedTables);
    }

    /* return list of root children */
    DBFactoryTree roots[] = rootNode.getChildren();
    if (roots != null) {
      // clear our temporary root node from the table factory roots
      for (int i = 0; i < roots.length; i++) {
        roots[i].setParentNode(null);
      }
    }
    return roots;
  }