dk.netarkivet.harvester.datamodel
Class JobDBDAO

java.lang.Object
  extended by dk.netarkivet.harvester.datamodel.JobDAO
      extended by dk.netarkivet.harvester.datamodel.JobDBDAO
All Implemented Interfaces:
java.lang.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 Summary
protected JobDBDAO()
          Create a new JobDAO implemented using database.
 
Method Summary
 void create(Job job)
          Creates an instance in persistent storage of the given job.
 boolean exists(java.lang.Long jobID)
          Check whether a particular job exists.
 java.util.Iterator<Job> getAll()
          Return a list of all jobs.
 java.util.Iterator<Job> getAll(JobStatus status)
          Return a list of all jobs with the given status, ordered by id.
 java.util.Iterator<java.lang.Long> getAllJobIds()
          Return a list of all job_ids .
 java.util.Iterator<java.lang.Long> getAllJobIds(JobStatus status)
          Return a list of all job_id's representing jobs with the given status.
 java.util.Iterator<java.lang.Long> getAllJobIds(JobStatus status, JobPriority priority)
          Return a list of all job_id's representing jobs with the given status and priority.
 int getCountJobs()
          Returns the number of existing jobs.
 java.util.List<java.lang.Long> getJobIDsForDuplicateReduction(long jobID)
          Calculate all jobIDs to use for duplication reduction.
 JobStatus getJobStatus(java.lang.Long jobID)
          Get Jobstatus for the job with the given id.
 HarvestStatus getStatusInfo(HarvestStatusQuery query)
          Get a list of small and immediately usable status information for given job status and in given job id order.
 java.util.List<JobStatusInfo> getStatusInfo(JobStatus status)
          Get a list of small and immediately usable status information for given job status.
 Job read(java.lang.Long jobID)
          Read a single job from the job database.
 long rescheduleJob(long oldJobID)
          Reschedule a job by creating a new job (in status NEW) and setting the old job to status RESUBMITTED.
 void update(Job job)
          Update a Job in persistent storage.
 
Methods inherited from class dk.netarkivet.harvester.datamodel.JobDAO
getInstance, iterator, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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, one is generated for it.

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(java.lang.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(java.lang.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 java.util.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 java.util.Iterator<java.lang.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 java.util.Iterator<java.lang.Long> getAllJobIds(JobStatus status,
                                                       JobPriority priority)
Description copied from class: JobDAO
Return a list of all job_id's representing jobs with the given status and priority.

Specified by:
getAllJobIds in class JobDAO
Parameters:
status - A given status
priority - A given priority
Returns:
A list of all job_id's representing jobs with given status and priority.

getAll

public java.util.Iterator<Job> getAll()
Return a list of all jobs.

Specified by:
getAll in class JobDAO
Returns:
A list of all jobs

getAllJobIds

public java.util.Iterator<java.lang.Long> getAllJobIds()
Return a list of all job_ids .

Specified by:
getAllJobIds in class JobDAO
Returns:
A list of all job_ids

getStatusInfo

public java.util.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 java.util.List<java.lang.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
See Also:
JobDAO.rescheduleJob(long)

getJobStatus

public JobStatus getJobStatus(java.lang.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