📄 stdjdbcdelegate.java
字号:
* returned triggers to ensure that they are fired.
* </p>
*
* @param conn
* the DB Connection
* @return an array of <code>{@link org.quartz.Trigger}</code> objects
*/
public Trigger[] selectTriggersForRecoveringJobs(Connection conn)
throws SQLException, IOException, ClassNotFoundException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn
.prepareStatement(rtp(SELECT_INSTANCES_RECOVERABLE_FIRED_TRIGGERS));
ps.setString(1, instanceId);
setBoolean(ps, 2, true);
rs = ps.executeQuery();
long dumId = System.currentTimeMillis();
ArrayList list = new ArrayList();
while (rs.next()) {
String jobName = rs.getString(COL_JOB_NAME);
String jobGroup = rs.getString(COL_JOB_GROUP);
String trigName = rs.getString(COL_TRIGGER_NAME);
String trigGroup = rs.getString(COL_TRIGGER_GROUP);
long firedTime = rs.getLong(COL_FIRED_TIME);
int priority = rs.getInt(COL_PRIORITY);
SimpleTrigger rcvryTrig = new SimpleTrigger("recover_"
+ instanceId + "_" + String.valueOf(dumId++),
Scheduler.DEFAULT_RECOVERY_GROUP, new Date(firedTime));
rcvryTrig.setJobName(jobName);
rcvryTrig.setJobGroup(jobGroup);
rcvryTrig.setPriority(priority);
rcvryTrig
.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
JobDataMap jd = selectTriggerJobDataMap(conn, trigName, trigGroup);
jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_NAME, trigName);
jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_GROUP, trigGroup);
jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDS, String.valueOf(firedTime));
rcvryTrig.setJobDataMap(jd);
list.add(rcvryTrig);
}
Object[] oArr = list.toArray();
Trigger[] tArr = new Trigger[oArr.length];
System.arraycopy(oArr, 0, tArr, 0, oArr.length);
return tArr;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
/**
* <p>
* Delete all fired triggers.
* </p>
*
* @param conn
* the DB Connection
* @return the number of rows deleted
*/
public int deleteFiredTriggers(Connection conn) throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(DELETE_FIRED_TRIGGERS));
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
public int deleteFiredTriggers(Connection conn, String instanceId)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(DELETE_INSTANCES_FIRED_TRIGGERS));
ps.setString(1, instanceId);
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
//---------------------------------------------------------------------------
// jobs
//---------------------------------------------------------------------------
/**
* <p>
* Insert the job detail record.
* </p>
*
* @param conn
* the DB Connection
* @param job
* the job to insert
* @return number of rows inserted
* @throws IOException
* if there were problems serializing the JobDataMap
*/
public int insertJobDetail(Connection conn, JobDetail job)
throws IOException, SQLException {
ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());
PreparedStatement ps = null;
int insertResult = 0;
try {
ps = conn.prepareStatement(rtp(INSERT_JOB_DETAIL));
ps.setString(1, job.getName());
ps.setString(2, job.getGroup());
ps.setString(3, job.getDescription());
ps.setString(4, job.getJobClass().getName());
setBoolean(ps, 5, job.isDurable());
setBoolean(ps, 6, job.isVolatile());
setBoolean(ps, 7, job.isStateful());
setBoolean(ps, 8, job.requestsRecovery());
setBytes(ps, 9, baos);
insertResult = ps.executeUpdate();
} finally {
closeStatement(ps);
}
if (insertResult > 0) {
String[] jobListeners = job.getJobListenerNames();
for (int i = 0; jobListeners != null && i < jobListeners.length; i++) {
insertJobListener(conn, job, jobListeners[i]);
}
}
return insertResult;
}
/**
* <p>
* Update the job detail record.
* </p>
*
* @param conn
* the DB Connection
* @param job
* the job to update
* @return number of rows updated
* @throws IOException
* if there were problems serializing the JobDataMap
*/
public int updateJobDetail(Connection conn, JobDetail job)
throws IOException, SQLException {
ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());
PreparedStatement ps = null;
int insertResult = 0;
try {
ps = conn.prepareStatement(rtp(UPDATE_JOB_DETAIL));
ps.setString(1, job.getDescription());
ps.setString(2, job.getJobClass().getName());
setBoolean(ps, 3, job.isDurable());
setBoolean(ps, 4, job.isVolatile());
setBoolean(ps, 5, job.isStateful());
setBoolean(ps, 6, job.requestsRecovery());
setBytes(ps, 7, baos);
ps.setString(8, job.getName());
ps.setString(9, job.getGroup());
insertResult = ps.executeUpdate();
} finally {
closeStatement(ps);
}
if (insertResult > 0) {
deleteJobListeners(conn, job.getName(), job.getGroup());
String[] jobListeners = job.getJobListenerNames();
for (int i = 0; jobListeners != null && i < jobListeners.length; i++) {
insertJobListener(conn, job, jobListeners[i]);
}
}
return insertResult;
}
/**
* <p>
* Get the names of all of the triggers associated with the given job.
* </p>
*
* @param conn
* the DB Connection
* @param jobName
* the name of the job
* @param groupName
* the group containing the job
* @return an array of <code>{@link
* org.quartz.utils.Key}</code> objects
*/
public Key[] selectTriggerNamesForJob(Connection conn, String jobName,
String groupName) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(rtp(SELECT_TRIGGERS_FOR_JOB));
ps.setString(1, jobName);
ps.setString(2, groupName);
rs = ps.executeQuery();
ArrayList list = new ArrayList(10);
while (rs.next()) {
String trigName = rs.getString(COL_TRIGGER_NAME);
String trigGroup = rs.getString(COL_TRIGGER_GROUP);
list.add(new Key(trigName, trigGroup));
}
Object[] oArr = list.toArray();
Key[] kArr = new Key[oArr.length];
System.arraycopy(oArr, 0, kArr, 0, oArr.length);
return kArr;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
/**
* <p>
* Delete all job listeners for the given job.
* </p>
*
* @param conn
* the DB Connection
* @param jobName
* the name of the job
* @param groupName
* the group containing the job
* @return the number of rows deleted
*/
public int deleteJobListeners(Connection conn, String jobName,
String groupName) throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(DELETE_JOB_LISTENERS));
ps.setString(1, jobName);
ps.setString(2, groupName);
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
/**
* <p>
* Delete the job detail record for the given job.
* </p>
*
* @param conn
* the DB Connection
* @param jobName
* the name of the job
* @param groupName
* the group containing the job
* @return the number of rows deleted
*/
public int deleteJobDetail(Connection conn, String jobName, String groupName)
throws SQLException {
PreparedStatement ps = null;
try {
if (logger.isDebugEnabled()) {
logger.debug("Deleting job: " + groupName + "." + jobName);
}
ps = conn.prepareStatement(rtp(DELETE_JOB_DETAIL));
ps.setString(1, jobName);
ps.setString(2, groupName);
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
/**
* <p>
* Check whether or not the given job is stateful.
* </p>
*
* @param conn
* the DB Connection
* @param jobName
* the name of the job
* @param groupName
* the group containing the job
* @return true if the job exists and is stateful, false otherwise
*/
public boolean isJobStateful(Connection conn, String jobName,
String groupName) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(rtp(SELECT_JOB_STATEFUL));
ps.setString(1, jobName);
ps.setString(2, groupName);
rs = ps.executeQuery();
if (!rs.next()) { return false; }
return getBoolean(rs, COL_IS_STATEFUL);
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
/**
* <p>
* Check whether or not the given job exists.
* </p>
*
* @param conn
* the DB Connection
* @param jobName
* the name of the job
* @param groupName
* the group containing the job
* @return true if the job exists, false otherwise
*/
public boolean jobExists(Connection conn, String jobName, String groupName)
throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(rtp(SELECT_JOB_EXISTENCE));
ps.setString(1, jobName);
ps.setString(2, groupName);
rs = ps.executeQuery();
if (rs.next()) {
return true;
} else {
return false;
}
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
/**
* <p>
* Update the job data map for the given job.
* </p>
*
* @param conn
* the DB Connection
* @param job
* the job to update
* @return the number of rows updated
*/
public int updateJobData(Connection conn, JobDetail job)
throws IOException, SQLException {
ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(UPDATE_JOB_DATA));
setBytes(ps, 1, baos);
ps.setString(2, job.getName());
ps.setString(3, job.getGroup());
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
/**
* <p>
* Associate a listener with a job.
* </p>
*
* @param conn
* the DB Connection
* @param job
* the job to associate with the listener
* @param listener
* the listener to insert
* @return the number of rows inserted
*/
public int insertJobListener(Connection conn, JobDetail job, String listener)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(INSERT_JOB_LISTENER));
ps.setString(1, job.getName());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -