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 { |
55 |
|
|
56 |
String sql = |
String sql = |
57 |
"select max(latitude) latmax, min(latitude) latmin, max(longitude) lngmax,min(longitude) lngmin " + |
"SELECT max(latitude) latmax, min(latitude) latmin, max(longitude) lngmax,min(longitude) lngmin " + |
58 |
"from fulddaekning.adressetabel WHERE postnr=? and rute is null;"; |
"FROM fulddaekning.adressetabel WHERE postnr=? and rute is null;"; |
59 |
|
|
60 |
PreparedStatement stmt = conn.prepareStatement(sql); |
PreparedStatement stmt = conn.prepareStatement(sql); |
61 |
stmt.setInt(1, postnr); |
stmt.setInt(1, postnr); |
78 |
public Queue<Adresse> hentIkkedaekkedeAdresser(int postnr) throws SQLException { |
public Queue<Adresse> hentIkkedaekkedeAdresser(int postnr) throws SQLException { |
79 |
ConcurrentLinkedQueue<Adresse> queue = new ConcurrentLinkedQueue<Adresse>(); |
ConcurrentLinkedQueue<Adresse> queue = new ConcurrentLinkedQueue<Adresse>(); |
80 |
|
|
81 |
String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute FROM fulddaekning.adressetabel " + |
String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute " + |
82 |
|
"FROM fulddaekning.adressetabel " + |
83 |
"WHERE rute IS NULL " + //Ingen dækning |
"WHERE rute IS NULL " + //Ingen dækning |
84 |
"AND postnr=? " + |
"AND postnr=? " + |
85 |
"AND latitude IS NOT NULL " + |
"AND latitude IS NOT NULL " + |
96 |
ArrayList<Integer> list = new ArrayList<Integer>(); |
ArrayList<Integer> list = new ArrayList<Integer>(); |
97 |
|
|
98 |
|
|
99 |
String sql = "SELECT postnr FROM fulddaekning.adressetabel WHERE distributor = 'DAO' and rute is not null GROUP BY postnr ORDER by postnr"; |
String sql = "SELECT postnr " + |
100 |
|
"FROM fulddaekning.adressetabel " + |
101 |
|
"WHERE distributor = ? and rute is not null " + |
102 |
|
"GROUP BY postnr " + |
103 |
|
"ORDER by postnr"; |
104 |
PreparedStatement stmt = conn.prepareStatement(sql); |
PreparedStatement stmt = conn.prepareStatement(sql); |
105 |
|
stmt.setString(1, Lookup.distributor ); |
106 |
ResultSet res = stmt.executeQuery(); |
ResultSet res = stmt.executeQuery(); |
107 |
|
|
108 |
while (res.next()) { |
while (res.next()) { |
118 |
} |
} |
119 |
|
|
120 |
public ArrayList<Adresse> hentDaekkedeAdresser( BoundingBox bbox) throws SQLException { |
public ArrayList<Adresse> hentDaekkedeAdresser( BoundingBox bbox) throws SQLException { |
121 |
String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute FROM fulddaekning.adressetabel " + |
String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute " + |
122 |
|
"FROM fulddaekning.adressetabel " + |
123 |
"WHERE rute IS NOT NULL " + |
"WHERE rute IS NOT NULL " + |
124 |
"AND latitude BETWEEN ? AND ? " + |
"AND latitude BETWEEN ? AND ? " + |
125 |
"AND longitude BETWEEN ? AND ? " + |
"AND longitude BETWEEN ? AND ? " + |
126 |
"AND distributor = 'DAO' "; |
"AND distributor = ? "; |
127 |
|
|
128 |
// Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets) |
// Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets) |
129 |
// Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html |
// Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html |
135 |
stmt.setDouble(2, bbox.latitudeMax); |
stmt.setDouble(2, bbox.latitudeMax); |
136 |
stmt.setDouble(3, bbox.longitudeMin); |
stmt.setDouble(3, bbox.longitudeMin); |
137 |
stmt.setDouble(4, bbox.longitudeMax); |
stmt.setDouble(4, bbox.longitudeMax); |
138 |
|
stmt.setString(5, Lookup.distributor); |
139 |
|
|
140 |
return hentAdresseListe( stmt ); |
return hentAdresseListe( stmt ); |
141 |
|
|
211 |
return list; |
return list; |
212 |
} |
} |
213 |
|
|
214 |
public Connection getConnection(Properties conf) throws SQLException, IOException { |
public Connection getConnection(SafeProperties conf) throws SQLException, IOException { |
215 |
|
|
216 |
String db_host = conf.getProperty("DB_HOST"); |
String db_host = conf.getSafeProperty("DB_HOST"); |
217 |
String db_user = conf.getProperty("DB_USER"); |
String db_user = conf.getSafeProperty("DB_USER"); |
218 |
String db_pass = conf.getProperty("DB_PASS"); |
String db_pass = conf.getSafeProperty("DB_PASS"); |
219 |
|
|
220 |
|
|
221 |
|
|