⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db2v7delegate.java

📁 定时器开源项目, 相对于 jcrontab, Quartz 算是更完整的一个项目, 随著开发的版本上来, 他已经脱离只是写在程序里面的计时器, 在指定的时间或区间, 处理所指定的事件. 也加入了 se
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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.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.quartz.impl.jdbcjobstore.StdJDBCDelegate;import org.apache.commons.logging.Log;import org.quartz.Calendar;import org.quartz.CronTrigger;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 v7 databases. *  * @author Blair Jensen */public class DB2v7Delegate extends StdJDBCDelegate {    public DB2v7Delegate(Log logger, String tablePrefix, String instanceId) {        super(logger, tablePrefix, instanceId);    }    public DB2v7Delegate(Log log, String tablePrefix, String instanceId,            Boolean useProperties) {        super(log, tablePrefix, instanceId, useProperties);    }        public Trigger[] selectTriggersForRecoveringJobs(Connection conn)            throws SQLException {        PreparedStatement ps = null;        ResultSet rs = null;        try {            ps = conn                    .prepareStatement(rtp(SELECT_INSTANCES_RECOVERABLE_FIRED_TRIGGERS));            ps.setString(1, instanceId);            ps.setString(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);                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);                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.setString(5, toBooleanIntString(job.isDurable()));            ps.setString(6, toBooleanIntString(job.isVolatile()));            ps.setString(7, toBooleanIntString(job.isStateful()));            ps.setString(8, toBooleanIntString(job.requestsRecovery()));            //ps.setBoolean (5, job.isDurable());            //ps.setBoolean (6, job.isVolatile());            //ps.setBoolean (7, job.isStateful());            //ps.setBoolean (8, job.requestsRecovery());            ps.setObject(9, baos.toByteArray(), java.sql.Types.BLOB);            //ps.setBytes (9, baos.toByteArray());            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.setString(3, toBooleanIntString(job.isDurable()));            ps.setString(4, toBooleanIntString(job.isVolatile()));            ps.setString(5, toBooleanIntString(job.isStateful()));            ps.setString(6, toBooleanIntString(job.requestsRecovery()));            //ps.setBoolean (3, job.isDurable());            //ps.setBoolean (4, job.isVolatile());            //ps.setBoolean (5, job.isStateful());            //ps.setBoolean (6, job.requestsRecovery());            ps.setObject(7, baos.toByteArray(), java.sql.Types.BLOB);            //ps.setBytes (7, baos.toByteArray());            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 {        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.setString(5, toBooleanIntString(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());            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 {        PreparedStatement ps = null;        int insertResult = 0;        try {            ps = conn.prepareStatement(rtp(UPDATE_TRIGGER));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -