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. If no jobs are found in the database, it will attempt to migrate from the XML-based implementation. 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
 Job copyJob(Job oldJob)
          Make a copy of the given job with new ID.
 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(long harvestId, long numEvent)
          Get a list of small and immediately usable status information for a given harvest run.
 Job read(java.lang.Long jobID)
          Read a single job from the job database.
 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.

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 -
Throws:
PermissionDenied - If a job already exists in persistent storage with id of the given job
IOFailure - If some IOException occurs while writing the job_.xml

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

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.

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

copyJob

public Job copyJob(Job oldJob)
Make a copy of the given job with new ID. Used for resubmitting.

Overrides:
copyJob in class JobDAO
Parameters:
oldJob - A job to copy.
Returns:
A new job with exactly the same data, except for ID which will be autogenerated and status which will be NEW.

getCountJobs

public int getCountJobs()
Returns the number of existing jobs.

Specified by:
getCountJobs in class JobDAO
Returns:
Number of jobs in 'jobs' table