sascha@4073: package de.intevation.aft; sascha@4073: sascha@4075: import java.util.Map; sascha@4075: import java.util.HashMap; sascha@4075: import java.util.List; sascha@4075: import java.util.ArrayList; sascha@4075: sascha@4075: sascha@4073: import java.sql.SQLException; sascha@4075: import java.sql.ResultSet; sascha@4073: sascha@4075: import de.intevation.db.ConnectedStatements; sascha@4075: sascha@4075: import org.apache.log4j.Logger; sascha@4073: sascha@4073: public class Rivers sascha@4073: { sascha@4075: private static Logger log = Logger.getLogger(Rivers.class); sascha@4073: sascha@4075: public Rivers() { sascha@4073: } sascha@4073: sascha@4094: public boolean sync(SyncContext context) throws SQLException { sascha@4077: sascha@4075: log.info("sync: rivers"); sascha@4073: sascha@4077: ConnectedStatements flysStatements = context.getFlysStatements(); sascha@4077: ConnectedStatements aftStatements = context.getAftStatements(); sascha@4077: teichmann@4753: Map flysRivers = new HashMap(); sascha@4075: sascha@4075: ResultSet flysRs = flysStatements teichmann@4753: .getStatement("select.rivers").executeQuery(); sascha@4075: teichmann@4753: try { teichmann@4753: while (flysRs.next()) { teichmann@4753: int id = flysRs.getInt("id"); teichmann@4753: String name = flysRs.getString("name"); teichmann@4753: double from = flysRs.getDouble("min_km"); teichmann@4753: double to = flysRs.getDouble("max_km"); teichmann@4753: flysRivers.put(name.toLowerCase(), new River(id, name, from, to)); teichmann@4753: } sascha@4075: } teichmann@4753: finally { teichmann@4753: flysRs.close(); teichmann@4753: } sascha@4075: sascha@4075: List commonRivers = new ArrayList(); sascha@4075: sascha@4075: ResultSet aftRs = aftStatements sascha@4075: .getStatement("select.gewaesser").executeQuery(); sascha@4075: teichmann@4753: try { teichmann@4753: while (aftRs.next()) { teichmann@4753: String name = aftRs.getString("NAME"); teichmann@4753: River river = flysRivers.get(name.toLowerCase()); teichmann@4753: if (river != null) { teichmann@4753: int id2 = aftRs.getInt("GEWAESSER_NR"); teichmann@4753: river.setId2(id2); teichmann@4753: commonRivers.add(river); teichmann@4753: } sascha@4075: } sascha@4075: } teichmann@4753: finally { teichmann@4753: aftRs.close(); teichmann@4753: } sascha@4075: sascha@4075: sascha@4094: boolean modified = false; sascha@4094: sascha@4075: for (River river: commonRivers) { sascha@4094: modified |= river.sync(context); sascha@4075: } sascha@4094: sascha@4094: return modified; sascha@4073: } sascha@4073: } sascha@4073: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :