Class PropertySettingJobFactory
- java.lang.Object
-
- org.quartz.simpl.SimpleJobFactory
-
- org.quartz.simpl.PropertySettingJobFactory
-
- All Implemented Interfaces:
JobFactory
public class PropertySettingJobFactory extends SimpleJobFactory
A JobFactory that instantiates the Job instance (using the default no-arg constructor, or more specifically:class.newInstance()), and then attempts to set all values from theSchedulerContextand theJobExecutionContext's mergedJobDataMaponto bean properties of theJob.Set the warnIfPropertyNotFound property to true if you'd like noisy logging in the case of values in the JobDataMap not mapping to properties on your Job class. This may be useful for troubleshooting typos of property names, etc. but very noisy if you regularly (and purposely) have extra things in your JobDataMap.
Also of possible interest is the throwIfPropertyNotFound property which will throw exceptions on unmatched JobDataMap keys.
-
-
Constructor Summary
Constructors Constructor Description PropertySettingJobFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisThrowIfPropertyNotFound()Whether the JobInstantiation should fail and throw and exception if a key (name) and value (type) found in the JobDataMap does not correspond to a property setter on the Job class.booleanisWarnIfPropertyNotFound()Whether a warning should be logged if a key (name) and value (type) found in the JobDataMap does not correspond to a property setter on the Job class.JobnewJob(TriggerFiredBundle bundle, Scheduler scheduler)Called by the scheduler at the time of the trigger firing, in order to produce aJobinstance on which to call execute.protected voidsetBeanProps(java.lang.Object obj, JobDataMap data)voidsetThrowIfPropertyNotFound(boolean throwIfNotFound)Whether the JobInstantiation should fail and throw and exception if a key (name) and value (type) found in the JobDataMap does not correspond to a property setter on the Job class.voidsetWarnIfPropertyNotFound(boolean warnIfNotFound)Whether a warning should be logged if a key (name) and value (type) found in the JobDataMap does not correspond to a property setter on the Job class.-
Methods inherited from class org.quartz.simpl.SimpleJobFactory
getLog
-
-
-
-
Method Detail
-
newJob
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException
Description copied from interface:JobFactoryCalled by the scheduler at the time of the trigger firing, in order to produce aJobinstance on which to call execute.It should be extremely rare for this method to throw an exception - basically only the case where there is no way at all to instantiate and prepare the Job for execution. When the exception is thrown, the Scheduler will move all triggers associated with the Job into the
Trigger.STATE_ERRORstate, which will require human intervention (e.g. an application restart after fixing whatever configuration problem led to the issue with instantiating the Job.- Specified by:
newJobin interfaceJobFactory- Overrides:
newJobin classSimpleJobFactory- Parameters:
bundle- The TriggerFiredBundle from which theJobDetailand other info relating to the trigger firing can be obtained.scheduler- a handle to the scheduler that is about to execute the job.- Returns:
- the newly instantiated Job
- Throws:
SchedulerException- if there is a problem instantiating the Job.
-
setBeanProps
protected void setBeanProps(java.lang.Object obj, JobDataMap data) throws SchedulerException- Throws:
SchedulerException
-
isThrowIfPropertyNotFound
public boolean isThrowIfPropertyNotFound()
Whether the JobInstantiation should fail and throw and exception if a key (name) and value (type) found in the JobDataMap does not correspond to a property setter on the Job class.- Returns:
- Returns the throwIfNotFound.
-
setThrowIfPropertyNotFound
public void setThrowIfPropertyNotFound(boolean throwIfNotFound)
Whether the JobInstantiation should fail and throw and exception if a key (name) and value (type) found in the JobDataMap does not correspond to a property setter on the Job class.- Parameters:
throwIfNotFound- defaults tofalse.
-
isWarnIfPropertyNotFound
public boolean isWarnIfPropertyNotFound()
Whether a warning should be logged if a key (name) and value (type) found in the JobDataMap does not correspond to a property setter on the Job class.- Returns:
- Returns the warnIfNotFound.
-
setWarnIfPropertyNotFound
public void setWarnIfPropertyNotFound(boolean warnIfNotFound)
Whether a warning should be logged if a key (name) and value (type) found in the JobDataMap does not correspond to a property setter on the Job class.- Parameters:
warnIfNotFound- defaults totrue.
-
-