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