📄 jobstoresupport.java
字号:
/* * Copyright James House (c) 2001-2004 * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: 1. * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. 2. Redistributions in * binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other * materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */package org.quartz.impl.jdbcjobstore;import java.io.IOException;import java.lang.reflect.Constructor;import java.lang.reflect.InvocationTargetException;import java.sql.Connection;import java.sql.SQLException;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Set;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.quartz.Calendar;import org.quartz.CronTrigger;import org.quartz.JobDetail;import org.quartz.JobPersistenceException;import org.quartz.ObjectAlreadyExistsException;import org.quartz.Scheduler;import org.quartz.SchedulerConfigException;import org.quartz.SchedulerException;import org.quartz.SimpleTrigger;import org.quartz.Trigger;import org.quartz.core.SchedulingContext;import org.quartz.spi.ClassLoadHelper;import org.quartz.spi.JobStore;import org.quartz.spi.SchedulerSignaler;import org.quartz.spi.TriggerFiredBundle;import org.quartz.utils.DBConnectionManager;import org.quartz.utils.Key;import org.quartz.utils.TriggerStatus;/** * <p> * Contains base functionality for JDBC-based JobStore implementations. * </p> * * @author <a href="mailto:jeff@binaryfeed.org">Jeffrey Wescott</a> * @author James House */public abstract class JobStoreSupport implements JobStore, Constants { /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Constants. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ protected static String LOCK_TRIGGER_ACCESS = "TRIGGER_ACCESS"; protected static String LOCK_JOB_ACCESS = "JOB_ACCESS"; protected static String LOCK_CALENDAR_ACCESS = "CALENDAR_ACCESS"; protected static String LOCK_STATE_ACCESS = "STATE_ACCESS"; protected static String LOCK_MISFIRE_ACCESS = "MISFIRE_ACCESS"; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Data members. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ protected String dsName; protected String tablePrefix = DEFAULT_TABLE_PREFIX; protected boolean useProperties = false; protected String instanceId; protected String instanceName; protected Class delegateClass = StdJDBCDelegate.class; protected HashMap calendarCache = new HashMap(); private DriverDelegate delegate; private long misfireThreshold = 60000L; // one minute private boolean dontSetAutoCommitFalse = false; private boolean isClustered = false; private boolean useDBLocks = false; private boolean lockOnInsert = true; private Semaphore lockHandler = null; // set in initialize() method... private String selectWithLockSQL = null; private long clusterCheckinInterval = 7500L; private ClusterManager clusterManagementThread = null; private MisfireHandler misfireHandler = null; private ClassLoadHelper classLoadHelper; private SchedulerSignaler signaler; protected int maxToRecoverAtATime = 20; private boolean setTxIsolationLevelSequential = false; private long dbRetryInterval = 10000; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Interface. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** * <p> * Set the name of the <code>DataSource</code> that should be used for * performing database functions. * </p> */ public void setDataSource(String dsName) { this.dsName = dsName; } /** * <p> * Get the name of the <code>DataSource</code> that should be used for * performing database functions. * </p> */ public String getDataSource() { return dsName; } /** * <p> * Set the prefix that should be pre-pended to all table names. * </p> */ public void setTablePrefix(String prefix) { if (prefix == null) prefix = ""; this.tablePrefix = prefix; } /** * <p> * Get the prefix that should be pre-pended to all table names. * </p> */ public String getTablePrefix() { return tablePrefix; } /** * <p> * Set whether String-only properties will be handled in JobDataMaps. * </p> */ public void setUseProperties(String useProp) { if (useProp == null) useProp = "false"; this.useProperties = Boolean.valueOf(useProp).booleanValue(); } /** * <p> * Get whether String-only properties will be handled in JobDataMaps. * </p> */ public boolean canUseProperties() { return useProperties; } /** * <p> * Set the instance Id of the Scheduler (must be unique within a cluster). * </p> */ public void setInstanceId(String instanceId) { this.instanceId = instanceId; } /** * <p> * Get the instance Id of the Scheduler (must be unique within a cluster). * </p> */ public String getInstanceId() { return instanceId; } /** * <p> * Set the instance Id of the Scheduler (must be unique within a cluster). * </p> */ public void setInstanceName(String instanceName) { this.instanceName = instanceName; } /** * <p> * Get the instance Id of the Scheduler (must be unique within a cluster). * </p> */ public String getInstanceName() { return instanceName; } /** * <p> * Set whether this instance is part of a cluster. * </p> */ public void setIsClustered(boolean isClustered) { this.isClustered = isClustered; } /** * <p> * Get whether this instance is part of a cluster. * </p> */ public boolean isClustered() { return isClustered; } /** * <p> * Get the frequency (in milliseconds) at which this instance "checks-in" * with the other instances of the cluster. -- Affects the rate of * detecting failed instances. * </p> */ public long getClusterCheckinInterval() { return clusterCheckinInterval; } /** * <p> * Set the frequency (in milliseconds) at which this instance "checks-in" * with the other instances of the cluster. -- Affects the rate of * detecting failed instances. * </p> */ public void setClusterCheckinInterval(long l) { clusterCheckinInterval = l; } /** * <p> * Get the maximum number of misfired triggers that the misfire handling * thread will try to recover at one time (within one transaction). The * default is 20. * </p> */ public int getMaxMisfiresToHandleAtATime() { return maxToRecoverAtATime; } /** * <p> * Set the maximum number of misfired triggers that the misfire handling * thread will try to recover at one time (within one transaction). The * default is 20. * </p> */ public void setMaxMisfiresToHandleAtATime(int maxToRecoverAtATime) { this.maxToRecoverAtATime = maxToRecoverAtATime; } /** * @return Returns the dbRetryInterval. */ public long getDbRetryInterval() { return dbRetryInterval; } /** * @param dbRetryInterval The dbRetryInterval to set. */ public void setDbRetryInterval(long dbRetryInterval) { this.dbRetryInterval = dbRetryInterval; } /** * <p> * Set whether this instance should use database-based thread * synchronization. * </p> */ public void setUseDBLocks(boolean useDBLocks) { this.useDBLocks = useDBLocks; } /** * <p> * Get whether this instance should use database-based thread * synchronization. * </p> */ public boolean getUseDBLocks() { return useDBLocks; } public boolean isLockOnInsert() { return lockOnInsert; } /** * Whether or not to obtain locks when inserting new jobs/triggers. * Defaults to <code>true</code>, which is safest - some db's (such as * MS SQLServer) seem to require this to avoid deadlocks under high load, * while others seem to do fine without. * * <p>Setting this property to <code>false</code> will provide a * significant performance increase during the addition of new jobs * and triggers.</p> * * @param lockOnInsert */ public void setLockOnInsert(boolean lockOnInsert) { this.lockOnInsert = lockOnInsert; } public long getMisfireThreshold() { return misfireThreshold; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -