24 |
Connection conn; |
Connection conn; |
25 |
PreparedStatement saveStmt; |
PreparedStatement saveStmt; |
26 |
|
|
27 |
|
Adresse alleAdresser[]; |
28 |
|
|
29 |
|
DeduplicateHelper<String> husnrbogstavCache = new DeduplicateHelper<String>(); |
30 |
|
DeduplicateHelper<String> ruteCache = new DeduplicateHelper<String>(); |
31 |
|
|
32 |
private HashMap<String,BoundingBox> bbCache = new HashMap<String,BoundingBox>(); |
private HashMap<String,BoundingBox> bbCache = new HashMap<String,BoundingBox>(); |
33 |
|
|
34 |
public Database(SafeProperties conf) throws SQLException,IOException { |
public Database(SafeProperties conf) throws SQLException,IOException { |
177 |
return list; |
return list; |
178 |
} |
} |
179 |
|
|
180 |
|
@Deprecated |
181 |
public Adresse[] hentDaekkedeAdresser( BoundingBox bbox) throws SQLException { |
public Adresse[] hentDaekkedeAdresser( BoundingBox bbox) throws SQLException { |
182 |
|
long start = System.currentTimeMillis(); |
183 |
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
184 |
"FROM fulddaekning.adressetabel a " + |
"FROM fulddaekning.adressetabel a " + |
185 |
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
201 |
stmt.setString(5, LookupMain.distributor); |
stmt.setString(5, LookupMain.distributor); |
202 |
|
|
203 |
List<Adresse> list = hentAdresseListe( stmt ); |
List<Adresse> list = hentAdresseListe( stmt ); |
204 |
|
long stop = System.currentTimeMillis(); |
205 |
|
logger.info("Elapsed DB: " + (stop - start)); |
206 |
return list.toArray( new Adresse[ list.size() ] ); |
return list.toArray( new Adresse[ list.size() ] ); |
207 |
} |
} |
208 |
|
|
209 |
|
public Adresse[] hentDaekkedeAdresserCache( BoundingBox bbox) { |
210 |
|
long start = System.currentTimeMillis(); |
211 |
|
ArrayList<Adresse> list = new ArrayList<Adresse>(); |
212 |
|
for (Adresse a : alleAdresser) { |
213 |
|
if ( a.latitude > bbox.latitudeMin && a.latitude< bbox.latitudeMax && a.longitude> bbox.longitudeMin && a.longitude < bbox.longitudeMax) { |
214 |
|
list.add(a); |
215 |
|
} |
216 |
|
} |
217 |
|
long stop = System.currentTimeMillis(); |
218 |
|
logger.info("Elapsed cache: " + (stop - start)); |
219 |
|
return list.toArray( new Adresse[ list.size() ] ); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
public Adresse[] hentAlleDaekkedeAdresser() throws SQLException { |
public Adresse[] hentAlleDaekkedeAdresser() throws SQLException { |
224 |
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
if ( alleAdresser == null ) { |
225 |
"FROM fulddaekning.adressetabel a " + |
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
226 |
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
"FROM fulddaekning.adressetabel a " + |
227 |
"WHERE rute IS NOT NULL " + |
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
228 |
"AND latitude IS NOT NULL " + |
"WHERE rute IS NOT NULL " + |
229 |
"AND longitude IS NOT NULL " + |
"AND latitude IS NOT NULL " + |
230 |
"AND a.distributor = ? "; |
"AND longitude IS NOT NULL " + |
231 |
|
"AND a.distributor = ? "; |
232 |
// Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets) |
|
233 |
// Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html |
// Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets) |
234 |
//PreparedStatement stmt = conn.prepareStatement(sql); |
// Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html |
235 |
PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
//PreparedStatement stmt = conn.prepareStatement(sql); |
236 |
stmt.setFetchSize(Integer.MIN_VALUE); |
PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
237 |
|
stmt.setFetchSize(Integer.MIN_VALUE); |
238 |
stmt.setString(1, LookupMain.distributor); |
|
239 |
|
stmt.setString(1, LookupMain.distributor); |
240 |
List<Adresse> list = hentAdresseListe( stmt ); |
|
241 |
return list.toArray( new Adresse[ list.size() ] ); |
List<Adresse> list = hentAdresseListe( stmt ); |
242 |
|
alleAdresser = list.toArray( new Adresse[ list.size() ] ); |
243 |
|
} |
244 |
|
return alleAdresser; |
245 |
} |
} |
246 |
|
|
247 |
|
|
322 |
adr.adresse = res.getString(3); |
adr.adresse = res.getString(3); |
323 |
adr.gadeid = res.getInt(4); |
adr.gadeid = res.getInt(4); |
324 |
adr.husnr = res.getInt(5); |
adr.husnr = res.getInt(5); |
325 |
adr.husnrbogstav = res.getString(6); |
adr.husnrbogstav = husnrbogstavCache.getInstance( res.getString(6) ); |
326 |
adr.latitude = res.getDouble(7); |
adr.latitude = res.getDouble(7); |
327 |
adr.longitude = res.getDouble(8); |
adr.longitude = res.getDouble(8); |
328 |
adr.rute = res.getString(9); |
adr.rute = ruteCache.getInstance( res.getString(9) ); |
329 |
adr.ho = res.getInt(10); |
adr.ho = res.getInt(10); |
330 |
|
|
331 |
list.add(adr); |
list.add(adr); |