Class DatabaseManager

java.lang.Object
org.owasp.dependencycheck.data.nvdcve.DatabaseManager

@ThreadSafe public final class DatabaseManager extends Object
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 Details

    • DB_STRUCTURE_RESOURCE

      public static final String DB_STRUCTURE_RESOURCE
      Resource location for SQL file used to create the database schema.
      See Also:
    • DB_STRUCTURE_UPDATE_RESOURCE

      public static final String DB_STRUCTURE_UPDATE_RESOURCE
      Resource location for SQL file used to create the database schema.
      See Also:
    • UPGRADE_HELP_URL

      public static final String UPGRADE_HELP_URL
      The URL that discusses upgrading non-H2 databases.
      See Also:
  • Constructor Details

    • DatabaseManager

      public DatabaseManager(Settings settings) throws DatabaseException
      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

      public boolean h2DataFileExists() throws IOException
      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

      public static boolean h2DataFileExists(Settings configuration) throws IOException
      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

      public static File getH2DataFile(Settings configuration) throws IOException
      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

      public String 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

      public static boolean isH2Connection(Settings configuration)
      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

      public static boolean isH2Connection(String connectionString)
      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

      public ResourceBundle 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

      public Connection getConnection() throws DatabaseException
      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