Class DefaultEntityValidator

java.lang.Object
is.codion.framework.domain.entity.DefaultEntityValidator
All Implemented Interfaces:
EntityValidator, Serializable

public class DefaultEntityValidator extends Object implements EntityValidator, Serializable
A default EntityValidator implementation providing null validation for attributes marked as not null, item validation for item based attributes, range validation for numerical attributes with max and/or min values specified and string length validation based on the specified max length. This Validator can be extended to provide further validation.
See Also:
  • Field Summary

    Fields inherited from interface is.codion.framework.domain.entity.EntityValidator

    STRICT_VALIDATION
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates a new DefaultEntityValidator
    DefaultEntityValidator(boolean strictValidation)
    Instantiates a new DefaultEntityValidator
  • 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultEntityValidator

      public DefaultEntityValidator()
      Instantiates a new DefaultEntityValidator
      See Also:
    • DefaultEntityValidator

      public DefaultEntityValidator(boolean strictValidation)
      Instantiates a new DefaultEntityValidator
      Parameters:
      strictValidation - true if strict validation should be performed
      See Also:
  • Method Details

    • valid

      public boolean valid(Entity entity)
      Description copied from interface: EntityValidator
      Returns true if the given entity contains only valid values.
      Specified by:
      valid in interface EntityValidator
      Parameters:
      entity - the entity
      Returns:
      true if the given entity contains only valid values
    • nullable

      public <T> boolean nullable(Entity entity, Attribute<T> attribute)
      Description copied from interface: EntityValidator
      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.
      Specified by:
      nullable in interface EntityValidator
      Type Parameters:
      T - the value type
      Parameters:
      entity - the entity being validated
      attribute - the attribute
      Returns:
      true if the attribute accepts a null value
    • validate

      public void validate(Entity entity) throws ValidationException
      Description copied from interface: EntityValidator
      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 EntityValidator.STRICT_VALIDATION configuration value to change the default behaviour.
      Specified by:
      validate in interface EntityValidator
      Parameters:
      entity - the entity
      Throws:
      ValidationException - in case of an invalid value
      See Also:
    • validate

      public <T> void validate(Entity entity, Attribute<T> attribute) throws ValidationException
      Description copied from interface: EntityValidator
      Checks if the value associated with the give attribute is valid, throws a ValidationException if not
      Specified by:
      validate in interface EntityValidator
      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