Interface TableEditor

All Known Implementing Classes:
NoOpTableEditorImpl, TableEditorImpl

@NotThreadSafe public interface TableEditor
An editor for Table instances, normally obtained from a Tables instance.
Author:
Randall Hauch
  • Method Details

    • noOp

      static TableEditor noOp(TableId id)
      Create a new editor that does nothing.
      Parameters:
      id - the table's identifier; may not be null
      Returns:
      the editor; never null
    • tableId

      TableId tableId()
      Get the identifier for this table.
      Returns:
      the table identifier; may be null if not set
    • tableId

      TableEditor tableId(TableId tableId)
      Set the table identifier.
      Parameters:
      tableId - the table identifier
      Returns:
      this editor so callers can chain methods together
    • columns

      List<Column> columns()
      Get the definitions for the columns in this table. The resulting list should not be modified directly; instead, the column definitions should be defined with addColumns(Column...), addColumns(Iterable), setColumns(Column...), setColumns(Iterable), or removeColumn(String).
      Returns:
      the ordered list of definitions; never null
    • columnNames

      default List<String> columnNames()
      Get the names of the columns in this table. The resulting list should not be modified directly; instead, the column definitions should be defined with addColumns(Column...), addColumns(Iterable), setColumns(Column...), setColumns(Iterable), or removeColumn(String).
      Returns:
      the ordered list of column names; never null
    • columnWithName

      Column columnWithName(String name)
      Get the definition for the column in this table with the supplied name. The case of the supplied name does not matter.
      Parameters:
      name - the case-insensitive name of the column
      Returns:
      the column definition, or null if there is no column with the given name
    • primaryKeyColumnNames

      List<String> primaryKeyColumnNames()
      The list of column names that make up the primary key for this table. The resulting list should not be modified directly; instead, the set of primary key names should be defined with setPrimaryKeyNames(String...).
      Returns:
      the list of column names that make up the primary key; never null but possibly empty
    • hasPrimaryKey

      default boolean hasPrimaryKey()
      Determine whether this table has a primary key.
      Returns:
      true if this table has at least one primary key column, or false if there are no primary key columns
    • addColumn

      default TableEditor addColumn(Column column)
      Add one columns to this table, regardless of the position of the supplied columns. However, if an existing column definition matches a supplied column, the new column definition will replace the existing column definition.
      Parameters:
      column - the definition for the column to be added
      Returns:
      this editor so callers can chain methods together
    • addColumns

      TableEditor addColumns(Column... columns)
      Add one or more columns to this table, regardless of the position of the supplied columns. However, if an existing column definition matches a supplied column, the new column definition will replace the existing column definition.
      Parameters:
      columns - the definitions for the columns to be added
      Returns:
      this editor so callers can chain methods together
    • addColumns

      TableEditor addColumns(Iterable<Column> columns)
      Add one or more columns to the end of this table's list of columns, regardless of the position of the supplied columns. However, if an existing column definition matches a supplied column, the new column definition will replace the existing column definition.
      Parameters:
      columns - the definitions for the columns to be added
      Returns:
      this editor so callers can chain methods together
    • setColumns

      TableEditor setColumns(Column... columns)
      Set this table's column definitions. The table's primary key columns may be removed as a result of this method if they refer to columns that are not in the supplied list of column definitions.
      Parameters:
      columns - the definitions for the columns to be added
      Returns:
      this editor so callers can chain methods together
    • setColumns

      TableEditor setColumns(Iterable<Column> columns)
      Set this table's column definitions. The table's primary key columns may be removed as a result of this method if they refer to columns that are not in the supplied list of column definitions.
      Parameters:
      columns - the definitions for the columns to be added
      Returns:
      this editor so callers can chain methods together
    • removeColumn

      TableEditor removeColumn(String columnName)
      Remove the column with the given name. This method does nothing if no such column exists.
      Parameters:
      columnName - the name of the column to be removed
      Returns:
      this editor so callers can chain methods together
    • updateColumn

      TableEditor updateColumn(Column column)
      Update the column with the given name. The existing column definition with the name as the column provided is replaced with the new one.
      Parameters:
      column - the new column definition
      Returns:
      this editor so callers can chain methods together
    • reorderColumn

      TableEditor reorderColumn(String columnName, String afterColumnName)
      Reorder the column with the given name to be positioned after the designated column. If afterColumnName is null, the column will be moved to the first column.
      Parameters:
      columnName - the name of the column to be removed
      afterColumnName - the name of the column after which the moved column is to be positioned; may be null if the column is to be moved to the first column
      Returns:
      this editor so callers can chain methods together
    • renameColumn

      TableEditor renameColumn(String existingName, String newName)
      Rename the column with the given name to the new specified name.
      Parameters:
      existingName - the existing name of the column to be renamed; may not be null
      newName - the new name of the column; may not be null
      Returns:
      this editor so callers can chain methods together
    • setPrimaryKeyNames

      TableEditor setPrimaryKeyNames(String... pkColumnNames)
      Set the columns that make up this table's primary key.
      Parameters:
      pkColumnNames - the names of this tables columns that make up the primary key
      Returns:
      this editor so callers can chain methods together
      Throws:
      IllegalArgumentException - if a name does not correspond to an existing column
    • setPrimaryKeyNames

      TableEditor setPrimaryKeyNames(List<String> pkColumnNames)
      Set the columns that make up this table's primary key.
      Parameters:
      pkColumnNames - the names of this tables columns that make up the primary key
      Returns:
      this editor so callers can chain methods together
      Throws:
      IllegalArgumentException - if a name does not correspond to an existing column
    • setUniqueValues

      TableEditor setUniqueValues()
      Sets this table's primary key to contain all columns, ensuring that all values are unique within the table. This is analogous to calling setPrimaryKeyNames(columnNames()) except that the primary key is updated when columns are added or removed.
      Returns:
      this editor so callers can chain methods together
      Throws:
      IllegalArgumentException - if a name does not correspond to an existing column
    • setDefaultCharsetName

      TableEditor setDefaultCharsetName(String charsetName)
      Set the name of the character set that should be used by default in the columns that require a character set but have not defined one.
      Parameters:
      charsetName - the name of the character set that should be used by default
      Returns:
      this editor so callers can chain methods together
    • setComment

      TableEditor setComment(String comment)
      Set the comment of the table
      Parameters:
      comment - table comment
      Returns:
      this editor so callers can chain methods together
    • hasDefaultCharsetName

      boolean hasDefaultCharsetName()
      Determine if a default character set has been set on this table.
      Returns:
      true if this has a default character set, or false if one has not yet been set
    • hasComment

      boolean hasComment()
      Determine if a comment has been set on this table.
      Returns:
      true if this has a comment, or false if one has not yet been set
    • hasUniqueValues

      boolean hasUniqueValues()
      Determine whether this table's primary key contains all columns (via setUniqueValues()) such that all rows within the table are unique.
      Returns:
      true if setUniqueValues() was last called on this table, or false otherwise
    • attributes

      List<Attribute> attributes()
      Get the definitions for the attributes in this table. The resulting list should not be modified directly; instead, the attributes definitions should be defined with addAttribute(Attribute) or removeAttribute(String).
      Returns:
      the list of attribute definitions; never null
    • attributeWithName

      Attribute attributeWithName(String attributeName)
      Get the definition for the attribute in this table with the supplied name. The case of the supplied name does not matter.
      Parameters:
      attributeName - the attribute name
      Returns:
      the attribute definition; or null if no attribute exists with the given name
    • addAttribute

      TableEditor addAttribute(Attribute attribute)
      Add a new attribute to this table.
      Parameters:
      attribute - the definition for the attribute to be added
      Returns:
      this editor so callers can chain methods together
    • addAttributes

      TableEditor addAttributes(List<Attribute> attributes)
      Add attributes to this table.
      Parameters:
      attributes - the list of attribute definitions to be added
      Returns:
      this editor so callers can chain methods together
    • removeAttribute

      TableEditor removeAttribute(String attributeName)
      Remove an attribute from this table.
      Parameters:
      attributeName - the name of the attribute to be removed
      Returns:
      this editor so callers can chain methods togethe
    • create

      Table create()
      Obtain an immutable table definition representing the current state of this editor. This editor can be reused after this method, since the resulting table definition no longer refers to any of the data used in this editor.
      Returns:
      the immutable table definition; never null