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.
(package private)  java.lang.Long generateNextID()
          Generates the next id of job.
 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.
 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.
 java.util.List<JobStatusInfo> getStatusInfo()
          Get a list of small and immediately usable status information.
 java.util.List<JobStatusInfo> getStatusInfo(boolean asc)
          Get a list of small and immediately usable status information in given job id order.
 java.util.List<JobStatusInfo> getStatusInfo(boolean asc, JobStatus... states)
          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.
 java.util.List<JobStatusInfo> getStatusInfo(long harvestId, long numEvent)
          Get a list of small and immediately usable status information for a given harvest run.
 java.util.List<JobStatusInfo> getStatusInfo(long harvestId, long harvestNum, boolean asc)
          Get the list of all jobs ordered by JobID (represented by JobStatusInfo objects) belonging to a specific harvestdefinition, and a specific harvestnumber.
 java.util.List<JobStatusInfo> getStatusInfo(long harvestId, long harvestNum, boolean asc, java.util.Set<JobStatus> selectedStatusSet)
          Get statusInfo.
 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.

generateNextID

java.lang.Long generateNextID()
Description copied from class: JobDAO
Generates the next id of job.

Specified by:
generateNextID in class JobDAO
Returns:
id
See Also:
JobDAO.generateNextID()

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.

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()
Get a list of small and immediately usable status information.

Specified by:
getStatusInfo in class JobDAO
Returns:
List of JobStatusInfo objects for all jobs.
Throws:
IOFailure - on trouble getting data from database

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 java.util.List<JobStatusInfo> getStatusInfo(boolean asc)
Get a list of small and immediately usable status information in given job id order.

Specified by:
getStatusInfo in class JobDAO
Parameters:
asc - True if result must be given in ascending order, false if result must be given in descending order
Returns:
List of JobStatusInfo objects for all jobs with given job id order
Throws:
IOFailure - on trouble getting data from database

getStatusInfo

public java.util.List<JobStatusInfo> getStatusInfo(boolean asc,
                                                   JobStatus... states)
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:
states - The states (one or more) asked for.
asc - True if result must be given in ascending order, false if result must be given in descending order
Returns:
List of JobStatusInfo objects for all jobs with given job status and job id order
Throws:
ArgumentNotValid - for invalid jobStatusCode
IOFailure - on trouble getting data from database

getStatusInfo

public java.util.List<JobStatusInfo> getStatusInfo(long harvestId,
                                                   long numEvent)
Get a list of small and immediately usable status information for a given harvest run.

Specified by:
getStatusInfo in class JobDAO
Parameters:
harvestId - The ID of the harvest
numEvent - The harvest run number
Returns:
List of JobStatusInfo objects for all jobs for a given harvest ID.
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)

getStatusInfo

public java.util.List<JobStatusInfo> getStatusInfo(long harvestId,
                                                   long harvestNum,
                                                   boolean asc)
Description copied from class: JobDAO
Get the list of all jobs ordered by JobID (represented by JobStatusInfo objects) belonging to a specific harvestdefinition, and a specific harvestnumber. Can be ordered in either ascending or descending mode.

Specified by:
getStatusInfo in class JobDAO
Parameters:
harvestId - The Id of a specific harvestdefinition
harvestNum - A specific harvestnumber
asc - Should this list be ordered in ascending mode (true), or descending mode (false)
Returns:
the list
See Also:
JobDAO.getStatusInfo(long, long, boolean)

getStatusInfo

public java.util.List<JobStatusInfo> getStatusInfo(long harvestId,
                                                   long harvestNum,
                                                   boolean asc,
                                                   java.util.Set<JobStatus> selectedStatusSet)
Get statusInfo.

Specified by:
getStatusInfo in class JobDAO
Parameters:
harvestId - The Id of a specific harvestdefinition
harvestNum - A specific harvestnumber
asc - Should this list be ordered in ascending mode (true), or descending mode (false)
selectedStatusSet - The set of chosen Jobstates
Returns:
the list
See Also:
JobDAO.getStatusInfo(long, long, boolean, Set)