Search in sources :

Example 1 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class BatchInserterImpl method createUniquenessConstraintRule.

private void createUniquenessConstraintRule(UniquenessConstraint constraint) {
    // TODO: Do not create duplicate index
    long indexRuleId = schemaStore.nextId();
    long constraintRuleId = schemaStore.nextId();
    int propertyKeyId = constraint.indexDescriptor().schema().getPropertyId();
    IndexRule indexRule = IndexRule.constraintIndexRule(indexRuleId, NewIndexDescriptorFactory.uniqueForLabel(constraint.label(), propertyKeyId), this.schemaIndexProviders.getDefaultProvider().getProviderDescriptor(), constraintRuleId);
    ConstraintRule constraintRule = ConstraintRule.constraintRule(constraintRuleId, ConstraintDescriptorFactory.uniqueForLabel(constraint.label(), propertyKeyId), indexRuleId);
    for (DynamicRecord record : schemaStore.allocateFrom(constraintRule)) {
        schemaStore.updateRecord(record);
    }
    schemaCache.addSchemaRule(constraintRule);
    for (DynamicRecord record : schemaStore.allocateFrom(indexRule)) {
        schemaStore.updateRecord(record);
    }
    schemaCache.addSchemaRule(indexRule);
    labelsTouched = true;
    flushStrategy.forceFlush();
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint)

Example 2 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class SchemaCacheTest method shouldListConstraintsForRelationshipType.

@Test
public void shouldListConstraintsForRelationshipType() {
    // Given
    ConstraintRule rule1 = relPropertyExistenceConstraintRule(0, 1, 1);
    ConstraintRule rule2 = relPropertyExistenceConstraintRule(0, 2, 1);
    ConstraintRule rule3 = relPropertyExistenceConstraintRule(0, 1, 2);
    SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
    // When
    Set<ConstraintDescriptor> listed = asSet(cache.constraintsForRelationshipType(1));
    // Then
    Set<ConstraintDescriptor> expected = asSet(rule1.getConstraintDescriptor(), rule3.getConstraintDescriptor());
    assertEquals(expected, listed);
}
Also used : ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

Example 3 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class SchemaCacheTest method shouldListConstraintsForSchema.

@Test
public void shouldListConstraintsForSchema() {
    // Given
    ConstraintRule rule1 = uniquenessConstraintRule(0, 1, 1, 0);
    ConstraintRule rule2 = uniquenessConstraintRule(1, 2, 1, 0);
    ConstraintRule rule3 = nodePropertyExistenceConstraintRule(2, 1, 2);
    SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
    // When
    Set<ConstraintDescriptor> listed = asSet(cache.constraintsForSchema(rule3.schema()));
    // Then
    assertEquals(singleton(rule3.getConstraintDescriptor()), listed);
}
Also used : ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

Example 4 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class SchemaCacheTest method shouldListConstraintsForLabel.

@Test
public void shouldListConstraintsForLabel() {
    // Given
    ConstraintRule rule1 = uniquenessConstraintRule(0, 1, 1, 0);
    ConstraintRule rule2 = uniquenessConstraintRule(1, 2, 1, 0);
    ConstraintRule rule3 = nodePropertyExistenceConstraintRule(2, 1, 2);
    SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
    // When
    Set<ConstraintDescriptor> listed = asSet(cache.constraintsForLabel(1));
    // Then
    Set<ConstraintDescriptor> expected = asSet(rule1.getConstraintDescriptor(), rule3.getConstraintDescriptor());
    assertEquals(expected, listed);
}
Also used : ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

Example 5 with ConstraintRule

use of org.neo4j.kernel.impl.store.record.ConstraintRule in project neo4j by neo4j.

the class IntegrityValidatorTest method shouldValidateUniquenessIndexes.

@Test
public void shouldValidateUniquenessIndexes() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    IndexingService indexes = mock(IndexingService.class);
    IntegrityValidator validator = new IntegrityValidator(store, indexes);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
    doThrow(new UniquePropertyValueValidationException(constraint, ConstraintValidationException.Phase.VERIFICATION, new RuntimeException())).when(indexes).validateIndex(2L);
    ConstraintRule record = ConstraintRule.constraintRule(1L, constraint, 2L);
    // When
    try {
        validator.validateSchemaRule(record);
        fail("Should have thrown integrity error.");
    } catch (Exception e) {
    // good
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Test(org.junit.Test)

Aggregations

ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)26 Test (org.junit.Test)20 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)16 SchemaRuleUtil.uniquenessConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule)8 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)8 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)6 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)6 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)6 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)6 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)5 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)5 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)5 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)3 SchemaRuleUtil.nodePropertyExistenceConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.nodePropertyExistenceConstraintRule)3 SchemaRuleUtil.relPropertyExistenceConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.relPropertyExistenceConstraintRule)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)3 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)2 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2