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 |
|
} |
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 |
|
|
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 |
|
|