21 |
Connection conn; |
Connection conn; |
22 |
PreparedStatement saveStmt; |
PreparedStatement saveStmt; |
23 |
|
|
24 |
public Database(Properties conf) throws SQLException,IOException { |
public Database(SafeProperties conf) throws SQLException,IOException { |
25 |
this.conn = getConnection( conf ); |
this.conn = getConnection( conf ); |
26 |
|
|
27 |
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_ny (orgId,orgPostnr, orgAdresse,orgGadeid,orgHusnr,orgHusnrBogstav,orgLatitude,orgLongitude,orgRute,id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,afstand,`timestamp`) "+ |
28 |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
29 |
|
|
30 |
saveStmt = conn.prepareStatement(sql); |
saveStmt = conn.prepareStatement(sql); |
32 |
} |
} |
33 |
|
|
34 |
public void resetResultTable() throws SQLException { |
public void resetResultTable() throws SQLException { |
35 |
logger.info("Truncating result table"); |
logger.info("Dropping old result table (if exists)"); |
36 |
String sql = "TRUNCATE TABLE fulddaekning.afstand_anden_rute_thn"; |
String sql = "DROP TABLE IF EXISTS fulddaekning.afstand_anden_rute_ny"; |
37 |
conn.createStatement().executeUpdate(sql); |
conn.createStatement().executeUpdate(sql); |
38 |
|
|
39 |
|
logger.info("Create new result table"); |
40 |
|
sql = "CREATE TABLE fulddaekning.afstand_anden_rute_ny LIKE fulddaekning.afstand_anden_rute"; |
41 |
|
conn.createStatement().executeUpdate(sql); |
42 |
|
} |
43 |
|
|
44 |
|
public void renameResultTables() throws SQLException { |
45 |
|
logger.info("Dropping old backup table (if exists)"); |
46 |
|
String sql = "DROP TABLE IF EXISTS fulddaekning.afstand_anden_rute_old"; |
47 |
|
conn.createStatement().executeUpdate(sql); |
48 |
|
|
49 |
|
logger.info("Rename tables"); |
50 |
|
sql = "RENAME TABLE fulddaekning.afstand_anden_rute TO fulddaekning.afstand_anden_rute_old, fulddaekning.afstand_anden_rute_ny TO fulddaekning.afstand_anden_rute"; |
51 |
|
conn.createStatement().executeUpdate(sql); |
52 |
} |
} |
53 |
|
|
54 |
public BoundingBox getBoundingbox(int postnr) throws SQLException { |
public BoundingBox getBoundingbox(int postnr) throws SQLException { |
203 |
return list; |
return list; |
204 |
} |
} |
205 |
|
|
206 |
public Connection getConnection(Properties conf) throws SQLException, IOException { |
public Connection getConnection(SafeProperties conf) throws SQLException, IOException { |
207 |
|
|
208 |
String db_host = conf.getProperty("DB_HOST"); |
String db_host = conf.getSafeProperty("DB_HOST"); |
209 |
String db_user = conf.getProperty("DB_USER"); |
String db_user = conf.getSafeProperty("DB_USER"); |
210 |
String db_pass = conf.getProperty("DB_PASS"); |
String db_pass = conf.getSafeProperty("DB_PASS"); |
211 |
|
|
212 |
|
|
213 |
|
|