| ... |
... |
@@ -23,6 +23,9 @@ package fr.ird.observe.services.local.service.actions.synchro.referential.sql; |
|
23
|
23
|
*/
|
|
24
|
24
|
|
|
25
|
25
|
import com.google.common.collect.ImmutableList;
|
|
|
26
|
+import fr.ird.observe.entities.referentiel.ObserveReferentialEntity;
|
|
|
27
|
+import fr.ird.observe.persistence.ObserveEntityEnum;
|
|
|
28
|
+import org.nuiton.topia.persistence.TopiaEntity;
|
|
26
|
29
|
import org.nuiton.topia.persistence.metadata.TopiaMetadataAssociation;
|
|
27
|
30
|
import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
|
|
28
|
31
|
import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
|
| ... |
... |
@@ -42,11 +45,13 @@ import java.util.Set; |
|
42
|
45
|
public class DeleteSqlStatementGenerator {
|
|
43
|
46
|
|
|
44
|
47
|
private final Set<TopiaMetadataAssociation> associations;
|
|
|
48
|
+ private final Set<TopiaMetadataAssociation> reverseAssociations;
|
|
45
|
49
|
private final TopiaMetadataEntity metadataEntity;
|
|
46
|
50
|
|
|
47
|
51
|
public DeleteSqlStatementGenerator(TopiaMetadataModel topiaMetadataModel, TopiaMetadataEntity metadataEntity) {
|
|
48
|
52
|
this.metadataEntity = Objects.requireNonNull(metadataEntity);
|
|
49
|
|
- this.associations = topiaMetadataModel.getReverseAssociations(metadataEntity);
|
|
|
53
|
+ this.associations = topiaMetadataModel.getAssociations(metadataEntity);
|
|
|
54
|
+ this.reverseAssociations = topiaMetadataModel.getReverseAssociations(metadataEntity);
|
|
50
|
55
|
}
|
|
51
|
56
|
|
|
52
|
57
|
public List<String> generateSql(String id) {
|
| ... |
... |
@@ -54,9 +59,19 @@ public class DeleteSqlStatementGenerator { |
|
54
|
59
|
String sql = TopiaSqlStatements.generateDeleteStatement(metadataEntity, id);
|
|
55
|
60
|
result.add(sql);
|
|
56
|
61
|
for (TopiaMetadataAssociation association : associations) {
|
|
57
|
|
- String sql2 = TopiaSqlStatements.generateAssociationDeleteStatement(association, id);
|
|
|
62
|
+ String sql2 = TopiaSqlStatements.generateManyToManyAssociationDeleteStatement(association, id);
|
|
58
|
63
|
result.add(TopiaSqlStatements.boxAssociationStatement(sql2));
|
|
59
|
64
|
}
|
|
|
65
|
+ for (TopiaMetadataAssociation association : reverseAssociations) {
|
|
|
66
|
+ Class<? extends TopiaEntity> entityType = ObserveEntityEnum.valueOf(association.getOwner().getType()).getContract();
|
|
|
67
|
+ if (ObserveReferentialEntity.class.isAssignableFrom(entityType)) {
|
|
|
68
|
+ // always delete referential associations
|
|
|
69
|
+ // this is the opposite of https://gitlab.com/ultreiaio/ird-observe/issues/1065
|
|
|
70
|
+ // See https://gitlab.com/ultreiaio/ird-observe/issues/11270
|
|
|
71
|
+ String sql2 = TopiaSqlStatements.generateAssociationDeleteStatement(association, id);
|
|
|
72
|
+ result.add(TopiaSqlStatements.boxAssociationStatement(sql2));
|
|
|
73
|
+ }
|
|
|
74
|
+ }
|
|
60
|
75
|
return result.build();
|
|
61
|
76
|
}
|
|
62
|
77
|
|