Package org.pgcodekeeper.core.schema
Class AbstractTable
java.lang.Object
org.pgcodekeeper.core.schema.PgStatement
org.pgcodekeeper.core.schema.PgStatementContainer
org.pgcodekeeper.core.schema.AbstractTable
- All Implemented Interfaces:
IHashable,IOptionContainer,IRelation,ISearchPath,IStatement,IStatementContainer
- Direct Known Subclasses:
AbstractPgTable,ChTable,MsTable
Abstract base class for database tables.
Contains columns, constraints, indexes, triggers, and other table-related objects.
Provides common functionality for tables across different database types.
-
Field Summary
Fields inherited from class org.pgcodekeeper.core.schema.PgStatement
GOFields inherited from interface org.pgcodekeeper.core.schema.IOptionContainer
GP_OPTION_LIST -
Method Summary
Modifier and TypeMethodDescriptionvoidaddColumn(AbstractColumn column) Adds a column to the table.voidaddConstraint(AbstractConstraint constraint) Adds a constraint to this container.voidAdds an option to this container.voidappendMoveDataSql(PgStatement newCondition, SQLScript script, String tblTmpBareName, List<String> identityCols) Adds commands to the script for move data from the temporary table to the new table, given the identity columns, and a command to delete the temporary table.static Stream<PgStatement>Creates a stream that includes the statement itself and its columns if it's a table.booleancompare(PgStatement obj) This method does not account for nested child PgStatements.booleanDeep part ofPgStatement.equals(Object).static booleancompareIgnoringColumnOrder(AbstractTable oldTable, AbstractTable newTable) Checks that tables are equal regardless of column order.voidcomputeChildrenHash(Hasher hasher) voidcomputeHash(Hasher hasher) Computes the hash of the implementing object using the provided hasher.booleancontainsColumn(String name) Checks if a column with the specified name exists.abstract StringgetAlterTable(boolean only) Generates beginning of alter table statement.Finds column according to specified columnname.Getter forcolumns.getConstraint(String name) Finds constraint according to specified constraintname.Getter forconstraints.Gets the value for the specified option.Gets all options for this container.Gets the columns of this relation as name-type pairs.Gets the type of this database object.final booleanisRecreated(AbstractTable newTable, ISettings settings) Compares this table with thenewTableto determine if a full table recreation is required.Copies all object properties into a new object and leaves all its children empty.Methods inherited from class org.pgcodekeeper.core.schema.PgStatementContainer
addChild, addIndex, addPolicy, addRule, addTrigger, getChild, getContainingSchema, getIndex, getIndexes, getPolicies, getPolicy, getRule, getRules, getTrigger, getTriggers, isClusteredMethods inherited from class org.pgcodekeeper.core.schema.PgStatement
addAllDeps, addDep, addPrivilege, appendAlterComments, appendAlterSQL, appendComments, appendOwnerSQL, canDrop, canDropBeforeCreate, checkComments, clearPrivileges, deepCopy, equals, getAuthor, getBareName, getChildren, getComment, getCreationSQL, getDbType, getDeps, getDescendants, getDropSQL, getDropSQL, getLibName, getLocation, getName, getObjectState, getObjectState, getOwner, getParent, getPrivileges, getQualifiedName, getSQL, getTwin, getTypeName, hasChildren, hashCode, isLib, isOwned, isSubElement, setAuthor, setComment, setLibName, setLocation, setOwner, setParent, toStringMethods inherited from interface org.pgcodekeeper.core.schema.IOptionContainer
compareOptionsMethods inherited from interface org.pgcodekeeper.core.schema.ISearchPath
getDatabase, getSchemaNameMethods inherited from interface org.pgcodekeeper.core.schema.IStatement
getBareName, getComment, getName, getParent, getQualifiedName
-
Method Details
-
getStatementType
Description copied from interface:IStatementGets the type of this database object.- Specified by:
getStatementTypein interfaceIStatement- Returns:
- the database object type
-
columnAdder
Creates a stream that includes the statement itself and its columns if it's a table.- Parameters:
st- the statement to process- Returns:
- a stream containing the statement and its columns (if applicable)
-
getAlterTable
Generates beginning of alter table statement.- Parameters:
only- if true, append 'ONLY' to statement- Returns:
- alter table statement beginning in String format
-
getColumn
Finds column according to specified columnname.- Parameters:
name- name of the column to be searched- Returns:
- found column or null if no such column has been found
-
getColumns
Getter forcolumns. The list cannot be modified.- Returns:
columns
-
getRelationColumns
Description copied from interface:IRelationGets the columns of this relation as name-type pairs.- Specified by:
getRelationColumnsin interfaceIRelation- Returns:
- a stream of column name and type pairs
-
getConstraint
Description copied from class:PgStatementContainerFinds constraint according to specified constraintname.- Specified by:
getConstraintin classPgStatementContainer- Parameters:
name- name of the constraint to be searched- Returns:
- found constraint or null if no such constraint has been found
-
getConstraints
Getter forconstraints. The list cannot be modified.- Specified by:
getConstraintsin classPgStatementContainer- Returns:
constraints
-
isRecreated
Compares this table with thenewTableto determine if a full table recreation is required. A full recreation (DROP and CREATE) is needed when the tables differ in ways that cannot be altered using ALTER TABLE statements.- Parameters:
newTable- the new table definition to compare againstsettings- application settings that may affect the comparison logic- Returns:
trueif the table requires recreation (DROP and CREATE) rather than being alterable,falseif the changes can be applied via ALTER TABLE
-
getOptions
Description copied from interface:IOptionContainerGets all options for this container.- Specified by:
getOptionsin interfaceIOptionContainer- Returns:
- a map of option keys to values
-
getOption
Gets the value for the specified option.- Parameters:
option- the option key- Returns:
- the option value, or null if not found
-
addOption
Description copied from interface:IOptionContainerAdds an option to this container.- Specified by:
addOptionin interfaceIOptionContainer- Parameters:
option- the option keyvalue- the option value
-
addColumn
Adds a column to the table.- Parameters:
column- the column to add
-
addConstraint
Description copied from class:PgStatementContainerAdds a constraint to this container.- Specified by:
addConstraintin classPgStatementContainer- Parameters:
constraint- the constraint to add
-
containsColumn
Checks if a column with the specified name exists.- Parameters:
name- the column name- Returns:
- true if column exists, false otherwise
-
compare
Description copied from class:PgStatementThis method does not account for nested child PgStatements. Shallow version ofPgStatement.equals(Object)- Overrides:
comparein classPgStatement
-
compareIgnoringColumnOrder
Checks that tables are equal regardless of column order.- Parameters:
oldTable- old state of the tablenewTable- new state of the table- Returns:
- true if the tables are identical
-
compareChildren
Description copied from class:PgStatementDeep part ofPgStatement.equals(Object). Compares all object's child PgStatements for equality.- Overrides:
compareChildrenin classPgStatementContainer
-
computeChildrenHash
- Overrides:
computeChildrenHashin classPgStatementContainer
-
computeHash
Description copied from interface:IHashableComputes the hash of the implementing object using the provided hasher. The implementation should call appropriateputmethods on the hasher for all fields that should contribute to the hash value.- Specified by:
computeHashin interfaceIHashable- Parameters:
hasher- the hasher instance to use for hash computation
-
shallowCopy
Description copied from class:PgStatementCopies all object properties into a new object and leaves all its children empty.- Overrides:
shallowCopyin classPgStatementContainer- Returns:
- shallow copy of a DB object.
-
appendMoveDataSql
public void appendMoveDataSql(PgStatement newCondition, SQLScript script, String tblTmpBareName, List<String> identityCols) Adds commands to the script for move data from the temporary table to the new table, given the identity columns, and a command to delete the temporary table.
-