/[projects]/dao/FuldDaekningWorker/src/main/java/dk/daoas/fulddaekning/Database.java
ViewVC logotype

Diff of /dao/FuldDaekningWorker/src/main/java/dk/daoas/fulddaekning/Database.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2241 by torben, Wed Dec 10 09:50:33 2014 UTC revision 2261 by torben, Mon Feb 9 14:39:37 2015 UTC
# Line 7  import java.sql.PreparedStatement; Line 7  import java.sql.PreparedStatement;
7  import java.sql.ResultSet;  import java.sql.ResultSet;
8  import java.sql.SQLException;  import java.sql.SQLException;
9  import java.util.ArrayList;  import java.util.ArrayList;
10    import java.util.HashMap;
11  import java.util.List;  import java.util.List;
12  import java.util.Properties;  import java.util.Properties;
13  import java.util.Queue;  import java.util.Queue;
# Line 22  public class Database { Line 23  public class Database {
23    
24          Connection conn;          Connection conn;
25          PreparedStatement saveStmt;          PreparedStatement saveStmt;
26            
27            private HashMap<String,BoundingBox> bbCache = new HashMap<String,BoundingBox>();
28    
29          public Database(SafeProperties conf)  throws SQLException,IOException {          public Database(SafeProperties conf)  throws SQLException,IOException {
30                  this.conn = getConnection( conf );                        this.conn = getConnection( conf );      
# Line 56  public class Database { Line 59  public class Database {
59    
60                  logger.info("Executing: " + sql);                  logger.info("Executing: " + sql);
61                  conn.createStatement().executeUpdate(sql);                                conn.createStatement().executeUpdate(sql);              
62          }                }
63            
64          public BoundingBox getBoundingbox(String postnr) throws SQLException {          public BoundingBox getBoundingbox(String postnr) throws SQLException {
65                    BoundingBox bb = bbCache.get(postnr);
66                    if ( bb == null ) {
67                            bb = getBoundingboxFromDb(postnr);
68                            bbCache.put(postnr, bb);
69                    } else {
70                            logger.info("Serving BB from cache");
71                    }
72                    
73                    return bb.clone();//never return the original / cached object
74            }
75    
76            private BoundingBox getBoundingboxFromDb(String postnr) throws SQLException {
77                  String minPostnr = postnr.replace('x', '0');                  String minPostnr = postnr.replace('x', '0');
78                  String maxPostnr = postnr.replace('x', '9');                  String maxPostnr = postnr.replace('x', '9');
79    
# Line 84  public class Database { Line 99  public class Database {
99    
100                  return bbox;                  return bbox;
101          }          }
102            
103            
104    
105          public Queue<Adresse> hentIkkedaekkedeAdresser(String postnr)  throws SQLException {          public Queue<Adresse> hentIkkedaekkedeAdresser(String postnr)  throws SQLException {
106                                    
# Line 261  public class Database { Line 278  public class Database {
278    
279                  while (res.next()) {                  while (res.next()) {
280                          Adresse adr = new Adresse();                          Adresse adr = new Adresse();
281    
282                            /*
283                          adr.id = res.getInt("id");                          adr.id = res.getInt("id");
284                          adr.postnr = res.getInt("postnr");                          adr.postnr = res.getInt("postnr");
285                          adr.adresse = res.getString("adresse");                          adr.adresse = res.getString("adresse");
# Line 271  public class Database { Line 290  public class Database {
290                          adr.longitude = res.getDouble("longitude");                          adr.longitude = res.getDouble("longitude");
291                          adr.rute = res.getString("rute");                          adr.rute = res.getString("rute");
292                          adr.ho = res.getInt("ho");                          adr.ho = res.getInt("ho");
293                            */
294            
295                            adr.id = res.getInt(1);
296                            adr.postnr = res.getInt(2);
297                            adr.adresse = res.getString(3);
298                            adr.gadeid = res.getInt(4);
299                            adr.husnr = res.getInt(5);
300                            adr.husnrbogstav = res.getString(6);
301                            adr.latitude = res.getDouble(7);
302                            adr.longitude = res.getDouble(8);
303                            adr.rute = res.getString(9);
304                            adr.ho = res.getInt(10);
305    
306                          list.add(adr);                          list.add(adr);
307    

Legend:
Removed from v.2241  
changed lines
  Added in v.2261

  ViewVC Help
Powered by ViewVC 1.1.20