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

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

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

revision 2246 by torben, Wed Dec 10 09:50:33 2014 UTC revision 2247 by torben, Mon Dec 15 11:12:21 2014 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                    }
70                    
71                    return bb.clone();//never return the original / cached object
72            }
73    
74            private BoundingBox getBoundingboxFromDb(String postnr) throws SQLException {
75                  String minPostnr = postnr.replace('x', '0');                  String minPostnr = postnr.replace('x', '0');
76                  String maxPostnr = postnr.replace('x', '9');                  String maxPostnr = postnr.replace('x', '9');
77    
# Line 84  public class Database { Line 97  public class Database {
97    
98                  return bbox;                  return bbox;
99          }          }
100            
101            
102    
103          public Queue<Adresse> hentIkkedaekkedeAdresser(String postnr)  throws SQLException {          public Queue<Adresse> hentIkkedaekkedeAdresser(String postnr)  throws SQLException {
104                                    

Legend:
Removed from v.2246  
changed lines
  Added in v.2247

  ViewVC Help
Powered by ViewVC 1.1.20