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