Skip to content

Commit 004d131

Browse files
committed
Improve code quality
1 parent 49415fe commit 004d131

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

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

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -172,47 +172,49 @@ public static String getSQLUpsertStatement(Collection<ICONWeatherModel> entities
172172
public static String getSQLUpsertStatement(
173173
Collection<ICONWeatherModel> entities, String database_schema) {
174174
StringBuilder upsertStatementBuilder = new StringBuilder();
175-
upsertStatementBuilder.append(
176-
"INSERT INTO "
177-
+ database_schema
178-
+ ".weather(\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"
180-
+ "\t VALUES ");
175+
upsertStatementBuilder
176+
.append("INSERT INTO ")
177+
.append(database_schema)
178+
.append(".weather(\n")
179+
.append(
180+
"\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")
181+
.append("\t VALUES ");
181182
entities.forEach(
182-
entity -> upsertStatementBuilder.append(entity.getSQLInsertValuesString() + ", "));
183+
entity -> upsertStatementBuilder.append(entity.getSQLInsertValuesString()).append(", "));
183184
int lastComma = upsertStatementBuilder.lastIndexOf(",");
184185
upsertStatementBuilder.deleteCharAt(lastComma);
185-
upsertStatementBuilder.append("ON CONFLICT (coordinate_id, time) DO UPDATE \n" + " SET ");
186-
upsertStatementBuilder.append(
187-
"time=excluded.time,\n"
188-
+ " alb_rad=excluded.alb_rad,\n"
189-
+ " asob_s=excluded.asob_s,\n"
190-
+ " aswdifd_s=excluded.aswdifd_s,\n"
191-
+ " aswdifu_s=excluded.aswdifu_s,\n"
192-
+ " aswdir_s=excluded.aswdir_s,\n"
193-
+ " sobs_rad=excluded.sobs_rad,\n"
194-
+ " p_20m=excluded.p_20m,\n"
195-
+ " p_65m=excluded.p_65m,\n"
196-
+ " p_131m=excluded.p_131m,\n"
197-
+ " t_131m=excluded.t_131m,\n"
198-
+ " t_2m=excluded.t_2m,\n"
199-
+ " t_g=excluded.t_g,\n"
200-
+ " u_10m=excluded.u_10m,\n"
201-
+ " u_131m=excluded.u_131m,\n"
202-
+ " u_20m=excluded.u_20m,\n"
203-
+ " u_216m=excluded.u_216m,\n"
204-
+ " u_65m=excluded.u_65m,\n"
205-
+ " v_10m=excluded.v_10m,\n"
206-
+ " v_131m=excluded.v_131m,\n"
207-
+ " v_20m=excluded.v_20m,\n"
208-
+ " v_216m=excluded.v_216m,\n"
209-
+ " v_65m=excluded.v_65m,\n"
210-
+ " w_131m=excluded.w_131m,\n"
211-
+ " w_20m=excluded.w_20m,\n"
212-
+ " w_216m=excluded.w_216m,\n"
213-
+ " w_65m=excluded.w_65m,\n"
214-
+ " z0=excluded.z0,\n"
215-
+ " coordinate_id=excluded.coordinate_id;");
186+
upsertStatementBuilder
187+
.append("ON CONFLICT (coordinate_id, time) DO UPDATE \n" + " SET ")
188+
.append(
189+
"time=excluded.time,\n"
190+
+ " alb_rad=excluded.alb_rad,\n"
191+
+ " asob_s=excluded.asob_s,\n"
192+
+ " aswdifd_s=excluded.aswdifd_s,\n"
193+
+ " aswdifu_s=excluded.aswdifu_s,\n"
194+
+ " aswdir_s=excluded.aswdir_s,\n"
195+
+ " sobs_rad=excluded.sobs_rad,\n"
196+
+ " p_20m=excluded.p_20m,\n"
197+
+ " p_65m=excluded.p_65m,\n"
198+
+ " p_131m=excluded.p_131m,\n"
199+
+ " t_131m=excluded.t_131m,\n"
200+
+ " t_2m=excluded.t_2m,\n"
201+
+ " t_g=excluded.t_g,\n"
202+
+ " u_10m=excluded.u_10m,\n"
203+
+ " u_131m=excluded.u_131m,\n"
204+
+ " u_20m=excluded.u_20m,\n"
205+
+ " u_216m=excluded.u_216m,\n"
206+
+ " u_65m=excluded.u_65m,\n"
207+
+ " v_10m=excluded.v_10m,\n"
208+
+ " v_131m=excluded.v_131m,\n"
209+
+ " v_20m=excluded.v_20m,\n"
210+
+ " v_216m=excluded.v_216m,\n"
211+
+ " v_65m=excluded.v_65m,\n"
212+
+ " w_131m=excluded.w_131m,\n"
213+
+ " w_20m=excluded.w_20m,\n"
214+
+ " w_216m=excluded.w_216m,\n"
215+
+ " w_65m=excluded.w_65m,\n"
216+
+ " z0=excluded.z0,\n"
217+
+ " coordinate_id=excluded.coordinate_id;");
216218
return upsertStatementBuilder.toString();
217219
}
218220

0 commit comments

Comments
 (0)