Interface DatabaseManagerBl

All Known Implementing Classes:
DatabaseManagerBlImpl

public interface DatabaseManagerBl
Database manager can work with database version and upgraded state of perun DB.
Author:
Michal Stava email:<stavamichal@gmail.com>
  • Field Details

  • Method Details

    • prepareSQLArrayOfNumbers

      static Array prepareSQLArrayOfNumbers(List<? extends PerunBean> perunBeans, PreparedStatement preparedStatement) throws SQLException
      Take list of perunBeans and generate an array of ids in sql database from it. Implementation can be different for every type of supported DB
      Parameters:
      perunBeans - list of PerunBeans to get Ids from
      preparedStatement - database prepared statement to get working connection
      Returns:
      java sql array with pre-loaded list of ids
      Throws:
      SQLException - if any sql exception has been thrown
      InternalErrorException - if oracle method to work with an array can't be get or invoked
    • prepareSQLArrayOfNumbersFromIntegers

      static Array prepareSQLArrayOfNumbersFromIntegers(List<Integer> integers, PreparedStatement preparedStatement) throws SQLException
      Take list of integers and generate an array of integers in sql database from it. Implementation can be different for every type of supported DB
      Parameters:
      integers - list of integers
      preparedStatement - database prepared statement to get working connection
      Returns:
      java sql array with pre-loaded list of integers
      Throws:
      SQLException - if any sql exception has been thrown
      InternalErrorException - if oracle method to work with an array can't be get or invoked
    • prepareSQLArrayOfStrings

      static Array prepareSQLArrayOfStrings(List<String> strings, PreparedStatement preparedStatement) throws SQLException
      Take list of String and generate an array in sql database from it. Implementation can be different for every type of supported DB
      Parameters:
      strings - list of Strings to get an sql array from
      preparedStatement - database prepared statement to get working connection
      Returns:
      java sql array with pre-loaded list of strings
      Throws:
      SQLException - if any sql exception has been thrown
      InternalErrorException - if oracle method to work with an array can't be get or invoked
    • createProperty

      void createProperty(String property)
      Create new property in configurations. Initial value will be "N/A".
      Parameters:
      property - name of property to be created
    • getChangelogVersions

      List<DBVersion> getChangelogVersions(String currentDBVersion, String fileName)
      Parses all new database versions from DB changelog file and creates from them list of DBVersion objects. The list contains all versions from currentDBVersion (without currentDBVersion itself) to now (the version at the top of the changelog file)
      Parameters:
      currentDBVersion - current DB version
      fileName - DB changelog file name, file should be in resources
      Returns:
      list of DBVersion objects ordered by version descending
      Throws:
      InternalErrorException - if 1.there is an error reading file, 2.currentDBVersion was not found 3.DBVersion does not match pattern 4.DB versions are not ordered as they should be
    • getCurrentDatabaseVersion

      String getCurrentDatabaseVersion()
      Return current database version in string (ex. 3.0.1)
      Returns:
      return current database version
      Throws:
      InternalErrorException
    • getDatabaseDriverInformation

      String getDatabaseDriverInformation()
      Get DB driver information from datasource (name-version)
      Returns:
      string information about database driver
      Throws:
      InternalErrorException
    • getDatabaseInformation

      String getDatabaseInformation()
      Get DB information from datasource (name-version)
      Returns:
      string information about database
      Throws:
      InternalErrorException
    • getJdbcPerunTemplate

      JdbcPerunTemplate getJdbcPerunTemplate()
      Return JDBC template for performing custom simple SQLs where jdbc is not normally available
      Returns:
      Peruns JDBC template
    • getTimeOfQueryPerformance

      long getTimeOfQueryPerformance()
      Get time in ns "nanoseconds" of calling 1 simple update query to DB. This query will update property for this purpose in configurations table.
      Returns:
      time of processing query in nanoseconds
    • propertyExists

      boolean propertyExists(String property)
      Return true if property already exists, false if not.
      Parameters:
      property - name of property to check existence
      Returns:
      true if property exists, false if not
    • updateDatabaseVersion

      void updateDatabaseVersion(List<DBVersion> dbVersions)
      Method updates database to the current code version. It takes list of dbVersions and executes all the commands from them. Commands from the oldest (lowest) version are executed first.
      Parameters:
      dbVersions - list of dbVersion objects ordered by version descending, should not be empty
      Throws:
      InternalErrorException - if any of the commands fails to execute