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. The statements to create the tables are located in:


Constructor Summary
HarvestDefinitionDBDAO()
          Create a new HarvestDefinitionDAO using database.
 
Method Summary
 void addDomainConfiguration(PartialHarvest ph, SparseDomainConfiguration dcKey)
          Add a domainconfiguration to a PartialHarvest.
 java.lang.Long create(HarvestDefinition harvestDefinition)
          Create a harvest definition in Database.
 boolean exists(java.lang.Long oid)
          Check, if there exists a HarvestDefinition identified by a given OID.
 boolean exists(java.lang.String name)
          Check, if there exists a HarvestDefinition identified by a given name.
 void flipActive(SparsePartialHarvest harvestDefinition)
          Activates or deactivates a partial harvest definition.
 java.util.Iterator<HarvestDefinition> getAllHarvestDefinitions()
          Get a list of all existing 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.lang.String getHarvestName(java.lang.Long harvestDefinitionID)
          Get the name of a harvest given its ID.
 java.util.List<HarvestRunInfo> getHarvestRunInfo(long harvestID)
          Returns a list with information on the runs of a particular harvest.
 java.util.Set<java.lang.Long> getJobIdsForSnapshotDeduplicationIndex(java.lang.Long harvestId)
          Get a collection of jobIds for snapshot deduplication index.
 java.util.List<java.lang.String> getListOfDomainsOfHarvestDefinition(java.lang.String harvestName)
          Get a sorted list of all domain names of a HarvestDefinition.
 java.util.List<java.lang.String> getListOfSeedsOfDomainOfHarvestDefinition(java.lang.String harvestName, java.lang.String domainName)
          Get a sorted list of all seeds of a Domain in a HarvestDefinition.
 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.util.List<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 isSnapshot(java.lang.Long harvestDefinitionID)
          Get whether a given harvest is a snapshot or selective harvest.
 HarvestDefinition read(java.lang.Long harvestDefinitionID)
          Read the stored harvest definition for the given ID.
 void removeDomainConfiguration(java.lang.Long harvestId, SparseDomainConfiguration key)
          Remove Domain configuration from a specific PartialHarvest.
 void resetDomainConfigurations(PartialHarvest ph, java.util.List<DomainConfiguration> dcList)
          Reset the list of domainconfiguration for a PartialHarvest.
 void setIndexIsReady(java.lang.Long harvestId, boolean newValue)
          Set the isindexready field available for snapshot harvests.
 void update(HarvestDefinition hd)
          Update an existing harvest definition with new info.
 void updateNextdate(PartialHarvest ph, java.util.Date nextdate)
          Update the given PartialHarvest (i.e.
 
Methods inherited from class dk.netarkivet.harvester.datamodel.HarvestDefinitionDAO
getInstance, 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)

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)

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)

flipActive

public void flipActive(SparsePartialHarvest harvestDefinition)
Activates or deactivates a partial harvest definition. This method is actually to be used not to have to read from the DB big harvest definitions and optimize the activation / deactivation, it is sort of a lightweight version of update.

Specified by:
flipActive in class HarvestDefinitionDAO
Parameters:
harvestDefinition - the harvest definition object.

exists

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

Specified by:
exists in class HarvestDefinitionDAO
Parameters:
name - a given name
Returns:
true, if such a harvestdefinition exists.

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.

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
Parameters:
now - The current date
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.

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. The list is ordered by descending run number.

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

getSparseDomainConfigurations

public java.util.List<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

getHarvestName

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

Specified by:
getHarvestName in class HarvestDefinitionDAO
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 boolean isSnapshot(java.lang.Long harvestDefinitionID)
Get whether a given harvest is a snapshot or selective harvest.

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

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.
UnknownID - if no harvest has the given ID.
IOFailure - on any other error talking to the database

getListOfDomainsOfHarvestDefinition

public java.util.List<java.lang.String> getListOfDomainsOfHarvestDefinition(java.lang.String harvestName)
Get a sorted list of all domain names of a HarvestDefinition.

Specified by:
getListOfDomainsOfHarvestDefinition in class HarvestDefinitionDAO
Parameters:
harvestName - of HarvestDefinition
Returns:
List of all domains of the HarvestDefinition.

getListOfSeedsOfDomainOfHarvestDefinition

public java.util.List<java.lang.String> getListOfSeedsOfDomainOfHarvestDefinition(java.lang.String harvestName,
                                                                                  java.lang.String domainName)
Get a sorted list of all seeds of a Domain in a HarvestDefinition.

Specified by:
getListOfSeedsOfDomainOfHarvestDefinition in class HarvestDefinitionDAO
Parameters:
harvestName - of HarvestDefinition
domainName - of Domain
Returns:
List of all seeds of the Domain in the HarvestDefinition.

getJobIdsForSnapshotDeduplicationIndex

public java.util.Set<java.lang.Long> getJobIdsForSnapshotDeduplicationIndex(java.lang.Long harvestId)
Description copied from class: HarvestDefinitionDAO
Get a collection of jobIds for snapshot deduplication index.

Specified by:
getJobIdsForSnapshotDeduplicationIndex in class HarvestDefinitionDAO
Parameters:
harvestId - the id of the harvest
Returns:
a collection of jobIds to create a deduplication index.

setIndexIsReady

public void setIndexIsReady(java.lang.Long harvestId,
                            boolean newValue)
Description copied from class: HarvestDefinitionDAO
Set the isindexready field available for snapshot harvests.

Specified by:
setIndexIsReady in class HarvestDefinitionDAO
Parameters:
harvestId - the ID of the harvest.
newValue - the new isindexready value

removeDomainConfiguration

public void removeDomainConfiguration(java.lang.Long harvestId,
                                      SparseDomainConfiguration key)
Description copied from class: HarvestDefinitionDAO
Remove Domain configuration from a specific PartialHarvest.

Specified by:
removeDomainConfiguration in class HarvestDefinitionDAO
Parameters:
harvestId - Id for a specific PartialHarvest
key - a SparseDomainConfiguration uniquely identifying the domainconfig.

updateNextdate

public void updateNextdate(PartialHarvest ph,
                           java.util.Date nextdate)
Description copied from class: HarvestDefinitionDAO
Update the given PartialHarvest (i.e. Selective Harvest) with a new time for the next harvestrun.

Specified by:
updateNextdate in class HarvestDefinitionDAO
Parameters:
ph - A given PartialHarvest (i.e. Selective Harvest).
nextdate - A new date for the next harvest run.

addDomainConfiguration

public void addDomainConfiguration(PartialHarvest ph,
                                   SparseDomainConfiguration dcKey)
Description copied from class: HarvestDefinitionDAO
Add a domainconfiguration to a PartialHarvest.

Specified by:
addDomainConfiguration in class HarvestDefinitionDAO
Parameters:
ph - a given PartialHarvest
dcKey - a reduced domainconfiguration object

resetDomainConfigurations

public void resetDomainConfigurations(PartialHarvest ph,
                                      java.util.List<DomainConfiguration> dcList)
Description copied from class: HarvestDefinitionDAO
Reset the list of domainconfiguration for a PartialHarvest.

Specified by:
resetDomainConfigurations in class HarvestDefinitionDAO
Parameters:
ph - a given PartialHarvest
dcList - the new list of domainconfigurations