Class ValidatorImpl
java.lang.Object
org.apache.openjpa.validation.AbstractValidator
org.apache.openjpa.persistence.validation.ValidatorImpl
- All Implemented Interfaces:
Validator
-
Constructor Summary
ConstructorDescriptionDefault constructor.ValidatorImpl
(jakarta.validation.ValidatorFactory validatorFactory, jakarta.persistence.ValidationMode mode) Type-specific constructor Returns an Exception if a Validator could not be created.ValidatorImpl
(Configuration conf) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addValidationGroup
(Integer event, Class<?>... validationGroup) Add a validation group for a specified event.void
addValidationGroup
(String validationGroupName, Class<?>... vgs) Add a validation group for the specific property.void
addValidationGroup
(String validationGroupName, String group) Add the validation group(s) for the specified event.jakarta.validation.metadata.BeanDescriptor
getConstraintsForClass
(Class<?> cls) Returns the validation constraints for the specified classClass<?>[]
getValidationGroup
(Integer event) Return the validation groups to be validated for a specified eventboolean
isValidating
(Integer event) Returns whether the Validator is validating for the specified event.validate
(T arg0, int event) Validates a given instancevalidateProperty
(T arg0, String property, int event) Validates a property of a given instancevalidateValue
(Class<T> arg0, String arg1, Object arg2, int event) Validates a value based upon the constraints applied to a given class attribute.<T> boolean
validating
(T arg0, int event) Returns whether validation is active for the given event.
-
Constructor Details
-
ValidatorImpl
public ValidatorImpl()Default constructor. Builds a default validator factory, if available and creates the validator. Returns an Exception if a Validator could not be created. -
ValidatorImpl
-
ValidatorImpl
public ValidatorImpl(jakarta.validation.ValidatorFactory validatorFactory, jakarta.persistence.ValidationMode mode) Type-specific constructor Returns an Exception if a Validator could not be created.- Parameters:
validatorFactory
- Instance of validator factory to use. Specify null to use the default factory.mode
- ValdiationMode enum value
-
-
Method Details
-
addValidationGroup
Add a validation group for the specific property. The properties map to a specific lifecycle event. To disable validation for a group, set the validation group to null.- Parameters:
validationGroupName
-vgs
-
-
addValidationGroup
Add a validation group for a specified event. Event definitions are defined in LifecycleEvent. To disable validation for a group, set the validation group to null.- Parameters:
event
-validationGroup
-
-
addValidationGroup
Add the validation group(s) for the specified event. Event definitions are defined in LifecycleEvent- Parameters:
event
-group
-
-
getValidationGroup
Return the validation groups to be validated for a specified event- Parameters:
event
- Lifecycle event id- Returns:
- An array of validation groups
-
isValidating
Returns whether the Validator is validating for the specified event. Based on whether validation groups are specified for the event.- Parameters:
event
- the event to check for validation- Returns:
- returns true if validating for this particular event
-
getConstraintsForClass
Returns the validation constraints for the specified class- Parameters:
cls
- Class for which constraints to return- Returns:
- The validation bean descriptor
-
validate
Validates a given instance- Specified by:
validate
in interfaceValidator
- Specified by:
validate
in classAbstractValidator
- Type Parameters:
T
- The instance to validate- Parameters:
arg0
- The class, of type T to validateevent
- The event id- Returns:
- ValidationException if the validator produces one or more constraint violations.
-
validateProperty
Validates a property of a given instance- Specified by:
validateProperty
in interfaceValidator
- Specified by:
validateProperty
in classAbstractValidator
- Type Parameters:
T
- The instance to validate- Parameters:
arg0
- The property to validateproperty
- The property to validateevent
- The event id- Returns:
- ValidationException if the validator produces one or more constraint violations.
-
validateValue
Validates a value based upon the constraints applied to a given class attribute.- Specified by:
validateValue
in interfaceValidator
- Specified by:
validateValue
in classAbstractValidator
- Type Parameters:
T
- The instance type to base validation upon- Parameters:
arg0
- The class of type T to validatearg1
- The property to validatearg2
- The property value to validateevent
- The event id- Returns:
- ValidationException if the validator produces one or more constraint violations.
-
validating
public <T> boolean validating(T arg0, int event) Returns whether validation is active for the given event.- Specified by:
validating
in interfaceValidator
- Overrides:
validating
in classAbstractValidator
- Type Parameters:
T
-- Parameters:
arg0
- Type being validatedevent
- event type- Returns:
- true if validation is active for the specified event
-