Skip to content

Commit

Permalink
Merge pull request #26 from dynamicweb/mss/19895
Browse files Browse the repository at this point in the history
added logic for setting rowsAffected and handling of empty values for…
  • Loading branch information
dw-sha authored Aug 1, 2024
2 parents cf167ac + 6596430 commit 7f6d043
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.16</Version>
<Version>10.6.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Order Provider</Title>
<Description>Order Provider</Description>
Expand All @@ -14,7 +14,7 @@
<Copyright>Copyright © 2023 Dynamicweb Software A/S</Copyright>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand All @@ -23,8 +23,8 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.0.17" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.0.9" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.6.3" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.6.3" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/OrderDestinationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal void FinishWriting()
}
}

internal void MoveDataToMainTable(SqlTransaction sqlTransaction, bool updateOnlyExistingRecords, bool insertOnlyNewRecords) =>
internal int MoveDataToMainTable(SqlTransaction sqlTransaction, bool updateOnlyExistingRecords, bool insertOnlyNewRecords) =>
MoveDataToMainTable(Mapping, SqlCommand, sqlTransaction, TempTablePrefix, updateOnlyExistingRecords, insertOnlyNewRecords);

public new void Write(Dictionary<string, object> row)
Expand All @@ -102,7 +102,7 @@ internal void MoveDataToMainTable(SqlTransaction sqlTransaction, bool updateOnly
}
else
{
Logger.Info(BaseDestinationWriter.GetRowValueNotFoundMessage(row, columnMapping.SourceColumn.Table.Name, columnMapping.SourceColumn.Name));
Logger.Info(GetRowValueNotFoundMessage(row, columnMapping.SourceColumn.Table.Name, columnMapping.SourceColumn.Name));
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/OrderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@ public override bool RunJob(Job job)
while (!reader.IsDone())
{
sourceRow = reader.GetNext();
ProcessInputRow(mapping, sourceRow);
ProcessRow(mapping, columnMappings, sourceRow);
writer.Write(sourceRow);
if (ProcessInputRow(sourceRow, mapping))
{
ProcessRow(mapping, columnMappings, sourceRow);
writer.Write(sourceRow);
}
}
writer.FinishWriting();
writers.Add(writer);
Expand All @@ -375,7 +377,7 @@ public override bool RunJob(Job job)
sqlTransaction = Connection.BeginTransaction();
foreach (OrderDestinationWriter writer in writers)
{
writer.MoveDataToMainTable(sqlTransaction, false, false);
TotalRowsAffected += writer.MoveDataToMainTable(sqlTransaction, false, false);
}

RemoveMissingRows(writers, sqlTransaction);
Expand All @@ -396,6 +398,9 @@ public override bool RunJob(Job job)
Logger.Log("Import job failed: " + msg);
if (sqlTransaction != null)
sqlTransaction.Rollback();

TotalRowsAffected = 0;

return false;
}
finally
Expand Down Expand Up @@ -546,7 +551,7 @@ private void RemoveMissingRows(IEnumerable<OrderDestinationWriter> writers, SqlT
writer.SqlCommand.CommandText = $"DELETE FROM EcomOrderLines WHERE OrderLineID NOT IN (SELECT OrderLineID FROM {tempTableName}) " +
$"AND OrderLineOrderID IN(SELECT DISTINCT(OrderLineOrderID) FROM EcomOrderLines WHERE OrderLineID IN(SELECT OrderLineID FROM {tempTableName}))";
}
writer.SqlCommand.ExecuteNonQuery();
TotalRowsAffected += writer.SqlCommand.ExecuteNonQuery();
}
}
}
Expand Down

0 comments on commit 7f6d043

Please sign in to comment.