Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
d0cee04c
by Tony Chemit at 2020-12-22T19:35:16+01:00
-
17341bb8
by Tony Chemit at 2020-12-22T19:37:31+01:00
-
1acf1864
by Tony Chemit at 2020-12-22T19:37:38+01:00
8 changed files:
- models/persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaApplicationContext.java
- models/persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaEntitySqlModelSupportImpl.java
- server/core/src/main/filtered-resources/mapping
- services/api/src/main/java/fr/ird/observe/services/service/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeEngine.java
- services/api/src/main/java/fr/ird/observe/services/service/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeLocalService.java
- services/api/src/main/java/fr/ird/observe/services/service/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeResult.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeLocalServiceLocal.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/sql/ReplaceSqlStatementGenerator.java
Changes:
| ... | ... | @@ -22,6 +22,8 @@ package fr.ird.observe.entities; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
+import com.google.common.collect.ImmutableSet;
|
|
| 26 |
+import fr.ird.observe.dto.referential.ReferentialDto;
|
|
| 25 | 27 |
import org.apache.logging.log4j.LogManager;
|
| 26 | 28 |
import org.apache.logging.log4j.Logger;
|
| 27 | 29 |
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
| ... | ... | @@ -165,6 +167,10 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat |
| 165 | 167 |
return getTopiaEntitySqlModelSupport().getSqlModel();
|
| 166 | 168 |
}
|
| 167 | 169 |
|
| 170 |
+ public ImmutableSet<Class<? extends ReferentialDto>> referentialForReplicationDto() {
|
|
| 171 |
+ return getTopiaEntitySqlModelSupport().referentialForReplicationDto();
|
|
| 172 |
+ }
|
|
| 173 |
+ |
|
| 168 | 174 |
@Override
|
| 169 | 175 |
public boolean equals(Object o) {
|
| 170 | 176 |
if (this == o) return true;
|
| ... | ... | @@ -22,7 +22,12 @@ package fr.ird.observe.entities; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
+import com.google.common.collect.ImmutableSet;
|
|
| 26 |
+import fr.ird.observe.dto.referential.ReferentialDto;
|
|
| 25 | 27 |
import fr.ird.observe.entities.referential.ReferentialEntity;
|
| 28 |
+import fr.ird.observe.spi.PersistenceBusinessProject;
|
|
| 29 |
+import fr.ird.observe.spi.context.ReferentialDtoEntityContext;
|
|
| 30 |
+import io.ultreia.java4all.lang.Objects2;
|
|
| 26 | 31 |
import org.nuiton.topia.persistence.metadata.sql.TopiaEntitySqlDescriptor;
|
| 27 | 32 |
import org.nuiton.topia.persistence.metadata.sql.TopiaEntitySqlDescriptors;
|
| 28 | 33 |
|
| ... | ... | @@ -34,6 +39,8 @@ import org.nuiton.topia.persistence.metadata.sql.TopiaEntitySqlDescriptors; |
| 34 | 39 |
*/
|
| 35 | 40 |
public class ObserveTopiaEntitySqlModelSupportImpl extends ObserveTopiaEntitySqlModelSupport {
|
| 36 | 41 |
|
| 42 |
+ private ImmutableSet<Class<? extends ReferentialDto>> referentialForReplication;
|
|
| 43 |
+ |
|
| 37 | 44 |
public TopiaEntitySqlDescriptors dataPsTripForReplication() {
|
| 38 | 45 |
return getSqlModel().getReplicationOrderByEntryPointDescriptors(fr.ird.observe.entities.data.ps.common.Trip.class.getName());
|
| 39 | 46 |
}
|
| ... | ... | @@ -64,4 +71,21 @@ public class ObserveTopiaEntitySqlModelSupportImpl extends ObserveTopiaEntitySql |
| 64 | 71 |
return getSqlModel().getDescriptor(fqn);
|
| 65 | 72 |
}
|
| 66 | 73 |
|
| 74 |
+ @SuppressWarnings({"rawtypes", "unchecked"})
|
|
| 75 |
+ public ImmutableSet<Class<? extends ReferentialDto>> referentialForReplicationDto() {
|
|
| 76 |
+ if (referentialForReplication == null) {
|
|
| 77 |
+ ImmutableSet.Builder<Class<? extends ReferentialDto>> builder = ImmutableSet.builder();
|
|
| 78 |
+ for (TopiaEntitySqlDescriptor descriptor : getSqlModel().getReplicationOrderWithStandaloneDescriptors()) {
|
|
| 79 |
+ String entityName = descriptor.getTable().getEntityName();
|
|
| 80 |
+ Class<? extends ReferentialEntity> entityType = Objects2.forName(entityName);
|
|
| 81 |
+ ReferentialDtoEntityContext spi = PersistenceBusinessProject.fromReferentialEntity(entityType);
|
|
| 82 |
+ if (spi != null) {
|
|
| 83 |
+ Class<? extends ReferentialDto> dtoType = spi.toDtoType();
|
|
| 84 |
+ builder.add(dtoType);
|
|
| 85 |
+ }
|
|
| 86 |
+ }
|
|
| 87 |
+ referentialForReplication = builder.build();
|
|
| 88 |
+ }
|
|
| 89 |
+ return referentialForReplication;
|
|
| 90 |
+ }
|
|
| 67 | 91 |
}
|
| ... | ... | @@ -81,6 +81,7 @@ POST /api/v1/actions/synchro/referential/legacy/UnidirectionalReferentialSynch |
| 81 | 81 |
GET /api/v1/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeLocalService/filterIdsUsedInLocalSource v1.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeLocalServiceRestApi.filterIdsUsedInLocalSource
|
| 82 | 82 |
GET /api/v1/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeLocalService/generateSqlRequests v1.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeLocalServiceRestApi.generateSqlRequests
|
| 83 | 83 |
GET /api/v1/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeLocalService/getLocalSourceReferentialToDelete v1.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeLocalServiceRestApi.getLocalSourceReferentialToDelete
|
| 84 |
+GET /api/v1/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeLocalService/referentialReplicationOrder v1.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeLocalServiceRestApi.referentialReplicationOrder
|
|
| 84 | 85 |
POST /api/v1/actions/synchro/referential/legacy/UnidirectionalReferentialSynchronizeLocalService/updateLastUpdateDates v1.actions.synchro.referential.legacy.UnidirectionalReferentialSynchronizeLocalServiceRestApi.updateLastUpdateDates
|
| 85 | 86 |
POST /api/v1/actions/synchro/referential/ng/ReferentialSynchronizeService/executeSqlListRequest v1.actions.synchro.referential.ng.ReferentialSynchronizeServiceRestApi.executeSqlListRequest
|
| 86 | 87 |
POST /api/v1/actions/synchro/referential/ng/ReferentialSynchronizeService/produceSqlListRequest v1.actions.synchro.referential.ng.ReferentialSynchronizeServiceRestApi.produceSqlListRequest
|
| ... | ... | @@ -78,6 +78,8 @@ public class UnidirectionalReferentialSynchronizeEngine { |
| 78 | 78 |
.addAll(rightDiffStates.keySet())
|
| 79 | 79 |
.build();
|
| 80 | 80 |
|
| 81 |
+ ImmutableSet<Class<? extends ReferentialDto>> replicationOrder = localService.referentialReplicationOrder();
|
|
| 82 |
+ |
|
| 81 | 83 |
ImmutableSet.Builder<UnidirectionalReferentialSynchronizeRequest.Builder<?>> referentialSynchronizeRequestBuilders = ImmutableSet.builder();
|
| 82 | 84 |
|
| 83 | 85 |
UnidirectionalReferentialSynchronizeCallbackRequests callbackRequests = new UnidirectionalReferentialSynchronizeCallbackRequests();
|
| ... | ... | @@ -86,7 +88,7 @@ public class UnidirectionalReferentialSynchronizeEngine { |
| 86 | 88 |
|
| 87 | 89 |
ObserveBusinessProject businessProject = ObserveBusinessProject.get();
|
| 88 | 90 |
|
| 89 |
- for (Class<? extends ReferentialDto> dtoType : businessProject.getReferentialTypes()) {
|
|
| 91 |
+ for (Class<? extends ReferentialDto> dtoType : replicationOrder) {
|
|
| 90 | 92 |
|
| 91 | 93 |
if (types.contains(dtoType)) {
|
| 92 | 94 |
@SuppressWarnings("rawtypes") DtoReferenceDefinition referentialDefinition = businessProject.getOptionalReferenceDefinition(dtoType).orElseThrow(IllegalStateException::new);
|
| ... | ... | @@ -141,7 +143,7 @@ public class UnidirectionalReferentialSynchronizeEngine { |
| 141 | 143 |
|
| 142 | 144 |
result.flushRequest(referentialSynchronizeRequest);
|
| 143 | 145 |
|
| 144 |
- Set<String> generatedSqlRequests = localService.generateSqlRequests(referentialSynchronizeRequest);
|
|
| 146 |
+ List<String> generatedSqlRequests = localService.generateSqlRequests(referentialSynchronizeRequest);
|
|
| 145 | 147 |
for (String sqlStatement : generatedSqlRequests) {
|
| 146 | 148 |
|
| 147 | 149 |
if (sqlStatement.startsWith("INSERT")) {
|
| ... | ... | @@ -22,6 +22,7 @@ package fr.ird.observe.services.service.actions.synchro.referential.legacy; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
+import com.google.common.collect.ImmutableList;
|
|
| 25 | 26 |
import com.google.common.collect.ImmutableSet;
|
| 26 | 27 |
import fr.ird.observe.dto.reference.ReferentialDtoReference;
|
| 27 | 28 |
import fr.ird.observe.dto.reference.ReferentialDtoReferenceSet;
|
| ... | ... | @@ -43,6 +44,14 @@ import io.ultreia.java4all.http.spi.Post; |
| 43 | 44 |
*/
|
| 44 | 45 |
public interface UnidirectionalReferentialSynchronizeLocalService extends ObserveService {
|
| 45 | 46 |
|
| 47 |
+ /**
|
|
| 48 |
+ * @return the replication order to insert data
|
|
| 49 |
+ * @since 8.0.2
|
|
| 50 |
+ */
|
|
| 51 |
+ @MethodCredential(Permission.READ_REFERENTIAL)
|
|
| 52 |
+ @Get
|
|
| 53 |
+ ImmutableSet<Class<? extends ReferentialDto>> referentialReplicationOrder();
|
|
| 54 |
+ |
|
| 46 | 55 |
/**
|
| 47 | 56 |
* Pour un référentiel d'un type donné (son nom est donné), détecte les référentiels dont
|
| 48 | 57 |
* les identifiants sont passés en paramètres qui sont réellement utilisés dans la source locale.
|
| ... | ... | @@ -73,16 +82,16 @@ public interface UnidirectionalReferentialSynchronizeLocalService extends Observ |
| 73 | 82 |
*
|
| 74 | 83 |
* @param <D> type des référentiels à traiter
|
| 75 | 84 |
* @param request la demande des actions à produire pour un référentiel donné
|
| 76 |
- * @return l'ensemble des requètes sql à appliquer.
|
|
| 85 |
+ * @return l'ensemble des requêtes sql à appliquer.
|
|
| 77 | 86 |
*/
|
| 78 | 87 |
@MethodCredential(Permission.READ_REFERENTIAL)
|
| 79 | 88 |
@Get
|
| 80 |
- <D extends ReferentialDto> ImmutableSet<String> generateSqlRequests(UnidirectionalReferentialSynchronizeRequest<D> request);
|
|
| 89 |
+ <D extends ReferentialDto> ImmutableList<String> generateSqlRequests(UnidirectionalReferentialSynchronizeRequest<D> request);
|
|
| 81 | 90 |
|
| 82 | 91 |
/**
|
| 83 |
- * Pour appliquer les requètes sql de mise à jour du réferentiel.
|
|
| 92 |
+ * Pour appliquer les requêtes sql de mise à jour du référentiel.
|
|
| 84 | 93 |
*
|
| 85 |
- * @param sqlRequests les requètes sql à appliquer
|
|
| 94 |
+ * @param sqlRequests les requêtes sql à appliquer
|
|
| 86 | 95 |
*/
|
| 87 | 96 |
@MethodCredential(Permission.READ_REFERENTIAL)
|
| 88 | 97 |
//FIXME::Security Il faut introduire une nouvelle permission EditReferentialPermission et ici bien utiliser WriteReferentialPermission
|
| ... | ... | @@ -23,14 +23,12 @@ package fr.ird.observe.services.service.actions.synchro.referential.legacy; |
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 | 25 |
import com.google.common.collect.ArrayListMultimap;
|
| 26 |
-import com.google.common.collect.Multimap;
|
|
| 27 | 26 |
import fr.ird.observe.dto.ObserveDto;
|
| 28 | 27 |
import fr.ird.observe.dto.referential.ReferentialDto;
|
| 29 | 28 |
import org.apache.commons.lang3.tuple.Pair;
|
| 30 | 29 |
|
| 31 |
-import java.util.Collection;
|
|
| 32 | 30 |
import java.util.LinkedHashSet;
|
| 33 |
-import java.util.Map;
|
|
| 31 |
+import java.util.List;
|
|
| 34 | 32 |
import java.util.Set;
|
| 35 | 33 |
|
| 36 | 34 |
/**
|
| ... | ... | @@ -44,10 +42,10 @@ import java.util.Set; |
| 44 | 42 |
public class UnidirectionalReferentialSynchronizeResult implements ObserveDto {
|
| 45 | 43 |
|
| 46 | 44 |
private final Set<Class<? extends ReferentialDto>> referentialNames;
|
| 47 |
- private final Multimap<Class<? extends ReferentialDto>, String> referentialAdded;
|
|
| 48 |
- private final Multimap<Class<? extends ReferentialDto>, String> referentialUpdated;
|
|
| 49 |
- private final Multimap<Class<? extends ReferentialDto>, Pair<String, String>> referentialReplaced;
|
|
| 50 |
- private final Multimap<Class<? extends ReferentialDto>, String> referentialRemoved;
|
|
| 45 |
+ private final ArrayListMultimap<Class<? extends ReferentialDto>, String> referentialAdded;
|
|
| 46 |
+ private final ArrayListMultimap<Class<? extends ReferentialDto>, String> referentialUpdated;
|
|
| 47 |
+ private final ArrayListMultimap<Class<? extends ReferentialDto>, Pair<String, String>> referentialReplaced;
|
|
| 48 |
+ private final ArrayListMultimap<Class<? extends ReferentialDto>, String> referentialRemoved;
|
|
| 51 | 49 |
|
| 52 | 50 |
public UnidirectionalReferentialSynchronizeResult() {
|
| 53 | 51 |
this.referentialNames = new LinkedHashSet<>();
|
| ... | ... | @@ -65,58 +63,36 @@ public class UnidirectionalReferentialSynchronizeResult implements ObserveDto { |
| 65 | 63 |
return referentialNames;
|
| 66 | 64 |
}
|
| 67 | 65 |
|
| 68 |
- public Collection<String> getReferentialAdded(Class<? extends ReferentialDto> referentialName) {
|
|
| 66 |
+ public List<String> getReferentialAdded(Class<? extends ReferentialDto> referentialName) {
|
|
| 69 | 67 |
return referentialAdded.get(referentialName);
|
| 70 | 68 |
}
|
| 71 | 69 |
|
| 72 |
- public Collection<String> getReferentialUpdated(Class<? extends ReferentialDto> referentialName) {
|
|
| 70 |
+ public List<String> getReferentialUpdated(Class<? extends ReferentialDto> referentialName) {
|
|
| 73 | 71 |
return referentialUpdated.get(referentialName);
|
| 74 | 72 |
}
|
| 75 | 73 |
|
| 76 |
- public Collection<Pair<String, String>> getReferentialReplaced(Class<? extends ReferentialDto> referentialName) {
|
|
| 74 |
+ public List<Pair<String, String>> getReferentialReplaced(Class<? extends ReferentialDto> referentialName) {
|
|
| 77 | 75 |
return referentialReplaced.get(referentialName);
|
| 78 | 76 |
}
|
| 79 | 77 |
|
| 80 |
- public Collection<String> getReferentialRemoved(Class<? extends ReferentialDto> referentialName) {
|
|
| 78 |
+ public List<String> getReferentialRemoved(Class<? extends ReferentialDto> referentialName) {
|
|
| 81 | 79 |
return referentialRemoved.get(referentialName);
|
| 82 | 80 |
}
|
| 83 | 81 |
|
| 84 | 82 |
void flushRequest(UnidirectionalReferentialSynchronizeRequest<?> referentialSynchronizeRequest) {
|
| 85 |
- |
|
| 86 | 83 |
Class<? extends ReferentialDto> referentialName = referentialSynchronizeRequest.getReferentialName();
|
| 87 |
- |
|
| 88 | 84 |
if (referentialSynchronizeRequest.withReferentialToAdd()) {
|
| 89 |
- |
|
| 90 |
- for (ReferentialDto referentialDto : referentialSynchronizeRequest.getReferentialToAdd()) {
|
|
| 91 |
- addReferentialAdded(referentialName, referentialDto.getId());
|
|
| 92 |
- }
|
|
| 93 |
- |
|
| 85 |
+ referentialSynchronizeRequest.getReferentialToAdd().forEach(referentialDto -> addReferentialAdded(referentialName, referentialDto.getId()));
|
|
| 94 | 86 |
}
|
| 95 |
- |
|
| 96 | 87 |
if (referentialSynchronizeRequest.withReferentialToUpdate()) {
|
| 97 |
- |
|
| 98 |
- for (ReferentialDto referentialDto : referentialSynchronizeRequest.getReferentialToUpdate()) {
|
|
| 99 |
- addReferentialUpdated(referentialName, referentialDto.getId());
|
|
| 100 |
- }
|
|
| 101 |
- |
|
| 88 |
+ referentialSynchronizeRequest.getReferentialToUpdate().forEach(referentialDto -> addReferentialUpdated(referentialName, referentialDto.getId()));
|
|
| 102 | 89 |
}
|
| 103 |
- |
|
| 104 | 90 |
if (referentialSynchronizeRequest.withReferentialToRemove()) {
|
| 105 |
- |
|
| 106 |
- for (String id : referentialSynchronizeRequest.getReferentialToRemove()) {
|
|
| 107 |
- addReferentialRemoved(referentialName, id);
|
|
| 108 |
- }
|
|
| 109 |
- |
|
| 91 |
+ referentialSynchronizeRequest.getReferentialToRemove().forEach(id -> addReferentialRemoved(referentialName, id));
|
|
| 110 | 92 |
}
|
| 111 |
- |
|
| 112 | 93 |
if (referentialSynchronizeRequest.withReferentialToReplace()) {
|
| 113 |
- |
|
| 114 |
- for (Map.Entry<String, String> entry : referentialSynchronizeRequest.getReferentialToReplace().entrySet()) {
|
|
| 115 |
- addReferentialReplaced(referentialName, entry.getKey(), entry.getValue());
|
|
| 116 |
- }
|
|
| 117 |
- |
|
| 94 |
+ referentialSynchronizeRequest.getReferentialToReplace().forEach((key, value) -> addReferentialReplaced(referentialName, key, value));
|
|
| 118 | 95 |
}
|
| 119 |
- |
|
| 120 | 96 |
}
|
| 121 | 97 |
|
| 122 | 98 |
private void addReferentialAdded(Class<? extends ReferentialDto> referentialName, String id) {
|
| ... | ... | @@ -32,7 +32,6 @@ import fr.ird.observe.entities.ObserveEntityEnum; |
| 32 | 32 |
import fr.ird.observe.entities.referential.ReferentialEntity;
|
| 33 | 33 |
import fr.ird.observe.services.local.ObserveServiceContextLocal;
|
| 34 | 34 |
import fr.ird.observe.services.local.service.ObserveServiceLocal;
|
| 35 |
-import fr.ird.observe.services.local.service.actions.synchro.referential.sql.ApplySqlRequestWork;
|
|
| 36 | 35 |
import fr.ird.observe.services.local.service.actions.synchro.referential.sql.DeleteSqlStatementGenerator;
|
| 37 | 36 |
import fr.ird.observe.services.local.service.actions.synchro.referential.sql.InsertSqlStatementGenerator;
|
| 38 | 37 |
import fr.ird.observe.services.local.service.actions.synchro.referential.sql.ReplaceSqlStatementGenerator;
|
| ... | ... | @@ -45,12 +44,18 @@ import fr.ird.observe.services.service.usage.DtoUsageCountResult; |
| 45 | 44 |
import fr.ird.observe.services.service.usage.UsageService;
|
| 46 | 45 |
import fr.ird.observe.spi.ObservePersistenceBusinessProject;
|
| 47 | 46 |
import fr.ird.observe.spi.context.ReferentialDtoEntityContext;
|
| 47 |
+import org.apache.logging.log4j.LogManager;
|
|
| 48 |
+import org.apache.logging.log4j.Logger;
|
|
| 48 | 49 |
import org.nuiton.topia.persistence.TopiaDao;
|
| 49 | 50 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
|
| 50 | 51 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
|
| 51 |
-import org.nuiton.topia.persistence.support.TopiaSqlWork;
|
|
| 52 |
+import org.nuiton.topia.persistence.script.SqlScriptReader;
|
|
| 53 |
+import org.nuiton.topia.persistence.script.TopiaSqlScript;
|
|
| 52 | 54 |
|
| 55 |
+import java.io.IOException;
|
|
| 56 |
+import java.nio.file.Path;
|
|
| 53 | 57 |
import java.util.LinkedHashSet;
|
| 58 |
+import java.util.LinkedList;
|
|
| 54 | 59 |
import java.util.List;
|
| 55 | 60 |
import java.util.Map;
|
| 56 | 61 |
import java.util.Set;
|
| ... | ... | @@ -62,6 +67,7 @@ import java.util.Set; |
| 62 | 67 |
* @since 5.0
|
| 63 | 68 |
*/
|
| 64 | 69 |
public class UnidirectionalReferentialSynchronizeLocalServiceLocal extends ObserveServiceLocal implements UnidirectionalReferentialSynchronizeLocalService {
|
| 70 |
+ private static final Logger log = LogManager.getLogger(UnidirectionalReferentialSynchronizeLocalServiceLocal.class);
|
|
| 65 | 71 |
|
| 66 | 72 |
private LastUpdateDateService lastUpdateDateService;
|
| 67 | 73 |
private UsageService usageService;
|
| ... | ... | @@ -73,6 +79,11 @@ public class UnidirectionalReferentialSynchronizeLocalServiceLocal extends Obser |
| 73 | 79 |
usageService = serviceContext.newService(UsageService.class);
|
| 74 | 80 |
}
|
| 75 | 81 |
|
| 82 |
+ @Override
|
|
| 83 |
+ public ImmutableSet<Class<? extends ReferentialDto>> referentialReplicationOrder() {
|
|
| 84 |
+ return serviceContext.getTopiaApplicationContext().referentialForReplicationDto();
|
|
| 85 |
+ }
|
|
| 86 |
+ |
|
| 76 | 87 |
@Override
|
| 77 | 88 |
public <D extends ReferentialDto> ImmutableSet<String> filterIdsUsedInLocalSource(Class<D> dtoType, ImmutableSet<String> ids) {
|
| 78 | 89 |
Set<String> result = new LinkedHashSet<>();
|
| ... | ... | @@ -89,13 +100,12 @@ public class UnidirectionalReferentialSynchronizeLocalServiceLocal extends Obser |
| 89 | 100 |
public <D extends ReferentialDto, R extends ReferentialDtoReference> ReferentialDtoReferenceSet<R> getLocalSourceReferentialToDelete(Class<D> dtoType, ImmutableSet<String> ids) {
|
| 90 | 101 |
ReferentialDtoEntityContext<D, R, ?, ?> modelContext = ObservePersistenceBusinessProject.fromReferentialDto(dtoType);
|
| 91 | 102 |
Class<? extends ReferentialEntity<D, R>> entityType = modelContext.toEntityType();
|
| 92 |
- Class<R> referenceType = modelContext.toReferenceType();
|
|
| 93 |
- return getLocalSourceReferentialToDelete0(entityType, referenceType, ids);
|
|
| 103 |
+ return getLocalSourceReferentialToDelete0(entityType, ids);
|
|
| 94 | 104 |
}
|
| 95 | 105 |
|
| 96 | 106 |
@Override
|
| 97 |
- public <D extends ReferentialDto> ImmutableSet<String> generateSqlRequests(UnidirectionalReferentialSynchronizeRequest<D> request) {
|
|
| 98 |
- Set<String> result = new LinkedHashSet<>();
|
|
| 107 |
+ public <D extends ReferentialDto> ImmutableList<String> generateSqlRequests(UnidirectionalReferentialSynchronizeRequest<D> request) {
|
|
| 108 |
+ List<String> result = new LinkedList<>();
|
|
| 99 | 109 |
Class<D> dtoType = request.getReferentialName();
|
| 100 | 110 |
Class<ReferentialEntity<D, ?>> entityType = ObservePersistenceBusinessProject.fromReferentialDtoWeak(dtoType).toEntityType();
|
| 101 | 111 |
ObserveEntityEnum entityEnum = ObserveEntityEnum.valueOf(entityType);
|
| ... | ... | @@ -137,13 +147,23 @@ public class UnidirectionalReferentialSynchronizeLocalServiceLocal extends Obser |
| 137 | 147 |
result.addAll(sql);
|
| 138 | 148 |
}
|
| 139 | 149 |
}
|
| 140 |
- return ImmutableSet.copyOf(result);
|
|
| 150 |
+ return ImmutableList.copyOf(result);
|
|
| 141 | 151 |
}
|
| 142 | 152 |
|
| 143 | 153 |
@Override
|
| 144 | 154 |
public void applySqlRequests(ImmutableSet<String> sqlRequests) {
|
| 145 |
- TopiaSqlWork applySqlWork = new ApplySqlRequestWork(sqlRequests);
|
|
| 146 |
- getTopiaPersistenceContext().getSqlSupport().doSqlWork(applySqlWork);
|
|
| 155 |
+ |
|
| 156 |
+ Path scriptPath = serviceContext.getTemporaryDirectoryRoot().toPath().resolve("apply-UnidirectionalReferentialSynchronize-" + serviceContext.now().getTime() + "-sql");
|
|
| 157 |
+ |
|
| 158 |
+ TopiaSqlScript topiaSqlScript = TopiaSqlScript.of(scriptPath);
|
|
| 159 |
+ topiaSqlScript.setLocation(() -> SqlScriptReader.of(sqlRequests));
|
|
| 160 |
+ try {
|
|
| 161 |
+ topiaSqlScript.copy(scriptPath);
|
|
| 162 |
+ } catch (IOException e) {
|
|
| 163 |
+ throw new IllegalStateException("Can't write script at: " + scriptPath, e);
|
|
| 164 |
+ }
|
|
| 165 |
+ log.info(String.format("Will execute script (with %d statement(s): %s", sqlRequests.size(), scriptPath));
|
|
| 166 |
+ getTopiaPersistenceContext().executeSqlScript(topiaSqlScript);
|
|
| 147 | 167 |
}
|
| 148 | 168 |
|
| 149 | 169 |
@Override
|
| ... | ... | @@ -157,7 +177,7 @@ public class UnidirectionalReferentialSynchronizeLocalServiceLocal extends Obser |
| 157 | 177 |
return usageCount.getCount().values().stream().reduce(Long::sum).orElse(0L);
|
| 158 | 178 |
}
|
| 159 | 179 |
|
| 160 |
- private <E extends ReferentialEntity<D, R>, D extends ReferentialDto, R extends ReferentialDtoReference> ReferentialDtoReferenceSet<R> getLocalSourceReferentialToDelete0(Class<E> entityType, Class<R> referenceType, ImmutableSet<String> ids) {
|
|
| 180 |
+ private <E extends ReferentialEntity<D, R>, D extends ReferentialDto, R extends ReferentialDtoReference> ReferentialDtoReferenceSet<R> getLocalSourceReferentialToDelete0(Class<E> entityType, ImmutableSet<String> ids) {
|
|
| 161 | 181 |
TopiaDao<E> dao = getTopiaPersistenceContext().getDao(entityType);
|
| 162 | 182 |
List<E> entities = dao.forTopiaIdIn(ids).findAll();
|
| 163 | 183 |
ReferentialDtoEntityContext<D, R, E, ?> spi = ObservePersistenceBusinessProject.fromReferentialEntity(entityType);
|
| ... | ... | @@ -70,7 +70,7 @@ public class ReplaceSqlStatementGenerator { |
| 70 | 70 |
for (TopiaMetadataAssociation replacementStruct : associations) {
|
| 71 | 71 |
Class<? extends TopiaEntity> entityType = ObserveEntityEnum.valueOf(replacementStruct.getOwner().getType()).getContract();
|
| 72 | 72 |
if (ReferentialEntity.class.isAssignableFrom(entityType)) {
|
| 73 |
- // do not update referentials associations (see https://gitlab.com/ultreiaio/ird-observe/issues/1065)
|
|
| 73 |
+ // do not update referential associations (see https://gitlab.com/ultreiaio/ird-observe/issues/1065)
|
|
| 74 | 74 |
continue;
|
| 75 | 75 |
}
|
| 76 | 76 |
String sql = SqlStatements.generateAssociationUpdateStatement(replacementStruct, sourceId, replacementId);
|