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

📄 pointbasedelegate.java

📁 定时器开源项目, 相对于 jcrontab, Quartz 算是更完整的一个项目, 随著开发的版本上来, 他已经脱离只是写在程序里面的计时器, 在指定的时间或区间, 处理所指定的事件. 也加入了 se
💻 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.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.ObjectInputStream;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import org.apache.commons.logging.Log;import org.quartz.Calendar;import org.quartz.JobDetail;/** * <p> * This is a driver delegate for the Pointbase JDBC driver. * </p> *  * @author Gregg Freeman */public class PointbaseDelegate extends StdJDBCDelegate {    //private static Category log =    // Category.getInstance(PointbaseJDBCDelegate.class);    /**     * <p>     * Create new PointbaseJDBCDelegate instance.     * </p>     *      * @param logger     *          the logger to use during execution     * @param tablePrefix     *          the prefix of all table names     */    public PointbaseDelegate(Log logger, String tablePrefix, String instanceId) {        super(logger, tablePrefix, instanceId);    }    /**     * <p>     * Create new PointbaseJDBCDelegate instance.     * </p>     *      * @param logger     *          the logger to use during execution     * @param tablePrefix     *          the prefix of all table names     */    public PointbaseDelegate(Log logger, String tablePrefix, String instanceId,            Boolean useProperties) {        super(logger, tablePrefix, instanceId, useProperties);    }    //---------------------------------------------------------------------------    // 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 {        //log.debug( "Inserting JobDetail " + job );        ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());        int len = baos.toByteArray().length;        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());        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.setBoolean(5, job.isDurable());            ps.setBoolean(6, job.isVolatile());            ps.setBoolean(7, job.isStateful());            ps.setBoolean(8, job.requestsRecovery());            ps.setBinaryStream(9, bais, len);            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;    }    /**     * <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 {        //log.debug( "Updating job detail " + job );        ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());        int len = baos.toByteArray().length;        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());        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.setBoolean(3, job.isDurable());            ps.setBoolean(4, job.isVolatile());            ps.setBoolean(5, job.isStateful());            ps.setBoolean(6, job.requestsRecovery());            ps.setBinaryStream(7, bais, len);            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;    }    /**     * <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 {        //log.debug( "Updating Job Data for Job " + job );        ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());        int len = baos.toByteArray().length;        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());        PreparedStatement ps = null;        try {            ps = conn.prepareStatement(rtp(UPDATE_JOB_DATA));            ps.setBinaryStream(1, bais, len);            ps.setString(2, job.getName());            ps.setString(3, job.getGroup());            return ps.executeUpdate();        } finally {            if (null != ps) {                try {                    ps.close();                } catch (SQLException ignore) {                }            }        }    }    //---------------------------------------------------------------------------    // triggers    //---------------------------------------------------------------------------    //---------------------------------------------------------------------------    // calendars    //---------------------------------------------------------------------------    /**     * <p>     * Insert a new calendar.     * </p>     *      * @param conn     *          the DB Connection     * @param calendarName     *          the name for the new calendar     * @param calendar     *          the calendar     * @return the number of rows inserted     * @throws IOException     *           if there were problems serializing the calendar     */    public int insertCalendar(Connection conn, String calendarName,            Calendar calendar) throws IOException, SQLException {        //log.debug( "Inserting Calendar " + calendarName + " : " + calendar        // );        ByteArrayOutputStream baos = serializeObject(calendar);        byte buf[] = baos.toByteArray();        ByteArrayInputStream bais = new ByteArrayInputStream(buf);        PreparedStatement ps = null;        try {            ps = conn.prepareStatement(rtp(INSERT_CALENDAR));            ps.setString(1, calendarName);            ps.setBinaryStream(2, bais, buf.length);            return ps.executeUpdate();        } finally {            if (null != ps) {                try {                    ps.close();                } catch (SQLException ignore) {                }            }        }    }    /**     * <p>     * Update a calendar.     * </p>     *      * @param conn     *          the DB Connection     * @param calendarName     *          the name for the new calendar     * @param calendar     *          the calendar     * @return the number of rows updated     * @throws IOException     *           if there were problems serializing the calendar     */    public int updateCalendar(Connection conn, String calendarName,            Calendar calendar) throws IOException, SQLException {        //log.debug( "Updating calendar " + calendarName + " : " + calendar );        ByteArrayOutputStream baos = serializeObject(calendar);        byte buf[] = baos.toByteArray();        ByteArrayInputStream bais = new ByteArrayInputStream(buf);        PreparedStatement ps = null;        try {            ps = conn.prepareStatement(rtp(UPDATE_CALENDAR));            ps.setBinaryStream(1, bais, buf.length);            ps.setString(2, calendarName);            return ps.executeUpdate();        } finally {            if (null != ps) {                try {                    ps.close();                } catch (SQLException ignore) {                }            }        }    }    //---------------------------------------------------------------------------    // protected methods that can be overridden by subclasses    //---------------------------------------------------------------------------    /**     * <p>     * This method should be overridden by any delegate subclasses that need     * special handling for BLOBs. The default implementation uses standard     * JDBC <code>java.sql.Blob</code> operations.     * </p>     *      * @param rs     *          the result set, already queued to the correct row     * @param colName     *          the column name for the BLOB     * @return the deserialized Object from the ResultSet BLOB     * @throws ClassNotFoundException     *           if a class found during deserialization cannot be found     * @throws IOException     *           if deserialization causes an error     */    protected Object getObjectFromBlob(ResultSet rs, String colName)            throws ClassNotFoundException, IOException, SQLException {        //log.debug( "Getting blob from column: " + colName );        Object obj = null;        byte binaryData[] = rs.getBytes(colName);        InputStream binaryInput = new ByteArrayInputStream(binaryData);        if (null != binaryInput) {            ObjectInputStream in = new ObjectInputStream(binaryInput);            obj = in.readObject();            in.close();        }        return obj;    }    /**     * <p>     * This method should be overridden by any delegate subclasses that need     * special handling for BLOBs for job details. The default implementation     * uses standard JDBC <code>java.sql.Blob</code> operations.     * </p>     *      * @param rs     *          the result set, already queued to the correct row     * @param colName     *          the column name for the BLOB     * @return the deserialized Object from the ResultSet BLOB     * @throws ClassNotFoundException     *           if a class found during deserialization cannot be found     * @throws IOException     *           if deserialization causes an error     */    protected Object getJobDetailFromBlob(ResultSet rs, String colName)            throws ClassNotFoundException, IOException, SQLException {        //log.debug( "Getting Job details from blob in col " + colName );        if (canUseProperties()) {            byte data[] = rs.getBytes(colName);            InputStream binaryInput = new ByteArrayInputStream(data);            return binaryInput;        }        return getObjectFromBlob(rs, colName);    }}// EOF

⌨️ 快捷键说明

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