Record Class ColumnConstraint

java.lang.Object
java.lang.Record
io.bloviate.db.ColumnConstraint
Record Components:
allowedValues - the permitted values (their text form), or null for a range constraint
min - the lower bound, or null if unbounded below
minInclusive - whether min is inclusive
max - the upper bound, or null if unbounded above
maxInclusive - whether max is inclusive

public record ColumnConstraint(List<String> allowedValues, BigDecimal min, boolean minInclusive, BigDecimal max, boolean maxInclusive) extends Record
A value constraint captured for a column — the machine-readable part of a CHECK constraint or an ENUM/domain's allowed values — so the fill engine can generate values that satisfy it instead of values a constraint would reject (issue #479).

A constraint is one of two shapes: a set of allowed values (from col IN (...), = ANY (ARRAY[...]), or an enum's labels) or a numeric range (from BETWEEN / >= / <= / > / <). Forms the reader can't interpret are not represented here — the engine warns and falls back to its type default for those.

Since:
2.14.0
  • Constructor Details

    • ColumnConstraint

      public ColumnConstraint(List<String> allowedValues, BigDecimal min, boolean minInclusive, BigDecimal max, boolean maxInclusive)
      Creates an instance of a ColumnConstraint record class.
      Parameters:
      allowedValues - the value for the allowedValues record component
      min - the value for the min record component
      minInclusive - the value for the minInclusive record component
      max - the value for the max record component
      maxInclusive - the value for the maxInclusive record component
  • Method Details

    • ofValues

      public static ColumnConstraint ofValues(List<String> allowedValues)
      A set-of-allowed-values constraint (categorical / enum / IN).
      Parameters:
      allowedValues - the permitted values (their text form); defensively copied
      Returns:
      a constraint that admits only allowedValues
    • ofRange

      public static ColumnConstraint ofRange(BigDecimal min, BigDecimal max)
      A closed numeric range [min, max] (both inclusive).
      Parameters:
      min - the inclusive lower bound
      max - the inclusive upper bound
      Returns:
      a constraint that admits values in [min, max]
    • hasAllowedValues

      public boolean hasAllowedValues()
      True if this is a set-of-allowed-values constraint.
      Returns:
      whether allowed values are present
    • hasBoundedRange

      public boolean hasBoundedRange()
      True if this is a numeric range with both bounds (the form the engine can honor).
      Returns:
      whether both min and max are present
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • allowedValues

      public List<String> allowedValues()
      Returns the value of the allowedValues record component.
      Returns:
      the value of the allowedValues record component
    • min

      public BigDecimal min()
      Returns the value of the min record component.
      Returns:
      the value of the min record component
    • minInclusive

      public boolean minInclusive()
      Returns the value of the minInclusive record component.
      Returns:
      the value of the minInclusive record component
    • max

      public BigDecimal max()
      Returns the value of the max record component.
      Returns:
      the value of the max record component
    • maxInclusive

      public boolean maxInclusive()
      Returns the value of the maxInclusive record component.
      Returns:
      the value of the maxInclusive record component