Class DefaultDatabaseLengthValidationConfiguration

java.lang.Object
org.faktorips.runtime.validation.DefaultDatabaseLengthValidationConfiguration
All Implemented Interfaces:
IDatabaseLengthValidationConfiguration

public class DefaultDatabaseLengthValidationConfiguration extends Object implements IDatabaseLengthValidationConfiguration
Default configuration for the DatabaseLengthValidation.

It offers a number of with~ methods for a fluent configuration.

  • Field Details

  • Constructor Details

    • DefaultDatabaseLengthValidationConfiguration

      public DefaultDatabaseLengthValidationConfiguration(Locale locale, ResourceBundle resourceBundle)
      Creates a new configuration using the given Locale and ResourceBundle to create validation messages.
      Parameters:
      locale - the locale to be used
      resourceBundle - a resource bundle; it should contain messages for the validation messages in the given locale
    • DefaultDatabaseLengthValidationConfiguration

      public DefaultDatabaseLengthValidationConfiguration(Locale locale)
      Creates a new configuration using the given Locale using the default ResourceBundle for RESOURCE_BUNDLE_NAME.
      Parameters:
      locale - the locale to be used
  • Method Details

    • getLocale

      public Locale getLocale()
      Description copied from interface: IDatabaseLengthValidationConfiguration
      Returns the locale to be used for validation messages.
      Specified by:
      getLocale in interface IDatabaseLengthValidationConfiguration
      Returns:
      the locale to be used for validation messages
    • getResourceBundle

      protected ResourceBundle getResourceBundle()
      Returns the used resource bundle.
      Returns:
      the used resource bundle
    • withTechnicalConstraintViolationMarker

      public DefaultDatabaseLengthValidationConfiguration withTechnicalConstraintViolationMarker(IMarker technicalConstraintViolationMarker)
      Returns this configuration, updated to use the given marker on validation messages.
      Parameters:
      technicalConstraintViolationMarker - a marker to be used on all validation messages created by this configuration
      Returns:
      this configuration, updated to use the given marker on validation messages
    • getTechnicalConstraintViolationMarker

      public IMarker getTechnicalConstraintViolationMarker()
      Description copied from interface: IDatabaseLengthValidationConfiguration
      Returns the marker to be used for validation messages.
      Specified by:
      getTechnicalConstraintViolationMarker in interface IDatabaseLengthValidationConfiguration
      Returns:
      the marker to be used for validation messages
    • withStringLengthConstraint

      public DefaultDatabaseLengthValidationConfiguration withStringLengthConstraint(StringLengthConstraint stringLengthConstraint)
      Returns this configuration, updated to use the given constraint to check String values.
      Parameters:
      stringLengthConstraint - a StringLengthConstraint to be used to check String values
      Returns:
      this configuration, updated to use the given constraint to check String values
    • withStringLengthConstraint

      public DefaultDatabaseLengthValidationConfiguration withStringLengthConstraint(Charset stringEncoding, int maxStringByteLength)
      Returns this configuration, updated to use a new constraint created from the given encoding and length to check String values.
      Parameters:
      stringEncoding - a Charset to be used to convert Strings into their Byte representation
      maxStringByteLength - the maximum number of Bytes a String representation may have
      Returns:
      this configuration, updated to use a new constraint created from the given encoding and length to check String values
      See Also:
    • withStringLengthConstraint

      public DefaultDatabaseLengthValidationConfiguration withStringLengthConstraint(int maxStringByteLength)
      Returns this configuration, updated to use a new constraint created from the given length to check String values in UTF-8.
      Parameters:
      maxStringByteLength - the maximum number of Bytes a String representation in StandardCharsets.UTF_8 may have
      Returns:
      this configuration, updated to use a new constraint created from the given length to check String values in UTF-8
      See Also:
    • getStringLengthConstraint

      public StringLengthConstraint getStringLengthConstraint()
      Description copied from interface: IDatabaseLengthValidationConfiguration
      Returns the constraint to be used to validate String attributes.
      Specified by:
      getStringLengthConstraint in interface IDatabaseLengthValidationConfiguration
      Returns:
      the constraint to be used to validate String attributes
    • withNumericConstraint

      public DefaultDatabaseLengthValidationConfiguration withNumericConstraint(Class<? extends Number> numericDatatype, NumericConstraint numericConstraint)
      Returns this configuration, updated to use the given constraint to check numeric values of the given data type.
      Parameters:
      numericDatatype - a (wrapper) class used for numeric values - primitive types should not be used and are validated with the same settings as their wrapper types.
      numericConstraint - a NumericConstraint to be used to check numeric values
      Returns:
      this configuration, updated to use the given constraint to check numeric values of the given data type
    • withNumericConstraint

      public DefaultDatabaseLengthValidationConfiguration withNumericConstraint(Class<? extends Number> numericDatatype, int precision, int scale)
      Returns this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of the given data type.
      Parameters:
      numericDatatype - a (wrapper) class used for numeric values - primitive types should not be used and are validated with the same settings as their wrapper types.
      precision - the maximum total number of digits usable to represent a number of the given type
      scale - the maximum number of decimal places usable to represent a number of the given type
      Returns:
      this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of the given data type
      See Also:
    • withNumericConstraint

      public DefaultDatabaseLengthValidationConfiguration withNumericConstraint(Class<? extends Number> numericDatatype, int precision)
      Returns this configuration, updated to use a new constraint created from the given precision (and no scale) to check numeric values of the given data type.
      Parameters:
      numericDatatype - a (wrapper) class used for numeric values - primitive types should not be used and are validated with the same settings as their wrapper types.
      precision - the maximum total number of digits usable to represent a number of the given type
      Returns:
      this configuration, updated to use a new constraint created from the given precision (and no scale) to check numeric values of the given data type
      See Also:
    • withNumericConstraintForAllNumbers

      public DefaultDatabaseLengthValidationConfiguration withNumericConstraintForAllNumbers(int precision, int scale)
      Returns this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of any numeric data type.
      Parameters:
      precision - the maximum total number of digits usable to represent a number of the given type
      scale - the maximum number of decimal places usable to represent a number of the given type
      Returns:
      this configuration, updated to use a new constraint created from the given precision and scale to check numeric values of any numeric data type
      See Also:
    • getNumericConstraint

      public NumericConstraint getNumericConstraint(Class<? extends Number> numericDatatype)
      Description copied from interface: IDatabaseLengthValidationConfiguration
      Returns the constraint to be used to validate numeric attributes of the given type.
      Specified by:
      getNumericConstraint in interface IDatabaseLengthValidationConfiguration
      Parameters:
      numericDatatype - a (wrapper) class used for numeric values - primitive types should not be used and are validated with the same settings as their wrapper types.
      Returns:
      the constraint to be used to validate numeric attributes of the given type
    • shouldValidate

      public boolean shouldValidate(PolicyAttribute policyAttribute, IModelObject modelObject)
      Description copied from interface: IDatabaseLengthValidationConfiguration
      Decides whether the given PolicyAttribute should be validated for the given IModelObject.
      Specified by:
      shouldValidate in interface IDatabaseLengthValidationConfiguration
      Parameters:
      policyAttribute - the model type reference for the validated attribute
      modelObject - the model object instance on which the attribute may be validated
      Returns:
      whether validation for the given combination of PolicyAttribute and IModelObject should run
    • withAttributeFilter

      Returns this configuration, updated to use the given predicate to determine which attributes to validate.
      Parameters:
      shouldValidate - a predicate, returning true for attributes that should be validated
      Returns:
      this configuration, updated to use the given predicate to determine which attributes to validate
      See Also:
    • createMessageForStringLengthViolation

      public Message createMessageForStringLengthViolation(PolicyAttribute attribute, IModelObject modelObject, int actualLength, int lengthLimit)
      Description copied from interface: IDatabaseLengthValidationConfiguration
      Creates a message to indicate that the given attribute's value on the given model object exceeds the configured StringLengthConstraint.
      Specified by:
      createMessageForStringLengthViolation in interface IDatabaseLengthValidationConfiguration
      Parameters:
      attribute - the model type reference for the validated attribute
      modelObject - the model object instance on which the attribute was validated
      actualLength - the actual value's length in bytes according to the Charset used in the constraint
      lengthLimit - the exceeded limit, set in the constraint
    • createMessageForPrecisionViolation

      public Message createMessageForPrecisionViolation(PolicyAttribute attribute, IModelObject modelObject, Class<? extends Number> numericDatatype, int actualPrecision, int precisionLimit)
      Description copied from interface: IDatabaseLengthValidationConfiguration
      Creates a message to indicate that the given attribute's value on the given model object exceeds the configured NumericConstraint`s precision.
      Specified by:
      createMessageForPrecisionViolation in interface IDatabaseLengthValidationConfiguration
      Parameters:
      attribute - the model type reference for the validated attribute
      modelObject - the model object instance on which the attribute was validated
      actualPrecision - the actual value's length in digits
      precisionLimit - the exceeded limit, set in the constraint
    • createMessageForScaleViolation

      public Message createMessageForScaleViolation(PolicyAttribute attribute, IModelObject modelObject, Class<? extends Number> numericDatatype, int actualScale, int scaleLimit)
      Description copied from interface: IDatabaseLengthValidationConfiguration
      Creates a message to indicate that the given attribute's value on the given model object exceeds the configured NumericConstraint`s scale.
      Specified by:
      createMessageForScaleViolation in interface IDatabaseLengthValidationConfiguration
      Parameters:
      attribute - the model type reference for the validated attribute
      modelObject - the model object instance on which the attribute was validated
      actualScale - the actual value's amount of decimal places
      scaleLimit - the exceeded limit, set in the constraint
    • createMessage

      protected Message createMessage(String msgKey, String msgCode, IModelObject modelObject, PolicyAttribute attribute, int actualValue, int maxValue)
      Returns a message, using the given parameters as follows:.
      Parameters:
      msgKey - is used to retrieve the message text from the ResourceBundle
      msgCode - is used for Message.getCode()
      modelObject - is used to determine the invalid ObjectProperty.getObject()
      attribute - is used to determine the invalid ObjectProperty.getProperty()
      actualValue - the invalid value
      maxValue - the limit that was exceeded
      Returns:
      a message, using the given parameters as follows:
    • addMarker

      protected void addMarker(Message.Builder messageBuilder)
      Parameters:
      messageBuilder - a message builder, usually used inside createMessage(String, String, IModelObject, PolicyAttribute, int, int)