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 new domain in the DB.
 boolean exists(java.lang.String domainName)
          Return true if a domain with the given name exists.
 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()
          Get a list of all domains.
 java.util.Iterator<Domain> getAllDomainsInSnapshotHarvestOrder()
          Get a list of all domains in snapshot harvest order.
 int getCountDomains()
          Get the total number of domains in the database.
 java.util.List<DomainHarvestInfo> getDomainHarvestInfo(java.lang.String domainName, boolean latestFirst)
          Get a list of info about harvests performed on a given 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<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 database.
 SparseDomain readSparse(java.lang.String domainName)
          Read a Domain from Database, and return the domain information as a SparseDomain object.
 void update(Domain d)
          Change an existing domain in the DB.
 
Methods inherited from class dk.netarkivet.harvester.datamodel.DomainDAO
create, create, getHarvestInfoBasedOnPreviousHarvestDefinition, 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)
Create a new domain in the DB.

Specified by:
create in class DomainDAO
Parameters:
connection - a connection to the harvest definition database.
d - a given Domain object.
See Also:
DomainDAO.create(Connection,Domain)

update

public void update(Domain d)
Change an existing domain in the DB.

Specified by:
update in class DomainDAO
Parameters:
d - the domain to update
See Also:
DomainDAO.update(Domain)

read

protected Domain read(java.sql.Connection c,
                      java.lang.String domainName)
Read a domain from the database.

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
See Also:
DomainDAO.read(Connection, String)

exists

public boolean exists(java.lang.String domainName)
Return true if a domain with the given name exists.

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

getCountDomains

public int getCountDomains()
Get the total number of domains in the database.

Specified by:
getCountDomains in class DomainDAO
Returns:
the total number of registered domanis.
See Also:
DomainDAO.getCountDomains()

getAllDomains

public java.util.Iterator<Domain> getAllDomains()
Get a list of all domains. Warning: This will build a string list of the domains, which will be rather long in a full system.

Specified by:
getAllDomains in class DomainDAO
Returns:
List of all added domains
See Also:
DomainDAO.getAllDomains()

getAllDomainsInSnapshotHarvestOrder

public java.util.Iterator<Domain> getAllDomainsInSnapshotHarvestOrder()
Get a list of all domains in snapshot harvest order. Warning: This will build a string list of the domains, which will be rather long in a full system.

Specified by:
getAllDomainsInSnapshotHarvestOrder in class DomainDAO
Returns:
List of all added domains
See Also:
DomainDAO.getAllDomainsInSnapshotHarvestOrder()

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.
See Also:
DomainDAO.getDomains(String)

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
See Also:
DomainDAO.mayDelete(DomainConfiguration)

readSparse

public 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.

Specified by:
readSparse in class DomainDAO
Parameters:
domainName - a given domain
Returns:
a SparseDomain.
Throws:
ArgumentNotValid - if domainName is null or empty.
UnknownID - if domain does not exist

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.
See Also:
DomainDAO.getAliases(String)

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.
See Also:
DomainDAO.getAllAliases()

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.
See Also:
DomainDAO.getDomainJobInfo(Job, String, String)

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.
See Also:
DomainDAO.getDomainHarvestInfo(String, boolean)