-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into ps/#554-HandlingNoWeatherData
- Loading branch information
Showing
21 changed files
with
1,412 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* © 2023. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.io; | ||
|
||
import static edu.ie3.datamodel.io.SqlUtils.quote; | ||
|
||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
/** Class for identification of entities and results from grids in SQL databases. */ | ||
public record DbGridMetadata(String gridName, UUID uuid) { | ||
|
||
public static final String GRID_TABLE_COLUMN = "grids"; | ||
public static final String GRID_NAME_COLUMN = "grid_name"; | ||
public static final String GRID_UUID_COLUMN = "grid_uuid"; | ||
|
||
public String toString() { | ||
return GRID_NAME_COLUMN + "=" + gridName + ", " + GRID_UUID_COLUMN + "=" + uuid.toString(); | ||
} | ||
|
||
/** @return Stream with grid uuid */ | ||
public Stream<String> getStreamForQuery() { | ||
return Stream.of(quote(uuid.toString(), "'")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* © 2023. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.io; | ||
|
||
import java.util.Objects; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SqlUtils { | ||
|
||
protected static final Logger log = LoggerFactory.getLogger(SqlUtils.class); | ||
private static final String END_QUERY_CREATE_TABLE = | ||
")\n \t WITHOUT OIDS\n \t TABLESPACE pg_default;"; | ||
|
||
private SqlUtils() { | ||
throw new IllegalStateException("Utility classes cannot be instantiated"); | ||
} | ||
|
||
private static String beginQueryCreateTable(String schemaName, String tableName) { | ||
return "CREATE TABLE " + schemaName + "." + tableName + "\n(\n"; | ||
} | ||
|
||
/** @return query to create a SQL table for a grid */ | ||
public static String queryCreateGridTable(String schemaName) { | ||
return beginQueryCreateTable(schemaName, DbGridMetadata.GRID_TABLE_COLUMN) | ||
+ "\tuuid uuid PRIMARY KEY,\n\tname TEXT NOT NULL\n" | ||
+ END_QUERY_CREATE_TABLE; | ||
} | ||
|
||
/** | ||
* To avoid data type conflicts while insertion into a SQL table all columns should be quoted. | ||
* | ||
* @return input with quoteSymbol | ||
*/ | ||
public static String quote(String input, String quoteSymbol) { | ||
if (Objects.equals(input, "") || Objects.equals(input, "null")) { | ||
return "NULL"; | ||
} else { | ||
return input.matches("^\".*\"$") ? input : quoteSymbol + input + quoteSymbol; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.