Search in sources :

Example 21 with UniquenessConstraintDescriptor

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

the class RecordStorageReaderTestBase method createUniquenessConstraint.

protected IndexDescriptor createUniquenessConstraint(Label label, String propertyKey) throws Exception {
    IndexDescriptor index = createUniqueIndex(label, propertyKey);
    TxState txState = new TxState();
    int labelId = getOrCreateLabelId(label);
    int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyId);
    constraint = constraint.withName(index.getName()).withOwnedIndexId(index.getId());
    txState.constraintDoAdd(constraint);
    apply(txState);
    return index;
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 22 with UniquenessConstraintDescriptor

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

the class SchemaRuleSerialization35Test method assertParseUniqueConstraintRule.

private static void assertParseUniqueConstraintRule(String serialized, String name) throws MalformedSchemaRuleException {
    // GIVEN
    long ruleId = 1;
    int propertyKey = 3;
    int labelId = 55;
    long ownedIndexId = 2;
    UniquenessConstraintDescriptor constraint = uniqueForLabel(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 : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)

Example 23 with UniquenessConstraintDescriptor

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

the class SchemaCheckerTest method shouldReportConstraintIndexRuleNotReferencingBack.

@Test
void shouldReportConstraintIndexRuleNotReferencingBack() 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(index.getId());
        index = index.withOwningConstraintId(UNUSED);
        schemaStorage.writeSchemaRule(index, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(uniquenessConstraint, cursorContext, INSTANCE);
    }
    // when
    check();
    // then
    expect(SchemaConsistencyReport.class, report -> report.constraintIndexRuleNotReferencingBack(any()));
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 24 with UniquenessConstraintDescriptor

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

the class SchemaCheckerTest method shouldReportWhenConstraintIndexHasNoConstraintOwnerReference.

@Test
void shouldReportWhenConstraintIndexHasNoConstraintOwnerReference() 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(index.getId());
        schemaStorage.writeSchemaRule(index, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(uniquenessConstraint, cursorContext, INSTANCE);
    }
    // when
    check();
    // then
    expect(SchemaConsistencyReport.class, report -> report.constraintIndexRuleNotReferencingBack(any()));
}
Also used : UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 25 with UniquenessConstraintDescriptor

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

the class SchemaCheckerTest method shouldReportDuplicateObligationForConstraint.

@Test
void shouldReportDuplicateObligationForConstraint() 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 uniquenessConstraint1 = ConstraintDescriptorFactory.uniqueForLabel(label1, propertyKey1).withId(schemaStore.nextId(cursorContext)).withName(NAME).withOwnedIndexId(index.getId());
        UniquenessConstraintDescriptor uniquenessConstraint2 = ConstraintDescriptorFactory.uniqueForLabel(label2, propertyKey2).withId(schemaStore.nextId(cursorContext)).withName(NAME2).withOwnedIndexId(index.getId());
        index = index.withOwningConstraintId(uniquenessConstraint1.getId());
        schemaStorage.writeSchemaRule(index, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(uniquenessConstraint1, cursorContext, INSTANCE);
        schemaStorage.writeSchemaRule(uniquenessConstraint2, 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)

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