Skip to content

Commit 6bb4abe

Browse files
committed
Code Cleaning
1 parent 6667c3d commit 6bb4abe

File tree

4 files changed

+0
-211
lines changed

4 files changed

+0
-211
lines changed

src/main/java/edu/ie3/datamodel/Main.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/edu/ie3/datamodel/io/SqlUtils.java

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,7 @@
55
*/
66
package edu.ie3.datamodel.io;
77

8-
import static edu.ie3.util.StringUtils.camelCaseToSnakeCase;
9-
10-
import edu.ie3.datamodel.exceptions.EntityProcessorException;
11-
import edu.ie3.datamodel.exceptions.ProcessorProviderException;
12-
import edu.ie3.datamodel.io.naming.DatabaseNamingStrategy;
13-
import edu.ie3.datamodel.io.processor.ProcessorProvider;
14-
import edu.ie3.datamodel.models.Entity;
15-
import java.util.Arrays;
16-
import java.util.HashMap;
17-
import java.util.Map;
188
import java.util.Objects;
19-
import java.util.stream.Collectors;
20-
import java.util.stream.Stream;
219
import org.slf4j.Logger;
2210
import org.slf4j.LoggerFactory;
2311

@@ -42,149 +30,6 @@ public static String queryCreateGridTable(String schemaName) {
4230
+ endQueryCreateTable;
4331
}
4432

45-
/** @return query to create a SQL table for an unique entity */
46-
public static String queryCreateTableUniqueEntity(Class<? extends Entity> cls, String schemaName)
47-
throws EntityProcessorException, ProcessorProviderException {
48-
ProcessorProvider processorProvider = new ProcessorProvider();
49-
DatabaseNamingStrategy namingStrategy = new DatabaseNamingStrategy();
50-
String[] headerElements = processorProvider.getHeaderElements(cls);
51-
Stream<String> strHeader =
52-
Stream.concat(Arrays.stream(headerElements), Stream.of(DbGridMetadata.GRID_UUID));
53-
Stream<String> dtHeader =
54-
strHeader.map(
55-
element ->
56-
camelCaseToSnakeCase(element)
57-
+ " "
58-
+ columnToSqlDataType().get(camelCaseToSnakeCase(element)));
59-
return "CREATE TABLE "
60-
+ schemaName
61-
+ "."
62-
+ namingStrategy.getEntityName(cls).orElseThrow()
63-
+ "\n(\n\t"
64-
+ String.valueOf(dtHeader.collect(Collectors.joining(",\n\t")))
65-
+ "\n)\n\t"
66-
+ "WITHOUT OIDS\n"
67-
+ "\t"
68-
+ "TABLESPACE pg_default;\n";
69-
}
70-
71-
/**
72-
* Map to create a SQL table for an entity with the right data types.
73-
*
74-
* @return Map column name -> data type
75-
*/
76-
public static Map<String, String> columnToSqlDataType() {
77-
Map<String, String> map = new HashMap<>();
78-
79-
map.put("uuid", "uuid PRIMARY KEY");
80-
map.put("time_series", "uuid NOT NULL");
81-
map.put("time", "timestamp with time zone NOT NULL");
82-
map.put("p", "double precision NOT NULL");
83-
map.put("q", "double precision NOT NULL");
84-
map.put("c", "double precision NOT NULL");
85-
map.put("s_rated", "double precision NOT NULL");
86-
87-
map.put("cost_controlled", "bool NOT NULL");
88-
map.put("feed_in_tariff", "int NOT NULL");
89-
map.put("id", "TEXT NOT NULL");
90-
map.put("market_reaction", "bool NOT NULL");
91-
map.put("node", "uuid NOT NULL");
92-
map.put("operates_from", "timestamp with time zone");
93-
map.put("operates_until", "timestamp with time zone");
94-
map.put("operator", "uuid");
95-
map.put("q_characteristics", "TEXT NOT NULL");
96-
map.put("geo_position", "TEXT NOT NULL");
97-
map.put("length", "double precision NOT NULL");
98-
map.put("node_a", "uuid NOT NULL");
99-
map.put("node_b", "uuid NOT NULL");
100-
map.put("olm_characteristic", "TEXT NOT NULL");
101-
map.put("parallel_devices", "int NOT NULL");
102-
map.put("cos_phi_rated", "TEXT NOT NULL");
103-
map.put("dsm", "bool NOT NULL");
104-
map.put("e_cons_annual", "double precision NOT NULL");
105-
map.put("load_profile", "TEXT NOT NULL");
106-
map.put("controlling_em", "uuid NOT NULL");
107-
108-
map.put("auto_tap", "bool NOT NULL");
109-
map.put("tap_pos", "int NOT NULL");
110-
map.put("type", "uuid NOT NULL");
111-
112-
map.put("v_ang", "bool NOT NULL");
113-
map.put("v_mag", "bool NOT NULL");
114-
map.put("slack", "bool NOT NULL");
115-
map.put("subnet", "int NOT NULL");
116-
map.put("v_rated", "double precision NOT NULL");
117-
map.put("v_target", "double precision NOT NULL");
118-
map.put("volt_lvl", "TEXT NOT NULL");
119-
map.put("charging_points", "int NOT NULL");
120-
map.put("location_type", "TEXT NOT NULL");
121-
map.put("v_2g_support", "bool NOT NULL");
122-
123-
map.put("albedo", "double precision NOT NULL");
124-
map.put("azimuth", "double precision NOT NULL");
125-
map.put("elevation_angle", "double precision NOT NULL");
126-
map.put("eta_conv", "double precision NOT NULL");
127-
map.put("k_g", "double precision NOT NULL");
128-
map.put("k_t", "double precision NOT NULL");
129-
130-
map.put("grid_name", "TEXT NOT NULL");
131-
map.put("grid_uuid", "uuid NOT NULL");
132-
133-
map.put("b_m", "double precision NOT NULL");
134-
map.put("d_phi", "double precision NOT NULL");
135-
map.put("d_v", "double precision NOT NULL");
136-
map.put("g_m", "double precision NOT NULL");
137-
map.put("r_sc", "double precision NOT NULL");
138-
map.put("tap_max", "int NOT NULL");
139-
map.put("tap_min", "int NOT NULL");
140-
map.put("tap_neutr", "int NOT NULL");
141-
map.put("tap_side", "bool NOT NULL");
142-
map.put("v_rated_a", "int NOT NULL");
143-
map.put("v_rated_b", "int NOT NULL");
144-
map.put("x_sc", "int NOT NULL");
145-
map.put("graphic_layer", "TEXT NOT NULL");
146-
map.put("line", "uuid NOT NULL");
147-
map.put("path", "TEXT NOT NULL");
148-
map.put("point", "TEXT NOT NULL");
149-
map.put("inlet_temp", "double precision NOT NULL");
150-
map.put("return_temp", "double precision NOT NULL");
151-
map.put("storage_volume_lvl", "double precision NOT NULL");
152-
map.put("storage_volume_lvl_min", "double precision NOT NULL");
153-
map.put("thermal_bus", "uuid NOT NULL");
154-
map.put("eth_capa", "double precision NOT NULL");
155-
map.put("eth_losses", "double precision NOT NULL");
156-
map.put("lower_temperature_limit", "double precision NOT NULL");
157-
map.put("target_temperature", "double precision NOT NULL");
158-
map.put("upper_temperature_limit", "double precision NOT NULL");
159-
map.put("b", "double precision NOT NULL");
160-
map.put("g", "double precision NOT NULL");
161-
map.put("i_max", "double precision NOT NULL");
162-
map.put("r", "double precision NOT NULL");
163-
map.put("x", "double precision NOT NULL");
164-
165-
map.put("connected_assets", "TEXT NOT NULL");
166-
map.put("capex", "double precision NOT NULL");
167-
map.put("control_strategy", "TEXT NOT NULL");
168-
169-
map.put("input_model", "uuid NOT NULL");
170-
map.put("soc", "double precision NOT NULL");
171-
map.put("p_max", "double precision NOT NULL");
172-
map.put("p_min", "double precision NOT NULL");
173-
map.put("p_ref", "double precision NOT NULL");
174-
175-
map.put("dod", "double precision NOT NULL");
176-
map.put("e_storage", "double precision NOT NULL");
177-
map.put("eta", "double precision NOT NULL");
178-
map.put("life_cycle", "double precision NOT NULL");
179-
map.put("life_time", "double precision NOT NULL");
180-
map.put("opex", "double precision NOT NULL");
181-
map.put("active_power_gradient", "double precision NOT NULL");
182-
183-
// TODO: Not all data types are implemented
184-
185-
return map;
186-
}
187-
18833
/**
18934
* To avoid data type conflicts while insertion into a SQL table all columns should be quoted.
19035
*

src/main/java/edu/ie3/datamodel/io/sink/SqlSink.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -504,28 +504,6 @@ private String writeOneLine(String[] entries, String[] addParams) {
504504

505505
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
506506

507-
/**
508-
* Creates a table for an entity class
509-
*
510-
* @param cls The class for which a table should be created
511-
* @param schemaName Schema name of the database
512-
*/
513-
public void createClassTable(Class<? extends Entity> cls, String schemaName)
514-
throws SQLException, ProcessorProviderException, EntityProcessorException {
515-
String query = queryCreateTableUniqueEntity(cls, schemaName);
516-
connector.executeUpdate(query);
517-
}
518-
519-
/**
520-
* Creates a table for a grid
521-
*
522-
* @param schemaName Schema name of the database
523-
*/
524-
public void createGridTable(String schemaName) throws SQLException {
525-
String query = queryCreateGridTable(schemaName);
526-
connector.executeUpdate(query);
527-
}
528-
529507
/** @return insertion order for unique entities */
530508
private static List<Class<?>> hierarchicInsert() {
531509
List<Class<?>> sortedInsert = new ArrayList<>();

src/test/groovy/edu/ie3/datamodel/io/sink/SqlSinkTest.groovy

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,6 @@ class SqlSinkTest extends Specification implements TestContainerHelper, TimeSeri
321321
" Detail: Key (node)=(4ca90220-74c2-4369-9afa-a18bf068840d) is not present in table \"node_input\"."
322322
}
323323

324-
def "A valid SqlSink can create a table for entity class."() {
325-
given:
326-
def sink = new SqlSink(schemaName, namingStrategy, connector)
327-
def hp = SystemParticipantTestData.hpInput
328-
329-
when:
330-
sink.createClassTable(hp.getClass(), schemaName)
331-
332-
then:
333-
sqlSource.checkExistingTable("hp_input")
334-
}
335324
def "A valid SqlSink throws an exception if a grid does not exist."() {
336325
given:
337326
def sink = new SqlSink(schemaName, namingStrategy, connector)

0 commit comments

Comments
 (0)