Class JobDBDAO
- java.lang.Object
-
- dk.netarkivet.harvester.datamodel.JobDAO
-
- dk.netarkivet.harvester.datamodel.JobDBDAO
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
GET_JOB_BY_ID_SQL
-
Constructor Summary
Constructors Modifier Constructor Description protected
JobDBDAO()
Create a new JobDAO implemented using database.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
create(Job job)
Creates an instance in persistent storage of the given job.boolean
exists(Long jobID)
Check whether a particular job exists.Iterator<Job>
getAll()
Return a list of all jobs.Iterator<Job>
getAll(JobStatus status)
Return a list of all jobs with the given status, ordered by id.Iterator<Long>
getAllJobIds()
Return a list of all job_ids .Iterator<Long>
getAllJobIds(JobStatus status)
Return a list of all job_id's representing jobs with the given status.Iterator<Long>
getAllJobIds(JobStatus status, HarvestChannel channel)
Return a list of all job_id's representing jobs with the given status and channel.int
getCountJobs()
Returns the number of existing jobs.List<AliasInfo>
getJobAliasInfo(Job job)
Get a list of AliasInfo objects for all the domains included in the job.List<Long>
getJobIDsForDuplicateReduction(long jobID)
Calculate all jobIDs to use for duplication reduction.JobStatus
getJobStatus(Long jobID)
Get Jobstatus for the job with the given id.List<JobStatusInfo>
getStatusInfo(JobStatus status)
Get a list of small and immediately usable status information for given job status.HarvestStatus
getStatusInfo(HarvestStatusQuery query)
Get a list of small and immediately usable status information for given job status and in given job id order.Job
read(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
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
GET_JOB_BY_ID_SQL
protected static final String GET_JOB_BY_ID_SQL
- See Also:
- Constant Field Values
-
-
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 classJobDAO
- 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 jobIOFailure
- If some IOException occurs while writing the job to persistent storage
-
exists
public boolean exists(Long jobID)
Check whether a particular job exists.
-
update
public void update(Job job)
Update a Job in persistent storage.- Specified by:
update
in classJobDAO
- Parameters:
job
- The Job to update- Throws:
ArgumentNotValid
- If the Job is nullUnknownID
- If the Job doesn't exist in the DAOIOFailure
- If writing the job to persistent storage failsPermissionDenied
- If the job has been updated behind our backs
-
read
public Job read(long jobID)
Read a single job from the job database.
-
getAll
public Iterator<Job> getAll(JobStatus status)
Return a list of all jobs with the given status, ordered by id.
-
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 classJobDAO
- 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 classJobDAO
- Parameters:
status
- A given statuschannel
- A givenHarvestChannel
- Returns:
- A list of all job_id's representing jobs with given status and channel.
-
getAllJobIds
public Iterator<Long> getAllJobIds()
Return a list of all job_ids .- Specified by:
getAllJobIds
in classJobDAO
- 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 classJobDAO
- Parameters:
status
- The status asked for.- Returns:
- List of JobStatusInfo objects for all jobs with given job status
- Throws:
ArgumentNotValid
- for invalid jobStatusIOFailure
- 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 classJobDAO
- 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 classJobDAO
- 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 unknownIOFailure
- on trouble querying database
-
getCountJobs
public int getCountJobs()
Returns the number of existing jobs.- Specified by:
getCountJobs
in classJobDAO
- 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 classJobDAO
- 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 classJobDAO
- 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 classJobDAO
- Returns:
- a list of AliasInfo objects for all the domains included in the job.
-
-