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
protected abstract  void create(java.sql.Connection connection, Domain domain)
          Create a domain in persistent storage.
 void create(Domain domain)
          Create a domain in persistent storage.
 void create(java.util.List<Domain> domains)
          Create a list of domains in persistent storage.
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  java.util.List<DomainHarvestInfo> getDomainHarvestInfo(java.lang.String domainName, boolean latestFirst)
          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(int level)
          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(DomainConfiguration config)
          Return whether the given configuration can be deleted.
protected abstract  Domain read(java.sql.Connection connection, java.lang.String domainName)
          Read a domain from the persistent storage.
 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 void create(Domain domain)
Create a domain in persistent storage.

Parameters:
domain - a given Domain object.

create

public void create(java.util.List<Domain> domains)
Create a list of domains in persistent storage.

Parameters:
domains - a list of Domain objects.

create

protected abstract void create(java.sql.Connection connection,
                               Domain domain)
Create a domain in persistent storage.

Parameters:
connection - a connection to the harvest definition database.
domain - a given Domain object.

read

public 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

read

protected abstract Domain read(java.sql.Connection connection,
                               java.lang.String domainName)
Read a domain from the persistent storage.

Parameters:
connection - a connection to the harvest definition database.
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.

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! TODO remove this, no test methods in business classes!


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.

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.

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

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(int level)
Get a list of all TLDs present in the domains table. IP-numbers registered are counted together.

Parameters:
level - maximum level of TLD
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.

getDomainHarvestInfo

public abstract java.util.List<DomainHarvestInfo> getDomainHarvestInfo(java.lang.String domainName,
                                                                       boolean latestFirst)
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.
latestFirst - true if histories are to be returned sorted with the most recent harvests first, false if they are to be sorted with the oldest harvests first.
Returns:
List of DomainHarvestInfo objects with information on that domain.