Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
2cae4cee
by Tony Chemit at 2022-10-03T16:47:31+02:00
-
24b02ad3
by Tony Chemit at 2022-10-03T16:50:28+02:00
-
584a769e
by Tony Chemit at 2022-10-03T17:10:03+02:00
-
f122995d
by Tony Chemit at 2022-10-03T17:12:29+02:00
-
e90b62b8
by Tony Chemit at 2022-10-03T17:21:07+02:00
-
6c6c9178
by Tony Chemit at 2022-10-03T17:31:12+02:00
6 changed files:
- core/persistence/resources/src/main/resources/db/migration/v9/9.0/96_add_referential_ps_common_ObservedSystem_110-common.sql
- core/services/local/src/main/java/fr/ird/observe/services/local/service/referential/SynchronizeServiceLocalSupport.java
- toolkit/api/src/main/java/fr/ird/observe/spi/referential/synchro/OneSideSqlResult.java
- toolkit/persistence/src/main/java/fr/ird/observe/spi/context/DtoEntityContext.java
- toolkit/persistence/src/main/java/fr/ird/observe/spi/referential/OneSideSqlResultBuilderForType.java
- toolkit/persistence/src/main/java/org/nuiton/topia/service/sql/script/EntitySqlScript.java
Changes:
| ... | ... | @@ -20,4 +20,4 @@ |
| 20 | 20 | -- #L%
|
| 21 | 21 | ---
|
| 22 | 22 | -- See https://gitlab.com/ultreiaio/ird-observe/-/issues/2070
|
| 23 | -INSERT INTO ps_common.ObservedSystem(topiaId, topiaVersion, code, status, topiaCreateDate, lastUpdateDate, needComment, schoolType, allowObservation, allowLogbook, label1, label2, label3)VALUES ('fr.ird.referential.common.ObservedSystem#${REFERENTIAL_PREFIX}110', 0, '110', 1, ${CURRENT_DATE}, ${CURRENT_TIMESTAMP}, false, '${SchoolType_0}', TRUE, TRUE, 'Emptying the sack', 'Chavirage de la poche', 'Emptying the sack TODO'); |
|
| 23 | +INSERT INTO ps_common.ObservedSystem(topiaId, topiaVersion, code, status, topiaCreateDate, lastUpdateDate, needComment, schoolType, allowObservation, allowLogbook, label1, label2, label3)VALUES ('fr.ird.referential.common.ObservedSystem#${REFERENTIAL_PREFIX}110', 0, '110', 1, ${CURRENT_DATE}, ${CURRENT_TIMESTAMP}, false, '${SchoolType_0}', TRUE, TRUE, 'Discarding the content of the sack at sea', 'Chavirage de la poche', 'Discarding the content of the sack at sea TODO'); |
| ... | ... | @@ -35,6 +35,7 @@ import fr.ird.observe.spi.module.ObserveBusinessProject; |
| 35 | 35 | import fr.ird.observe.spi.referential.synchro.OneSideSqlRequest;
|
| 36 | 36 | import fr.ird.observe.spi.referential.synchro.OneSideSqlResult;
|
| 37 | 37 | import io.ultreia.java4all.util.sql.SqlScript;
|
| 38 | +import io.ultreia.java4all.util.sql.SqlScriptConsumer;
|
|
| 38 | 39 | |
| 39 | 40 | import java.util.LinkedHashSet;
|
| 40 | 41 | import java.util.Map;
|
| ... | ... | @@ -78,7 +79,7 @@ public class SynchronizeServiceLocalSupport extends ObserveServiceLocal implemen |
| 78 | 79 | @Override
|
| 79 | 80 | public void applySql(SqlScript script, String lastUpdateDateKey) {
|
| 80 | 81 | if (script != null) {
|
| 81 | - getTopiaPersistenceContext().executeSqlScript(script);
|
|
| 82 | + getTopiaPersistenceContext().executeSqlScript(SqlScriptConsumer.of(script));
|
|
| 82 | 83 | }
|
| 83 | 84 | updateLastUpdateDates(lastUpdateDateKey);
|
| 84 | 85 | }
|
| ... | ... | @@ -186,8 +186,8 @@ public class OneSideSqlResult implements JsonAware { |
| 186 | 186 | statements.addAll(oppositeSqlResult.getUpdateSqlCode());
|
| 187 | 187 | statements.addAll(oppositeSqlResult.getUpdateAssociationSqlCode());
|
| 188 | 188 | }
|
| 189 | - statements.addAll(getDeleteSqlCode());
|
|
| 190 | 189 | statements.addAll(getDeactivateSqlCode());
|
| 190 | + statements.addAll(getDeleteSqlCode());
|
|
| 191 | 191 | if (statements.isEmpty()) {
|
| 192 | 192 | return Optional.empty();
|
| 193 | 193 | }
|
| ... | ... | @@ -287,14 +287,14 @@ public interface DtoEntityContext< |
| 287 | 287 | |
| 288 | 288 | default List<String> updateLastUpdateDateField(ToolkitTopiaPersistenceContextSupport persistenceContext, String id, Date timeStamp) {
|
| 289 | 289 | List<String> requests = getUpdateLastUpdateDateFieldScript().generate(id, timeStamp);
|
| 290 | - String sql = String.join("\n", requests);
|
|
| 290 | + String sql = String.join("", requests);
|
|
| 291 | 291 | persistenceContext.executeSqlScript(SqlScriptReader.of(sql));
|
| 292 | 292 | return requests;
|
| 293 | 293 | }
|
| 294 | 294 | |
| 295 | 295 | default List<String> updateLastUpdateDateTable(ToolkitTopiaPersistenceContextSupport persistenceContext, Date timeStamp) {
|
| 296 | 296 | List<String> requests = getUpdateLastUpdateDateTableScript().generate(timeStamp);
|
| 297 | - String sql = String.join("\n", requests);
|
|
| 297 | + String sql = String.join("", requests);
|
|
| 298 | 298 | persistenceContext.executeSqlScript(SqlScriptReader.of(sql));
|
| 299 | 299 | return requests;
|
| 300 | 300 | }
|
| ... | ... | @@ -31,6 +31,7 @@ import fr.ird.observe.spi.referential.synchro.SynchronizeTask; |
| 31 | 31 | import fr.ird.observe.spi.service.ServiceContext;
|
| 32 | 32 | import org.apache.logging.log4j.LogManager;
|
| 33 | 33 | import org.apache.logging.log4j.Logger;
|
| 34 | +import org.nuiton.topia.service.sql.script.EntitySqlScript;
|
|
| 34 | 35 | import org.nuiton.topia.service.sql.script.ReplaceReferentialScript;
|
| 35 | 36 | |
| 36 | 37 | import java.util.Date;
|
| ... | ... | @@ -117,7 +118,7 @@ public class OneSideSqlResultBuilderForType<D extends ReferentialDto, E extends |
| 117 | 118 | }
|
| 118 | 119 | for (E entity : insertEntities) {
|
| 119 | 120 | List<String> sqlList = copyScript.generateCopyScript(context.getTopiaPersistenceContext(), entity, idsOnlyExistingOnThisSide);
|
| 120 | - sqlList.forEach(resultBuilder::addInsertStatement);
|
|
| 121 | + EntitySqlScript.appendEol(sqlList.stream()).forEach(resultBuilder::addInsertStatement);
|
|
| 121 | 122 | }
|
| 122 | 123 | }
|
| 123 | 124 | |
| ... | ... | @@ -129,7 +130,7 @@ public class OneSideSqlResultBuilderForType<D extends ReferentialDto, E extends |
| 129 | 130 | Set<String> optionalIncludedPropertyNames = task.getOptionalIncludedPropertyNames().orElse(null);
|
| 130 | 131 | Date lastUpdateDate = date(task.getLastUpdateDate());
|
| 131 | 132 | List<String> sqlList = updateScript.generateUpdateScript(context.getTopiaPersistenceContext(), entity, optionalIncludedPropertyNames, lastUpdateDate, idsOnlyExistingOnThisSide);
|
| 132 | - sqlList.forEach(resultBuilder::addUpdateStatement);
|
|
| 133 | + EntitySqlScript.appendEol(sqlList.stream()).forEach(resultBuilder::addUpdateStatement);
|
|
| 133 | 134 | }
|
| 134 | 135 | }
|
| 135 | 136 | |
| ... | ... | @@ -141,7 +142,7 @@ public class OneSideSqlResultBuilderForType<D extends ReferentialDto, E extends |
| 141 | 142 | Set<String> optionalIncludedPropertyNames = task.getOptionalIncludedPropertyNames().orElse(null);
|
| 142 | 143 | Date lastUpdateDate = date(task.getLastUpdateDate());
|
| 143 | 144 | List<String> sqlList = updateScript.generateUpdateScript(context.getTopiaPersistenceContext(), entity, optionalIncludedPropertyNames, lastUpdateDate, idsOnlyExistingOnThisSide);
|
| 144 | - sqlList.forEach(resultBuilder::addUpdateStatement);
|
|
| 145 | + EntitySqlScript.appendEol(sqlList.stream()).forEach(resultBuilder::addUpdateStatement);
|
|
| 145 | 146 | }
|
| 146 | 147 | }
|
| 147 | 148 |
| ... | ... | @@ -36,6 +36,7 @@ import java.util.stream.Stream; |
| 36 | 36 | */
|
| 37 | 37 | public class EntitySqlScript {
|
| 38 | 38 | |
| 39 | + private static final String EOL = "\n";
|
|
| 39 | 40 | //FIXME Add also parameters descriptions (how many and their type) to produce a safe script
|
| 40 | 41 | private final List<String> requests;
|
| 41 | 42 | |
| ... | ... | @@ -45,7 +46,7 @@ public class EntitySqlScript { |
| 45 | 46 | |
| 46 | 47 | public List<String> generate(Function<String, String> lineTransformer) {
|
| 47 | 48 | Stream<String> requests = stream();
|
| 48 | - return requests.map(lineTransformer).collect(Collectors.toList());
|
|
| 49 | + return appendEol(requests.map(lineTransformer)).collect(Collectors.toList());
|
|
| 49 | 50 | }
|
| 50 | 51 | |
| 51 | 52 | public Stream<String> stream() {
|
| ... | ... | @@ -55,4 +56,15 @@ public class EntitySqlScript { |
| 55 | 56 | public List<String> requests() {
|
| 56 | 57 | return requests;
|
| 57 | 58 | }
|
| 59 | + |
|
| 60 | + public static String appendEol(String l) {
|
|
| 61 | + if (l.endsWith(EOL)) {
|
|
| 62 | + return l;
|
|
| 63 | + }
|
|
| 64 | + return l + EOL;
|
|
| 65 | + }
|
|
| 66 | + |
|
| 67 | + public static Stream<String> appendEol(Stream<String> s) {
|
|
| 68 | + return s.map(EntitySqlScript::appendEol);
|
|
| 69 | + }
|
|
| 58 | 70 | } |