# HG changeset patch # User Sascha L. Teichmann # Date 1324034772 0 # Node ID 039413d7e3946269876636aeb1e1d61f30f90076 # Parent dbd0b3b1b8b8296f83a5912bff83f0b7510cf9f3 Load gauges from both dbs. flys-aft/trunk@3436 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r dbd0b3b1b8b8 -r 039413d7e394 flys-aft/ChangeLog --- a/flys-aft/ChangeLog Wed Dec 14 17:53:15 2011 +0000 +++ b/flys-aft/ChangeLog Fri Dec 16 11:26:12 2011 +0000 @@ -1,3 +1,15 @@ +2011-12-16 Sascha L. Teichmann + + * src/main/java/de/intevation/db/SymbolicStatement.java: + Made the setX() methods cascadable. + + * src/main/java/de/intevation/aft/River.java: Fetches + the gauges from the database. + + * src/main/resources/sql/aft-common.properties, + src/main/resources/sql/flys-common.properties: Added gauges + statements. + 2011-12-14 Sascha L. Teichmann * src/main/java/de/intevation/db/SymbolicStatement.java: diff -r dbd0b3b1b8b8 -r 039413d7e394 flys-aft/src/main/java/de/intevation/aft/River.java --- a/flys-aft/src/main/java/de/intevation/aft/River.java Wed Dec 14 17:53:15 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/River.java Fri Dec 16 11:26:12 2011 +0000 @@ -1,5 +1,6 @@ package de.intevation.aft; +import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; @@ -32,6 +33,31 @@ throws SQLException { log.info("sync river: " + this); + ResultSet messstellenRs = aftStatements + .getStatement("select.messstelle") + .clearParameters() + .setInt("GEWAESSER_NR", id2).executeQuery(); + + while (messstellenRs.next()) { + String name = messstellenRs.getString("NAME"); + String num = messstellenRs.getString("MESSSTELLE_NR"); + System.err.println(name + ": " + num); + } + + messstellenRs.close(); + + ResultSet gaugesRs = flysStatements + .getStatement("select.gauges") + .clearParameters() + .setInt("river_id", id1).executeQuery(); + + while (gaugesRs.next()) { + int gaugeId = gaugesRs.getInt("id"); + String name = gaugesRs.getString("name"); + System.err.println(name + ": " + gaugeId); + } + + gaugesRs.close(); } public String toString() { diff -r dbd0b3b1b8b8 -r 039413d7e394 flys-aft/src/main/java/de/intevation/db/SymbolicStatement.java --- a/flys-aft/src/main/java/de/intevation/db/SymbolicStatement.java Wed Dec 14 17:53:15 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/db/SymbolicStatement.java Fri Dec 16 11:26:12 2011 +0000 @@ -45,7 +45,7 @@ } } - public void setInt(String key, int value) + public Instance setInt(String key, int value) throws SQLException { List pos = positions.get(key.toLowerCase()); @@ -54,9 +54,11 @@ stmnt.setInt(p, value); } } + + return this; } - public void setString(String key, String value) + public Instance setString(String key, String value) throws SQLException { List pos = positions.get(key.toLowerCase()); @@ -65,9 +67,10 @@ stmnt.setString(p, value); } } + return this; } - public void setObject(String key, Object value) + public Instance setObject(String key, Object value) throws SQLException { List pos = positions.get(key.toLowerCase()); @@ -76,9 +79,10 @@ stmnt.setObject(p, value); } } + return this; } - public void setTimestamp(String key, Timestamp value) + public Instance setTimestamp(String key, Timestamp value) throws SQLException { List pos = positions.get(key.toLowerCase()); @@ -87,9 +91,10 @@ stmnt.setTimestamp(p, value); } } + return this; } - public void setDouble(String key, int value) + public Instance setDouble(String key, int value) throws SQLException { List pos = positions.get(key.toLowerCase()); @@ -98,9 +103,10 @@ stmnt.setDouble(p, value); } } + return this; } - public void setNull(String key, int sqlType) + public Instance setNull(String key, int sqlType) throws SQLException { List pos = positions.get(key.toLowerCase()); @@ -109,16 +115,19 @@ stmnt.setNull(p, sqlType); } } + return this; } - public void set(Map map) throws SQLException { + public Instance set(Map map) throws SQLException { for (Map.Entry entry: map.entrySet()) { setObject(entry.getKey(), entry.getValue()); } + return this; } - public void clearParameters() throws SQLException { + public Instance clearParameters() throws SQLException { stmnt.clearParameters(); + return this; } public boolean execute() throws SQLException { diff -r dbd0b3b1b8b8 -r 039413d7e394 flys-aft/src/main/resources/sql/aft-common.properties --- a/flys-aft/src/main/resources/sql/aft-common.properties Wed Dec 14 17:53:15 2011 +0000 +++ b/flys-aft/src/main/resources/sql/aft-common.properties Fri Dec 16 11:26:12 2011 +0000 @@ -1,2 +1,3 @@ select.gewaesser = SELECT GEWAESSER_NR, NAME FROM SL_GEWAESSER +select.messstelle = SELECT NAME, MESSSTELLE_NR FROM MESSSTELLE WHERE GEWAESSER_NR = :GEWAESSER_NR diff -r dbd0b3b1b8b8 -r 039413d7e394 flys-aft/src/main/resources/sql/flys-common.properties --- a/flys-aft/src/main/resources/sql/flys-common.properties Wed Dec 14 17:53:15 2011 +0000 +++ b/flys-aft/src/main/resources/sql/flys-common.properties Fri Dec 16 11:26:12 2011 +0000 @@ -1,1 +1,2 @@ select.river = SELECT id, name FROM rivers +select.gauges = SELECT id, name FROM gauges WHERE river_id = :river_id