Interface EntityValidator

All Known Implementing Classes:
DefaultEntityValidator

public interface EntityValidator
Responsible for providing validation for entities.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final PropertyValue<Boolean>
    Specifies whether the default validator performs strict validation or not.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> boolean
    nullable(Entity entity, Attribute<T> attribute)
    Returns true if the value based on the given attribute accepts a null value for the given entity, by default this method simply returns the nullable state of the underlying attribute.
    boolean
    valid(Entity entity)
    Returns true if the given entity contains only valid values.
    void
    validate(Entity entity)
    Checks if the values in the given entity are valid.
    <T> void
    validate(Entity entity, Attribute<T> attribute)
    Checks if the value associated with the give attribute is valid, throws a ValidationException if not
  • Field Details

    • STRICT_VALIDATION

      static final PropertyValue<Boolean> STRICT_VALIDATION
      Specifies whether the default validator performs strict validation or not. By default all non-read-only attribute values are validated if the entity is being inserted (as in, when it does not exist according to Entity.exists()). If the entity exists, only modified values are validated. With strict validation enabled all values are validated, regardless of whether the entity exists or not.
      Value type: Boolean
      Default value: false
  • Method Details

    • nullable

      <T> boolean nullable(Entity entity, Attribute<T> attribute)
      Returns true if the value based on the given attribute accepts a null value for the given entity, by default this method simply returns the nullable state of the underlying attribute.
      Type Parameters:
      T - the value type
      Parameters:
      entity - the entity being validated
      attribute - the attribute
      Returns:
      true if the attribute accepts a null value
    • valid

      boolean valid(Entity entity)
      Returns true if the given entity contains only valid values.
      Parameters:
      entity - the entity
      Returns:
      true if the given entity contains only valid values
    • validate

      void validate(Entity entity) throws ValidationException
      Checks if the values in the given entity are valid. Note that by default, if the entity instance does not exist according to Entity.exists() all values are validated, otherwise only modified values are validated. Use the STRICT_VALIDATION configuration value to change the default behaviour.
      Parameters:
      entity - the entity
      Throws:
      ValidationException - in case of an invalid value
      See Also:
    • validate

      <T> void validate(Entity entity, Attribute<T> attribute) throws ValidationException
      Checks if the value associated with the give attribute is valid, throws a ValidationException if not
      Type Parameters:
      T - the value type
      Parameters:
      entity - the entity to validate
      attribute - the attribute the value is associated with
      Throws:
      ValidationException - if the given value is not valid for the given attribute