Package org.jumpmind.db.model
Class Table
java.lang.Object
org.jumpmind.db.model.Table
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<Table>
Represents a table in the database model.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given column at the specified position.final void
Adds the given column.void
Adds the column after the given previous column.void
addColumns
(String[] columnNames) void
addColumns
(Collection<Column> columns) Adds the given columns.void
addForeignKey
(int idx, ForeignKey foreignKey) Adds the given foreign key at the specified position.void
addForeignKey
(ForeignKey foreignKey) Adds the given foreign key.void
addForeignKeys
(Collection<ForeignKey> foreignKeys) Adds the given foreign keys.void
Adds the given index at the specified position.void
Adds the given index.void
addIndices
(Collection<IIndex> indices) Adds the given indices.void
addTrigger
(int idx, Trigger trigger) final void
addTrigger
(Trigger trigger) void
addTrigger
(Trigger previousTrigger, Trigger trigger) void
addTriggers
(Collection<Trigger> triggers) static boolean
areAllColumnsPrimaryKeys
(Column[] columns) static Table
buildTable
(String tableName, String[] keyNames, String[] columnNames) int
protected int
calculateTableHashcode
(boolean includeTypes) int
clone()
int
boolean
boolean
containsLobColumns
(IDatabasePlatform platform) copy()
copyAndFilterColumns
(String[] orderedColumnNames, String[] pkColumnNames, boolean setPrimaryKeys, boolean addMissingColumns) Creates a copy of this table and orders the columns according to the supplied array of column names.void
copyColumnTypesFrom
(Table table) boolean
boolean
boolean
equalsByName
(Table other) static String
escapeColumnNameForCsv
(String columnName) findColumn
(String name) Finds the column with the specified name, using case insensitive matching.findColumn
(String name, boolean caseSensitive) Finds the column with the specified name, using case insensitive matching.findForeignKey
(ForeignKey key) Finds the foreign key in this table that is equal to the supplied foreign key.findForeignKey
(ForeignKey key, boolean caseSensitive) Finds the foreign key in this table that is equal to the supplied foreign key.Finds the index with the specified name, using case insensitive matching.Finds the index with the specified name, using case insensitive matching.findTrigger
(String name, boolean caseSensitive) static String[]
getArrayColumns
(Column[] cols) Column[]
Returns the auto increment columns in this table.Returns the catalog of this table as read from the database.getColumn
(int idx) Returns the column at the specified position.int
Returns the number of columns in this table.int
getColumnIndex
(String columnName) int
getColumnIndex
(Column column) Determines the index of the given column.String[]
Column[]
Returns the columns in this table.Returns the columns in this table.Column[]
getColumnsWithName
(String[] columnNames) final Column
getColumnWithName
(String name) static String
getCommaDeliminatedColumns
(Column[] cols) Returns the description of the table.Column[]
getForeignKey
(int idx) Returns the foreign key at the given position.int
Returns the number of foreign keys.Returns the foreign keys of this table.getFullyQualifiedTableName
(String quote) static String
getFullyQualifiedTableName
(String catalogName, String schemaName, String tableName) static String
getFullyQualifiedTableName
(String catalogName, String schemaName, String tableName, String quoteString, String catalogSeparator, String schemaSeparator) static String
getFullyQualifiedTablePrefix
(StringBuilder sb, String catalogName, String schemaName, String quoteString, String catalogSeparator, String schemaSeparator) static String
getFullyQualifiedTablePrefix
(String catalogName, String schemaName) static String
getFullyQualifiedTablePrefix
(String catalogName, String schemaName, String quoteString, String catalogSeparator, String schemaSeparator) getIndex
(int idx) Returns the index at the specified position.int
Returns the number of indices.IIndex[]
Returns the indices of this table.getLobColumns
(IDatabasePlatform platform) boolean
Reports table's mode for write-ahead (transaction) log.getName()
Returns the name of the table.Column[]
Returns the columns in this table that are not a PK.IIndex[]
Gets a list of non-unique indices on this table.int
int
getPrimaryKeyColumnIndex
(String columnName) String[]
Column[]
Returns the primary key columns of this table.Returns the primary key columns of this table.Column[]
getQualifiedColumnName
(Column column) getQualifiedTableName
(String quoteString, String catalogSeparator, String schemaSeparator) getQualifiedTablePrefix
(String quoteString, String catalogSeparator, String schemaSeparator) Returns the schema of this table as read from the database.Returns the foreign key referencing this table if it exists.getTrigger
(int i) int
Trigger[]
getType()
Returns the type of this table as read from the database.IIndex[]
Gets a list of unique indices on this table.boolean
boolean
int
hashCode()
boolean
boolean
Determines whether there is at least one primary key column on this table.boolean
boolean
void
orderColumns
(String[] columnNames) void
orderColumns
(String[] columnNames, boolean addMissingColumns) static Column[]
orderColumns
(String[] columnNames, Table table, boolean addMissingColumns) void
void
void
void
void
void
void
removeColumn
(int idx) Removes the indicated column.void
removeColumn
(Column column) Removes the given column.void
removeForeignKey
(int idx) Removes the indicated foreign key.void
removeForeignKey
(ForeignKey foreignKey) Removes the given foreign key.void
removeIndex
(int idx) Removes the indicated index.void
removeIndex
(IIndex index) Removes the given index.void
removeTrigger
(Trigger trigger) void
setAccessControlled
(boolean isAccessControlled) void
setCatalog
(String catalog) Sets the catalog of this table.void
setCompressionType
(CompressionTypes compressionType) void
setDescription
(String description) Sets the description of the table.void
setLogging
(boolean value) void
setMadeAllColumnsPrimaryKey
(boolean madeAllColumnsPrimaryKey) void
Sets the name of the table.void
setOldCatalog
(String oldCatalog) void
setOldSchema
(String oldSchema) void
setPrimaryKeyConstraintName
(String primaryKeyConstraintName) void
setPrimaryKeys
(String[] primaryKeys) void
Sets the schema of this table.void
Sets the type of this table.void
sortForeignKeys
(boolean caseSensitive) Sorts the foreign keys alphabetically.toString()
Returns a verbose string representation of this table.
-
Constructor Details
-
Table
public Table() -
Table
-
Table
-
Table
-
Table
-
-
Method Details
-
removeAllColumns
public void removeAllColumns() -
removeAllColumnDefaults
public void removeAllColumnDefaults() -
removeAllIndices
public void removeAllIndices() -
removeAllForeignKeys
public void removeAllForeignKeys() -
removeAllIndexes
public void removeAllIndexes() -
removeAllTriggers
public void removeAllTriggers() -
getCatalog
Returns the catalog of this table as read from the database.- Returns:
- The catalog
-
setCatalog
Sets the catalog of this table.- Parameters:
catalog
- The catalog
-
getSchema
Returns the schema of this table as read from the database.- Returns:
- The schema
-
setSchema
Sets the schema of this table.- Parameters:
schema
- The schema
-
getType
Returns the type of this table as read from the database.- Returns:
- The type
-
setType
Sets the type of this table.- Parameters:
type
- The type
-
getName
Returns the name of the table.- Returns:
- The name
-
setName
Sets the name of the table.- Parameters:
name
- The name
-
getDescription
Returns the description of the table.- Returns:
- The description
-
setDescription
Sets the description of the table.- Parameters:
description
- The description
-
getColumnCount
public int getColumnCount()Returns the number of columns in this table.- Returns:
- The number of columns
-
getPrimaryKeyColumnCount
public int getPrimaryKeyColumnCount() -
getColumn
Returns the column at the specified position.- Parameters:
idx
- The column index- Returns:
- The column at this position
-
getColumns
Returns the columns in this table.- Returns:
- The columns
-
getColumnsAsList
Returns the columns in this table.- Returns:
- The columns
-
addColumn
Adds the given column.- Parameters:
column
- The column
-
addColumn
Adds the given column at the specified position.- Parameters:
idx
- The index where to add the columncolumn
- The column
-
addColumn
Adds the column after the given previous column.- Parameters:
previousColumn
- The column to add the new column after; usenull
for adding at the begincolumn
- The column
-
addColumns
Adds the given columns.- Parameters:
columns
- The columns
-
setPrimaryKeys
-
addColumns
-
removeColumn
Removes the given column.- Parameters:
column
- The column to remove
-
removeColumn
public void removeColumn(int idx) Removes the indicated column.- Parameters:
idx
- The index of the column to remove
-
getForeignKeyCount
public int getForeignKeyCount()Returns the number of foreign keys.- Returns:
- The number of foreign keys
-
getForeignKey
Returns the foreign key at the given position.- Parameters:
idx
- The foreign key index- Returns:
- The foreign key
-
getForeignKeys
Returns the foreign keys of this table.- Returns:
- The foreign keys
-
addForeignKey
Adds the given foreign key.- Parameters:
foreignKey
- The foreign key
-
addForeignKey
Adds the given foreign key at the specified position.- Parameters:
idx
- The index to add the foreign key atforeignKey
- The foreign key
-
addForeignKeys
Adds the given foreign keys.- Parameters:
foreignKeys
- The foreign keys
-
removeForeignKey
Removes the given foreign key.- Parameters:
foreignKey
- The foreign key to remove
-
removeForeignKey
public void removeForeignKey(int idx) Removes the indicated foreign key.- Parameters:
idx
- The index of the foreign key to remove
-
getIndexCount
public int getIndexCount()Returns the number of indices.- Returns:
- The number of indices
-
getIndex
Returns the index at the specified position.- Parameters:
idx
- The position- Returns:
- The index
-
addIndex
Adds the given index.- Parameters:
index
- The index
-
addIndex
Adds the given index at the specified position.- Parameters:
idx
- The position to add the index atindex
- The index
-
addIndices
Adds the given indices.- Parameters:
indices
- The indices
-
getIndices
Returns the indices of this table.- Returns:
- The indices
-
getNonUniqueIndices
Gets a list of non-unique indices on this table.- Returns:
- The unique indices
-
getUniqueIndices
Gets a list of unique indices on this table.- Returns:
- The unique indices
-
removeIndex
Removes the given index.- Parameters:
index
- The index to remove
-
removeIndex
public void removeIndex(int idx) Removes the indicated index.- Parameters:
idx
- The position of the index to remove
-
hasPrimaryKey
public boolean hasPrimaryKey()Determines whether there is at least one primary key column on this table.- Returns:
true
if there are one or more primary key columns
-
hasNTypeColumns
public boolean hasNTypeColumns() -
hasGeneratedColumns
public boolean hasGeneratedColumns() -
findColumn
Finds the column with the specified name, using case insensitive matching. Note that this method is not called getColumn(String) to avoid introspection problems.- Parameters:
name
- The name of the column- Returns:
- The column or
null
if there is no such column
-
findColumn
Finds the column with the specified name, using case insensitive matching. Note that this method is not called getColumn(String) to avoid introspection problems.- Parameters:
name
- The name of the columncaseSensitive
- Whether case matters for the names- Returns:
- The column or
null
if there is no such column
-
getColumnIndex
Determines the index of the given column.- Parameters:
column
- The column- Returns:
- The index or
-1
if it is no column of this table
-
getColumnIndex
-
getPrimaryKeyColumnIndex
-
findIndex
Finds the index with the specified name, using case insensitive matching. Note that this method is not called getIndex to avoid introspection problems.- Parameters:
name
- The name of the index- Returns:
- The index or
null
if there is no such index
-
findIndex
Finds the index with the specified name, using case insensitive matching. Note that this method is not called getIndex to avoid introspection problems.- Parameters:
name
- The name of the indexcaseSensitive
- Whether case matters for the names- Returns:
- The index or
null
if there is no such index
-
findForeignKey
Finds the foreign key in this table that is equal to the supplied foreign key.- Parameters:
key
- The foreign key to search for- Returns:
- The found foreign key
-
findForeignKey
Finds the foreign key in this table that is equal to the supplied foreign key.- Parameters:
key
- The foreign key to search forcaseSensitive
- Whether case matters for the names- Returns:
- The found foreign key
-
getSelfReferencingForeignKey
Returns the foreign key referencing this table if it exists.- Returns:
- The self-referencing foreign key if any
-
getPrimaryKeyColumnsAsList
Returns the primary key columns of this table.- Returns:
- The primary key columns
-
getPrimaryKeyColumns
Returns the primary key columns of this table.- Returns:
- The primary key columns
-
getPrimaryKeyColumnsInIndexOrder
-
getNonPrimaryKeyColumns
Returns the columns in this table that are not a PK. -
getAutoIncrementColumns
Returns the auto increment columns in this table. If no incrementcolumns are found, it will return an empty array.- Returns:
- The columns
-
sortForeignKeys
public void sortForeignKeys(boolean caseSensitive) Sorts the foreign keys alphabetically.- Parameters:
caseSensitive
- Whether case matters
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
equals
-
equalsByName
-
hashCode
public int hashCode() -
toString
-
toVerboseString
Returns a verbose string representation of this table.- Returns:
- The string representation
-
getTableKey
-
containsLobColumns
-
getLobColumns
-
getFullyQualifiedTableName
-
getFullyQualifiedTableNameLowerCase
-
getFullyQualifiedTableName
-
getNameLowerCase
-
getFullyQualifiedTableName
-
getQualifiedColumnName
-
getFullyQualifiedTablePrefix
-
getQualifiedTableName
-
getQualifiedTableName
-
getFullyQualifiedTableName
-
getFullyQualifiedTablePrefix
-
getFullyQualifiedTablePrefix
-
getQualifiedTablePrefix
-
getColumnWithName
-
getColumnsWithName
-
doesIndexContainOnlyPrimaryKeyColumns
-
hasAutoIncrementColumn
public boolean hasAutoIncrementColumn() -
getDistributionKeyColumns
-
orderColumns
-
orderColumns
-
orderColumns
-
getOldCatalog
-
setOldCatalog
-
getOldSchema
-
setOldSchema
-
isAccessControlled
public boolean isAccessControlled()- Returns:
- the isAccessControlled
-
setAccessControlled
public void setAccessControlled(boolean isAccessControlled) - Parameters:
isAccessControlled
- the isAccessControlled to set
-
copy
-
copyAndFilterColumns
public Table copyAndFilterColumns(String[] orderedColumnNames, String[] pkColumnNames, boolean setPrimaryKeys, boolean addMissingColumns) Creates a copy of this table and orders the columns according to the supplied array of column names.- Parameters:
orderedColumnNames
- An array of column names whose order determines the order of the returned table's columnspkColumnNames
- An array of the names of the columns that make up the table's primary keysetPrimaryKeys
- Whether to change the returned table's primary key columns based on the supplied array of primary key column namesaddMissingColumns
- Whether to add columns to the returned table if they are present in the supplied array of column names but not in the existing table's list of columns- Returns:
- A copy of this table
-
getColumnNames
-
getPrimaryKeyColumnNames
-
calculateTableHashcode
public int calculateTableHashcode() -
calculateTableLiteHashcode
public int calculateTableLiteHashcode() -
calculateTableHashcode
protected int calculateTableHashcode(boolean includeTypes) -
areAllColumnsPrimaryKeys
-
buildTable
-
getCommaDeliminatedColumns
-
getArrayColumns
-
setPrimaryKeyConstraintName
-
getPrimaryKeyConstraintName
-
containsJdbcTypes
public boolean containsJdbcTypes() -
copyColumnTypesFrom
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Table>
-
escapeColumnNameForCsv
-
getCompressionType
-
setCompressionType
-
isMadeAllColumnsPrimaryKey
public boolean isMadeAllColumnsPrimaryKey() -
setMadeAllColumnsPrimaryKey
public void setMadeAllColumnsPrimaryKey(boolean madeAllColumnsPrimaryKey) -
getTriggerCount
public int getTriggerCount() -
getTrigger
-
getTriggers
-
getTriggersAsList
-
addTrigger
-
addTrigger
-
addTrigger
-
addTriggers
-
findTrigger
-
removeTrigger
-
getLogging
public boolean getLogging()Reports table's mode for write-ahead (transaction) log.- Returns:
- true, if table is being logged
-
setLogging
public void setLogging(boolean value)
-