Mercurial > dive4elements > river
comparison flys-aft/src/main/java/org/dive4elements/etl/aft/Rivers.java @ 5824:06643e440d1e
Moved directories to org.dive4elements.etl
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 11:35:06 +0200 |
parents | flys-aft/src/main/java/de/intevation/aft/Rivers.java@f939e1e6cfa4 |
children |
comparison
equal
deleted
inserted
replaced
5823:52e966cc7d35 | 5824:06643e440d1e |
---|---|
1 package de.intevation.aft; | |
2 | |
3 import de.intevation.db.ConnectedStatements; | |
4 | |
5 import java.sql.ResultSet; | |
6 import java.sql.SQLException; | |
7 | |
8 import java.util.ArrayList; | |
9 import java.util.HashMap; | |
10 import java.util.List; | |
11 import java.util.Map; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 | |
15 public class Rivers | |
16 { | |
17 private static Logger log = Logger.getLogger(Rivers.class); | |
18 | |
19 public Rivers() { | |
20 } | |
21 | |
22 public boolean sync(SyncContext context) throws SQLException { | |
23 | |
24 log.info("sync: rivers"); | |
25 | |
26 ConnectedStatements flysStatements = context.getFlysStatements(); | |
27 ConnectedStatements aftStatements = context.getAftStatements(); | |
28 | |
29 Map<String, River> flysRivers = new HashMap<String, River>(); | |
30 | |
31 ResultSet flysRs = flysStatements | |
32 .getStatement("select.rivers").executeQuery(); | |
33 | |
34 try { | |
35 while (flysRs.next()) { | |
36 int id = flysRs.getInt("id"); | |
37 String name = flysRs.getString("name"); | |
38 double from = flysRs.getDouble("min_km"); | |
39 double to = flysRs.getDouble("max_km"); | |
40 flysRivers.put(name.toLowerCase(), new River(id, name, from, to)); | |
41 } | |
42 } | |
43 finally { | |
44 flysRs.close(); | |
45 } | |
46 | |
47 List<River> commonRivers = new ArrayList<River>(); | |
48 | |
49 ResultSet aftRs = aftStatements | |
50 .getStatement("select.gewaesser").executeQuery(); | |
51 | |
52 try { | |
53 while (aftRs.next()) { | |
54 String name = aftRs.getString("NAME"); | |
55 River river = flysRivers.get(name.toLowerCase()); | |
56 if (river != null) { | |
57 int id2 = aftRs.getInt("GEWAESSER_NR"); | |
58 river.setId2(id2); | |
59 commonRivers.add(river); | |
60 } | |
61 } | |
62 } | |
63 finally { | |
64 aftRs.close(); | |
65 } | |
66 | |
67 | |
68 boolean modified = false; | |
69 | |
70 for (River river: commonRivers) { | |
71 modified |= river.sync(context); | |
72 } | |
73 | |
74 return modified; | |
75 } | |
76 } | |
77 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |