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