--- dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Database.java 2014/12/10 09:50:33 2241 +++ dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Database.java 2015/02/09 14:39:37 2261 @@ -7,6 +7,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Properties; import java.util.Queue; @@ -22,6 +23,8 @@ Connection conn; PreparedStatement saveStmt; + + private HashMap bbCache = new HashMap(); public Database(SafeProperties conf) throws SQLException,IOException { this.conn = getConnection( conf ); @@ -56,9 +59,21 @@ logger.info("Executing: " + sql); conn.createStatement().executeUpdate(sql); - } - + } + public BoundingBox getBoundingbox(String postnr) throws SQLException { + BoundingBox bb = bbCache.get(postnr); + if ( bb == null ) { + bb = getBoundingboxFromDb(postnr); + bbCache.put(postnr, bb); + } else { + logger.info("Serving BB from cache"); + } + + return bb.clone();//never return the original / cached object + } + + private BoundingBox getBoundingboxFromDb(String postnr) throws SQLException { String minPostnr = postnr.replace('x', '0'); String maxPostnr = postnr.replace('x', '9'); @@ -84,6 +99,8 @@ return bbox; } + + public Queue hentIkkedaekkedeAdresser(String postnr) throws SQLException { @@ -261,6 +278,8 @@ while (res.next()) { Adresse adr = new Adresse(); + + /* adr.id = res.getInt("id"); adr.postnr = res.getInt("postnr"); adr.adresse = res.getString("adresse"); @@ -271,6 +290,18 @@ adr.longitude = res.getDouble("longitude"); adr.rute = res.getString("rute"); adr.ho = res.getInt("ho"); + */ + + adr.id = res.getInt(1); + adr.postnr = res.getInt(2); + adr.adresse = res.getString(3); + adr.gadeid = res.getInt(4); + adr.husnr = res.getInt(5); + adr.husnrbogstav = res.getString(6); + adr.latitude = res.getDouble(7); + adr.longitude = res.getDouble(8); + adr.rute = res.getString(9); + adr.ho = res.getInt(10); list.add(adr);