From 8209e9da075d013dddd227af67927f2630ad6757 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Mon, 8 Aug 2022 17:05:08 +0200 Subject: [PATCH 1/9] Substation preloading strategy Signed-off-by: Geoffroy Jamgotchian --- .../store/client/NetworkStoreService.java | 2 + .../store/client/PreloadingStrategy.java | 3 +- .../store/client/RestNetworkStoreClient.java | 5 ++ ...ubstationPreloadingNetworkStoreClient.java | 39 +++++++++++++ .../store/iidm/impl/NetworkStoreClient.java | 2 + .../iidm/impl/OfflineNetworkStoreClient.java | 5 ++ .../store/integration/NetworkStoreIT.java | 22 +++++++- .../store/server/NetworkStoreController.java | 13 +++++ .../store/server/NetworkStoreRepository.java | 56 +++++++++++++++++++ .../network/store/server/QueryCatalog.java | 10 ++++ 10 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 network-store-client/src/main/java/com/powsybl/network/store/client/SubstationPreloadingNetworkStoreClient.java diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreService.java b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreService.java index f56d86e25..bdbdfee40 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreService.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreService.java @@ -95,6 +95,8 @@ private static NetworkStoreClient createStoreClient(RestClient restClient, Prelo return cachedClient; case COLLECTION: return new PreloadingNetworkStoreClient(cachedClient); + case SUBSTATION: + return new SubstationPreloadingNetworkStoreClient(cachedClient); default: throw new IllegalStateException("Unknown preloading strategy: " + preloadingStrategy); } diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingStrategy.java b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingStrategy.java index cef87bb03..12a2429f9 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingStrategy.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingStrategy.java @@ -11,5 +11,6 @@ */ public enum PreloadingStrategy { NONE, - COLLECTION + COLLECTION, + SUBSTATION } diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index 83461deeb..a768a4ab1 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -730,6 +730,11 @@ public Optional> getIdentifiable(UUID networkUu return get("identifiable", "/networks/{networkUuid}/{variantNum}/identifiables/{id}", networkUuid, variantNum, id); } + @Override + public List> getIdentifiablesWithSameSubstationAs(UUID networkUuid, int variantNum, String id) { + return getAll("identifiable", "/networks/{networkUuid}/{variantNum}/identifiables?same_substation_as={id}", networkUuid, variantNum, id); + } + @Override public void flush() { // nothing to do diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/SubstationPreloadingNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/SubstationPreloadingNetworkStoreClient.java new file mode 100644 index 000000000..9f888730e --- /dev/null +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/SubstationPreloadingNetworkStoreClient.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2022, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.network.store.client; + +import com.powsybl.network.store.iidm.impl.AbstractForwardingNetworkStoreClient; +import com.powsybl.network.store.iidm.impl.NetworkStoreClient; +import com.powsybl.network.store.model.BusbarSectionAttributes; +import com.powsybl.network.store.model.Resource; +import com.powsybl.network.store.model.SubstationAttributes; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +/** + * @author Geoffroy Jamgotchian + */ +public class SubstationPreloadingNetworkStoreClient extends AbstractForwardingNetworkStoreClient implements NetworkStoreClient { + + public SubstationPreloadingNetworkStoreClient(NetworkStoreClient delegate) { + super(delegate); + } + + @Override + public List> getVoltageLevelBusbarSections(UUID networkUuid, int variantNum, String voltageLevelId) { + delegate.getIdentifiablesWithSameSubstationAs(networkUuid, variantNum, voltageLevelId); + return super.getVoltageLevelBusbarSections(networkUuid, variantNum, voltageLevelId); + } + + @Override + public Optional> getSubstation(UUID networkUuid, int variantNum, String substationId) { + delegate.getIdentifiablesWithSameSubstationAs(networkUuid, variantNum, substationId); + return super.getSubstation(networkUuid, variantNum, substationId); + } +} diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkStoreClient.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkStoreClient.java index 6454ac8cb..fa8d9eac1 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkStoreClient.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkStoreClient.java @@ -277,6 +277,8 @@ public interface NetworkStoreClient { Optional> getIdentifiable(UUID networkUuid, int variantNum, String id); + List> getIdentifiablesWithSameSubstationAs(UUID networkUuid, int variantNum, String id); + void flush(); } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/OfflineNetworkStoreClient.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/OfflineNetworkStoreClient.java index 80c67b559..17030c888 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/OfflineNetworkStoreClient.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/OfflineNetworkStoreClient.java @@ -574,6 +574,11 @@ public Optional> getIdentifiable(UUID networkUu return Optional.empty(); } + @Override + public List> getIdentifiablesWithSameSubstationAs(UUID networkUuid, int variantNum, String id) { + return Collections.emptyList(); + } + @Override public void flush() { // nothing to do diff --git a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java index 920aa9086..60f773884 100644 --- a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java +++ b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java @@ -92,11 +92,15 @@ private NetworkStoreService createNetworkStoreService() { } private NetworkStoreService createNetworkStoreService(RestClientMetrics metrics) { + return createNetworkStoreService(metrics, PreloadingStrategy.NONE); + } + + private NetworkStoreService createNetworkStoreService(RestClientMetrics metrics, PreloadingStrategy preloadingStrategy) { RestClient restClient = new RestClientImpl(getBaseUrl()); if (metrics != null) { restClient = new TestRestClient(restClient, metrics); } - return new NetworkStoreService(restClient, PreloadingStrategy.NONE); + return new NetworkStoreService(restClient, preloadingStrategy); } @Test @@ -5024,4 +5028,20 @@ public void testNanValues() { assertEquals(Double.NaN, generator.getTerminal().getQ(), .0001); } } + + @Test + public void testSubstationPreloading() { + UUID networkUuid; + try (NetworkStoreService service = createNetworkStoreService()) { + Network network = EurostagTutorialExample1Factory.create(service.getNetworkFactory()); + networkUuid = service.getNetworkUuid(network); + service.flush(network); + } + + RestClientMetrics metrics = new RestClientMetrics(); + try (NetworkStoreService service = createNetworkStoreService(metrics, PreloadingStrategy.SUBSTATION)) { + Network network = service.getNetwork(networkUuid); + network.getSubstation("P1"); + } + } } diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java index 01e3ec0b0..96ad8f8e7 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java @@ -1202,4 +1202,17 @@ public ResponseEntity> getIdentifiable( @Parameter(description = "Identifiable ID", required = true) @PathVariable("id") String id) { return get(() -> repository.getIdentifiable(networkId, variantNum, id)); } + + @GetMapping(value = "/{networkUuid}/{variantNum}/identifiables", produces = APPLICATION_JSON_VALUE) + @Operation(summary = "Get all identifiables with same substation as identifiable with specified id") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Successfully get all identifiables with same substation as identifiable with specified id"), + @ApiResponse(responseCode = "404", description = "The specified identifiable has not been found") + }) + public ResponseEntity> getIdentifiablesWithSameSubstationAs(@Parameter(description = "Network UUID", required = true) @PathVariable("networkUuid") UUID networkUuid, + @Parameter(description = "Variant number", required = true) @PathVariable("variantNum") int variantNum, + @Parameter(description = "An identifiable to get the substation", required = true) @RequestParam("same_substation_as") String id) { + return ResponseEntity.ok() + .body(TopLevelDocument.of(repository.getIdentifiablesWithSameSubstationAs(networkUuid, variantNum, id))); + } } diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index f56bb0af6..9c018ca51 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -1175,4 +1175,60 @@ public Optional> getIdentifiable(UUID networkUu } return Optional.empty(); } + + private List> getVoltageLevelsInSubstation(UUID networkUuid, int variantNum, String substationId) { + try (var connection = dataSource.getConnection()) { + var voltageLevelMapping = mappings.getVoltageLevelMappings(); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetVoltageLevelsInSubstationQuery(voltageLevelMapping.getColumnMapping().keySet(), substationId)); + preparedStmt.setObject(1, networkUuid); + preparedStmt.setInt(2, variantNum); + preparedStmt.setString(3, substationId); + List> resources = new ArrayList<>(3); + try (ResultSet resultSet = preparedStmt.executeQuery()) { + if (resultSet.next()) { + VoltageLevelAttributes attributes = new VoltageLevelAttributes(); + MutableInt columnIndex = new MutableInt(2); + voltageLevelMapping.getColumnMapping().forEach((columnName, columnMapping) -> { + bindAttributes(resultSet, columnIndex.getValue(), columnMapping, attributes); + columnIndex.increment(); + }); + resources.add(Resource.voltageLevelBuilder() + .id(resultSet.getString(1)) + .variantNum(variantNum) + .attributes(attributes) + .build()); + } + } + return resources; + } catch (SQLException e) { + throw new UncheckedSqlException(e); + } + } + + public List> getIdentifiablesWithSameSubstationAs(UUID networkUuid, int variantNum, String id) { + // get substation from given identifiable + Resource resource = getIdentifiable(networkUuid, variantNum, id) + .orElseThrow(() -> new PowsyblException("Identifiable '" + id + "' not found")); + String substationId; + if (resource.getType() == ResourceType.SUBSTATION) { + substationId = id; + } else if (resource.getType() == ResourceType.VOLTAGE_LEVEL) { + substationId = ((VoltageLevelAttributes) resource.getAttributes()).getSubstationId(); + } else if (resource.getAttributes() instanceof InjectionAttributes) { + String voltageLevelId = ((InjectionAttributes) resource.getAttributes()).getVoltageLevelId(); + Resource voltageLevelResource = getVoltageLevel(networkUuid, variantNum, voltageLevelId).orElseThrow(); + substationId = voltageLevelResource.getAttributes().getSubstationId(); + } else { + throw new PowsyblException("TODO"); + } + System.out.println(substationId); + + // get list of voltage levels contained in this substation + var voltageLevelResources = getVoltageLevelsInSubstation(networkUuid, variantNum, substationId); + System.out.println(voltageLevelResources); + + // get identifiables contained in these voltage levels + + return Collections.emptyList(); + } } diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index b15b2741a..73a3743b5 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -37,6 +37,7 @@ public final class QueryCatalog { static final String CONFIGURED_BUS = "configuredBus"; static final String LOAD = "load"; static final String LINE = "line"; + static final String SUBSTATION_ID = "substationId"; static final List ELEMENT_TABLES = List.of(SUBSTATION, VOLTAGE_LEVEL, BUSBAR_SECTION, CONFIGURED_BUS, SWITCH, GENERATOR, BATTERY, LOAD, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR, VSC_CONVERTER_STATION, LCC_CONVERTER_STATION, TWO_WINDINGS_TRANSFORMER, @@ -230,4 +231,13 @@ public static String buildCloneNetworksQuery(Collection columns) { " from network" + " " + "where uuid = ? and variantNum = ?"; } + + public static String buildGetVoltageLevelsInSubstationQuery(Collection columns, String substationId) { + return "select " + ID_STR + ", " + + String.join(", ", columns) + + " from " + VOLTAGE_LEVEL + + " where " + NETWORK_UUID + " = ?" + + " and " + VARIANT_NUM + " = ?" + + " and " + SUBSTATION_ID + " = ?"; + } } From ad0e9e90164f7a6344d9a1a17689e5e74af067a9 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 9 Aug 2022 09:18:42 +0200 Subject: [PATCH 2/9] Wip Signed-off-by: Geoffroy Jamgotchian --- .../store/server/NetworkStoreRepository.java | 24 ++++++++++++++++--- .../network/store/server/QueryCatalog.java | 24 +++++++++++++------ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index 9c018ca51..b57f3f21c 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -519,11 +519,21 @@ private List> getIdentifiablesInC Map mappings, String tableName, Resource.Builder resourceBuilder, Supplier attributesSupplier) { + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), containerColumnName, mappings, tableName, resourceBuilder, attributesSupplier); + } + + private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, List containerIds, + String containerColumnName, + Map mappings, String tableName, + Resource.Builder resourceBuilder, + Supplier attributesSupplier) { try (var connection = dataSource.getConnection()) { - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableName, mappings.keySet(), containerColumnName)); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableName, mappings.keySet(), containerColumnName, containerIds.size())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); - preparedStmt.setString(3, containerId); + for (int i = 0; i < containerIds.size(); i++) { + preparedStmt.setString(3 + i, containerIds.get(i)); + } return getIdentifiablesInternal(variantNum, preparedStmt, mappings, resourceBuilder, attributesSupplier); } catch (SQLException e) { throw new UncheckedSqlException(e); @@ -1205,10 +1215,15 @@ private List> getVoltageLevelsInSubstation(UUID } } + @SuppressWarnings("unchecked") public List> getIdentifiablesWithSameSubstationAs(UUID networkUuid, int variantNum, String id) { - // get substation from given identifiable + Map> resourcesById = new LinkedHashMap<>(); + Resource resource = getIdentifiable(networkUuid, variantNum, id) .orElseThrow(() -> new PowsyblException("Identifiable '" + id + "' not found")); + resourcesById.put(resource.getId(), resource); + + // get substation from given identifiable String substationId; if (resource.getType() == ResourceType.SUBSTATION) { substationId = id; @@ -1225,6 +1240,9 @@ public List> getIdentifiablesWithSameSubstation // get list of voltage levels contained in this substation var voltageLevelResources = getVoltageLevelsInSubstation(networkUuid, variantNum, substationId); + for (var voltageLevelResource : voltageLevelResources) { + resourcesById.put(voltageLevelResource.getId(), voltageLevelResource); + } System.out.println(voltageLevelResources); // get identifiables contained in these voltage levels diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index 73a3743b5..ca927aebc 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -9,6 +9,7 @@ import com.powsybl.network.store.model.Resource; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -77,13 +78,22 @@ public static String buildGetIdentifiablesQuery(String tableName, Collection columns, String containerColumnName) { - return "select " + ID_STR + ", " + - String.join(", ", columns) + - " from " + tableName + - " where " + NETWORK_UUID + " = ?" + - " and " + VARIANT_NUM + " = ?" + - " and " + containerColumnName + " = ?"; + public static String buildGetIdentifiablesInContainerQuery(String tableName, Collection columns, String containerColumnName, int containerCount) { + StringBuilder sql = new StringBuilder() + .append("select ").append(ID_STR).append(", ") + .append(String.join(", ", columns)) + .append(" from ").append(tableName) + .append(" where ").append(NETWORK_UUID).append(" = ?") + .append(" and ").append(VARIANT_NUM).append(" = ?") + .append(" and ").append(containerColumnName); + if (containerCount == 1) { + sql.append(" = ?"); + } else { + sql.append(" in (") + .append(String.join(", ", Collections.nCopies(containerCount, "?"))) + .append(")"); + } + return sql.toString(); } public static String buildGetIdentifiablesWithSideQuery(String tableName, Collection columns, String side) { From 3250dc8dadf8fb1206c1ae62dcd2a5a34ea09b89 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 9 Aug 2022 14:57:12 +0200 Subject: [PATCH 3/9] Wip Signed-off-by: Geoffroy Jamgotchian --- .../store/server/NetworkStoreRepository.java | 17 ++++++++++++++--- .../network/store/server/QueryCatalog.java | 10 ++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index 1c7753fc7..efddb44b5 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -523,7 +523,7 @@ private List> getIdentifiablesInC Map mappings, String tableName, Resource.Builder resourceBuilder, Supplier attributesSupplier) { - return getIdentifiablesInContainer(networkUuid, variantNum, containerId, Set.of(containerColumn), mappings, tableName, resourceBuilder, attributesSupplier); + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), Set.of(containerColumn), mappings, tableName, resourceBuilder, attributesSupplier); } private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, String containerId, @@ -531,12 +531,23 @@ private List> getIdentifiablesInC Map mappings, String tableName, Resource.Builder resourceBuilder, Supplier attributesSupplier) { + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), containerColumns, mappings, tableName, resourceBuilder, attributesSupplier); + } + + private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, List containerIds, + Set containerColumns, + Map mappings, String tableName, + Resource.Builder resourceBuilder, + Supplier attributesSupplier) { try (var connection = dataSource.getConnection()) { - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableName, mappings.keySet(), containerColumns)); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableName, mappings.keySet(), containerColumns, containerIds.size())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); for (int i = 0; i < containerColumns.size(); i++) { - preparedStmt.setString(3 + i, containerId); + for (int j = 0; j < containerIds.size(); j++) { + String containerId = containerIds.get(j); + preparedStmt.setString(3 + i * containerIds.size() + j, containerId); + } } return getIdentifiablesInternal(variantNum, preparedStmt, mappings, resourceBuilder, attributesSupplier); } catch (SQLException e) { diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index 5a07e5bc6..c81fa4529 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -79,7 +79,8 @@ public static String buildGetIdentifiablesQuery(String tableName, Collection columns, Set containerColumns) { + public static String buildGetIdentifiablesInContainerQuery(String tableName, Collection columns, Set containerColumns, + int containerIdsSize) { StringBuilder sql = new StringBuilder() .append("select ").append(ID_STR).append(", ") .append(String.join(", ", columns)) @@ -90,7 +91,12 @@ public static String buildGetIdentifiablesInContainerQuery(String tableName, Col var it = containerColumns.iterator(); while (it.hasNext()) { String containerColumn = it.next(); - sql.append(containerColumn).append(" = ?"); + sql.append(containerColumn); + if (containerIdsSize == 1) { + sql.append(" = ?"); + } else { + sql.append(" in (").append(String.join(", ", Collections.nCopies(containerIdsSize, "?"))).append(")"); + } if (it.hasNext()) { sql.append(" or "); } From d1e5c5a0dc7d2322e72b25ff5ad4f8f811e8fd15 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 9 Aug 2022 15:33:57 +0200 Subject: [PATCH 4/9] Wip Signed-off-by: Geoffroy Jamgotchian --- .../network/store/server/Mappings.java | 59 ++++-- .../store/server/NetworkStoreRepository.java | 186 ++++++++---------- .../network/store/server/QueryCatalog.java | 40 +--- 3 files changed, 138 insertions(+), 147 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java index 5c14cf549..71c1f22cc 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java @@ -20,24 +20,47 @@ @Service public class Mappings { - private final TableMapping lineMappings = new TableMapping("line", ResourceType.LINE, LineAttributes::new); - private final TableMapping loadMappings = new TableMapping("load", ResourceType.LOAD, LoadAttributes::new); - private final TableMapping generatorMappings = new TableMapping("generator", ResourceType.GENERATOR, GeneratorAttributes::new); - private final TableMapping switchMappings = new TableMapping("switch", ResourceType.SWITCH, SwitchAttributes::new); - private final TableMapping substationMappings = new TableMapping("substation", ResourceType.SUBSTATION, SubstationAttributes::new); - private final TableMapping networkMappings = new TableMapping("network", ResourceType.NETWORK, NetworkAttributes::new); - private final TableMapping voltageLevelMappings = new TableMapping("voltageLevel", ResourceType.VOLTAGE_LEVEL, VoltageLevelAttributes::new); - private final TableMapping batteryMappings = new TableMapping("battery", ResourceType.BATTERY, BatteryAttributes::new); - private final TableMapping busbarSectionMappings = new TableMapping("busbarSection", ResourceType.BUSBAR_SECTION, BusbarSectionAttributes::new); - private final TableMapping configuredBusMappings = new TableMapping("configuredBus", ResourceType.CONFIGURED_BUS, ConfiguredBusAttributes::new); - private final TableMapping danglingLineMappings = new TableMapping("danglingLine", ResourceType.DANGLING_LINE, DanglingLineAttributes::new); - private final TableMapping shuntCompensatorMappings = new TableMapping("shuntCompensator", ResourceType.SHUNT_COMPENSATOR, ShuntCompensatorAttributes::new); - private final TableMapping vscConverterStationMappings = new TableMapping("vscConverterStation", ResourceType.VSC_CONVERTER_STATION, VscConverterStationAttributes::new); - private final TableMapping lccConverterStationMappings = new TableMapping("lccConverterStation", ResourceType.LCC_CONVERTER_STATION, LccConverterStationAttributes::new); - private final TableMapping staticVarCompensatorMappings = new TableMapping("staticVarCompensator", ResourceType.STATIC_VAR_COMPENSATOR, StaticVarCompensatorAttributes::new); - private final TableMapping hvdcLineMappings = new TableMapping("hvdcLine", ResourceType.HVDC_LINE, HvdcLineAttributes::new); - private final TableMapping twoWindingsTransformerMappings = new TableMapping("twoWindingsTransformer", ResourceType.TWO_WINDINGS_TRANSFORMER, TwoWindingsTransformerAttributes::new); - private final TableMapping threeWindingsTransformerMappings = new TableMapping("threeWindingsTransformer", ResourceType.THREE_WINDINGS_TRANSFORMER, ThreeWindingsTransformerAttributes::new); + static final String NETWORK_TABLE = "network"; + static final String SUBSTATION_TABLE = "substation"; + static final String VOLTAGE_LEVEL_TABLE = "voltageLevel"; + static final String GENERATOR_TABLE = "generator"; + static final String BATTERY_TABLE = "battery"; + static final String SHUNT_COMPENSATOR_TABLE = "shuntCompensator"; + static final String VSC_CONVERTER_STATION_TABLE = "vscConverterStation"; + static final String LCC_CONVERTER_STATION_TABLE = "lccConverterStation"; + static final String STATIC_VAR_COMPENSATOR_TABLE = "staticVarCompensator"; + static final String BUSBAR_SECTION_TABLE = "busbarSection"; + static final String SWITCH_TABLE = "switch"; + static final String TWO_WINDINGS_TRANSFORMER_TABLE = "twoWindingsTransformer"; + static final String THREE_WINDINGS_TRANSFORMER_TABLE = "threeWindingsTransformer"; + static final String HVDC_LINE_TABLE = "hvdcLine"; + static final String DANGLING_LINE_TABLE = "danglingLine"; + static final String CONFIGURED_BUS_TABLE = "configuredBus"; + static final String LOAD_TABLE = "load"; + static final String LINE_TABLE = "line"; + + static final List ELEMENT_TABLES = List.of(SUBSTATION_TABLE, VOLTAGE_LEVEL_TABLE, BUSBAR_SECTION_TABLE, CONFIGURED_BUS_TABLE, SWITCH_TABLE, GENERATOR_TABLE, BATTERY_TABLE, LOAD_TABLE, SHUNT_COMPENSATOR_TABLE, + STATIC_VAR_COMPENSATOR_TABLE, VSC_CONVERTER_STATION_TABLE, LCC_CONVERTER_STATION_TABLE, TWO_WINDINGS_TRANSFORMER_TABLE, + THREE_WINDINGS_TRANSFORMER_TABLE, LINE_TABLE, HVDC_LINE_TABLE, DANGLING_LINE_TABLE); + + private final TableMapping lineMappings = new TableMapping(LINE_TABLE, ResourceType.LINE, LineAttributes::new); + private final TableMapping loadMappings = new TableMapping(LOAD_TABLE, ResourceType.LOAD, LoadAttributes::new); + private final TableMapping generatorMappings = new TableMapping(GENERATOR_TABLE, ResourceType.GENERATOR, GeneratorAttributes::new); + private final TableMapping switchMappings = new TableMapping(SWITCH_TABLE, ResourceType.SWITCH, SwitchAttributes::new); + private final TableMapping substationMappings = new TableMapping(SUBSTATION_TABLE, ResourceType.SUBSTATION, SubstationAttributes::new); + private final TableMapping networkMappings = new TableMapping(NETWORK_TABLE, ResourceType.NETWORK, NetworkAttributes::new); + private final TableMapping voltageLevelMappings = new TableMapping(VOLTAGE_LEVEL_TABLE, ResourceType.VOLTAGE_LEVEL, VoltageLevelAttributes::new); + private final TableMapping batteryMappings = new TableMapping(BATTERY_TABLE, ResourceType.BATTERY, BatteryAttributes::new); + private final TableMapping busbarSectionMappings = new TableMapping(BUSBAR_SECTION_TABLE, ResourceType.BUSBAR_SECTION, BusbarSectionAttributes::new); + private final TableMapping configuredBusMappings = new TableMapping(CONFIGURED_BUS_TABLE, ResourceType.CONFIGURED_BUS, ConfiguredBusAttributes::new); + private final TableMapping danglingLineMappings = new TableMapping(DANGLING_LINE_TABLE, ResourceType.DANGLING_LINE, DanglingLineAttributes::new); + private final TableMapping shuntCompensatorMappings = new TableMapping(SHUNT_COMPENSATOR_TABLE, ResourceType.SHUNT_COMPENSATOR, ShuntCompensatorAttributes::new); + private final TableMapping vscConverterStationMappings = new TableMapping(VSC_CONVERTER_STATION_TABLE, ResourceType.VSC_CONVERTER_STATION, VscConverterStationAttributes::new); + private final TableMapping lccConverterStationMappings = new TableMapping(LCC_CONVERTER_STATION_TABLE, ResourceType.LCC_CONVERTER_STATION, LccConverterStationAttributes::new); + private final TableMapping staticVarCompensatorMappings = new TableMapping(STATIC_VAR_COMPENSATOR_TABLE, ResourceType.STATIC_VAR_COMPENSATOR, StaticVarCompensatorAttributes::new); + private final TableMapping hvdcLineMappings = new TableMapping(HVDC_LINE_TABLE, ResourceType.HVDC_LINE, HvdcLineAttributes::new); + private final TableMapping twoWindingsTransformerMappings = new TableMapping(TWO_WINDINGS_TRANSFORMER_TABLE, ResourceType.TWO_WINDINGS_TRANSFORMER, TwoWindingsTransformerAttributes::new); + private final TableMapping threeWindingsTransformerMappings = new TableMapping(THREE_WINDINGS_TRANSFORMER_TABLE, ResourceType.THREE_WINDINGS_TRANSFORMER, ThreeWindingsTransformerAttributes::new); private final List all = List.of(lineMappings, loadMappings, diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index efddb44b5..8960d327a 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -36,6 +36,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; +import static com.powsybl.network.store.server.Mappings.*; import static com.powsybl.network.store.server.QueryCatalog.*; /** @@ -452,11 +453,11 @@ public void createIdentifiables(UUID networkU } private Optional> getIdentifiable(UUID networkUuid, int variantNum, String equipmentId, - Map mappings, String tableName, + TableMapping tableMapping, Resource.Builder resourceBuilder, Supplier attributesSupplier) { try (var connection = dataSource.getConnection()) { - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiableQuery(tableName, mappings.keySet())); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiableQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); preparedStmt.setString(3, equipmentId); @@ -464,7 +465,7 @@ private Optional> getIdentifiable if (resultSet.next()) { T attributes = attributesSupplier.get(); MutableInt columnIndex = new MutableInt(1); - mappings.forEach((columnName, columnMapping) -> { + tableMapping.getColumnMapping().forEach((columnName, columnMapping) -> { bindAttributes(resultSet, columnIndex.getValue(), columnMapping, attributes); columnIndex.increment(); }); @@ -505,14 +506,14 @@ private List> getIdentifiablesInt } private List> getIdentifiables(UUID networkUuid, int variantNum, - Map mappings, String tableName, + TableMapping tableMapping, Resource.Builder resourceBuilder, Supplier attributesSupplier) { try (var connection = dataSource.getConnection()) { - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesQuery(tableName, mappings.keySet())); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); - return getIdentifiablesInternal(variantNum, preparedStmt, mappings, resourceBuilder, attributesSupplier); + return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping.getColumnMapping(), resourceBuilder, attributesSupplier); } catch (SQLException e) { throw new UncheckedSqlException(e); } @@ -520,27 +521,27 @@ private List> getIdentifiables(UU private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, String containerId, String containerColumn, - Map mappings, String tableName, + TableMapping tableMapping, Resource.Builder resourceBuilder, Supplier attributesSupplier) { - return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), Set.of(containerColumn), mappings, tableName, resourceBuilder, attributesSupplier); + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), Set.of(containerColumn), tableMapping, resourceBuilder, attributesSupplier); } private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, String containerId, Set containerColumns, - Map mappings, String tableName, + TableMapping tableMapping, Resource.Builder resourceBuilder, Supplier attributesSupplier) { - return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), containerColumns, mappings, tableName, resourceBuilder, attributesSupplier); + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), containerColumns, tableMapping, resourceBuilder, attributesSupplier); } private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, List containerIds, Set containerColumns, - Map mappings, String tableName, + TableMapping tableMapping, Resource.Builder resourceBuilder, Supplier attributesSupplier) { try (var connection = dataSource.getConnection()) { - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableName, mappings.keySet(), containerColumns, containerIds.size())); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet(), containerColumns, containerIds.size())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); for (int i = 0; i < containerColumns.size(); i++) { @@ -549,7 +550,7 @@ private List> getIdentifiablesInC preparedStmt.setString(3 + i * containerIds.size() + j, containerId); } } - return getIdentifiablesInternal(variantNum, preparedStmt, mappings, resourceBuilder, attributesSupplier); + return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping.getColumnMapping(), resourceBuilder, attributesSupplier); } catch (SQLException e) { throw new UncheckedSqlException(e); } @@ -626,12 +627,11 @@ public void deleteIdentifiable(UUID networkUuid, int variantNum, String id, Stri // substation public List> getSubstations(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getSubstationMappings().getColumnMapping(), SUBSTATION, Resource.substationBuilder(), SubstationAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getSubstationMappings(), Resource.substationBuilder(), SubstationAttributes::new); } public Optional> getSubstation(UUID networkUuid, int variantNum, String substationId) { - return getIdentifiable(networkUuid, variantNum, substationId, mappings.getSubstationMappings().getColumnMapping(), - SUBSTATION, Resource.substationBuilder(), SubstationAttributes::new); + return getIdentifiable(networkUuid, variantNum, substationId, mappings.getSubstationMappings(), Resource.substationBuilder(), SubstationAttributes::new); } public void createSubstations(UUID networkUuid, List> resources) { @@ -643,7 +643,7 @@ public void updateSubstations(UUID networkUuid, List> getVoltageLevels(UUID networkUuid, int variantNum, String substationId) { - return getIdentifiablesInContainer(networkUuid, variantNum, substationId, SUBSTATION_ID, mappings.getVoltageLevelMappings().getColumnMapping(), VOLTAGE_LEVEL, Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, substationId, SUBSTATION_ID, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); } public Optional> getVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiable(networkUuid, variantNum, voltageLevelId, mappings.getVoltageLevelMappings().getColumnMapping(), - VOLTAGE_LEVEL, Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); + return getIdentifiable(networkUuid, variantNum, voltageLevelId, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); } public List> getVoltageLevels(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getVoltageLevelMappings().getColumnMapping(), VOLTAGE_LEVEL, Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); } public void deleteVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId) { - deleteIdentifiable(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL); + deleteIdentifiable(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_TABLE); } // generator @@ -680,16 +679,15 @@ public void createGenerators(UUID networkUuid, List> getGenerator(UUID networkUuid, int variantNum, String generatorId) { - return getIdentifiable(networkUuid, variantNum, generatorId, mappings.getGeneratorMappings().getColumnMapping(), - GENERATOR, Resource.generatorBuilder(), GeneratorAttributes::new); + return getIdentifiable(networkUuid, variantNum, generatorId, mappings.getGeneratorMappings(), Resource.generatorBuilder(), GeneratorAttributes::new); } public List> getGenerators(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getGeneratorMappings().getColumnMapping(), GENERATOR, Resource.generatorBuilder(), GeneratorAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getGeneratorMappings(), Resource.generatorBuilder(), GeneratorAttributes::new); } public List> getVoltageLevelGenerators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getGeneratorMappings().getColumnMapping(), GENERATOR, Resource.generatorBuilder(), GeneratorAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getGeneratorMappings(), Resource.generatorBuilder(), GeneratorAttributes::new); } public void updateGenerators(UUID networkUuid, List> resources) { @@ -697,7 +695,7 @@ public void updateGenerators(UUID networkUuid, List> } public Optional> getBattery(UUID networkUuid, int variantNum, String batteryId) { - return getIdentifiable(networkUuid, variantNum, batteryId, mappings.getBatteryMappings().getColumnMapping(), - BATTERY, Resource.batteryBuilder(), BatteryAttributes::new); + return getIdentifiable(networkUuid, variantNum, batteryId, mappings.getBatteryMappings(), Resource.batteryBuilder(), BatteryAttributes::new); } public List> getBatteries(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getBatteryMappings().getColumnMapping(), BATTERY, Resource.batteryBuilder(), BatteryAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getBatteryMappings(), Resource.batteryBuilder(), BatteryAttributes::new); } public List> getVoltageLevelBatteries(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBatteryMappings().getColumnMapping(), BATTERY, Resource.batteryBuilder(), BatteryAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBatteryMappings(), Resource.batteryBuilder(), BatteryAttributes::new); } public void updateBatteries(UUID networkUuid, List> resources) { @@ -724,7 +721,7 @@ public void updateBatteries(UUID networkUuid, List> } public void deleteBattery(UUID networkUuid, int variantNum, String batteryId) { - deleteIdentifiable(networkUuid, variantNum, batteryId, BATTERY); + deleteIdentifiable(networkUuid, variantNum, batteryId, BATTERY_TABLE); } // load @@ -734,16 +731,15 @@ public void createLoads(UUID networkUuid, List> resourc } public Optional> getLoad(UUID networkUuid, int variantNum, String loadId) { - return getIdentifiable(networkUuid, variantNum, loadId, mappings.getLoadMappings().getColumnMapping(), - LOAD, Resource.loadBuilder(), LoadAttributes::new); + return getIdentifiable(networkUuid, variantNum, loadId, mappings.getLoadMappings(), Resource.loadBuilder(), LoadAttributes::new); } public List> getLoads(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getLoadMappings().getColumnMapping(), LOAD, Resource.loadBuilder(), LoadAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getLoadMappings(), Resource.loadBuilder(), LoadAttributes::new); } public List> getVoltageLevelLoads(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLoadMappings().getColumnMapping(), LOAD, Resource.loadBuilder(), LoadAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLoadMappings(), Resource.loadBuilder(), LoadAttributes::new); } public void updateLoads(UUID networkUuid, List> resources) { @@ -751,7 +747,7 @@ public void updateLoads(UUID networkUuid, List> resourc } public void deleteLoad(UUID networkUuid, int variantNum, String loadId) { - deleteIdentifiable(networkUuid, variantNum, loadId, LOAD); + deleteIdentifiable(networkUuid, variantNum, loadId, LOAD_TABLE); } // shunt compensator @@ -761,16 +757,15 @@ public void createShuntCompensators(UUID networkUuid, List> getShuntCompensator(UUID networkUuid, int variantNum, String shuntCompensatorId) { - return getIdentifiable(networkUuid, variantNum, shuntCompensatorId, mappings.getShuntCompensatorMappings().getColumnMapping(), - SHUNT_COMPENSATOR, Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); + return getIdentifiable(networkUuid, variantNum, shuntCompensatorId, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); } public List> getShuntCompensators(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getShuntCompensatorMappings().getColumnMapping(), SHUNT_COMPENSATOR, Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); } public List> getVoltageLevelShuntCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getShuntCompensatorMappings().getColumnMapping(), SHUNT_COMPENSATOR, Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); } public void updateShuntCompensators(UUID networkUuid, List> resources) { @@ -778,7 +773,7 @@ public void updateShuntCompensators(UUID networkUuid, List> getVscConverterStation(UUID networkUuid, int variantNum, String vscConverterStationId) { - return getIdentifiable(networkUuid, variantNum, vscConverterStationId, mappings.getVscConverterStationMappings().getColumnMapping(), - VSC_CONVERTER_STATION, Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); + return getIdentifiable(networkUuid, variantNum, vscConverterStationId, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); } public List> getVscConverterStations(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getVscConverterStationMappings().getColumnMapping(), VSC_CONVERTER_STATION, Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); } public List> getVoltageLevelVscConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getVscConverterStationMappings().getColumnMapping(), VSC_CONVERTER_STATION, Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); } public void updateVscConverterStations(UUID networkUuid, List> resources) { @@ -805,7 +799,7 @@ public void updateVscConverterStations(UUID networkUuid, List> getLccConverterStation(UUID networkUuid, int variantNum, String lccConverterStationId) { - return getIdentifiable(networkUuid, variantNum, lccConverterStationId, mappings.getLccConverterStationMappings().getColumnMapping(), - LCC_CONVERTER_STATION, Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); + return getIdentifiable(networkUuid, variantNum, lccConverterStationId, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); } public List> getLccConverterStations(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getLccConverterStationMappings().getColumnMapping(), LCC_CONVERTER_STATION, Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); } public List> getVoltageLevelLccConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLccConverterStationMappings().getColumnMapping(), LCC_CONVERTER_STATION, Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); } public void updateLccConverterStations(UUID networkUuid, List> resources) { @@ -832,7 +825,7 @@ public void updateLccConverterStations(UUID networkUuid, List> getStaticVarCompensator(UUID networkUuid, int variantNum, String staticVarCompensatorId) { - return getIdentifiable(networkUuid, variantNum, staticVarCompensatorId, mappings.getStaticVarCompensatorMappings().getColumnMapping(), - STATIC_VAR_COMPENSATOR, Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); + return getIdentifiable(networkUuid, variantNum, staticVarCompensatorId, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); } public List> getStaticVarCompensators(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getStaticVarCompensatorMappings().getColumnMapping(), STATIC_VAR_COMPENSATOR, Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); } public List> getVoltageLevelStaticVarCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getStaticVarCompensatorMappings().getColumnMapping(), STATIC_VAR_COMPENSATOR, Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); } public void updateStaticVarCompensators(UUID networkUuid, List> resources) { @@ -859,7 +851,7 @@ public void updateStaticVarCompensators(UUID networkUuid, List> getBusbarSection(UUID networkUuid, int variantNum, String busbarSectionId) { - return getIdentifiable(networkUuid, variantNum, busbarSectionId, mappings.getBusbarSectionMappings().getColumnMapping(), - BUSBAR_SECTION, Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); + return getIdentifiable(networkUuid, variantNum, busbarSectionId, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); } public List> getBusbarSections(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getBusbarSectionMappings().getColumnMapping(), BUSBAR_SECTION, Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); } public List> getVoltageLevelBusbarSections(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBusbarSectionMappings().getColumnMapping(), BUSBAR_SECTION, Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); } public void deleteBusBarSection(UUID networkUuid, int variantNum, String busBarSectionId) { - deleteIdentifiable(networkUuid, variantNum, busBarSectionId, BUSBAR_SECTION); + deleteIdentifiable(networkUuid, variantNum, busBarSectionId, BUSBAR_SECTION_TABLE); } // switch @@ -896,16 +887,15 @@ public void createSwitches(UUID networkUuid, List> re } public Optional> getSwitch(UUID networkUuid, int variantNum, String switchId) { - return getIdentifiable(networkUuid, variantNum, switchId, mappings.getSwitchMappings().getColumnMapping(), - SWITCH, Resource.switchBuilder(), SwitchAttributes::new); + return getIdentifiable(networkUuid, variantNum, switchId, mappings.getSwitchMappings(), Resource.switchBuilder(), SwitchAttributes::new); } public List> getSwitches(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getSwitchMappings().getColumnMapping(), SWITCH, Resource.switchBuilder(), SwitchAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getSwitchMappings(), Resource.switchBuilder(), SwitchAttributes::new); } public List> getVoltageLevelSwitches(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getSwitchMappings().getColumnMapping(), SWITCH, Resource.switchBuilder(), SwitchAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getSwitchMappings(), Resource.switchBuilder(), SwitchAttributes::new); } public void updateSwitches(UUID networkUuid, List> resources) { @@ -913,7 +903,7 @@ public void updateSwitches(UUID networkUuid, List> re } public void deleteSwitch(UUID networkUuid, int variantNum, String switchId) { - deleteIdentifiable(networkUuid, variantNum, switchId, SWITCH); + deleteIdentifiable(networkUuid, variantNum, switchId, SWITCH_TABLE); } // 2 windings transformer @@ -923,16 +913,15 @@ public void createTwoWindingsTransformers(UUID networkUuid, List> getTwoWindingsTransformer(UUID networkUuid, int variantNum, String twoWindingsTransformerId) { - return getIdentifiable(networkUuid, variantNum, twoWindingsTransformerId, mappings.getTwoWindingsTransformerMappings().getColumnMapping(), - TWO_WINDINGS_TRANSFORMER, Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); + return getIdentifiable(networkUuid, variantNum, twoWindingsTransformerId, mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); } public List> getTwoWindingsTransformers(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getTwoWindingsTransformerMappings().getColumnMapping(), TWO_WINDINGS_TRANSFORMER, Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); } public List> getVoltageLevelTwoWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getTwoWindingsTransformerMappings().getColumnMapping(), TWO_WINDINGS_TRANSFORMER, Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); } public void updateTwoWindingsTransformers(UUID networkUuid, List> resources) { @@ -940,7 +929,7 @@ public void updateTwoWindingsTransformers(UUID networkUuid, List> getThreeWindingsTransformer(UUID networkUuid, int variantNum, String threeWindingsTransformerId) { - return getIdentifiable(networkUuid, variantNum, threeWindingsTransformerId, mappings.getThreeWindingsTransformerMappings().getColumnMapping(), - THREE_WINDINGS_TRANSFORMER, Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); + return getIdentifiable(networkUuid, variantNum, threeWindingsTransformerId, mappings.getThreeWindingsTransformerMappings(), Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); } public List> getThreeWindingsTransformers(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getThreeWindingsTransformerMappings().getColumnMapping(), THREE_WINDINGS_TRANSFORMER, + return getIdentifiables(networkUuid, variantNum, mappings.getThreeWindingsTransformerMappings(), Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); } public List> getVoltageLevelThreeWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2", "voltageLevelId3"), mappings.getThreeWindingsTransformerMappings().getColumnMapping(), THREE_WINDINGS_TRANSFORMER, + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2", "voltageLevelId3"), mappings.getThreeWindingsTransformerMappings(), Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); } @@ -969,7 +957,7 @@ public void updateThreeWindingsTransformers(UUID networkUuid, List> resourc } public Optional> getLine(UUID networkUuid, int variantNum, String lineId) { - return getIdentifiable(networkUuid, variantNum, lineId, mappings.getLineMappings().getColumnMapping(), - LINE, Resource.lineBuilder(), LineAttributes::new); + return getIdentifiable(networkUuid, variantNum, lineId, mappings.getLineMappings(), Resource.lineBuilder(), LineAttributes::new); } public List> getLines(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getLineMappings().getColumnMapping(), LINE, Resource.lineBuilder(), LineAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getLineMappings(), Resource.lineBuilder(), LineAttributes::new); } public List> getVoltageLevelLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getLineMappings().getColumnMapping(), LINE, Resource.lineBuilder(), LineAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getLineMappings(), Resource.lineBuilder(), LineAttributes::new); } public void updateLines(UUID networkUuid, List> resources) { @@ -996,18 +983,17 @@ public void updateLines(UUID networkUuid, List> resourc } public void deleteLine(UUID networkUuid, int variantNum, String lineId) { - deleteIdentifiable(networkUuid, variantNum, lineId, LINE); + deleteIdentifiable(networkUuid, variantNum, lineId, LINE_TABLE); } // Hvdc line public List> getHvdcLines(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getHvdcLineMappings().getColumnMapping(), HVDC_LINE, Resource.hvdcLineBuilder(), HvdcLineAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getHvdcLineMappings(), Resource.hvdcLineBuilder(), HvdcLineAttributes::new); } public Optional> getHvdcLine(UUID networkUuid, int variantNum, String hvdcLineId) { - return getIdentifiable(networkUuid, variantNum, hvdcLineId, mappings.getHvdcLineMappings().getColumnMapping(), - HVDC_LINE, Resource.hvdcLineBuilder(), HvdcLineAttributes::new); + return getIdentifiable(networkUuid, variantNum, hvdcLineId, mappings.getHvdcLineMappings(), Resource.hvdcLineBuilder(), HvdcLineAttributes::new); } public void createHvdcLines(UUID networkUuid, List> resources) { @@ -1019,22 +1005,21 @@ public void updateHvdcLines(UUID networkUuid, List> } public void deleteHvdcLine(UUID networkUuid, int variantNum, String hvdcLineId) { - deleteIdentifiable(networkUuid, variantNum, hvdcLineId, HVDC_LINE); + deleteIdentifiable(networkUuid, variantNum, hvdcLineId, HVDC_LINE_TABLE); } // Dangling line public List> getDanglingLines(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getDanglingLineMappings().getColumnMapping(), DANGLING_LINE, Resource.danglingLineBuilder(), DanglingLineAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder(), DanglingLineAttributes::new); } public Optional> getDanglingLine(UUID networkUuid, int variantNum, String danglingLineId) { - return getIdentifiable(networkUuid, variantNum, danglingLineId, mappings.getDanglingLineMappings().getColumnMapping(), - DANGLING_LINE, Resource.danglingLineBuilder(), DanglingLineAttributes::new); + return getIdentifiable(networkUuid, variantNum, danglingLineId, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder(), DanglingLineAttributes::new); } public List> getVoltageLevelDanglingLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getDanglingLineMappings().getColumnMapping(), DANGLING_LINE, Resource.danglingLineBuilder(), DanglingLineAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder(), DanglingLineAttributes::new); } public void createDanglingLines(UUID networkUuid, List> resources) { @@ -1042,7 +1027,7 @@ public void createDanglingLines(UUID networkUuid, List> resources) { @@ -1056,16 +1041,15 @@ public void createBuses(UUID networkUuid, List } public Optional> getConfiguredBus(UUID networkUuid, int variantNum, String busId) { - return getIdentifiable(networkUuid, variantNum, busId, mappings.getConfiguredBusMappings().getColumnMapping(), - CONFIGURED_BUS, Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); + return getIdentifiable(networkUuid, variantNum, busId, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); } public List> getConfiguredBuses(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getConfiguredBusMappings().getColumnMapping(), CONFIGURED_BUS, Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); } public List> getVoltageLevelBuses(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getConfiguredBusMappings().getColumnMapping(), CONFIGURED_BUS, Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); } public void updateBuses(UUID networkUuid, List> resources) { @@ -1073,7 +1057,7 @@ public void updateBuses(UUID networkUuid, List } public void deleteBus(UUID networkUuid, int variantNum, String configuredBusId) { - deleteIdentifiable(networkUuid, variantNum, configuredBusId, CONFIGURED_BUS); + deleteIdentifiable(networkUuid, variantNum, configuredBusId, CONFIGURED_BUS_TABLE); } private static String getNonEmptyTable(ResultSet resultSet) throws SQLException { @@ -1163,8 +1147,12 @@ private List> getVoltageLevelsInSubstation(UUID } @SuppressWarnings("unchecked") + private static Resource downcast(Resource r) { + return (Resource) r; + } + public List> getIdentifiablesWithSameSubstationAs(UUID networkUuid, int variantNum, String id) { - Map> resourcesById = new LinkedHashMap<>(); + Map> resourcesById = new LinkedHashMap<>(); Resource resource = getIdentifiable(networkUuid, variantNum, id) .orElseThrow(() -> new PowsyblException("Identifiable '" + id + "' not found")); @@ -1188,12 +1176,12 @@ public List> getIdentifiablesWithSameSubstation // get list of voltage levels contained in this substation var voltageLevelResources = getVoltageLevelsInSubstation(networkUuid, variantNum, substationId); for (var voltageLevelResource : voltageLevelResources) { - resourcesById.put(voltageLevelResource.getId(), voltageLevelResource); + resourcesById.put(voltageLevelResource.getId(), downcast(voltageLevelResource)); } System.out.println(voltageLevelResources); // get identifiables contained in these voltage levels - return Collections.emptyList(); + return new ArrayList<>(resourcesById.values()); } } diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index c81fa4529..f6fe5b351 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -10,10 +10,11 @@ import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import static com.powsybl.network.store.server.Mappings.*; + /** * @author Geoffroy Jamgotchian */ @@ -21,29 +22,8 @@ public final class QueryCatalog { static final String VARIANT_ID = "variantId"; static final String UUID_STR = "uuid"; - static final String NETWORK = "network"; - static final String SUBSTATION = "substation"; - static final String VOLTAGE_LEVEL = "voltageLevel"; - static final String GENERATOR = "generator"; - static final String BATTERY = "battery"; - static final String SHUNT_COMPENSATOR = "shuntCompensator"; - static final String VSC_CONVERTER_STATION = "vscConverterStation"; - static final String LCC_CONVERTER_STATION = "lccConverterStation"; - static final String STATIC_VAR_COMPENSATOR = "staticVarCompensator"; - static final String BUSBAR_SECTION = "busbarSection"; - static final String SWITCH = "switch"; - static final String TWO_WINDINGS_TRANSFORMER = "twoWindingsTransformer"; - static final String THREE_WINDINGS_TRANSFORMER = "threeWindingsTransformer"; - static final String HVDC_LINE = "hvdcLine"; - static final String DANGLING_LINE = "danglingLine"; - static final String CONFIGURED_BUS = "configuredBus"; - static final String LOAD = "load"; - static final String LINE = "line"; - static final String SUBSTATION_ID = "substationId"; - static final List ELEMENT_TABLES = List.of(SUBSTATION, VOLTAGE_LEVEL, BUSBAR_SECTION, CONFIGURED_BUS, SWITCH, GENERATOR, BATTERY, LOAD, SHUNT_COMPENSATOR, - STATIC_VAR_COMPENSATOR, VSC_CONVERTER_STATION, LCC_CONVERTER_STATION, TWO_WINDINGS_TRANSFORMER, - THREE_WINDINGS_TRANSFORMER, LINE, HVDC_LINE, DANGLING_LINE); + static final String SUBSTATION_ID = "substationId"; static final String NETWORK_UUID = "networkUuid"; static final String VARIANT_NUM = "variantNum"; @@ -66,7 +46,7 @@ public static String buildGetIdentifiableQuery(String tableName, Collection columns) { return "select " + ID_STR + ", " + String.join(", ", columns) + - " from " + NETWORK + + " from " + NETWORK_TABLE + " where " + UUID_STR + " = ?" + " and " + VARIANT_NUM + " = ?"; } @@ -114,11 +94,11 @@ public static String buildDeleteIdentifiableQuery(String tableName) { } public static String buildDeleteNetworkQuery() { - return "delete from " + NETWORK + " where " + UUID_STR + " = ?"; + return "delete from " + NETWORK_TABLE + " where " + UUID_STR + " = ?"; } public static String buildDeleteNetworkVariantQuery() { - return "delete from " + NETWORK + " where " + UUID_STR + " = ? and " + VARIANT_NUM + " = ?"; + return "delete from " + NETWORK_TABLE + " where " + UUID_STR + " = ? and " + VARIANT_NUM + " = ?"; } public static String buildDeleteIdentifiablesQuery(String tableName) { @@ -161,13 +141,13 @@ public static String buildGetIdentifiableForAllTablesQuery() { public static String buildGetNetworkInfos() { return "select " + UUID_STR + ", " + ID_STR + - " from " + NETWORK + + " from " + NETWORK_TABLE + " where " + VARIANT_NUM + " = " + Resource.INITIAL_VARIANT_NUM; } public static String buildGetVariantsInfos() { return "select " + VARIANT_ID + ", " + VARIANT_NUM + - " from " + NETWORK + + " from " + NETWORK_TABLE + " where " + UUID_STR + " = ?"; } @@ -196,7 +176,7 @@ public static String buildUpdateIdentifiableQuery(String tableName, Collection columns) { StringBuilder query = new StringBuilder("update ") - .append(NETWORK) + .append(NETWORK_TABLE) .append(" set ").append(ID_STR).append(" = ?"); columns.forEach(column -> { if (!column.equals(UUID_STR) && !column.equals(VARIANT_ID)) { @@ -245,7 +225,7 @@ public static String buildCloneNetworksQuery(Collection columns) { public static String buildGetVoltageLevelsInSubstationQuery(Collection columns, String substationId) { return "select " + ID_STR + ", " + String.join(", ", columns) + - " from " + VOLTAGE_LEVEL + + " from " + VOLTAGE_LEVEL_TABLE + " where " + NETWORK_UUID + " = ?" + " and " + VARIANT_NUM + " = ?" + " and " + SUBSTATION_ID + " = ?"; From 1194049a5635213350c806c32929d1e355bb3160 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 9 Aug 2022 15:49:06 +0200 Subject: [PATCH 5/9] Wip Signed-off-by: Geoffroy Jamgotchian --- .../network/store/server/Mappings.java | 11 +- .../store/server/NetworkStoreRepository.java | 143 ++++++++---------- .../network/store/server/QueryCatalog.java | 2 +- 3 files changed, 75 insertions(+), 81 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java index 71c1f22cc..6e43588e3 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java @@ -13,6 +13,7 @@ import java.time.Instant; import java.util.*; +import java.util.function.Supplier; /** * @author Franck Lecuyer @@ -20,6 +21,14 @@ @Service public class Mappings { + private static final Supplier THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER = () -> { + ThreeWindingsTransformerAttributes attributes = new ThreeWindingsTransformerAttributes(); + attributes.setLeg1(LegAttributes.builder().legNumber(1).build()); + attributes.setLeg2(LegAttributes.builder().legNumber(2).build()); + attributes.setLeg3(LegAttributes.builder().legNumber(3).build()); + return attributes; + }; + static final String NETWORK_TABLE = "network"; static final String SUBSTATION_TABLE = "substation"; static final String VOLTAGE_LEVEL_TABLE = "voltageLevel"; @@ -60,7 +69,7 @@ public class Mappings { private final TableMapping staticVarCompensatorMappings = new TableMapping(STATIC_VAR_COMPENSATOR_TABLE, ResourceType.STATIC_VAR_COMPENSATOR, StaticVarCompensatorAttributes::new); private final TableMapping hvdcLineMappings = new TableMapping(HVDC_LINE_TABLE, ResourceType.HVDC_LINE, HvdcLineAttributes::new); private final TableMapping twoWindingsTransformerMappings = new TableMapping(TWO_WINDINGS_TRANSFORMER_TABLE, ResourceType.TWO_WINDINGS_TRANSFORMER, TwoWindingsTransformerAttributes::new); - private final TableMapping threeWindingsTransformerMappings = new TableMapping(THREE_WINDINGS_TRANSFORMER_TABLE, ResourceType.THREE_WINDINGS_TRANSFORMER, ThreeWindingsTransformerAttributes::new); + private final TableMapping threeWindingsTransformerMappings = new TableMapping(THREE_WINDINGS_TRANSFORMER_TABLE, ResourceType.THREE_WINDINGS_TRANSFORMER, THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); private final List all = List.of(lineMappings, loadMappings, diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index 8960d327a..9f5f89eb1 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -33,7 +33,6 @@ import java.time.Instant; import java.util.*; import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; import java.util.stream.Collectors; import static com.powsybl.network.store.server.Mappings.*; @@ -48,14 +47,6 @@ public class NetworkStoreRepository { private static final Logger LOGGER = LoggerFactory.getLogger(NetworkStoreRepository.class); - private static final Supplier THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER = () -> { - ThreeWindingsTransformerAttributes attributes = new ThreeWindingsTransformerAttributes(); - attributes.setLeg1(LegAttributes.builder().legNumber(1).build()); - attributes.setLeg2(LegAttributes.builder().legNumber(2).build()); - attributes.setLeg3(LegAttributes.builder().legNumber(3).build()); - return attributes; - }; - @Autowired public NetworkStoreRepository(DataSource dataSource, ObjectMapper mapper, Mappings mappings) { this.dataSource = dataSource; @@ -454,8 +445,7 @@ public void createIdentifiables(UUID networkU private Optional> getIdentifiable(UUID networkUuid, int variantNum, String equipmentId, TableMapping tableMapping, - Resource.Builder resourceBuilder, - Supplier attributesSupplier) { + Resource.Builder resourceBuilder) { try (var connection = dataSource.getConnection()) { var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiableQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet())); preparedStmt.setObject(1, networkUuid); @@ -463,7 +453,7 @@ private Optional> getIdentifiable preparedStmt.setString(3, equipmentId); try (ResultSet resultSet = preparedStmt.executeQuery()) { if (resultSet.next()) { - T attributes = attributesSupplier.get(); + T attributes = (T) tableMapping.getAttributesSupplier().get(); MutableInt columnIndex = new MutableInt(1); tableMapping.getColumnMapping().forEach((columnName, columnMapping) -> { bindAttributes(resultSet, columnIndex.getValue(), columnMapping, attributes); @@ -482,16 +472,16 @@ private Optional> getIdentifiable } } - private List> getIdentifiablesInternal(int variantNum, PreparedStatement preparedStmt, Map mappings, - Resource.Builder resourceBuilder, Supplier attributesSupplier) throws SQLException { + private List> getIdentifiablesInternal(int variantNum, PreparedStatement preparedStmt, TableMapping tableMapping, + Resource.Builder resourceBuilder) throws SQLException { try (ResultSet resultSet = preparedStmt.executeQuery()) { List> resources = new ArrayList<>(); while (resultSet.next()) { // first is ID String id = resultSet.getString(1); - T attributes = attributesSupplier.get(); + T attributes = (T) tableMapping.getAttributesSupplier().get(); MutableInt columnIndex = new MutableInt(2); - mappings.forEach((columnName, columnMapping) -> { + tableMapping.getColumnMapping().forEach((columnName, columnMapping) -> { bindAttributes(resultSet, columnIndex.getValue(), columnMapping, attributes); columnIndex.increment(); }); @@ -507,13 +497,12 @@ private List> getIdentifiablesInt private List> getIdentifiables(UUID networkUuid, int variantNum, TableMapping tableMapping, - Resource.Builder resourceBuilder, - Supplier attributesSupplier) { + Resource.Builder resourceBuilder) { try (var connection = dataSource.getConnection()) { var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); - return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping.getColumnMapping(), resourceBuilder, attributesSupplier); + return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping, resourceBuilder); } catch (SQLException e) { throw new UncheckedSqlException(e); } @@ -522,24 +511,21 @@ private List> getIdentifiables(UU private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, String containerId, String containerColumn, TableMapping tableMapping, - Resource.Builder resourceBuilder, - Supplier attributesSupplier) { - return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), Set.of(containerColumn), tableMapping, resourceBuilder, attributesSupplier); + Resource.Builder resourceBuilder) { + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), Set.of(containerColumn), tableMapping, resourceBuilder); } private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, String containerId, Set containerColumns, TableMapping tableMapping, - Resource.Builder resourceBuilder, - Supplier attributesSupplier) { - return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), containerColumns, tableMapping, resourceBuilder, attributesSupplier); + Resource.Builder resourceBuilder) { + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), containerColumns, tableMapping, resourceBuilder); } private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, List containerIds, Set containerColumns, TableMapping tableMapping, - Resource.Builder resourceBuilder, - Supplier attributesSupplier) { + Resource.Builder resourceBuilder) { try (var connection = dataSource.getConnection()) { var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet(), containerColumns, containerIds.size())); preparedStmt.setObject(1, networkUuid); @@ -550,7 +536,7 @@ private List> getIdentifiablesInC preparedStmt.setString(3 + i * containerIds.size() + j, containerId); } } - return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping.getColumnMapping(), resourceBuilder, attributesSupplier); + return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping, resourceBuilder); } catch (SQLException e) { throw new UncheckedSqlException(e); } @@ -627,11 +613,11 @@ public void deleteIdentifiable(UUID networkUuid, int variantNum, String id, Stri // substation public List> getSubstations(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getSubstationMappings(), Resource.substationBuilder(), SubstationAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getSubstationMappings(), Resource.substationBuilder()); } public Optional> getSubstation(UUID networkUuid, int variantNum, String substationId) { - return getIdentifiable(networkUuid, variantNum, substationId, mappings.getSubstationMappings(), Resource.substationBuilder(), SubstationAttributes::new); + return getIdentifiable(networkUuid, variantNum, substationId, mappings.getSubstationMappings(), Resource.substationBuilder()); } public void createSubstations(UUID networkUuid, List> resources) { @@ -657,15 +643,15 @@ public void updateVoltageLevels(UUID networkUuid, List> getVoltageLevels(UUID networkUuid, int variantNum, String substationId) { - return getIdentifiablesInContainer(networkUuid, variantNum, substationId, SUBSTATION_ID, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, substationId, SUBSTATION_ID, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder()); } public Optional> getVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiable(networkUuid, variantNum, voltageLevelId, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); + return getIdentifiable(networkUuid, variantNum, voltageLevelId, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder()); } public List> getVoltageLevels(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder()); } public void deleteVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId) { @@ -679,15 +665,15 @@ public void createGenerators(UUID networkUuid, List> getGenerator(UUID networkUuid, int variantNum, String generatorId) { - return getIdentifiable(networkUuid, variantNum, generatorId, mappings.getGeneratorMappings(), Resource.generatorBuilder(), GeneratorAttributes::new); + return getIdentifiable(networkUuid, variantNum, generatorId, mappings.getGeneratorMappings(), Resource.generatorBuilder()); } public List> getGenerators(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getGeneratorMappings(), Resource.generatorBuilder(), GeneratorAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getGeneratorMappings(), Resource.generatorBuilder()); } public List> getVoltageLevelGenerators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getGeneratorMappings(), Resource.generatorBuilder(), GeneratorAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getGeneratorMappings(), Resource.generatorBuilder()); } public void updateGenerators(UUID networkUuid, List> resources) { @@ -705,15 +691,15 @@ public void createBatteries(UUID networkUuid, List> } public Optional> getBattery(UUID networkUuid, int variantNum, String batteryId) { - return getIdentifiable(networkUuid, variantNum, batteryId, mappings.getBatteryMappings(), Resource.batteryBuilder(), BatteryAttributes::new); + return getIdentifiable(networkUuid, variantNum, batteryId, mappings.getBatteryMappings(), Resource.batteryBuilder()); } public List> getBatteries(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getBatteryMappings(), Resource.batteryBuilder(), BatteryAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getBatteryMappings(), Resource.batteryBuilder()); } public List> getVoltageLevelBatteries(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBatteryMappings(), Resource.batteryBuilder(), BatteryAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBatteryMappings(), Resource.batteryBuilder()); } public void updateBatteries(UUID networkUuid, List> resources) { @@ -731,15 +717,15 @@ public void createLoads(UUID networkUuid, List> resourc } public Optional> getLoad(UUID networkUuid, int variantNum, String loadId) { - return getIdentifiable(networkUuid, variantNum, loadId, mappings.getLoadMappings(), Resource.loadBuilder(), LoadAttributes::new); + return getIdentifiable(networkUuid, variantNum, loadId, mappings.getLoadMappings(), Resource.loadBuilder()); } public List> getLoads(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getLoadMappings(), Resource.loadBuilder(), LoadAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getLoadMappings(), Resource.loadBuilder()); } public List> getVoltageLevelLoads(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLoadMappings(), Resource.loadBuilder(), LoadAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLoadMappings(), Resource.loadBuilder()); } public void updateLoads(UUID networkUuid, List> resources) { @@ -757,15 +743,15 @@ public void createShuntCompensators(UUID networkUuid, List> getShuntCompensator(UUID networkUuid, int variantNum, String shuntCompensatorId) { - return getIdentifiable(networkUuid, variantNum, shuntCompensatorId, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); + return getIdentifiable(networkUuid, variantNum, shuntCompensatorId, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder()); } public List> getShuntCompensators(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder()); } public List> getVoltageLevelShuntCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder()); } public void updateShuntCompensators(UUID networkUuid, List> resources) { @@ -783,15 +769,15 @@ public void createVscConverterStations(UUID networkUuid, List> getVscConverterStation(UUID networkUuid, int variantNum, String vscConverterStationId) { - return getIdentifiable(networkUuid, variantNum, vscConverterStationId, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); + return getIdentifiable(networkUuid, variantNum, vscConverterStationId, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder()); } public List> getVscConverterStations(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder()); } public List> getVoltageLevelVscConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder()); } public void updateVscConverterStations(UUID networkUuid, List> resources) { @@ -809,15 +795,15 @@ public void createLccConverterStations(UUID networkUuid, List> getLccConverterStation(UUID networkUuid, int variantNum, String lccConverterStationId) { - return getIdentifiable(networkUuid, variantNum, lccConverterStationId, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); + return getIdentifiable(networkUuid, variantNum, lccConverterStationId, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder()); } public List> getLccConverterStations(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder()); } public List> getVoltageLevelLccConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder()); } public void updateLccConverterStations(UUID networkUuid, List> resources) { @@ -835,15 +821,15 @@ public void createStaticVarCompensators(UUID networkUuid, List> getStaticVarCompensator(UUID networkUuid, int variantNum, String staticVarCompensatorId) { - return getIdentifiable(networkUuid, variantNum, staticVarCompensatorId, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); + return getIdentifiable(networkUuid, variantNum, staticVarCompensatorId, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder()); } public List> getStaticVarCompensators(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder()); } public List> getVoltageLevelStaticVarCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder()); } public void updateStaticVarCompensators(UUID networkUuid, List> resources) { @@ -865,15 +851,15 @@ public void updateBusbarSections(UUID networkUuid, List> getBusbarSection(UUID networkUuid, int variantNum, String busbarSectionId) { - return getIdentifiable(networkUuid, variantNum, busbarSectionId, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); + return getIdentifiable(networkUuid, variantNum, busbarSectionId, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder()); } public List> getBusbarSections(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder()); } public List> getVoltageLevelBusbarSections(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder()); } public void deleteBusBarSection(UUID networkUuid, int variantNum, String busBarSectionId) { @@ -887,15 +873,15 @@ public void createSwitches(UUID networkUuid, List> re } public Optional> getSwitch(UUID networkUuid, int variantNum, String switchId) { - return getIdentifiable(networkUuid, variantNum, switchId, mappings.getSwitchMappings(), Resource.switchBuilder(), SwitchAttributes::new); + return getIdentifiable(networkUuid, variantNum, switchId, mappings.getSwitchMappings(), Resource.switchBuilder()); } public List> getSwitches(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getSwitchMappings(), Resource.switchBuilder(), SwitchAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getSwitchMappings(), Resource.switchBuilder()); } public List> getVoltageLevelSwitches(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getSwitchMappings(), Resource.switchBuilder(), SwitchAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getSwitchMappings(), Resource.switchBuilder()); } public void updateSwitches(UUID networkUuid, List> resources) { @@ -913,15 +899,15 @@ public void createTwoWindingsTransformers(UUID networkUuid, List> getTwoWindingsTransformer(UUID networkUuid, int variantNum, String twoWindingsTransformerId) { - return getIdentifiable(networkUuid, variantNum, twoWindingsTransformerId, mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); + return getIdentifiable(networkUuid, variantNum, twoWindingsTransformerId, mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder()); } public List> getTwoWindingsTransformers(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder()); } public List> getVoltageLevelTwoWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder()); } public void updateTwoWindingsTransformers(UUID networkUuid, List> resources) { @@ -939,17 +925,16 @@ public void createThreeWindingsTransformers(UUID networkUuid, List> getThreeWindingsTransformer(UUID networkUuid, int variantNum, String threeWindingsTransformerId) { - return getIdentifiable(networkUuid, variantNum, threeWindingsTransformerId, mappings.getThreeWindingsTransformerMappings(), Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); + return getIdentifiable(networkUuid, variantNum, threeWindingsTransformerId, mappings.getThreeWindingsTransformerMappings(), Resource.threeWindingsTransformerBuilder()); } public List> getThreeWindingsTransformers(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getThreeWindingsTransformerMappings(), - Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); + return getIdentifiables(networkUuid, variantNum, mappings.getThreeWindingsTransformerMappings(), Resource.threeWindingsTransformerBuilder()); } public List> getVoltageLevelThreeWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2", "voltageLevelId3"), mappings.getThreeWindingsTransformerMappings(), - Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); + Resource.threeWindingsTransformerBuilder()); } public void updateThreeWindingsTransformers(UUID networkUuid, List> resources) { @@ -967,15 +952,15 @@ public void createLines(UUID networkUuid, List> resourc } public Optional> getLine(UUID networkUuid, int variantNum, String lineId) { - return getIdentifiable(networkUuid, variantNum, lineId, mappings.getLineMappings(), Resource.lineBuilder(), LineAttributes::new); + return getIdentifiable(networkUuid, variantNum, lineId, mappings.getLineMappings(), Resource.lineBuilder()); } public List> getLines(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getLineMappings(), Resource.lineBuilder(), LineAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getLineMappings(), Resource.lineBuilder()); } public List> getVoltageLevelLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getLineMappings(), Resource.lineBuilder(), LineAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getLineMappings(), Resource.lineBuilder()); } public void updateLines(UUID networkUuid, List> resources) { @@ -989,11 +974,11 @@ public void deleteLine(UUID networkUuid, int variantNum, String lineId) { // Hvdc line public List> getHvdcLines(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getHvdcLineMappings(), Resource.hvdcLineBuilder(), HvdcLineAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getHvdcLineMappings(), Resource.hvdcLineBuilder()); } public Optional> getHvdcLine(UUID networkUuid, int variantNum, String hvdcLineId) { - return getIdentifiable(networkUuid, variantNum, hvdcLineId, mappings.getHvdcLineMappings(), Resource.hvdcLineBuilder(), HvdcLineAttributes::new); + return getIdentifiable(networkUuid, variantNum, hvdcLineId, mappings.getHvdcLineMappings(), Resource.hvdcLineBuilder()); } public void createHvdcLines(UUID networkUuid, List> resources) { @@ -1011,15 +996,15 @@ public void deleteHvdcLine(UUID networkUuid, int variantNum, String hvdcLineId) // Dangling line public List> getDanglingLines(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder(), DanglingLineAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder()); } public Optional> getDanglingLine(UUID networkUuid, int variantNum, String danglingLineId) { - return getIdentifiable(networkUuid, variantNum, danglingLineId, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder(), DanglingLineAttributes::new); + return getIdentifiable(networkUuid, variantNum, danglingLineId, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder()); } public List> getVoltageLevelDanglingLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder(), DanglingLineAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder()); } public void createDanglingLines(UUID networkUuid, List> resources) { @@ -1041,15 +1026,15 @@ public void createBuses(UUID networkUuid, List } public Optional> getConfiguredBus(UUID networkUuid, int variantNum, String busId) { - return getIdentifiable(networkUuid, variantNum, busId, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); + return getIdentifiable(networkUuid, variantNum, busId, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder()); } public List> getConfiguredBuses(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); + return getIdentifiables(networkUuid, variantNum, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder()); } public List> getVoltageLevelBuses(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder()); } public void updateBuses(UUID networkUuid, List> resources) { @@ -1120,7 +1105,7 @@ public Optional> getIdentifiable(UUID networkUu private List> getVoltageLevelsInSubstation(UUID networkUuid, int variantNum, String substationId) { try (var connection = dataSource.getConnection()) { var voltageLevelMapping = mappings.getVoltageLevelMappings(); - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetVoltageLevelsInSubstationQuery(voltageLevelMapping.getColumnMapping().keySet(), substationId)); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetVoltageLevelsInSubstationQuery(voltageLevelMapping.getColumnMapping().keySet())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); preparedStmt.setString(3, substationId); diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index f6fe5b351..2be02db5b 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -222,7 +222,7 @@ public static String buildCloneNetworksQuery(Collection columns) { "where uuid = ? and variantNum = ?"; } - public static String buildGetVoltageLevelsInSubstationQuery(Collection columns, String substationId) { + public static String buildGetVoltageLevelsInSubstationQuery(Collection columns) { return "select " + ID_STR + ", " + String.join(", ", columns) + " from " + VOLTAGE_LEVEL_TABLE + From d73e15ddc8001cdcfdf472c207fb71d8232a8a56 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 9 Aug 2022 15:53:24 +0200 Subject: [PATCH 6/9] Wip Signed-off-by: Geoffroy Jamgotchian --- .../store/server/NetworkStoreRepository.java | 48 ++++---- .../network/store/server/QueryCatalog.java | 114 +++++++++--------- 2 files changed, 80 insertions(+), 82 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index 9f5f89eb1..86c4f65c7 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -272,7 +272,7 @@ public void updateNetworks(List> resources) { for (var e : networkMapping.getColumnMapping().entrySet()) { String columnName = e.getKey(); var mapping = e.getValue(); - if (!columnName.equals(UUID_STR) && !columnName.equals(VARIANT_ID)) { + if (!columnName.equals(UUID_COLUMN) && !columnName.equals(VARIANT_ID_COLUMN)) { values.add(mapping.get(attributes)); } } @@ -673,11 +673,11 @@ public List> getGenerators(UUID networkUuid, int v } public List> getVoltageLevelGenerators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getGeneratorMappings(), Resource.generatorBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getGeneratorMappings(), Resource.generatorBuilder()); } public void updateGenerators(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getGeneratorMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getGeneratorMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public void deleteGenerator(UUID networkUuid, int variantNum, String generatorId) { @@ -699,11 +699,11 @@ public List> getBatteries(UUID networkUuid, int vari } public List> getVoltageLevelBatteries(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBatteryMappings(), Resource.batteryBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getBatteryMappings(), Resource.batteryBuilder()); } public void updateBatteries(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getBatteryMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getBatteryMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public void deleteBattery(UUID networkUuid, int variantNum, String batteryId) { @@ -725,11 +725,11 @@ public List> getLoads(UUID networkUuid, int variantNum) } public List> getVoltageLevelLoads(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLoadMappings(), Resource.loadBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getLoadMappings(), Resource.loadBuilder()); } public void updateLoads(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getLoadMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getLoadMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public void deleteLoad(UUID networkUuid, int variantNum, String loadId) { @@ -751,11 +751,11 @@ public List> getShuntCompensators(UUID netw } public List> getVoltageLevelShuntCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder()); } public void updateShuntCompensators(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getShuntCompensatorMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getShuntCompensatorMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public void deleteShuntCompensator(UUID networkUuid, int variantNum, String shuntCompensatorId) { @@ -777,11 +777,11 @@ public List> getVscConverterStations(UUI } public List> getVoltageLevelVscConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder()); } public void updateVscConverterStations(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getVscConverterStationMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getVscConverterStationMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public void deleteVscConverterStation(UUID networkUuid, int variantNum, String vscConverterStationId) { @@ -803,11 +803,11 @@ public List> getLccConverterStations(UUI } public List> getVoltageLevelLccConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder()); } public void updateLccConverterStations(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getLccConverterStationMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getLccConverterStationMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public void deleteLccConverterStation(UUID networkUuid, int variantNum, String lccConverterStationId) { @@ -829,11 +829,11 @@ public List> getStaticVarCompensators(U } public List> getVoltageLevelStaticVarCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder()); } public void updateStaticVarCompensators(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getStaticVarCompensatorMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getStaticVarCompensatorMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public void deleteStaticVarCompensator(UUID networkUuid, int variantNum, String staticVarCompensatorId) { @@ -847,7 +847,7 @@ public void createBusbarSections(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getBusbarSectionMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getBusbarSectionMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public Optional> getBusbarSection(UUID networkUuid, int variantNum, String busbarSectionId) { @@ -859,7 +859,7 @@ public List> getBusbarSections(UUID networkUui } public List> getVoltageLevelBusbarSections(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder()); } public void deleteBusBarSection(UUID networkUuid, int variantNum, String busBarSectionId) { @@ -881,11 +881,11 @@ public List> getSwitches(UUID networkUuid, int varian } public List> getVoltageLevelSwitches(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getSwitchMappings(), Resource.switchBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getSwitchMappings(), Resource.switchBuilder()); } public void updateSwitches(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getSwitchMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getSwitchMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public void deleteSwitch(UUID networkUuid, int variantNum, String switchId) { @@ -1004,7 +1004,7 @@ public Optional> getDanglingLine(UUID networkUu } public List> getVoltageLevelDanglingLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder()); } public void createDanglingLines(UUID networkUuid, List> resources) { @@ -1016,7 +1016,7 @@ public void deleteDanglingLine(UUID networkUuid, int variantNum, String dangling } public void updateDanglingLines(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getDanglingLineMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getDanglingLineMappings(), VOLTAGE_LEVEL_ID_COLUMN); } // configured buses @@ -1034,11 +1034,11 @@ public List> getConfiguredBuses(UUID networkUu } public List> getVoltageLevelBuses(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder()); } public void updateBuses(UUID networkUuid, List> resources) { - updateIdentifiables(networkUuid, resources, mappings.getConfiguredBusMappings(), VOLTAGE_LEVEL_ID); + updateIdentifiables(networkUuid, resources, mappings.getConfiguredBusMappings(), VOLTAGE_LEVEL_ID_COLUMN); } public void deleteBus(UUID networkUuid, int variantNum, String configuredBusId) { @@ -1048,7 +1048,7 @@ public void deleteBus(UUID networkUuid, int variantNum, String configuredBusId) private static String getNonEmptyTable(ResultSet resultSet) throws SQLException { var metaData = resultSet.getMetaData(); for (int col = 4; col <= metaData.getColumnCount(); col++) { // skip 3 first columns corresponding to first inner select - if (metaData.getColumnName(col).equalsIgnoreCase(ID_STR) && resultSet.getObject(col) != null) { + if (metaData.getColumnName(col).equalsIgnoreCase(ID_COLUMN) && resultSet.getObject(col) != null) { return metaData.getTableName(col).toLowerCase(); } } diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index 2be02db5b..dc69a7d17 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -20,16 +20,14 @@ */ public final class QueryCatalog { - static final String VARIANT_ID = "variantId"; - static final String UUID_STR = "uuid"; - - static final String SUBSTATION_ID = "substationId"; - - static final String NETWORK_UUID = "networkUuid"; - static final String VARIANT_NUM = "variantNum"; - static final String ID_STR = "id"; - static final String VOLTAGE_LEVEL_ID = "voltageLevelId"; - static final String NAME = "name"; + static final String VARIANT_ID_COLUMN = "variantId"; + static final String UUID_COLUMN = "uuid"; + static final String SUBSTATION_ID_COLUMN = "substationId"; + static final String NETWORK_UUID_COLUMN = "networkUuid"; + static final String VARIANT_NUM_COLUMN = "variantNum"; + static final String ID_COLUMN = "id"; + static final String VOLTAGE_LEVEL_ID_COLUMN = "voltageLevelId"; + static final String NAME_COLUMN = "name"; private QueryCatalog() { } @@ -38,35 +36,35 @@ public static String buildGetIdentifiableQuery(String tableName, Collection columns) { - return "select " + ID_STR + ", " + + return "select " + ID_COLUMN + ", " + String.join(", ", columns) + " from " + NETWORK_TABLE + - " where " + UUID_STR + " = ?" + - " and " + VARIANT_NUM + " = ?"; + " where " + UUID_COLUMN + " = ?" + + " and " + VARIANT_NUM_COLUMN + " = ?"; } public static String buildGetIdentifiablesQuery(String tableName, Collection columns) { - return "select " + ID_STR + ", " + + return "select " + ID_COLUMN + ", " + String.join(", ", columns) + " from " + tableName + - " where " + NETWORK_UUID + " = ?" + - " and " + VARIANT_NUM + " = ?"; + " where " + NETWORK_UUID_COLUMN + " = ?" + + " and " + VARIANT_NUM_COLUMN + " = ?"; } public static String buildGetIdentifiablesInContainerQuery(String tableName, Collection columns, Set containerColumns, int containerIdsSize) { StringBuilder sql = new StringBuilder() - .append("select ").append(ID_STR).append(", ") + .append("select ").append(ID_COLUMN).append(", ") .append(String.join(", ", columns)) .append(" from ").append(tableName) - .append(" where ").append(NETWORK_UUID).append(" = ?") - .append(" and ").append(VARIANT_NUM).append(" = ?") + .append(" where ").append(NETWORK_UUID_COLUMN).append(" = ?") + .append(" and ").append(VARIANT_NUM_COLUMN).append(" = ?") .append(" and ("); var it = containerColumns.iterator(); while (it.hasNext()) { @@ -88,37 +86,37 @@ public static String buildGetIdentifiablesInContainerQuery(String tableName, Col public static String buildDeleteIdentifiableQuery(String tableName) { return "delete from " + tableName + - " where " + NETWORK_UUID + " = ?" + - " and " + VARIANT_NUM + " = ?" + - " and " + ID_STR + " = ?"; + " where " + NETWORK_UUID_COLUMN + " = ?" + + " and " + VARIANT_NUM_COLUMN + " = ?" + + " and " + ID_COLUMN + " = ?"; } public static String buildDeleteNetworkQuery() { - return "delete from " + NETWORK_TABLE + " where " + UUID_STR + " = ?"; + return "delete from " + NETWORK_TABLE + " where " + UUID_COLUMN + " = ?"; } public static String buildDeleteNetworkVariantQuery() { - return "delete from " + NETWORK_TABLE + " where " + UUID_STR + " = ? and " + VARIANT_NUM + " = ?"; + return "delete from " + NETWORK_TABLE + " where " + UUID_COLUMN + " = ? and " + VARIANT_NUM_COLUMN + " = ?"; } public static String buildDeleteIdentifiablesQuery(String tableName) { - return "delete from " + tableName + " where " + NETWORK_UUID + " = ?"; + return "delete from " + tableName + " where " + NETWORK_UUID_COLUMN + " = ?"; } public static String buildDeleteIdentifiablesVariantQuery(String tableName) { - return "delete from " + tableName + " where " + NETWORK_UUID + " = ? and " + VARIANT_NUM + " = ?"; + return "delete from " + tableName + " where " + NETWORK_UUID_COLUMN + " = ? and " + VARIANT_NUM_COLUMN + " = ?"; } public static String buildInsertNetworkQuery(String tableName, Collection columns) { return "insert into " + tableName + - "(" + VARIANT_NUM + ", " + ID_STR + ", " + String.join(", ", columns) + + "(" + VARIANT_NUM_COLUMN + ", " + ID_COLUMN + ", " + String.join(", ", columns) + ") values (?, ?, " + columns.stream().map(s -> "?").collect(Collectors.joining(", ")) + ")"; } public static String buildInsertIdentifiableQuery(String tableName, Collection columns) { return "insert into " + tableName + - "(" + NETWORK_UUID + ", " + VARIANT_NUM + ", " + ID_STR + ", " + String.join(", ", columns) + + "(" + NETWORK_UUID_COLUMN + ", " + VARIANT_NUM_COLUMN + ", " + ID_COLUMN + ", " + String.join(", ", columns) + ") values (?, ?, ?, " + columns.stream().map(s -> "?").collect(Collectors.joining(", ")) + ")"; } @@ -140,15 +138,15 @@ public static String buildGetIdentifiableForAllTablesQuery() { } public static String buildGetNetworkInfos() { - return "select " + UUID_STR + ", " + ID_STR + + return "select " + UUID_COLUMN + ", " + ID_COLUMN + " from " + NETWORK_TABLE + - " where " + VARIANT_NUM + " = " + Resource.INITIAL_VARIANT_NUM; + " where " + VARIANT_NUM_COLUMN + " = " + Resource.INITIAL_VARIANT_NUM; } public static String buildGetVariantsInfos() { - return "select " + VARIANT_ID + ", " + VARIANT_NUM + + return "select " + VARIANT_ID_COLUMN + ", " + VARIANT_NUM_COLUMN + " from " + NETWORK_TABLE + - " where " + UUID_STR + " = ?"; + " where " + UUID_COLUMN + " = ?"; } public static String buildUpdateIdentifiableQuery(String tableName, Collection columns, String columnToAddToWhereClause) { @@ -165,9 +163,9 @@ public static String buildUpdateIdentifiableQuery(String tableName, Collection columns) { StringBuilder query = new StringBuilder("update ") .append(NETWORK_TABLE) - .append(" set ").append(ID_STR).append(" = ?"); + .append(" set ").append(ID_COLUMN).append(" = ?"); columns.forEach(column -> { - if (!column.equals(UUID_STR) && !column.equals(VARIANT_ID)) { + if (!column.equals(UUID_COLUMN) && !column.equals(VARIANT_ID_COLUMN)) { query.append(", ").append(column).append(" = ?"); } }); - query.append(" where ").append(UUID_STR).append(" = ?") - .append(" and ").append(VARIANT_NUM).append(" = ?"); + query.append(" where ").append(UUID_COLUMN).append(" = ?") + .append(" and ").append(VARIANT_NUM_COLUMN).append(" = ?"); return query.toString(); } public static String buildCloneIdentifiablesQuery(String tableName, Collection columns) { return "insert into " + tableName + "(" + - VARIANT_NUM + ", " + - NETWORK_UUID + ", " + - ID_STR + ", " + + VARIANT_NUM_COLUMN + ", " + + NETWORK_UUID_COLUMN + ", " + + ID_COLUMN + ", " + String.join(",", columns) + ") " + "select " + "?" + "," + "?" + "," + - ID_STR + "," + + ID_COLUMN + "," + String.join(",", columns) + " from " + tableName + " " + "where networkUuid = ? and variantNum = ?"; @@ -206,28 +204,28 @@ public static String buildCloneIdentifiablesQuery(String tableName, Collection columns) { return "insert into network(" + - VARIANT_NUM + ", " + - VARIANT_ID + ", " + - UUID_STR + ", " + - ID_STR + ", " + - columns.stream().filter(column -> !column.equals(UUID_STR) && !column.equals(VARIANT_ID) && !column.equals(NAME)).collect(Collectors.joining(",")) + + VARIANT_NUM_COLUMN + ", " + + VARIANT_ID_COLUMN + ", " + + UUID_COLUMN + ", " + + ID_COLUMN + ", " + + columns.stream().filter(column -> !column.equals(UUID_COLUMN) && !column.equals(VARIANT_ID_COLUMN) && !column.equals(NAME_COLUMN)).collect(Collectors.joining(",")) + ") " + "select" + " " + "?" + ", " + "?" + ", " + - UUID_STR + ", " + - ID_STR + ", " + - columns.stream().filter(column -> !column.equals(UUID_STR) && !column.equals(VARIANT_ID) && !column.equals(NAME)).collect(Collectors.joining(",")) + + UUID_COLUMN + ", " + + ID_COLUMN + ", " + + columns.stream().filter(column -> !column.equals(UUID_COLUMN) && !column.equals(VARIANT_ID_COLUMN) && !column.equals(NAME_COLUMN)).collect(Collectors.joining(",")) + " from network" + " " + "where uuid = ? and variantNum = ?"; } public static String buildGetVoltageLevelsInSubstationQuery(Collection columns) { - return "select " + ID_STR + ", " + + return "select " + ID_COLUMN + ", " + String.join(", ", columns) + " from " + VOLTAGE_LEVEL_TABLE + - " where " + NETWORK_UUID + " = ?" + - " and " + VARIANT_NUM + " = ?" + - " and " + SUBSTATION_ID + " = ?"; + " where " + NETWORK_UUID_COLUMN + " = ?" + + " and " + VARIANT_NUM_COLUMN + " = ?" + + " and " + SUBSTATION_ID_COLUMN + " = ?"; } } From 689817f307118574705d6dd973db9f2a0d4c1216 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 9 Aug 2022 16:08:16 +0200 Subject: [PATCH 7/9] Wip Signed-off-by: Geoffroy Jamgotchian --- .../network/store/server/Mappings.java | 36 ++--- .../store/server/NetworkStoreRepository.java | 127 +++++++++--------- .../network/store/server/TableMapping.java | 10 +- 3 files changed, 88 insertions(+), 85 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java index 6e43588e3..4e69a0cf2 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java @@ -52,24 +52,24 @@ public class Mappings { STATIC_VAR_COMPENSATOR_TABLE, VSC_CONVERTER_STATION_TABLE, LCC_CONVERTER_STATION_TABLE, TWO_WINDINGS_TRANSFORMER_TABLE, THREE_WINDINGS_TRANSFORMER_TABLE, LINE_TABLE, HVDC_LINE_TABLE, DANGLING_LINE_TABLE); - private final TableMapping lineMappings = new TableMapping(LINE_TABLE, ResourceType.LINE, LineAttributes::new); - private final TableMapping loadMappings = new TableMapping(LOAD_TABLE, ResourceType.LOAD, LoadAttributes::new); - private final TableMapping generatorMappings = new TableMapping(GENERATOR_TABLE, ResourceType.GENERATOR, GeneratorAttributes::new); - private final TableMapping switchMappings = new TableMapping(SWITCH_TABLE, ResourceType.SWITCH, SwitchAttributes::new); - private final TableMapping substationMappings = new TableMapping(SUBSTATION_TABLE, ResourceType.SUBSTATION, SubstationAttributes::new); - private final TableMapping networkMappings = new TableMapping(NETWORK_TABLE, ResourceType.NETWORK, NetworkAttributes::new); - private final TableMapping voltageLevelMappings = new TableMapping(VOLTAGE_LEVEL_TABLE, ResourceType.VOLTAGE_LEVEL, VoltageLevelAttributes::new); - private final TableMapping batteryMappings = new TableMapping(BATTERY_TABLE, ResourceType.BATTERY, BatteryAttributes::new); - private final TableMapping busbarSectionMappings = new TableMapping(BUSBAR_SECTION_TABLE, ResourceType.BUSBAR_SECTION, BusbarSectionAttributes::new); - private final TableMapping configuredBusMappings = new TableMapping(CONFIGURED_BUS_TABLE, ResourceType.CONFIGURED_BUS, ConfiguredBusAttributes::new); - private final TableMapping danglingLineMappings = new TableMapping(DANGLING_LINE_TABLE, ResourceType.DANGLING_LINE, DanglingLineAttributes::new); - private final TableMapping shuntCompensatorMappings = new TableMapping(SHUNT_COMPENSATOR_TABLE, ResourceType.SHUNT_COMPENSATOR, ShuntCompensatorAttributes::new); - private final TableMapping vscConverterStationMappings = new TableMapping(VSC_CONVERTER_STATION_TABLE, ResourceType.VSC_CONVERTER_STATION, VscConverterStationAttributes::new); - private final TableMapping lccConverterStationMappings = new TableMapping(LCC_CONVERTER_STATION_TABLE, ResourceType.LCC_CONVERTER_STATION, LccConverterStationAttributes::new); - private final TableMapping staticVarCompensatorMappings = new TableMapping(STATIC_VAR_COMPENSATOR_TABLE, ResourceType.STATIC_VAR_COMPENSATOR, StaticVarCompensatorAttributes::new); - private final TableMapping hvdcLineMappings = new TableMapping(HVDC_LINE_TABLE, ResourceType.HVDC_LINE, HvdcLineAttributes::new); - private final TableMapping twoWindingsTransformerMappings = new TableMapping(TWO_WINDINGS_TRANSFORMER_TABLE, ResourceType.TWO_WINDINGS_TRANSFORMER, TwoWindingsTransformerAttributes::new); - private final TableMapping threeWindingsTransformerMappings = new TableMapping(THREE_WINDINGS_TRANSFORMER_TABLE, ResourceType.THREE_WINDINGS_TRANSFORMER, THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); + private final TableMapping lineMappings = new TableMapping(LINE_TABLE, ResourceType.LINE, Resource.lineBuilder(), LineAttributes::new); + private final TableMapping loadMappings = new TableMapping(LOAD_TABLE, ResourceType.LOAD, Resource.loadBuilder(), LoadAttributes::new); + private final TableMapping generatorMappings = new TableMapping(GENERATOR_TABLE, ResourceType.GENERATOR, Resource.generatorBuilder(), GeneratorAttributes::new); + private final TableMapping switchMappings = new TableMapping(SWITCH_TABLE, ResourceType.SWITCH, Resource.switchBuilder(), SwitchAttributes::new); + private final TableMapping substationMappings = new TableMapping(SUBSTATION_TABLE, ResourceType.SUBSTATION, Resource.substationBuilder(), SubstationAttributes::new); + private final TableMapping networkMappings = new TableMapping(NETWORK_TABLE, ResourceType.NETWORK, Resource.networkBuilder(), NetworkAttributes::new); + private final TableMapping voltageLevelMappings = new TableMapping(VOLTAGE_LEVEL_TABLE, ResourceType.VOLTAGE_LEVEL, Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); + private final TableMapping batteryMappings = new TableMapping(BATTERY_TABLE, ResourceType.BATTERY, Resource.batteryBuilder(), BatteryAttributes::new); + private final TableMapping busbarSectionMappings = new TableMapping(BUSBAR_SECTION_TABLE, ResourceType.BUSBAR_SECTION, Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); + private final TableMapping configuredBusMappings = new TableMapping(CONFIGURED_BUS_TABLE, ResourceType.CONFIGURED_BUS, Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); + private final TableMapping danglingLineMappings = new TableMapping(DANGLING_LINE_TABLE, ResourceType.DANGLING_LINE, Resource.danglingLineBuilder(), DanglingLineAttributes::new); + private final TableMapping shuntCompensatorMappings = new TableMapping(SHUNT_COMPENSATOR_TABLE, ResourceType.SHUNT_COMPENSATOR, Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); + private final TableMapping vscConverterStationMappings = new TableMapping(VSC_CONVERTER_STATION_TABLE, ResourceType.VSC_CONVERTER_STATION, Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); + private final TableMapping lccConverterStationMappings = new TableMapping(LCC_CONVERTER_STATION_TABLE, ResourceType.LCC_CONVERTER_STATION, Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); + private final TableMapping staticVarCompensatorMappings = new TableMapping(STATIC_VAR_COMPENSATOR_TABLE, ResourceType.STATIC_VAR_COMPENSATOR, Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); + private final TableMapping hvdcLineMappings = new TableMapping(HVDC_LINE_TABLE, ResourceType.HVDC_LINE, Resource.hvdcLineBuilder(), HvdcLineAttributes::new); + private final TableMapping twoWindingsTransformerMappings = new TableMapping(TWO_WINDINGS_TRANSFORMER_TABLE, ResourceType.TWO_WINDINGS_TRANSFORMER, Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); + private final TableMapping threeWindingsTransformerMappings = new TableMapping(THREE_WINDINGS_TRANSFORMER_TABLE, ResourceType.THREE_WINDINGS_TRANSFORMER, Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); private final List all = List.of(lineMappings, loadMappings, diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index 86c4f65c7..f9a84c13f 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -444,8 +444,7 @@ public void createIdentifiables(UUID networkU } private Optional> getIdentifiable(UUID networkUuid, int variantNum, String equipmentId, - TableMapping tableMapping, - Resource.Builder resourceBuilder) { + TableMapping tableMapping) { try (var connection = dataSource.getConnection()) { var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiableQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet())); preparedStmt.setObject(1, networkUuid); @@ -459,6 +458,7 @@ private Optional> getIdentifiable bindAttributes(resultSet, columnIndex.getValue(), columnMapping, attributes); columnIndex.increment(); }); + Resource.Builder resourceBuilder = (Resource.Builder) tableMapping.getResourceBuilder(); return Optional.of(resourceBuilder .id(equipmentId) .variantNum(variantNum) @@ -472,8 +472,7 @@ private Optional> getIdentifiable } } - private List> getIdentifiablesInternal(int variantNum, PreparedStatement preparedStmt, TableMapping tableMapping, - Resource.Builder resourceBuilder) throws SQLException { + private List> getIdentifiablesInternal(int variantNum, PreparedStatement preparedStmt, TableMapping tableMapping) throws SQLException { try (ResultSet resultSet = preparedStmt.executeQuery()) { List> resources = new ArrayList<>(); while (resultSet.next()) { @@ -485,6 +484,7 @@ private List> getIdentifiablesInt bindAttributes(resultSet, columnIndex.getValue(), columnMapping, attributes); columnIndex.increment(); }); + Resource.Builder resourceBuilder = (Resource.Builder) tableMapping.getResourceBuilder(); resources.add(resourceBuilder .id(id) .variantNum(variantNum) @@ -496,13 +496,12 @@ private List> getIdentifiablesInt } private List> getIdentifiables(UUID networkUuid, int variantNum, - TableMapping tableMapping, - Resource.Builder resourceBuilder) { + TableMapping tableMapping) { try (var connection = dataSource.getConnection()) { var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); - return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping, resourceBuilder); + return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping); } catch (SQLException e) { throw new UncheckedSqlException(e); } @@ -510,22 +509,19 @@ private List> getIdentifiables(UU private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, String containerId, String containerColumn, - TableMapping tableMapping, - Resource.Builder resourceBuilder) { - return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), Set.of(containerColumn), tableMapping, resourceBuilder); + TableMapping tableMapping) { + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), Set.of(containerColumn), tableMapping); } private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, String containerId, Set containerColumns, - TableMapping tableMapping, - Resource.Builder resourceBuilder) { - return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), containerColumns, tableMapping, resourceBuilder); + TableMapping tableMapping) { + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), containerColumns, tableMapping); } private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, List containerIds, Set containerColumns, - TableMapping tableMapping, - Resource.Builder resourceBuilder) { + TableMapping tableMapping) { try (var connection = dataSource.getConnection()) { var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet(), containerColumns, containerIds.size())); preparedStmt.setObject(1, networkUuid); @@ -536,7 +532,7 @@ private List> getIdentifiablesInC preparedStmt.setString(3 + i * containerIds.size() + j, containerId); } } - return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping, resourceBuilder); + return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping); } catch (SQLException e) { throw new UncheckedSqlException(e); } @@ -613,11 +609,11 @@ public void deleteIdentifiable(UUID networkUuid, int variantNum, String id, Stri // substation public List> getSubstations(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getSubstationMappings(), Resource.substationBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getSubstationMappings()); } public Optional> getSubstation(UUID networkUuid, int variantNum, String substationId) { - return getIdentifiable(networkUuid, variantNum, substationId, mappings.getSubstationMappings(), Resource.substationBuilder()); + return getIdentifiable(networkUuid, variantNum, substationId, mappings.getSubstationMappings()); } public void createSubstations(UUID networkUuid, List> resources) { @@ -643,15 +639,15 @@ public void updateVoltageLevels(UUID networkUuid, List> getVoltageLevels(UUID networkUuid, int variantNum, String substationId) { - return getIdentifiablesInContainer(networkUuid, variantNum, substationId, SUBSTATION_ID, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, substationId, SUBSTATION_ID, mappings.getVoltageLevelMappings()); } public Optional> getVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiable(networkUuid, variantNum, voltageLevelId, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder()); + return getIdentifiable(networkUuid, variantNum, voltageLevelId, mappings.getVoltageLevelMappings()); } public List> getVoltageLevels(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getVoltageLevelMappings(), Resource.voltageLevelBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getVoltageLevelMappings()); } public void deleteVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId) { @@ -665,15 +661,15 @@ public void createGenerators(UUID networkUuid, List> getGenerator(UUID networkUuid, int variantNum, String generatorId) { - return getIdentifiable(networkUuid, variantNum, generatorId, mappings.getGeneratorMappings(), Resource.generatorBuilder()); + return getIdentifiable(networkUuid, variantNum, generatorId, mappings.getGeneratorMappings()); } public List> getGenerators(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getGeneratorMappings(), Resource.generatorBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getGeneratorMappings()); } public List> getVoltageLevelGenerators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getGeneratorMappings(), Resource.generatorBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getGeneratorMappings()); } public void updateGenerators(UUID networkUuid, List> resources) { @@ -691,15 +687,15 @@ public void createBatteries(UUID networkUuid, List> } public Optional> getBattery(UUID networkUuid, int variantNum, String batteryId) { - return getIdentifiable(networkUuid, variantNum, batteryId, mappings.getBatteryMappings(), Resource.batteryBuilder()); + return getIdentifiable(networkUuid, variantNum, batteryId, mappings.getBatteryMappings()); } public List> getBatteries(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getBatteryMappings(), Resource.batteryBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getBatteryMappings()); } public List> getVoltageLevelBatteries(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getBatteryMappings(), Resource.batteryBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getBatteryMappings()); } public void updateBatteries(UUID networkUuid, List> resources) { @@ -717,15 +713,15 @@ public void createLoads(UUID networkUuid, List> resourc } public Optional> getLoad(UUID networkUuid, int variantNum, String loadId) { - return getIdentifiable(networkUuid, variantNum, loadId, mappings.getLoadMappings(), Resource.loadBuilder()); + return getIdentifiable(networkUuid, variantNum, loadId, mappings.getLoadMappings()); } public List> getLoads(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getLoadMappings(), Resource.loadBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getLoadMappings()); } public List> getVoltageLevelLoads(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getLoadMappings(), Resource.loadBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getLoadMappings()); } public void updateLoads(UUID networkUuid, List> resources) { @@ -743,15 +739,15 @@ public void createShuntCompensators(UUID networkUuid, List> getShuntCompensator(UUID networkUuid, int variantNum, String shuntCompensatorId) { - return getIdentifiable(networkUuid, variantNum, shuntCompensatorId, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder()); + return getIdentifiable(networkUuid, variantNum, shuntCompensatorId, mappings.getShuntCompensatorMappings()); } public List> getShuntCompensators(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getShuntCompensatorMappings()); } public List> getVoltageLevelShuntCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getShuntCompensatorMappings(), Resource.shuntCompensatorBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getShuntCompensatorMappings()); } public void updateShuntCompensators(UUID networkUuid, List> resources) { @@ -769,15 +765,15 @@ public void createVscConverterStations(UUID networkUuid, List> getVscConverterStation(UUID networkUuid, int variantNum, String vscConverterStationId) { - return getIdentifiable(networkUuid, variantNum, vscConverterStationId, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder()); + return getIdentifiable(networkUuid, variantNum, vscConverterStationId, mappings.getVscConverterStationMappings()); } public List> getVscConverterStations(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getVscConverterStationMappings()); } public List> getVoltageLevelVscConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getVscConverterStationMappings(), Resource.vscConverterStationBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getVscConverterStationMappings()); } public void updateVscConverterStations(UUID networkUuid, List> resources) { @@ -795,15 +791,15 @@ public void createLccConverterStations(UUID networkUuid, List> getLccConverterStation(UUID networkUuid, int variantNum, String lccConverterStationId) { - return getIdentifiable(networkUuid, variantNum, lccConverterStationId, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder()); + return getIdentifiable(networkUuid, variantNum, lccConverterStationId, mappings.getLccConverterStationMappings()); } public List> getLccConverterStations(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getLccConverterStationMappings()); } public List> getVoltageLevelLccConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getLccConverterStationMappings(), Resource.lccConverterStationBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getLccConverterStationMappings()); } public void updateLccConverterStations(UUID networkUuid, List> resources) { @@ -821,15 +817,15 @@ public void createStaticVarCompensators(UUID networkUuid, List> getStaticVarCompensator(UUID networkUuid, int variantNum, String staticVarCompensatorId) { - return getIdentifiable(networkUuid, variantNum, staticVarCompensatorId, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder()); + return getIdentifiable(networkUuid, variantNum, staticVarCompensatorId, mappings.getStaticVarCompensatorMappings()); } public List> getStaticVarCompensators(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getStaticVarCompensatorMappings()); } public List> getVoltageLevelStaticVarCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getStaticVarCompensatorMappings(), Resource.staticVarCompensatorBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getStaticVarCompensatorMappings()); } public void updateStaticVarCompensators(UUID networkUuid, List> resources) { @@ -851,15 +847,15 @@ public void updateBusbarSections(UUID networkUuid, List> getBusbarSection(UUID networkUuid, int variantNum, String busbarSectionId) { - return getIdentifiable(networkUuid, variantNum, busbarSectionId, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder()); + return getIdentifiable(networkUuid, variantNum, busbarSectionId, mappings.getBusbarSectionMappings()); } public List> getBusbarSections(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getBusbarSectionMappings()); } public List> getVoltageLevelBusbarSections(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getBusbarSectionMappings(), Resource.busbarSectionBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getBusbarSectionMappings()); } public void deleteBusBarSection(UUID networkUuid, int variantNum, String busBarSectionId) { @@ -873,15 +869,15 @@ public void createSwitches(UUID networkUuid, List> re } public Optional> getSwitch(UUID networkUuid, int variantNum, String switchId) { - return getIdentifiable(networkUuid, variantNum, switchId, mappings.getSwitchMappings(), Resource.switchBuilder()); + return getIdentifiable(networkUuid, variantNum, switchId, mappings.getSwitchMappings()); } public List> getSwitches(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getSwitchMappings(), Resource.switchBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getSwitchMappings()); } public List> getVoltageLevelSwitches(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getSwitchMappings(), Resource.switchBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getSwitchMappings()); } public void updateSwitches(UUID networkUuid, List> resources) { @@ -899,15 +895,15 @@ public void createTwoWindingsTransformers(UUID networkUuid, List> getTwoWindingsTransformer(UUID networkUuid, int variantNum, String twoWindingsTransformerId) { - return getIdentifiable(networkUuid, variantNum, twoWindingsTransformerId, mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder()); + return getIdentifiable(networkUuid, variantNum, twoWindingsTransformerId, mappings.getTwoWindingsTransformerMappings()); } public List> getTwoWindingsTransformers(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getTwoWindingsTransformerMappings()); } public List> getVoltageLevelTwoWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getTwoWindingsTransformerMappings(), Resource.twoWindingsTransformerBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getTwoWindingsTransformerMappings()); } public void updateTwoWindingsTransformers(UUID networkUuid, List> resources) { @@ -925,16 +921,15 @@ public void createThreeWindingsTransformers(UUID networkUuid, List> getThreeWindingsTransformer(UUID networkUuid, int variantNum, String threeWindingsTransformerId) { - return getIdentifiable(networkUuid, variantNum, threeWindingsTransformerId, mappings.getThreeWindingsTransformerMappings(), Resource.threeWindingsTransformerBuilder()); + return getIdentifiable(networkUuid, variantNum, threeWindingsTransformerId, mappings.getThreeWindingsTransformerMappings()); } public List> getThreeWindingsTransformers(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getThreeWindingsTransformerMappings(), Resource.threeWindingsTransformerBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getThreeWindingsTransformerMappings()); } public List> getVoltageLevelThreeWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2", "voltageLevelId3"), mappings.getThreeWindingsTransformerMappings(), - Resource.threeWindingsTransformerBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2", "voltageLevelId3"), mappings.getThreeWindingsTransformerMappings()); } public void updateThreeWindingsTransformers(UUID networkUuid, List> resources) { @@ -952,15 +947,15 @@ public void createLines(UUID networkUuid, List> resourc } public Optional> getLine(UUID networkUuid, int variantNum, String lineId) { - return getIdentifiable(networkUuid, variantNum, lineId, mappings.getLineMappings(), Resource.lineBuilder()); + return getIdentifiable(networkUuid, variantNum, lineId, mappings.getLineMappings()); } public List> getLines(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getLineMappings(), Resource.lineBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getLineMappings()); } public List> getVoltageLevelLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getLineMappings(), Resource.lineBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getLineMappings()); } public void updateLines(UUID networkUuid, List> resources) { @@ -974,11 +969,11 @@ public void deleteLine(UUID networkUuid, int variantNum, String lineId) { // Hvdc line public List> getHvdcLines(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getHvdcLineMappings(), Resource.hvdcLineBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getHvdcLineMappings()); } public Optional> getHvdcLine(UUID networkUuid, int variantNum, String hvdcLineId) { - return getIdentifiable(networkUuid, variantNum, hvdcLineId, mappings.getHvdcLineMappings(), Resource.hvdcLineBuilder()); + return getIdentifiable(networkUuid, variantNum, hvdcLineId, mappings.getHvdcLineMappings()); } public void createHvdcLines(UUID networkUuid, List> resources) { @@ -996,15 +991,15 @@ public void deleteHvdcLine(UUID networkUuid, int variantNum, String hvdcLineId) // Dangling line public List> getDanglingLines(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getDanglingLineMappings()); } public Optional> getDanglingLine(UUID networkUuid, int variantNum, String danglingLineId) { - return getIdentifiable(networkUuid, variantNum, danglingLineId, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder()); + return getIdentifiable(networkUuid, variantNum, danglingLineId, mappings.getDanglingLineMappings()); } public List> getVoltageLevelDanglingLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getDanglingLineMappings(), Resource.danglingLineBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getDanglingLineMappings()); } public void createDanglingLines(UUID networkUuid, List> resources) { @@ -1026,15 +1021,15 @@ public void createBuses(UUID networkUuid, List } public Optional> getConfiguredBus(UUID networkUuid, int variantNum, String busId) { - return getIdentifiable(networkUuid, variantNum, busId, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder()); + return getIdentifiable(networkUuid, variantNum, busId, mappings.getConfiguredBusMappings()); } public List> getConfiguredBuses(UUID networkUuid, int variantNum) { - return getIdentifiables(networkUuid, variantNum, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder()); + return getIdentifiables(networkUuid, variantNum, mappings.getConfiguredBusMappings()); } public List> getVoltageLevelBuses(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getConfiguredBusMappings(), Resource.configuredBusBuilder()); + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getConfiguredBusMappings()); } public void updateBuses(UUID networkUuid, List> resources) { diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java b/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java index c1cec7f19..fa421f44b 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java @@ -7,6 +7,7 @@ package com.powsybl.network.store.server; import com.powsybl.network.store.model.IdentifiableAttributes; +import com.powsybl.network.store.model.Resource; import com.powsybl.network.store.model.ResourceType; import java.util.LinkedHashMap; @@ -26,11 +27,14 @@ public class TableMapping { private final Supplier attributesSupplier; + private final Resource.Builder resourceBuilder; + private final Map columnMapping = new LinkedHashMap<>(); - public TableMapping(String table, ResourceType resourceType, Supplier attributesSupplier) { + public TableMapping(String table, ResourceType resourceType, Resource.Builder resourceBuilder, Supplier attributesSupplier) { this.table = Objects.requireNonNull(table); this.resourceType = Objects.requireNonNull(resourceType); + this.resourceBuilder = Objects.requireNonNull(resourceBuilder); this.attributesSupplier = Objects.requireNonNull(attributesSupplier); } @@ -42,6 +46,10 @@ public ResourceType getResourceType() { return resourceType; } + public Resource.Builder getResourceBuilder() { + return resourceBuilder; + } + public Supplier getAttributesSupplier() { return attributesSupplier; } From f62ca6d8e9430fde7df1d555669518712bca5e80 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 9 Aug 2022 16:38:24 +0200 Subject: [PATCH 8/9] Wip Signed-off-by: Geoffroy Jamgotchian --- .../network/store/server/Mappings.java | 58 +++++++++++++------ .../store/server/NetworkStoreRepository.java | 50 +++++++++------- .../network/store/server/QueryCatalog.java | 3 + .../network/store/server/TableMapping.java | 11 +++- 4 files changed, 81 insertions(+), 41 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java index 4e69a0cf2..e97e3746d 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java @@ -15,6 +15,8 @@ import java.util.*; import java.util.function.Supplier; +import static com.powsybl.network.store.server.QueryCatalog.*; + /** * @author Franck Lecuyer */ @@ -52,24 +54,24 @@ public class Mappings { STATIC_VAR_COMPENSATOR_TABLE, VSC_CONVERTER_STATION_TABLE, LCC_CONVERTER_STATION_TABLE, TWO_WINDINGS_TRANSFORMER_TABLE, THREE_WINDINGS_TRANSFORMER_TABLE, LINE_TABLE, HVDC_LINE_TABLE, DANGLING_LINE_TABLE); - private final TableMapping lineMappings = new TableMapping(LINE_TABLE, ResourceType.LINE, Resource.lineBuilder(), LineAttributes::new); - private final TableMapping loadMappings = new TableMapping(LOAD_TABLE, ResourceType.LOAD, Resource.loadBuilder(), LoadAttributes::new); - private final TableMapping generatorMappings = new TableMapping(GENERATOR_TABLE, ResourceType.GENERATOR, Resource.generatorBuilder(), GeneratorAttributes::new); - private final TableMapping switchMappings = new TableMapping(SWITCH_TABLE, ResourceType.SWITCH, Resource.switchBuilder(), SwitchAttributes::new); - private final TableMapping substationMappings = new TableMapping(SUBSTATION_TABLE, ResourceType.SUBSTATION, Resource.substationBuilder(), SubstationAttributes::new); - private final TableMapping networkMappings = new TableMapping(NETWORK_TABLE, ResourceType.NETWORK, Resource.networkBuilder(), NetworkAttributes::new); - private final TableMapping voltageLevelMappings = new TableMapping(VOLTAGE_LEVEL_TABLE, ResourceType.VOLTAGE_LEVEL, Resource.voltageLevelBuilder(), VoltageLevelAttributes::new); - private final TableMapping batteryMappings = new TableMapping(BATTERY_TABLE, ResourceType.BATTERY, Resource.batteryBuilder(), BatteryAttributes::new); - private final TableMapping busbarSectionMappings = new TableMapping(BUSBAR_SECTION_TABLE, ResourceType.BUSBAR_SECTION, Resource.busbarSectionBuilder(), BusbarSectionAttributes::new); - private final TableMapping configuredBusMappings = new TableMapping(CONFIGURED_BUS_TABLE, ResourceType.CONFIGURED_BUS, Resource.configuredBusBuilder(), ConfiguredBusAttributes::new); - private final TableMapping danglingLineMappings = new TableMapping(DANGLING_LINE_TABLE, ResourceType.DANGLING_LINE, Resource.danglingLineBuilder(), DanglingLineAttributes::new); - private final TableMapping shuntCompensatorMappings = new TableMapping(SHUNT_COMPENSATOR_TABLE, ResourceType.SHUNT_COMPENSATOR, Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new); - private final TableMapping vscConverterStationMappings = new TableMapping(VSC_CONVERTER_STATION_TABLE, ResourceType.VSC_CONVERTER_STATION, Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new); - private final TableMapping lccConverterStationMappings = new TableMapping(LCC_CONVERTER_STATION_TABLE, ResourceType.LCC_CONVERTER_STATION, Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new); - private final TableMapping staticVarCompensatorMappings = new TableMapping(STATIC_VAR_COMPENSATOR_TABLE, ResourceType.STATIC_VAR_COMPENSATOR, Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new); - private final TableMapping hvdcLineMappings = new TableMapping(HVDC_LINE_TABLE, ResourceType.HVDC_LINE, Resource.hvdcLineBuilder(), HvdcLineAttributes::new); - private final TableMapping twoWindingsTransformerMappings = new TableMapping(TWO_WINDINGS_TRANSFORMER_TABLE, ResourceType.TWO_WINDINGS_TRANSFORMER, Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new); - private final TableMapping threeWindingsTransformerMappings = new TableMapping(THREE_WINDINGS_TRANSFORMER_TABLE, ResourceType.THREE_WINDINGS_TRANSFORMER, Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER); + private final TableMapping lineMappings = new TableMapping(LINE_TABLE, ResourceType.LINE, Resource.lineBuilder(), LineAttributes::new, Set.of(VOLTAGE_LEVEL_ID_1_COLUMN, VOLTAGE_LEVEL_ID_2_COLUMN)); + private final TableMapping loadMappings = new TableMapping(LOAD_TABLE, ResourceType.LOAD, Resource.loadBuilder(), LoadAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping generatorMappings = new TableMapping(GENERATOR_TABLE, ResourceType.GENERATOR, Resource.generatorBuilder(), GeneratorAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping switchMappings = new TableMapping(SWITCH_TABLE, ResourceType.SWITCH, Resource.switchBuilder(), SwitchAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping substationMappings = new TableMapping(SUBSTATION_TABLE, ResourceType.SUBSTATION, Resource.substationBuilder(), SubstationAttributes::new, Collections.emptySet()); + private final TableMapping networkMappings = new TableMapping(NETWORK_TABLE, ResourceType.NETWORK, Resource.networkBuilder(), NetworkAttributes::new, Collections.emptySet()); + private final TableMapping voltageLevelMappings = new TableMapping(VOLTAGE_LEVEL_TABLE, ResourceType.VOLTAGE_LEVEL, Resource.voltageLevelBuilder(), VoltageLevelAttributes::new, Collections.emptySet()); + private final TableMapping batteryMappings = new TableMapping(BATTERY_TABLE, ResourceType.BATTERY, Resource.batteryBuilder(), BatteryAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping busbarSectionMappings = new TableMapping(BUSBAR_SECTION_TABLE, ResourceType.BUSBAR_SECTION, Resource.busbarSectionBuilder(), BusbarSectionAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping configuredBusMappings = new TableMapping(CONFIGURED_BUS_TABLE, ResourceType.CONFIGURED_BUS, Resource.configuredBusBuilder(), ConfiguredBusAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping danglingLineMappings = new TableMapping(DANGLING_LINE_TABLE, ResourceType.DANGLING_LINE, Resource.danglingLineBuilder(), DanglingLineAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping shuntCompensatorMappings = new TableMapping(SHUNT_COMPENSATOR_TABLE, ResourceType.SHUNT_COMPENSATOR, Resource.shuntCompensatorBuilder(), ShuntCompensatorAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping vscConverterStationMappings = new TableMapping(VSC_CONVERTER_STATION_TABLE, ResourceType.VSC_CONVERTER_STATION, Resource.vscConverterStationBuilder(), VscConverterStationAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping lccConverterStationMappings = new TableMapping(LCC_CONVERTER_STATION_TABLE, ResourceType.LCC_CONVERTER_STATION, Resource.lccConverterStationBuilder(), LccConverterStationAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping staticVarCompensatorMappings = new TableMapping(STATIC_VAR_COMPENSATOR_TABLE, ResourceType.STATIC_VAR_COMPENSATOR, Resource.staticVarCompensatorBuilder(), StaticVarCompensatorAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping hvdcLineMappings = new TableMapping(HVDC_LINE_TABLE, ResourceType.HVDC_LINE, Resource.hvdcLineBuilder(), HvdcLineAttributes::new, Set.of(VOLTAGE_LEVEL_ID_COLUMN)); + private final TableMapping twoWindingsTransformerMappings = new TableMapping(TWO_WINDINGS_TRANSFORMER_TABLE, ResourceType.TWO_WINDINGS_TRANSFORMER, Resource.twoWindingsTransformerBuilder(), TwoWindingsTransformerAttributes::new, Set.of(VOLTAGE_LEVEL_ID_1_COLUMN, VOLTAGE_LEVEL_ID_2_COLUMN)); + private final TableMapping threeWindingsTransformerMappings = new TableMapping(THREE_WINDINGS_TRANSFORMER_TABLE, ResourceType.THREE_WINDINGS_TRANSFORMER, Resource.threeWindingsTransformerBuilder(), THREE_WINDINGS_TRANSFORMER_ATTRIBUTES_SUPPLIER, Set.of(VOLTAGE_LEVEL_ID_1_COLUMN, VOLTAGE_LEVEL_ID_2_COLUMN, VOLTAGE_LEVEL_ID_3_COLUMN)); private final List all = List.of(lineMappings, loadMappings, @@ -91,6 +93,22 @@ public class Mappings { twoWindingsTransformerMappings, threeWindingsTransformerMappings); + private final List noneContainerTableMapping = List.of(lineMappings, + loadMappings, + generatorMappings, + switchMappings, + batteryMappings, + busbarSectionMappings, + configuredBusMappings, + danglingLineMappings, + shuntCompensatorMappings, + vscConverterStationMappings, + vscConverterStationMappings, + lccConverterStationMappings, + staticVarCompensatorMappings, + twoWindingsTransformerMappings, + threeWindingsTransformerMappings); + private final Map mappingByTable = new LinkedHashMap<>(); private static final String VOLTAGE_LEVEL_ID = "voltageLevelId"; @@ -121,6 +139,10 @@ public class Mappings { private static final String REACTIVE_CAPABILITY_CURVE = "reactiveCapabilityCurve"; private static final String REGULATION_TERMINAL = "regulatingTerminal"; + public List getNoneContainerTableMapping() { + return noneContainerTableMapping; + } + public TableMapping getTableMapping(String table) { Objects.requireNonNull(table); TableMapping tableMapping = mappingByTable.get(table); diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index f9a84c13f..144c8d77c 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -513,12 +513,6 @@ private List> getIdentifiablesInC return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), Set.of(containerColumn), tableMapping); } - private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, String containerId, - Set containerColumns, - TableMapping tableMapping) { - return getIdentifiablesInContainer(networkUuid, variantNum, List.of(containerId), containerColumns, tableMapping); - } - private List> getIdentifiablesInContainer(UUID networkUuid, int variantNum, List containerIds, Set containerColumns, TableMapping tableMapping) { @@ -538,6 +532,14 @@ private List> getIdentifiablesInC } } + private List> getIdentifiablesInVoltageLevel(UUID networkUuid, int variantNum, List voltageLevelIds, TableMapping tableMapping) { + return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelIds, tableMapping.getVoltageLevelIdColumns(), tableMapping); + } + + private List> getIdentifiablesInVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId, TableMapping tableMapping) { + return getIdentifiablesInContainer(networkUuid, variantNum, List.of(voltageLevelId), tableMapping.getVoltageLevelIdColumns(), tableMapping); + } + public void updateIdentifiables(UUID networkUuid, List> resources, TableMapping tableMapping, String columnToAddToWhereClause) { try (var connection = dataSource.getConnection()) { @@ -669,7 +671,7 @@ public List> getGenerators(UUID networkUuid, int v } public List> getVoltageLevelGenerators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getGeneratorMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getGeneratorMappings()); } public void updateGenerators(UUID networkUuid, List> resources) { @@ -695,7 +697,7 @@ public List> getBatteries(UUID networkUuid, int vari } public List> getVoltageLevelBatteries(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getBatteryMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getBatteryMappings()); } public void updateBatteries(UUID networkUuid, List> resources) { @@ -721,7 +723,7 @@ public List> getLoads(UUID networkUuid, int variantNum) } public List> getVoltageLevelLoads(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getLoadMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getLoadMappings()); } public void updateLoads(UUID networkUuid, List> resources) { @@ -747,7 +749,7 @@ public List> getShuntCompensators(UUID netw } public List> getVoltageLevelShuntCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getShuntCompensatorMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getShuntCompensatorMappings()); } public void updateShuntCompensators(UUID networkUuid, List> resources) { @@ -773,7 +775,7 @@ public List> getVscConverterStations(UUI } public List> getVoltageLevelVscConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getVscConverterStationMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getVscConverterStationMappings()); } public void updateVscConverterStations(UUID networkUuid, List> resources) { @@ -799,7 +801,7 @@ public List> getLccConverterStations(UUI } public List> getVoltageLevelLccConverterStations(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getLccConverterStationMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getLccConverterStationMappings()); } public void updateLccConverterStations(UUID networkUuid, List> resources) { @@ -825,7 +827,7 @@ public List> getStaticVarCompensators(U } public List> getVoltageLevelStaticVarCompensators(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getStaticVarCompensatorMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getStaticVarCompensatorMappings()); } public void updateStaticVarCompensators(UUID networkUuid, List> resources) { @@ -855,7 +857,7 @@ public List> getBusbarSections(UUID networkUui } public List> getVoltageLevelBusbarSections(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getBusbarSectionMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getBusbarSectionMappings()); } public void deleteBusBarSection(UUID networkUuid, int variantNum, String busBarSectionId) { @@ -877,7 +879,7 @@ public List> getSwitches(UUID networkUuid, int varian } public List> getVoltageLevelSwitches(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getSwitchMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getSwitchMappings()); } public void updateSwitches(UUID networkUuid, List> resources) { @@ -903,7 +905,7 @@ public List> getTwoWindingsTransforme } public List> getVoltageLevelTwoWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getTwoWindingsTransformerMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getTwoWindingsTransformerMappings()); } public void updateTwoWindingsTransformers(UUID networkUuid, List> resources) { @@ -929,7 +931,7 @@ public List> getThreeWindingsTransf } public List> getVoltageLevelThreeWindingsTransformers(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2", "voltageLevelId3"), mappings.getThreeWindingsTransformerMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getThreeWindingsTransformerMappings()); } public void updateThreeWindingsTransformers(UUID networkUuid, List> resources) { @@ -955,7 +957,7 @@ public List> getLines(UUID networkUuid, int variantNum) } public List> getVoltageLevelLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, Set.of("voltageLevelId1", "voltageLevelId2"), mappings.getLineMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getLineMappings()); } public void updateLines(UUID networkUuid, List> resources) { @@ -999,7 +1001,7 @@ public Optional> getDanglingLine(UUID networkUu } public List> getVoltageLevelDanglingLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getDanglingLineMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getDanglingLineMappings()); } public void createDanglingLines(UUID networkUuid, List> resources) { @@ -1029,7 +1031,7 @@ public List> getConfiguredBuses(UUID networkUu } public List> getVoltageLevelBuses(UUID networkUuid, int variantNum, String voltageLevelId) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, VOLTAGE_LEVEL_ID_COLUMN, mappings.getConfiguredBusMappings()); + return getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelId, mappings.getConfiguredBusMappings()); } public void updateBuses(UUID networkUuid, List> resources) { @@ -1151,16 +1153,20 @@ public List> getIdentifiablesWithSameSubstation } else { throw new PowsyblException("TODO"); } - System.out.println(substationId); // get list of voltage levels contained in this substation var voltageLevelResources = getVoltageLevelsInSubstation(networkUuid, variantNum, substationId); for (var voltageLevelResource : voltageLevelResources) { resourcesById.put(voltageLevelResource.getId(), downcast(voltageLevelResource)); } - System.out.println(voltageLevelResources); // get identifiables contained in these voltage levels + List voltageLevelIds = voltageLevelResources.stream().map(Resource::getId).collect(Collectors.toList()); + for (var tableMapping : mappings.getNoneContainerTableMapping()) { + for (Resource identifiableResource : getIdentifiablesInVoltageLevel(networkUuid, variantNum, voltageLevelIds, tableMapping)) { + resourcesById.put(identifiableResource.getId(), identifiableResource); + } + } return new ArrayList<>(resourcesById.values()); } diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index dc69a7d17..979ac5660 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -27,6 +27,9 @@ public final class QueryCatalog { static final String VARIANT_NUM_COLUMN = "variantNum"; static final String ID_COLUMN = "id"; static final String VOLTAGE_LEVEL_ID_COLUMN = "voltageLevelId"; + static final String VOLTAGE_LEVEL_ID_1_COLUMN = "voltageLevelId1"; + static final String VOLTAGE_LEVEL_ID_2_COLUMN = "voltageLevelId2"; + static final String VOLTAGE_LEVEL_ID_3_COLUMN = "voltageLevelId3"; static final String NAME_COLUMN = "name"; private QueryCatalog() { diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java b/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java index fa421f44b..9975a5830 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java @@ -13,6 +13,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.function.Supplier; /** @@ -29,13 +30,17 @@ public class TableMapping { private final Resource.Builder resourceBuilder; + private final Set voltageLevelIdColumns; + private final Map columnMapping = new LinkedHashMap<>(); - public TableMapping(String table, ResourceType resourceType, Resource.Builder resourceBuilder, Supplier attributesSupplier) { + public TableMapping(String table, ResourceType resourceType, Resource.Builder resourceBuilder, + Supplier attributesSupplier, Set voltageLevelIdColumns) { this.table = Objects.requireNonNull(table); this.resourceType = Objects.requireNonNull(resourceType); this.resourceBuilder = Objects.requireNonNull(resourceBuilder); this.attributesSupplier = Objects.requireNonNull(attributesSupplier); + this.voltageLevelIdColumns = Objects.requireNonNull(voltageLevelIdColumns); } public String getTable() { @@ -54,6 +59,10 @@ public Supplier getAttributesSupplier() { return attributesSupplier; } + public Set getVoltageLevelIdColumns() { + return voltageLevelIdColumns; + } + public Map getColumnMapping() { return columnMapping; } From 3f0268931ea176958d59d2df07e510e446129a19 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 13 Sep 2022 09:02:53 +0200 Subject: [PATCH 9/9] Fix merge Signed-off-by: Geoffroy Jamgotchian --- .../network/store/server/Mappings.java | 28 +++++++++---------- .../store/server/NetworkStoreRepository.java | 16 ++++------- .../network/store/server/QueryCatalog.java | 1 + .../network/store/server/TableMapping.java | 6 ++-- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java index 558114d6b..208af8daf 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/Mappings.java @@ -94,20 +94,20 @@ public class Mappings { threeWindingsTransformerMappings); private final List noneContainerTableMapping = List.of(lineMappings, - loadMappings, - generatorMappings, - switchMappings, - batteryMappings, - busbarSectionMappings, - configuredBusMappings, - danglingLineMappings, - shuntCompensatorMappings, - vscConverterStationMappings, - vscConverterStationMappings, - lccConverterStationMappings, - staticVarCompensatorMappings, - twoWindingsTransformerMappings, - threeWindingsTransformerMappings); + loadMappings, + generatorMappings, + switchMappings, + batteryMappings, + busbarSectionMappings, + configuredBusMappings, + danglingLineMappings, + shuntCompensatorMappings, + vscConverterStationMappings, + vscConverterStationMappings, + lccConverterStationMappings, + staticVarCompensatorMappings, + twoWindingsTransformerMappings, + threeWindingsTransformerMappings); private final Map mappingByTable = new LinkedHashMap<>(); diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index 748b4734e..2a8cf5058 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -446,7 +446,7 @@ public void createIdentifiables(UUID networkU private Optional> getIdentifiable(UUID networkUuid, int variantNum, String equipmentId, TableMapping tableMapping) { try (var connection = dataSource.getConnection()) { - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiableQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet())); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiableQuery(tableMapping.getTable(), tableMapping.getColumnsMapping().keySet())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); preparedStmt.setString(3, equipmentId); @@ -454,7 +454,7 @@ private Optional> getIdentifiable if (resultSet.next()) { T attributes = (T) tableMapping.getAttributesSupplier().get(); MutableInt columnIndex = new MutableInt(1); - tableMapping.getColumnMapping().forEach((columnName, columnMapping) -> { + tableMapping.getColumnsMapping().forEach((columnName, columnMapping) -> { bindAttributes(resultSet, columnIndex.getValue(), columnMapping, attributes); columnIndex.increment(); }); @@ -498,7 +498,7 @@ private List> getIdentifiablesInt private List> getIdentifiables(UUID networkUuid, int variantNum, TableMapping tableMapping) { try (var connection = dataSource.getConnection()) { - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet())); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesQuery(tableMapping.getTable(), tableMapping.getColumnsMapping().keySet())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); return getIdentifiablesInternal(variantNum, preparedStmt, tableMapping); @@ -517,7 +517,7 @@ private List> getIdentifiablesInC Set containerColumns, TableMapping tableMapping) { try (var connection = dataSource.getConnection()) { - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableMapping.getTable(), tableMapping.getColumnMapping().keySet(), containerColumns, containerIds.size())); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetIdentifiablesInContainerQuery(tableMapping.getTable(), tableMapping.getColumnsMapping().keySet(), containerColumns, containerIds.size())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); for (int i = 0; i < containerColumns.size(); i++) { @@ -540,10 +540,6 @@ private List> getIdentifiablesInV return getIdentifiablesInContainer(networkUuid, variantNum, List.of(voltageLevelId), tableMapping.getVoltageLevelIdColumns(), tableMapping); } - private List> getIdentifiablesInVoltageLevel(UUID networkUuid, int variantNum, String voltageLevelId, TableMapping tableMapping) { - return getIdentifiablesInContainer(networkUuid, variantNum, voltageLevelId, tableMapping.getVoltageLevelIdColumns(), tableMapping); - } - public void updateIdentifiables(UUID networkUuid, List> resources, TableMapping tableMapping, String columnToAddToWhereClause) { try (var connection = dataSource.getConnection()) { @@ -1106,7 +1102,7 @@ public Optional> getIdentifiable(UUID networkUu private List> getVoltageLevelsInSubstation(UUID networkUuid, int variantNum, String substationId) { try (var connection = dataSource.getConnection()) { var voltageLevelMapping = mappings.getVoltageLevelMappings(); - var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetVoltageLevelsInSubstationQuery(voltageLevelMapping.getColumnMapping().keySet())); + var preparedStmt = connection.prepareStatement(QueryCatalog.buildGetVoltageLevelsInSubstationQuery(voltageLevelMapping.getColumnsMapping().keySet())); preparedStmt.setObject(1, networkUuid); preparedStmt.setInt(2, variantNum); preparedStmt.setString(3, substationId); @@ -1115,7 +1111,7 @@ private List> getVoltageLevelsInSubstation(UUID if (resultSet.next()) { VoltageLevelAttributes attributes = new VoltageLevelAttributes(); MutableInt columnIndex = new MutableInt(2); - voltageLevelMapping.getColumnMapping().forEach((columnName, columnMapping) -> { + voltageLevelMapping.getColumnsMapping().forEach((columnName, columnMapping) -> { bindAttributes(resultSet, columnIndex.getValue(), columnMapping, attributes); columnIndex.increment(); }); diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java index 0467487d4..027c05e8b 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/QueryCatalog.java @@ -25,6 +25,7 @@ public final class QueryCatalog { static final String VARIANT_ID_COLUMN = "variantId"; static final String UUID_COLUMN = "uuid"; + static final String SUBSTATION_ID_COLUMN = "substationId"; static final String NETWORK_UUID_COLUMN = "networkUuid"; static final String VARIANT_NUM_COLUMN = "variantNum"; static final String ID_COLUMN = "id"; diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java b/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java index 623b64123..57ee57b1b 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/TableMapping.java @@ -32,7 +32,7 @@ public class TableMapping { private final Set voltageLevelIdColumns; - private final Map columnMapping = new LinkedHashMap<>(); + private final Map columnsMapping = new LinkedHashMap<>(); public TableMapping(String table, ResourceType resourceType, Resource.Builder resourceBuilder, Supplier attributesSupplier, Set voltageLevelIdColumns) { @@ -63,8 +63,8 @@ public Set getVoltageLevelIdColumns() { return voltageLevelIdColumns; } - public Map getColumnMapping() { - return columnMapping; + public Map getColumnsMapping() { + return columnsMapping; } public void addColumnMapping(String name, ColumnMapping columnMapping) {