Ejemplo n.º 1
0
  /** Write the column definition to the create table statement. */
  protected void writeColumnDefinition(DdlBuffer buffer, Column column, boolean useIdentity)
      throws IOException {

    boolean identityColumn = useIdentity && isTrue(column.isPrimaryKey());
    String platformType = convertToPlatformType(column.getType(), identityColumn);

    buffer.append("  ");
    buffer.append(lowerName(column.getName()), 30);
    buffer.append(platformType);
    if (isTrue(column.isNotnull()) || isTrue(column.isPrimaryKey())) {
      buffer.append(" not null");
    }

    // add check constraints later as we really want to give them a nice name
    // so that the database can potentially provide a nice SQL error
  }
  protected void alterTableAddColumn(
      DdlBuffer buffer, String tableName, Column column, boolean onHistoryTable)
      throws IOException {

    buffer
        .append("alter table ")
        .append(tableName)
        .append(" add column ")
        .append(column.getName())
        .append(" ")
        .append(column.getType());

    if (!onHistoryTable) {
      if (isTrue(column.isNotnull())) {
        buffer.append(" not null");
      }
      if (hasValue(column.getCheckConstraint())) {
        buffer.append(" ").append(column.getCheckConstraint());
      }
    }
    buffer.endOfStatement();
  }