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 |
static class LogPersistanceWorker implements Runnable {
|
14 |
String brugerid;
|
15 |
String postnr;
|
16 |
String adresse;
|
17 |
SearchResult result;
|
18 |
|
19 |
public LogPersistanceWorker(String brugerid, String postnr, String adresse, SearchResult result) {
|
20 |
this.brugerid = brugerid;
|
21 |
this.postnr = postnr;
|
22 |
this.adresse = adresse;
|
23 |
this.result = result;
|
24 |
}
|
25 |
|
26 |
@Override
|
27 |
public void run() {
|
28 |
try {
|
29 |
DatabaseLayer.saveRequestLog(brugerid,postnr,adresse,result);
|
30 |
} catch (SQLException e) {
|
31 |
System.out.println("Error saving log entry " + e.getMessage() + ". Postnr=" + postnr + ". Adresse=" + adresse);
|
32 |
}
|
33 |
}
|
34 |
}
|
35 |
|
36 |
public void saveRequestLog(String brugerid, String postnr, String adresse, SearchResult result) {
|
37 |
threadPool.execute( new LogPersistanceWorker(brugerid,postnr,adresse,result) );
|
38 |
}
|
39 |
|
40 |
|
41 |
public void shutdown() {
|
42 |
threadPool.shutdown();
|
43 |
}
|
44 |
}
|