dk.netarkivet.harvester.datamodel
Class DomainDBDAO

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

public class DomainDBDAO
extends DomainDAO

A database-based implementation of the DomainDAO. The statements to create the tables are located in:


Constructor Summary
protected DomainDBDAO()
          Creates a database-based implementation of the DomainDAO.
 
Method Summary
protected  void create(java.sql.Connection connection, Domain d)
          Create a domain in persistent storage.
 boolean exists(java.lang.String domainName)
          Check existence of a domain with the given domainName.
 java.util.List<AliasInfo> getAliases(java.lang.String domain)
          Return a list of AliasInfo objects.
 java.util.List<AliasInfo> getAllAliases()
          Get a list of all current alias-relations.
 java.util.Iterator<Domain> getAllDomains()
          Gets list of all domains.
 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.
 int getCountDomains()
          Get the total number of domains available.
 DomainConfiguration getDomainConfiguration(java.lang.String domainName, java.lang.String configName)
          Get the DomainConfiguration given a specific domainName and a configurationName.
 java.util.List<DomainHarvestInfo> getDomainHarvestInfo(java.lang.String domainName, boolean latestFirst)
          Get a list of info about harvests performed on a given domain.
 DomainHistory getDomainHistory(java.lang.String domainName)
          Get the domainHistory for a specific domain.
 HarvestInfo getDomainJobInfo(Job j, java.lang.String domainName, java.lang.String configName)
          Get the HarvestInfo object for a certain job and DomainConfiguration defined by domainName and configName.
 java.util.List<java.lang.String> getDomains(java.lang.String glob)
          Use a glob-like matcher to find a subset of domains.
 java.util.List<java.lang.String> getDomains(java.lang.String glob, java.lang.String searchField)
          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.
 java.util.List<TLDInfo> getTLDs(int level)
          Return all TLDs represented by the domains in the domains table.
 boolean mayDelete(DomainConfiguration config)
          Return whether the given configuration can be deleted.
protected  Domain read(java.sql.Connection c, java.lang.String domainName)
          Read a domain from the persistent storage.
 SparseDomain readSparse(java.lang.String domainName)
          Read a Domain from Database, and return the domain information as a SparseDomain object.
 void update(Domain d)
          Update information about existing domain information.
 
Methods inherited from class dk.netarkivet.harvester.datamodel.DomainDAO
create, create, getInstance, iterator, read, resetSingleton
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomainDBDAO

protected DomainDBDAO()
Creates a database-based implementation of the DomainDAO. Will check that all schemas have correct versions, and update the ones that haven't.

Throws:
IOFailure - on trouble updating tables to new versions, or on tables with wrong versions that we don't know how to change to expected version.
Method Detail

create

protected void create(java.sql.Connection connection,
                      Domain d)
Description copied from class: DomainDAO
Create a domain in persistent storage.

Specified by:
create in class DomainDAO
Parameters:
connection - a connection to the harvest definition database.
d - a given Domain object.

update

public void update(Domain d)
Description copied from class: DomainDAO
Update information about existing domain information.

Specified by:
update in class DomainDAO
Parameters:
d - the domain to update

read

protected Domain read(java.sql.Connection c,
                      java.lang.String domainName)
Description copied from class: DomainDAO
Read a domain from the persistent storage.

Specified by:
read in class DomainDAO
Parameters:
c - a connection to the harvest definition database.
domainName - the name of the domain to retrieve
Returns:
the retrieved Domain

exists

public boolean exists(java.lang.String domainName)
Description copied from class: DomainDAO
Check existence of a domain with the given domainName.

Specified by:
exists in class DomainDAO
Parameters:
domainName - A given domain name.
Returns:
true if the domain exists, false otherwise.

getCountDomains

public int getCountDomains()
Description copied from class: DomainDAO
Get the total number of domains available.

Specified by:
getCountDomains in class DomainDAO
Returns:
the total number of registered domains.

getAllDomains

public java.util.Iterator<Domain> getAllDomains()
Description copied from class: DomainDAO
Gets list of all domains.

Specified by:
getAllDomains in class DomainDAO
Returns:
List of all added domains

getAllDomainsInSnapshotHarvestOrder

public java.util.Iterator<Domain> getAllDomainsInSnapshotHarvestOrder()
Description copied from class: DomainDAO
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.

Specified by:
getAllDomainsInSnapshotHarvestOrder in class DomainDAO
Returns:
List of all added domains

getDomains

public java.util.List<java.lang.String> getDomains(java.lang.String glob)
Description copied from class: DomainDAO
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.

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

mayDelete

public boolean mayDelete(DomainConfiguration config)
Description copied from class: DomainDAO
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.

Specified by:
mayDelete in class DomainDAO
Parameters:
config - the given configuration
Returns:
true if the he given configuration can be deleted, false otherwise

readSparse

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

Specified by:
readSparse in class DomainDAO
Parameters:
domainName - a given domain
Returns:
a SparseDomain.

getAliases

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

Specified by:
getAliases in class DomainDAO
Parameters:
domain - a given domain
Returns:
a list of AliasInfo objects.

getAllAliases

public java.util.List<AliasInfo> getAllAliases()
Description copied from class: DomainDAO
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.

Specified by:
getAllAliases in class DomainDAO
Returns:
a list of all current alias-relations.

getTLDs

public java.util.List<TLDInfo> getTLDs(int level)
Return all TLDs represented by the domains in the domains table. it was asked that a level X TLD belong appear in TLD list where the level is <=X for example bidule.bnf.fr belong to .bnf.fr and to .fr it appear in the level 1 list of TLD and in the level 2 list

Specified by:
getTLDs in class DomainDAO
Parameters:
level - maximum level of TLD
Returns:
a list of TLDs
See Also:
DomainDAO.getTLDs(int)

getDomainJobInfo

public HarvestInfo getDomainJobInfo(Job j,
                                    java.lang.String domainName,
                                    java.lang.String configName)
Description copied from class: DomainDAO
Get the HarvestInfo object for a certain job and DomainConfiguration defined by domainName and configName.

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

getDomainHarvestInfo

public java.util.List<DomainHarvestInfo> getDomainHarvestInfo(java.lang.String domainName,
                                                              boolean latestFirst)
Description copied from class: DomainDAO
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.

Specified by:
getDomainHarvestInfo in class DomainDAO
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.

getDomainConfiguration

public DomainConfiguration getDomainConfiguration(java.lang.String domainName,
                                                  java.lang.String configName)
Description copied from class: DomainDAO
Get the DomainConfiguration given a specific domainName and a configurationName.

Specified by:
getDomainConfiguration in class DomainDAO
Parameters:
domainName - The name of a domain
configName - The name of a configuration for this domain
Returns:
the DomainConfiguration, if the specified configuration exists; otherwise throws UnknownID

getHarvestInfoBasedOnPreviousHarvestDefinition

public java.util.Iterator<HarvestInfo> getHarvestInfoBasedOnPreviousHarvestDefinition(HarvestDefinition previousHarvestDefinition)
Description copied from class: DomainDAO
Find all info about results of a harvest definition.

Specified by:
getHarvestInfoBasedOnPreviousHarvestDefinition in class DomainDAO
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.

getDomainHistory

public DomainHistory getDomainHistory(java.lang.String domainName)
Description copied from class: DomainDAO
Get the domainHistory for a specific domain.

Specified by:
getDomainHistory in class DomainDAO
Parameters:
domainName - A name of a specific domain.
Returns:
the domainHistory for a specific domain.

getDomains

public java.util.List<java.lang.String> getDomains(java.lang.String glob,
                                                   java.lang.String searchField)
Description copied from class: DomainDAO
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.

Specified by:
getDomains in class DomainDAO
Parameters:
glob - A domain name with * and ? wildcards
searchField - The field in the Domain table to search
Returns:
List of domain names matching the glob, sorted by name.