use of org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException in project neo4j by neo4j.
the class OperationsFacade method uniqueIndexGetForLabelAndPropertyKey.
@Override
public NewIndexDescriptor uniqueIndexGetForLabelAndPropertyKey(NodePropertyDescriptor descriptor) throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
NewIndexDescriptor result = null;
Iterator<NewIndexDescriptor> indexes = uniqueIndexesGetForLabel(descriptor.getLabelId());
while (indexes.hasNext()) {
NewIndexDescriptor index = indexes.next();
if (index.schema().equals(SchemaBoundary.map(descriptor))) {
if (null == result) {
result = index;
} else {
throw new DuplicateSchemaRuleException(SchemaRule.Kind.CONSTRAINT_INDEX_RULE, index.schema());
}
}
}
if (null == result) {
throw new SchemaRuleNotFoundException(SchemaRule.Kind.CONSTRAINT_INDEX_RULE, SchemaBoundary.map(descriptor));
}
return result;
}
use of org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException in project neo4j by neo4j.
the class SchemaStorage method constraintsGetSingle.
/**
* Get the constraint rule that matches the given ConstraintDescriptor
* @param descriptor the ConstraintDescriptor to match
* @return the matching ConstrainRule
* @throws SchemaRuleNotFoundException if no ConstraintRule matches the given descriptor
* @throws DuplicateSchemaRuleException if two or more ConstraintRules match the given descriptor
*/
public ConstraintRule constraintsGetSingle(final ConstraintDescriptor descriptor) throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
Iterator<ConstraintRule> rules = loadAllSchemaRules(descriptor::isSame, ConstraintRule.class, false);
if (!rules.hasNext()) {
throw new SchemaRuleNotFoundException(SchemaRule.Kind.map(descriptor), descriptor.schema());
}
ConstraintRule rule = rules.next();
if (rules.hasNext()) {
throw new DuplicateSchemaRuleException(SchemaRule.Kind.map(descriptor), descriptor.schema());
}
return rule;
}
Aggregations