/[projects]/dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/db/LogPersistance.java
ViewVC logotype

Contents of /dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/db/LogPersistance.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2608 - (show annotations) (download)
Wed Jul 15 06:52:05 2015 UTC (8 years, 10 months ago) by torben
File size: 1304 byte(s)
Separate database interface and implementation (preparation for mocking and more unit tests)
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

  ViewVC Help
Powered by ViewVC 1.1.20