Class Constraint

java.lang.Object
ac.simons.neo4j.migrations.core.catalog.Constraint
All Implemented Interfaces:
CatalogItem<Constraint.Type>, Formattable

public final class Constraint extends Object
A somewhat Neo4j version independent representation of a constraint.
Since:
1.7.0
Author:
Michael J. Simons
Soundtrack
Metallica - Ride The Lightning
  • Field Details

    • options

      protected final String options
      Any additional options to be passed to the item. Might be null.
  • Method Details

    • forNode

      public static Constraint.NodeConstraintBuilder forNode(String label)
      Starts defining a new instance of a node constraint.
      Parameters:
      label - The label on which the constraint should be applied
      Returns:
      The ongoing builder
    • forRelationship

      public static Constraint.RelationshipConstraintBuilder forRelationship(String type)
      Starts defining a new instance of a relationship constraint.
      Parameters:
      type - The type on which the constraint should be applied
      Returns:
      The ongoing builder
    • parse

      public static Constraint parse(org.neo4j.driver.types.MapAccessor row)
      Parses a constraint from a MapAccessor, which will either contain a result from call db.constraints() (Neo4j 3.5 upto 4.1) or from SHOW CONSTRAINTS YIELD * from Neo4j 4.2 and upwards
      Parameters:
      row - the result row
      Returns:
      A constraint
      Throws:
      IllegalArgumentException - if the row cannot be processed
    • parse

      public static Constraint parse(Element constraintElement)
      Creates a constraint from a xml definition.
      Parameters:
      constraintElement - as defined in migration.xsd.
      Returns:
      The new constraint if the element as parseable
    • withOptions

      public Constraint withOptions(String options)
      Creates a copy of this constraint with the specific set of options added. Will return this instance if the options are identical to current options
      Parameters:
      options - The new options to use
      Returns:
      A (potentially) new constraint
      Since:
      1.13.0
    • withName

      public Constraint withName(String name)
      Description copied from interface: CatalogItem
      Creates a copy of this item with the specific name. Will return this instance if the name has not changed.
      Parameters:
      name - The new name to use
      Returns:
      A (potentially) new item
    • isEquivalentTo

      public boolean isEquivalentTo(CatalogItem<?> that)
      true, if item is a constraint of the same type for the same entity containing the same properties.
      Parameters:
      that - the other item to compare to
      Returns:
      true if this and the other item are equivalent
    • getName

      public Name getName()
      Specified by:
      getName in interface CatalogItem<T extends ItemType>
      Returns:
      A unique name for a catalog item.
    • getType

      public Constraint.Type getType()
      Specified by:
      getType in interface CatalogItem<T extends ItemType>
      Returns:
      Type information for the given item, specialized to the item type itself.
    • getTargetEntityType

      public TargetEntityType getTargetEntityType()
      Returns:
      The target entity of this item.
    • getIdentifier

      public String getIdentifier()
      Returns:
      Identifier of this item to be used in create statements
    • getProperties

      public Set<String> getProperties()
      Returns:
      Set of properties to be included with the item
    • getOptionalOptions

      public Optional<String> getOptionalOptions()
      Returns:
      Optional options to be passed down during creation of the item
    • hasGeneratedName

      public boolean hasGeneratedName()
      Specified by:
      hasGeneratedName in interface CatalogItem<T extends ItemType>
      Returns:
      true if this item has a generated name.
    • formatTo

      public final void formatTo(Formatter formatter, int flags, int width, int precision)
      Specified by:
      formatTo in interface Formattable
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object