/[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 2203 by torben, Thu Sep 11 14:46:59 2014 UTC revision 2220 by torben, Mon Sep 15 10:37:25 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 122  public class Database { Line 124  public class Database {
124                  return list;                  return list;
125          }          }
126    
127          public ArrayList<Adresse> hentDaekkedeAdresser( BoundingBox bbox) throws SQLException {          public Adresse[] hentDaekkedeAdresser( BoundingBox bbox) throws SQLException {
128                  String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute " +                  String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute " +
129                                  "FROM fulddaekning.adressetabel " +                                  "FROM fulddaekning.adressetabel " +
130                                  "WHERE rute IS NOT NULL " +                                  "WHERE rute IS NOT NULL " +
# Line 142  public class Database { Line 144  public class Database {
144                  stmt.setDouble(4, bbox.longitudeMax);                  stmt.setDouble(4, bbox.longitudeMax);
145                  stmt.setString(5, Lookup.distributor);                  stmt.setString(5, Lookup.distributor);
146    
147                  return hentAdresseListe( stmt );                  List<Adresse> list = hentAdresseListe( stmt );
148                    return list.toArray( new Adresse[ list.size() ] );
149    
150          }          }
151    
# Line 176  public class Database { Line 179  public class Database {
179    
180                  saveStmt.setDouble(19, bedsteAfstand);                  saveStmt.setDouble(19, bedsteAfstand);
181    
182                  saveStmt.executeUpdate();                        saveStmt.addBatch();
183                  saveStmt.clearParameters();                  batchCount++;
184                    if (batchCount >= 100) {
185                            saveStmt.executeBatch();
186                            batchCount = 0;
187                    }
188                    //saveStmt.executeUpdate();    
189                    //saveStmt.clearParameters();
190    
191                  //saveStmt.close();                      //saveStmt.close();    
192            }
193            
194            public synchronized void saveBatch() throws SQLException{
195                    saveStmt.executeBatch();
196                    batchCount = 0;
197          }          }
198    
199    
200    
201          protected ArrayList<Adresse> hentAdresseListe(PreparedStatement stmt) throws SQLException{          protected ArrayList<Adresse> hentAdresseListe(PreparedStatement stmt) throws SQLException{
202                  ArrayList<Adresse> list = new ArrayList<Adresse>( 30000 );                  ArrayList<Adresse> list = new ArrayList<Adresse>( 1000000 );
203    
204                  //logger.info("Starting query");                  //logger.info("Starting query");
205                  ResultSet res = stmt.executeQuery();                  ResultSet res = stmt.executeQuery();
# Line 230  public class Database { Line 242  public class Database {
242              connectionProps.put("user", db_user);              connectionProps.put("user", db_user);
243              connectionProps.put("password", db_pass);              connectionProps.put("password", db_pass);
244    
245                //For debug output, tilføj denne til JDBC url'en: &profileSQL=true    
246              conn = DriverManager.getConnection(              conn = DriverManager.getConnection(
247                             "jdbc:mysql://" +                             "jdbc:mysql://" +
248                             db_host +                             db_host +
249                             ":3306/",                             ":3306/?rewriteBatchedStatements=true",
250                             connectionProps);                             connectionProps);
251              logger.info("Connected to database");              logger.info("Connected to database");
252              return conn;              return conn;

Legend:
Removed from v.2203  
changed lines
  Added in v.2220

  ViewVC Help
Powered by ViewVC 1.1.20