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

📄 jobstoresupport.java

📁 非常好用的计划任务调度包,能定义复杂的任务
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            return trigger;        } catch (Exception e) {            throw new JobPersistenceException("Couldn't retrieve trigger: "                    + e.getMessage(), e);        }    }    public int getTriggerState(Connection conn, SchedulingContext ctxt,            String triggerName, String groupName)            throws JobPersistenceException {        try {            String ts = getDelegate().selectTriggerState(conn, triggerName,                    groupName);            if (ts == null) return Trigger.STATE_NONE;            if (ts.equals(STATE_DELETED)) return Trigger.STATE_NONE;            if (ts.equals(STATE_COMPLETE)) return Trigger.STATE_COMPLETE;            if (ts.equals(STATE_PAUSED)) return Trigger.STATE_PAUSED;            if (ts.equals(STATE_ERROR)) return Trigger.STATE_ERROR;            if (ts.equals(STATE_BLOCKED)) return Trigger.STATE_BLOCKED;            return Trigger.STATE_NORMAL;        } catch (SQLException e) {            throw new JobPersistenceException(                    "Couldn't determine state of trigger (" + groupName + "."                            + triggerName + "): " + e.getMessage(), e);        }    }    protected void storeCalendar(Connection conn, SchedulingContext ctxt,            String calName, Calendar calendar, boolean replaceExisting, boolean updateTriggers)            throws ObjectAlreadyExistsException, JobPersistenceException {        try {            boolean existingCal = calendarExists(conn, calName);            if (existingCal && !replaceExisting) { throw new ObjectAlreadyExistsException(                    "Calendar with name '" + calName + "' already exists."); }            if (existingCal) {                if (getDelegate().updateCalendar(conn, calName, calendar) < 1) { throw new JobPersistenceException(                        "Couldn't store calendar.  Update failed."); }                                if(updateTriggers) {                    Trigger[] trigs = getDelegate().selectTriggersForCalendar(conn, calName);                                        for(int i=0; i < trigs.length; i++) {                        trigs[i].updateWithNewCalendar(calendar, getMisfireThreshold());                        storeTrigger(conn, ctxt, trigs[i], null, true, STATE_WAITING, false, false);                    }                }            } else {                if (getDelegate().insertCalendar(conn, calName, calendar) < 1) { throw new JobPersistenceException(                        "Couldn't store calendar.  Insert failed."); }            }            calendarCache.put(calName, calendar); // lazy-cache        } catch (IOException e) {            throw new JobPersistenceException(                    "Couldn't store calendar because the BLOB couldn't be serialized: "                            + e.getMessage(), e);        } catch (ClassNotFoundException e) {            throw new JobPersistenceException("Couldn't store calendar: "                    + e.getMessage(), e);        }catch (SQLException e) {            throw new JobPersistenceException("Couldn't store calendar: "                    + e.getMessage(), e);        }    }        protected boolean calendarExists(Connection conn, String calName)            throws JobPersistenceException {        try {            return getDelegate().calendarExists(conn, calName);        } catch (SQLException e) {            throw new JobPersistenceException(                    "Couldn't determine calendar existence (" + calName + "): "                            + e.getMessage(), e);        }    }    protected boolean removeCalendar(Connection conn, SchedulingContext ctxt,            String calName) throws JobPersistenceException {        try {            if (getDelegate().calendarIsReferenced(conn, calName)) { throw new JobPersistenceException(                    "Calender cannot be removed if it referenced by a trigger!"); }            calendarCache.remove(calName);            return (getDelegate().deleteCalendar(conn, calName) > 0);        } catch (SQLException e) {            throw new JobPersistenceException("Couldn't remove calendar: "                    + e.getMessage(), e);        }    }    protected Calendar retrieveCalendar(Connection conn,            SchedulingContext ctxt, String calName)            throws JobPersistenceException {        // all calendars are persistent, but we lazy-cache them during run        // time...        Calendar cal = (Calendar) calendarCache.get(calName);        if (cal != null) return cal;        try {            cal = getDelegate().selectCalendar(conn, calName);            calendarCache.put(calName, cal); // lazy-cache...            return cal;        } catch (ClassNotFoundException e) {            throw new JobPersistenceException(                    "Couldn't retrieve calendar because a required class was not found: "                            + e.getMessage(), e);        } catch (IOException e) {            throw new JobPersistenceException(                    "Couldn't retrieve calendar because the BLOB couldn't be deserialized: "                            + e.getMessage(), e);        } catch (SQLException e) {            throw new JobPersistenceException("Couldn't retrieve calendar: "                    + e.getMessage(), e);        }    }    protected int getNumberOfJobs(Connection conn, SchedulingContext ctxt)            throws JobPersistenceException {        try {            return getDelegate().selectNumJobs(conn);        } catch (SQLException e) {            throw new JobPersistenceException(                    "Couldn't obtain number of jobs: " + e.getMessage(), e);        }    }    protected int getNumberOfTriggers(Connection conn, SchedulingContext ctxt)            throws JobPersistenceException {        try {            return getDelegate().selectNumTriggers(conn);        } catch (SQLException e) {            throw new JobPersistenceException(                    "Couldn't obtain number of triggers: " + e.getMessage(), e);        }    }    protected int getNumberOfCalendars(Connection conn, SchedulingContext ctxt)            throws JobPersistenceException {        try {            return getDelegate().selectNumCalendars(conn);        } catch (SQLException e) {            throw new JobPersistenceException(                    "Couldn't obtain number of calendars: " + e.getMessage(), e);        }    }    protected String[] getJobNames(Connection conn, SchedulingContext ctxt,            String groupName) throws JobPersistenceException {        String[] jobNames = null;        try {            jobNames = getDelegate().selectJobsInGroup(conn, groupName);        } catch (SQLException e) {            throw new JobPersistenceException("Couldn't obtain job names: "                    + e.getMessage(), e);        }        return jobNames;    }    protected String[] getTriggerNames(Connection conn, SchedulingContext ctxt,            String groupName) throws JobPersistenceException {        String[] trigNames = null;        try {            trigNames = getDelegate().selectTriggersInGroup(conn, groupName);        } catch (SQLException e) {            throw new JobPersistenceException("Couldn't obtain trigger names: "                    + e.getMessage(), e);        }        return trigNames;    }    protected String[] getJobGroupNames(Connection conn, SchedulingContext ctxt)            throws JobPersistenceException {        String[] groupNames = null;        try {            groupNames = getDelegate().selectJobGroups(conn);        } catch (SQLException e) {            throw new JobPersistenceException("Couldn't obtain job groups: "                    + e.getMessage(), e);        }        return groupNames;    }    protected String[] getTriggerGroupNames(Connection conn,            SchedulingContext ctxt) throws JobPersistenceException {        String[] groupNames = null;        try {            groupNames = getDelegate().selectTriggerGroups(conn);        } catch (SQLException e) {            throw new JobPersistenceException(                    "Couldn't obtain trigger groups: " + e.getMessage(), e);        }        return groupNames;    }    protected String[] getCalendarNames(Connection conn, SchedulingContext ctxt)            throws JobPersistenceException {        try {            return getDelegate().selectCalendars(conn);        } catch (SQLException e) {            throw new JobPersistenceException(                    "Couldn't obtain trigger groups: " + e.getMessage(), e);        }    }    protected Trigger[] getTriggersForJob(Connection conn,            SchedulingContext ctxt, String jobName, String groupName)            throws JobPersistenceException {        Trigger[] array = null;        try {            array = getDelegate()                    .selectTriggersForJob(conn, jobName, groupName);        } catch (Exception e) {            throw new JobPersistenceException(                    "Couldn't obtain triggers for job: " + e.getMessage(), e);        }        return array;    }    /**     * <p>     * Pause the <code>{@link org.quartz.Trigger}</code> with the given name.     * </p>     *      * @see #resumeTrigger(Connection, SchedulingContext, String, String)     */    public void pauseTrigger(Connection conn, SchedulingContext ctxt,            String triggerName, String groupName)            throws JobPersistenceException {        try {            String oldState = getDelegate().selectTriggerState(conn,                    triggerName, groupName);            if (oldState.equals(STATE_WAITING)                    || oldState.equals(STATE_BLOCKED)                    || oldState.equals(STATE_ACQUIRED)) {                getDelegate().updateTriggerState(conn, triggerName,                        groupName, STATE_PAUSED);            }        } catch (SQLException e) {            throw new JobPersistenceException("Couldn't pause trigger '"                    + groupName + "." + triggerName + "': " + e.getMessage(), e);        }    }    protected String getStatusForResumedTrigger(Connection conn,            SchedulingContext ctxt, TriggerStatus status)            throws JobPersistenceException {        try {            String newState = STATE_WAITING;            List lst = getDelegate()                    .selectFiredTriggerRecordsByJob(conn,                            status.getJobKey().getName(),                            status.getJobKey().getGroup());            if (lst.size() > 0) {                FiredTriggerRecord rec = (FiredTriggerRecord) lst.get(0);                if (rec.isJobIsStateful()) // TODO: worry about                        // failed/recovering/volatile job                        // states?                        newState = STATE_BLOCKED;            }            return newState;        } catch (SQLException e) {            throw new JobPersistenceException(                    "Couldn't determine new state in order to resume trigger '"                            + status.getKey().getGroup() + "."                            + status.getKey().getName() + "': "                            + e.getMessage(), e);        }    }    protected String getNewStatusForTrigger(Connection conn,            SchedulingContext ctxt, String jobName, String groupName)            throws JobPersistenceException {        try {            String newState = STATE_WAITING;            List lst = getDelegate().selectFiredTriggerRecordsByJob(conn,                    jobName, groupName);            if (lst.size() > 0) {                FiredTriggerRecord rec = (FiredTriggerRecord) lst.get(0);                if (rec.isJobIsStateful()) // TODO: worry about                        // failed/recovering/volatile job                        // states?                        newState = STATE_BLOCKED;            }            return newState;        } catch (SQLException e) {            throw new JobPersistenceException(                    "Couldn't determine state for new trigger: "                            + e.getMessage(), e);        }    }    /*     * private List findTriggersToBeBlocked(Connection conn, SchedulingContext     * ctxt, String groupName) throws JobPersistenceException {     *      * try { List blockList = new LinkedList();     *      * List affectingJobs =     * getDelegate().selectStatefulJobsOfTriggerGroup(conn, groupName);     *      * Iterator itr = affectingJobs.iterator(); while(itr.hasNext()) { Key     * jobKey = (Key) itr.next();     *      * List lst = getDelegate().selectFiredTriggerRecordsByJob(conn,     * jobKey.getName(), jobKey.getGroup());     *      * This logic is BROKEN...     *      * if(lst.size() > 0) { FiredTriggerRecord rec =     * (FiredTriggerRecord)lst.get(0); if(rec.isJobIsStateful()) // TODO: worry     * about failed/recovering/volatile job states? blockList.add(     * rec.getTriggerKey() ); } }     *      *      * return blockList; } catch (SQLException e) { throw new     * JobPersistenceException ("Couldn't determine states of resumed triggers     * in group '" + groupName + "': " + e.getMessage(), e); } }     */    /**     * <p>     * Resume (un-pause) the <code>{@link org.quartz.Trigger}</code> with the     * given name.     * </p>     *      * <p>     * If the <code>Trigger</code> missed one or more fire-times, then the     * <code>Trigger</code>'s misfire instruction will be applied.     * </p>     * 

⌨️ 快捷键说明

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