Skip to content

Commit 1998d76

Browse files
authored
Optimize tabular modifications database operations (#650)
Signed-off-by: David BRAQUART <[email protected]>
1 parent 5f879cc commit 1998d76

34 files changed

+1244
-186
lines changed

src/main/java/org/gridsuite/modification/server/entities/EntityRegistry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.gridsuite.modification.server.entities.equipment.modification.attribute.IntegerEquipmentAttributeModificationEntity;
2121
import org.gridsuite.modification.server.entities.equipment.modification.attribute.StringEquipmentAttributeModificationEntity;
2222
import org.gridsuite.modification.server.entities.equipment.modification.byfilter.*;
23+
import org.gridsuite.modification.server.entities.tabular.TabularCreationEntity;
24+
import org.gridsuite.modification.server.entities.tabular.TabularModificationEntity;
2325

2426
/**
2527
* @author Ayoub LABIDI <ayoub.labidi at rte-france.com>

src/main/java/org/gridsuite/modification/server/entities/TabularBaseEntity.java renamed to src/main/java/org/gridsuite/modification/server/entities/tabular/TabularBaseEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
License, v. 2.0. If a copy of the MPL was not distributed with this
55
file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.modification.server.entities;
7+
package org.gridsuite.modification.server.entities.tabular;
88

99
import jakarta.persistence.CascadeType;
1010
import jakarta.persistence.FetchType;
@@ -16,6 +16,7 @@
1616
import lombok.NoArgsConstructor;
1717
import org.gridsuite.modification.dto.ModificationInfos;
1818
import org.gridsuite.modification.dto.TabularBaseInfos;
19+
import org.gridsuite.modification.server.entities.ModificationEntity;
1920

2021
import java.util.List;
2122

src/main/java/org/gridsuite/modification/server/entities/TabularCreationEntity.java renamed to src/main/java/org/gridsuite/modification/server/entities/tabular/TabularCreationEntity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
License, v. 2.0. If a copy of the MPL was not distributed with this
55
file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.modification.server.entities;
7+
package org.gridsuite.modification.server.entities.tabular;
88

99
import jakarta.persistence.CascadeType;
1010
import jakarta.persistence.Column;
@@ -21,6 +21,7 @@
2121
import org.gridsuite.modification.ModificationType;
2222
import org.gridsuite.modification.dto.ModificationInfos;
2323
import org.gridsuite.modification.dto.TabularCreationInfos;
24+
import org.gridsuite.modification.server.entities.ModificationEntity;
2425
import org.springframework.util.CollectionUtils;
2526

2627
import java.util.List;
@@ -40,7 +41,7 @@ public class TabularCreationEntity extends TabularBaseEntity {
4041
@Enumerated(EnumType.STRING)
4142
private ModificationType creationType;
4243

43-
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
44+
@OneToMany(cascade = CascadeType.ALL)
4445
@OrderColumn
4546
private List<ModificationEntity> creations;
4647

src/main/java/org/gridsuite/modification/server/entities/TabularModificationEntity.java renamed to src/main/java/org/gridsuite/modification/server/entities/tabular/TabularModificationEntity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
License, v. 2.0. If a copy of the MPL was not distributed with this
55
file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.modification.server.entities;
7+
package org.gridsuite.modification.server.entities.tabular;
88

99
import jakarta.persistence.*;
1010
import lombok.Getter;
@@ -17,6 +17,7 @@
1717

1818
import org.gridsuite.modification.ModificationType;
1919
import org.gridsuite.modification.dto.*;
20+
import org.gridsuite.modification.server.entities.ModificationEntity;
2021
import org.springframework.util.CollectionUtils;
2122

2223
/**
@@ -33,7 +34,7 @@ public class TabularModificationEntity extends TabularBaseEntity {
3334
@Enumerated(EnumType.STRING)
3435
private ModificationType modificationType;
3536

36-
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
37+
@OneToMany(cascade = CascadeType.ALL)
3738
@OrderColumn
3839
private List<ModificationEntity> modifications;
3940

src/main/java/org/gridsuite/modification/server/entities/TabularPropertyEntity.java renamed to src/main/java/org/gridsuite/modification/server/entities/tabular/TabularPropertyEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
package org.gridsuite.modification.server.entities;
8+
package org.gridsuite.modification.server.entities.tabular;
99

1010
import jakarta.persistence.Column;
1111
import jakarta.persistence.Entity;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package org.gridsuite.modification.server.repositories;
9+
10+
import org.gridsuite.modification.server.entities.equipment.creation.BatteryCreationEntity;
11+
import org.springframework.data.jpa.repository.EntityGraph;
12+
import org.springframework.data.jpa.repository.JpaRepository;
13+
import org.springframework.data.jpa.repository.Modifying;
14+
import org.springframework.data.jpa.repository.Query;
15+
16+
import java.util.List;
17+
import java.util.UUID;
18+
19+
/**
20+
* @author David Braquart <david.braquart_externe at rte-france.com>
21+
*/
22+
23+
public interface BatteryCreationRepository extends JpaRepository<BatteryCreationEntity, UUID> {
24+
@EntityGraph(attributePaths = {"reactiveCapabilityCurvePoints"}, type = EntityGraph.EntityGraphType.LOAD)
25+
List<BatteryCreationEntity> findAllReactiveCapabilityCurvePointsByIdIn(List<UUID> ids);
26+
27+
@EntityGraph(attributePaths = {"properties"}, type = EntityGraph.EntityGraphType.LOAD)
28+
List<BatteryCreationEntity> findAllPropertiesByIdIn(List<UUID> ids);
29+
30+
@Modifying
31+
@Query(value = "BEGIN;" +
32+
"DELETE FROM battery_creation_entity_reactive_capability_curve_points cp WHERE cp.battery_creation_entity_id IN ?1 ;" +
33+
"DELETE FROM free_property fp WHERE fp.equipment_modification_id IN ?1 ;" +
34+
"DELETE FROM battery_creation WHERE id IN ?1 ;" +
35+
"DELETE FROM tabular_creation_creations WHERE tabular_creation_entity_id = ?2 ;" +
36+
"DELETE FROM modification WHERE id IN ?1 ;" +
37+
"COMMIT;", nativeQuery = true)
38+
void deleteTabularSubModifications(List<UUID> subModificationIds, UUID tabularModificationId);
39+
40+
@Modifying
41+
@Query(value = "BEGIN;" +
42+
"DELETE FROM battery_creation_entity_reactive_capability_curve_points cp WHERE cp.battery_creation_entity_id IN ?1 ;" +
43+
"DELETE FROM free_property fp WHERE fp.equipment_modification_id IN ?1 ;" +
44+
"DELETE FROM battery_creation WHERE id IN ?1 ;" +
45+
"DELETE FROM tabular_creation_creations WHERE tabular_creation_entity_id = ?2 ;" +
46+
"DELETE FROM modification WHERE id IN ?1 ;" +
47+
"DELETE FROM tabular_creation WHERE id = ?2 ;" +
48+
"DELETE FROM modification WHERE id = ?2 ;" +
49+
"COMMIT;", nativeQuery = true)
50+
void deleteTabularModification(List<UUID> subModificationIds, UUID tabularModificationId);
51+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package org.gridsuite.modification.server.repositories;
9+
10+
import org.gridsuite.modification.server.entities.equipment.modification.BatteryModificationEntity;
11+
import org.springframework.data.jpa.repository.EntityGraph;
12+
import org.springframework.data.jpa.repository.JpaRepository;
13+
import org.springframework.data.jpa.repository.Modifying;
14+
import org.springframework.data.jpa.repository.Query;
15+
import org.springframework.stereotype.Repository;
16+
17+
import java.util.List;
18+
import java.util.UUID;
19+
20+
/**
21+
* @author David Braquart <david.braquart_externe at rte-france.com>
22+
*/
23+
@Repository
24+
public interface BatteryModificationRepository extends JpaRepository<BatteryModificationEntity, UUID> {
25+
26+
@EntityGraph(attributePaths = {"reactiveCapabilityCurvePoints"}, type = EntityGraph.EntityGraphType.LOAD)
27+
List<BatteryModificationEntity> findAllReactiveCapabilityCurvePointsByIdIn(List<UUID> ids);
28+
29+
@EntityGraph(attributePaths = {"properties"}, type = EntityGraph.EntityGraphType.LOAD)
30+
List<BatteryModificationEntity> findAllPropertiesByIdIn(List<UUID> ids);
31+
32+
@Modifying
33+
@Query(value = "BEGIN;" +
34+
"DELETE FROM battery_modification_entity_reactive_capability_curve_points cp WHERE cp.battery_modification_entity_id IN ?1 ;" +
35+
"DELETE FROM free_property fp WHERE fp.equipment_modification_id IN ?1 ;" +
36+
"DELETE FROM battery_modification WHERE id IN ?1 ;" +
37+
"DELETE FROM tabular_modification_modifications WHERE tabular_modification_entity_id = ?2 ;" +
38+
"DELETE FROM modification WHERE id IN ?1 ;" +
39+
"COMMIT;", nativeQuery = true)
40+
void deleteTabularSubModifications(List<UUID> subModificationIds, UUID tabularModificationId);
41+
42+
@Modifying
43+
@Query(value = "BEGIN;" +
44+
"DELETE FROM battery_modification_entity_reactive_capability_curve_points cp WHERE cp.battery_modification_entity_id IN ?1 ;" +
45+
"DELETE FROM free_property fp WHERE fp.equipment_modification_id IN ?1 ;" +
46+
"DELETE FROM battery_modification WHERE id IN ?1 ;" +
47+
"DELETE FROM tabular_modification_modifications WHERE tabular_modification_entity_id = ?2 ;" +
48+
"DELETE FROM modification WHERE id IN ?1 ;" +
49+
"DELETE FROM tabular_modification WHERE id = ?2 ;" +
50+
"DELETE FROM modification WHERE id = ?2 ;" +
51+
"COMMIT;", nativeQuery = true)
52+
void deleteTabularModification(List<UUID> subModificationIds, UUID tabularModificationId);
53+
}

src/main/java/org/gridsuite/modification/server/repositories/GeneratorCreationRepository.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.gridsuite.modification.server.entities.equipment.creation.GeneratorCreationEntity;
1111
import org.springframework.data.jpa.repository.EntityGraph;
1212
import org.springframework.data.jpa.repository.JpaRepository;
13+
import org.springframework.data.jpa.repository.Modifying;
14+
import org.springframework.data.jpa.repository.Query;
1315

1416
import java.util.List;
1517
import java.util.UUID;
@@ -24,4 +26,26 @@ public interface GeneratorCreationRepository extends JpaRepository<GeneratorCrea
2426

2527
@EntityGraph(attributePaths = {"properties"}, type = EntityGraph.EntityGraphType.LOAD)
2628
List<GeneratorCreationEntity> findAllPropertiesByIdIn(List<UUID> ids);
29+
30+
@Modifying
31+
@Query(value = "BEGIN;" +
32+
"DELETE FROM generator_creation_entity_reactive_capability_curve_points cp WHERE cp.generator_creation_entity_id IN ?1 ;" +
33+
"DELETE FROM free_property fp WHERE fp.equipment_modification_id IN ?1 ;" +
34+
"DELETE FROM generator_creation WHERE id IN ?1 ;" +
35+
"DELETE FROM tabular_creation_creations WHERE tabular_creation_entity_id = ?2 ;" +
36+
"DELETE FROM modification WHERE id IN ?1 ;" +
37+
"COMMIT;", nativeQuery = true)
38+
void deleteTabularSubModifications(List<UUID> subModificationIds, UUID tabularModificationId);
39+
40+
@Modifying
41+
@Query(value = "BEGIN;" +
42+
"DELETE FROM generator_creation_entity_reactive_capability_curve_points cp WHERE cp.generator_creation_entity_id IN ?1 ;" +
43+
"DELETE FROM free_property fp WHERE fp.equipment_modification_id IN ?1 ;" +
44+
"DELETE FROM generator_creation WHERE id IN ?1 ;" +
45+
"DELETE FROM tabular_creation_creations WHERE tabular_creation_entity_id = ?2 ;" +
46+
"DELETE FROM modification WHERE id IN ?1 ;" +
47+
"DELETE FROM tabular_creation WHERE id = ?2 ;" +
48+
"DELETE FROM modification WHERE id = ?2 ;" +
49+
"COMMIT;", nativeQuery = true)
50+
void deleteTabularModification(List<UUID> subModificationIds, UUID tabularModificationId);
2751
}

src/main/java/org/gridsuite/modification/server/repositories/GeneratorModificationRepository.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ public interface GeneratorModificationRepository extends JpaRepository<Generator
2929
@EntityGraph(attributePaths = {"properties"}, type = EntityGraph.EntityGraphType.LOAD)
3030
List<GeneratorModificationEntity> findAllPropertiesByIdIn(List<UUID> ids);
3131

32+
@Modifying
33+
@Query(value = "BEGIN;" +
34+
"DELETE FROM generator_modification_entity_reactive_capability_curve_points cp WHERE cp.generator_modification_entity_id IN ?1 ;" +
35+
"DELETE FROM free_property fp WHERE fp.equipment_modification_id IN ?1 ;" +
36+
"DELETE FROM generator_modification WHERE id IN ?1 ;" +
37+
"DELETE FROM tabular_modification_modifications WHERE tabular_modification_entity_id = ?2 ;" +
38+
"DELETE FROM modification WHERE id IN ?1 ;" +
39+
"COMMIT;", nativeQuery = true)
40+
void deleteTabularSubModifications(List<UUID> subModificationIds, UUID tabularModificationId);
41+
3242
@Modifying
3343
@Query(value = "BEGIN;" +
3444
"DELETE FROM generator_modification_entity_reactive_capability_curve_points cp WHERE cp.generator_modification_entity_id IN ?1 ;" +
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package org.gridsuite.modification.server.repositories;
9+
10+
import org.gridsuite.modification.server.entities.equipment.modification.LineModificationEntity;
11+
import org.springframework.data.jpa.repository.EntityGraph;
12+
import org.springframework.data.jpa.repository.JpaRepository;
13+
import org.springframework.data.jpa.repository.Modifying;
14+
import org.springframework.data.jpa.repository.Query;
15+
import org.springframework.stereotype.Repository;
16+
17+
import java.util.List;
18+
import java.util.UUID;
19+
20+
/**
21+
* @author David Braquart <david.braquart_externe at rte-france.com>
22+
*/
23+
@Repository
24+
public interface LineModificationRepository extends JpaRepository<LineModificationEntity, UUID> {
25+
26+
@EntityGraph(attributePaths = {"opLimitsGroups1"}, type = EntityGraph.EntityGraphType.LOAD)
27+
List<LineModificationEntity> findAllOperationalLimitsGroups1ByIdIn(List<UUID> ids);
28+
29+
@EntityGraph(attributePaths = {"opLimitsGroups2"}, type = EntityGraph.EntityGraphType.LOAD)
30+
List<LineModificationEntity> findAllOperationalLimitsGroups2ByIdIn(List<UUID> ids);
31+
32+
@EntityGraph(attributePaths = {"properties"}, type = EntityGraph.EntityGraphType.LOAD)
33+
List<LineModificationEntity> findAllPropertiesByIdIn(List<UUID> ids);
34+
35+
@Modifying
36+
@Query(value = "BEGIN;" +
37+
"DELETE FROM line_modification_op_limits_groups1 lm WHERE lm.branch_id IN ?3 ;" +
38+
"DELETE FROM line_modification_op_limits_groups2 lm WHERE lm.branch_id IN ?3 ;" +
39+
"DELETE FROM operational_limits_group_modification ol WHERE ol.uuid IN ?2 ;" +
40+
"DELETE FROM current_temporary_limits_modification cl WHERE cl.id IN ?1 ;" +
41+
"DELETE FROM current_limits_modification cl WHERE cl.id IN ?1 ;" +
42+
"DELETE FROM free_property fp WHERE fp.equipment_modification_id IN ?3 ;" +
43+
"DELETE FROM line_modification WHERE id IN ?3 ;" +
44+
"DELETE FROM tabular_modification_modifications WHERE tabular_modification_entity_id = ?4 ;" +
45+
"DELETE FROM modification WHERE id IN ?3 ;" +
46+
"COMMIT;", nativeQuery = true)
47+
void deleteTabularSubModifications(List<UUID> currentLimitsIds, List<UUID> opLimitsGroupsIds, List<UUID> subModificationIds, UUID tabularModificationId);
48+
49+
@Modifying
50+
@Query(value = "BEGIN;" +
51+
"DELETE FROM line_modification_op_limits_groups1 lm WHERE lm.branch_id IN ?3 ;" +
52+
"DELETE FROM line_modification_op_limits_groups2 lm WHERE lm.branch_id IN ?3 ;" +
53+
"DELETE FROM operational_limits_group_modification ol WHERE ol.uuid IN ?2 ;" +
54+
"DELETE FROM current_temporary_limits_modification cl WHERE cl.id IN ?1 ;" +
55+
"DELETE FROM current_limits_modification cl WHERE cl.id IN ?1 ;" +
56+
"DELETE FROM free_property fp WHERE fp.equipment_modification_id IN ?3 ;" +
57+
"DELETE FROM line_modification WHERE id IN ?3 ;" +
58+
"DELETE FROM tabular_modification_modifications WHERE tabular_modification_entity_id = ?4 ;" +
59+
"DELETE FROM modification WHERE id IN ?3 ;" +
60+
"DELETE FROM tabular_modification WHERE id = ?4 ;" +
61+
"DELETE FROM modification WHERE id = ?4 ;" +
62+
"COMMIT;", nativeQuery = true)
63+
void deleteTabularModification(List<UUID> currentLimitsIds, List<UUID> opLimitsGroupsIds, List<UUID> subModificationIds, UUID tabularModificationId);
64+
}

0 commit comments

Comments
 (0)