Package org.neo4j.graphdb.schema
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 Summary
Modifier and TypeMethodDescriptionassertPropertyExists
(String propertyKey) Imposes an existence constraint for the given property.assertPropertyIsNodeKey
(String propertyKey) Imposes both a uniqueness constraint, and a property existence constraint, for the given property.assertPropertyIsUnique
(String propertyKey) Imposes a uniqueness constraint for the given property.create()
Creates a constraint with the details specified by the other methods in this interface.withIndexConfiguration
(Map<IndexSetting, Object> indexConfiguration) Set index-specific index configurations.withIndexType
(IndexType indexType) Assign an index type to the constraint.Assign a name to the constraint, which will then be returned fromConstraintDefinition.getName()
, and can be used for finding the constraint withSchema.getConstraintByName(String)
, or the associated index withSchema.getIndexByName(String)
for index backed constraints.
-
Method Details
-
assertPropertyIsUnique
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
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
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
Assign a name to the constraint, which will then be returned fromConstraintDefinition.getName()
, and can be used for finding the constraint withSchema.getConstraintByName(String)
, or the associated index withSchema.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
Assign an index type to the constraint. If the constraint is not backed by an index, then the presence of an index type will causecreate()
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
Set index-specific index configurations. If the constraint is not backed by an index, then the presence of an index configuration will causecreate()
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.
-