44 |
} |
} |
45 |
|
|
46 |
public void renameResultTables() throws SQLException { |
public void renameResultTables() throws SQLException { |
47 |
|
Constants consts = Constants.getInstance(); |
48 |
|
String ext = consts.getTableExtension(); |
49 |
|
|
50 |
logger.info("Dropping old backup table (if exists)"); |
logger.info("Dropping old backup table (if exists)"); |
51 |
String sql = "DROP TABLE IF EXISTS fulddaekning.afstand_anden_rute_old"; |
String sql = "DROP TABLE IF EXISTS fulddaekning.afstand_anden_rute_old" + ext; |
52 |
conn.createStatement().executeUpdate(sql); |
conn.createStatement().executeUpdate(sql); |
53 |
|
|
54 |
logger.info("Rename tables"); |
logger.info("Rename tables"); |
55 |
sql = "RENAME TABLE fulddaekning.afstand_anden_rute TO fulddaekning.afstand_anden_rute_old, fulddaekning.afstand_anden_rute_ny TO fulddaekning.afstand_anden_rute"; |
sql = "RENAME TABLE fulddaekning.afstand_anden_rute" + ext + " TO fulddaekning.afstand_anden_rute_old" + ext + ", fulddaekning.afstand_anden_rute_ny TO fulddaekning.afstand_anden_rute" + ext; |
56 |
|
|
57 |
|
logger.info("Executing: " + sql); |
58 |
conn.createStatement().executeUpdate(sql); |
conn.createStatement().executeUpdate(sql); |
59 |
} |
} |
60 |
|
|
85 |
public Queue<Adresse> hentIkkedaekkedeAdresser(int postnr) throws SQLException { |
public Queue<Adresse> hentIkkedaekkedeAdresser(int postnr) throws SQLException { |
86 |
ConcurrentLinkedQueue<Adresse> queue = new ConcurrentLinkedQueue<Adresse>(); |
ConcurrentLinkedQueue<Adresse> queue = new ConcurrentLinkedQueue<Adresse>(); |
87 |
|
|
88 |
String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute " + |
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
89 |
"FROM fulddaekning.adressetabel " + |
"FROM fulddaekning.adressetabel a " + |
90 |
|
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
91 |
"WHERE rute IS NULL " + //Ingen dækning |
"WHERE rute IS NULL " + //Ingen dækning |
92 |
"AND postnr=? " + |
"AND a.postnr=? " + |
93 |
"AND latitude IS NOT NULL " + |
"AND latitude IS NOT NULL " + |
94 |
"AND longitude IS NOT NULL " + |
"AND longitude IS NOT NULL " + |
95 |
"AND gadeid IS NOT NULL "; |
"AND gadeid IS NOT NULL "; |
131 |
} |
} |
132 |
|
|
133 |
public Adresse[] hentDaekkedeAdresser( BoundingBox bbox) throws SQLException { |
public Adresse[] hentDaekkedeAdresser( BoundingBox bbox) throws SQLException { |
134 |
String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute " + |
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
135 |
"FROM fulddaekning.adressetabel " + |
"FROM fulddaekning.adressetabel a " + |
136 |
|
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
137 |
"WHERE rute IS NOT NULL " + |
"WHERE rute IS NOT NULL " + |
138 |
"AND latitude BETWEEN ? AND ? " + |
"AND latitude BETWEEN ? AND ? " + |
139 |
"AND longitude BETWEEN ? AND ? " + |
"AND longitude BETWEEN ? AND ? " + |
140 |
"AND distributor = ? "; |
"AND a.distributor = ? "; |
141 |
|
|
142 |
// 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) |
143 |
// 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 |
153 |
|
|
154 |
List<Adresse> list = hentAdresseListe( stmt ); |
List<Adresse> list = hentAdresseListe( stmt ); |
155 |
return list.toArray( new Adresse[ list.size() ] ); |
return list.toArray( new Adresse[ list.size() ] ); |
|
|
|
156 |
} |
} |
157 |
|
|
158 |
|
|
159 |
|
public Adresse[] hentAlleDaekkedeAdresser() throws SQLException { |
160 |
|
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
161 |
|
"FROM fulddaekning.adressetabel a " + |
162 |
|
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
163 |
|
"WHERE rute IS NOT NULL " + |
164 |
|
"AND latitude IS NOT NULL " + |
165 |
|
"AND longitude IS NOT NULL " + |
166 |
|
"AND a.distributor = ? "; |
167 |
|
|
168 |
|
// Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets) |
169 |
|
// Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html |
170 |
|
//PreparedStatement stmt = conn.prepareStatement(sql); |
171 |
|
PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
172 |
|
stmt.setFetchSize(Integer.MIN_VALUE); |
173 |
|
|
174 |
|
stmt.setString(1, Lookup.distributor); |
175 |
|
|
176 |
|
List<Adresse> list = hentAdresseListe( stmt ); |
177 |
|
return list.toArray( new Adresse[ list.size() ] ); |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
public synchronized void gemResultat(Adresse orgAdresse, Adresse bedsteAdresse, double bedsteAfstand) throws SQLException { |
public synchronized void gemResultat(Adresse orgAdresse, Adresse bedsteAdresse, double bedsteAfstand) throws SQLException { |
183 |
/*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`) "+ |
245 |
adr.latitude = res.getDouble("latitude"); |
adr.latitude = res.getDouble("latitude"); |
246 |
adr.longitude = res.getDouble("longitude"); |
adr.longitude = res.getDouble("longitude"); |
247 |
adr.rute = res.getString("rute"); |
adr.rute = res.getString("rute"); |
248 |
|
adr.ho = res.getInt("ho"); |
249 |
|
|
250 |
list.add(adr); |
list.add(adr); |
251 |
|
|
272 |
connectionProps.put("user", db_user); |
connectionProps.put("user", db_user); |
273 |
connectionProps.put("password", db_pass); |
connectionProps.put("password", db_pass); |
274 |
|
|
275 |
|
//For debug output, tilføj denne til JDBC url'en: &profileSQL=true |
|
|
|
276 |
conn = DriverManager.getConnection( |
conn = DriverManager.getConnection( |
277 |
"jdbc:mysql://" + |
"jdbc:mysql://" + |
278 |
db_host + |
db_host + |