Interface AttributeDefinition<T>

Type Parameters:
T - the underlying type
All Known Subinterfaces:
ColumnDefinition<T>, DerivedAttributeDefinition<T>, ForeignKeyDefinition, TransientAttributeDefinition<T>, ValueAttributeDefinition<T>

public sealed interface AttributeDefinition<T> permits DerivedAttributeDefinition<T>, ForeignKeyDefinition, ValueAttributeDefinition<T> (not exhaustive)
Defines an Attribute configuration including validation, formatting, and behavior settings.

AttributeDefinition instances specify how attributes behave within entities, including:

  • Display properties (caption, description, format patterns)
  • Validation rules (nullable, min/max values, length constraints)
  • Default values and value generation
  • UI behavior (items for combo boxes, comparators for sorting)
  • Data conversion and formatting

AttributeDefinitions are created using the builder pattern through attribute definers:

 public class Store extends DefaultDomain {

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

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

     void defineProduct() {
         Product.TYPE.define(
                 Product.ID.define()
                     .primaryKey()
                     .generator(Generator.identity())
                     .caption("Product ID"),

                 Product.NAME.define()
                     .column()
                     .caption("Product Name")
                     .nullable(false)
                     .maximumLength(100)
                     .description("The name of the product"),

                 Product.DESCRIPTION.define()
                     .column()
                     .caption("Description")
                     .maximumLength(500)
                     .nullable(true),

                 Product.PRICE.define()
                     .column()
                     .caption("Price")
                     .nullable(false)
                     .minimum(BigDecimal.ZERO)
                     .maximum(new BigDecimal("99999.99"))
                     .fractionDigits(2)
                     .defaultValue(BigDecimal.ZERO),

                 Product.CATEGORY.define()
                     .column()
                     .caption("Category")
                     .nullable(false)
                     .items(List.of(
                         Item.item("ELECTRONICS", "Electronics"),
                         Item.item("CLOTHING", "Clothing"),
                         Item.item("BOOKS", "Books"),
                         Item.item("HOME", "Home & Garden"))),

                 Product.ACTIVE.define()
                     .column()
                     .caption("Active")
                     .nullable(false)
                     .defaultValue(true),

                 Product.CREATED_DATE.define()
                     .column()
                     .caption("Created")
                     .nullable(false)
                     .withDefault(true) // Database sets this
                     .updatable(false))
             .build();
     }
 }
See Also:
  • Field Details

    • DEFAULT_FRACTION_DIGITS

      static final int DEFAULT_FRACTION_DIGITS
      The default maximum fraction digits for floating point numbers
      See Also:
    • FRACTION_DIGITS

      static final PropertyValue<Integer> FRACTION_DIGITS
      Specifies the default maximum number of fraction digits for double property values
      Note that values are rounded when set.
      • Value type: Integer
      • Default value: 10
    • ROUNDING_MODE

      static final PropertyValue<RoundingMode> ROUNDING_MODE
      Specifies the default rounding mode used for decimal property values
      See Also:
    • NUMBER_GROUPING

      static final PropertyValue<Boolean> NUMBER_GROUPING
      Specifies whether number grouping is used by default
      • Value type: Boolean
      • Default value: false
    • GROUPING_SEPARATOR

      static final PropertyValue<Character> GROUPING_SEPARATOR
      Specifies the default number grouping separator
      • Value type: Character
      • Default value: The grouping separator for the default locale
    • DECIMAL_SEPARATOR

      static final PropertyValue<Character> DECIMAL_SEPARATOR
      Specifies the default number decimal separator.
      • Value type: Character
      • Default value: The decimal separator for the default locale
    • USE_LEXICAL_STRING_COMPARATOR

      static final PropertyValue<Boolean> USE_LEXICAL_STRING_COMPARATOR
      Specifies whether String values should use a lexical comparator by default
      • Value type: Boolean
      • Default value: true
    • MNEMONIC_RESOURCE_SUFFIX

      static final String MNEMONIC_RESOURCE_SUFFIX
      The suffix used for the mnemonic resource key.
      • name=Name
      • name.mnemonic=N
      See Also:
    • DESCRIPTION_RESOURCE_SUFFIX

      static final String DESCRIPTION_RESOURCE_SUFFIX
      The suffix used for the description resource key.
      • name=Name
      • name.description=The customer name
      See Also:
  • Method Details

    • attribute

      Attribute<T> attribute()
      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.
      Returns:
      the attribute this definition is based on
    • entityType

      EntityType entityType()
      Returns:
      the type of the entity this attribute is associated with
    • caption

      String caption()
      Returns:
      the caption or the attribute name if no caption has been specified
      See Also:
    • description

      Optional<String> description()
      Returns:
      a String describing this attribute or an empty Optional if none is available
    • format

      String format(@Nullable T value)
      Returns a string representation of the given value formatted with this attributes format. If no format is available Object.toString() is used. By default, null values result in an empty string.
      Parameters:
      value - the value to format.
      Returns:
      the value formatted as a string
    • hidden

      boolean hidden()
      Returns:
      true if this attribute should be hidden in table views
    • mnemonic

      char mnemonic()
      Returns the mnemonic associated with this attribute.
      Returns:
      the mnemonic to use when creating a label for this attribute, 0 meaning no mnemonic
    • comparator

      Comparator<T> comparator()
      Returns:
      the Comparator to use when comparing values associated with this attribute
    • derived

      boolean derived()
      The value of a derived attribute can not be set, as it's value is derived from other values
      Returns:
      true if the value of this attribute is derived from one or more values
    • fractionDigits

      int fractionDigits()
      Returns:
      the maximum number of fraction digits to use for this attribute value, -1 if this attribute is not based on Types.DOUBLE or Types.DECIMAL
      See Also:
    • roundingMode

      RoundingMode roundingMode()
      Returns:
      the rounding mode to use when working with decimal values
      See Also:
    • format

      Optional<Format> format()
      Returns the Format used when presenting values for this attribute, an empty Optional if none has been specified.
      Returns:
      the Format object used to format the value of attributes when being presented
    • dateTimePattern

      Optional<String> dateTimePattern()
      Returns the date time format pattern used when presenting and inputting values for this attribute.
      Returns:
      the date/time format pattern
    • dateTimeFormatter

      Optional<DateTimeFormatter> dateTimeFormatter()
      Returns the date time formatter used when presenting and inputting values for this attribute.
      Returns:
      the DateTimeFormatter for this attribute or an empty Optional if this is not a date/time based attribute