Interface ValueAttributeDefinition<T>

Type Parameters:
T - the value type
All Superinterfaces:
AttributeDefinition<T>
All Known Subinterfaces:
ColumnDefinition<T>, TransientAttributeDefinition<T>

public sealed interface ValueAttributeDefinition<T> extends AttributeDefinition<T> permits ColumnDefinition<T>, TransientAttributeDefinition<T> (not exhaustive)
Defines an Attribute that holds concrete values (String, Integer, BigDecimal, etc.) requiring type-specific validation, formatting, and constraints.

Contrast with ForeignKeyDefinition which holds Entity references and delegates formatting to the referenced entity's stringFactory.

See Also:
  • Field Details

    • TRIM_STRINGS

      static final PropertyValue<Boolean> TRIM_STRINGS
      Specifies whether String values should be trimmed by default
      • Value type: Boolean
      • Default value: true
      See Also:
  • Method Details

    • nullable

      boolean nullable()
      Returns:
      true if null is a valid value for this attribute
    • maximum

      Optional<Number> maximum()
      Returns:
      the maximum allowed value for this attribute, an empty Optional if none is defined, only applicable to numerical attributes
    • minimum

      Optional<Number> minimum()
      Returns:
      the minimum allowed value for this attribute, an empty Optional if none is defined, only applicable to numerical attributes
    • maximumLength

      int maximumLength()
      Returns:
      the maximum length of this attribute value, -1 is returned if the maximum length is undefined, this only applies to String (varchar) based attributes
    • trim

      boolean trim()
      Returns:
      if string values should be trimmed, this applies to String (varchar) based attributes
    • validItem

      boolean validItem(@Nullable T value)
      Validates the given value against the valid items for this attribute. Always returns true if this is not an item based attribute.
      Parameters:
      value - the value to validate
      Returns:
      true if the given value is a valid item for this attribute
      See Also:
    • items

      List<Item<T>> items()
      Returns the valid items for this attribute or an empty list in case this is not an item based attribute
      Returns:
      an unmodifiable view of the valid items for this attribute
    • hasDefaultValue

      boolean hasDefaultValue()
      Returns:
      true if a default value has been set for this attribute
    • defaultValue

      @Nullable T defaultValue()
      Returns:
      the default value for this attribute, if no default value has been set null is returned
      See Also:
    • validate

      void validate(Entity entity, boolean nullable)
      Validates the value of this attribute as found in the given entity.

      Note: When validating non-nullable attributes during entity insertion (when the entity does not exist), null values are allowed for:

      • Columns with default values - the database will provide the default value
      • Generated primary key columns - the database will generate the key value
      Parameters:
      entity - the entity containing the value to validate
      nullable - true if null values are allowed in this validation context, false if null should trigger a NullValidationException
      Throws:
      ValidationException - in case of an invalid value