Interface ColumnDefinition<T>

Type Parameters:
T - the underlying type
All Superinterfaces:
AttributeDefinition<T>
All Known Subinterfaces:
AuditColumnDefinition<T>

public interface ColumnDefinition<T> extends AttributeDefinition<T>
Specifies an attribute definition based on a table column.

ColumnDefinition extends AttributeDefinition with column-specific configuration such as primary key properties, SQL expressions, insertable/updatable flags, and database value conversion logic.

Column definitions are created through the column builder API:

interface Product {
    EntityType TYPE = DOMAIN.entityType("store.product");

    Column<Integer> ID = TYPE.integerColumn("id");
    Column<String> NAME = TYPE.stringColumn("name");
    Column<BigDecimal> PRICE = TYPE.bigDecimalColumn("price");
    Column<Boolean> ACTIVE = TYPE.booleanColumn("active");
    Column<LocalDateTime> CREATED_DATE = TYPE.localDateTimeColumn("created_date");
}

Product.TYPE.define(
        // Primary key with auto-generation
        Product.ID.define()
            .primaryKey()
            .keyGenerator(KeyGenerator.identity()),

        // Required string column with length constraint
        Product.NAME.define()
            .column()
            .nullable(false)
            .maximumLength(100),

        // Decimal column with precision and range validation
        Product.PRICE.define()
            .column()
            .nullable(false)
            .minimumValue(BigDecimal.ZERO)
            .maximumValue(new BigDecimal("99999.99"))
            .maximumFractionDigits(2),

        // Boolean column with database mapping
        Product.ACTIVE.define()
            .booleanColumn(String.class, "Y", "N") // Maps Y/N to true/false
            .defaultValue(true),

        // Audit column (database-managed)
        Product.CREATED_DATE.define()
            .column()
            .insertable(false)  // Not included in INSERT
            .updatable(false)   // Not included in UPDATE
            .columnHasDefaultValue(true)) // Database provides value
    .build();
See Also:
  • Method Details

    • attribute

      Column<T> attribute()
      Description copied from interface: AttributeDefinition
      The Attribute this definition is based on, should be unique within an Entity. By default, the Attribute.name() serves as column name for database columns.
      Specified by:
      attribute in interface AttributeDefinition<T>
      Returns:
      the attribute this definition is based on
    • name

      String name()
      Note: returns null when used in a remote connection context.
      Returns:
      the column name
    • expression

      String expression()
      Note: returns null when used in a remote connection context.
      Returns:
      the column expression to use when selecting or the column name if no expression has been set
    • type

      int type()
      Returns:
      the sql data type of the underlying column (Types.
    • converter

      <C> Column.Converter<C,T> converter()
      Note: returns null when used in a remote connection context.
      Type Parameters:
      C - the colum value type
      Returns:
      the Column.Converter for this column.
    • primaryKeyIndex

      int primaryKeyIndex()
      Returns:
      this columns zero based index in the primary key, -1 if this column is not part of a primary key
    • primaryKey

      boolean primaryKey()
      Returns:
      true if this column is part of a primary key
    • groupBy

      boolean groupBy()
      Returns:
      true if this column should be grouped by
    • aggregate

      boolean aggregate()
      Returns:
      true if this column is based on an aggregate function
    • selected

      boolean selected()
      Returns:
      true if this column should be selected by default
    • insertable

      boolean insertable()
      Specifies whether this column is insertable
      Returns:
      true if this column is insertable
    • updatable

      boolean updatable()
      Indicates whether this column is updatable
      Returns:
      true if this column is updatable
    • readOnly

      boolean readOnly()
      Returns:
      true if this column is neither insertable nor updatable.
    • columnHasDefaultValue

      boolean columnHasDefaultValue()
      Returns:
      true if the underlying column has a default value
    • searchable

      boolean searchable()
      Returns:
      true if this column should be included when searching by string
    • get

      @Nullable T get(ResultSet resultSet, int index) throws SQLException
      Fetches a value for this column from a ResultSet
      Parameters:
      resultSet - the ResultSet
      index - this columns index in the result
      Returns:
      a single value fetched from the given ResultSet
      Throws:
      SQLException - in case of an exception
    • set

      void set(PreparedStatement statement, int index, @Nullable T value) throws SQLException
      Sets a parameter for this column in a PreparedStatement
      Parameters:
      statement - the statement
      index - the parameter index
      value - the value to set, may be null
      Throws:
      SQLException - in case of an exception