Mercurial > dive4elements > river
comparison etl/src/main/java/org/dive4elements/river/etl/aft/Rivers.java @ 6903:b3e2abe359d8
ETL: Take care of the fact that one river in AFT/SGM may correspond to N rivers in FLYS.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 22 Aug 2013 15:31:09 +0200 |
parents | 6f80d5f375fd |
children | 5fe8c64b48d4 |
comparison
equal
deleted
inserted
replaced
6902:143063f07405 | 6903:b3e2abe359d8 |
---|---|
12 | 12 |
13 import java.sql.ResultSet; | 13 import java.sql.ResultSet; |
14 import java.sql.SQLException; | 14 import java.sql.SQLException; |
15 | 15 |
16 import java.util.ArrayList; | 16 import java.util.ArrayList; |
17 import java.util.HashMap; | |
18 import java.util.List; | 17 import java.util.List; |
19 import java.util.Map; | |
20 | 18 |
21 import org.apache.log4j.Logger; | 19 import org.apache.log4j.Logger; |
22 | 20 |
23 public class Rivers | 21 public class Rivers |
24 { | 22 { |
25 private static Logger log = Logger.getLogger(Rivers.class); | 23 private static Logger log = Logger.getLogger(Rivers.class); |
26 | 24 |
27 public Rivers() { | 25 public Rivers() { |
28 } | 26 } |
29 | 27 |
28 private static List<River> findFLYSRivers( | |
29 List<River> flysRivers, | |
30 String needle | |
31 ) { | |
32 List<River> rivers = new ArrayList<River>(); | |
33 | |
34 needle = needle.toLowerCase(); | |
35 | |
36 for (River river: rivers) { | |
37 String name = river.getName().toLowerCase(); | |
38 if (name.contains(needle)) { | |
39 rivers.add(river); | |
40 } | |
41 } | |
42 | |
43 return rivers; | |
44 } | |
45 | |
30 public boolean sync(SyncContext context) throws SQLException { | 46 public boolean sync(SyncContext context) throws SQLException { |
31 | 47 |
32 log.info("sync: rivers"); | 48 log.info("sync: rivers"); |
33 | 49 |
34 ConnectedStatements flysStatements = context.getFlysStatements(); | 50 ConnectedStatements flysStatements = context.getFlysStatements(); |
35 ConnectedStatements aftStatements = context.getAftStatements(); | 51 ConnectedStatements aftStatements = context.getAftStatements(); |
36 | 52 |
37 Map<String, River> flysRivers = new HashMap<String, River>(); | 53 List<River> flysRivers = new ArrayList<River>(); |
38 | 54 |
39 ResultSet flysRs = flysStatements | 55 ResultSet flysRs = flysStatements |
40 .getStatement("select.rivers").executeQuery(); | 56 .getStatement("select.rivers").executeQuery(); |
41 | 57 |
42 try { | 58 try { |
43 while (flysRs.next()) { | 59 while (flysRs.next()) { |
44 int id = flysRs.getInt("id"); | 60 int id = flysRs.getInt("id"); |
45 String name = flysRs.getString("name"); | 61 String name = flysRs.getString("name"); |
46 double from = flysRs.getDouble("min_km"); | 62 double from = flysRs.getDouble("min_km"); |
47 double to = flysRs.getDouble("max_km"); | 63 double to = flysRs.getDouble("max_km"); |
48 flysRivers.put(name.toLowerCase(), new River(id, name, from, to)); | 64 flysRivers.add(new River(id, name, from, to)); |
49 } | 65 } |
50 } | 66 } |
51 finally { | 67 finally { |
52 flysRs.close(); | 68 flysRs.close(); |
53 } | 69 } |
58 .getStatement("select.gewaesser").executeQuery(); | 74 .getStatement("select.gewaesser").executeQuery(); |
59 | 75 |
60 try { | 76 try { |
61 while (aftRs.next()) { | 77 while (aftRs.next()) { |
62 String name = aftRs.getString("NAME"); | 78 String name = aftRs.getString("NAME"); |
63 River river = flysRivers.get(name.toLowerCase()); | 79 int id2 = aftRs.getInt("GEWAESSER_NR"); |
64 if (river != null) { | 80 for (River river: findFLYSRivers(flysRivers, name)) { |
65 int id2 = aftRs.getInt("GEWAESSER_NR"); | |
66 river.setId2(id2); | 81 river.setId2(id2); |
67 commonRivers.add(river); | 82 commonRivers.add(river); |
68 } | 83 } |
69 } | 84 } |
70 } | 85 } |
71 finally { | 86 finally { |
72 aftRs.close(); | 87 aftRs.close(); |
73 } | 88 } |
74 | |
75 | 89 |
76 boolean modified = false; | 90 boolean modified = false; |
77 | 91 |
78 for (River river: commonRivers) { | 92 for (River river: commonRivers) { |
79 modified |= river.sync(context); | 93 modified |= river.sync(context); |