dk.netarkivet.harvester.datamodel
Class DBSpecifics

java.lang.Object
  extended by dk.netarkivet.common.utils.SettingsFactory<DBSpecifics>
      extended by dk.netarkivet.harvester.datamodel.DBSpecifics
Direct Known Subclasses:
DerbySpecifics, MySQLSpecifics

public abstract class DBSpecifics
extends SettingsFactory<DBSpecifics>

Abstract collection of DB methods that are not standard SQL. This class is a singleton class whose actual implementation is provided by a subclass as determined by the DB_SPECIFICS_CLASS setting.


Field Summary
(package private)  org.apache.commons.logging.Log log
           
 
Constructor Summary
DBSpecifics()
           
 
Method Summary
abstract  void backupDatabase(java.io.File backupDir)
          Backup the database.
abstract  void dropJobConfigsTmpTable(java.sql.Connection c, java.lang.String tableName)
          Dispose of a temporary table gotten with getTemporaryTable.
abstract  java.lang.String getDriverClassName()
          Get the name of the JDBC driver class that handles interfacing to this server.
static DBSpecifics getInstance()
          Get the singleton instance of the DBSpecifics implementation class.
abstract  java.lang.String getJobConfigsTmpTable(java.sql.Connection c)
          Get a temporary table for short-time use.
protected abstract  void migrateConfigurationsv3ov4()
          Migrates the 'configurations' table from version 3 to version 4.
protected abstract  void migrateFullharvestsv2tov3()
          Migrates the 'fullharvests' table from version 2 to version 3.
protected abstract  void migrateJobsv3tov4()
          Migrates the 'jobs' table from version 3 to version 4 consisting of a change of the field forcemaxbytes from int to bigint and setting its default to -1.
protected abstract  void migrateJobsv4tov5()
          Migrates the 'jobs' table from version 4 to version 5 consisting of adding new fields 'resubmitted_as_job' and 'submittedDate'.
abstract  void shutdownDatabase()
          Shutdown the database system, if running embeddedly.
 void updateTable(java.lang.String tableName, int toVersion)
          Update a table to a newer version, if necessary.
 
Methods inherited from class dk.netarkivet.common.utils.SettingsFactory
getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

org.apache.commons.logging.Log log
Constructor Detail

DBSpecifics

public DBSpecifics()
Method Detail

getInstance

public static DBSpecifics getInstance()
Get the singleton instance of the DBSpecifics implementation class.

Returns:
An instance of DBSpecifics with implementations for a given DB.

shutdownDatabase

public abstract void shutdownDatabase()
Shutdown the database system, if running embeddedly. Otherwise, this is ignored. Will log a warning on errors, but otherwise ignore them.


getJobConfigsTmpTable

public abstract java.lang.String getJobConfigsTmpTable(java.sql.Connection c)
                                                throws java.sql.SQLException
Get a temporary table for short-time use. The table should be disposed of with dropTemporaryTable. The table has two columns domain_name varchar(Constants.MAX_NAME_SIZE) + config_name varchar(Constants.MAX_NAME_SIZE) All rows in the table must be deleted at commit or rollback.

Parameters:
c - The DB connection to use.
Returns:
The name of the created table
Throws:
java.sql.SQLException - if there is a problem getting the table.

dropJobConfigsTmpTable

public abstract void dropJobConfigsTmpTable(java.sql.Connection c,
                                            java.lang.String tableName)
Dispose of a temporary table gotten with getTemporaryTable. This can be expected to be called from within a finally clause, so it mustn't throw exceptions.

Parameters:
c - The DB connection to use.
tableName - The name of the temporarily created table.

backupDatabase

public abstract void backupDatabase(java.io.File backupDir)
                             throws java.sql.SQLException
Backup the database. For server-based databases, where the administrator is expected to perform the backups, this method should do nothing. This method gets called within one hour of the hour-of-day indicated by the DB_BACKUP_INIT_HOUR settings.

Parameters:
backupDir - Directory to which the database should be backed up
Throws:
java.sql.SQLException
PermissionDenied - if the directory cannot be created.

getDriverClassName

public abstract java.lang.String getDriverClassName()
Get the name of the JDBC driver class that handles interfacing to this server.

Returns:
The name of a JDBC driver class

updateTable

public void updateTable(java.lang.String tableName,
                        int toVersion)
Update a table to a newer version, if necessary. This will check the schemaversions table to see the current version and perform a table-specific update if required.

Parameters:
tableName - The table to update
toVersion - The version to update the table to.
Throws:
IllegalState - If the table is an unsupported version, and the toVersion is less than the current version of the table
NotImplementedException - If no method exists for migration from current version of the table to the toVersion of the table.
IOFailure - in case of problems in interacting with the database

migrateJobsv3tov4

protected abstract void migrateJobsv3tov4()
Migrates the 'jobs' table from version 3 to version 4 consisting of a change of the field forcemaxbytes from int to bigint and setting its default to -1. Furthermore the default value for field num_configs is set to 0.

Throws:
IOFailure - in case of problems in interacting with the database

migrateJobsv4tov5

protected abstract void migrateJobsv4tov5()
Migrates the 'jobs' table from version 4 to version 5 consisting of adding new fields 'resubmitted_as_job' and 'submittedDate'.

Throws:
IOFailure - in case of problems in interacting with the database

migrateConfigurationsv3ov4

protected abstract void migrateConfigurationsv3ov4()
Migrates the 'configurations' table from version 3 to version 4. This consists of altering the default value of field 'maxbytes' to -1.


migrateFullharvestsv2tov3

protected abstract void migrateFullharvestsv2tov3()
Migrates the 'fullharvests' table from version 2 to version 3. This consists of altering the default value of field 'maxbytes' to -1.