public boolean start(Table table) {
   /*
    * in the case when the target schema or catalog is set then we need to
    * use the previous schema or catalog to look up the table locally.
    */
   this.currentTable =
       platform.getTableFromCache(
           table.getOldCatalog(), table.getOldSchema(), table.getName(), false);
   if (this.currentTable != null) {
     this.currentTable =
         currentTable.copyAndFilterColumns(
             table.getColumnNames(), table.getPrimaryKeyColumnNames(), true);
     /*
      * restore the schema and catalog from the passed in table because
      * they might have not been originally set, but were set when
      * looking up the table locally
      */
     this.currentTable.setSchema(table.getSchema());
     this.currentTable.setCatalog(table.getCatalog());
     this.currentTable.setName(table.getName());
     return true;
   } else {
     return false;
   }
 }
Example #2
0
  private void alterCaseToMatchLogicalCase(Table table) {
    table.setName(table.getName().toUpperCase());

    Column[] columns = table.getColumns();
    for (Column column : columns) {
      column.setName(column.getName().toUpperCase());
    }

    IIndex[] indexes = table.getIndices();
    for (IIndex index : indexes) {
      index.setName(index.getName().toUpperCase());

      IndexColumn[] indexColumns = index.getColumns();
      for (IndexColumn indexColumn : indexColumns) {
        indexColumn.setName(indexColumn.getName().toUpperCase());
      }
    }
  }
  public static void write(Table table, Writer output) {

    try {
      output.write("\t<table name=\"" + StringEscapeUtils.escapeXml(table.getName()) + "\">\n");

      for (Column column : table.getColumns()) {
        output.write("\t\t<column name=\"" + StringEscapeUtils.escapeXml(column.getName()) + "\"");
        if (column.isPrimaryKey()) {
          output.write(" primaryKey=\"" + column.isPrimaryKey() + "\"");
        }
        if (column.isRequired()) {
          output.write(" required=\"" + column.isRequired() + "\"");
        }
        if (column.getMappedType() != null) {
          output.write(" type=\"" + column.getMappedType() + "\"");
        }
        if (column.getSize() != null) {
          output.write(" size=\"" + column.getSize() + "\"");
        }
        if (column.getDefaultValue() != null) {
          output.write(
              " default=\"" + StringEscapeUtils.escapeXml(column.getDefaultValue()) + "\"");
        }
        if (column.isAutoIncrement()) {
          output.write(" autoIncrement=\"" + column.isAutoIncrement() + "\"");
        }
        if (column.getJavaName() != null) {
          output.write(" javaName=\"" + column.getJavaName() + "\"");
        }

        if (column.getPlatformColumns() != null && column.getPlatformColumns().size() > 0) {
          Collection<PlatformColumn> platformColumns = column.getPlatformColumns().values();
          output.write(">\n");
          for (PlatformColumn platformColumn : platformColumns) {
            output.write("\t\t\t<platform-column name=\"" + platformColumn.getName() + "\"");
            output.write(" type=\"" + platformColumn.getType() + "\"");
            if (platformColumn.getSize() > 0) {
              output.write(" size=\"" + platformColumn.getSize() + "\"");
            }
            if (platformColumn.getDecimalDigits() > 0) {
              output.write(" decimalDigits=\"" + platformColumn.getDecimalDigits() + "\"");
            }

            if (platformColumn.getDefaultValue() != null) {
              output.write(
                  " default=\""
                      + StringEscapeUtils.escapeXml(platformColumn.getDefaultValue())
                      + "\"");
            }

            output.write("/>\n");
          }
          output.write("\t\t</column>\n");
        } else {
          output.write("/>\n");
        }
      }

      for (ForeignKey fk : table.getForeignKeys()) {
        output.write(
            "\t\t<foreign-key name=\""
                + StringEscapeUtils.escapeXml(fk.getName())
                + "\" foreignTable=\""
                + StringEscapeUtils.escapeXml(fk.getForeignTableName())
                + "\">\n");
        for (Reference ref : fk.getReferences()) {
          output.write(
              "\t\t\t<reference local=\""
                  + StringEscapeUtils.escapeXml(ref.getLocalColumnName())
                  + "\" foreign=\""
                  + StringEscapeUtils.escapeXml(ref.getForeignColumnName())
                  + "\"/>\n");
        }
        output.write("\t\t</foreign-key>\n");
      }

      for (IIndex index : table.getIndices()) {
        if (index.isUnique()) {
          output.write(
              "\t\t<unique name=\"" + StringEscapeUtils.escapeXml(index.getName()) + "\">\n");
          for (IndexColumn column : index.getColumns()) {
            output.write(
                "\t\t\t<unique-column name=\""
                    + StringEscapeUtils.escapeXml(column.getName())
                    + "\"/>\n");
          }
          output.write("\t\t</unique>\n");
        } else {
          output.write(
              "\t\t<index name=\"" + StringEscapeUtils.escapeXml(index.getName()) + "\">\n");
          for (IndexColumn column : index.getColumns()) {
            output.write(
                "\t\t\t<index-column name=\""
                    + StringEscapeUtils.escapeXml(column.getName())
                    + "\"");
            if (column.getSize() != null) {
              output.write(" size=\"" + column.getSize() + "\"");
            }
            output.write("/>\n");
          }
          output.write("\t\t</index>\n");
        }
      }

      output.write("\t</table>\n");
    } catch (IOException e) {
      throw new IoException(e);
    }
  }