예제 #1
0
  /**
   * Returns <code>true</code> if this table is referenced by no other tables.
   *
   * <p>Used in dependency analysis.
   *
   * @return
   */
  public boolean isLeaf() {
    for (TableColumn column : columns.values()) {
      if (!column.getChildren().isEmpty()) {
        return false;
      }
    }

    return true;
  }
예제 #2
0
  /**
   * Returns the number of tables that are referenced by this table
   *
   * @return
   */
  public int getNumParents() {
    int numParents = 0;

    for (TableColumn column : columns.values()) {
      numParents += column.getParents().size();
    }

    return numParents;
  }
예제 #3
0
  /**
   * Returns the number of tables that reference this table
   *
   * @return
   */
  public int getNumChildren() {
    int numChildren = 0;

    for (TableColumn column : columns.values()) {
      numChildren += column.getChildren().size();
    }

    return numChildren;
  }
예제 #4
0
  /**
   * Returns <code>true</code> if this table references no other tables..
   *
   * <p>Used in dependency analysis.
   *
   * @return
   */
  public boolean isRoot() {
    for (TableColumn column : columns.values()) {
      if (column.isForeignKey()) {
        return false;
      }
    }

    return true;
  }
예제 #5
0
 /**
  * Return a self referencing constraint if one exists
  *
  * @return
  */
 private ForeignKeyConstraint getSelfReferencingConstraint() {
   for (TableColumn column : columns.values()) {
     for (TableColumn parentColumn : column.getParents()) {
       if (compareTo(parentColumn.getTable()) == 0) {
         return column.getParentConstraint(parentColumn);
       }
     }
   }
   return null;
 }
예제 #6
0
 /**
  * Return a self referencing constraint if one exists
  *
  * @return
  */
 private ForeignKeyConstraint getSelfReferencingConstraint() {
   for (TableColumn column : columns.values()) {
     for (TableColumn parentColumn : column.getParents()) {
       if (parentColumn.getTable().getName().equals(getName())) {
         return column.getParentConstraint(parentColumn);
       }
     }
   }
   return null;
 }
예제 #7
0
  /**
   * Returns the number of non-implied parents
   *
   * @return
   */
  public int getNumNonImpliedParents() {
    int numParents = 0;

    for (TableColumn column : columns.values()) {
      for (TableColumn parentColumn : column.getParents()) {
        if (!column.getParentConstraint(parentColumn).isImplied()) ++numParents;
      }
    }

    return numParents;
  }
예제 #8
0
  /**
   * Returns the number of non-implied children
   *
   * @return
   */
  public int getNumNonImpliedChildren() {
    int numChildren = 0;

    for (TableColumn column : columns.values()) {
      for (TableColumn childColumn : column.getChildren()) {
        if (!column.getChildConstraint(childColumn).isImplied()) ++numChildren;
      }
    }

    return numChildren;
  }
예제 #9
0
  /**
   * Returns <code>true</code> if this table has no relationships
   *
   * @param withImpliedRelationships boolean
   * @return boolean
   */
  public boolean isOrphan(boolean withImpliedRelationships) {
    if (withImpliedRelationships) return getMaxParents() == 0 && getMaxChildren() == 0;

    for (TableColumn column : columns.values()) {
      for (TableColumn parentColumn : column.getParents()) {
        if (!column.getParentConstraint(parentColumn).isImplied()) return false;
      }
      for (TableColumn childColumn : column.getChildren()) {
        if (!column.getChildConstraint(childColumn).isImplied()) return false;
      }
    }
    return true;
  }
예제 #10
0
  /**
   * Remove any non-real foreign keys
   *
   * @return
   */
  public List<ForeignKeyConstraint> removeNonRealForeignKeys() {
    List<ForeignKeyConstraint> nonReals = new ArrayList<ForeignKeyConstraint>();

    for (TableColumn column : columns.values()) {
      for (TableColumn parentColumn : column.getParents()) {
        ForeignKeyConstraint constraint = column.getParentConstraint(parentColumn);
        if (constraint != null && !constraint.isReal()) {
          nonReals.add(remove(constraint));
        }
      }
    }

    return nonReals;
  }
예제 #11
0
  /**
   * Remove any non-real foreign keys
   *
   * @return
   */
  public List<ForeignKeyConstraint> removeNonRealForeignKeys() {
    List<ForeignKeyConstraint> nonReals = new ArrayList<ForeignKeyConstraint>();

    for (TableColumn column : columns.values()) {
      for (TableColumn parentColumn : column.getParents()) {
        ForeignKeyConstraint constraint = column.getParentConstraint(parentColumn);
        if (constraint != null && !constraint.isReal()) {
          nonReals.add(constraint);
        }
      }
    }

    // remove constraints outside of above loop to prevent
    // concurrent modification exceptions while iterating
    for (ForeignKeyConstraint constraint : nonReals) {
      remove(constraint);
    }

    return nonReals;
  }
예제 #12
0
 /** "Unlink" all of the child tables from this table */
 public void unlinkChildren() {
   for (TableColumn column : columns.values()) {
     column.unlinkChildren();
   }
 }
예제 #13
0
 /** "Unlink" all of the parent tables from this table */
 public void unlinkParents() {
   for (TableColumn column : columns.values()) {
     column.unlinkParents();
   }
 }
예제 #14
0
 /**
  * Returns <code>List</code> of <code>TableColumn</code>s in ascending column number order.
  *
  * @return
  */
 public List<TableColumn> getColumns() {
   Set<TableColumn> sorted = new TreeSet<TableColumn>(new ByColumnIdComparator());
   sorted.addAll(columns.values());
   return new ArrayList<TableColumn>(sorted);
 }
예제 #15
0
 /**
  * Returns the indexes that are applied to this table
  *
  * @return
  */
 public Set<TableIndex> getIndexes() {
   return new HashSet<TableIndex>(indexes.values());
 }
예제 #16
0
 /**
  * Get the foreign keys associated with this table
  *
  * @return
  */
 public Collection<ForeignKeyConstraint> getForeignKeys() {
   return Collections.unmodifiableCollection(foreignKeys.values());
 }