Exemplo n.º 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()
                  + '\'');
        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Update the table with the specified XML-derived metadata
   *
   * @param tableMeta
   */
  public void update(TableMeta tableMeta) {
    String newComments = tableMeta.getComments();
    if (newComments != null) {
      comments = newComments;
    }

    for (TableColumnMeta colMeta : tableMeta.getColumns()) {
      TableColumn col = getColumn(colMeta.getName());
      if (col == null) {
        if (tableMeta.getRemoteSchema() == null) {
          logger.warning(
              "Unrecognized column '" + colMeta.getName() + "' for table '" + getName() + '\'');
          continue;
        }

        col = addColumn(colMeta);
      }

      // update the column with the changes
      col.update(colMeta);
    }
  }
Exemplo n.º 3
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()
                  + '\'');
        }
      }
    }
  }