Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 0c952acb by Tony Chemit at 2020-12-18T20:32:47+01:00 remove unused method - - - - - b2ace90a by Tony Chemit at 2020-12-18T20:34:52+01:00 Il reste quelques optimisations à réaliser sur la couche de persistence - See #1664 * Suppression de contrat sur les entités inutiles * Utilisation de requetes optimisées pour construire le dto de la composition détaillée * suppression de liens sur le modèle de persistence inutiles - - - - - f11cbc8e by Tony Chemit at 2020-12-18T20:47:37+01:00 Generate some missing indexes - Closes #58 - - - - - 13 changed files: - − models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/LonglinePositionAware.java - models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/SetImpl.java - models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/LonglineElementAware.java → models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/SetTopiaDao.java - models/persistence/src/main/models/Observe-30-data-ll-observation.model - pom.xml - services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/SetDetailCompositionServiceLocal.java - services/local-impl/src/test/java/fr/ird/observe/services/local/service/data/ll/observation/SetDetailCompositionServiceLocalTest.java - tests/test/src/main/resources/db/8.0/dataForTestLongline.sql.gz - tests/test/src/main/resources/db/8.0/dataForTestSeine.sql.gz - tests/test/src/main/resources/db/8.0/empty_h2.sql.gz - tests/test/src/main/resources/db/8.0/empty_pg.sql.gz - tests/test/src/main/resources/db/8.0/referentiel.sql.gz - toolkit/persistence/src/main/java/fr/ird/observe/entities/EntityHelper.java Changes: ===================================== models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/LonglinePositionAware.java deleted ===================================== @@ -1,53 +0,0 @@ -package fr.ird.observe.entities.data.ll.observation; - -/* - * #%L - * ObServe Models :: Persistence - * %% - * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.dto.data.DataDto; -import fr.ird.observe.dto.reference.DataDtoReference; -import fr.ird.observe.entities.data.DataEntity; - -/** - * Place this contract on any data that use a position on a longline. - * Created on 1/6/15. - * - * @author Tony Chemit - dev@tchemit.fr - * @see Catch - * @see Tdr - * @see fr.ird.observe.dto.data.ll.observation.LonglinePositionAware - * @since 3.11 - */ -public interface LonglinePositionAware<Dt extends DataDto, R extends DataDtoReference> extends DataEntity<Dt, R> { - - void setSection(Section section); - - Section getSection(); - - void setBasket(Basket basket); - - Basket getBasket(); - - void setBranchline(Branchline branchline); - - Branchline getBranchline(); - -} ===================================== models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/SetImpl.java ===================================== @@ -22,15 +22,12 @@ package fr.ird.observe.entities.data.ll.observation; * #L% */ -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import fr.ird.observe.dto.CoordinateHelper; import fr.ird.observe.dto.data.DataDto; import fr.ird.observe.dto.data.ll.observation.BasketReference; import fr.ird.observe.dto.data.ll.observation.BranchlineReference; import fr.ird.observe.dto.data.ll.observation.LonglinePositionContainerAware; import fr.ird.observe.dto.data.ll.observation.SectionReference; -import fr.ird.observe.dto.data.ll.observation.SetDetailCompositionDto; import fr.ird.observe.dto.data.ll.observation.SetDto; import fr.ird.observe.dto.referential.ReferentialLocale; @@ -44,10 +41,6 @@ public class SetImpl extends SetAbstract { @Override public <D extends DataDto> void toDto(ReferentialLocale referentialLocale, D dto) { boolean useLonglinePosition = dto instanceof LonglinePositionContainerAware; - boolean detailComposition = dto instanceof SetDetailCompositionDto; - if (useLonglinePosition || detailComposition) { - loadEntityParents(); - } super.toDto(referentialLocale, dto); if (dto instanceof SetDto) { SetDto dto1 = (SetDto) dto; @@ -56,62 +49,27 @@ public class SetImpl extends SetAbstract { dto1.setHaulingStartQuadrant(CoordinateHelper.getQuadrant(haulingStartLongitude, haulingStartLatitude)); dto1.setHaulingEndQuadrant(CoordinateHelper.getQuadrant(haulingEndLongitude, haulingEndLatitude)); } - if (detailComposition) { - loadDtoParents((SetDetailCompositionDto) dto); - } if (useLonglinePosition) { loadDtoReferenceParents((LonglinePositionContainerAware) dto, referentialLocale); } } - private void loadEntityParents() { - getSection().forEach(section -> { - section.setParentId(getTopiaId()); - section.getBasket().forEach(basket -> { - String sectionId = section.getTopiaId(); - basket.setParentId(sectionId); - String basketId = basket.getTopiaId(); - basket.getBranchline().forEach(branchline -> branchline.setParentId(basketId)); - }); - }); - } - - private void loadDtoParents(SetDetailCompositionDto dto) { - //FIXME If not performant, let's used an optimized dao query - ImmutableMap<String, Section> sectionsById = Maps.uniqueIndex(getSection(), Section::getTopiaId); - dto.getSection().forEach(section -> { - section.setParentId(dto.getId()); - String sectionId = section.getTopiaId(); - Section entitySection = sectionsById.get(sectionId); - ImmutableMap<String, Basket> basketsById = Maps.uniqueIndex(entitySection.getBasket(), Basket::getTopiaId); - section.setNotUsed(entitySection.isNotUsed()); - section.getBasket().forEach(basket -> { - basket.setParentId(sectionId); - String basketId = basket.getTopiaId(); - Basket entityBasket = basketsById.get(basketId); - basket.setNotUsed(entityBasket.isNotUsed()); - ImmutableMap<String, Branchline> branchlinesById = Maps.uniqueIndex(entityBasket.getBranchline(), Branchline::getTopiaId); - basket.getBranchline().forEach(branchline -> { - String branchlineId = branchline.getId(); - Branchline entityBranchline = branchlinesById.get(branchlineId); - branchline.setParentId(basketId); - branchline.setNotUsed(entityBranchline.isNotUsed()); - }); - }); - }); - } - private void loadDtoReferenceParents(LonglinePositionContainerAware dto, ReferentialLocale referentialLocale) { List<SectionReference> sections = new LinkedList<>(); List<BasketReference> baskets = new LinkedList<>(); List<BranchlineReference> branchlines = new LinkedList<>(); getSection().forEach(section -> { + section.setParentId(getTopiaId()); + String sectionId = section.getTopiaId(); SectionReference sectionReference = section.toReference(referentialLocale); sections.add(sectionReference); section.getBasket().forEach(basket -> { + String basketId = basket.getTopiaId(); + basket.setParentId(sectionId); BasketReference basketReference = basket.toReference(referentialLocale); baskets.add(basketReference); basket.getBranchline().forEach(branchline -> { + branchline.setParentId(basketId); BranchlineReference branchlineReference = branchline.toReference(referentialLocale); branchlines.add(branchlineReference); }); ===================================== models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/LonglineElementAware.java → models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/SetTopiaDao.java ===================================== @@ -1,6 +1,6 @@ package fr.ird.observe.entities.data.ll.observation; -/* +/*- * #%L * ObServe Models :: Persistence * %% @@ -22,37 +22,44 @@ package fr.ird.observe.entities.data.ll.observation; * #L% */ -import fr.ird.observe.dto.DtoParentAware; -import fr.ird.observe.dto.data.DataDto; -import fr.ird.observe.dto.reference.DataDtoReference; -import fr.ird.observe.entities.data.DataEntity; +import com.google.common.collect.ImmutableSet; +import fr.ird.observe.spi.context.DataDtoEntityContext; + +import java.util.List; /** - * Place this contract on any element involved in longline definition. - * Created on 12/13/14. + * Created on 12/18/2020. * * @author Tony Chemit - dev@tchemit.fr - * @see Section - * @see Basket - * @see Branchline - * @see fr.ird.observe.dto.data.ll.observation.LonglineElementAware - * @since 3.10 + * @since 8.0.1 */ -public interface LonglineElementAware<Dt extends DataDto, R extends DataDtoReference> extends DataEntity<Dt, R>, DtoParentAware { - - Integer getSettingIdentifier(); - - void setSettingIdentifier(Integer settingIdentifier); +public class SetTopiaDao extends AbstractSetTopiaDao<Set> { - Integer getHaulingIdentifier(); + private static final String SQL_PATTERN = "SELECT DISTINCT(%1$s) FROM %2$s WHERE set = '%3$s' AND %1$s IS NOT NULL"; - void setHaulingIdentifier(Integer haulingIdentifier); + public ImmutableSet<String> getSectionUsed(String setId) { + ImmutableSet.Builder<String> builder = ImmutableSet.builder(); + getUsages(Tdr.SPI, Tdr.PROPERTY_SECTION, setId, builder); + getUsages(Catch.SPI, Catch.PROPERTY_SECTION, setId, builder); + return builder.build(); + } - boolean isTdrEmpty(); + public ImmutableSet<String> getBasketUsed(String setId) { + ImmutableSet.Builder<String> builder = ImmutableSet.builder(); + getUsages(Tdr.SPI, Tdr.PROPERTY_BASKET, setId, builder); + getUsages(Catch.SPI, Catch.PROPERTY_BASKET, setId, builder); + return builder.build(); + } - boolean isCatchesEmpty(); + public ImmutableSet<String> getBranchlineUsed(String setId) { + ImmutableSet.Builder<String> builder = ImmutableSet.builder(); + getUsages(Tdr.SPI, Tdr.PROPERTY_BRANCHLINE, setId, builder); + getUsages(Catch.SPI, Catch.PROPERTY_BRANCHLINE, setId, builder); + return builder.build(); + } - default boolean isNotUsed() { - return isTdrEmpty() && isCatchesEmpty(); + protected void getUsages(DataDtoEntityContext<?, ?, ?, ?> spi, String propertyName, String setId, ImmutableSet.Builder<String> ids) { + List<String> newIds = topiaSqlSupport.findMultipleResult(String.format(SQL_PATTERN, propertyName, spi.getEntitySqlDescriptor().getTable().getSchemaAndTableName(), setId), r -> r.getString(1)); + ids.addAll(newIds); } } ===================================== models/persistence/src/main/models/Observe-30-data-ll-observation.model ===================================== @@ -1,19 +1,5 @@ package fr.ird.observe.entities.data.ll.observation | dbSchema=ll_observation -interface data.ll.observation.LonglineElementAware > fr.ird.observe.entities.data.DataEntity -getSettingIdentifier() Integer -setSettingIdentifier(identifier Integer) -getHaulingIdentifier() Integer -setHaulingIdentifier(identifier Integer) - -interface data.ll.observation.LonglinePositionAware > fr.ird.observe.entities.data.DataEntity -getSection() data.ll.observation.Section -setSection(section data.ll.observation.Section) -getBasket() data.ll.observation.Basket -setBasket(basket data.ll.observation.Basket) -getBranchline() data.ll.observation.Branchline -setBranchline(branchline data.ll.observation.Branchline) - data.ll.observation.Activity > data.DataEntity | entity constants=date,time comment + {*:1} String | hibernateAttributeType=text timeStamp + {*:1} Date @@ -35,16 +21,14 @@ individualWeight + {*:1} Float baitSettingStatus {*:1} referential.ll.common.BaitSettingStatus baitType {*:1} referential.ll.common.BaitType -data.ll.observation.Basket > data.DataEntity >> data.ll.observation.LonglineElementAware fr.ird.observe.dto.DtoParentAware | entity +data.ll.observation.Basket > data.DataEntity >> fr.ird.observe.dto.DtoParentAware | entity settingIdentifier + {*:1} Integer | notNull haulingIdentifier + {*:1} Integer floatline1Length + {*:1} Float floatline2Length + {*:1} Float branchline + {*} data.ll.observation.Branchline | unique orderBy=settingIdentifier inverse=false -catches {*} data.ll.observation.Catch | skipModelNavigation inverse -tdr {*} data.ll.observation.Tdr | skipModelNavigation inverse -data.ll.observation.Branchline > data.DataEntity >> data.ll.observation.LonglineElementAware fr.ird.observe.dto.DtoParentAware | entity constants=timerTimeOnBoardDate,timerTimeOnBoardTime +data.ll.observation.Branchline > data.DataEntity >> fr.ird.observe.dto.DtoParentAware | entity constants=timerTimeOnBoardDate,timerTimeOnBoardTime comment + {*:1} String | hibernateAttributeType=text settingIdentifier + {*:1} Integer | notNull haulingIdentifier + {*:1} Integer @@ -62,8 +46,6 @@ tracelineLength + {*:1} Float | sqlType=numeric hookLost + {*:1} Boolean traceCutOff + {*:1} Boolean hookType {*:0..1} referential.ll.common.HookType -catches {*} data.ll.observation.Catch | skipModelNavigation inverse -tdr {*} data.ll.observation.Tdr | skipModelNavigation inverse baitType {*:0..1} referential.ll.common.BaitType topType {*:0..1} referential.ll.common.LineType tracelineType {*:0..1} referential.ll.common.LineType @@ -78,7 +60,7 @@ tracelineLength + {*:1} Float topType {*:0..1} referential.ll.common.LineType tracelineType {*:0..1} referential.ll.common.LineType -data.ll.observation.Catch > data.DataEntity >> data.ll.observation.LonglinePositionAware | entity +data.ll.observation.Catch > data.DataEntity | entity comment + {*:1} String | hibernateAttributeType=text count + {*:1} Integer totalWeight + {*:1} Float | sqlType=numeric @@ -123,12 +105,10 @@ hookOffset + {*:1} Integer hookType {*:1} referential.ll.common.HookType hookSize {*:1} referential.ll.common.HookSize -data.ll.observation.Section > data.DataEntity >> data.ll.observation.LonglineElementAware fr.ird.observe.dto.DtoParentAware | entity +data.ll.observation.Section > data.DataEntity >> fr.ird.observe.dto.DtoParentAware | entity settingIdentifier + {*:1} Integer | notNull haulingIdentifier + {*:1} Integer basket + {*} data.ll.observation.Basket | unique orderBy=settingIdentifier inverse=false -catches {*} data.ll.observation.Catch | skipModelNavigation inverse -tdr {*} data.ll.observation.Tdr | skipModelNavigation inverse data.ll.observation.SensorUsed > data.DataEntity >> data.DataFileAware | entity data + {*:1} !java.sql.Blob @@ -190,7 +170,7 @@ size + {*:1} Float | sqlType=numeric sizeMeasureType {*:1} referential.common.SizeMeasureType lengthMeasureMethod {*:0..1} referential.common.LengthMeasureMethod -data.ll.observation.Tdr > data.DataEntity >> data.ll.observation.LonglinePositionAware data.DataFileAware | entity constants=deploymentStartDate,deploymentStartTime,deploymentEndDate,deploymentEndTime,fishingStartDate,fishingStartTime,fishingEndDate,fishingEndTime +data.ll.observation.Tdr > data.DataEntity >> data.DataFileAware | entity constants=deploymentStartDate,deploymentStartTime,deploymentEndDate,deploymentEndTime,fishingStartDate,fishingStartTime,fishingEndDate,fishingEndTime floatline1Length + {*:1} Float | sqlType=numeric floatline2Length + {*:1} Float | sqlType=numeric serialNo + {*:1} String ===================================== pom.xml ===================================== @@ -153,7 +153,7 @@ <lib.version.h2>1.4.196</lib.version.h2> <lib.version.nuiton.utils>3.0</lib.version.nuiton.utils> -<!-- <lib.version.java4all.topia>1.31</lib.version.java4all.topia>--> + <lib.version.java4all.topia>1.32</lib.version.java4all.topia> <!-- <lib.version.java4all.eugene>3.0-alpha-38</lib.version.java4all.eugene>--> <lib.version.java4all.jaxx>3.0-alpha-85</lib.version.java4all.jaxx> <!--<lib.version.java4all.application-context>1.0.3-SNAPSHOT</lib.version.java4all.application-context>--> ===================================== services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/SetDetailCompositionServiceLocal.java ===================================== @@ -22,8 +22,11 @@ package fr.ird.observe.services.local.service.data.ll.observation; * #L% */ +import com.google.common.collect.ImmutableSet; import fr.ird.observe.dto.data.ll.observation.SetDetailCompositionDto; +import fr.ird.observe.dto.form.Form; import fr.ird.observe.entities.data.ll.observation.Set; +import fr.ird.observe.entities.data.ll.observation.SetTopiaDao; import fr.ird.observe.services.local.service.data.Simple2DataServiceLocalSupport; import fr.ird.observe.services.service.data.ll.observation.SetDetailCompositionService; @@ -37,4 +40,29 @@ public class SetDetailCompositionServiceLocal extends Simple2DataServiceLocalSup super(Set.SPI, Set.SET_DETAIL_COMPOSITION_SPI, null); } + @Override + protected Form<SetDetailCompositionDto> entityToForm(Set entity) { + Form<SetDetailCompositionDto> form = super.entityToForm(entity); + SetDetailCompositionDto dto = form.getObject(); + SetTopiaDao dao = Set.SPI.getDao(getTopiaPersistenceContext()); + ImmutableSet<String> sectionUsed = dao.getSectionUsed(entity.getTopiaId()); + ImmutableSet<String> basketUsed = dao.getBasketUsed(entity.getTopiaId()); + ImmutableSet<String> branchlineUsed = dao.getBranchlineUsed(entity.getTopiaId()); + dto.getSection().forEach(section -> { + section.setParentId(dto.getId()); + String sectionId = section.getTopiaId(); + section.setNotUsed(!sectionUsed.contains(sectionId)); + section.getBasket().forEach(basket -> { + basket.setParentId(sectionId); + String basketId = basket.getTopiaId(); + basket.setNotUsed(!basketUsed.contains(basketId)); + basket.getBranchline().forEach(branchline -> { + String branchlineId = branchline.getId(); + branchline.setParentId(basketId); + branchline.setNotUsed(!branchlineUsed.contains(branchlineId)); + }); + }); + }); + return form; + } } ===================================== services/local-impl/src/test/java/fr/ird/observe/services/local/service/data/ll/observation/SetDetailCompositionServiceLocalTest.java ===================================== @@ -79,6 +79,7 @@ public class SetDetailCompositionServiceLocalTest extends ServiceLocalTestSuppor Assert.assertEquals(Integer.valueOf(18), sectionDto.getHaulingIdentifier()); Assert.assertEquals(13, sectionDto.getBasketSize()); Assert.assertNotNull(sectionDto.getParentId()); + Assert.assertTrue(sectionDto.isNotUsed()); Assert.assertEquals(compositionDto.getId(), sectionDto.getParentId()); Assert.assertNotNull(sectionDto.toReference(ReferentialLocale.FR)); Assert.assertNotNull(sectionDto.toReference(ReferentialLocale.FR).getParentId()); @@ -88,6 +89,8 @@ public class SetDetailCompositionServiceLocalTest extends ServiceLocalTestSuppor Assert.assertEquals(Integer.valueOf(13), basketDto.getHaulingIdentifier()); Assert.assertEquals(6, basketDto.getBranchlineSize()); Assert.assertNotNull(basketDto.getParentId()); + Assert.assertTrue(basketDto.isNotUsed()); + Assert.assertEquals(sectionDto.getId(), basketDto.getParentId()); Assert.assertNotNull(basketDto.toReference(ReferentialLocale.FR)); Assert.assertNotNull(basketDto.toReference(ReferentialLocale.FR).getParentId()); @@ -96,9 +99,14 @@ public class SetDetailCompositionServiceLocalTest extends ServiceLocalTestSuppor Assert.assertEquals(Integer.valueOf(1), branchlineDto.getSettingIdentifier()); Assert.assertEquals(Integer.valueOf(6), branchlineDto.getHaulingIdentifier()); Assert.assertNotNull(branchlineDto.getParentId()); + Assert.assertTrue(branchlineDto.isNotUsed()); Assert.assertEquals(basketDto.getId(), branchlineDto.getParentId()); Assert.assertNotNull(branchlineDto.toReference(ReferentialLocale.FR)); Assert.assertNotNull(branchlineDto.toReference(ReferentialLocale.FR).getParentId()); + + sectionDto = compositionDto.getSection(6); + basketDto = sectionDto.getBasket(8); + Assert.assertFalse(basketDto.isNotUsed()); } @Test ===================================== tests/test/src/main/resources/db/8.0/dataForTestLongline.sql.gz ===================================== Binary files a/tests/test/src/main/resources/db/8.0/dataForTestLongline.sql.gz and b/tests/test/src/main/resources/db/8.0/dataForTestLongline.sql.gz differ ===================================== tests/test/src/main/resources/db/8.0/dataForTestSeine.sql.gz ===================================== Binary files a/tests/test/src/main/resources/db/8.0/dataForTestSeine.sql.gz and b/tests/test/src/main/resources/db/8.0/dataForTestSeine.sql.gz differ ===================================== tests/test/src/main/resources/db/8.0/empty_h2.sql.gz ===================================== Binary files a/tests/test/src/main/resources/db/8.0/empty_h2.sql.gz and b/tests/test/src/main/resources/db/8.0/empty_h2.sql.gz differ ===================================== tests/test/src/main/resources/db/8.0/empty_pg.sql.gz ===================================== Binary files a/tests/test/src/main/resources/db/8.0/empty_pg.sql.gz and b/tests/test/src/main/resources/db/8.0/empty_pg.sql.gz differ ===================================== tests/test/src/main/resources/db/8.0/referentiel.sql.gz ===================================== Binary files a/tests/test/src/main/resources/db/8.0/referentiel.sql.gz and b/tests/test/src/main/resources/db/8.0/referentiel.sql.gz differ ===================================== toolkit/persistence/src/main/java/fr/ird/observe/entities/EntityHelper.java ===================================== @@ -204,18 +204,6 @@ public class EntityHelper { return dtoList; } - public static <DD extends DataDto, RR extends DataDtoReference, EE extends DataEntity<DD, RR>> LinkedHashSet<RR> toDataReferenceLinkedHashSet(ReferentialLocale referentialLocale, Collection<EE> entities) { - LinkedHashSet<RR> result = null; - if (entities != null) { - result = new LinkedHashSet<>(); - for (EE entity : entities) { - result.add(entity.toReference(referentialLocale)); - } - } - return result; - } - - @SuppressWarnings({"unchecked", "unused"}) public static <DD extends DataDto, RR extends DataDtoReference, EE extends DataEntity<?, ?>, C extends Collection<EE>> C toDataEntityCollectionFromReference(Collection<RR> referencesList, C entities) { if (entities == null) { View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/5af39beb242c07d5e4268bd19... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/5af39beb242c07d5e4268bd19... You're receiving this email because of your account on gitlab.com.