Skip to content

Commit

Permalink
[Core] Ajout du type de flux "HardReplace"
Browse files Browse the repository at this point in the history
  • Loading branch information
gideruette committed Mar 21, 2024
1 parent 8767f5e commit 7574a46
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions TopModel.Core/Model/DataFlowType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public enum DataFlowType
/// </summary>
Replace,

/// <summary>
/// Remplacement des données (truncate cascade puis bulk insert).
/// </summary>
HardReplace,

/// <summary>
/// Fusion des données (bulk merge).
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions TopModel.Core/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@
"enum": [
"insert",
"replace",
"hardReplace",
"merge",
"mergeDisable"
]
Expand Down
8 changes: 4 additions & 4 deletions TopModel.Generator.Jpa/SpringDataFlowGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static void WriteBeanFlow(JavaWriter fw, DataFlow dataFlow)
fw.WriteLine();
fw.WriteLine(1, @$"@Bean(""{dataFlow.Name.ToPascalCase()}Flow"")");
fw.WriteLine(1, @$"public static Flow {dataFlow.Name.ToCamelCase()}Flow(");
if (dataFlow.Type == DataFlowType.Replace)
if (dataFlow.Type == DataFlowType.Replace || dataFlow.Type == DataFlowType.HardReplace)
{
fw.WriteLine(1, @$" @Qualifier(""{dataFlow.Name.ToPascalCase()}TruncateStep"") Step {dataFlow.Name.ToCamelCase()}TruncateStep,");
}
Expand All @@ -82,7 +82,7 @@ private static void WriteBeanFlow(JavaWriter fw, DataFlow dataFlow)
isFirst = false;
}

if (dataFlow.Type == DataFlowType.Replace)
if (dataFlow.Type == DataFlowType.Replace || dataFlow.Type == DataFlowType.HardReplace)
{
fw.WriteLine(3, @$".{(isFirst ? "start" : "next")}({dataFlow.Name.ToCamelCase()}TruncateStep) //");
fw.WriteLine(3, @$".next({dataFlow.Name.ToCamelCase()}Step) //");
Expand Down Expand Up @@ -112,7 +112,7 @@ private static void WriteBeanTruncateStep(JavaWriter fw, DataFlow dataFlow)
fw.AddImport("javax.sql.DataSource");
fw.WriteLine(1, @$" @Qualifier(""{dataFlow.Target}"") DataSource dataSource) {{");
fw.WriteLine(1, @$"return new StepBuilder(""{dataFlow.Name.ToPascalCase()}TruncateStep"", jobRepository) //");
fw.WriteLine(2, @$" .tasklet(new QueryTasklet(dataSource, ""truncate table {dataFlow.Class.SqlName}""), transactionManager) //");
fw.WriteLine(2, @$" .tasklet(new QueryTasklet(dataSource, ""truncate table {dataFlow.Class.SqlName}{(dataFlow.Type == DataFlowType.HardReplace ? " cascade" : string.Empty)}""), transactionManager) //");

fw.WriteLine(3, ".build();");
fw.WriteLine(1, "}");
Expand Down Expand Up @@ -315,7 +315,7 @@ private void WriteClassFlow(string fileName, DataFlow dataFlow, string tag)
WriteBeanFlow(fw, dataFlow);
WriteBeanStep(fw, dataFlow, tag);

if (dataFlow.Type == DataFlowType.Replace)
if (dataFlow.Type == DataFlowType.Replace || dataFlow.Type == DataFlowType.HardReplace)
{
WriteBeanTruncateStep(fw, dataFlow);
}
Expand Down
4 changes: 4 additions & 0 deletions docs/model/dataFlows.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Le flux de données doit insérer les éléments provenant de la source qui ne s
Le flux de données doit supprimer tous les éléments déjà existants, puis insérer les éléments provenant de la source.
### HardReplace
Le flux de données doit supprimer **en cascade** tous les éléments déjà existants, puis insérer les éléments provenant de la source.
### Merge-disable
Le comportement est le même que pour les flux de type merge, mais flux de données doit également effectuer une suppression logique (passer la propriété définie dans `activeProperty` à `false`) de tous les éléments qui ne font pas l'objet d'une mise à jour.
Expand Down

0 comments on commit 7574a46

Please sign in to comment.