Class AlterTableBuilder
java.lang.Object
com.valqueries.automapper.context.schema.AlterTableBuilder
- All Implemented Interfaces:
IAlterTableBuilder
,IBaseBuilder
- Direct Known Subclasses:
DryRunAlterTableBuilder
-
Constructor Summary
ConstructorsConstructorDescriptionAlterTableBuilder
(org.jooq.CloseableDSLContext jooq, Supplier<org.jooq.AlterTableStep> jooqStepSupplier, String formattedTableName, Database database, SchemaExaminer schemaExaminer, String schema, Token table) -
Method Summary
Modifier and TypeMethodDescriptionAdd a column with a specific sql type.addColumnIfNotExists
(Token columnName, SqlType<?> columnType) Add a column with a specific sql type.addForeignKey
(String constraintName, Token[] columns, Token referencedTable, Token[] referencedColumns) Add a foreign keyAdd an indexaddPrimaryKey
(Token firstColumn, Token... columns) Add a primary key.Add a unique constraintchangeColumnType
(Token columnName, SqlType<?> newColumnType) Change the type of column to a specific sql type.changeColumnTypeIfExists
(Token columnName, SqlType<?> newColumnType) Change the type of column to a specific sql type, if it exists.changePrimaryKey
(Token firstColumn, Token... columns) Change the primary key.dropColumn
(Token columnName) Drop a column.dropColumnIfExists
(Token columnName) Drop a column if it exists.dropForeignKey
(String constraintName) Drop a foreign key.Drop an index.Drop a primary key without adding a new one.Drop a primary key if it exists, without adding a new one.dropUnique
(String constraintName) Drop a unique constraint.void
execute()
Execute the create/alter table statement(s)getSql()
Useful for debuggingrenameColumn
(Token oldColumnName, Token newColumnName) Rename a column.renameColumnIfPossible
(Token oldColumnName, Token newColumnName) Rename a column if it exists and no column exists with the new name.renameIndex
(String oldIndexName, String newIndexName) Rename an indexrenameTable
(Token newTableName) Rename a table.renameTableIfPossible
(Token newTableName) Rename a table if no table exists with the new name.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.valqueries.automapper.context.schema.IAlterTableBuilder
addColumn, addColumn, addColumn, addColumnIfNotExists, addColumnIfNotExists, addColumnIfNotExists, addForeignKey, addForeignKey, addForeignKey, addIndex, addPrimaryKey, addUnique, changeColumnType, changeColumnType, changeColumnType, changeColumnTypeIfExists, changeColumnTypeIfExists, changeColumnTypeIfExists, changePrimaryKey, dropColumn, dropColumnIfExists, renameColumn, renameColumnIfPossible, renameTable, renameTableIfPossible
-
Constructor Details
-
AlterTableBuilder
-
-
Method Details
-
renameTable
Description copied from interface:IAlterTableBuilder
Rename a table.Note: This is a terminal statement.
- Specified by:
renameTable
in interfaceIAlterTableBuilder
- Parameters:
newTableName
- the new name of the table- Returns:
- this builder, but no more chaining makes sense after this statement. Remember to call
IBaseBuilder.execute()
-
renameTableIfPossible
Description copied from interface:IAlterTableBuilder
Rename a table if no table exists with the new name.Note: This is a terminal statement.
- Specified by:
renameTableIfPossible
in interfaceIAlterTableBuilder
- Parameters:
newTableName
- the new name of the table- Returns:
- this builder, but no more chaining makes sense after this statement. Remember to call
IBaseBuilder.execute()
-
addColumn
Description copied from interface:IAlterTableBuilder
Add a column with a specific sql type. Will fail if a column with the same name already exists. If you are adding auto-increment column it will be automatically made the new primary key.- Specified by:
addColumn
in interfaceIAlterTableBuilder
- Parameters:
columnName
- the name of the columncolumnType
- the type of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
addColumnIfNotExists
Description copied from interface:IAlterTableBuilder
Add a column with a specific sql type. Does nothing if a column with the same name already exists. If you are adding auto-increment column it will be automatically made the new primary key.- Specified by:
addColumnIfNotExists
in interfaceIAlterTableBuilder
- Parameters:
columnName
- the name of the columncolumnType
- the type of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
renameColumn
Description copied from interface:IAlterTableBuilder
Rename a column.- Specified by:
renameColumn
in interfaceIAlterTableBuilder
- Parameters:
oldColumnName
- the old name of the columnnewColumnName
- the new name of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
renameColumnIfPossible
Description copied from interface:IAlterTableBuilder
Rename a column if it exists and no column exists with the new name.- Specified by:
renameColumnIfPossible
in interfaceIAlterTableBuilder
- Parameters:
oldColumnName
- the old name of the columnnewColumnName
- the new name of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
changeColumnType
Description copied from interface:IAlterTableBuilder
Change the type of column to a specific sql type. Auto-increment is not supported, you will have to drop the column and add a new one.- Specified by:
changeColumnType
in interfaceIAlterTableBuilder
- Parameters:
columnName
- the name of the columnnewColumnType
- the new type of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
changeColumnTypeIfExists
Description copied from interface:IAlterTableBuilder
Change the type of column to a specific sql type, if it exists. Auto-increment is not supported, you will have to drop the column and add a new one.- Specified by:
changeColumnTypeIfExists
in interfaceIAlterTableBuilder
- Parameters:
columnName
- the name of the columnnewColumnType
- the new type of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropColumn
Description copied from interface:IAlterTableBuilder
Drop a column. Will fail if the column does not exist.- Specified by:
dropColumn
in interfaceIAlterTableBuilder
- Parameters:
columnName
- the name of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropColumnIfExists
Description copied from interface:IAlterTableBuilder
Drop a column if it exists.- Specified by:
dropColumnIfExists
in interfaceIAlterTableBuilder
- Parameters:
columnName
- the name of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
addPrimaryKey
Description copied from interface:IAlterTableBuilder
Add a primary key. If the table already has a primary key, useIAlterTableBuilder.changePrimaryKey(Token, Token...)
.- Specified by:
addPrimaryKey
in interfaceIAlterTableBuilder
- Parameters:
firstColumn
- the first column of the primary keycolumns
- the rest of the columns of the primary key- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
addForeignKey
public IAlterTableBuilder addForeignKey(String constraintName, Token[] columns, Token referencedTable, Token[] referencedColumns) Description copied from interface:IAlterTableBuilder
Add a foreign key- Specified by:
addForeignKey
in interfaceIAlterTableBuilder
- Parameters:
constraintName
- the name of the foreign keycolumns
- the columns of the foreign keyreferencedTable
- the table referenced by the foreign keyreferencedColumns
- the referenced columns of the foreign key- Returns:
- foreign key builder used to specify the referenced table and column(s)
-
addUnique
Description copied from interface:IAlterTableBuilder
Add a unique constraint- Specified by:
addUnique
in interfaceIAlterTableBuilder
- Parameters:
constraintName
- the name of the constraintfirstColumn
- the first column of the constraintcolumns
- the rest of the columns of the constraint- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
addIndex
Description copied from interface:IAlterTableBuilder
Add an index- Specified by:
addIndex
in interfaceIAlterTableBuilder
- Parameters:
indexName
- the name of the indexfirstColumn
- the first column of the indexcolumns
- the rest of the columns of the index- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
changePrimaryKey
Description copied from interface:IAlterTableBuilder
Change the primary key. Works regardless if the table already has a primary key or not.- Specified by:
changePrimaryKey
in interfaceIAlterTableBuilder
- Parameters:
firstColumn
- the first column of the primary keycolumns
- the rest of the columns of the primary key- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
renameIndex
Description copied from interface:IAlterTableBuilder
Rename an index- Specified by:
renameIndex
in interfaceIAlterTableBuilder
- Parameters:
oldIndexName
- the old name of the indexnewIndexName
- the new name of the index- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropPrimaryKey
Description copied from interface:IAlterTableBuilder
Drop a primary key without adding a new one. Consider usingIAlterTableBuilder.changePrimaryKey(String, String...)
instead. If you are adding auto-increment column as a new primary key, do not use this method, but useIAlterTableBuilder.changePrimaryKey(String, String...)
afterwards.- Specified by:
dropPrimaryKey
in interfaceIAlterTableBuilder
- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropPrimaryKeyIfExists
Description copied from interface:IAlterTableBuilder
Drop a primary key if it exists, without adding a new one. Consider usingIAlterTableBuilder.changePrimaryKey(String, String...)
instead. If you are adding auto-increment column as a new primary key, do not use this method, but useIAlterTableBuilder.changePrimaryKey(String, String...)
afterwards.- Specified by:
dropPrimaryKeyIfExists
in interfaceIAlterTableBuilder
- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropForeignKey
Description copied from interface:IAlterTableBuilder
Drop a foreign key. Will fail if the foreign key does not exist.- Specified by:
dropForeignKey
in interfaceIAlterTableBuilder
- Parameters:
constraintName
- the name of the foreign key- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropUnique
Description copied from interface:IAlterTableBuilder
Drop a unique constraint. Will fail if the constraint does not exist.- Specified by:
dropUnique
in interfaceIAlterTableBuilder
- Parameters:
constraintName
- the name of the constraint- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropIndex
Description copied from interface:IAlterTableBuilder
Drop an index. Will fail if the index does not exist.- Specified by:
dropIndex
in interfaceIAlterTableBuilder
- Parameters:
indexName
- the name of the index- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
execute
public void execute()Description copied from interface:IBaseBuilder
Execute the create/alter table statement(s)- Specified by:
execute
in interfaceIBaseBuilder
-
getSql
Description copied from interface:IBaseBuilder
Useful for debugging- Specified by:
getSql
in interfaceIBaseBuilder
- Returns:
- the sql that would be executed by
IBaseBuilder.execute()
-