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.voidexecute()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, waitMethods 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:IAlterTableBuilderRename a table.Note: This is a terminal statement.
- Specified by:
renameTablein 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:IAlterTableBuilderRename a table if no table exists with the new name.Note: This is a terminal statement.
- Specified by:
renameTableIfPossiblein 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:IAlterTableBuilderAdd 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:
addColumnin 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:IAlterTableBuilderAdd 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:
addColumnIfNotExistsin 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:IAlterTableBuilderRename a column.- Specified by:
renameColumnin 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:IAlterTableBuilderRename a column if it exists and no column exists with the new name.- Specified by:
renameColumnIfPossiblein 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:IAlterTableBuilderChange 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:
changeColumnTypein 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:IAlterTableBuilderChange 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:
changeColumnTypeIfExistsin 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:IAlterTableBuilderDrop a column. Will fail if the column does not exist.- Specified by:
dropColumnin interfaceIAlterTableBuilder- Parameters:
columnName- the name of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropColumnIfExists
Description copied from interface:IAlterTableBuilderDrop a column if it exists.- Specified by:
dropColumnIfExistsin interfaceIAlterTableBuilder- Parameters:
columnName- the name of the column- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
addPrimaryKey
Description copied from interface:IAlterTableBuilderAdd a primary key. If the table already has a primary key, useIAlterTableBuilder.changePrimaryKey(Token, Token...).- Specified by:
addPrimaryKeyin 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:IAlterTableBuilderAdd a foreign key- Specified by:
addForeignKeyin 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:IAlterTableBuilderAdd a unique constraint- Specified by:
addUniquein 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:IAlterTableBuilderAdd an index- Specified by:
addIndexin 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:IAlterTableBuilderChange the primary key. Works regardless if the table already has a primary key or not.- Specified by:
changePrimaryKeyin 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:IAlterTableBuilderRename an index- Specified by:
renameIndexin 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:IAlterTableBuilderDrop 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:
dropPrimaryKeyin interfaceIAlterTableBuilder- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropPrimaryKeyIfExists
Description copied from interface:IAlterTableBuilderDrop 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:
dropPrimaryKeyIfExistsin interfaceIAlterTableBuilder- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropForeignKey
Description copied from interface:IAlterTableBuilderDrop a foreign key. Will fail if the foreign key does not exist.- Specified by:
dropForeignKeyin interfaceIAlterTableBuilder- Parameters:
constraintName- the name of the foreign key- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropUnique
Description copied from interface:IAlterTableBuilderDrop a unique constraint. Will fail if the constraint does not exist.- Specified by:
dropUniquein interfaceIAlterTableBuilder- Parameters:
constraintName- the name of the constraint- Returns:
- this builder, for chaining. Remember to call
IBaseBuilder.execute()
-
dropIndex
Description copied from interface:IAlterTableBuilderDrop an index. Will fail if the index does not exist.- Specified by:
dropIndexin 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:IBaseBuilderExecute the create/alter table statement(s)- Specified by:
executein interfaceIBaseBuilder
-
getSql
Description copied from interface:IBaseBuilderUseful for debugging- Specified by:
getSqlin interfaceIBaseBuilder- Returns:
- the sql that would be executed by
IBaseBuilder.execute()
-