dk.netarkivet.harvester.datamodel
Class DomainDAO

java.lang.Object
  extended by dk.netarkivet.harvester.datamodel.DomainDAO
All Implemented Interfaces:
java.lang.Iterable<Domain>
Direct Known Subclasses:
DomainDBDAO

public abstract class DomainDAO
extends java.lang.Object
implements java.lang.Iterable<Domain>

Persistent storage for Domain objects. Configuration information and seeds are stored as well.


Constructor Summary
protected DomainDAO()
          protected constructor for singleton class.
 
Method Summary
abstract  void close()
          Close down any connections used by the DAO.
abstract  void create(Domain domain)
          Create a domain in persistent storage.
abstract  void delete(java.lang.String domainName)
          Delete domain from persistent storage.
abstract  java.lang.String describeUsages(java.lang.String domainName)
          Check where a domain is being used.
abstract  boolean exists(java.lang.String domainName)
          Check existence of a domain with the given domainName.
abstract  java.util.List<AliasInfo> getAliases(java.lang.String domain)
          Return a list of AliasInfo objects.
abstract  java.util.List<AliasInfo> getAllAliases()
          Get a list of all current alias-relations.
abstract  java.util.Iterator<Domain> getAllDomains()
          Gets list of all domains.
abstract  java.util.Iterator<Domain> getAllDomainsInSnapshotHarvestOrder()
          Gets list of all domains in the order expected by snapshot harvest job generation, that is order by template name, then byte limit (descending), then domain name.
abstract  int getCountDomains()
          Get the total number of domains available.
abstract  int getCountDomains(java.lang.String glob)
          Find the number of domains matching a given glob.
abstract  java.util.List<DomainHarvestInfo> getDomainHarvestInfo(java.lang.String domainName)
          Get a list of info about harvests performed on a given domain.
abstract  HarvestInfo getDomainJobInfo(Job job, java.lang.String domainName, java.lang.String configName)
          Get the HarvestInfo object for a certain job and DomainConfiguration defined by domainName and configName.
abstract  java.util.List<java.lang.String> getDomains(java.lang.String glob)
          Use a glob-like matcher to find a subset of domains.
 java.util.Iterator<HarvestInfo> getHarvestInfoBasedOnPreviousHarvestDefinition(HarvestDefinition previousHarvestDefinition)
          Find all info about results of a harvest definition.
static DomainDAO getInstance()
          Get the singleton DomainDAO instance.
abstract  java.util.List<TLDInfo> getTLDs()
          Get a list of all TLDs present in the domains table.
 java.util.Iterator<Domain> iterator()
          Gets an iterator of all domains.
abstract  boolean mayDelete(Domain domainName)
          Return whether the given domain can be deleted.
abstract  boolean mayDelete(DomainConfiguration config)
          Return whether the given configuration can be deleted.
abstract  boolean mayDelete(Password password)
          Return whether the given password can be deleted.
abstract  boolean mayDelete(SeedList seedlist)
          Return whether the given seedlist can be deleted.
abstract  Domain read(java.lang.String domainName)
          Read a domain from the persistent storage.
abstract  SparseDomain readSparse(java.lang.String domainName)
          Read a Domain from Database, and return the domain information as a SparseDomain object.
(package private) static void resetSingleton()
          Reset the singleton.
abstract  void update(Domain domain)
          Update information about existing domain information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomainDAO

protected DomainDAO()
protected constructor for singleton class.

Method Detail

getInstance

public static DomainDAO getInstance()
Get the singleton DomainDAO instance.

Returns:
the singleton DomainDAO

create

public abstract void create(Domain domain)
Create a domain in persistent storage.

Parameters:
domain - a given Domain object

read

public abstract Domain read(java.lang.String domainName)
Read a domain from the persistent storage.

Parameters:
domainName - the name of the domain to retrieve
Returns:
the retrieved Domain

exists

public abstract boolean exists(java.lang.String domainName)
Check existence of a domain with the given domainName.

Parameters:
domainName - A given domain name.
Returns:
true if the domain exists, false otherwise.
Throws:
ArgumentNotValid - if domainName is null or empty.

describeUsages

public abstract java.lang.String describeUsages(java.lang.String domainName)
Check where a domain is being used. This method is this way to check if a domain can be deleted.

Parameters:
domainName - A domain to check for usages of.
Returns:
A string explaining (in human-readable format) where the domain has been used. If it hasn't been used in any place that would prevent it from being deleted, returns null.

delete

public abstract void delete(java.lang.String domainName)
Delete domain from persistent storage.

Parameters:
domainName - name of the domain to delete
Throws:
ArgumentNotValid - if null or empty domainName supplied
UnknownID - if domainName does not match an existing domain
PermissionDenied - if the domain can not be deleted

update

public abstract void update(Domain domain)
Update information about existing domain information.

Parameters:
domain - the domain to update
Throws:
ArgumentNotValid - if domain is null
UnknownID - if the Domain domain has not been added previously to persistent storage.

getCountDomains

public abstract int getCountDomains()
Get the total number of domains available.

Returns:
the total number of registered domanis.

getAllDomains

public abstract java.util.Iterator<Domain> getAllDomains()
Gets list of all domains.

Returns:
List of all added domains

iterator

public java.util.Iterator<Domain> iterator()
Gets an iterator of all domains. Implements the Iterable interface.

Specified by:
iterator in interface java.lang.Iterable<Domain>
Returns:
Iterator of all presently known domains.

getAllDomainsInSnapshotHarvestOrder

public abstract java.util.Iterator<Domain> getAllDomainsInSnapshotHarvestOrder()
Gets list of all domains in the order expected by snapshot harvest job generation, that is order by template name, then byte limit (descending), then domain name.

Returns:
List of all added domains

resetSingleton

static void resetSingleton()
Reset the singleton. Only for use in tests!


getHarvestInfoBasedOnPreviousHarvestDefinition

public java.util.Iterator<HarvestInfo> getHarvestInfoBasedOnPreviousHarvestDefinition(HarvestDefinition previousHarvestDefinition)
Find all info about results of a harvest definition.

Parameters:
previousHarvestDefinition - A harvest definition that has already been run.
Returns:
An array of information for all domainconfigurations which were harvested by the given harvest definition.

close

public abstract void close()
Close down any connections used by the DAO.


getDomains

public abstract java.util.List<java.lang.String> getDomains(java.lang.String glob)
Use a glob-like matcher to find a subset of domains. In this simple matcher, * stands for any number of arbitrary characters, and ? stands for one arbitrary character. Including these, the given string must match the entire domain name.

Parameters:
glob - A domain name with * and ? wildcards
Returns:
List of domain names matching the glob, sorted by name.

getCountDomains

public abstract int getCountDomains(java.lang.String glob)
Find the number of domains matching a given glob.

Parameters:
glob - A domain name with * and ? wildcards
Returns:
the number of domains matching the glob
See Also:
getDomains(String)

getDomainHarvestInfo

public abstract java.util.List<DomainHarvestInfo> getDomainHarvestInfo(java.lang.String domainName)
Get a list of info about harvests performed on a given domain. Note that harvest info from before the DB DAOs are unreliable, as harvests cannot be told apart and no dates are available.

Parameters:
domainName - Domain to get info for.
Returns:
List of DomainHarvestInfo objects with information on that domain.

mayDelete

public abstract boolean mayDelete(DomainConfiguration config)
Return whether the given configuration 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 configuration can be deleted, the dao may still reject a delete request. If this method returns false, deletion will however definitely not be allowed.

Parameters:
config - the given configuration
Returns:
true if the he given configuration can be deleted, false otherwise

mayDelete

public abstract boolean mayDelete(SeedList seedlist)
Return whether the given seedlist 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 seedlist can be deleted, the dao may still reject a delete request. If this method returns false, deletion will however definitely not be allowed.

Parameters:
seedlist - the given seedlist
Returns:
true, if the given seedlist can be deleted, otherwise false.

mayDelete

public abstract boolean mayDelete(Password password)
Return whether the given password 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 password can be deleted, the dao may still reject a delete request. If this method returns false, deletion will however definitely not be allowed.

Parameters:
password - the given password
Returns:
true, if the given password can be deleted, otherwise false.

mayDelete

public abstract boolean mayDelete(Domain domainName)
Return whether the given domain 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 domain can be deleted, the dao may still reject a delete request. If this method returns false, deletion will however definitely not be allowed.

Parameters:
domainName - the given domain
Returns:
true, if the given domain can be deleted, otherwise false.

readSparse

public abstract SparseDomain readSparse(java.lang.String domainName)
Read a Domain from Database, and return the domain information as a SparseDomain object. We only read information relevant for the GUI listing.

Parameters:
domainName - a given domain
Returns:
a SparseDomain.
Throws:
ArgumentNotValid - if domainName is null or empty.
UnknownID - if domain does not exist

getAliases

public abstract java.util.List<AliasInfo> getAliases(java.lang.String domain)
Return a list of AliasInfo objects. If the given domain is not-null, it should return AliasInfo objects where AliasInfo.aliasOf == domain

Parameters:
domain - a given domain
Returns:
a list of AliasInfo objects.
Throws:
UnknownID - If the given domain does not exist. (!DomainDAO.exists(domain))
ArgumentNotValid - if domainName is null

getAllAliases

public abstract java.util.List<AliasInfo> getAllAliases()
Get a list of all current alias-relations. The list should be sorted by increasing last-update. This means any expired aliases will be at the start of the list, while un-expired aliases will be at the end.

Returns:
a list of all current alias-relations.

getTLDs

public abstract java.util.List<TLDInfo> getTLDs()
Get a list of all TLDs present in the domains table. IP-numbers registered are counted together.

Returns:
a list of all TLDs present in the domains table, sorted alphabetically.

getDomainJobInfo

public abstract HarvestInfo getDomainJobInfo(Job job,
                                             java.lang.String domainName,
                                             java.lang.String configName)
Get the HarvestInfo object for a certain job and DomainConfiguration defined by domainName and configName.

Parameters:
domainName - the name of a given domain
configName - the name of a given configuration
job - the job
Returns:
The HarvestInfo object for a certain job and DomainConfiguration or null, if job has not yet been started.