コード例 #1
0
  protected void writeForeignKey(
      DdlWrite write,
      String fkName,
      String tableName,
      String[] columns,
      String refTable,
      String[] refColumns,
      String indexName)
      throws IOException {

    tableName = lowerName(tableName);
    DdlBuffer fkeyBuffer = write.applyForeignKeys();
    alterTableAddForeignKey(fkeyBuffer, fkName, tableName, columns, refTable, refColumns);

    if (indexName != null) {
      // no matching unique constraint so add the index
      fkeyBuffer.append(platformDdl.createIndex(indexName, tableName, columns)).endOfStatement();
    }

    fkeyBuffer.end();

    write
        .rollbackForeignKeys()
        .append(platformDdl.alterTableDropForeignKey(tableName, fkName))
        .endOfStatement();

    if (indexName != null) {
      write
          .rollbackForeignKeys()
          .append(platformDdl.dropIndex(indexName, tableName))
          .endOfStatement();
    }

    write.rollbackForeignKeys().end();
  }
コード例 #2
0
  @Override
  public void generate(DdlWrite writer, CreateIndex createIndex) throws IOException {

    String[] cols = toColumnNamesSplit(createIndex.getColumns());
    writer
        .apply()
        .append(
            platformDdl.createIndex(createIndex.getIndexName(), createIndex.getTableName(), cols))
        .endOfStatement();
  }