Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize temporary and permanent limits db writings and db reading #82

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion network-store-server/pom.xml
Original file line number Diff line number Diff line change
@@ -107,7 +107,6 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2024, 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.server;

import com.powsybl.iidm.network.LimitType;
import com.powsybl.network.store.server.dto.PermanentLimitAttributes;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
@ToString
@Builder
@AllArgsConstructor
@Getter
public class PermanentLimitSqlData {
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved

private String operationalLimitsGroupId;
private double value;
private Integer side;
private LimitType limitType;

public PermanentLimitSqlData() { }
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved

public static PermanentLimitSqlData of(PermanentLimitAttributes permanentLimitAttributes) {
return PermanentLimitSqlData.builder()
.operationalLimitsGroupId(permanentLimitAttributes.getOperationalLimitsGroupId())
.value(permanentLimitAttributes.getValue())
.side(permanentLimitAttributes.getSide())
.limitType(permanentLimitAttributes.getLimitType())
.build();
}

public PermanentLimitAttributes toPermanentLimitAttributes() {
return PermanentLimitAttributes.builder()
.operationalLimitsGroupId(operationalLimitsGroupId)
.value(value)
.side(side)
.limitType(limitType)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -41,6 +41,8 @@ public final class QueryCatalog {
static final String ALPHA_COLUMN = "alpha";
static final String OPERATIONAL_LIMITS_GROUP_ID_COLUMN = "operationalLimitsGroupId";
static final String SELECTED_OPERATIONAL_LIMITS_GROUP_ID_COLUMN = "selectedOperationalLimitsGroupId";
static final String TEMPORARY_LIMITS = "temporarylimits";
static final String PERMANENT_LIMITS = "permanentlimits";
static final String TAP_CHANGER_STEP_TABLE = "tapChangerStep";
static final String REGULATING_POINT_TABLE = "regulatingPoint";
static final String REGULATION_MODE = "regulationMode";
@@ -278,151 +280,136 @@ public static String buildCloneNetworksQuery(Collection<String> columns) {
"where uuid = ? and " + VARIANT_NUM_COLUMN + " = ?";
}

// Temporary Limits
public static String buildCloneTemporaryLimitsQuery() {
return "insert into temporarylimit(" + EQUIPMENT_ID_COLUMN + ", " + EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " + VARIANT_NUM_COLUMN + ", " + OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " + SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", " + NAME_COLUMN +
", value_, acceptableDuration, fictitious) " + "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", ?, ?, " + OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " + SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", " + NAME_COLUMN +
", value_, acceptableDuration, fictitious from temporarylimit where " + NETWORK_UUID_COLUMN +
" = ? and " + VARIANT_NUM_COLUMN + " = ?";
// temporary limits
public static String buildInsertNewTemporaryLimitsQuery() {
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved
return "insert into " + TEMPORARY_LIMITS + "(" +
EQUIPMENT_ID_COLUMN + ", " + EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " + TEMPORARY_LIMITS + ") " +
" values (?, ?, ?, ?, ?)";
}

public static String buildTemporaryLimitQuery(String columnNameForWhereClause) {
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved
return "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " +
SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", " +
NAME_COLUMN + ", " +
"value_, acceptableDuration, fictitious " +
"from temporarylimit where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
columnNameForWhereClause + " = ?";
public static String buildDeleteNewTemporaryLimitsQuery() {
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved
return "delete from " + TEMPORARY_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ?";
}

public static String buildDeleteNewTemporaryLimitsVariantQuery() {
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved
return "delete from " + TEMPORARY_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ?";
}

public static String buildTemporaryLimitWithInClauseQuery(String columnNameForInClause, int numberOfValues) {
public static String buildDeleteNewTemporaryLimitsVariantEquipmentINQuery(int numberOfValues) {
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved
if (numberOfValues < 1) {
throw new IllegalArgumentException(MINIMAL_VALUE_REQUIREMENT_ERROR);
}
return "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " +
SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", " +
NAME_COLUMN + ", " +
"value_, acceptableDuration, fictitious " +
"from temporarylimit where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
columnNameForInClause + " in (" +
"?, ".repeat(numberOfValues - 1) + "?)";
}

public static String buildInsertTemporaryLimitsQuery() {
return "insert into temporarylimit(" +
EQUIPMENT_ID_COLUMN + ", " + EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " + SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", " +
NAME_COLUMN + ", value_, acceptableDuration, fictitious)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
return "delete from " + TEMPORARY_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
EQUIPMENT_ID_COLUMN + " in (" +
"?, ".repeat(numberOfValues - 1) + "?)";
}

public static String buildDeleteTemporaryLimitsVariantEquipmentINQuery(int numberOfValues) {
public static String buildNewTemporaryLimitWithInClauseQuery(String columnNameForInClause, int numberOfValues) {
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved
if (numberOfValues < 1) {
throw new IllegalArgumentException(MINIMAL_VALUE_REQUIREMENT_ERROR);
}
return "delete from temporarylimit where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
EQUIPMENT_ID_COLUMN + " in (" +
"?, ".repeat(numberOfValues - 1) + "?)";
return "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
TEMPORARY_LIMITS +
" from " + TEMPORARY_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
columnNameForInClause + " in (" +
"?, ".repeat(numberOfValues - 1) + "?)";
}

public static String buildDeleteTemporaryLimitsVariantQuery() {
return "delete from temporarylimit where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ?";
public static String buildCloneNewTemporaryLimitsQuery() {
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved
return "insert into " + TEMPORARY_LIMITS + "(" + EQUIPMENT_ID_COLUMN + ", " + EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " + VARIANT_NUM_COLUMN + ", " + TEMPORARY_LIMITS + ") " + "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", ?, ?, " + TEMPORARY_LIMITS + " from " + TEMPORARY_LIMITS + " where " + NETWORK_UUID_COLUMN +
" = ? and " + VARIANT_NUM_COLUMN + " = ?";
}

public static String buildDeleteTemporaryLimitsQuery() {
return "delete from temporarylimit where " +
NETWORK_UUID_COLUMN + " = ?";
public static String buildNewTemporaryLimitQuery(String columnNameForWhereClause) {
return "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
TEMPORARY_LIMITS +
" from " + TEMPORARY_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
columnNameForWhereClause + " = ?";
}

// permanent Limits
public static String buildClonePermanentLimitsQuery() {
return "insert into permanentlimit(" + EQUIPMENT_ID_COLUMN + ", " + EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " + VARIANT_NUM_COLUMN + ", " + OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " + SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", value_) " + "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", ?, ?, " + OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " + SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", value_ from permanentlimit where " + NETWORK_UUID_COLUMN +
" = ? and " + VARIANT_NUM_COLUMN + " = ?";
// permanent limits
public static String buildInsertNewPermanentLimitsQuery() {
return "insert into " + PERMANENT_LIMITS + " (" +
EQUIPMENT_ID_COLUMN + ", " + EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " + PERMANENT_LIMITS + ") " +
" values (?, ?, ?, ?, ?)";
}

public static String buildPermanentLimitQuery(String columnNameForWhereClause) {
return "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " +
SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", " +
"value_ " +
"from permanentlimit where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
columnNameForWhereClause + " = ?";
public static String buildDeleteNewPermanentLimitsQuery() {
return "delete from " + PERMANENT_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ?";
}

public static String buildDeleteNewPermanentLimitsVariantQuery() {
return "delete from " + PERMANENT_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ?";
}

public static String buildPermanentLimitWithInClauseQuery(String columnNameForInClause, int numberOfValues) {
public static String buildDeleteNewPermanentLimitsVariantEquipmentINQuery(int numberOfValues) {
if (numberOfValues < 1) {
throw new IllegalArgumentException(MINIMAL_VALUE_REQUIREMENT_ERROR);
}
return "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " +
SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", " +
"value_ " +
"from permanentlimit where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
columnNameForInClause + " in (" +
"?, ".repeat(numberOfValues - 1) + "?)";
}

public static String buildInsertPermanentLimitsQuery() {
return "insert into permanentlimit(" +
EQUIPMENT_ID_COLUMN + ", " + EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
OPERATIONAL_LIMITS_GROUP_ID_COLUMN + ", " + SIDE_COLUMN + ", " + LIMIT_TYPE_COLUMN + ", value_)" +
" values (?, ?, ?, ?, ?, ?, ?, ?)";
return "delete from " + PERMANENT_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
EQUIPMENT_ID_COLUMN + " in (" +
"?, ".repeat(numberOfValues - 1) + "?)";
}

public static String buildDeletePermanentLimitsVariantEquipmentINQuery(int numberOfValues) {
public static String buildNewPermanentLimitWithInClauseQuery(String columnNameForInClause, int numberOfValues) {
if (numberOfValues < 1) {
throw new IllegalArgumentException(MINIMAL_VALUE_REQUIREMENT_ERROR);
}
return "delete from permanentlimit where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
EQUIPMENT_ID_COLUMN + " in (" +
"?, ".repeat(numberOfValues - 1) + "?)";
return "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
PERMANENT_LIMITS +
" from " + PERMANENT_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
columnNameForInClause + " in (" +
"?, ".repeat(numberOfValues - 1) + "?)";
}

public static String buildDeletePermanentLimitsVariantQuery() {
return "delete from permanentlimit where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ?";
public static String buildCloneNewPermanentLimitsQuery() {
return "insert into " + PERMANENT_LIMITS + "(" + EQUIPMENT_ID_COLUMN + ", " + EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " + VARIANT_NUM_COLUMN + ", " + PERMANENT_LIMITS + ") " + "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", ?, ?, " + PERMANENT_LIMITS + " from " + PERMANENT_LIMITS + " where " + NETWORK_UUID_COLUMN +
" = ? and " + VARIANT_NUM_COLUMN + " = ?";
}

public static String buildDeletePermanentLimitsQuery() {
return "delete from permanentlimit where " +
NETWORK_UUID_COLUMN + " = ?";
public static String buildNewPermanentLimitQuery(String columnNameForWhereClause) {
return "select " + EQUIPMENT_ID_COLUMN + ", " +
EQUIPMENT_TYPE_COLUMN + ", " +
NETWORK_UUID_COLUMN + ", " +
VARIANT_NUM_COLUMN + ", " +
PERMANENT_LIMITS +
" from " + PERMANENT_LIMITS + " where " +
NETWORK_UUID_COLUMN + " = ? and " +
VARIANT_NUM_COLUMN + " = ? and " +
columnNameForWhereClause + " = ?";
}

// Reactive Capability Curve Point
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (c) 2024, 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.server;

import com.powsybl.iidm.network.LimitType;
import com.powsybl.network.store.model.TemporaryLimitAttributes;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
@ToString
@Builder
@AllArgsConstructor
@Getter
public class TemporaryLimitSqlData {
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved
private String operationalLimitsGroupId;
private Integer side;
private LimitType limitType;
private String name;
private double value;
private Integer acceptableDuration;
private boolean fictitious;

public TemporaryLimitSqlData() { }
EtienneLt marked this conversation as resolved.
Show resolved Hide resolved

public static TemporaryLimitSqlData of(TemporaryLimitAttributes temporaryLimit) {
return TemporaryLimitSqlData.builder()
.operationalLimitsGroupId(temporaryLimit.getOperationalLimitsGroupId())
.side(temporaryLimit.getSide())
.limitType(temporaryLimit.getLimitType())
.name(temporaryLimit.getName())
.value(temporaryLimit.getValue())
.acceptableDuration(temporaryLimit.getAcceptableDuration())
.fictitious(temporaryLimit.isFictitious())
.build();
}

public TemporaryLimitAttributes toTemporaryLimitAttributes() {
return TemporaryLimitAttributes.builder()
.operationalLimitsGroupId(operationalLimitsGroupId)
.side(side)
.limitType(limitType)
.name(name)
.value(value)
.acceptableDuration(acceptableDuration)
.fictitious(fictitious)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
@Schema(description = "limits attributes")
public class LimitsInfos {

@Schema(description = "List of permeant limits")
@Schema(description = "List of permanent limits")
private List<PermanentLimitAttributes> permanentLimits = new ArrayList<>();

@Schema(description = "List of temporary limits")
Loading