/[projects]/dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Database.java
ViewVC logotype

Diff of /dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Database.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2262 by torben, Mon Feb 9 14:39:37 2015 UTC revision 2263 by torben, Tue Feb 10 16:27:15 2015 UTC
# Line 24  public class Database { Line 24  public class Database {
24          Connection conn;          Connection conn;
25          PreparedStatement saveStmt;          PreparedStatement saveStmt;
26                    
27            Adresse alleAdresser[];
28            
29          private HashMap<String,BoundingBox> bbCache = new HashMap<String,BoundingBox>();          private HashMap<String,BoundingBox> bbCache = new HashMap<String,BoundingBox>();
30    
31          public Database(SafeProperties conf)  throws SQLException,IOException {          public Database(SafeProperties conf)  throws SQLException,IOException {
# Line 172  public class Database { Line 174  public class Database {
174                  return list;                  return list;
175          }          }
176    
177            @Deprecated
178          public Adresse[] hentDaekkedeAdresser( BoundingBox bbox) throws SQLException {          public Adresse[] hentDaekkedeAdresser( BoundingBox bbox) throws SQLException {
179                    long start = System.currentTimeMillis();
180                  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 " +
181                                  "FROM fulddaekning.adressetabel a " +                                  "FROM fulddaekning.adressetabel a " +
182                                  "LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " +                                  "LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " +
# Line 194  public class Database { Line 198  public class Database {
198                  stmt.setString(5, LookupMain.distributor);                  stmt.setString(5, LookupMain.distributor);
199    
200                  List<Adresse> list = hentAdresseListe( stmt );                  List<Adresse> list = hentAdresseListe( stmt );
201                    long stop = System.currentTimeMillis();
202                    logger.info("Elapsed DB: " + (stop - start));
203                  return list.toArray( new Adresse[ list.size() ] );                  return list.toArray( new Adresse[ list.size() ] );
204          }          }
205                    
206            public Adresse[] hentDaekkedeAdresserCache( BoundingBox bbox) {
207                    long start = System.currentTimeMillis();
208                    ArrayList<Adresse> list = new ArrayList<Adresse>();
209                    for (Adresse a : alleAdresser) {
210                            if ( a.latitude > bbox.latitudeMin && a.latitude< bbox.latitudeMax && a.longitude> bbox.longitudeMin && a.longitude < bbox.longitudeMax) {
211                                    list.add(a);
212                            }
213                    }
214                    long stop = System.currentTimeMillis();
215                    logger.info("Elapsed cache: " + (stop - start));
216                    return list.toArray( new Adresse[ list.size() ] );              
217            }
218            
219                    
220          public Adresse[] hentAlleDaekkedeAdresser() throws SQLException {          public Adresse[] hentAlleDaekkedeAdresser() throws SQLException {
221                  String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " +                  if ( alleAdresser == null ) {
222                                  "FROM fulddaekning.adressetabel a " +                          String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " +
223                                  "LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " +                                          "FROM fulddaekning.adressetabel a " +
224                                  "WHERE rute IS NOT NULL " +                                          "LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " +
225                                  "AND latitude IS NOT NULL " +                                          "WHERE rute IS NOT NULL " +
226                                  "AND longitude IS NOT NULL " +                                          "AND latitude IS NOT NULL " +
227                                  "AND a.distributor = ? ";                                          "AND longitude IS NOT NULL " +
228                                            "AND a.distributor = ? ";
229                  // Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets)          
230                  // 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)
231                  //PreparedStatement stmt = conn.prepareStatement(sql);                          // Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html
232                  PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);                          //PreparedStatement stmt = conn.prepareStatement(sql);
233                  stmt.setFetchSize(Integer.MIN_VALUE);                          PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
234                            stmt.setFetchSize(Integer.MIN_VALUE);
235                  stmt.setString(1, LookupMain.distributor);          
236                            stmt.setString(1, LookupMain.distributor);
237                  List<Adresse> list = hentAdresseListe( stmt );          
238                  return list.toArray( new Adresse[ list.size() ] );                          List<Adresse> list = hentAdresseListe( stmt );
239                            alleAdresser = list.toArray( new Adresse[ list.size() ] );
240                    }
241                    return alleAdresser;
242          }          }
243                    
244                    

Legend:
Removed from v.2262  
changed lines
  Added in v.2263

  ViewVC Help
Powered by ViewVC 1.1.20