mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-21 16:49:43 +01:00
Minor adjustments of caching for CveDB, based on code review
This commit is contained in:
@@ -24,6 +24,7 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -95,7 +96,7 @@ public final class CveDB implements AutoCloseable {
|
|||||||
private final EnumMap<PreparedStatementCveDb, PreparedStatement> preparedStatements = new EnumMap<>(PreparedStatementCveDb.class);
|
private final EnumMap<PreparedStatementCveDb, PreparedStatement> preparedStatements = new EnumMap<>(PreparedStatementCveDb.class);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private final Map<String, List<Vulnerability>> vulnerabilitiesForCpeCache = new ReferenceMap(HARD, SOFT);
|
private final Map<String, List<Vulnerability>> vulnerabilitiesForCpeCache = Collections.synchronizedMap(new ReferenceMap(HARD, SOFT));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The enum value names must match the keys of the statements in the
|
* The enum value names must match the keys of the statements in the
|
||||||
@@ -271,11 +272,11 @@ public final class CveDB implements AutoCloseable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
clearCache();
|
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
instance.usageCount -= 1;
|
instance.usageCount -= 1;
|
||||||
if (instance.usageCount <= 0 && instance.isOpen()) {
|
if (instance.usageCount <= 0 && instance.isOpen()) {
|
||||||
instance.usageCount = 0;
|
instance.usageCount = 0;
|
||||||
|
clearCache();
|
||||||
instance.closeStatements();
|
instance.closeStatements();
|
||||||
try {
|
try {
|
||||||
instance.connection.close();
|
instance.connection.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user