Search in sources :

Example 6 with ConstraintDescriptor

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);
}
Also used : UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)

Example 7 with ConstraintDescriptor

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);
}
Also used : UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)

Example 8 with ConstraintDescriptor

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);
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ExactPredicate(org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate)

Example 9 with ConstraintDescriptor

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);
    }
}
Also used : ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 10 with ConstraintDescriptor

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);
        }
    }
}
Also used : PropertyConstraint(org.neo4j.kernel.api.constraints.PropertyConstraint) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) RelationshipPropertyExistenceConstraint(org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint) NodePropertyExistenceConstraint(org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint)

Aggregations

ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)25 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)15 Test (org.junit.Test)11 NodeExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor)6 RelExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)6 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)3 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)3 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)3 ArrayList (java.util.ArrayList)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 Statement (org.neo4j.kernel.api.Statement)2 PropertyConstraint (org.neo4j.kernel.api.constraints.PropertyConstraint)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1