dk.netarkivet.harvester.datamodel
Class HarvestDBConnection

java.lang.Object
  extended by dk.netarkivet.harvester.datamodel.HarvestDBConnection

public final class HarvestDBConnection
extends java.lang.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:

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
static void cleanup()
          Closes the underlying data source.
static java.sql.Connection get()
          Get a connection to the harvest definition database from the pool.
static java.lang.String getDBUrl()
          Method for retrieving the url for the harvest definition database.
static void release(java.sql.Connection connection)
          Helper method to return a connection to the pool.
static void updateTable(java.sql.Connection c, java.lang.String table, int newVersion, java.lang.String... updates)
           
protected static void updateTable(java.lang.String table, int newVersion, java.lang.String... updates)
          Update a table by executing all the statements in the updates String array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static java.sql.Connection get()
Get a connection to the harvest definition database from the pool. The pool is configured via the following configuration properties: Note that the connection obtained must be returned to the pool by calling release(Connection).

Returns:
a connection to the harvest definition database
Throws:
IOFailure - if we cannot connect to the database (or find the driver).

updateTable

protected static void updateTable(java.lang.String table,
                                  int newVersion,
                                  java.lang.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(java.sql.Connection c,
                               java.lang.String table,
                               int newVersion,
                               java.lang.String... updates)

getDBUrl

public static java.lang.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(java.sql.Connection connection)
Helper method to return a connection to the pool.

Parameters:
connection - a connection