Skip to content

Commit

Permalink
fetchDataObjects fetchCapanilityApplicationMapping
Browse files Browse the repository at this point in the history
improve performance
  • Loading branch information
mauvaisetroupe committed Nov 16, 2023
1 parent d0c713c commit 933531b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class CapabilityApplicationMapping implements Serializable {
@Column(name = "id")
private Long id;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnoreProperties(value = { "subCapabilities", "capabilityApplicationMappings" }, allowSetters = true)
private Capability capability;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnoreProperties(
value = {
"owner",
Expand All @@ -43,7 +43,7 @@ public class CapabilityApplicationMapping implements Serializable {
)
private Application application;

@ManyToMany
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "rel_capability_ap__landscap_b2",
joinColumns = @JoinColumn(name = "capability_application_mapping_id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public interface LandscapeViewRepository extends JpaRepository<LandscapeView, Lo
" left join fetch l.owner o " +
" left join fetch l.flows f " +
" left join fetch f.landscapes l2 " +
" left join fetch l2.owner " +
" left join fetch f.steps s " +
" left join fetch s.group g " +
" left join fetch s.flowInterface fi " +
Expand All @@ -37,11 +38,6 @@ public interface LandscapeViewRepository extends JpaRepository<LandscapeView, Lo
" left join fetch fi.sourceComponent sc " +
" left join fetch fi.target ta " +
" left join fetch fi.targetComponent tc " +
" left join fetch l.capabilityApplicationMappings cm " +
" left join fetch cm.application a " +
" left join fetch cm.capability ca " +
" left join fetch l.dataObjects do " +
" left join fetch do.businessObject bo " +
" where l.id =:id"
)
Optional<LandscapeView> findOneWithEagerRelationships(@Param("id") Long id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.mauvaisetroupe.eadesignit.repository;

import com.mauvaisetroupe.eadesignit.domain.LandscapeView;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;

/**
* Utility repository to load bag relationships based on https://vladmihalcea.com/hibernate-multiplebagfetchexception/
*/
@Repository
public class LandscapeWithBagRelationshipsImpl {

@PersistenceContext
private EntityManager entityManager;

public LandscapeView fetchDataObjects(LandscapeView landscapeView) {
LandscapeView result = entityManager
.createQuery(
"select l from LandscapeView l " +
" left join fetch l.dataObjects do" +
" left join fetch do.businessObject " +
" where l=:landscapeView",
LandscapeView.class
)
.setParameter("landscapeView", landscapeView)
.getSingleResult();
return result;
}

public LandscapeView fetchCapanilityApplicationMapping(LandscapeView landscapeView) {
LandscapeView result = entityManager
.createQuery(
"select l from LandscapeView l " +
" left join fetch l.capabilityApplicationMappings cm " +
" left join fetch cm.application a " + // needed to build landscape report (appli w/ capa not in landscape)
" left join fetch cm.capability ca " +
" left join fetch ca.parent ca_p_1 " +
" left join fetch ca_p_1.parent ca_p_2" +
" left join fetch ca_p_2.parent ca_p_3" +
" left join fetch ca_p_3.parent ca_p_4" +
" left join fetch ca_p_4.parent ca_p_5" +
" left join fetch cm.landscapes cm_l " +
" left join fetch cm_l.owner cm_l_o" +
" where l=:landscapeView",
LandscapeView.class
)
.setParameter("landscapeView", landscapeView)
.getSingleResult();
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mauvaisetroupe.eadesignit.domain.Capability;
import com.mauvaisetroupe.eadesignit.domain.LandscapeView;
import com.mauvaisetroupe.eadesignit.repository.LandscapeViewRepository;
import com.mauvaisetroupe.eadesignit.repository.LandscapeWithBagRelationshipsImpl;
import com.mauvaisetroupe.eadesignit.repository.view.LandscapeLight;
import com.mauvaisetroupe.eadesignit.service.LandscapeViewService;
import com.mauvaisetroupe.eadesignit.service.diagram.drawio.MXFileSerializer;
Expand Down Expand Up @@ -57,6 +58,9 @@ public class LandscapeViewResource {
@Autowired
private LandscapeViewService landscapeViewService;

@Autowired
private LandscapeWithBagRelationshipsImpl landscapeWithBagRelationshipsImpl;

@Autowired
private CapabilityUtil capabilityUtil;

Expand Down Expand Up @@ -195,6 +199,8 @@ public LandscapeDTO getLandscapeView(@PathVariable Long id) {
.findOneWithEagerRelationships(id)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));

landscape = landscapeWithBagRelationshipsImpl.fetchDataObjects(landscape);
landscape = landscapeWithBagRelationshipsImpl.fetchCapanilityApplicationMapping(landscape);
if (landscape.getCapabilityApplicationMappings() != null) {
// Capabilities, we get root with a subset of tree

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package com.mauvaisetroupe.eadesignit.web.rest.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import com.mauvaisetroupe.eadesignit.domain.Application;
import com.mauvaisetroupe.eadesignit.domain.Capability;
import com.mauvaisetroupe.eadesignit.domain.LandscapeView;
import java.util.Set;

public class LandscapeDTO {

@JsonIgnoreProperties(value = { "capabilityApplicationMappings" })
LandscapeView landscape;

Capability consolidatedCapability;

@JsonIncludeProperties(value = { "id", "alias", "name" })
Set<Application> applicationsOnlyInCapabilities;

@JsonIncludeProperties(value = { "id", "alias", "name" })
Set<Application> applicationsOnlyInFlows;

public Capability getConsolidatedCapability() {
Expand Down Expand Up @@ -42,5 +50,5 @@ public Set<Application> getApplicationsOnlyInFlows() {

public void setApplicationsOnlyInFlows(Set<Application> applicationsOnlyInFlows) {
this.applicationsOnlyInFlows = applicationsOnlyInFlows;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default defineComponent({
const applicationsOnlyInCapabilities: Ref<IApplication[]> = ref([]);
const applicationsOnlyInFlows: Ref<IApplication[]> = ref([]);
const reportToDisplay = computed(() => {
return applicationsOnlyInCapabilities.value.length > 0 || applicationsOnlyInFlows.value.length > 0;
return applicationsOnlyInCapabilities.value?.length > 0 || applicationsOnlyInFlows.value?.length > 0;
});
const capabilitiesByApplicationID = ref(new Object());
const flowsByApplicationID = ref(new Object());
Expand Down Expand Up @@ -130,14 +130,6 @@ export default defineComponent({

const retrieveLandscapeView = async landscapeViewId => {
try {
loadTab(landscapeViewId);

// load landscape schema
getPlantUML(landscapeViewId);

// load golen/replicas schema
getDataObjectsLandscapePlantUML(landscapeViewId);

const res = await landscapeViewService().find(landscapeViewId);
const landscape = res.landscape;
conputeAllApplicationsByFlow(landscape);
Expand Down Expand Up @@ -176,8 +168,11 @@ export default defineComponent({
};

if (route.params?.landscapeViewId) {
const landscapeViewId: string = route.params?.landscapeViewId;
loadTab(landscapeViewId);
getPlantUML(landscapeViewId);
getDataObjectsLandscapePlantUML(landscapeViewId);
retrieveLandscapeView(route.params.landscapeViewId);
landscapeViewId.value = parseInt(route.params?.landscapeViewId);
}

const previousState = () => router.go(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
</b-tab>
<b-tab title="Report" id="tab-report">
<div>
<div v-if="applicationsOnlyInCapabilities.length">
<div v-if="applicationsOnlyInCapabilities?.length">
<h4>[Capability Mapping] Applications with no Functional Flow ({{ onlyCapabilitiesPercent }} %)</h4>
<b-table
:items="applicationsOnlyInCapabilities"
Expand Down

0 comments on commit 933531b

Please sign in to comment.