Class HarvestDBConnection


  • public final class HarvestDBConnection
    extends Object
    This class handles connections to the harvest definition database, and also defines basic logic for checking versions of tables.

    The statements to create the tables are located in:

    • Derby: scripts/sql/createfullhddb.sql
    • MySQL: scripts/sql/createfullhddb.mysql
    • PostgreSQL: scripts/postgresql/netarchivesuite_init.sql

    The implementation relies on a connection pool. Once acquired through the get() method, a connection must be explicitly returned to the pool by calling the release(Connection) method.

    THis class is intended to be used statically, and hence cannot be instantiated and is final.

    • Method Detail

      • updateTable

        protected static void updateTable​(String table,
                                          int newVersion,
                                          String... updates)
        Update a table by executing all the statements in the updates String array. If newVersion=1 then the table is created. Note that this method does not make any checks that the SQL statements in the updates parameter actually update or create the correct table.
        Parameters:
        table - The table to update
        newVersion - The version that the table should end up at
        updates - The SQL update statements that makes the necessary updates.
        Throws:
        IOFailure - in case of problems in interacting with the database
      • updateTable

        public static void updateTable​(Connection c,
                                       String table,
                                       int newVersion,
                                       String... updates)
      • updateTableVersion

        protected static void updateTableVersion​(String table,
                                                 int newVersion,
                                                 String... updates)
      • updateTableVersion

        public static void updateTableVersion​(Connection c,
                                              String table,
                                              int newVersion)
      • getDBUrl

        public static String getDBUrl()
        Method for retrieving the url for the harvest definition database. This url will be constructed from the base-url, the machine, the port and the directory. If the database is internal, then only the base-url should have a value.
        Returns:
        The url for the harvest definition database.
      • cleanup

        public static void cleanup()
        Closes the underlying data source.
      • release

        public static void release​(Connection connection)
        Helper method to return a connection to the pool.
        Parameters:
        connection - a connection
      • executeSql

        public static void executeSql​(String dbm,
                                      String tableName,
                                      int version)
        Execute the sql to update a given table to a given version. The necessary scripts are bundled into the root of the harvester-core.jar in the directory sql-migration. The source of these scripts are in one of these directories: $BASEDIR/deploy/deploy-core/scripts/postgresql/migration/ $BASEDIR/deploy/deploy-core/scripts/mysql/migration/ $BASEDIR/deploy/deploy-core/scripts/derby/migration/ To allow the user to update table 'eav_attribute' in postgresql to version 1 the file $BASEDIR/deploy/deploy-core/scripts/postgresql/migration/eav_attribute.1.sql must exist The postgresql files are during the build-phase put into the sql-migration/postgresql directory The same holds for mysql and derby.
        Parameters:
        dbm - the type of DBMS (mysql, postgresql,derby)
        tableName - The given table to update
        version - The table version to update to
      • executeSql

        public static void executeSql​(Connection conn,
                                      String dbm,
                                      String tableName,
                                      int version)
        Look for the file sql-migration/${dbm}/${tableName}.${version}.sql inside in the harvester-core.jar file.
        Parameters:
        conn - a valid database connection
        dbm - the name of the DBMS used
        tableName - the name of the table being updated
        version - The new version of the table