/[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 2218 by torben, Fri Sep 12 15:23:06 2014 UTC revision 2225 by torben, Sat Sep 20 11:28:20 2014 UTC
# Line 14  import java.util.concurrent.ConcurrentLi Line 14  import java.util.concurrent.ConcurrentLi
14  import java.util.logging.Logger;  import java.util.logging.Logger;
15    
16    
17    
18  public class Database {  public class Database {
19          Logger logger = Logger.getLogger(Database.class.getName());          Logger logger = Logger.getLogger(Database.class.getName());
20    
21            int batchCount = 0;
22    
23          Connection conn;          Connection conn;
24          PreparedStatement saveStmt;          PreparedStatement saveStmt;
# Line 42  public class Database { Line 44  public class Database {
44          }                }      
45                    
46          public void renameResultTables() throws SQLException {          public void renameResultTables() throws SQLException {
47                    Constants consts = Constants.getInstance();
48                    String ext = consts.getTableExtension();
49                    
50                  logger.info("Dropping old backup table (if exists)");                  logger.info("Dropping old backup table (if exists)");
51                  String sql = "DROP TABLE IF EXISTS fulddaekning.afstand_anden_rute_old";                  String sql = "DROP TABLE IF EXISTS fulddaekning.afstand_anden_rute_old" + ext;
52                  conn.createStatement().executeUpdate(sql);                  conn.createStatement().executeUpdate(sql);
53                                    
54                  logger.info("Rename tables");                  logger.info("Rename tables");
55                  sql = "RENAME TABLE fulddaekning.afstand_anden_rute TO fulddaekning.afstand_anden_rute_old, fulddaekning.afstand_anden_rute_ny TO fulddaekning.afstand_anden_rute";                  sql = "RENAME TABLE fulddaekning.afstand_anden_rute" + ext + " TO fulddaekning.afstand_anden_rute_old" + ext + ", fulddaekning.afstand_anden_rute_ny TO fulddaekning.afstand_anden_rute" + ext;
56                  conn.createStatement().executeUpdate(sql);                                conn.createStatement().executeUpdate(sql);              
57          }                }      
58    
# Line 144  public class Database { Line 149  public class Database {
149    
150                  List<Adresse> list = hentAdresseListe( stmt );                  List<Adresse> list = hentAdresseListe( stmt );
151                  return list.toArray( new Adresse[ list.size() ] );                  return list.toArray( new Adresse[ list.size() ] );
   
152          }          }
153            
154            
155            public Adresse[] hentAlleDaekkedeAdresser() throws SQLException {
156                    String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute " +
157                                    "FROM fulddaekning.adressetabel " +
158                                    "WHERE rute IS NOT NULL " +
159                                    "AND latitude IS NOT NULL" +
160                                    "AND longitude IS NOT NULL " +
161                                    "AND distributor = ? ";
162    
163                    // Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets)
164                    // Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html
165                    //PreparedStatement stmt = conn.prepareStatement(sql);
166                    PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
167                    stmt.setFetchSize(Integer.MIN_VALUE);
168    
169                    stmt.setString(1, Lookup.distributor);
170    
171                    List<Adresse> list = hentAdresseListe( stmt );
172                    return list.toArray( new Adresse[ list.size() ] );
173            }
174            
175            
176    
177          public synchronized void gemResultat(Adresse orgAdresse, Adresse bedsteAdresse, double bedsteAfstand) throws SQLException {          public synchronized void gemResultat(Adresse orgAdresse, Adresse bedsteAdresse, double bedsteAfstand) throws SQLException {
178                  /*String sql = "INSERT INTO fulddaekning.afstand_anden_rute_thn (orgId,orgPostnr, orgAdresse,orgGadeid,orgHusnr,orgHusnrBogstav,orgLatitude,orgLongitude,orgRute,id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,afstand,`timestamp`) "+                  /*String sql = "INSERT INTO fulddaekning.afstand_anden_rute_thn (orgId,orgPostnr, orgAdresse,orgGadeid,orgHusnr,orgHusnrBogstav,orgLatitude,orgLongitude,orgRute,id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,afstand,`timestamp`) "+
# Line 177  public class Database { Line 203  public class Database {
203    
204                  saveStmt.setDouble(19, bedsteAfstand);                  saveStmt.setDouble(19, bedsteAfstand);
205    
206                  saveStmt.executeUpdate();                        saveStmt.addBatch();
207                  saveStmt.clearParameters();                  batchCount++;
208                    if (batchCount >= 100) {
209                            saveStmt.executeBatch();
210                            batchCount = 0;
211                    }
212                    //saveStmt.executeUpdate();    
213                    //saveStmt.clearParameters();
214    
215                  //saveStmt.close();                      //saveStmt.close();    
216            }
217            
218            public synchronized void saveBatch() throws SQLException{
219                    saveStmt.executeBatch();
220                    batchCount = 0;
221          }          }
222    
223    
# Line 231  public class Database { Line 266  public class Database {
266              connectionProps.put("user", db_user);              connectionProps.put("user", db_user);
267              connectionProps.put("password", db_pass);              connectionProps.put("password", db_pass);
268    
269                //For debug output, tilføj denne til JDBC url'en: &profileSQL=true    
270              conn = DriverManager.getConnection(              conn = DriverManager.getConnection(
271                             "jdbc:mysql://" +                             "jdbc:mysql://" +
272                             db_host +                             db_host +

Legend:
Removed from v.2218  
changed lines
  Added in v.2225

  ViewVC Help
Powered by ViewVC 1.1.20