comparison flys-aft/src/main/java/de/intevation/aft/Rivers.java @ 4075:dbd0b3b1b8b8

Sync each river. flys-aft/trunk@3419 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 14 Dec 2011 17:53:15 +0000
parents 2c70fae83d0c
children 97de7a552b79
comparison
equal deleted inserted replaced
4074:100c4e0a45e1 4075:dbd0b3b1b8b8
1 package de.intevation.aft; 1 package de.intevation.aft;
2 2
3 import java.util.Map;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.ArrayList;
7
8
3 import java.sql.SQLException; 9 import java.sql.SQLException;
10 import java.sql.ResultSet;
4 11
5 import de.intevation.db.ConnectionBuilder; 12 import de.intevation.db.ConnectedStatements;
13
14 import org.apache.log4j.Logger;
6 15
7 public class Rivers 16 public class Rivers
8 { 17 {
9 protected ConnectionBuilder aftConnectionBuilder; 18 private static Logger log = Logger.getLogger(Rivers.class);
10 protected ConnectionBuilder flysConnectionBuilder;
11 19
12 public Rivers( 20 public Rivers() {
13 ConnectionBuilder aftConnectionBuilder,
14 ConnectionBuilder flysConnectionBuilder
15 ) {
16 this.aftConnectionBuilder = aftConnectionBuilder;
17 this.flysConnectionBuilder = flysConnectionBuilder;
18 } 21 }
19 22
20 public void sync() throws SQLException { 23 public void sync(
21 } 24 ConnectedStatements aftStatements,
25 ConnectedStatements flysStatements
26 )
27 throws SQLException
28 {
29 log.info("sync: rivers");
22 30
23 public void close() { 31 Map<String, Integer> flysRivers = new HashMap<String, Integer>();
32
33 ResultSet flysRs = flysStatements
34 .getStatement("select.river").executeQuery();
35
36 while (flysRs.next()) {
37 Integer id = flysRs.getInt("id");
38 String name = flysRs.getString("name").toLowerCase();
39 flysRivers.put(name, id);
40 }
41
42 flysRs.close();
43
44 List<River> commonRivers = new ArrayList<River>();
45
46 ResultSet aftRs = aftStatements
47 .getStatement("select.gewaesser").executeQuery();
48
49 while (aftRs.next()) {
50 String name = aftRs.getString("NAME");
51 Integer id1 = flysRivers.get(name.toLowerCase());
52 if (id1 != null) {
53 int id2 = aftRs.getInt("GEWAESSER_NR");
54 River river = new River(id1, id2, name);
55 System.err.println(river);
56 commonRivers.add(river);
57 }
58 }
59
60 aftRs.close();
61
62 for (River river: commonRivers) {
63 river.sync(aftStatements, flysStatements);
64 }
24 } 65 }
25 } 66 }
26 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 67 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
27

http://dive4elements.wald.intevation.org