dk.netarkivet.harvester.datamodel
Class HarvestDefinitionDAO

java.lang.Object
  extended by dk.netarkivet.harvester.datamodel.HarvestDefinitionDAO
All Implemented Interfaces:
java.lang.Iterable<HarvestDefinition>
Direct Known Subclasses:
HarvestDefinitionDBDAO

public abstract class HarvestDefinitionDAO
extends java.lang.Object
implements java.lang.Iterable<HarvestDefinition>

A Data Access Object for harvest definitions. This object is a singleton to ensure thread-safety. It handles the transformation from harvest definitions to persistent storage.


Field Summary
protected  org.apache.commons.logging.Log log
          The log.
 
Constructor Summary
protected HarvestDefinitionDAO()
          Default constructor.
 
Method Summary
abstract  java.lang.Long create(HarvestDefinition harvestDefinition)
          Create a harvest definition in persistent storage.
abstract  void delete(java.lang.Long oid)
          Delete a harvest definition from persistent storage.
abstract  java.lang.String describeUsages(java.lang.Long oid)
          Return a string describing the current uses of a harvest definition, or null if the harvest definition is safe to delete (i.e.
 java.lang.Long editHarvestDefinition(java.lang.Long harvestDefinitionID, HarvestDefinition harvestDefinition)
          Edit the harvestdefinition.
abstract  boolean exists(java.lang.Long oid)
          Check, if there exists a HarvestDefinition identified by a given OID.
 void generateJobs(java.util.Date now)
          Generate new jobs for the harvestdefinitions in persistent storage.
protected abstract  java.lang.Long generateNextID()
          Generates the next id of a harvest definition.
abstract  java.util.Iterator<FullHarvest> getAllFullHarvestDefinitions()
          Returns an iterator of all snapshot harvest definitions.
abstract  java.util.Iterator<HarvestDefinition> getAllHarvestDefinitions()
          Get a list of all existing harvest definitions.
abstract  java.util.Iterator<PartialHarvest> getAllPartialHarvestDefinitions()
          Returns an iterator of all non-snapshot harvest definitions.
abstract  java.lang.Iterable<SparseFullHarvest> getAllSparseFullHarvestDefinitions()
          Get all sparse versions of full harvests for GUI purposes.
abstract  java.lang.Iterable<SparsePartialHarvest> getAllSparsePartialHarvestDefinitions()
          Get all sparse versions of partial harvests for GUI purposes.
abstract  HarvestDefinition getHarvestDefinition(java.lang.String name)
          Get the harvest definition that has the given name, or null, if no harvestdefinition exist with this name.
abstract  java.lang.String getHarvestName(java.lang.Long harvestDefinitionID)
          Get the name of a harvest given its ID.
abstract  java.util.List<HarvestRunInfo> getHarvestRunInfo(long harvestID)
          Returns a list with information on the runs of a particular harvest.
static HarvestDefinitionDAO getInstance()
          Creates the singleton.
abstract  java.lang.Iterable<java.lang.Long> getReadyHarvestDefinitions(java.util.Date now)
          Get the IDs of the harvest definitions that are ready to run.
abstract  java.util.Iterator<DomainConfiguration> getSnapShotConfigurations()
          Gets default configurations for all domains.
abstract  java.lang.Iterable<SparseDomainConfiguration> getSparseDomainConfigurations(java.lang.Long harvestDefinitionID)
          Get all domain,configuration pairs for a harvest definition in sparse version for GUI purposes.
abstract  SparseFullHarvest getSparseFullHarvest(java.lang.String harvestName)
          Get a sparse version of a full harvest for GUI purposes.
abstract  SparsePartialHarvest getSparsePartialHarvest(java.lang.String harvestName)
          Get a sparse version of a partial harvest for GUI purposes.
 boolean isGeneratingJobs()
          Returns true if any harvestdefinition is in the middle of having jobs scheduled.
abstract  boolean isSnapshot(java.lang.Long harvestDefinitionID)
          Get whether a given harvest is a snapshot or selective harvest.
 java.util.Iterator<HarvestDefinition> iterator()
          Get an iterator of all harvest definitions.
abstract  boolean mayDelete(HarvestDefinition hd)
          Return whether the given harvestdefinition can be deleted.
abstract  HarvestDefinition read(java.lang.Long harvestDefinitionID)
          Read the stored harvest definition for the given ID.
(package private) static void reset()
          Reset the DAO instance.
abstract  void update(HarvestDefinition harvestDefinition)
          Update an existing harvest definition with new info in persistent storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log
The log.

Constructor Detail

HarvestDefinitionDAO

protected HarvestDefinitionDAO()
Default constructor. Does not do anything, however.

Method Detail

getInstance

public static HarvestDefinitionDAO getInstance()
Creates the singleton.

Returns:
the HarvestDefinitionDAO singleton.
Throws:
IOFailure - if unable to create the singleton.

create

public abstract java.lang.Long create(HarvestDefinition harvestDefinition)
Create a harvest definition in persistent storage.

Parameters:
harvestDefinition - A new harvest definition to write out.
Returns:
The harvestId for the just created harvest definition.

generateNextID

protected abstract java.lang.Long generateNextID()
Generates the next id of a harvest definition. TODO: Maybe this method is not needed in this superclass as an abstract method. It is really only a helper method for the create() method.

Returns:
id The next available id.

read

public abstract HarvestDefinition read(java.lang.Long harvestDefinitionID)
                                throws UnknownID,
                                       IOFailure
Read the stored harvest definition for the given ID.

Parameters:
harvestDefinitionID - An ID number for a harvest definition
Returns:
A harvest definition that has been read from persistent storage.
Throws:
UnknownID - if no file with that ID exists
IOFailure - if the File does not exist, does not have the correct ID, or otherwise fails to load correctly.

describeUsages

public abstract java.lang.String describeUsages(java.lang.Long oid)
Return a string describing the current uses of a harvest definition, or null if the harvest definition is safe to delete (i.e. has never been run).

Parameters:
oid - a given identifier designating a harvest definition.
Returns:
the above mentioned usage-string.

delete

public abstract void delete(java.lang.Long oid)
Delete a harvest definition from persistent storage.

Parameters:
oid - The ID of a harvest definition to delete.

update

public abstract void update(HarvestDefinition harvestDefinition)
Update an existing harvest definition with new info in persistent storage.

Parameters:
harvestDefinition - An updated harvest definition object to be persisted.

exists

public abstract boolean exists(java.lang.Long oid)
Check, if there exists a HarvestDefinition identified by a given OID.

Parameters:
oid - a given OID
Returns:
true, if such a harvestdefinition exists.

getAllHarvestDefinitions

public abstract java.util.Iterator<HarvestDefinition> getAllHarvestDefinitions()
Get a list of all existing harvest definitions.

Returns:
An iterator that give the existing harvest definitions in turn

iterator

public java.util.Iterator<HarvestDefinition> iterator()
Get an iterator of all harvest definitions. Implements the Iterable interface.

Specified by:
iterator in interface java.lang.Iterable<HarvestDefinition>
Returns:
Iterator of all harvest definitions, Selective and Full both.

getSnapShotConfigurations

public abstract java.util.Iterator<DomainConfiguration> getSnapShotConfigurations()
Gets default configurations for all domains.

Returns:
Iterator containing the default DomainConfiguration for all domains

editHarvestDefinition

public java.lang.Long editHarvestDefinition(java.lang.Long harvestDefinitionID,
                                            HarvestDefinition harvestDefinition)
Edit the harvestdefinition.

Parameters:
harvestDefinitionID - The ID for the harvestdefintion to be updated
harvestDefinition - the HarvestDefinition object to used to update harvestdefinition with the above ID
Returns:
the ID for the updated harvestdefinition (this should be equal to harvestDefinitionID?)

generateJobs

public void generateJobs(java.util.Date now)
Generate new jobs for the harvestdefinitions in persistent storage.

Parameters:
now - The current time (hopefully)

getReadyHarvestDefinitions

public abstract java.lang.Iterable<java.lang.Long> getReadyHarvestDefinitions(java.util.Date now)
Get the IDs of the harvest definitions that are ready to run.

Parameters:
now -
Returns:
IDs of the harvest definitions that are currently ready to be scheduled. Some of these might already be in the process of being scheduled.

getHarvestDefinition

public abstract HarvestDefinition getHarvestDefinition(java.lang.String name)
Get the harvest definition that has the given name, or null, if no harvestdefinition exist with this name.

Parameters:
name - The name of a harvest definition.
Returns:
The HarvestDefinition object with that name, or null if none has that name.

getAllFullHarvestDefinitions

public abstract java.util.Iterator<FullHarvest> getAllFullHarvestDefinitions()
Returns an iterator of all snapshot harvest definitions.

Returns:
An iterator (possibly empty) of FullHarvests

getAllPartialHarvestDefinitions

public abstract java.util.Iterator<PartialHarvest> getAllPartialHarvestDefinitions()
Returns an iterator of all non-snapshot harvest definitions.

Returns:
An iterator (possibly empty) of PartialHarvests

getHarvestRunInfo

public abstract java.util.List<HarvestRunInfo> getHarvestRunInfo(long harvestID)
Returns a list with information on the runs of a particular harvest.

Parameters:
harvestID - ID of an existing harvest
Returns:
List of objects with selected information.

reset

static void reset()
Reset the DAO instance. Only for use in tests.


isGeneratingJobs

public boolean isGeneratingJobs()
Returns true if any harvestdefinition is in the middle of having jobs scheduled. Notice that this synchronizes with generateJobs.

Returns:
true if there is at least one harvestdefinition currently scheduling jobs.

mayDelete

public abstract boolean mayDelete(HarvestDefinition hd)
Return whether the given harvestdefinition can be deleted. This should be a fairly lightweight method, but is not likely to be instantaneous. Note that to increase speed, this method may rely on underlying systems to enforce transitive invariants. This means that if this method says a harvestdefinition can be deleted, the dao may still reject a delete request. If this method returns false, deletion will however definitely not be allowed.

Parameters:
hd - A given harvestdefinition
Returns:
true, if this HarvestDefinition can be deleted without problems.

getSparseDomainConfigurations

public abstract java.lang.Iterable<SparseDomainConfiguration> getSparseDomainConfigurations(java.lang.Long harvestDefinitionID)
Get all domain,configuration pairs for a harvest definition in sparse version for GUI purposes.

Parameters:
harvestDefinitionID - The ID of the harvest definition.
Returns:
Domain,configuration pairs for that HD. Returns an empty iterable for unknown harvest definitions.
Throws:
ArgumentNotValid - on null argument.

getSparsePartialHarvest

public abstract SparsePartialHarvest getSparsePartialHarvest(java.lang.String harvestName)
Get a sparse version of a partial harvest for GUI purposes.

Parameters:
harvestName - Name of harvest definition.
Returns:
Sparse version of partial harvest or null for none.
Throws:
ArgumentNotValid - on null or empty name.

getAllSparsePartialHarvestDefinitions

public abstract java.lang.Iterable<SparsePartialHarvest> getAllSparsePartialHarvestDefinitions()
Get all sparse versions of partial harvests for GUI purposes.

Returns:
An iterable (possibly empty) of SparsePartialHarvests

getSparseFullHarvest

public abstract SparseFullHarvest getSparseFullHarvest(java.lang.String harvestName)
Get a sparse version of a full harvest for GUI purposes.

Parameters:
harvestName - Name of harvest definition.
Returns:
Sparse version of full harvest or null for none.
Throws:
ArgumentNotValid - on null or empty name.

getAllSparseFullHarvestDefinitions

public abstract java.lang.Iterable<SparseFullHarvest> getAllSparseFullHarvestDefinitions()
Get all sparse versions of full harvests for GUI purposes.

Returns:
An iterable (possibly empty) of SparseFullHarvests

getHarvestName

public abstract java.lang.String getHarvestName(java.lang.Long harvestDefinitionID)
Get the name of a harvest given its ID.

Parameters:
harvestDefinitionID - The ID of a harvest
Returns:
The name of the given harvest.
Throws:
ArgumentNotValid - on null argument
UnknownID - if no harvest has the given ID.
IOFailure - on any other error talking to the database

isSnapshot

public abstract boolean isSnapshot(java.lang.Long harvestDefinitionID)
Get whether a given harvest is a snapshot or selective harvest.

Parameters:
harvestDefinitionID - ID of a harvest
Returns:
True if the given harvest is a snapshot harvest, false otherwise.
Throws:
ArgumentNotValid - on null argument
UnknownID - if no harvest has the given ID.
IOFailure - on any other error talking to the database