001package io.ebeaninternal.dbmigration.ddlgeneration.platform; 002 003import io.ebean.annotation.ConstraintMode; 004import io.ebean.config.dbplatform.DatabasePlatform; 005 006/** 007 * Oracle platform specific DDL. 008 */ 009public class OracleDdl extends PlatformDdl { 010 011 public OracleDdl(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.dropTableCascade = " cascade constraints purge"; 018 this.addColumn = "add"; 019 this.alterColumn = "modify"; 020 this.columnSetNotnull = "not null"; 021 this.columnSetNull = "null"; 022 this.columnSetDefault = "default"; 023 this.identitySuffix = " generated by default as identity"; 024 } 025 026 @Override 027 public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns) { 028 if (nullableColumns == null || nullableColumns.length == 0) { 029 return super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns); 030 } else { 031 // Hmm: https://stackoverflow.com/questions/11893134/oracle-create-unique-index-but-ignore-nulls 032 return "-- NOT YET IMPLEMENTED: " + super.alterTableAddUniqueConstraint(tableName, uqName, columns, nullableColumns); 033 } 034 } 035 036 @Override 037 protected void appendForeignKeyOnUpdate(StringBuilder buffer, ConstraintMode mode) { 038 // do nothing, no on update clause for oracle 039 } 040 041 @Override 042 protected void appendForeignKeyMode(StringBuilder buffer, String onMode, ConstraintMode mode) { 043 switch (mode) { 044 case SET_NULL: 045 case CASCADE: 046 super.appendForeignKeyMode(buffer, onMode, mode); 047 default: 048 // do nothing, defaults to RESTRICT effectively 049 } 050 } 051 052 /** 053 * Modify and return the column definition for autoincrement or identity definition. 054 */ 055 @Override 056 public String asIdentityColumn(String columnDefn, DdlIdentity identity) { 057 return asIdentityStandardOptions(columnDefn, identity); 058 } 059 060}