Module is.codion.framework.domain
Class DefaultEntityValidator
java.lang.Object
is.codion.framework.domain.entity.DefaultEntityValidator
- All Implemented Interfaces:
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.-
Field Summary
Fields inherited from interface is.codion.framework.domain.entity.EntityValidator
STRICT_VALIDATION
-
Constructor Summary
ConstructorDescriptionInstantiates a new DefaultEntityValidatorDefaultEntityValidator
(boolean strictValidation) Instantiates a new DefaultEntityValidator -
Method Summary
Modifier and TypeMethodDescription<T> boolean
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
Returns true if the given entity contains only valid values.void
Checks if the values in the given entity are valid.<T> void
Checks if the value associated with the give attribute is valid, throws a ValidationException if not
-
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
Description copied from interface:EntityValidator
Returns true if the given entity contains only valid values.- Specified by:
valid
in interfaceEntityValidator
- Parameters:
entity
- the entity- Returns:
- true if the given entity contains only valid values
-
nullable
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 interfaceEntityValidator
- Type Parameters:
T
- the value type- Parameters:
entity
- the entity being validatedattribute
- the attribute- Returns:
- true if the attribute accepts a null value
-
validate
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 toEntity.exists()
all values are validated, otherwise only modified values are validated. Use theEntityValidator.STRICT_VALIDATION
configuration value to change the default behaviour.- Specified by:
validate
in interfaceEntityValidator
- Parameters:
entity
- the entity- Throws:
ValidationException
- in case of an invalid value- See Also:
-
validate
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 interfaceEntityValidator
- Type Parameters:
T
- the value type- Parameters:
entity
- the entity to validateattribute
- the attribute the value is associated with- Throws:
ValidationException
- if the given value is not valid for the given attribute
-