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 import java.util.Map;
27
28 import org.apache.log4j.Logger;
29 import org.fosstrak.llrp.adaptor.exception.LLRPRuntimeException;
30 import org.fosstrak.llrp.client.ROAccessReportsRepository;
31 import org.fosstrak.llrp.client.repository.sql.roaccess.DerbyROAccessReportsRepository;
32
33
34
35
36
37
38
39
40
41
42
43 public class DerbyRepository extends AbstractSQLRepository {
44
45
46 private static Logger log = Logger.getLogger(DerbyRepository.class);
47
48
49 protected DerbyROAccessReportsRepository repoROAccessReports = null;
50
51
52 private static final String DB_PROTOCOL = "jdbc:derby:";
53
54
55 private static final String DB_CREATE = ";create=true";
56
57
58 public static final String ARG_REPO_LOCATION = "argRepoLocation";
59
60
61 private String repoLocation;
62
63
64
65
66 public DerbyRepository() {
67 }
68
69 @Override
70 public void initialize(Map<String, String> args)
71 throws LLRPRuntimeException {
72
73 super.initialize(args);
74
75 String argRepoLoc = null;
76 if ((null == args) || (null == args.get(ARG_REPO_LOCATION))) {
77 argRepoLoc = DB_NAME;
78 } else {
79 argRepoLoc = args.get(ARG_REPO_LOCATION);
80 }
81 repoLocation = argRepoLoc + DB_NAME;
82 }
83
84 @Override
85 protected Connection openConnection() throws Exception {
86 return DriverManager.getConnection(DB_PROTOCOL + repoLocation + DB_CREATE);
87 }
88
89 public ROAccessReportsRepository getROAccessRepository() {
90 if (!logROAccess) return null;
91
92 if (null == repoROAccessReports) {
93 log.debug("No RepoROAccessReports handle yet - Create a new one.");
94 repoROAccessReports = new DerbyROAccessReportsRepository();
95 try {
96 repoROAccessReports.initialize(this);
97 } catch (LLRPRuntimeException e) {
98 log.error(String.format(
99 "Could not initialize the RO_ACCESS_REPORTS repo: '%s'",
100 e.getMessage()));
101 }
102 }
103 return repoROAccessReports;
104 }
105 }
106