Class JobDBDAO

  • All Implemented Interfaces:
    DAO, Iterable<Job>

    public class JobDBDAO
    extends JobDAO
    A database-based implementation of the JobDAO class. The statements to create the tables are now in scripts/sql/createfullhddb.sql
    • Constructor Detail

      • JobDBDAO

        protected JobDBDAO()
        Create a new JobDAO implemented using database. This constructor also tries to upgrade the jobs and jobs_configs tables in the current database. throws and IllegalState exception, if it is impossible to make the necessary updates.
    • Method Detail

      • create

        public void create​(Job job)
        Creates an instance in persistent storage of the given job. If the job doesn't have an ID (which it shouldn't at this point, one is generated for it. After that the harvestnamePrefix is set. Both existing harvestnameprefix factory-classes depends on the JobID being set before being called.
        Specified by:
        create in class JobDAO
        Parameters:
        job - a given job to add to persistent storage
        Throws:
        PermissionDenied - If a job already exists in persistent storage with the same id as the given job
        IOFailure - If some IOException occurs while writing the job to persistent storage
      • exists

        public boolean exists​(Long jobID)
        Check whether a particular job exists.
        Specified by:
        exists in class JobDAO
        Parameters:
        jobID - Id of the job.
        Returns:
        true if the job exists in any state.
      • update

        public void update​(Job job)
        Update a Job in persistent storage.
        Specified by:
        update in class JobDAO
        Parameters:
        job - The Job to update
        Throws:
        ArgumentNotValid - If the Job is null
        UnknownID - If the Job doesn't exist in the DAO
        IOFailure - If writing the job to persistent storage fails
        PermissionDenied - If the job has been updated behind our backs
      • read

        public Job read​(long jobID)
        Read a single job from the job database.
        Specified by:
        read in class JobDAO
        Parameters:
        jobID - ID of the job.
        Returns:
        A Job object
        Throws:
        UnknownID - if the job id does not exist.
        IOFailure - if there was some problem talking to the database.
      • getAll

        public Iterator<Job> getAll​(JobStatus status)
        Return a list of all jobs with the given status, ordered by id.
        Specified by:
        getAll in class JobDAO
        Parameters:
        status - A given status.
        Returns:
        A list of all job with given status
      • getAllJobIds

        public Iterator<Long> getAllJobIds​(JobStatus status)
        Return a list of all job_id's representing jobs with the given status.
        Specified by:
        getAllJobIds in class JobDAO
        Parameters:
        status - A given status.
        Returns:
        A list of all job_id's representing jobs with given status
        Throws:
        ArgumentNotValid - If the given status is not one of the five valid statuses specified in Job.
      • getAllJobIds

        public Iterator<Long> getAllJobIds​(JobStatus status,
                                           HarvestChannel channel)
        Description copied from class: JobDAO
        Return a list of all job_id's representing jobs with the given status and channel.
        Specified by:
        getAllJobIds in class JobDAO
        Parameters:
        status - A given status
        channel - A given HarvestChannel
        Returns:
        A list of all job_id's representing jobs with given status and channel.
      • getAll

        public Iterator<Job> getAll()
        Return a list of all jobs.
        Specified by:
        getAll in class JobDAO
        Returns:
        A list of all jobs
      • getAllJobIds

        public Iterator<Long> getAllJobIds()
        Return a list of all job_ids .
        Specified by:
        getAllJobIds in class JobDAO
        Returns:
        A list of all job_ids
      • getStatusInfo

        public List<JobStatusInfo> getStatusInfo​(JobStatus status)
        Get a list of small and immediately usable status information for given job status.
        Specified by:
        getStatusInfo in class JobDAO
        Parameters:
        status - The status asked for.
        Returns:
        List of JobStatusInfo objects for all jobs with given job status
        Throws:
        ArgumentNotValid - for invalid jobStatus
        IOFailure - on trouble getting data from database
      • getStatusInfo

        public HarvestStatus getStatusInfo​(HarvestStatusQuery query)
        Get a list of small and immediately usable status information for given job status and in given job id order.
        Specified by:
        getStatusInfo in class JobDAO
        Parameters:
        query - the user query
        Returns:
        A HarvestStatus object corresponding to the given query.
        Throws:
        IOFailure - on trouble getting data from database
      • getJobIDsForDuplicateReduction

        public List<Long> getJobIDsForDuplicateReduction​(long jobID)
                                                  throws UnknownID
        Calculate all jobIDs to use for duplication reduction.

        More precisely, this method calculates the following: If the job ID corresponds to a partial harvest, all jobIDs from the previous scheduled harvest are returned, or the empty list if this harvest hasn't been scheduled before.

        If the job ID corresponds to a full harvest, the entire chain of harvests this is based on is returned, and all jobIDs from the previous chain of full harvests is returned.

        This method is synchronized to avoid DB locking.

        Specified by:
        getJobIDsForDuplicateReduction in class JobDAO
        Parameters:
        jobID - The job ID to find duplicate reduction data for.
        Returns:
        A list of job IDs (possibly empty) of potential previous harvests of this job, to use for duplicate reduction.
        Throws:
        UnknownID - if job ID is unknown
        IOFailure - on trouble querying database
      • getCountJobs

        public int getCountJobs()
        Returns the number of existing jobs.
        Specified by:
        getCountJobs in class JobDAO
        Returns:
        Number of jobs in 'jobs' table
      • rescheduleJob

        public long rescheduleJob​(long oldJobID)
        Description copied from class: JobDAO
        Reschedule a job by creating a new job (in status NEW) and setting the old job to status RESUBMITTED.

        Notice the slightly confusing naming: The only job is marked RESUBMITTED, but the new job is not really submitted, that happens in a separate stage, the new job is in status NEW.

        Specified by:
        rescheduleJob in class JobDAO
        Parameters:
        oldJobID - ID of a job to reschedule
        Returns:
        ID of the newly created job
      • getJobStatus

        public JobStatus getJobStatus​(Long jobID)
        Get Jobstatus for the job with the given id.
        Specified by:
        getJobStatus in class JobDAO
        Parameters:
        jobID - A given Jobid
        Returns:
        the Jobstatus for the job with the given id.
        Throws:
        UnknownID - if no job exists with id jobID
      • getJobAliasInfo

        public List<AliasInfo> getJobAliasInfo​(Job job)
        Get a list of AliasInfo objects for all the domains included in the job.
        Specified by:
        getJobAliasInfo in class JobDAO
        Returns:
        a list of AliasInfo objects for all the domains included in the job.