mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-09 17:52:35 -05:00
Implicit Revert Row Cleanup Logic (#297)
This change enhances the way that edit/updateCell and edit/revertCell operations are performed. ## **THE API BREAKING CHANGES**: * edit/updateCell now returns an EditCell (a DbCellValue with a dirty flag) and a row dirty flag. * edit/revertCell now returns an EditCell (a DbCellValue with a dirty flag) and a row dirty flag. If by setting the value of a cell via edit/updateCell the row no longer has any edits (an "implicit revert"), the entire row's edit will be removed from the cache. Additionally, if by requesting edit/revert all the pending edits for a row are removed, the entire row's edit will be removed from the cache. This will prevent issues where committing will generate an invalid script because it has no pending changes. * Adding EditCell class Returning EditCell with EditUpdateCellResult * Adding code that will remove a row update if the row is clean after a cell update * Adding code that will return an EditCell and row dirty flag when a cell is reverted. If the row is reverted by the cell revert, the pending update will be removed * Comments for edit cell * Changes as per pull request comments
This commit is contained in:
@@ -308,7 +308,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
/// <param name="rowId">Internal ID of the row to have its edits reverted</param>
|
||||
/// <param name="columnId">Ordinal ID of the column to revert</param>
|
||||
/// <returns>String version of the old value for the cell</returns>
|
||||
public string RevertCell(long rowId, int columnId)
|
||||
public EditRevertCellResult RevertCell(long rowId, int columnId)
|
||||
{
|
||||
ThrowIfNotInitialized();
|
||||
|
||||
@@ -319,8 +319,12 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
throw new ArgumentOutOfRangeException(nameof(rowId), SR.EditDataUpdateNotPending);
|
||||
}
|
||||
|
||||
// Update the row
|
||||
EditRevertCellResult revertResult = pendingEdit.RevertCell(columnId);
|
||||
CleanupEditIfRowClean(rowId, revertResult);
|
||||
|
||||
// Have the edit base revert the cell
|
||||
return pendingEdit.RevertCell(columnId);
|
||||
return revertResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -410,8 +414,11 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
// doesn't already exist in the cache
|
||||
RowEditBase editRow = EditCache.GetOrAdd(rowId, key => new RowUpdate(rowId, associatedResultSet, objectMetadata));
|
||||
|
||||
// Pass the call to the row update
|
||||
return editRow.SetCell(columnId, newValue);
|
||||
// Update the row
|
||||
EditUpdateCellResult result = editRow.SetCell(columnId, newValue);
|
||||
CleanupEditIfRowClean(rowId, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -521,6 +528,24 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the edit from the edit cache if the row is no longer dirty
|
||||
/// </summary>
|
||||
/// <param name="rowId">ID of the update to cleanup</param>
|
||||
/// <param name="editCellResult">Result with row dirty flag</param>
|
||||
private void CleanupEditIfRowClean(long rowId, EditCellResult editCellResult)
|
||||
{
|
||||
// If the row is still dirty, don't do anything
|
||||
if (editCellResult.IsRowDirty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Make an attempt to remove the clean row edit. If this fails, it'll be handled on commit attempt.
|
||||
RowEditBase removedRow;
|
||||
EditCache.TryRemove(rowId, out removedRow);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user