1 |
package dk.daoas.fulddaekning; |
package dk.daoas.fulddaekning; |
2 |
|
|
|
import java.io.IOException; |
|
3 |
import java.sql.Connection; |
import java.sql.Connection; |
|
import java.sql.DriverManager; |
|
4 |
import java.sql.PreparedStatement; |
import java.sql.PreparedStatement; |
5 |
import java.sql.ResultSet; |
import java.sql.ResultSet; |
6 |
import java.sql.SQLException; |
import java.sql.SQLException; |
7 |
import java.util.ArrayList; |
import java.util.ArrayList; |
8 |
import java.util.List; |
import java.util.List; |
|
import java.util.Properties; |
|
9 |
import java.util.Queue; |
import java.util.Queue; |
10 |
import java.util.concurrent.ConcurrentLinkedQueue; |
import java.util.concurrent.ConcurrentLinkedQueue; |
11 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
16 |
|
|
17 |
|
|
18 |
Connection conn; |
Connection conn; |
|
Connection writeConn; |
|
|
|
|
19 |
PreparedStatement saveStmt; |
PreparedStatement saveStmt; |
20 |
|
|
21 |
public Database(Properties conf) throws SQLException,IOException { |
public Database(Connection conn) throws SQLException { |
22 |
conn = getConnection(conf); |
this.conn = conn; |
|
conn.setReadOnly(true); |
|
|
|
|
|
writeConn = getConnection(conf); |
|
|
|
|
23 |
|
|
24 |
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`) "+ |
25 |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
26 |
|
|
27 |
saveStmt = writeConn.prepareStatement(sql); |
saveStmt = conn.prepareStatement(sql); |
|
|
|
|
} |
|
|
|
|
|
public void resetResultTable() throws SQLException { |
|
|
logger.info("Truncating result table"); |
|
|
String sql = "TRUNCATE TABLE fulddaekning.afstand_anden_rute_thn"; |
|
|
writeConn.createStatement().executeUpdate(sql); |
|
|
|
|
|
} |
|
|
|
|
|
public Connection getConnection(Properties conf) throws SQLException, IOException { |
|
|
|
|
|
String db_host = conf.getProperty("DB_HOST"); |
|
|
String db_user = conf.getProperty("DB_USER"); |
|
|
String db_pass = conf.getProperty("DB_PASS"); |
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
Connection conn = null; |
|
|
Properties connectionProps = new Properties(); |
|
|
connectionProps.put("user", db_user); |
|
|
connectionProps.put("password", db_pass); |
|
|
|
|
|
conn = DriverManager.getConnection( |
|
|
"jdbc:mysql://" + |
|
|
db_host + |
|
|
":3306/", |
|
|
connectionProps); |
|
|
logger.info("Connected to database"); |
|
|
return conn; |
|
29 |
} |
} |
30 |
|
|
31 |
public BoundingBox getBoundingbox(int postnr) throws SQLException { |
public BoundingBox getBoundingbox(int postnr) throws SQLException { |