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()));
}
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()));
}
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));
}
}
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);
}
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);
}
Aggregations