mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-21 00:29:21 +01:00
made initialize and cleanup synchronized so we can avoid un-needed duplicate initialization/cleanup
Former-commit-id: 061d6a1a5c56806ea7c23d2599a6c6f7df1dae58
This commit is contained in:
@@ -80,7 +80,12 @@ public final class ConnectionFactory {
|
|||||||
*
|
*
|
||||||
* @throws DatabaseException thrown if we are unable to connect to the database
|
* @throws DatabaseException thrown if we are unable to connect to the database
|
||||||
*/
|
*/
|
||||||
public static void initialize() throws DatabaseException {
|
public static synchronized void initialize() throws DatabaseException {
|
||||||
|
//this only needs to be called once.
|
||||||
|
if (connectionString != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//load the driver if necessary
|
//load the driver if necessary
|
||||||
final String driverName = Settings.getString(Settings.KEYS.DB_DRIVER_NAME, "");
|
final String driverName = Settings.getString(Settings.KEYS.DB_DRIVER_NAME, "");
|
||||||
if (!driverName.isEmpty()) { //likely need to load the correct driver
|
if (!driverName.isEmpty()) { //likely need to load the correct driver
|
||||||
@@ -173,7 +178,7 @@ public final class ConnectionFactory {
|
|||||||
/**
|
/**
|
||||||
* Cleans up resources and unloads any registered database drivers.
|
* Cleans up resources and unloads any registered database drivers.
|
||||||
*/
|
*/
|
||||||
public static void cleanup() {
|
public static synchronized void cleanup() {
|
||||||
if (driver != null) {
|
if (driver != null) {
|
||||||
try {
|
try {
|
||||||
DriverManager.deregisterDriver(driver);
|
DriverManager.deregisterDriver(driver);
|
||||||
@@ -182,6 +187,9 @@ public final class ConnectionFactory {
|
|||||||
}
|
}
|
||||||
driver = null;
|
driver = null;
|
||||||
}
|
}
|
||||||
|
connectionString = null;
|
||||||
|
userName = null;
|
||||||
|
password = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user