/[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 2200 by torben, Thu Sep 11 08:14:40 2014 UTC revision 2219 by torben, Fri Sep 12 21:03:06 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 94  public class Database { Line 96  public class Database {
96    
97          public List<Integer> hentPostnumre() throws SQLException {          public List<Integer> hentPostnumre() throws SQLException {
98                  ArrayList<Integer> list = new ArrayList<Integer>();                  ArrayList<Integer> list = new ArrayList<Integer>();
99                    
100                    Constants consts = Constants.getInstance();
101    
102    
103                  String sql = "SELECT postnr " +                  String sql = "SELECT postnr " +
104                                           "FROM fulddaekning.adressetabel " +                                           "FROM fulddaekning.adressetabel " +
105                                           "WHERE distributor = ? and rute is not null " +                                           //"WHERE distributor = ? and rute is not null " +
106                                             "WHERE postnr BETWEEN ? AND ? " +
107                                           "GROUP BY postnr " +                                           "GROUP BY postnr " +
108                                           "ORDER by postnr";                                           "ORDER by postnr";
109                  PreparedStatement stmt = conn.prepareStatement(sql);                  PreparedStatement stmt = conn.prepareStatement(sql);
110                  stmt.setString(1, Lookup.distributor );                  //stmt.setString(1, Lookup.distributor );
111                    stmt.setInt(1, consts.getMinPostnr());
112                    stmt.setInt(2, consts.getMaxPostnr());
113                  ResultSet res = stmt.executeQuery();                  ResultSet res = stmt.executeQuery();
114    
115                  while (res.next()) {                  while (res.next()) {
# Line 117  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 137  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 171  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 225  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    
246                
247              conn = DriverManager.getConnection(              conn = DriverManager.getConnection(
248                             "jdbc:mysql://" +                             "jdbc:mysql://" +
249                             db_host +                             db_host +
250                             ":3306/",                             ":3306/?rewriteBatchedStatements=true",
251                             connectionProps);                             connectionProps);
252              logger.info("Connected to database");              logger.info("Connected to database");
253              return conn;              return conn;

Legend:
Removed from v.2200  
changed lines
  Added in v.2219

  ViewVC Help
Powered by ViewVC 1.1.20