private void createConstraintRule(UniquenessConstraint constraint) { // TODO: Do not create duplicate index SchemaStore schemaStore = getSchemaStore(); long indexRuleId = schemaStore.nextId(); long constraintRuleId = schemaStore.nextId(); IndexRule indexRule = IndexRule.constraintIndexRule( indexRuleId, constraint.label(), constraint.propertyKeyId(), this.schemaIndexProviders.getDefaultProvider().getProviderDescriptor(), constraintRuleId); UniquenessConstraintRule constraintRule = UniquenessConstraintRule.uniquenessConstraintRule( constraintRuleId, constraint.label(), constraint.propertyKeyId(), indexRuleId); for (DynamicRecord record : schemaStore.allocateFrom(constraintRule)) { schemaStore.updateRecord(record); } schemaCache.addSchemaRule(constraintRule); for (DynamicRecord record : schemaStore.allocateFrom(indexRule)) { schemaStore.updateRecord(record); } schemaCache.addSchemaRule(indexRule); labelsTouched = true; recordAccess.commit(); }
private void showUniqueConstraints( DbStructureVisitor visitor, ReadOperations read, TokenNameLookup nameLookup) { Iterator<UniquenessConstraint> constraints = read.constraintsGetAll(); while (constraints.hasNext()) { UniquenessConstraint constraint = constraints.next(); String userDescription = constraint.userDescription(nameLookup); visitor.visitUniqueConstraint(constraint, userDescription); } }
@Override public boolean constraintDoUnRemove(UniquenessConstraint constraint) { // hasChanges should already be set correctly when this is called if (constraintsChanges().unRemove(constraint)) { constraintIndexChanges.unRemove( new IndexDescriptor(constraint.label(), constraint.propertyKeyId())); return true; } return false; }
@Override public String getUserMessage(TokenNameLookup tokenNameLookup) { StringBuilder message = new StringBuilder(); for (Evidence evidenceItem : evidence()) { IndexEntryConflictException conflict = evidenceItem.conflict; message.append( conflict.evidenceMessage( tokenNameLookup.labelGetName(constraint.label()), tokenNameLookup.propertyKeyGetName(constraint.propertyKeyId()))); } return message.toString(); }
@Override public void constraintDoDrop(UniquenessConstraint constraint) { if (constraintsChanges().remove(constraint)) { createdConstraintIndexesByConstraint().remove(constraint); // TODO: someone needs to make sure that the index we created gets dropped. // I think this can wait until commit/rollback, but we need to be able to know that the index // was created... } constraintIndexDoDrop(new IndexDescriptor(constraint.label(), constraint.propertyKeyId())); constraintsChangesForLabel(constraint.label()).remove(constraint); hasChanges = true; }
@Override public void constraintDoAdd(UniquenessConstraint constraint, long indexId) { constraintsChanges().add(constraint); createdConstraintIndexesByConstraint().put(constraint, indexId); getOrCreateLabelState(constraint.label()).constraintsChanges().add(constraint); hasChanges = true; }