db2v8delegate.java
来自「Quartz 是个开源的作业调度框架」· Java 代码 · 共 552 行 · 第 1/2 页
JAVA
552 行
/*
* Copyright 2004-2005 OpenSymphony
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
package org.quartz.impl.jdbcjobstore;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.quartz.Calendar;
import org.quartz.CronTrigger;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.quartz.utils.Key;
/**
* Quartz JDBC delegate for DB2 v8 databases.
*
* @author Blair Jensen
*/
public class DB2v8Delegate extends StdJDBCDelegate {
public DB2v8Delegate(Log logger, String tablePrefix, String instanceId) {
super(logger, tablePrefix, instanceId);
}
public DB2v8Delegate(Log log, String tablePrefix, String instanceId,
Boolean useProperties) {
super(log, tablePrefix, instanceId, useProperties);
}
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);
ps.setInt(2, 1);
//ps.setBoolean(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);
SimpleTrigger rcvryTrig = new SimpleTrigger("recover_"
+ instanceId + "_" + String.valueOf(dumId++),
Scheduler.DEFAULT_RECOVERY_GROUP, new Date(firedTime));
rcvryTrig.setJobName(jobName);
rcvryTrig.setJobGroup(jobGroup);
rcvryTrig
.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
JobDataMap jd = selectTriggerJobDataMap(conn, trigName, trigGroup);
jd.put("QRTZ_FAILED_JOB_ORIG_TRIGGER_NAME", trigName);
jd.put("QRTZ_FAILED_JOB_ORIG_TRIGGER_GROUP", trigGroup);
jd.put("QRTZ_FAILED_JOB_ORIG_TRIGGER_FIRETIME_IN_MILLISECONDS_AS_STRING", 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 {
if (null != rs) {
try {
rs.close();
} catch (SQLException ignore) {
}
}
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
}
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());
ps.setInt(5, toBooleanInt(job.isDurable()));
ps.setInt(6, toBooleanInt(job.isVolatile()));
ps.setInt(7, toBooleanInt(job.isStateful()));
ps.setInt(8, toBooleanInt(job.requestsRecovery()));
//ps.setBoolean (5, job.isDurable());
//ps.setBoolean (6, job.isVolatile());
//ps.setBoolean (7, job.isStateful());
//ps.setBoolean (8, job.requestsRecovery());
ps.setBytes(9, baos.toByteArray());
//ps.setObject(9, baos.toByteArray(), Types.BLOB);
insertResult = ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
if (insertResult > 0) {
String[] jobListeners = job.getJobListenerNames();
for (int i = 0; jobListeners != null && i < jobListeners.length; i++)
insertJobListener(conn, job, jobListeners[i]);
}
return insertResult;
}
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());
ps.setInt(3, toBooleanInt(job.isDurable()));
ps.setInt(4, toBooleanInt(job.isVolatile()));
ps.setInt(5, toBooleanInt(job.isStateful()));
ps.setInt(6, toBooleanInt(job.requestsRecovery()));
//ps.setBoolean (3, job.isDurable());
//ps.setBoolean (4, job.isVolatile());
//ps.setBoolean (5, job.isStateful());
//ps.setBoolean (6, job.requestsRecovery());
ps.setBytes (7, baos.toByteArray());
//ps.setObject(7, baos.toByteArray(), java.sql.Types.BLOB);
ps.setString(8, job.getName());
ps.setString(9, job.getGroup());
insertResult = ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
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;
}
public int insertTrigger(Connection conn, Trigger trigger, String state,
JobDetail jobDetail) throws SQLException, IOException {
ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap());
PreparedStatement ps = null;
int insertResult = 0;
try {
ps = conn.prepareStatement(rtp(INSERT_TRIGGER));
ps.setString(1, trigger.getName());
ps.setString(2, trigger.getGroup());
ps.setString(3, trigger.getJobName());
ps.setString(4, trigger.getJobGroup());
ps.setInt(5, toBooleanInt(trigger.isVolatile()));
//ps.setBoolean(5, trigger.isVolatile());
ps.setString(6, trigger.getDescription());
ps.setBigDecimal(7, new BigDecimal(String.valueOf(trigger
.getNextFireTime().getTime())));
long prevFireTime = -1;
if (trigger.getPreviousFireTime() != null) {
prevFireTime = trigger.getPreviousFireTime().getTime();
}
ps.setBigDecimal(8, new BigDecimal(String.valueOf(prevFireTime)));
ps.setString(9, state);
if (trigger instanceof SimpleTrigger) {
ps.setString(10, TTYPE_SIMPLE);
} else if (trigger instanceof CronTrigger) {
ps.setString(10, TTYPE_CRON);
} else { // (trigger instanceof BlobTrigger)
ps.setString(10, TTYPE_BLOB);
}
ps.setBigDecimal(11, new BigDecimal(String.valueOf(trigger
.getStartTime().getTime())));
long endTime = 0;
if (trigger.getEndTime() != null) {
endTime = trigger.getEndTime().getTime();
}
ps.setBigDecimal(12, new BigDecimal(String.valueOf(endTime)));
ps.setString(13, trigger.getCalendarName());
ps.setInt(14, trigger.getMisfireInstruction());
ps.setBytes(15, baos.toByteArray());
insertResult = ps.executeUpdate();
} finally {
if (null != ps) {
try {
ps.close();
} catch (SQLException ignore) {
}
}
}
if (insertResult > 0) {
String[] trigListeners = trigger.getTriggerListenerNames();
for (int i = 0; trigListeners != null && i < trigListeners.length; i++)
insertTriggerListener(conn, trigger, trigListeners[i]);
}
return insertResult;
}
public int updateTrigger(Connection conn, Trigger trigger, String state,
JobDetail jobDetail) throws SQLException, IOException {
ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap());
PreparedStatement ps = null;
int insertResult = 0;
try {
ps = conn.prepareStatement(rtp(UPDATE_TRIGGER));
ps.setString(1, trigger.getJobName());
ps.setString(2, trigger.getJobGroup());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?