Class PlatformDdl
- java.lang.Object
-
- io.ebeaninternal.dbmigration.ddlgeneration.platform.PlatformDdl
-
- Direct Known Subclasses:
AbstractHanaDdl,ClickHouseDdl,CockroachDdl,DB2Ddl,H2Ddl,HsqldbDdl,MySqlDdl,NuoDbDdl,OracleDdl,PostgresDdl,SQLiteDdl,SqlServerDdl
public class PlatformDdl extends Object
Controls the DDL generation for a specific database platform.
-
-
Constructor Summary
Constructors Constructor Description PlatformDdl(io.ebean.config.dbplatform.DatabasePlatform platform)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddColumnComment(DdlBuffer apply, String table, String column, String comment)Add column comment as a separate statement.voidaddHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable)Add history support to an existing table.voidaddTableComment(DdlBuffer apply, String tableName, String tableComment)Add table comment as a separate statement (from the create table statement).voidaddTablePartition(DdlBuffer apply, String partitionMode, String partitionColumn)StringalterColumnBaseAttributes(AlterColumn alter)Alter column setting both the type and not null constraint.StringalterColumnDefaultValue(String tableName, String columnName, String defaultValue)Alter column setting the default value.StringalterColumnNotnull(String tableName, String columnName, boolean notnull)Alter a column adding or removing the not null constraint.StringalterColumnType(String tableName, String columnName, String type)Alter a column type.StringalterTableAddCheckConstraint(String tableName, String checkConstraintName, String checkConstraint)Alter table adding the check constraint.voidalterTableAddColumn(DdlBuffer buffer, String tableName, Column column, boolean onHistoryTable, String defaultValue)StringalterTableAddForeignKey(DdlOptions options, io.ebeaninternal.dbmigration.ddlgeneration.platform.WriteForeignKey request)Add foreign key.StringalterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns)Add a unique constraint to the table.voidalterTableDropColumn(DdlBuffer buffer, String tableName, String columnName)StringalterTableDropConstraint(String tableName, String constraintName)Drop a unique constraint from the table.StringalterTableDropForeignKey(String tableName, String fkName)Return the drop foreign key clause.StringalterTableDropUniqueConstraint(String tableName, String uniqueConstraintName)Drop a unique constraint from the table (Sometimes this is an index).StringasIdentityColumn(String columnDefn, DdlIdentity identity)Modify and return the column definition for autoincrement or identity definition.voidconfigure(io.ebean.config.DatabaseConfig config)Set configuration options.Stringconvert(String type)Convert the standard type to the platform specific type.StringconvertDefaultValue(String dbDefault)Convert the DB column default literal to platform specific.StringcreateCheckConstraint(String ckName, String checkConstraint)Returns the check constraint.DdlHandlercreateDdlHandler(io.ebean.config.DatabaseConfig config)Create a DdlHandler for the specific database platform.StringcreateIndex(io.ebeaninternal.dbmigration.ddlgeneration.platform.WriteCreateIndex create)StringcreateSequence(String sequenceName, DdlIdentity identity)Generate and return the create sequence DDL.voidcreateWithHistory(DdlWrite writer, MTable table)Add history support to this table using the platform specific mechanism.voiddropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable)Drop history support for a given table.StringdropIndex(String indexName, String tableName)Return the drop index statement for known non concurrent index.StringdropIndex(String indexName, String tableName, boolean concurrent)Return the drop index statement.StringdropSequence(String sequenceName)Return the drop sequence statement (potentially with if exists clause).StringdropTable(String tableName)Return the drop table statement (potentially with if exists clause).voidgenerateEpilog(DdlWrite write)Use this to generate an epilog.voidgenerateProlog(DdlWrite write)Use this to generate a prolog for each script (stored procedures)StringgetCreateTableCommandPrefix()Returns the database-specific "create table" command prefix.io.ebean.config.dbplatform.DatabasePlatformgetPlatform()StringgetUpdateNullWithDefault()voidinlineTableComment(DdlBuffer apply, String tableComment)Add an inline table comment to the create table statement.booleanisIncludeStorageEngine()Return true if the platform includes storage engine clause.booleanisInlineComments()Return true if the table and column comments are included inline.booleanisInlineForeignKeys()Return true if foreign key reference constraints need to inlined with create table.booleanisInlineUniqueWhenNullable()Return true if unique constraints for nullable columns can be inlined as normal.voidlockTables(DdlBuffer buffer, Collection<String> tables)Mysql-specific: Locks all tables for triggers that have to be updated.voidregenerateHistoryTriggers(DdlWrite write, HistoryTableUpdate update)Regenerate the history triggers (or function) due to a column being added/dropped/excluded or included.StringsetLockTimeout(int lockTimeoutSeconds)By default this does nothing returning null / no lock timeout.booleansuppressPrimaryKeyOnPartition()StringtableInlineForeignKey(io.ebeaninternal.dbmigration.ddlgeneration.platform.WriteForeignKey request)Return the foreign key constraint when used inline with create table.voidtableStorageEngine(DdlBuffer apply, String storageEngine)Add an table storage engine to the create table statement.voidunlockTables(DdlBuffer buffer, Collection<String> tables)Mysql-specific: Unlocks all tables for triggers that have to be updated.io.ebean.config.dbplatform.IdTypeuseIdentityType(io.ebean.config.dbplatform.IdType modelIdentity)Return the identity type to use given the support in the underlying database platform for sequences and identity/autoincrement.voidwriteTableColumns(DdlBuffer apply, List<Column> columns, DdlIdentity identity)Write all the table columns converting to platform types as necessary.
-
-
-
Constructor Detail
-
PlatformDdl
public PlatformDdl(io.ebean.config.dbplatform.DatabasePlatform platform)
-
-
Method Detail
-
configure
public void configure(io.ebean.config.DatabaseConfig config)
Set configuration options.
-
createDdlHandler
public DdlHandler createDdlHandler(io.ebean.config.DatabaseConfig config)
Create a DdlHandler for the specific database platform.
-
useIdentityType
public io.ebean.config.dbplatform.IdType useIdentityType(io.ebean.config.dbplatform.IdType modelIdentity)
Return the identity type to use given the support in the underlying database platform for sequences and identity/autoincrement.
-
asIdentityColumn
public String asIdentityColumn(String columnDefn, DdlIdentity identity)
Modify and return the column definition for autoincrement or identity definition.
-
isInlineComments
public boolean isInlineComments()
Return true if the table and column comments are included inline.
-
isIncludeStorageEngine
public boolean isIncludeStorageEngine()
Return true if the platform includes storage engine clause.
-
isInlineForeignKeys
public boolean isInlineForeignKeys()
Return true if foreign key reference constraints need to inlined with create table. Ideally we don't do this as then the constraints are not named. Do this for SQLite.
-
setLockTimeout
public String setLockTimeout(int lockTimeoutSeconds)
By default this does nothing returning null / no lock timeout.
-
writeTableColumns
public void writeTableColumns(DdlBuffer apply, List<Column> columns, DdlIdentity identity) throws IOException
Write all the table columns converting to platform types as necessary.- Throws:
IOException
-
createCheckConstraint
public String createCheckConstraint(String ckName, String checkConstraint)
Returns the check constraint.
-
convertDefaultValue
public String convertDefaultValue(String dbDefault)
Convert the DB column default literal to platform specific.
-
alterTableDropForeignKey
public String alterTableDropForeignKey(String tableName, String fkName)
Return the drop foreign key clause.
-
convert
public String convert(String type)
Convert the standard type to the platform specific type.
-
createWithHistory
public void createWithHistory(DdlWrite writer, MTable table) throws IOException
Add history support to this table using the platform specific mechanism.- Throws:
IOException
-
dropHistoryTable
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException
Drop history support for a given table.- Throws:
IOException
-
addHistoryTable
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException
Add history support to an existing table.- Throws:
IOException
-
regenerateHistoryTriggers
public void regenerateHistoryTriggers(DdlWrite write, HistoryTableUpdate update) throws IOException
Regenerate the history triggers (or function) due to a column being added/dropped/excluded or included.- Throws:
IOException
-
createSequence
public String createSequence(String sequenceName, DdlIdentity identity)
Generate and return the create sequence DDL.
-
dropSequence
public String dropSequence(String sequenceName)
Return the drop sequence statement (potentially with if exists clause).
-
dropTable
public String dropTable(String tableName)
Return the drop table statement (potentially with if exists clause).
-
dropIndex
public String dropIndex(String indexName, String tableName)
Return the drop index statement for known non concurrent index.
-
dropIndex
public String dropIndex(String indexName, String tableName, boolean concurrent)
Return the drop index statement.
-
createIndex
public String createIndex(io.ebeaninternal.dbmigration.ddlgeneration.platform.WriteCreateIndex create)
-
tableInlineForeignKey
public String tableInlineForeignKey(io.ebeaninternal.dbmigration.ddlgeneration.platform.WriteForeignKey request)
Return the foreign key constraint when used inline with create table.
-
alterTableAddForeignKey
public String alterTableAddForeignKey(DdlOptions options, io.ebeaninternal.dbmigration.ddlgeneration.platform.WriteForeignKey request)
Add foreign key.
-
alterTableDropUniqueConstraint
public String alterTableDropUniqueConstraint(String tableName, String uniqueConstraintName)
Drop a unique constraint from the table (Sometimes this is an index).
-
alterTableDropConstraint
public String alterTableDropConstraint(String tableName, String constraintName)
Drop a unique constraint from the table.
-
alterTableAddUniqueConstraint
public String alterTableAddUniqueConstraint(String tableName, String uqName, String[] columns, String[] nullableColumns)
Add a unique constraint to the table.Overridden by MsSqlServer for specific null handling on unique constraints.
-
alterTableAddColumn
public void alterTableAddColumn(DdlBuffer buffer, String tableName, Column column, boolean onHistoryTable, String defaultValue) throws IOException
- Throws:
IOException
-
alterTableDropColumn
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) throws IOException
- Throws:
IOException
-
isInlineUniqueWhenNullable
public boolean isInlineUniqueWhenNullable()
Return true if unique constraints for nullable columns can be inlined as normal. Returns false for MsSqlServer and DB2 due to it's not possible to to put a constraint on a nullable column
-
alterColumnType
public String alterColumnType(String tableName, String columnName, String type)
Alter a column type.Note that that MySql and SQL Server instead use alterColumnBaseAttributes()
-
alterColumnNotnull
public String alterColumnNotnull(String tableName, String columnName, boolean notnull)
Alter a column adding or removing the not null constraint.Note that that MySql, SQL Server, and HANA instead use alterColumnBaseAttributes()
-
alterTableAddCheckConstraint
public String alterTableAddCheckConstraint(String tableName, String checkConstraintName, String checkConstraint)
Alter table adding the check constraint.
-
alterColumnDefaultValue
public String alterColumnDefaultValue(String tableName, String columnName, String defaultValue)
Alter column setting the default value.
-
alterColumnBaseAttributes
public String alterColumnBaseAttributes(AlterColumn alter)
Alter column setting both the type and not null constraint.Used by MySql, SQL Server, and HANA as these require both column attributes to be set together.
-
getPlatform
public io.ebean.config.dbplatform.DatabasePlatform getPlatform()
-
getUpdateNullWithDefault
public String getUpdateNullWithDefault()
-
inlineTableComment
public void inlineTableComment(DdlBuffer apply, String tableComment) throws IOException
Add an inline table comment to the create table statement.- Throws:
IOException
-
tableStorageEngine
public void tableStorageEngine(DdlBuffer apply, String storageEngine) throws IOException
Add an table storage engine to the create table statement.- Throws:
IOException
-
addTableComment
public void addTableComment(DdlBuffer apply, String tableName, String tableComment) throws IOException
Add table comment as a separate statement (from the create table statement).- Throws:
IOException
-
addColumnComment
public void addColumnComment(DdlBuffer apply, String table, String column, String comment) throws IOException
Add column comment as a separate statement.- Throws:
IOException
-
generateProlog
public void generateProlog(DdlWrite write) throws IOException
Use this to generate a prolog for each script (stored procedures)- Throws:
IOException
-
generateEpilog
public void generateEpilog(DdlWrite write) throws IOException
Use this to generate an epilog. Will be added at the end of script- Throws:
IOException
-
lockTables
public void lockTables(DdlBuffer buffer, Collection<String> tables) throws IOException
Mysql-specific: Locks all tables for triggers that have to be updated.- Throws:
IOException
-
unlockTables
public void unlockTables(DdlBuffer buffer, Collection<String> tables) throws IOException
Mysql-specific: Unlocks all tables for triggers that have to be updated.- Throws:
IOException
-
getCreateTableCommandPrefix
public String getCreateTableCommandPrefix()
Returns the database-specific "create table" command prefix. For HANA this is either "create column table" or "create row table", for all other databases it is "create table".- Returns:
- The "create table" command prefix
-
suppressPrimaryKeyOnPartition
public boolean suppressPrimaryKeyOnPartition()
-
addTablePartition
public void addTablePartition(DdlBuffer apply, String partitionMode, String partitionColumn) throws IOException
- Throws:
IOException
-
-