Class TableDefinition


  • public final class TableDefinition
    extends java.lang.Object
    The schema of a table.
    • Constructor Detail

      • TableDefinition

        public TableDefinition​(TableName tableName,
                               java.util.List<TableDefinition.Column> columns,
                               Persistence persistence)
        Creates a new TableDefinition with the given columns and persistence.
        Parameters:
        tableName - The table name.
        columns - The columns.
        persistence - The persistence.
      • TableDefinition

        public TableDefinition​(TableName tableName,
                               java.util.List<TableDefinition.Column> columns)
        Creates a new TableDefinition of permanent persistence with the given columns.
        Parameters:
        tableName - The table name.
        columns - The columns.
      • TableDefinition

        public TableDefinition​(TableName tableName,
                               Persistence persistence)
        Creates a new, empty TableDefinition with the given persistence.
        Parameters:
        tableName - The table name.
        persistence - The persistence.
      • TableDefinition

        public TableDefinition​(TableName tableName)
        Creates a new, empty TableDefinition of permanent persistence.
        Parameters:
        tableName - The table name.
    • Method Detail

      • getColumns

        public java.util.List<TableDefinition.Column> getColumns()
        Returns all columns.
        Returns:
        The columns.
      • getColumn

        public TableDefinition.Column getColumn​(int position)
        Returns a column by position.
        Parameters:
        position - The position starting at 0.
        Returns:
        The column.
      • getColumnByName

        public java.util.Optional<TableDefinition.Column> getColumnByName​(java.lang.String columnName)
        Retrieves the column named "columnName", if it exists.
        Parameters:
        columnName - The name of the column to retrieve.
        Returns:
        The column if it exists.
      • getColumnByName

        public java.util.Optional<TableDefinition.Column> getColumnByName​(Name columnName)
        Retrieves the column named "columnName", if it exists.
        Parameters:
        columnName - The name of the column to retrieve.
        Returns:
        The column if it exists.
      • getColumnPositionByName

        public java.util.OptionalInt getColumnPositionByName​(java.lang.String columnName)
        Retrieves the column position of a column named "columnName", if it exists.
        Parameters:
        columnName - The name of the column to retrieve.
        Returns:
        The position of the column if it exists.
      • getColumnPositionByName

        public java.util.OptionalInt getColumnPositionByName​(Name columnName)
        Retrieves the column position of a column named "columnName", if it exists.
        Parameters:
        columnName - The name of the column to retrieve.
        Returns:
        The position of the column if it exists.
      • getColumnCount

        public int getColumnCount()
        Returns the number of columns.
        Returns:
        The number of columns.
      • getTableName

        public TableName getTableName()
        Returns the name of the table.
        Returns:
        The table name.
      • setTableName

        public TableDefinition setTableName​(TableName tableName)
        Sets the table name.
        Parameters:
        tableName - The new table name.
        Returns:
        The table definition for method chaining.
      • getPersistence

        public Persistence getPersistence()
        Returns the persistence of the table.
        Returns:
        The persistence.
      • setPersistence

        public TableDefinition setPersistence​(Persistence persistence)
        Sets the table persistence.
        Parameters:
        persistence - The new table persistence.
        Returns:
        The table definition for method chaining.
      • addColumn

        public TableDefinition addColumn​(TableDefinition.Column column)
        Adds a column to the table definition.
        Parameters:
        column - The column to add.
        Returns:
        The table definition for method chaining.
      • addColumn

        public TableDefinition addColumn​(java.lang.String columnName,
                                         SqlType type,
                                         java.lang.String collation,
                                         Nullability nullability)
        Adds a column to the table definition.
        Parameters:
        columnName - Column name.
        type - SQL type.
        collation - Collation (used for sorting and equality checks).
        nullability - Whether the column should allow null values.
        Returns:
        The table definition for method chaining.
      • addColumn

        public TableDefinition addColumn​(java.lang.String columnName,
                                         SqlType type,
                                         java.lang.String collation)
        Adds a column to the table definition.
        Parameters:
        columnName - Column name.
        type - SQL type.
        collation - Collation (used for sorting and equality checks).
        Returns:
        The table definition for method chaining.
      • addColumn

        public TableDefinition addColumn​(java.lang.String columnName,
                                         SqlType type,
                                         Nullability nullability)
        Adds a column to the table definition.
        Parameters:
        columnName - Column name.
        type - SQL type.
        nullability - Whether the column should allow null values.
        Returns:
        The table definition for method chaining.
      • addColumn

        public TableDefinition addColumn​(java.lang.String columnName,
                                         SqlType type)
        Adds a column to the table definition.
        Parameters:
        columnName - Column name.
        type - SQL type.
        Returns:
        The table definition for method chaining.