use of org.neo4j.internal.schema.SchemaProcessor in project neo4j by neo4j.
the class SchemaProcessorTest method shouldHandleCorrectDescriptorVersions.
@Test
void shouldHandleCorrectDescriptorVersions() {
List<String> callHistory = new ArrayList<>();
SchemaProcessor processor = new SchemaProcessor() {
@Override
public void processSpecific(LabelSchemaDescriptor schema) {
callHistory.add("LabelSchemaDescriptor");
}
@Override
public void processSpecific(RelationTypeSchemaDescriptor schema) {
callHistory.add("RelationTypeSchemaDescriptor");
}
@Override
public void processSpecific(SchemaDescriptor schemaDescriptor) {
callHistory.add("SchemaDescriptor");
}
};
disguisedLabel().processWith(processor);
disguisedLabel().processWith(processor);
disguisedRelType().processWith(processor);
disguisedLabel().processWith(processor);
disguisedRelType().processWith(processor);
disguisedRelType().processWith(processor);
assertThat(callHistory).containsExactly("LabelSchemaDescriptor", "LabelSchemaDescriptor", "RelationTypeSchemaDescriptor", "LabelSchemaDescriptor", "RelationTypeSchemaDescriptor", "RelationTypeSchemaDescriptor");
}
use of org.neo4j.internal.schema.SchemaProcessor in project neo4j by neo4j.
the class SchemaChecker method performSchemaCheck.
private void performSchemaCheck(long highId, RecordReader<SchemaRecord> reader, Map<Long, SchemaRecord> indexObligations, Map<Long, SchemaRecord> constraintObligations, SchemaStorage schemaStorage, MutableIntObjectMap<MutableIntSet> mandatoryNodeProperties, MutableIntObjectMap<MutableIntSet> mandatoryRelationshipProperties, CursorContext cursorContext) {
SchemaRecord record = reader.record();
SchemaProcessor basicSchemaCheck = new BasicSchemaCheck(record, cursorContext);
SchemaProcessor mandatoryPropertiesBuilder = new MandatoryPropertiesBuilder(mandatoryNodeProperties, mandatoryRelationshipProperties);
for (long id = schemaStore.getNumberOfReservedLowIds(); id < highId && !context.isCancelled(); id++) {
try {
reader.read(id);
if (record.inUse()) {
SchemaRule schemaRule = schemaStorage.loadSingleSchemaRule(id, cursorContext);
schemaRule.schema().processWith(basicSchemaCheck);
if (schemaRule instanceof IndexDescriptor) {
IndexDescriptor rule = (IndexDescriptor) schemaRule;
if (rule.isUnique()) {
SchemaRecord obligation = indexObligations.get(rule.getId());
if (// no pointer to here
obligation == null) {
if (// we only expect a pointer if we have an owner
rule.getOwningConstraintId().isPresent()) {
reporter.forSchema(record).missingObligation(SchemaRuleKind.UNIQUENESS_CONSTRAINT.name());
}
} else {
// if someone points to here, it must be our owner
OptionalLong owningConstraintId = rule.getOwningConstraintId();
if (owningConstraintId.isEmpty() || obligation.getId() != owningConstraintId.getAsLong()) {
reporter.forSchema(record).constraintIndexRuleNotReferencingBack(obligation);
}
}
}
if (indexAccessors.notOnlineRules().contains(rule)) {
reporter.forSchema(record).schemaRuleNotOnline(rule);
}
if (indexAccessors.inconsistentRules().contains(rule)) {
reporter.forSchema(record).malformedSchemaRule();
}
} else if (schemaRule instanceof ConstraintDescriptor) {
ConstraintDescriptor rule = (ConstraintDescriptor) schemaRule;
if (rule.enforcesUniqueness()) {
SchemaRecord obligation = constraintObligations.get(rule.getId());
if (obligation == null) {
reporter.forSchema(record).missingObligation(SchemaRuleKind.CONSTRAINT_INDEX_RULE.name());
} else {
if (obligation.getId() != rule.asIndexBackedConstraint().ownedIndexId()) {
reporter.forSchema(record).uniquenessConstraintNotReferencingBack(obligation);
}
}
}
if (rule.enforcesPropertyExistence()) {
rule.schema().processWith(mandatoryPropertiesBuilder);
}
} else {
reporter.forSchema(record).unsupportedSchemaRuleType(null);
}
}
} catch (MalformedSchemaRuleException e) {
reporter.forSchema(record).malformedSchemaRule();
}
}
}
Aggregations