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; |
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 ); |
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 |
|
|
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 |
|
|
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"); |
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 |
|
|