1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.fosstrak.llrp.client.repository.sql;
23
24 import java.sql.Connection;
25 import java.sql.DriverManager;
26
27 import org.apache.log4j.Logger;
28 import org.fosstrak.llrp.adaptor.exception.LLRPRuntimeException;
29 import org.fosstrak.llrp.client.ROAccessReportsRepository;
30 import org.fosstrak.llrp.client.repository.sql.roaccess.DerbyROAccessReportsRepository;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public class PostgreSQLRepository extends AbstractSQLRepository {
46
47
48 protected final String DBDRIVER = "org.postgresql.Driver";
49
50
51
52 protected DerbyROAccessReportsRepository repoROAccessReports = null;
53
54
55 public static final String JDBC_STR =
56 String.format("jdbc:postgresql://localhost:5432/%s", "llrpmsgdb");
57
58
59 private static Logger log = Logger.getLogger(PostgreSQLRepository.class);
60
61 @Override
62 protected String getDBDriver() {
63 return DBDRIVER;
64 }
65
66 @Override
67 protected Connection openConnection() throws Exception {
68 log.debug(String.format("Opening PostgreSQL connection with:\n" +
69 "\tusername: %s\n " +
70 "\tJDBC connector URL: %s\n", username, connectURL));
71
72 return DriverManager.getConnection(connectURL, username, password);
73 }
74
75 @Override
76 protected String sqlCreateTable() {
77 return "CREATE TABLE " + TABLE_LLRP_REPOSITORY + " "
78 + "(MSG_ID CHAR(32),"
79 + "MSG_TYPE CHAR(32),"
80 + "READER CHAR(64),"
81 + "ADAPTER CHAR(64),"
82 + "MSG_TIME TIMESTAMP,"
83 + "STATUS CHAR(64),"
84 + "COMMENT VARCHAR(64),"
85 + "MARK CHAR(3),"
86 + "CONTENT text)";
87 }
88
89 public ROAccessReportsRepository getROAccessRepository() {
90 if (!logROAccess) return null;
91
92
93
94
95 if (null == repoROAccessReports) {
96 log.debug("No RepoROAccessReports handle yet - Create a new one.");
97 repoROAccessReports = new DerbyROAccessReportsRepository();
98 try {
99 repoROAccessReports.initialize(this);
100 } catch (LLRPRuntimeException e) {
101 log.error(String.format(
102 "Could not initialize the RO_ACCESS_REPORTS repo: '%s'",
103 e.getMessage()));
104 }
105 }
106 return repoROAccessReports;
107 }
108
109 }