예제 #1
0
  /**
   * Same as {@link #connectForeignKeys(Map, Database, Properties, Pattern, Pattern)}, but uses
   * XML-based metadata
   *
   * @param tableMeta
   * @param tables
   * @param remoteTables
   */
  public void connect(
      TableMeta tableMeta, Map<String, Table> tables, Map<String, Table> remoteTables) {
    for (TableColumnMeta colMeta : tableMeta.getColumns()) {
      TableColumn col = getColumn(colMeta.getName());

      // go thru the new foreign key defs and associate them with our columns
      for (ForeignKeyMeta fk : colMeta.getForeignKeys()) {
        Table parent =
            fk.getRemoteSchema() == null
                ? tables.get(fk.getTableName())
                : remoteTables.get(fk.getRemoteSchema() + '.' + fk.getTableName());
        if (parent != null) {
          TableColumn parentColumn = parent.getColumn(fk.getColumnName());

          if (parentColumn == null) {
            logger.warning(parent.getName() + '.' + fk.getColumnName() + " doesn't exist");
          } else {
            /**
             * Merely instantiating a foreign key constraint ties it into its parent and child
             * columns (& therefore their tables)
             */
            new ForeignKeyConstraint(parentColumn, col) {
              @Override
              public String getName() {
                return "Defined in XML";
              }
            };
          }
        } else {
          logger.warning(
              "Undefined table '"
                  + fk.getTableName()
                  + "' referenced by '"
                  + getName()
                  + '.'
                  + col.getName()
                  + '\'');
        }
      }
    }
  }
예제 #2
0
  /** @param tableMeta */
  public void connect(
      TableMeta tableMeta, Map<String, Table> tables, Map<String, Table> remoteTables) {
    for (TableColumnMeta colMeta : tableMeta.getColumns()) {
      TableColumn col = getColumn(colMeta.getName());

      // go thru the new foreign key defs and associate them with our columns
      for (ForeignKeyMeta fk : colMeta.getForeignKeys()) {
        Table parent =
            fk.getRemoteSchema() == null
                ? tables.get(fk.getTableName())
                : remoteTables.get(fk.getRemoteSchema() + '.' + fk.getTableName());
        if (parent != null) {
          TableColumn parentColumn = parent.getColumn(fk.getColumnName());

          if (parentColumn == null) {
            System.err.println();
            System.err.println(parent.getName() + '.' + fk.getColumnName() + " doesn't exist");
          } else {
            new ForeignKeyConstraint(parentColumn, col) {
              @Override
              public String getName() {
                return "Defined in XML";
              }
            };
          }
        } else {
          System.err.println();
          System.err.print(
              "Undefined table '"
                  + fk.getTableName()
                  + "' referenced by '"
                  + getName()
                  + '.'
                  + col.getName()
                  + '\'');
        }
      }
    }
  }