Skip to content

Commit 49415fe

Browse files
committed
Adapt column naming from "datum" to "time"
1 parent d1b45f5 commit 49415fe

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

src/main/java/edu/ie3/tools/Converter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private void validation() {
407407
private List<ICONWeatherModel> checkForPreviousEntries(List<ICONWeatherModel> entities) {
408408
LinkedList<ICONWeatherModel> checkedEntities = new LinkedList<>();
409409
Map<ZonedDateTime, List<ICONWeatherModel>> entitiesByDate =
410-
entities.stream().collect(Collectors.groupingBy(ICONWeatherModel::getDate));
410+
entities.stream().collect(Collectors.groupingBy(ICONWeatherModel::getTime));
411411
entitiesByDate.forEach(
412412
(date, entitiesAtDate) ->
413413
checkedEntities.addAll(checkForPreviousEntries(entitiesAtDate, date)));

src/main/java/edu/ie3/tools/models/persistence/CoordinateModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
+ "AND longitude BETWEEN :minLongitude AND :maxLongitude"),
3030
})
3131
@Entity(name = "icon_coordinates")
32-
public class CoordinateModel extends edu.ie3.tools.models.persistence.AbstractCoordinateModel {
32+
public class CoordinateModel extends AbstractCoordinateModel {
3333

3434
public static final String COSMO_Coordinates = "CoordinateModel.COSMO_Coordinates";
3535
public static final String ICON_Coordinates = "CoordinateModel.ICON_Coordinates";

src/main/java/edu/ie3/tools/models/persistence/ICONWeatherModel.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class ICONWeatherModel implements Serializable {
2121
private static final long serialVersionUID = -3506091597737302833L;
2222

2323
@Id
24-
@Column(name = "datum", nullable = false)
25-
private ZonedDateTime date;
24+
@Column(name = "time", nullable = false)
25+
private ZonedDateTime time;
2626

2727
@Id
2828
@ManyToOne(cascade = CascadeType.DETACH)
@@ -138,8 +138,8 @@ public class ICONWeatherModel implements Serializable {
138138

139139
public ICONWeatherModel() {}
140140

141-
public ICONWeatherModel(ZonedDateTime date, CoordinateModel coordinate) {
142-
this.date = date;
141+
public ICONWeatherModel(ZonedDateTime time, CoordinateModel coordinate) {
142+
this.time = time;
143143
this.coordinate = coordinate;
144144
}
145145

@@ -162,7 +162,7 @@ public static ICONWeatherModel getInterpolatedEntity(ICONWeatherModel... entitie
162162
}
163163

164164
public ICONWeatherKey getKey() {
165-
return new ICONWeatherKey(coordinate, date);
165+
return new ICONWeatherKey(coordinate, time);
166166
}
167167

168168
public static String getSQLUpsertStatement(Collection<ICONWeatherModel> entities) {
@@ -176,15 +176,15 @@ public static String getSQLUpsertStatement(
176176
"INSERT INTO "
177177
+ database_schema
178178
+ ".weather(\n"
179-
+ "\tdatum, alb_rad, asob_s, aswdifd_s, aswdifu_s, aswdir_s, sobs_rad, p_20m, p_65m, p_131m, t_131m, t_2m, t_g, u_10m, u_131m, u_20m, u_216m, u_65m, v_10m, v_131m, v_20m, v_216m, v_65m, w_131m, w_20m, w_216m, w_65m, z0, coordinate_id)\n"
179+
+ "\ttime, alb_rad, asob_s, aswdifd_s, aswdifu_s, aswdir_s, sobs_rad, p_20m, p_65m, p_131m, t_131m, t_2m, t_g, u_10m, u_131m, u_20m, u_216m, u_65m, v_10m, v_131m, v_20m, v_216m, v_65m, w_131m, w_20m, w_216m, w_65m, z0, coordinate_id)\n"
180180
+ "\t VALUES ");
181181
entities.forEach(
182182
entity -> upsertStatementBuilder.append(entity.getSQLInsertValuesString() + ", "));
183183
int lastComma = upsertStatementBuilder.lastIndexOf(",");
184184
upsertStatementBuilder.deleteCharAt(lastComma);
185-
upsertStatementBuilder.append("ON CONFLICT (coordinate_id, datum) DO UPDATE \n" + " SET ");
185+
upsertStatementBuilder.append("ON CONFLICT (coordinate_id, time) DO UPDATE \n" + " SET ");
186186
upsertStatementBuilder.append(
187-
"datum=excluded.datum,\n"
187+
"time=excluded.time,\n"
188188
+ " alb_rad=excluded.alb_rad,\n"
189189
+ " asob_s=excluded.asob_s,\n"
190190
+ " aswdifd_s=excluded.aswdifd_s,\n"
@@ -216,12 +216,12 @@ public static String getSQLUpsertStatement(
216216
return upsertStatementBuilder.toString();
217217
}
218218

219-
public ZonedDateTime getDate() {
220-
return date;
219+
public ZonedDateTime getTime() {
220+
return time;
221221
}
222222

223-
public void setDate(ZonedDateTime date) {
224-
this.date = date;
223+
public void setTime(ZonedDateTime date) {
224+
this.time = date;
225225
}
226226

227227
public Double getAlb_rad() {
@@ -714,13 +714,13 @@ public void setCoordinate(CoordinateModel coordinate) {
714714
this.coordinate = coordinate;
715715
}
716716

717-
// (datum, alb_rad, asob_s, aswdifd_s, aswdifu_s, aswdir_s,sobs_rad,p_20m,p_65m,p_131m, t_131m,
717+
// (time, alb_rad, asob_s, aswdifd_s, aswdifu_s, aswdir_s,sobs_rad,p_20m,p_65m,p_131m, t_131m,
718718
// t_2m, t_g, u_10m, u_131m, u_20m,
719719
// u_216m, u_65m, v_10m, v_131m, v_20m, v_216m, v_65m, w_131m, w_20m, w_216m, w_65m, z0,
720720
// coordinate_id)
721721
public String getSQLInsertValuesString() {
722722
String insertValues = "(";
723-
insertValues += "'" + ConfigurationParameters.SQL_FORMATTER(date) + "', ";
723+
insertValues += "'" + ConfigurationParameters.SQL_FORMATTER(time) + "', ";
724724
insertValues += alb_rad + ", ";
725725
insertValues += asob_s + ", ";
726726
insertValues += aswdifd_s + ", ";
@@ -765,7 +765,7 @@ public static String getPSQLFindString(String database_schema) {
765765
+ ".weather w JOIN "
766766
+ database_schema
767767
+ ".icon_coordinates c ON w.coordinate_id = c.id "
768-
+ "WHERE datum=? AND coordinate_id = ANY(?);";
768+
+ "WHERE time=? AND coordinate_id = ANY(?);";
769769
return query;
770770
}
771771

@@ -774,7 +774,7 @@ public boolean equals(Object o) {
774774
if (this == o) return true;
775775
if (!(o instanceof ICONWeatherModel)) return false;
776776
ICONWeatherModel that = (ICONWeatherModel) o;
777-
return Objects.equals(date, that.date)
777+
return Objects.equals(time, that.time)
778778
&& Objects.equals(coordinate, that.coordinate)
779779
&& Objects.equals(alb_rad, that.alb_rad)
780780
&& Objects.equals(asob_s, that.asob_s)
@@ -807,14 +807,14 @@ public boolean equals(Object o) {
807807

808808
@Override
809809
public int hashCode() {
810-
return Objects.hash(coordinate, date);
810+
return Objects.hash(coordinate, time);
811811
}
812812

813813
@Override
814814
public String toString() {
815815
return "ICONWeatherModel{"
816-
+ "date="
817-
+ date
816+
+ "time="
817+
+ time
818818
+ "\n, coordinate="
819819
+ coordinate
820820
+ ", alb_rad="

src/main/java/edu/ie3/tools/models/persistence/keys/ICONWeatherKey.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
public class ICONWeatherKey implements Serializable {
1414

1515
private CoordinateModel coordinate;
16-
private ZonedDateTime date;
16+
private ZonedDateTime time;
1717

18-
public ICONWeatherKey(CoordinateModel coordinate, ZonedDateTime date) {
18+
public ICONWeatherKey(CoordinateModel coordinate, ZonedDateTime time) {
1919
this.coordinate = coordinate;
20-
this.date = date;
20+
this.time = time;
2121
}
2222

2323
public ICONWeatherKey() {}
@@ -30,16 +30,16 @@ public void setCoordinate(CoordinateModel coordinate) {
3030
this.coordinate = coordinate;
3131
}
3232

33-
public ZonedDateTime getDate() {
34-
return date;
33+
public ZonedDateTime getTime() {
34+
return time;
3535
}
3636

37-
public void setDate(ZonedDateTime date) {
38-
this.date = date;
37+
public void setTime(ZonedDateTime date) {
38+
this.time = date;
3939
}
4040

4141
@Override
4242
public String toString() {
43-
return "ICONWeatherKey{" + "coordinate=" + coordinate + ", date=" + date + '}';
43+
return "ICONWeatherKey{" + "coordinate=" + coordinate + ", time=" + time + '}';
4444
}
4545
}

src/main/java/edu/ie3/tools/utils/DatabaseController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private Collection<ICONWeatherModel> jdbcFindWeather(
200200
coordinateModel.setLongitude(rs.getDouble("longitude"));
201201
ICONWeatherModel weather =
202202
new ICONWeatherModel(
203-
ZonedDateTime.of(rs.getTimestamp("datum").toLocalDateTime(), ZoneId.of("UTC")),
203+
ZonedDateTime.of(rs.getTimestamp("time").toLocalDateTime(), ZoneId.of("UTC")),
204204
coordinateModel);
205205

206206
for (Parameter parameter : Parameter.values()) {

src/test/java/edu/ie3/tools/ConverterIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ public void testAmountOfData() {
200200
assertEquals(numberOfCoordinates * 3, numberOfRows);
201201

202202
statement = connect.createStatement();
203-
rs = statement.executeQuery("SELECT DISTINCT(datum) AS datum FROM icon.weather;");
203+
rs = statement.executeQuery("SELECT DISTINCT(time) AS time FROM icon.weather;");
204204
statement.closeOnCompletion();
205205
Set<String> dates = new HashSet<>();
206206
while (rs.next()) {
207-
dates.add(rs.getTimestamp("datum").toString());
207+
dates.add(rs.getTimestamp("time").toString());
208208
}
209209
// contains three dates, as two date points should overlap
210210
// (Modelrun 3 + Timestep 0 == Modelrun 0 + Timestep 3 == 3 o' Clock)
@@ -347,7 +347,7 @@ private String getValueQuery(int coord_id, String dateString, String param) {
347347
+ param
348348
+ " as value from icon.weather where coordinate_id = "
349349
+ coord_id
350-
+ " and datum = '"
350+
+ " and time = '"
351351
+ dateString
352352
+ "';";
353353
return query;

src/test/java/edu/ie3/tools/models/persistence/ICONWeatherModelTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ public void setUp() throws Exception {
5858
@Test
5959
public void getInterpolatedEntity() {
6060
ICONWeatherModel interpolatedEntity = ICONWeatherModel.getInterpolatedEntity(weather);
61-
interpolatedEntity.setDate(date);
61+
interpolatedEntity.setTime(date);
6262
interpolatedEntity.setCoordinate(coordinate);
6363
assertEquals(weather, interpolatedEntity); // should be the same
6464

6565
ICONWeatherModel newWeather = new ICONWeatherModel(date, coordinate);
66-
interpolatedEntity.setDate(date);
66+
interpolatedEntity.setTime(date);
6767
interpolatedEntity.setCoordinate(coordinate);
6868
newWeather.setAlb_rad(alb_rad);
6969

7070
interpolatedEntity = ICONWeatherModel.getInterpolatedEntity(weather, newWeather);
71-
interpolatedEntity.setDate(date);
71+
interpolatedEntity.setTime(date);
7272
interpolatedEntity.setCoordinate(coordinate);
7373
assertEquals(
7474
weather,
@@ -82,7 +82,7 @@ public void getInterpolatedEntity() {
8282
}
8383
HashMap<String, Double> collectedParameterValues = collectParameterValues(testEntities);
8484
interpolatedEntity = ICONWeatherModel.getInterpolatedEntity(testEntities);
85-
interpolatedEntity.setDate(date);
85+
interpolatedEntity.setTime(date);
8686
interpolatedEntity.setCoordinate(coordinate);
8787

8888
assertEquals(collectedParameterValues.get("alb_rad") / 10, interpolatedEntity.getAlb_rad());
@@ -117,20 +117,20 @@ public void getInterpolatedEntity() {
117117
@Test
118118
public void getSQLUpsertStatement() {
119119
ICONWeatherModel randWeather1 = generateRandomWeatherEntity();
120-
randWeather1.setDate(date);
120+
randWeather1.setTime(date);
121121
randWeather1.setCoordinate(coordinate);
122122
ICONWeatherModel randWeather2 = generateRandomWeatherEntity();
123-
randWeather2.setDate(date);
123+
randWeather2.setTime(date);
124124
randWeather2.setCoordinate(coordinate);
125125
Collection<ICONWeatherModel> entities = Arrays.asList(weather, randWeather1, randWeather2);
126126
String generatedUpsertStatement = ICONWeatherModel.getSQLUpsertStatement(entities, "test");
127127
String sqlInsertInto =
128-
"INSERT INTO test.weather(\n\tdatum, alb_rad, asob_s, aswdifd_s, aswdifu_s, aswdir_s, sobs_rad, p_20m, p_65m, p_131m, t_131m, t_2m, t_g, "
128+
"INSERT INTO test.weather(\n\ttime, alb_rad, asob_s, aswdifd_s, aswdifu_s, aswdir_s, sobs_rad, p_20m, p_65m, p_131m, t_131m, t_2m, t_g, "
129129
+ "u_10m, u_131m, u_20m, u_216m, u_65m, v_10m, v_131m, v_20m, v_216m, v_65m, w_131m, w_20m, w_216m, w_65m, "
130130
+ "z0, coordinate_id)\n\t VALUES ";
131131
assertTrue(generatedUpsertStatement.startsWith(sqlInsertInto));
132132
String sqlOnConflict =
133-
" ON CONFLICT (coordinate_id, datum) DO UPDATE \n SET datum=excluded.datum,\n "
133+
" ON CONFLICT (coordinate_id, time) DO UPDATE \n SET time=excluded.time,\n "
134134
+ "alb_rad=excluded.alb_rad,\n asob_s=excluded.asob_s,\n aswdifd_s=excluded.aswdifd_s,\n "
135135
+ "aswdifu_s=excluded.aswdifu_s,\n aswdir_s=excluded.aswdir_s,\n sobs_rad=excluded.sobs_rad,\n "
136136
+ "p_20m=excluded.p_20m,\n p_65m=excluded.p_65m,\n p_131m=excluded.p_131m,\n t_131m=excluded.t_131m,\n "

src/test/resources/sql/initDatabase.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CREATE TABLE icon.icon_coordinates (
55
coordinate_type character varying(255), CONSTRAINT pk_icon_coordinates PRIMARY KEY (id));
66

77
CREATE TABLE icon.weather (
8-
datum timestamp without time zone NOT NULL, alb_rad double precision, asob_s double precision,
8+
time timestamp without time zone NOT NULL, alb_rad double precision, asob_s double precision,
99
aswdifd_s double precision, aswdifu_s double precision, aswdir_s double precision, sobs_rad double precision,
1010
p_20m double precision, p_65m double precision, p_131m double precision,
1111
t_131m double precision, t_2m double precision, t_g double precision, u_10m double precision,
@@ -14,7 +14,7 @@ CREATE TABLE icon.weather (
1414
v_65m double precision, w_131m double precision, w_20m double precision, w_216m double precision,
1515
w_65m double precision, z0 double precision,
1616
coordinate_id integer NOT NULL,
17-
CONSTRAINT pk_weather PRIMARY KEY (coordinate_id, datum),
17+
CONSTRAINT pk_weather PRIMARY KEY (coordinate_id, time),
1818
CONSTRAINT fk_weather_coordinates FOREIGN KEY (coordinate_id) REFERENCES icon.icon_coordinates (id)
1919
MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION);
2020

0 commit comments

Comments
 (0)