use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class DataIntegrityValidatingStatementOperations method nodePropertyExistenceConstraintCreate.
@Override
public NodeExistenceConstraintDescriptor nodePropertyExistenceConstraintCreate(KernelStatement state, LabelSchemaDescriptor descriptor) throws AlreadyConstrainedException, CreateConstraintFailureException, RepeatedPropertyInCompositeSchemaException {
assertValidDescriptor(descriptor, OperationContext.CONSTRAINT_CREATION);
ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForSchema(descriptor);
assertConstraintDoesNotExist(state, constraint);
return schemaWriteDelegate.nodePropertyExistenceConstraintCreate(state, descriptor);
}
use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class DataIntegrityValidatingStatementOperations method relationshipPropertyExistenceConstraintCreate.
@Override
public RelExistenceConstraintDescriptor relationshipPropertyExistenceConstraintCreate(KernelStatement state, RelationTypeSchemaDescriptor descriptor) throws AlreadyConstrainedException, CreateConstraintFailureException, RepeatedPropertyInCompositeSchemaException {
assertValidDescriptor(descriptor, OperationContext.CONSTRAINT_CREATION);
ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForSchema(descriptor);
assertConstraintDoesNotExist(state, constraint);
return schemaWriteDelegate.relationshipPropertyExistenceConstraintCreate(state, descriptor);
}
use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method nodeAddLabel.
@Override
public boolean nodeAddLabel(KernelStatement state, long nodeId, int labelId) throws EntityNotFoundException, ConstraintValidationException {
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
Iterator<ConstraintDescriptor> constraints = schemaReadOperations.constraintsGetForLabel(state, labelId);
while (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
if (constraint.type() == UNIQUE) {
UniquenessConstraintDescriptor uniqueConstraint = (UniquenessConstraintDescriptor) constraint;
ExactPredicate[] propertyValues = getAllPropertyValues(state, uniqueConstraint.schema(), node);
if (propertyValues != null) {
validateNoExistingNodeWithExactValues(state, uniqueConstraint, propertyValues, node.id());
}
}
}
}
return entityWriteOperations.nodeAddLabel(state, nodeId, labelId);
}
use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class BatchInserterImpl method verifyIndexOrUniquenessConstraintCanBeCreated.
private void verifyIndexOrUniquenessConstraintCanBeCreated(int labelId, int[] propertyKeyIds, String errorMessage) {
LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyIds);
ConstraintDescriptor constraintDescriptor = ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyIds);
if (schemaCache.hasIndexRule(schemaDescriptor) || schemaCache.hasConstraintRule(constraintDescriptor)) {
throw new ConstraintViolationException(errorMessage);
}
}
use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.
the class GraphDbStructureGuide method showUniqueConstraints.
private void showUniqueConstraints(DbStructureVisitor visitor, ReadOperations read, TokenNameLookup nameLookup) {
Iterator<ConstraintDescriptor> constraints = read.constraintsGetAll();
while (constraints.hasNext()) {
PropertyConstraint constraint = ConstraintBoundary.map(constraints.next());
String userDescription = constraint.userDescription(nameLookup);
if (constraint instanceof UniquenessConstraint) {
visitor.visitUniqueConstraint((UniquenessConstraint) constraint, userDescription);
} else if (constraint instanceof NodePropertyExistenceConstraint) {
NodePropertyExistenceConstraint existenceConstraint = (NodePropertyExistenceConstraint) constraint;
visitor.visitNodePropertyExistenceConstraint(existenceConstraint, userDescription);
} else if (constraint instanceof RelationshipPropertyExistenceConstraint) {
RelationshipPropertyExistenceConstraint existenceConstraint = (RelationshipPropertyExistenceConstraint) constraint;
visitor.visitRelationshipPropertyExistenceConstraint(existenceConstraint, userDescription);
} else {
throw new IllegalArgumentException("Unknown constraint type: " + constraint.getClass() + ", " + "constraint: " + constraint);
}
}
}
Aggregations