Class DatabaseManager
java.lang.Object
org.owasp.dependencycheck.data.nvdcve.DatabaseManager
Loads the configured database driver and returns the database connection. If
the embedded H2 database is used obtaining a connection will ensure the
database file exists and that the appropriate table structure has been
created.
- Author:
- Jeremy Long
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDatabaseManager(Settings settings) Private constructor for this factory class; no instance is ever needed. -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup()Cleans up resources and unloads any registered database drivers.voidclose()Closes the database connection pool.Constructs a new database connection object per the database configuration.Returns the database product name.static FilegetH2DataFile(Settings configuration) Returns a reference to the H2 database file.Returns a resource bundle containing the SQL Statements needed for the database engine being used.booleanDetermines if the H2 database file exists.static booleanh2DataFileExists(Settings configuration) Determines if the H2 database file exists.booleanDetermines if the connection string is for an H2 database.static booleanisH2Connection(String connectionString) Determines if the connection string is for an H2 database.static booleanisH2Connection(Settings configuration) Determines if the connection string is for an H2 database.booleanisOpen()Returns if the connection pool is open.booleanisOracle()Determines if the connection string is for an Oracle database.voidopen()Opens the database connection pool.
-
Field Details
-
DB_STRUCTURE_RESOURCE
Resource location for SQL file used to create the database schema.- See Also:
-
DB_STRUCTURE_UPDATE_RESOURCE
Resource location for SQL file used to create the database schema.- See Also:
-
UPGRADE_HELP_URL
The URL that discusses upgrading non-H2 databases.- See Also:
-
-
Constructor Details
-
DatabaseManager
Private constructor for this factory class; no instance is ever needed.- Parameters:
settings- the configured settings- Throws:
DatabaseException- thrown if we are unable to connect to the database
-
-
Method Details
-
cleanup
public void cleanup()Cleans up resources and unloads any registered database drivers. This needs to be called to ensure the driver is unregistered prior to the finalize method being called as during shutdown the class loader used to load the driver may be unloaded prior to the driver being de-registered. -
h2DataFileExists
Determines if the H2 database file exists. If it does not exist then the data structure will need to be created.- Returns:
- true if the H2 database file does not exist; otherwise false
- Throws:
IOException- thrown if the data directory does not exist and cannot be created
-
h2DataFileExists
Determines if the H2 database file exists. If it does not exist then the data structure will need to be created.- Parameters:
configuration- the configured settings- Returns:
- true if the H2 database file does not exist; otherwise false
- Throws:
IOException- thrown if the data directory does not exist and cannot be created
-
getH2DataFile
Returns a reference to the H2 database file.- Parameters:
configuration- the configured settings- Returns:
- the path to the H2 database file
- Throws:
IOException- thrown if there is an error
-
getDatabaseProductName
Returns the database product name.- Returns:
- the database product name
-
isH2Connection
public boolean isH2Connection()Determines if the connection string is for an H2 database.- Returns:
- true if the connection string is for an H2 database
-
isOracle
public boolean isOracle()Determines if the connection string is for an Oracle database.- Returns:
- true if the connection string is for an Oracle database
-
isH2Connection
Determines if the connection string is for an H2 database.- Parameters:
configuration- the configured settings- Returns:
- true if the connection string is for an H2 database
-
isH2Connection
Determines if the connection string is for an H2 database.- Parameters:
connectionString- the connection string- Returns:
- true if the connection string is for an H2 database
-
getSqlStatements
Returns a resource bundle containing the SQL Statements needed for the database engine being used.- Returns:
- a resource bundle containing the SQL Statements
-
open
public void open()Opens the database connection pool. -
close
public void close()Closes the database connection pool. -
isOpen
public boolean isOpen()Returns if the connection pool is open.- Returns:
- if the connection pool is open
-
getConnection
Constructs a new database connection object per the database configuration.- Returns:
- a database connection object
- Throws:
DatabaseException- thrown if there is an exception obtaining the database connection
-