Class TableMetaData

java.lang.Object
org.tentackle.sql.metadata.TableMetaData

public class TableMetaData extends Object
Database metadata for a table that is part of the model.
Author:
harald
  • Constructor Details

    • TableMetaData

      public TableMetaData(ModelMetaData modelMetaData, String modelTableName)
      Creates a table metadata instance.
      Parameters:
      modelMetaData - the model this table belongs to
      modelTableName - the table name used in the model
  • Method Details

    • setupTableFromMetaData

      public void setupTableFromMetaData(DatabaseMetaData metaData, String[] schemas, String schemaPattern, String tablePattern) throws SQLException
      Sets up the table, its columns, indexes and foreign keys from the database metadata.

      The method is idempotent: any state left over from a previous attempt is discarded. This is essential because the caller retries with different name patterns and metadata sources until the table is found (see Backend#getTableMetaData), and a failed attempt may already have collected some columns.

      Parameters:
      metaData - the database metadata
      schemas - valid schemas to scan, null if all
      schemaPattern - the schema (null if none, "" if without schema)
      tablePattern - the table pattern
      Throws:
      SQLException - if processing the metadata failed
      BackendException - if the metadata is inconsistent
    • getModelMetaData

      public ModelMetaData getModelMetaData()
      Gets the model this table belongs to.
      Returns:
      the model
    • getModelTableName

      public String getModelTableName()
      Gets the table name used in the model.
      Returns:
      the model's table name
    • getSchemaName

      public String getSchemaName()
      Gets the database schema name.
      The name is returned as reported by the database, which may be uppercase (Oracle, for example).
      Returns:
      the schema, null if none
    • getTableName

      public String getTableName()
      Gets the database table name.
      The name is returned as reported by the database, which may be uppercase (Oracle, for example).
      Returns:
      the table name (without schema)
    • getFullTableName

      public String getFullTableName()
      Gets the database table name with optional schema name prepended.
      The name is returned as reported by the database, which may be uppercase (Oracle, for example).
      Returns:
      the full table name
    • getComment

      public String getComment()
      Gets the comment.
      Returns:
      the comment, null if none
    • setComment

      public void setComment(String comment)
      Sets the comment.
      Parameters:
      comment - the comment, null if none
    • getColumns

      public Collection<ColumnMetaData> getColumns()
      Gets the metadata for columns.
      Returns:
      the columns
    • getColumnByName

      public ColumnMetaData getColumnByName(String columnName)
      Gets a column by its column name.
      Parameters:
      columnName - the column name
      Returns:
      the column, null if no such column
    • getIndexes

      public Collection<IndexMetaData> getIndexes()
      Gets the metadata for indexes.
      Returns:
      the indexes
    • getForeignKeys

      public Collection<ForeignKeyMetaData> getForeignKeys()
      Gets the foreign keys.
      Returns:
      the foreign keys
    • validate

      public void validate()
      Validates and post-processes the table data.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object