Search in sources :

Example 1 with DuplicateSchemaRuleException

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;
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) DuplicateSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException)

Example 2 with DuplicateSchemaRuleException

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;
}
Also used : ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) DuplicateSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException)

Aggregations

DuplicateSchemaRuleException (org.neo4j.kernel.api.exceptions.schema.DuplicateSchemaRuleException)2 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)1