Class AbstractTable

All Implemented Interfaces:
IHashable, IOptionContainer, IRelation, ISearchPath, IStatement, IStatementContainer
Direct Known Subclasses:
AbstractPgTable, ChTable, MsTable

public abstract class AbstractTable extends PgStatementContainer implements IOptionContainer
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.
  • Method Details

    • getStatementType

      public DbObjType getStatementType()
      Description copied from interface: IStatement
      Gets the type of this database object.
      Specified by:
      getStatementType in interface IStatement
      Returns:
      the database object type
    • columnAdder

      public static Stream<PgStatement> columnAdder(PgStatement st)
      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

      public abstract String getAlterTable(boolean only)
      Generates beginning of alter table statement.
      Parameters:
      only - if true, append 'ONLY' to statement
      Returns:
      alter table statement beginning in String format
    • getColumn

      public AbstractColumn getColumn(String name)
      Finds column according to specified column name.
      Parameters:
      name - name of the column to be searched
      Returns:
      found column or null if no such column has been found
    • getColumns

      public List<AbstractColumn> getColumns()
      Getter for columns. The list cannot be modified.
      Returns:
      columns
    • getRelationColumns

      public Stream<Pair<String,String>> getRelationColumns()
      Description copied from interface: IRelation
      Gets the columns of this relation as name-type pairs.
      Specified by:
      getRelationColumns in interface IRelation
      Returns:
      a stream of column name and type pairs
    • getConstraint

      public AbstractConstraint getConstraint(String name)
      Description copied from class: PgStatementContainer
      Finds constraint according to specified constraint name.
      Specified by:
      getConstraint in class PgStatementContainer
      Parameters:
      name - name of the constraint to be searched
      Returns:
      found constraint or null if no such constraint has been found
    • getConstraints

      public Collection<AbstractConstraint> getConstraints()
      Getter for constraints. The list cannot be modified.
      Specified by:
      getConstraints in class PgStatementContainer
      Returns:
      constraints
    • isRecreated

      public final boolean isRecreated(AbstractTable newTable, ISettings settings)
      Compares this table with the newTable to 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 against
      settings - application settings that may affect the comparison logic
      Returns:
      true if the table requires recreation (DROP and CREATE) rather than being alterable, false if the changes can be applied via ALTER TABLE
    • getOptions

      public Map<String,String> getOptions()
      Description copied from interface: IOptionContainer
      Gets all options for this container.
      Specified by:
      getOptions in interface IOptionContainer
      Returns:
      a map of option keys to values
    • getOption

      public String getOption(String option)
      Gets the value for the specified option.
      Parameters:
      option - the option key
      Returns:
      the option value, or null if not found
    • addOption

      public void addOption(String option, String value)
      Description copied from interface: IOptionContainer
      Adds an option to this container.
      Specified by:
      addOption in interface IOptionContainer
      Parameters:
      option - the option key
      value - the option value
    • addColumn

      public void addColumn(AbstractColumn column)
      Adds a column to the table.
      Parameters:
      column - the column to add
    • addConstraint

      public void addConstraint(AbstractConstraint constraint)
      Description copied from class: PgStatementContainer
      Adds a constraint to this container.
      Specified by:
      addConstraint in class PgStatementContainer
      Parameters:
      constraint - the constraint to add
    • containsColumn

      public boolean containsColumn(String name)
      Checks if a column with the specified name exists.
      Parameters:
      name - the column name
      Returns:
      true if column exists, false otherwise
    • compare

      public boolean compare(PgStatement obj)
      Description copied from class: PgStatement
      This method does not account for nested child PgStatements. Shallow version of PgStatement.equals(Object)
      Overrides:
      compare in class PgStatement
    • compareIgnoringColumnOrder

      public static boolean compareIgnoringColumnOrder(AbstractTable oldTable, AbstractTable newTable)
      Checks that tables are equal regardless of column order.
      Parameters:
      oldTable - old state of the table
      newTable - new state of the table
      Returns:
      true if the tables are identical
    • compareChildren

      public boolean compareChildren(PgStatement obj)
      Description copied from class: PgStatement
      Deep part of PgStatement.equals(Object). Compares all object's child PgStatements for equality.
      Overrides:
      compareChildren in class PgStatementContainer
    • computeChildrenHash

      public void computeChildrenHash(Hasher hasher)
      Overrides:
      computeChildrenHash in class PgStatementContainer
    • computeHash

      public void computeHash(Hasher hasher)
      Description copied from interface: IHashable
      Computes the hash of the implementing object using the provided hasher. The implementation should call appropriate put methods on the hasher for all fields that should contribute to the hash value.
      Specified by:
      computeHash in interface IHashable
      Parameters:
      hasher - the hasher instance to use for hash computation
    • shallowCopy

      public AbstractTable shallowCopy()
      Description copied from class: PgStatement
      Copies all object properties into a new object and leaves all its children empty.
      Overrides:
      shallowCopy in class PgStatementContainer
      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.