view flys-aft/src/main/java/de/intevation/aft/Rivers.java @ 4902:e1566938d04c

Added new functions to datacage templating language. * get minimum of location/distance: dc:fromValue($ld_mode, $ld_locations, $ld_from) - returns -Double.MAX_VALUE if no min exists. * get maximum of location/distance: dc:toValue($ld_mode, $ld_locations, $ld_to) - returns Double.MAX_VALUE if no max exists.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 29 Jan 2013 17:11:26 +0100
parents f939e1e6cfa4
children
line wrap: on
line source
package de.intevation.aft;

import de.intevation.db.ConnectedStatements;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

public class Rivers
{
    private static Logger log = Logger.getLogger(Rivers.class);

    public Rivers() {
    }

    public boolean sync(SyncContext context) throws SQLException {

        log.info("sync: rivers");

        ConnectedStatements flysStatements = context.getFlysStatements();
        ConnectedStatements aftStatements  = context.getAftStatements();

        Map<String, River> flysRivers = new HashMap<String, River>();

        ResultSet flysRs = flysStatements
            .getStatement("select.rivers").executeQuery();

        try {
            while (flysRs.next()) {
                int    id   = flysRs.getInt("id");
                String name = flysRs.getString("name");
                double from = flysRs.getDouble("min_km");
                double to   = flysRs.getDouble("max_km");
                flysRivers.put(name.toLowerCase(), new River(id, name, from, to));
            }
        }
        finally {
            flysRs.close();
        }

        List<River> commonRivers = new ArrayList<River>();

        ResultSet aftRs = aftStatements
            .getStatement("select.gewaesser").executeQuery();

        try {
            while (aftRs.next()) {
                String name = aftRs.getString("NAME");
                River river = flysRivers.get(name.toLowerCase());
                if (river != null) {
                    int id2 = aftRs.getInt("GEWAESSER_NR");
                    river.setId2(id2);
                    commonRivers.add(river);
                }
            }
        }
        finally {
            aftRs.close();
        }


        boolean modified = false;

        for (River river: commonRivers) {
            modified |= river.sync(context);
        }

        return modified;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org