private bool VisitIndexAddCommand(IndexCommand command, EntityId entityId) { try { CommitContext context = CommitContext(command); string key = _definitions.getKey(command.KeyId); object value = command.Value; // Below is a check for a null value where such a value is ignored. This may look strange, but the // reason is that there was this bug where adding a null value to an index would be fine and written // into the log as a command, to later fail during application of that command, i.e. here. // There was a fix introduced to throw IllegalArgumentException out to user right away if passing in // null or object that had toString() produce null. Although databases already affected by this would // not be able to recover, which is why this check is here. if (value != null) { context.EnsureWriterInstantiated(); context.IndexType.addToDocument(context.GetDocument(entityId, true).Document, key, value); } } catch (ExplicitIndexNotFoundKernelException) { // Pretend the index never existed. } return(false); }
public override bool VisitIndexRemoveCommand(IndexCommand.RemoveCommand command) { try { CommitContext context = CommitContext(command); string key = _definitions.getKey(command.KeyId); object value = command.Value; context.EnsureWriterInstantiated(); CommitContext.DocumentContext document = context.GetDocument(new IdData(command.EntityId), false); if (document != null) { context.IndexType.removeFromDocument(document.Document, key, value); } } catch (ExplicitIndexNotFoundKernelException) { // Pretend the index never existed. } return(false); }