Mercurial > dive4elements > river
diff flys-aft/src/main/java/de/intevation/aft/DischargeTable.java @ 4102:e8967ee1cb05
Fixed logic bug when writing discharge tables of an gauge existing in both dbs.
flys-aft/trunk@3631 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 09 Jan 2012 16:43:14 +0000 |
parents | b6a18d706cbe |
children | 2305731f563c |
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java Mon Jan 09 15:34:19 2012 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java Mon Jan 09 16:43:14 2012 +0000 @@ -6,6 +6,7 @@ import java.sql.SQLException; import java.sql.ResultSet; +import java.sql.Types; import de.intevation.db.SymbolicStatement; import de.intevation.db.ConnectedStatements; @@ -248,5 +249,56 @@ return dts; } + + public void persistFlysTimeInterval( + SyncContext context + ) + throws SQLException + { + if (timeInterval != null) { + timeInterval = context.fetchOrCreateFLYSTimeInterval( + timeInterval); + } + } + + public int persistFlysDischargeTable( + SyncContext context, + int gaugeId + ) + throws SQLException + { + ConnectedStatements flysStatements = + context.getFlysStatements(); + + ResultSet rs = flysStatements + .getStatement("next.discharge.id") + .executeQuery(); + + rs.next(); + int flysId = rs.getInt("discharge_table_id"); + rs.close(); + + SymbolicStatement.Instance insertDT = flysStatements + .getStatement("insert.dischargetable") + .clearParameters() + .setInt("id", flysId) + .setInt("gauge_id", gaugeId) + .setString("description", description); + + if (timeInterval != null) { + insertDT.setInt("time_interval_id", timeInterval.getId()); + } + else { + insertDT.setNull("time_interval_id", Types.INTEGER); + } + + insertDT.execute(); + + if (log.isDebugEnabled()) { + log.debug("FLYS: Created discharge table id: " + id); + } + + return flysId; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :