/**
   * {@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;
  }
Exemple #2
0
  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());
  }
Exemple #3
0
  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;
  }
 @Override
 public ForeignKey getForeignKey(final String name) {
   if (foreignKey.getName().equals(name)) {
     return foreignKey;
   } else {
     return null;
   }
 }