Class HarvestDBConnection
- java.lang.Object
-
- dk.netarkivet.harvester.datamodel.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
cleanup()
Closes the underlying data source.static void
executeSql(String dbm, String tableName, int version)
Execute the sql to update a given table to a given version.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.static Connection
get()
Get a connection to the harvest definition database from the pool.static String
getDBUrl()
Method for retrieving the url for the harvest definition database.static void
release(Connection connection)
Helper method to return a connection to the pool.protected static void
updateTable(String table, int newVersion, String... updates)
Update a table by executing all the statements in the updates String array.static void
updateTable(Connection c, String table, int newVersion, String... updates)
protected static void
updateTableVersion(String table, int newVersion, String... updates)
static void
updateTableVersion(Connection c, String table, int newVersion)
-
-
-
Method Detail
-
get
public static Connection get()
Get a connection to the harvest definition database from the pool. The pool is configured via the following configuration properties:- @see
CommonSettings.DB_POOL_MIN_SIZE
- @see
CommonSettings.DB_POOL_MAX_SIZE
- @see
CommonSettings.DB_POOL_ACQ_INC
release(Connection)
.- Returns:
- a connection to the harvest definition database
- Throws:
IOFailure
- if we cannot connect to the database (or find the driver).
- @see
-
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 updatenewVersion
- The version that the table should end up atupdates
- 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 updateversion
- 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 connectiondbm
- the name of the DBMS usedtableName
- the name of the table being updatedversion
- The new version of the table
-
-