dk.netarkivet.harvester.datamodel
Class HarvestDefinitionDBDAO

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

public class HarvestDefinitionDBDAO
extends HarvestDefinitionDAO

A database-oriented implementation of the HarvestDefinitionDAO. Statements to create the tables are in scripts/sql/createfullhddb.sql


Constructor Summary
HarvestDefinitionDBDAO()
          Create a new HarvestDefinitionDAO using database.
 
Method Summary
 java.lang.Long create(HarvestDefinition harvestDefinition)
          Create a harvest definition in Database.
 void delete(java.lang.Long oid)
          Delete a harvest definition from persistent storage.
 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.
 boolean exists(java.lang.Long oid)
          Check, if there exists a HarvestDefinition identified by a given OID.
protected  java.lang.Long generateNextID()
          Generates the next id of a harvest definition.
 java.util.Iterator<FullHarvest> getAllFullHarvestDefinitions()
          Returns an iterator of all snapshot harvest definitions ordered by name.
 java.util.Iterator<HarvestDefinition> getAllHarvestDefinitions()
          Get a list of all existing harvest definitions ordered by name.
 java.util.Iterator<PartialHarvest> getAllPartialHarvestDefinitions()
          Returns an iterator of all non-snapshot harvest definitions ordered by name.
 java.lang.Iterable<SparseFullHarvest> getAllSparseFullHarvestDefinitions()
          Get all sparse versions of full harvests for GUI purposes.
 java.lang.Iterable<SparsePartialHarvest> getAllSparsePartialHarvestDefinitions()
          Get all sparse versions of partial harvests for GUI purposes.
 HarvestDefinition getHarvestDefinition(java.lang.String name)
          Get the harvest definition that has the given name, if any.
 java.util.List<HarvestRunInfo> getHarvestRunInfo(long harvestID)
          Returns a list with information on the runs of a particular harvest.
 java.lang.Iterable<java.lang.Long> getReadyHarvestDefinitions(java.util.Date now)
          Returns a list of IDs of harvest definitions that are ready to be scheduled.
 java.util.Iterator<DomainConfiguration> getSnapShotConfigurations()
          Gets default configurations for all domains that are not aliases.
 java.lang.Iterable<SparseDomainConfiguration> getSparseDomainConfigurations(java.lang.Long harvestDefinitionID)
          Get all domain,configuration pairs for a harvest definition in sparse version for GUI purposes.
 SparseFullHarvest getSparseFullHarvest(java.lang.String harvestName)
          Get a sparse version of a full harvest for GUI purposes.
 SparsePartialHarvest getSparsePartialHarvest(java.lang.String harvestName)
          Get a sparse version of a partial harvest for GUI purposes.
 boolean mayDelete(HarvestDefinition hd)
          Return whether the given harvestdefinition can be deleted.
 HarvestDefinition read(java.lang.Long harvestDefinitionID)
          Read the stored harvest definition for the given ID.
 void update(HarvestDefinition hd)
          Update an existing harvest definition with new info.
 
Methods inherited from class dk.netarkivet.harvester.datamodel.HarvestDefinitionDAO
editHarvestDefinition, generateJobs, getInstance, isGeneratingJobs, iterator, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HarvestDefinitionDBDAO

HarvestDefinitionDBDAO()
Create a new HarvestDefinitionDAO using database.

Method Detail

create

public java.lang.Long create(HarvestDefinition harvestDefinition)
Create a harvest definition in Database. The harvest definition object should not have its ID set unless we are in the middle of migrating.

Specified by:
create in class HarvestDefinitionDAO
Parameters:
harvestDefinition - A new harvest definition to store in the database.
Returns:
The harvestId for the just created harvest definition.
See Also:
HarvestDefinitionDAO.create(HarvestDefinition)

generateNextID

protected java.lang.Long generateNextID()
Generates the next id of a harvest definition. this implementation retrieves the maximum value of harvest_id in the DB, and returns this value + 1.

Specified by:
generateNextID in class HarvestDefinitionDAO
Returns:
The next available ID
See Also:
HarvestDefinitionDAO.generateNextID()

read

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

Specified by:
read in class HarvestDefinitionDAO
Parameters:
harvestDefinitionID - An ID number for a harvest definition
Returns:
A harvest definition that has been read from persistent storage.
Throws:
UnknownID - if no entry with that ID exists in the database
IOFailure - If DB-failure occurs?
See Also:
HarvestDefinitionDAO.read(Long)

describeUsages

public java.lang.String describeUsages(java.lang.Long oid)
Description copied from class: HarvestDefinitionDAO
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).

Specified by:
describeUsages in class HarvestDefinitionDAO
Parameters:
oid - a given identifier designating a harvest definition.
Returns:
the above mentioned usage-string.

delete

public void delete(java.lang.Long oid)
Delete a harvest definition from persistent storage. You cannot delete a harvest definition that is referenced by jobs or harvestinfo.

Specified by:
delete in class HarvestDefinitionDAO
Parameters:
oid - The ID of a harvest definition to delete.
See Also:
HarvestDefinitionDAO.delete(Long)

update

public void update(HarvestDefinition hd)
Update an existing harvest definition with new info.

Specified by:
update in class HarvestDefinitionDAO
Parameters:
hd - An updated harvest definition
See Also:
HarvestDefinitionDAO.update(HarvestDefinition)

exists

public boolean exists(java.lang.Long oid)
Description copied from class: HarvestDefinitionDAO
Check, if there exists a HarvestDefinition identified by a given OID.

Specified by:
exists in class HarvestDefinitionDAO
Parameters:
oid - a given OID
Returns:
true, if such a harvestdefinition exists.
See Also:
HarvestDefinitionDAO.exists(Long)

getAllHarvestDefinitions

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

Specified by:
getAllHarvestDefinitions in class HarvestDefinitionDAO
Returns:
An iterator that give the existing harvest definitions in turn

getSnapShotConfigurations

public java.util.Iterator<DomainConfiguration> getSnapShotConfigurations()
Gets default configurations for all domains that are not aliases. This method currently gives an iterator that reads in all domains, although only on demand, that is: when calling "hasNext".

Specified by:
getSnapShotConfigurations in class HarvestDefinitionDAO
Returns:
Iterator containing the default DomainConfiguration for all domains that are not aliases

getReadyHarvestDefinitions

public java.lang.Iterable<java.lang.Long> getReadyHarvestDefinitions(java.util.Date now)
Returns a list of IDs of harvest definitions that are ready to be scheduled.

Specified by:
getReadyHarvestDefinitions in class HarvestDefinitionDAO
Returns:
List of ready harvest definitions. No check is performed for whether these are already in the middle of being scheduled.

getHarvestDefinition

public HarvestDefinition getHarvestDefinition(java.lang.String name)
Get the harvest definition that has the given name, if any.

Specified by:
getHarvestDefinition in class HarvestDefinitionDAO
Parameters:
name - The name of a harvest definition.
Returns:
The HarvestDefinition object with that name, or null if none has that name.

getAllFullHarvestDefinitions

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

Specified by:
getAllFullHarvestDefinitions in class HarvestDefinitionDAO
Returns:
An iterator (possibly empty) of FullHarvests
See Also:
HarvestDefinitionDAO.getAllFullHarvestDefinitions()

getAllPartialHarvestDefinitions

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

Specified by:
getAllPartialHarvestDefinitions in class HarvestDefinitionDAO
Returns:
An iterator (possibly empty) of PartialHarvests
See Also:
HarvestDefinitionDAO.getAllPartialHarvestDefinitions()

getHarvestRunInfo

public java.util.List<HarvestRunInfo> getHarvestRunInfo(long harvestID)
Description copied from class: HarvestDefinitionDAO
Returns a list with information on the runs of a particular harvest.

Specified by:
getHarvestRunInfo in class HarvestDefinitionDAO
Parameters:
harvestID - ID of an existing harvest
Returns:
List of objects with selected information.

mayDelete

public boolean mayDelete(HarvestDefinition hd)
Description copied from class: HarvestDefinitionDAO
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.

Specified by:
mayDelete in class HarvestDefinitionDAO
Parameters:
hd - A given harvestdefinition
Returns:
true, if this HarvestDefinition can be deleted without problems.

getSparseDomainConfigurations

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

Specified by:
getSparseDomainConfigurations in class HarvestDefinitionDAO
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.

getAllSparsePartialHarvestDefinitions

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

Specified by:
getAllSparsePartialHarvestDefinitions in class HarvestDefinitionDAO
Returns:
An iterable (possibly empty) of SparsePartialHarvests

getSparsePartialHarvest

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

Specified by:
getSparsePartialHarvest in class HarvestDefinitionDAO
Parameters:
harvestName - Name of harvest definition.
Returns:
Sparse version of partial harvest or null for none.
Throws:
ArgumentNotValid - on null or empty name.

getAllSparseFullHarvestDefinitions

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

Specified by:
getAllSparseFullHarvestDefinitions in class HarvestDefinitionDAO
Returns:
An iterable (possibly empty) of SparseFullHarvests

getSparseFullHarvest

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

Specified by:
getSparseFullHarvest in class HarvestDefinitionDAO
Parameters:
harvestName - Name of harvest definition.
Returns:
Sparse version of full harvest or null for none.
Throws:
ArgumentNotValid - on null or empty name.