Class MTable
- java.lang.Object
-
- io.ebeaninternal.dbmigration.model.MTable
-
public class MTable extends Object
Holds the logical model for a given Table and everything associated to it.This effectively represents a table, its columns and all associated constraints, foreign keys and indexes.
Migrations can be applied to this such that it represents the state of a given table after various migrations have been applied.
This table model can also be derived from the EbeanServer bean descriptor and associated properties.
-
-
Constructor Summary
Constructors Constructor Description MTable(CreateTable createTable)
Construct for migration.MTable(BeanDescriptor<?> descriptor)
MTable(String name)
Construct for element collection or intersection table.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColumn(MColumn column)
Add a model column (typically from EbeanServer meta data).MColumn
addColumn(String dbCol, String columnDefn, boolean notnull)
Add a column checking if it already exists and if so return the existing column.void
addForeignKey(MCompoundForeignKey compoundKey)
Add a compound foreign key.void
addForeignKey(String name, String refTableName, String indexName, String columnNames, String refColumnNames)
void
addUniqueConstraint(MCompoundUniqueConstraint uniqueConstraint)
Add a unique constraint.void
adjustReferences(ModelContainer modelContainer)
Adjust the references (FK) if it should relate to a draft table.Collection<MColumn>
allColumns()
Return all the columns (excluding columns marked as dropped).List<String>
allHistoryColumns(boolean includeDropped)
void
apply(AddColumn addColumn)
Apply AddColumn migration.void
apply(AlterColumn alterColumn)
Apply AddColumn migration.void
apply(DropColumn dropColumn)
Apply DropColumn migration.void
apply(RenameColumn renameColumn)
void
checkDuplicateForeignKeys()
Check if there are duplicate foreign keys.void
clearForeignKeyIndexes()
Clear the indexes on the foreign keys as they are covered by unique constraints.void
compare(ModelDiff modelDiff, MTable newTable)
Compare to another version of the same table to perform a diff.MTable
createDraftTable()
Create a copy of this table structure as a 'draft' table.CreateTable
createTable()
Return the CreateTable migration for this table.DropTable
dropTable()
Return the DropTable migration for this table.MColumn
getColumn(String name)
Return the column by name.String
getComment()
List<MCompoundForeignKey>
getCompoundKeys()
String
getIndexTablespace()
String
getName()
PartitionMeta
getPartitionMeta()
Return the partition meta for this table.String
getPkName()
String
getSchema()
String
getTablespace()
List<MCompoundUniqueConstraint>
getUniqueConstraints()
String
getWhenCreatedColumn()
boolean
isDraft()
Return true if this table is a 'Draft' table.boolean
isPartitioned()
Return true if this table is partitioned.boolean
isWithHistory()
List<MColumn>
primaryKeyColumns()
Return the list of columns that make the primary key.void
registerPendingDropColumn(String columnName)
Register a pending un-applied drop column.void
removeForeignKey(String name)
void
setComment(String comment)
void
setPkName(String pkName)
MIndex
setReusedElementCollection()
Clear foreign key as this element collection table logically references back to multiple tables.MTable
setWithHistory(boolean withHistory)
String
singlePrimaryKey()
Return the primary key column if it is a simple primary key.void
updateCompoundIndices()
This method adds information which columns are nullable or not to the compound indices.
-
-
-
Constructor Detail
-
MTable
public MTable(BeanDescriptor<?> descriptor)
-
MTable
public MTable(CreateTable createTable)
Construct for migration.
-
-
Method Detail
-
createDraftTable
public MTable createDraftTable()
Create a copy of this table structure as a 'draft' table.Note that both tables contain @DraftOnly MColumns and these are filtered out later when creating the CreateTable object.
-
addForeignKey
public void addForeignKey(String name, String refTableName, String indexName, String columnNames, String refColumnNames)
-
createTable
public CreateTable createTable()
Return the CreateTable migration for this table.
-
compare
public void compare(ModelDiff modelDiff, MTable newTable)
Compare to another version of the same table to perform a diff.
-
apply
public void apply(AlterColumn alterColumn)
Apply AddColumn migration.
-
apply
public void apply(DropColumn dropColumn)
Apply DropColumn migration.
-
apply
public void apply(RenameColumn renameColumn)
-
isDraft
public boolean isDraft()
Return true if this table is a 'Draft' table.
-
isPartitioned
public boolean isPartitioned()
Return true if this table is partitioned.
-
getPartitionMeta
public PartitionMeta getPartitionMeta()
Return the partition meta for this table.
-
getComment
public String getComment()
-
setComment
public void setComment(String comment)
-
getTablespace
public String getTablespace()
-
getIndexTablespace
public String getIndexTablespace()
-
isWithHistory
public boolean isWithHistory()
-
setWithHistory
public MTable setWithHistory(boolean withHistory)
-
allHistoryColumns
public List<String> allHistoryColumns(boolean includeDropped)
-
allColumns
public Collection<MColumn> allColumns()
Return all the columns (excluding columns marked as dropped).
-
getUniqueConstraints
public List<MCompoundUniqueConstraint> getUniqueConstraints()
-
getCompoundKeys
public List<MCompoundForeignKey> getCompoundKeys()
-
getWhenCreatedColumn
public String getWhenCreatedColumn()
-
primaryKeyColumns
public List<MColumn> primaryKeyColumns()
Return the list of columns that make the primary key.
-
singlePrimaryKey
public String singlePrimaryKey()
Return the primary key column if it is a simple primary key.
-
addColumn
public void addColumn(MColumn column)
Add a model column (typically from EbeanServer meta data).
-
addUniqueConstraint
public void addUniqueConstraint(MCompoundUniqueConstraint uniqueConstraint)
Add a unique constraint.
-
addForeignKey
public void addForeignKey(MCompoundForeignKey compoundKey)
Add a compound foreign key.
-
addColumn
public MColumn addColumn(String dbCol, String columnDefn, boolean notnull)
Add a column checking if it already exists and if so return the existing column. Sometimes the case for a primaryKey that is also a foreign key.
-
registerPendingDropColumn
public void registerPendingDropColumn(String columnName)
Register a pending un-applied drop column.This means this column still needs to be included in history views/triggers etc even though it is not part of the current model.
-
checkDuplicateForeignKeys
public void checkDuplicateForeignKeys()
Check if there are duplicate foreign keys.This can occur when an ManyToMany relates back to itself.
-
adjustReferences
public void adjustReferences(ModelContainer modelContainer)
Adjust the references (FK) if it should relate to a draft table.
-
updateCompoundIndices
public void updateCompoundIndices()
This method adds information which columns are nullable or not to the compound indices.
-
removeForeignKey
public void removeForeignKey(String name)
-
clearForeignKeyIndexes
public void clearForeignKeyIndexes()
Clear the indexes on the foreign keys as they are covered by unique constraints.
-
setReusedElementCollection
public MIndex setReusedElementCollection()
Clear foreign key as this element collection table logically references back to multiple tables.
-
-