Skip to content

Commit

Permalink
Merge pull request #3206 from jeremylong/pooling
Browse files Browse the repository at this point in the history
Implement Connection Pooling
  • Loading branch information
jeremylong committed May 14, 2021
2 parents d4d24b9 + 8a6d7d8 commit ebd3a31
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 335 deletions.
4 changes: 4 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ Copyright (c) 2012 Jeremy Long. All Rights Reserved.
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
Expand Down
15 changes: 8 additions & 7 deletions core/src/main/java/org/owasp/dependencycheck/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.owasp.dependencycheck.analyzer.Analyzer;
import org.owasp.dependencycheck.analyzer.AnalyzerService;
import org.owasp.dependencycheck.analyzer.FileTypeAnalyzer;
import org.owasp.dependencycheck.data.nvdcve.ConnectionFactory;
import org.owasp.dependencycheck.data.nvdcve.DatabaseManager;
import org.owasp.dependencycheck.data.nvdcve.CveDB;
import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties;
Expand Down Expand Up @@ -686,7 +686,7 @@ private void initializeAndUpdateDatabase(@NotNull final List<Throwable> exceptio
}
} else {
try {
if (ConnectionFactory.isH2Connection(settings) && !ConnectionFactory.h2DataFileExists(settings)) {
if (DatabaseManager.isH2Connection(settings) && !DatabaseManager.h2DataFileExists(settings)) {
throw new ExceptionCollection(new NoDataException("Autoupdate is disabled and the database does not exist"), true);
} else {
openDatabase(true, true);
Expand All @@ -709,7 +709,7 @@ private void initializeAndUpdateDatabase(@NotNull final List<Throwable> exceptio
*/
private void throwFatalDatabaseException(DatabaseException ex, final List<Throwable> exceptions) throws ExceptionCollection {
final String msg;
if (ex.getMessage().contains("Unable to connect") && ConnectionFactory.isH2Connection(settings)) {
if (ex.getMessage().contains("Unable to connect") && DatabaseManager.isH2Connection(settings)) {
msg = "Unable to connect to the database - if this error persists it may be "
+ "due to a corrupt database. Consider running `purge` to delete the existing database";
} else {
Expand Down Expand Up @@ -856,7 +856,7 @@ public void doUpdates() throws UpdateException, DatabaseException {
*/
public void doUpdates(boolean remainOpen) throws UpdateException, DatabaseException {
if (mode.isDatabaseRequired()) {
try (WriteLock dblock = new WriteLock(getSettings(), ConnectionFactory.isH2Connection(getSettings()))) {
try (WriteLock dblock = new WriteLock(getSettings(), DatabaseManager.isH2Connection(getSettings()))) {
//lock is not needed as we already have the lock held
openDatabase(false, false);
LOGGER.info("Checking for updates");
Expand Down Expand Up @@ -962,11 +962,11 @@ public void openDatabase() throws DatabaseException {
*/
public void openDatabase(boolean readOnly, boolean lockRequired) throws DatabaseException {
if (mode.isDatabaseRequired() && database == null) {
try (WriteLock dblock = new WriteLock(getSettings(), lockRequired && ConnectionFactory.isH2Connection(settings))) {
try (WriteLock dblock = new WriteLock(getSettings(), lockRequired && DatabaseManager.isH2Connection(settings))) {
if (readOnly
&& ConnectionFactory.isH2Connection(settings)
&& DatabaseManager.isH2Connection(settings)
&& settings.getString(Settings.KEYS.DB_CONNECTION_STRING).contains("file:%s")) {
final File db = ConnectionFactory.getH2DataFile(settings);
final File db = DatabaseManager.getH2DataFile(settings);
if (db.isFile()) {
final File temp = settings.getTempDirectory();
final File tempDB = new File(temp, db.getName());
Expand All @@ -989,6 +989,7 @@ public void openDatabase(boolean readOnly, boolean lockRequired) throws Database
} catch (WriteLockException ex) {
throw new DatabaseException("Failed to obtain lock - unable to open database", ex);
}
database.open();
}
}

Expand Down

0 comments on commit ebd3a31

Please sign in to comment.