コード例 #1
0
  /**
   * {@inheritDoc}
   *
   * <p>Note: Since foreign keys are not always explicitly named in databases, the sorting routine
   * orders the foreign keys by the names of the columns in the foreign keys.
   */
  @Override
  public int compareTo(final NamedObject obj) {
    final ForeignKey other = (ForeignKey) obj;
    int comparison = 0;
    final ForeignKeyColumnMap[] thisColumnPairs = getColumnPairs();
    final ForeignKeyColumnMap[] otherColumnPairs = other.getColumnPairs();

    if (comparison == 0) {
      comparison = thisColumnPairs.length - otherColumnPairs.length;
    }

    if (comparison == 0) {
      for (int i = 0; i < thisColumnPairs.length; i++) {
        final ForeignKeyColumnMap thisColumnPair = thisColumnPairs[i];
        final ForeignKeyColumnMap otherColumnPair = otherColumnPairs[i];
        if (comparison == 0) {
          comparison = thisColumnPair.compareTo(otherColumnPair);
        } else {
          break;
        }
      }
    }

    return comparison;
  }
コード例 #2
0
ファイル: DbAnalyse.java プロジェクト: breakpoint-au/Hedron
  private static boolean isOutgoingForeignKey(final Table table, final ForeignKey foreignKey) {
    final List<ForeignKeyColumnReference> fkcms = foreignKey.getColumnReferences();
    ThreadContext.assertFault(
        fkcms.size() > 0,
        "Table [%s] reports a foreign key [%s] with no columns",
        table.getName(),
        foreignKey.getName());
    final ForeignKeyColumnReference fkcm = fkcms.get(0);

    final Column referencedColumn = fkcm.getPrimaryKeyColumn();
    final String referencedtableName = referencedColumn.getParent().getName();

    return !referencedtableName.equals(table.getName());
  }
コード例 #3
0
ファイル: DbAnalyse.java プロジェクト: breakpoint-au/Hedron
  private static Element createForeignKeyElement(final Document dom, final ForeignKey foreignKey) {
    // <constraint name="C1" type="compoundforeignkey">
    //     <column name="ActivationDate" referencedtable="ActivationDate" referencedcolumn="Value"/>
    // </constraint>
    final Element eForeignKey = dom.createElement("constraint");
    eForeignKey.setAttribute("name", foreignKey.getName());
    eForeignKey.setAttribute("type", "compoundforeignkey");

    final List<ForeignKeyColumnReference> fkcms = foreignKey.getColumnReferences();
    for (final ForeignKeyColumnReference fkcm : fkcms) {
      final Element eColumn = createForeignKeyColumnElement(dom, fkcm);
      eForeignKey.appendChild(eColumn);
    }

    return eForeignKey;
  }
コード例 #4
0
 @Override
 public ForeignKey getForeignKey(final String name) {
   if (foreignKey.getName().equals(name)) {
     return foreignKey;
   } else {
     return null;
   }
 }