1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.data.update;
19
20 import org.owasp.dependencycheck.data.nvdcve.CveDB;
21 import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
22 import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties;
23 import org.owasp.dependencycheck.data.update.exception.UpdateException;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27
28
29
30
31 public abstract class BaseUpdater {
32
33
34
35
36 private static final Logger LOGGER = LoggerFactory.getLogger(BaseUpdater.class);
37
38
39
40 private DatabaseProperties properties;
41
42
43
44 private CveDB cveDB = null;
45
46 protected CveDB getCveDB() {
47 return cveDB;
48 }
49
50 protected DatabaseProperties getProperties() {
51 return properties;
52 }
53
54
55
56
57 protected void closeDataStores() {
58 if (cveDB != null) {
59 try {
60 cveDB.close();
61 cveDB = null;
62 properties = null;
63 } catch (Throwable ignore) {
64 LOGGER.trace("Error closing the database", ignore);
65 }
66 }
67 }
68
69
70
71
72
73
74 protected final void openDataStores() throws UpdateException {
75 if (cveDB != null) {
76 return;
77 }
78 try {
79 cveDB = new CveDB();
80 cveDB.open();
81 properties = cveDB.getDatabaseProperties();
82 } catch (DatabaseException ex) {
83 closeDataStores();
84 LOGGER.debug("Database Exception opening databases", ex);
85 throw new UpdateException("Error updating the database, please see the log file for more details.");
86 }
87 }
88 }