Search in sources :

Example 6 with NodeKeyConstraintDescriptor

use of org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor in project neo4j by neo4j.

the class TransactionToRecordStateVisitor method visitAddedNodeKeyConstraint.

private void visitAddedNodeKeyConstraint(NodeKeyConstraintDescriptor uniqueConstraint, long constraintId) throws KernelException {
    IndexDescriptor indexRule = (IndexDescriptor) schemaStorage.loadSingleSchemaRule(uniqueConstraint.ownedIndexId(), cursorContext);
    ConstraintDescriptor constraint = constraintSemantics.createNodeKeyConstraintRule(constraintId, uniqueConstraint, indexRule.getId());
    schemaStateChanger.createSchemaRule(recordState, constraint);
    schemaStateChanger.setConstraintIndexOwner(recordState, indexRule, constraintId);
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 7 with NodeKeyConstraintDescriptor

use of org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor in project neo4j by neo4j.

the class SchemaRuleSerialization35Test method assertParseNodeKeyConstraintRule.

private static void assertParseNodeKeyConstraintRule(String serialized, String name) throws MalformedSchemaRuleException {
    // GIVEN
    long ruleId = 1;
    int propertyKey = 3;
    int labelId = 55;
    long ownedIndexId = 2;
    NodeKeyConstraintDescriptor constraint = nodeKeyForLabel(labelId, propertyKey);
    byte[] bytes = decodeBase64(serialized);
    // WHEN
    ConstraintDescriptor deserialized = assertConstraintRule(SchemaRuleSerialization35.deserialize(ruleId, ByteBuffer.wrap(bytes)));
    // THEN
    assertThat(deserialized.getId()).isEqualTo(ruleId);
    assertThat(deserialized).isEqualTo(constraint);
    assertThat(deserialized.schema()).isEqualTo(constraint.schema());
    assertThat(deserialized.asIndexBackedConstraint().ownedIndexId()).isEqualTo(ownedIndexId);
    assertThat(deserialized.getName()).isEqualTo(name);
}
Also used : NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)

Example 8 with NodeKeyConstraintDescriptor

use of org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor in project neo4j by neo4j.

the class Operations method nodeKeyConstraintCreate.

@Override
public ConstraintDescriptor nodeKeyConstraintCreate(IndexPrototype prototype) throws KernelException {
    SchemaDescriptor schema = prototype.schema();
    exclusiveSchemaLock(schema);
    ktx.assertOpen();
    prototype = ensureIndexPrototypeHasIndexProvider(prototype);
    NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForSchema(schema);
    try {
        // Check data integrity
        assertValidDescriptor(schema, SchemaKernelException.OperationContext.CONSTRAINT_CREATION);
        if (prototype.getName().isEmpty()) {
            constraint = ensureConstraintHasName(constraint);
            prototype = prototype.withName(constraint.getName());
        } else {
            constraint = constraint.withName(prototype.getName().get());
        }
        exclusiveSchemaNameLock(constraint.getName());
        assertNoBlockingSchemaRulesExists(constraint);
    } catch (SchemaKernelException e) {
        exclusiveSchemaUnlock(schema);
        throw e;
    }
    // enforce constraints
    enforceNodeKeyConstraint(schema);
    // create constraint
    indexBackedConstraintCreate(constraint, prototype);
    return constraint;
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)

Example 9 with NodeKeyConstraintDescriptor

use of org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor in project neo4j by neo4j.

the class BuiltInProceduresTest method givenNodeKeys.

private void givenNodeKeys(String label, String... props) {
    int labelId = token(label, labels);
    int[] propIds = new int[props.length];
    for (int i = 0; i < propIds.length; i++) {
        propIds[i] = token(props[i], propKeys);
    }
    final NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForLabel(labelId, propIds).withName("MyNodeKeyConstraint");
    constraints.add(constraint);
}
Also used : NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)

Aggregations

NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)9 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)3 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)3 Test (org.junit.jupiter.api.Test)2 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)2 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)2 MalformedSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)1 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)1 NodeExistenceConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor)1 RelExistenceConstraintDescriptor (org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor)1 AlreadyConstrainedException (org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException)1 TxState (org.neo4j.kernel.impl.api.state.TxState)1 NamedToken (org.neo4j.token.api.NamedToken)1