1 |
package dk.daoas.daoadresseservice.db;
|
2 |
|
3 |
import java.sql.SQLException;
|
4 |
import java.util.concurrent.ExecutorService;
|
5 |
import java.util.concurrent.Executors;
|
6 |
|
7 |
import dk.daoas.daoadresseservice.beans.SearchResult;
|
8 |
|
9 |
public class LogPersistance {
|
10 |
|
11 |
ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
12 |
|
13 |
private static class LogPersistanceWorker implements Runnable {
|
14 |
|
15 |
DatabaseLayer db;
|
16 |
String brugerid;
|
17 |
String postnr;
|
18 |
String adresse;
|
19 |
SearchResult result;
|
20 |
|
21 |
public LogPersistanceWorker(DatabaseLayer db, String brugerid, String postnr, String adresse, SearchResult result) {
|
22 |
this.db = db;
|
23 |
this.brugerid = brugerid;
|
24 |
this.postnr = postnr;
|
25 |
this.adresse = adresse;
|
26 |
this.result = result;
|
27 |
}
|
28 |
|
29 |
@Override
|
30 |
public void run() {
|
31 |
try {
|
32 |
db.saveRequestLog(brugerid,postnr,adresse,result);
|
33 |
} catch (SQLException e) {
|
34 |
System.out.println("Error saving log entry " + e.getMessage() + ". Postnr=" + postnr + ". Adresse=" + adresse);
|
35 |
}
|
36 |
}
|
37 |
}
|
38 |
|
39 |
public void saveRequestLog(DatabaseLayer db, String brugerid, String postnr, String adresse, SearchResult result) {
|
40 |
threadPool.execute( new LogPersistanceWorker(db, brugerid, postnr, adresse, result) );
|
41 |
}
|
42 |
|
43 |
|
44 |
public void shutdown() {
|
45 |
threadPool.shutdown();
|
46 |
}
|
47 |
}
|
48 |
|