Interface ConstraintCreator


public interface ConstraintCreator
A builder for entering details about a constraint to create. After all details have been entered create() must be called for the constraint to actually be created. A constraint creator knows which label it is to be created for. All methods except create() will return an ConstraintCreator which should be used for further interaction. Compatibility note: New methods may be added to this interface without notice, backwards compatibility is only guaranteed for clients of this interface, not for implementors.
See Also:
  • Method Details

    • assertPropertyIsUnique

      ConstraintCreator assertPropertyIsUnique(String propertyKey)
      Imposes a uniqueness constraint for the given property. This means that there can be at most one node, having the given label, for any set value of that property key. Multiple calls to this method will result in compound uniqueness constraint.
      Parameters:
      propertyKey - property to impose the uniqueness constraint for.
      Returns:
      a ConstraintCreator instance to be used for further interaction.
    • assertPropertyExists

      ConstraintCreator assertPropertyExists(String propertyKey)
      Imposes an existence constraint for the given property. This means that all nodes with the given label must have a value for this property.
      Parameters:
      propertyKey - property to impose the existence constraint for.
      Returns:
      a ConstraintCreator instance to be used for further interaction.
    • assertPropertyIsNodeKey

      ConstraintCreator assertPropertyIsNodeKey(String propertyKey)
      Imposes both a uniqueness constraint, and a property existence constraint, for the given property. This means that all nodes with the given label must have this property, and they must all have different values for the property. Multiple calls to this method will result in compound node key constraint.
      Parameters:
      propertyKey - property to use as the node key.
      Returns:
      a ConstraintCreator instance to be used for further interaction.
    • withName

      ConstraintCreator withName(String name)
      Assign a name to the constraint, which will then be returned from ConstraintDefinition.getName(), and can be used for finding the constraint with Schema.getConstraintByName(String), or the associated index with Schema.getIndexByName(String) for index backed constraints.
      Parameters:
      name - the name to give the constraint.
      Returns:
      a ConstraintCreator instance to be used for further interaction.
    • withIndexType

      ConstraintCreator withIndexType(IndexType indexType)
      Assign an index type to the constraint. If the constraint is not backed by an index, then the presence of an index type will cause create() to throw an exception.
      Parameters:
      indexType - the type of index wanted for backing the constraint.
      Returns:
      a ConstraintCreator instance to be used for further interaction.
      See Also:
    • withIndexConfiguration

      ConstraintCreator withIndexConfiguration(Map<IndexSetting,Object> indexConfiguration)
      Set index-specific index configurations. If the constraint is not backed by an index, then the presence of an index configuration will cause create() to throw an exception.

      This call will override the settings from any previous call to this method.

      Parameters:
      indexConfiguration - The index settings in the index configuration that differ from their defaults.
      Returns:
      a ConstraintCreator instance to be used for further interaction.
    • create

      Creates a constraint with the details specified by the other methods in this interface.
      Returns:
      the created constraint.
      Throws:
      ConstraintViolationException - if creating this constraint would violate any existing constraints.