use of org.neo4j.internal.kernel.api.exceptions.schema.DuplicateSchemaRuleException in project neo4j by neo4j.
the class TransactionToRecordStateVisitor method visitRemovedConstraint.
@Override
public void visitRemovedConstraint(ConstraintDescriptor constraint) {
clearSchemaState = true;
try {
ConstraintDescriptor rule = schemaStorage.constraintsGetSingle(constraint, cursorContext);
schemaStateChanger.dropSchemaRule(recordState, rule);
if (constraint.enforcesUniqueness()) {
// Remove the index for the constraint as well
IndexDescriptor[] indexes = schemaStorage.indexGetForSchema(constraint.schema(), cursorContext);
for (IndexDescriptor index : indexes) {
OptionalLong owningConstraintId = index.getOwningConstraintId();
if (owningConstraintId.isPresent() && owningConstraintId.getAsLong() == rule.getId()) {
visitRemovedIndex(index);
}
// Note that we _could_ also go through all the matching indexes that have isUnique == true and no owning constraint id, and remove those
// as well. These might be orphaned indexes from failed constraint creations. However, since we want to allow multiple indexes and
// constraints on the same schema, they could also be constraint indexes that are currently populating for other constraints, and if that's
// the case, then we cannot remove them, since that would ruin the constraint they are being built for.
}
}
} catch (SchemaRuleNotFoundException e) {
throw new IllegalStateException("Constraint to be removed should exist, since its existence should have been validated earlier " + "and the schema should have been locked.", e);
} catch (DuplicateSchemaRuleException e) {
throw new IllegalStateException("Multiple constraints found for specified label and property.", e);
}
}
use of org.neo4j.internal.kernel.api.exceptions.schema.DuplicateSchemaRuleException in project neo4j by neo4j.
the class SchemaImpl method getIndexReference.
private static IndexDescriptor getIndexReference(SchemaRead schemaRead, TokenRead tokenRead, IndexDefinitionImpl index) throws SchemaRuleException {
// Use the precise embedded index reference when available.
IndexDescriptor reference = index.getIndexReference();
if (reference != null) {
return reference;
}
// Otherwise attempt to reverse engineer the schema that will let us look up the real IndexReference.
int[] propertyKeyIds = resolveAndValidatePropertyKeys(tokenRead, index.getPropertyKeysArrayShared());
SchemaDescriptor schema;
if (index.isNodeIndex()) {
int[] labelIds = resolveAndValidateTokens("Label", index.getLabelArrayShared(), Label::name, tokenRead::nodeLabel);
if (index.isMultiTokenIndex()) {
schema = fulltext(EntityType.NODE, labelIds, propertyKeyIds);
} else if (index.getIndexType() == IndexType.LOOKUP) {
schema = forAnyEntityTokens(EntityType.NODE);
} else {
schema = forLabel(labelIds[0], propertyKeyIds);
}
} else if (index.isRelationshipIndex()) {
int[] relTypes = resolveAndValidateTokens("Relationship type", index.getRelationshipTypesArrayShared(), RelationshipType::name, tokenRead::relationshipType);
if (index.isMultiTokenIndex()) {
schema = fulltext(EntityType.RELATIONSHIP, relTypes, propertyKeyIds);
} else if (index.getIndexType() == IndexType.LOOKUP) {
schema = forAnyEntityTokens(EntityType.RELATIONSHIP);
} else {
schema = forRelType(relTypes[0], propertyKeyIds);
}
} else {
throw new IllegalArgumentException("The given index is neither a node index, nor a relationship index: " + index + ".");
}
Iterator<IndexDescriptor> iterator = schemaRead.index(schema);
if (!iterator.hasNext()) {
throw new SchemaRuleNotFoundException(schema, tokenRead);
}
reference = iterator.next();
if (iterator.hasNext()) {
throw new DuplicateSchemaRuleException(schema, tokenRead);
}
return reference;
}
Aggregations