/[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 2145 by torben, Wed Apr 30 08:15:48 2014 UTC revision 2149 by torben, Wed Apr 30 14:18:43 2014 UTC
# Line 1  Line 1 
1  package dk.daoas.fulddaekning;  package dk.daoas.fulddaekning;
2    
3    import java.io.IOException;
4  import java.sql.Connection;  import java.sql.Connection;
5    import java.sql.DriverManager;
6  import java.sql.PreparedStatement;  import java.sql.PreparedStatement;
7  import java.sql.ResultSet;  import java.sql.ResultSet;
8  import java.sql.SQLException;  import java.sql.SQLException;
9  import java.util.ArrayList;  import java.util.ArrayList;
10  import java.util.List;  import java.util.List;
11    import java.util.Properties;
12  import java.util.Queue;  import java.util.Queue;
13  import java.util.concurrent.ConcurrentLinkedQueue;  import java.util.concurrent.ConcurrentLinkedQueue;
14  import java.util.logging.Logger;  import java.util.logging.Logger;
# Line 16  public class Database { Line 19  public class Database {
19                    
20                    
21          Connection conn;          Connection conn;
22            Connection writeConn;
23            
24          PreparedStatement saveStmt;          PreparedStatement saveStmt;
25    
26          public Database(Connection conn)  throws SQLException {          public Database(Properties conf)  throws SQLException,IOException {
27                  this.conn = conn;                                                conn = getConnection(conf);
28                    conn.setReadOnly(true);
29                    
30                    writeConn = getConnection(conf);
31                    
32                                    
33                  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`) "+
34                  "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )";                  "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )";
35    
36                  saveStmt = conn.prepareStatement(sql);                            saveStmt = writeConn.prepareStatement(sql);            
37                    
38            }
39            
40            public void resetResultTable() throws SQLException {
41                    logger.info("Truncating result table");
42                    String sql = "TRUNCATE TABLE fulddaekning.afstand_anden_rute_thn";
43                    writeConn.createStatement().executeUpdate(sql);
44                    
45            }
46            
47            public Connection getConnection(Properties conf) throws SQLException, IOException {
48                    
49                    String db_host = conf.getProperty("DB_HOST");
50                    String db_user = conf.getProperty("DB_USER");
51                    String db_pass = conf.getProperty("DB_PASS");
52    
53                                    
54                    
55    
56                Connection conn = null;
57                Properties connectionProps = new Properties();
58                connectionProps.put("user", db_user);
59                connectionProps.put("password", db_pass);
60    
61                    conn = DriverManager.getConnection(
62                               "jdbc:mysql://" +
63                               db_host +
64                               ":3306/",
65                               connectionProps);
66                logger.info("Connected to database");
67                return conn;
68          }          }
69                    
70          public BoundingBox getBoundingbox(int postnr) throws SQLException {          public BoundingBox getBoundingbox(int postnr) throws SQLException {

Legend:
Removed from v.2145  
changed lines
  Added in v.2149

  ViewVC Help
Powered by ViewVC 1.1.20