Record Class Table

java.lang.Object
java.lang.Record
io.bloviate.db.Table
Record Components:
name - the table name
primaryKey - the primary key definition, may be null if no primary key exists
columns - the list of all columns in this table
foreignKeys - the list of foreign key relationships from this table to others

public record Table(String name, PrimaryKey primaryKey, List<Column> columns, List<ForeignKey> foreignKeys) extends Record
Represents a database table with its columns, keys, and relationships.

This immutable record encapsulates all metadata for a single database table, including its columns, primary key, and foreign key relationships. It provides utility methods for generating SQL statements and filtering columns based on their characteristics.

Tables are typically discovered through database metadata analysis and are used by TableFiller to generate appropriate data for each column.

Author:
Tim Veil
See Also:
  • Constructor Details

    • Table

      public Table(String name, PrimaryKey primaryKey, List<Column> columns, List<ForeignKey> foreignKeys)
      Creates an instance of a Table record class.
      Parameters:
      name - the value for the name record component
      primaryKey - the value for the primaryKey record component
      columns - the value for the columns record component
      foreignKeys - the value for the foreignKeys record component
  • Method Details

    • insertString

      public String insertString()
      Generates an SQL INSERT statement template for this table.

      Creates a parameterized INSERT statement using question mark placeholders for all non-auto-increment columns. Auto-increment columns are excluded as they are populated automatically by the database.

      Returns:
      a parameterized SQL INSERT statement string
    • filteredColumns

      public List<Column> filteredColumns()
      Returns a list of columns excluding auto-increment columns.

      This filtered list is used for INSERT operations since auto-increment columns should not have values explicitly provided.

      Returns:
      a new list containing only non-auto-increment columns
    • findColumn

      public Column findColumn(String name)
      Finds a column by name using case-insensitive comparison.
      Parameters:
      name - the name of the column to find
      Returns:
      the column with the specified name, or null if not found
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • primaryKey

      public PrimaryKey primaryKey()
      Returns the value of the primaryKey record component.
      Returns:
      the value of the primaryKey record component
    • columns

      public List<Column> columns()
      Returns the value of the columns record component.
      Returns:
      the value of the columns record component
    • foreignKeys

      public List<ForeignKey> foreignKeys()
      Returns the value of the foreignKeys record component.
      Returns:
      the value of the foreignKeys record component