Interface ColumnDefinition<T>

Type Parameters:
T - the underlying type
All Superinterfaces:
AttributeDefinition<T>, ValueAttributeDefinition<T>

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

ColumnDefinition extends ValueAttributeDefinition 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 Invoice {
	EntityType TYPE = DOMAIN.entityType("chinook.invoice");

	Column<Long> ID = TYPE.longColumn("id");
	Column<LocalDate> DATE = TYPE.localDateColumn("invoicedate");
	Column<String> BILLINGCITY = TYPE.stringColumn("billingcity");
	Column<BigDecimal> TOTAL = TYPE.bigDecimalColumn("total");
	Column<LocalDateTime> INSERT_TIME = TYPE.localDateTimeColumn("insert_time");
}

EntityDefinition invoice() {
	return Invoice.TYPE.as()
					.attributes(
									// Primary key with auto-generation
									Invoice.ID.as()
													.primaryKey()
													.generator(Generator.identity()),

									// Required column
									Invoice.DATE.as()
													.column()
													.caption("Date")
													.nullable(false),

									// String column with length constraint
									Invoice.BILLINGCITY.as()
													.column()
													.caption("Billing city")
													.maximumLength(40),

									// Decimal column with precision and range validation,
									// the database providing a default value
									Invoice.TOTAL.as()
													.column()
													.caption("Total")
													.nullable(false)
													.minimum(0)
													.fractionDigits(2)
													.withDefault(true),

									// Audit column (database-managed)
									Invoice.INSERT_TIME.as()
													.column()
													.caption("Inserted")
													.insertable(false)  // Not included in INSERT
													.updatable(false)   // Not included in UPDATE
													.withDefault(true)) // Database provides a default 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).
    • generated

      boolean generated()
      Returns:
      true if the value of this column is generated.
      See Also:
    • generator

      Column.Generator<T> generator()
      Returns:
      the Column.Generator used to populate the value of this column
      Throws:
      IllegalStateException - in case a generator is not available
      See Also:
    • converter

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

      int keyIndex()
      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.
    • withDefault

      boolean withDefault()
      Returns:
      true if the underlying database 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, Database database) throws SQLException
      Fetches a value for this column from a ResultSet
      Parameters:
      resultSet - the ResultSet
      index - this columns index in the result
      database - the Database providing the default value getters
      Returns:
      a single value fetched from the given ResultSet
      Throws:
      SQLException - in case of an exception
    • get

      @Nullable T get(ResultSet resultSet, Database database) throws SQLException
      Fetches a value for this column from a ResultSet by name
      Parameters:
      resultSet - the ResultSet
      database - the Database providing the default value getters
      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, Database database) 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
      database - the Database providing the default parameter setters
      Throws:
      SQLException - in case of an exception