Search in sources :

Example 76 with ConstraintDescriptor

use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.

the class SchemaImpl method getConstraintByName.

@Override
public ConstraintDefinition getConstraintByName(String constraintName) {
    transaction.assertOpen();
    requireNonNull(constraintName);
    ConstraintDescriptor constraint = transaction.schemaRead().constraintGetForName(constraintName);
    if (constraint == null) {
        throw new IllegalArgumentException("No constraint found with the name '" + constraintName + "'.");
    }
    return asConstraintDefinition(constraint, transaction.tokenRead());
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor)

Example 77 with ConstraintDescriptor

use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.

the class ConstraintDescriptorFactoryTest method shouldCreateNodeKeyConstraintDescriptors.

@Test
void shouldCreateNodeKeyConstraintDescriptors() {
    ConstraintDescriptor desc;
    desc = ConstraintDescriptorFactory.nodeKeyForLabel(LABEL_ID, 1);
    assertThat(desc.type()).isEqualTo(ConstraintType.UNIQUE_EXISTS);
    assertThat(desc.schema()).isEqualTo(SchemaDescriptor.forLabel(LABEL_ID, 1));
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 78 with ConstraintDescriptor

use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.

the class ConstraintDescriptorFactoryTest method shouldCreateConstraintDescriptorsFromSchema.

@Test
void shouldCreateConstraintDescriptorsFromSchema() {
    ConstraintDescriptor desc;
    desc = ConstraintDescriptorFactory.uniqueForSchema(SchemaDescriptor.forLabel(LABEL_ID, 1));
    assertThat(desc.type()).isEqualTo(ConstraintType.UNIQUE);
    assertThat(desc.schema()).isEqualTo(SchemaDescriptor.forLabel(LABEL_ID, 1));
    desc = ConstraintDescriptorFactory.nodeKeyForSchema(SchemaDescriptor.forLabel(LABEL_ID, 1));
    assertThat(desc.type()).isEqualTo(ConstraintType.UNIQUE_EXISTS);
    assertThat(desc.schema()).isEqualTo(SchemaDescriptor.forLabel(LABEL_ID, 1));
    desc = ConstraintDescriptorFactory.existsForSchema(SchemaDescriptor.forRelType(REL_TYPE_ID, 1));
    assertThat(desc.type()).isEqualTo(ConstraintType.EXISTS);
    assertThat(desc.schema()).isEqualTo(SchemaDescriptor.forRelType(REL_TYPE_ID, 1));
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 79 with ConstraintDescriptor

use of org.neo4j.internal.schema.ConstraintDescriptor 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 80 with ConstraintDescriptor

use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldReportInvalidConstraintBackReferences.

@Test
void shouldReportInvalidConstraintBackReferences() throws Exception {
    // given
    AtomicReference<IndexDescriptor> descriptor = new AtomicReference<>();
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) throws KernelException {
            int ruleId1 = (int) next.schema();
            int ruleId2 = (int) next.schema();
            int labelId = next.label();
            int propertyKeyId = next.propertyKey();
            SchemaRecord before1 = new SchemaRecord(ruleId1);
            SchemaRecord before2 = new SchemaRecord(ruleId2);
            SchemaRecord after1 = cloneRecord(before1).initialize(true, 0);
            SchemaRecord after2 = cloneRecord(before2).initialize(true, 0);
            IndexDescriptor rule1 = constraintIndexRule(ruleId1, labelId, propertyKeyId, DESCRIPTOR, ruleId2);
            rule1 = tx.completeConfiguration(rule1);
            ConstraintDescriptor rule2 = uniquenessConstraintRule(ruleId2, labelId, propertyKeyId, ruleId2);
            serializeRule(rule1, after1, tx, next);
            serializeRule(rule2, after2, tx, next);
            tx.nodeLabel(labelId, "label", false);
            tx.propertyKey(propertyKeyId, "property", false);
            tx.createSchema(before1, after1, rule1);
            tx.createSchema(before2, after2, rule2);
            descriptor.set(rule1);
        }
    });
    fixture.indexingService().activateIndex(descriptor.get());
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.SCHEMA, 2).andThatsAllFolks();
}
Also used : TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) AtomicReference(java.util.concurrent.atomic.AtomicReference) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) KernelException(org.neo4j.exceptions.KernelException) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)107 Test (org.junit.jupiter.api.Test)62 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)34 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)32 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)26 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)21 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)20 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)19 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)16 TokenRead (org.neo4j.internal.kernel.api.TokenRead)9 ArrayList (java.util.ArrayList)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)6 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)6 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)6 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)5 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)5 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)5 SchemaRule (org.neo4j.internal.schema.SchemaRule)5 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)5 OptionalLong (java.util.OptionalLong)4