Class Tables


  • @ThreadSafe
    public final class Tables
    extends Object
    Structural definitions for a set of tables in a JDBC database.
    Author:
    Randall Hauch
    • Constructor Detail

      • Tables

        public Tables​(boolean tableIdCaseInsensitive)
        Create an empty set of definitions.
        Parameters:
        tableIdCaseInsensitive - - true if lookup is case insensitive (typical for MySQL on Windows)
      • Tables

        public Tables()
        Create case sensitive empty set of definitions.
      • Tables

        protected Tables​(Tables other,
                         boolean tableIdCaseInsensitive)
    • Method Detail

      • clear

        public void clear()
      • size

        public int size()
        Get the number of tables that are in this object.
        Returns:
        the table count
      • drainChanges

        public Set<TableId> drainChanges()
      • overwriteTable

        public Table overwriteTable​(TableId tableId,
                                    List<Column> columnDefs,
                                    List<String> primaryKeyColumnNames,
                                    String defaultCharsetName)
        Add or update the definition for the identified table.
        Parameters:
        tableId - the identifier of the table
        columnDefs - the list of column definitions; may not be null or empty
        primaryKeyColumnNames - the list of the column names that make up the primary key; may be null or empty
        defaultCharsetName - the name of the character set that should be used by default
        Returns:
        the previous table definition, or null if there was no prior table definition
      • overwriteTable

        public Table overwriteTable​(Table table)
        Add or update the definition for the identified table.
        Parameters:
        table - the definition for the table; may not be null
        Returns:
        the previous table definition, or null if there was no prior table definition
      • removeTablesForDatabase

        public void removeTablesForDatabase​(String schemaName)
      • removeTablesForDatabase

        public void removeTablesForDatabase​(String catalogName,
                                            String schemaName)
      • renameTable

        public Table renameTable​(TableId existingTableId,
                                 TableId newTableId)
        Rename an existing table.
        Parameters:
        existingTableId - the identifier of the existing table to be renamed; may not be null
        newTableId - the new identifier for the table; may not be null
        Returns:
        the previous table definition, or null if there was no prior table definition
      • updateTable

        public Table updateTable​(TableId tableId,
                                 Function<Table,​Table> changer)
        Add or update the definition for the identified table.
        Parameters:
        tableId - the identifier of the table
        changer - the function that accepts the current Table and returns either the same or an updated Table; may not be null
        Returns:
        the previous table definition, or null if there was no prior table definition
      • removeTable

        public Table removeTable​(TableId tableId)
        Remove the definition of the identified table.
        Parameters:
        tableId - the identifier of the table
        Returns:
        the existing table definition that was removed, or null if there was no prior table definition
      • forTable

        public Table forTable​(TableId tableId)
        Obtain the definition of the identified table.
        Parameters:
        tableId - the identifier of the table
        Returns:
        the table definition, or null if there was no definition for the identified table
      • forTable

        public Table forTable​(String catalogName,
                              String schemaName,
                              String tableName)
        Obtain the definition of the identified table.
        Parameters:
        catalogName - the name of the database catalog that contains the table; may be null if the JDBC driver does not show a schema for this table
        schemaName - the name of the database schema that contains the table; may be null if the JDBC driver does not show a schema for this table
        tableName - the name of the table
        Returns:
        the table definition, or null if there was no definition for the identified table
      • tableIds

        public Set<TableId> tableIds()
        Get the set of TableIds for which there is a Schema.
        Returns:
        the immutable set of table identifiers; never null
      • editTable

        public TableEditor editTable​(TableId tableId)
        Obtain an editor for the table with the given ID. This method does not lock the set of table definitions, so use with caution. The resulting editor can be used to modify the table definition, but when completed the new Table needs to be added back to this object via overwriteTable(Table).
        Parameters:
        tableId - the identifier of the table
        Returns:
        the editor for the table, or null if there is no table with the specified ID
      • editOrCreateTable

        public TableEditor editOrCreateTable​(TableId tableId)
        Obtain an editor for the table with the given ID. This method does not lock or modify the set of table definitions, so use with caution. The resulting editor can be used to modify the table definition, but when completed the new Table needs to be added back to this object via overwriteTable(Table).
        Parameters:
        tableId - the identifier of the table
        Returns:
        the editor for the table, or null if there is no table with the specified ID
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object