Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<properties>

<jib.from.image>powsybl/java-dynawo:3.0.0</jib.from.image>
<gridsuite-dependencies.version>44.1.0</gridsuite-dependencies.version>
<gridsuite-dependencies.version>45.0.0</gridsuite-dependencies.version>
<liquibase-hibernate-package>org.gridsuite.securityanalysis.server</liquibase-hibernate-package>
<db-util.version>1.0.5</db-util.version>
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Specification<PreContingencyLimitViolationEntity> resultUuidEquals(UUID v
}

public Specification<PreContingencyLimitViolationEntity> buildSpecification(UUID resultUuid, List<ResourceFilterDTO> resourceFilters) {
Specification<PreContingencyLimitViolationEntity> specification = Specification.where(resultUuidEquals(resultUuid));
Specification<PreContingencyLimitViolationEntity> specification = resultUuidEquals(resultUuid);

return SpecificationUtils.appendFiltersToSpecification(specification, resourceFilters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,30 @@ public Page<ContingencyEntity> findContingenciesPage(UUID resultUuid, UUID netwo
// HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
// cf. https://vladmihalcea.com/fix-hibernate-hhh000104-entity-fetch-pagination-warning-message/
// We must separate in two requests, one with pagination the other one with Join Fetch
// Determine which properties to project based on sort fields
// When using DISTINCT, all ORDER BY columns must be in the SELECT list
List<String> projectionProperties = new ArrayList<>();
projectionProperties.add("uuid");

// Add sort properties to projection to satisfy DISTINCT + ORDER BY requirement
for (Sort.Order order : modifiedPageable.getSort()) {
String property = order.getProperty();
if (!property.equals("uuid") && !projectionProperties.contains(property)) {
projectionProperties.add(property);
}
}

// First, we fetch contingencies UUIDs, with all the filters and pagination
Page<ContingencyRepository.EntityUuid> uuidPage = contingencyRepository.findBy(specification, q ->
q.project("uuid")
.as(ContingencyRepository.EntityUuid.class)
.sortBy(modifiedPageable.getSort())
.page(modifiedPageable)
);
Page<ContingencyRepository.EntityUuid> uuidPage = contingencyRepository.findBy(specification, q -> {
var query = q.as(ContingencyRepository.EntityUuid.class)
.sortBy(modifiedPageable.getSort());
if (projectionProperties.size() == 1) {
query = query.project("uuid");
} else {
query = query.project(projectionProperties.toArray(new String[0]));
}
return query.page(modifiedPageable);
});

if (!uuidPage.hasContent()) {
// Since springboot 3.2, the return value of Page.empty() is not serializable. See https://github.com/spring-projects/spring-data-commons/issues/2987
Expand Down Expand Up @@ -363,12 +379,30 @@ public Page<SubjectLimitViolationEntity> findSubjectLimitViolationsPage(UUID res
// HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
// cf. https://vladmihalcea.com/fix-hibernate-hhh000104-entity-fetch-pagination-warning-message/
// We must separate in two requests, one with pagination the other one with Join Fetch
Page<SubjectLimitViolationRepository.EntityId> uuidPage = subjectLimitViolationRepository.findBy(specification, q ->
q.project("id")
.as(SubjectLimitViolationRepository.EntityId.class)
.sortBy(modifiedPageable.getSort())
.page(modifiedPageable)
);

// Determine which properties to project based on sort fields
// When using DISTINCT, all ORDER BY columns must be in the SELECT list
List<String> projectionProperties = new ArrayList<>();
projectionProperties.add("id");

// Add sort properties to projection to satisfy DISTINCT + ORDER BY requirement
for (Sort.Order order : modifiedPageable.getSort()) {
String property = order.getProperty();
if (!property.equals("id") && !projectionProperties.contains(property)) {
projectionProperties.add(property);
}
}

Page<SubjectLimitViolationRepository.EntityId> uuidPage = subjectLimitViolationRepository.findBy(specification, q -> {
var query = q.as(SubjectLimitViolationRepository.EntityId.class)
.sortBy(modifiedPageable.getSort());
if (projectionProperties.size() == 1) {
query = query.project("id");
} else {
query = query.project(projectionProperties.toArray(new String[0]));
}
return query.page(modifiedPageable);
});

if (!uuidPage.hasContent()) {
// Since springboot 3.2, the return value of Page.empty() is not serializable. See https://github.com/spring-projects/spring-data-commons/issues/2987
Expand Down
Loading