001package io.ebeaninternal.dbmigration.ddlgeneration.platform;
002
003import io.ebean.annotation.ConstraintMode;
004import io.ebean.config.dbplatform.DatabasePlatform;
005
006/**
007 * DB2 platform specific DDL.
008 */
009public class DB2Ddl extends PlatformDdl {
010
011  public DB2Ddl(DatabasePlatform platform) {
012    super(platform);
013    this.dropTableIfExists = "drop table ";
014    this.dropSequenceIfExists = "drop sequence ";
015    this.dropConstraintIfExists = "drop constraint";
016    this.dropIndexIfExists = "drop index ";
017    this.identitySuffix = " generated by default as identity";
018    this.inlineUniqueWhenNullable = false;
019  }
020
021  @Override
022  public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) {
023    if (nullableColumns == null || nullableColumns.length == 0) {
024      return super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
025    } else {
026      // Hmm: Complex workaround: https://www.ibm.com/developerworks/mydeveloperworks/blogs/SQLTips4DB2LUW/entry/unique_where_not_null_indexes26?lang=en
027      return "-- NOT SUPPORTED " + super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns);
028    }
029  }
030
031  @Override
032  protected void appendForeignKeyOnUpdate(StringBuilder buffer, ConstraintMode mode) {
033    // do nothing, no on update clause for db2
034  }
035
036}