Search in sources :

Example 11 with UniquenessConstraintDescriptor

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

the class SchemaCheckerTest method shouldReportDuplicateObligationForIndex.

@Test
void shouldReportDuplicateObligationForIndex() throws Exception {
    // given
    try (AutoCloseable ignored = tx()) {
        var cursorContext = CursorContext.NULL;
        IndexDescriptor index1 = IndexPrototype.uniqueForSchema(SchemaDescriptor.forLabel(label1, propertyKey1)).withName(NAME).withIndexProvider(DESCRIPTOR).materialise(schemaStore.nextId(cursorContext));
        IndexDescriptor index2 = IndexPrototype.uniqueForSchema(SchemaDescriptor.forLabel(label2, propertyKey2)).withName(NAME2).withIndexProvider(DESCRIPTOR).materialise(schemaStore.nextId(cursorContext));
        UniquenessConstraintDescriptor uniquenessConstraint = ConstraintDescriptorFactory.uniqueForLabel(label1, propertyKey1).withId(schemaStore.nextId(cursorContext)).withName(NAME).withOwnedIndexId(index1.getId());
        index1 = index1.withOwningConstraintId(uniquenessConstraint.getId());
        index2 = index2.withOwningConstraintId(uniquenessConstraint.getId());
        schemaStorage.writeSchemaRule(index1, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(index2, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(uniquenessConstraint, cursorContext, INSTANCE);
    }
    // when
    check();
    // then
    expect(SchemaConsistencyReport.class, report -> report.duplicateObligation(any()));
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 12 with UniquenessConstraintDescriptor

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

the class SchemaCheckerTest method shouldReportUniquenessConstraintNotReferencingBack.

@Test
void shouldReportUniquenessConstraintNotReferencingBack() throws Exception {
    // given
    try (AutoCloseable ignored = tx()) {
        var cursorContext = CursorContext.NULL;
        IndexDescriptor index = IndexPrototype.uniqueForSchema(SchemaDescriptor.forLabel(label1, propertyKey1)).withName(NAME).withIndexProvider(DESCRIPTOR).materialise(schemaStore.nextId(cursorContext));
        UniquenessConstraintDescriptor uniquenessConstraint = ConstraintDescriptorFactory.uniqueForLabel(label1, propertyKey1).withId(schemaStore.nextId(cursorContext)).withName(NAME).withOwnedIndexId(UNUSED);
        index = index.withOwningConstraintId(uniquenessConstraint.getId());
        schemaStorage.writeSchemaRule(index, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(uniquenessConstraint, cursorContext, INSTANCE);
    }
    // when
    check();
    // then
    expect(SchemaConsistencyReport.class, report -> report.uniquenessConstraintNotReferencingBack(any()));
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 13 with UniquenessConstraintDescriptor

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

the class SchemaRuleSerialization35 method readConstraintRule.

// READ CONSTRAINT
private static ConstraintDescriptor readConstraintRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
    SchemaDescriptor schema;
    byte constraintRuleType = source.get();
    String name;
    switch(constraintRuleType) {
        case EXISTS_CONSTRAINT:
            schema = readSchema(source);
            name = readRuleName(source).orElse(null);
            return ConstraintDescriptorFactory.existsForSchema(schema).withId(id).withName(name);
        case UNIQUE_CONSTRAINT:
            long ownedUniqueIndex = source.getLong();
            schema = readSchema(source);
            UniquenessConstraintDescriptor descriptor = ConstraintDescriptorFactory.uniqueForSchema(schema);
            name = readRuleName(source).orElse(null);
            return descriptor.withId(id).withOwnedIndexId(ownedUniqueIndex).withName(name);
        case UNIQUE_EXISTS_CONSTRAINT:
            long ownedNodeKeyIndex = source.getLong();
            schema = readSchema(source);
            NodeKeyConstraintDescriptor nodeKeyConstraintDescriptor = ConstraintDescriptorFactory.nodeKeyForSchema(schema);
            name = readRuleName(source).orElse(null);
            return nodeKeyConstraintDescriptor.withId(id).withOwnedIndexId(ownedNodeKeyIndex).withName(name);
        default:
            throw new MalformedSchemaRuleException(format("Got unknown constraint rule type '%d'.", constraintRuleType));
    }
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)

Example 14 with UniquenessConstraintDescriptor

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

the class SchemaRuleDeserializer2_0to3_1 method readUniquenessConstraintRule.

// === CONSTRAINT RULES ===
public static ConstraintDescriptor readUniquenessConstraintRule(long id, int labelId, ByteBuffer buffer) {
    int[] propertyIds = readConstraintPropertyKeys(buffer);
    Long ownedIndex = readOwnedIndexRule(buffer);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyIds);
    return constraint.withId(id).withOwnedIndexId(ownedIndex);
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)

Example 15 with UniquenessConstraintDescriptor

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

the class TransactionToRecordStateVisitor method visitAddedUniquenessConstraint.

private void visitAddedUniquenessConstraint(UniquenessConstraintDescriptor uniqueConstraint, long constraintId) throws KernelException {
    IndexDescriptor indexRule = (IndexDescriptor) schemaStorage.loadSingleSchemaRule(uniqueConstraint.ownedIndexId(), cursorContext);
    ConstraintDescriptor constraint = constraintSemantics.createUniquenessConstraintRule(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)

Aggregations

UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)26 Test (org.junit.jupiter.api.Test)17 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)7 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)6 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)6 RepeatedTest (org.junit.jupiter.api.RepeatedTest)4 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)4 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)2 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)2 NodeExistenceConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor)2 RelExistenceConstraintDescriptor (org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor)2 KernelException (org.neo4j.exceptions.KernelException)1 UnspecifiedKernelException (org.neo4j.exceptions.UnspecifiedKernelException)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)1 IndexNotApplicableKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)1 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)1 MalformedSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)1 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)1