14 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
15 |
|
|
16 |
|
|
17 |
|
|
18 |
public class Database { |
public class Database { |
19 |
Logger logger = Logger.getLogger(Database.class.getName()); |
Logger logger = Logger.getLogger(Database.class.getName()); |
20 |
|
|
21 |
|
int batchCount = 0; |
22 |
|
|
23 |
Connection conn; |
Connection conn; |
24 |
PreparedStatement saveStmt; |
PreparedStatement saveStmt; |
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 |
conn.createStatement().executeUpdate(sql); |
conn.createStatement().executeUpdate(sql); |
57 |
} |
} |
58 |
|
|
182 |
|
|
183 |
saveStmt.setDouble(19, bedsteAfstand); |
saveStmt.setDouble(19, bedsteAfstand); |
184 |
|
|
185 |
saveStmt.executeUpdate(); |
saveStmt.addBatch(); |
186 |
saveStmt.clearParameters(); |
batchCount++; |
187 |
|
if (batchCount >= 100) { |
188 |
|
saveStmt.executeBatch(); |
189 |
|
batchCount = 0; |
190 |
|
} |
191 |
|
//saveStmt.executeUpdate(); |
192 |
|
//saveStmt.clearParameters(); |
193 |
|
|
194 |
//saveStmt.close(); |
//saveStmt.close(); |
195 |
|
} |
196 |
|
|
197 |
|
public synchronized void saveBatch() throws SQLException{ |
198 |
|
saveStmt.executeBatch(); |
199 |
|
batchCount = 0; |
200 |
} |
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
protected ArrayList<Adresse> hentAdresseListe(PreparedStatement stmt) throws SQLException{ |
protected ArrayList<Adresse> hentAdresseListe(PreparedStatement stmt) throws SQLException{ |
205 |
ArrayList<Adresse> list = new ArrayList<Adresse>( 30000 ); |
ArrayList<Adresse> list = new ArrayList<Adresse>( 1000000 ); |
206 |
|
|
207 |
//logger.info("Starting query"); |
//logger.info("Starting query"); |
208 |
ResultSet res = stmt.executeQuery(); |
ResultSet res = stmt.executeQuery(); |
245 |
connectionProps.put("user", db_user); |
connectionProps.put("user", db_user); |
246 |
connectionProps.put("password", db_pass); |
connectionProps.put("password", db_pass); |
247 |
|
|
248 |
|
//For debug output, tilføj denne til JDBC url'en: &profileSQL=true |
249 |
conn = DriverManager.getConnection( |
conn = DriverManager.getConnection( |
250 |
"jdbc:mysql://" + |
"jdbc:mysql://" + |
251 |
db_host + |
db_host + |
252 |
":3306/", |
":3306/?rewriteBatchedStatements=true", |
253 |
connectionProps); |
connectionProps); |
254 |
logger.info("Connected to database"); |
logger.info("Connected to database"); |
255 |
return conn; |
return conn; |