Skip to content

Comments

Feature/rm 9639 batched save command factory#1404

Open
Mario185 wants to merge 2 commits intodevelopfrom
feature/RM-9639-BatchedSaveCommandFactory
Open

Feature/rm 9639 batched save command factory#1404
Mario185 wants to merge 2 commits intodevelopfrom
feature/RM-9639-BatchedSaveCommandFactory

Conversation

@Mario185
Copy link
Contributor

refactored MultiDataContainerSaveCommand so it does not longer use Tuple<ObjectID,IDBCommandBuilder> but insted uses the new MultiDataContainerSaveCommandContext
@Mario185 Mario185 requested a review from a-ctor February 23, 2026 07:48
Comment on lines +72 to +91
private IEnumerable<SingleObjectMultiDataContainerSaveCommandContext> CreateDbCommandsForSave (IEnumerable<DataContainer> dataContainers)
{
var insertCommands = new List<Tuple<ObjectID, IDbCommandBuilder>>();
var updateCommands = new List<Tuple<ObjectID, IDbCommandBuilder>>();
var deleteCommands = new List<Tuple<ObjectID, IDbCommandBuilder>>();
var insertCommands = new List<SingleObjectMultiDataContainerSaveCommandContext>();
var updateCommands = new List<SingleObjectMultiDataContainerSaveCommandContext>();
var deleteCommands = new List<SingleObjectMultiDataContainerSaveCommandContext>();

foreach (var dataContainer in dataContainers)
{
var tableDefinition = _tableDefinitionFinder.GetTableDefinition(dataContainer.ID);

if (ShouldCreateInsertCommand(dataContainer))
insertCommands.Add(Tuple.Create(dataContainer.ID, CreateDbCommandForInsert(dataContainer, tableDefinition)));
insertCommands.Add(new SingleObjectMultiDataContainerSaveCommandContext(dataContainer.ID, CreateDbCommandForInsert(dataContainer, tableDefinition)));
if (ShouldCreateDeleteCommand(dataContainer))
deleteCommands.Add(Tuple.Create(dataContainer.ID, CreateDbCommandForDelete(dataContainer, tableDefinition)));
deleteCommands.Add(new SingleObjectMultiDataContainerSaveCommandContext(dataContainer.ID, CreateDbCommandForDelete(dataContainer, tableDefinition)));

var updatedColumnValues = GetUpdatedColumnValues(dataContainer, tableDefinition).ToArray();
if (updatedColumnValues.Any())
{
var dbCommandForUpdate = CreateDbCommandForUpdate(dataContainer, tableDefinition, updatedColumnValues);
updateCommands.Add(Tuple.Create(dataContainer.ID, dbCommandForUpdate));
updateCommands.Add(new SingleObjectMultiDataContainerSaveCommandContext(dataContainer.ID, dbCommandForUpdate));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer copying the MultiDataContainerSaveCommand and keeping this code as is. By keeping the new code separate we ensure that the working, battle tested, code is not lost and if a project falls back to the individual strategy it works like it does today. This also gives us a bit more freedom for refactoring the command once we implemented batching (because then we don't need the command context abstraction anymore).

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants