Class DomainDAO

  • All Implemented Interfaces:
    DAO, Iterable<Domain>
    Direct Known Subclasses:
    DomainDBDAO

    public abstract class DomainDAO
    extends Object
    implements DAO, Iterable<Domain>
    Persistent storage for Domain objects. Configuration information and seeds are stored as well.
    • 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​(List<Domain> domains)
        Create a list of domains in persistent storage.
        Parameters:
        domains - a list of Domain objects.
      • create

        protected abstract void create​(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​(String domainName)
        Read a domain from the persistent storage.
        Parameters:
        domainName - the name of the domain to retrieve
        Returns:
        the retrieved Domain
      • readKnown

        public Domain readKnown​(String domainName)
        Read a domain from the persistent storage known to exist.
        Parameters:
        domainName - the name of the domain to retrieve
        Returns:
        the retrieved Domain
      • read

        protected abstract Domain read​(Connection connection,
                                       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
      • readKnown

        protected abstract Domain readKnown​(Connection connection,
                                            String domainName)
        Read a domain from the persistent storage known to exist.
        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​(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 domains.
      • getAllDomains

        public abstract Iterator<Domain> getAllDomains()
        Gets list of all domains.
        Returns:
        List of all added domains
      • iterator

        public Iterator<Domain> iterator()
        Gets an iterator of all domains. Implements the Iterable interface.
        Specified by:
        iterator in interface Iterable<Domain>
        Returns:
        Iterator of all presently known domains.
      • getAllDomainsInSnapshotHarvestOrder

        public abstract 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
      • getHarvestInfoBasedOnPreviousHarvestDefinition

        public abstract 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 List<String> getDomains​(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​(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 List<AliasInfo> getAliases​(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 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 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,
                                                     String domainName,
                                                     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.
      • listDomainHarvestInfo

        public abstract List<DomainHarvestInfo> listDomainHarvestInfo​(String domainName,
                                                                      String orderBy,
                                                                      boolean asc)
        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.
        orderBy - The column attribute to order by.
        asc - true if the results should be ordered according to the natural order, false if they are to be sorted in reverse.
        Returns:
        List of DomainHarvestInfo objects with information on that domain.
      • getDomainConfiguration

        public abstract DomainConfiguration getDomainConfiguration​(String domainName,
                                                                   String configName)
        Get the DomainConfiguration given a specific domainName and a configurationName.
        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
      • getDomainHistory

        public abstract DomainHistory getDomainHistory​(String domainName)
        Get the domainHistory for a specific domain.
        Parameters:
        domainName - A name of a specific domain.
        Returns:
        the domainHistory for a specific domain.
      • getDomains

        public abstract List<String> getDomains​(String glob,
                                                String searchField)
        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
        searchField - The field in the Domain table to search
        Returns:
        List of domain names matching the glob, sorted by name.
      • findUsedConfigurations

        public abstract List<Long> findUsedConfigurations​(Long domainID)
        Read the used configurations name + seedslists for the domain. Note that even though a list of DomainConfiguration object are returned, only the name + seeds lists are set.

        A used configuration is the default configuration + configurations used in a active harvest definition.

        Parameters:
        domainID - The domain to find the configurations for.
        Returns:
        The list of ID for the used configurations.
      • renameAndUpdateConfig

        public abstract void renameAndUpdateConfig​(Domain domain,
                                                   DomainConfiguration domainConf,
                                                   String configOldName)
        Rename and update a DomainConfiguration for a specific domain.
        Parameters:
        domain - The given domain
        domainConf - The given domainConfig
        configOldName - The old name of the domainConfig
      • getDefaultDomainConfigurationName

        public abstract String getDefaultDomainConfigurationName​(String domainName)
        Get the name of the default configuration for the given domain.
        Parameters:
        domainName - a name of a domain
        Returns:
        the name of the default configuration for the given domain.
      • getAllDomainNames

        public abstract List<String> getAllDomainNames()
      • getHarvestInfoForDomainInHarvest

        public abstract HarvestInfo getHarvestInfoForDomainInHarvest​(HarvestDefinition harvestDefinition,
                                                                     Domain domain)
        Retrieve HarvestInfo for a given harvestdefinition and domain combination.
        Parameters:
        harvestDefinition - a given harvestdefinition
        domain - a given domain
        Returns:
        null, if no HarvestInfo found for the given harvestdefinition and domain combination, otherwise it returns the first matching HarvestInfo found and gives a warning if more than one match exist.
      • getDomainsInSnapshotHarvestOrder

        public abstract Iterator<Domain> getDomainsInSnapshotHarvestOrder​(Long previousHid)
        Gets list of all domains in the order expected by the snapshot harvest job generation, that is order by template name, then byte limit (descending), then domain name.
        Parameters:
        previousHid - The harvestDefinitionId of the harvestdefinition that we are continuing. If null, we start from scratch.
        Returns:
        List of all added domains