--- dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Database.java 2014/12/10 08:26:12 2240 +++ dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Database.java 2014/12/15 11:13:48 2248 @@ -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 { @@ -174,7 +191,7 @@ stmt.setDouble(2, bbox.latitudeMax); stmt.setDouble(3, bbox.longitudeMin); stmt.setDouble(4, bbox.longitudeMax); - stmt.setString(5, Lookup.distributor); + stmt.setString(5, LookupMain.distributor); List list = hentAdresseListe( stmt ); return list.toArray( new Adresse[ list.size() ] ); @@ -196,7 +213,7 @@ PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); - stmt.setString(1, Lookup.distributor); + stmt.setString(1, LookupMain.distributor); List list = hentAdresseListe( stmt ); return list.toArray( new Adresse[ list.size() ] );