Class ValidatorImpl

java.lang.Object
org.apache.openjpa.validation.AbstractValidator
org.apache.openjpa.persistence.validation.ValidatorImpl
All Implemented Interfaces:
Validator

public class ValidatorImpl extends AbstractValidator
  • 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

      public ValidatorImpl(Configuration conf)
    • 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

      public void addValidationGroup(String validationGroupName, Class<?>... vgs)
      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

      public void addValidationGroup(Integer event, Class<?>... validationGroup)
      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

      public void addValidationGroup(String validationGroupName, String group)
      Add the validation group(s) for the specified event. Event definitions are defined in LifecycleEvent
      Parameters:
      event -
      group -
    • getValidationGroup

      public Class<?>[] getValidationGroup(Integer event)
      Return the validation groups to be validated for a specified event
      Parameters:
      event - Lifecycle event id
      Returns:
      An array of validation groups
    • isValidating

      public boolean isValidating(Integer event)
      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

      public jakarta.validation.metadata.BeanDescriptor getConstraintsForClass(Class<?> cls)
      Returns the validation constraints for the specified class
      Parameters:
      cls - Class for which constraints to return
      Returns:
      The validation bean descriptor
    • validate

      public <T> ValidationException validate(T arg0, int event)
      Validates a given instance
      Specified by:
      validate in interface Validator
      Specified by:
      validate in class AbstractValidator
      Type Parameters:
      T - The instance to validate
      Parameters:
      arg0 - The class, of type T to validate
      event - The event id
      Returns:
      ValidationException if the validator produces one or more constraint violations.
    • validateProperty

      public <T> ValidationException validateProperty(T arg0, String property, int event)
      Validates a property of a given instance
      Specified by:
      validateProperty in interface Validator
      Specified by:
      validateProperty in class AbstractValidator
      Type Parameters:
      T - The instance to validate
      Parameters:
      arg0 - The property to validate
      property - The property to validate
      event - The event id
      Returns:
      ValidationException if the validator produces one or more constraint violations.
    • validateValue

      public <T> ValidationException validateValue(Class<T> arg0, String arg1, Object arg2, int event)
      Validates a value based upon the constraints applied to a given class attribute.
      Specified by:
      validateValue in interface Validator
      Specified by:
      validateValue in class AbstractValidator
      Type Parameters:
      T - The instance type to base validation upon
      Parameters:
      arg0 - The class of type T to validate
      arg1 - The property to validate
      arg2 - The property value to validate
      event - 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 interface Validator
      Overrides:
      validating in class AbstractValidator
      Type Parameters:
      T -
      Parameters:
      arg0 - Type being validated
      event - event type
      Returns:
      true if validation is active for the specified event