001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.cron;
018:
019: import org.apache.avalon.framework.context.Context;
020: import org.apache.avalon.framework.logger.Logger;
021: import org.apache.avalon.framework.service.ServiceManager;
022:
023: import org.quartz.Calendar;
024: import org.quartz.CronTrigger;
025: import org.quartz.JobDataMap;
026: import org.quartz.JobDetail;
027: import org.quartz.SimpleTrigger;
028: import org.quartz.Trigger;
029: import org.quartz.impl.jdbcjobstore.DriverDelegate;
030: import org.quartz.spi.ClassLoadHelper;
031: import org.quartz.utils.Key;
032: import org.quartz.utils.TriggerStatus;
033:
034: import java.io.IOException;
035: import java.sql.Connection;
036: import java.sql.SQLException;
037: import java.util.List;
038: import java.util.Set;
039:
040: /**
041: * Wrapper around another DriverDelegate instance.
042: *
043: * <p>This wrapper makes sure that three Cocoon specific transient objects are
044: * removed from the JobDataMap before serializing it into the database, and
045: * populated back into the map when JobDetailMap is loaded from the database.
046: * These objects are:</p>
047: * <ul>
048: * <li>Logger</li>
049: * <li>ServiceManager</li>
050: * <li>Context</li>
051: * <li>
052: *
053: * @version CVS $Id: QuartzDriverDelegate.java 433543 2006-08-22 06:22:54Z crossley $
054: * @since 2.1.6
055: */
056: public class QuartzDriverDelegate implements DriverDelegate {
057: private Logger logger;
058: private ServiceManager manager;
059: private Context context;
060: private DriverDelegate delegate;
061:
062: public QuartzDriverDelegate(Logger logger, ServiceManager manager,
063: Context context, DriverDelegate delegate) {
064: this .logger = logger;
065: this .manager = manager;
066: this .context = context;
067: this .delegate = delegate;
068: }
069:
070: public int insertJobDetail(Connection conn, JobDetail job)
071: throws IOException, SQLException {
072: removeTransientData(job);
073: return delegate.insertJobDetail(conn, job);
074: }
075:
076: public int updateJobDetail(Connection conn, JobDetail job)
077: throws IOException, SQLException {
078: removeTransientData(job);
079: return delegate.updateJobDetail(conn, job);
080: }
081:
082: public int updateJobData(Connection conn, JobDetail job)
083: throws IOException, SQLException {
084: removeTransientData(job);
085: return delegate.updateJobData(conn, job);
086: }
087:
088: private void removeTransientData(JobDetail job) {
089: JobDataMap map = job.getJobDataMap();
090: if (map != null) {
091: this .logger
092: .debug("QuartzDriverDelegate: Removing transient data");
093: map.remove(QuartzJobScheduler.DATA_MAP_LOGGER);
094: map.remove(QuartzJobScheduler.DATA_MAP_CONTEXT);
095: map.remove(QuartzJobScheduler.DATA_MAP_MANAGER);
096: }
097: }
098:
099: public JobDetail selectJobDetail(Connection conn, String jobName,
100: String groupName, ClassLoadHelper loadHelper)
101: throws ClassNotFoundException, IOException, SQLException {
102: JobDetail job = delegate.selectJobDetail(conn, jobName,
103: groupName, loadHelper);
104: if (job != null) {
105: JobDataMap map = job.getJobDataMap();
106: if (map != null) {
107: this .logger
108: .debug("QuartzDriverDelegate: Adding transient data");
109: map
110: .put(QuartzJobScheduler.DATA_MAP_LOGGER,
111: this .logger);
112: map.put(QuartzJobScheduler.DATA_MAP_CONTEXT,
113: this .context);
114: map.put(QuartzJobScheduler.DATA_MAP_MANAGER,
115: this .manager);
116: }
117: }
118: return job;
119: }
120:
121: //
122: // Delegate all other methods
123: //
124:
125: public int updateTriggerStatesFromOtherStates(Connection conn,
126: String newState, String oldState1, String oldState2)
127: throws SQLException {
128: return delegate.updateTriggerStatesFromOtherStates(conn,
129: newState, oldState1, oldState2);
130: }
131:
132: public Key[] selectMisfiredTriggers(Connection conn, long ts)
133: throws SQLException {
134: return delegate.selectMisfiredTriggers(conn, ts);
135: }
136:
137: public Key[] selectMisfiredTriggersInState(Connection conn,
138: String state, long ts) throws SQLException {
139: return delegate.selectMisfiredTriggersInState(conn, state, ts);
140: }
141:
142: public Key[] selectMisfiredTriggersInGroupInState(Connection conn,
143: String groupName, String state, long ts)
144: throws SQLException {
145: return delegate.selectMisfiredTriggersInGroupInState(conn,
146: groupName, state, ts);
147: }
148:
149: public Trigger[] selectTriggersForRecoveringJobs(Connection conn)
150: throws SQLException, IOException, ClassNotFoundException {
151: return delegate.selectTriggersForRecoveringJobs(conn);
152: }
153:
154: public int deleteFiredTriggers(Connection conn) throws SQLException {
155: return delegate.deleteFiredTriggers(conn);
156: }
157:
158: public int deleteFiredTriggers(Connection conn, String instanceId)
159: throws SQLException {
160: return delegate.deleteFiredTriggers(conn, instanceId);
161: }
162:
163: public int deleteVolatileFiredTriggers(Connection conn)
164: throws SQLException {
165: return delegate.deleteVolatileFiredTriggers(conn);
166: }
167:
168: public Key[] selectVolatileTriggers(Connection conn)
169: throws SQLException {
170: return delegate.selectVolatileTriggers(conn);
171: }
172:
173: public Key[] selectVolatileJobs(Connection conn)
174: throws SQLException {
175: return delegate.selectVolatileJobs(conn);
176: }
177:
178: public Key[] selectTriggerNamesForJob(Connection conn,
179: String jobName, String groupName) throws SQLException {
180: return delegate.selectTriggerNamesForJob(conn, jobName,
181: groupName);
182: }
183:
184: public int deleteJobListeners(Connection conn, String jobName,
185: String groupName) throws SQLException {
186: return delegate.deleteJobListeners(conn, jobName, groupName);
187: }
188:
189: public int deleteJobDetail(Connection conn, String jobName,
190: String groupName) throws SQLException {
191: return delegate.deleteJobDetail(conn, jobName, groupName);
192: }
193:
194: public boolean isJobStateful(Connection conn, String jobName,
195: String groupName) throws SQLException {
196: return delegate.isJobStateful(conn, jobName, groupName);
197: }
198:
199: public boolean jobExists(Connection conn, String jobName,
200: String groupName) throws SQLException {
201: return delegate.jobExists(conn, jobName, groupName);
202: }
203:
204: public int insertJobListener(Connection conn, JobDetail job,
205: String listener) throws SQLException {
206: return delegate.insertJobListener(conn, job, listener);
207: }
208:
209: public String[] selectJobListeners(Connection conn, String jobName,
210: String groupName) throws SQLException {
211: return delegate.selectJobListeners(conn, jobName, groupName);
212: }
213:
214: public int selectNumJobs(Connection conn) throws SQLException {
215: return delegate.selectNumJobs(conn);
216: }
217:
218: public String[] selectJobGroups(Connection conn)
219: throws SQLException {
220: return delegate.selectJobGroups(conn);
221: }
222:
223: public String[] selectJobsInGroup(Connection conn, String groupName)
224: throws SQLException {
225: return delegate.selectJobsInGroup(conn, groupName);
226: }
227:
228: public int insertTrigger(Connection conn, Trigger trigger,
229: String state, JobDetail jobDetail) throws SQLException,
230: IOException {
231: return delegate.insertTrigger(conn, trigger, state, jobDetail);
232: }
233:
234: public int insertSimpleTrigger(Connection conn,
235: SimpleTrigger trigger) throws SQLException {
236: return delegate.insertSimpleTrigger(conn, trigger);
237: }
238:
239: public int insertBlobTrigger(Connection conn, Trigger trigger)
240: throws SQLException, IOException {
241: return delegate.insertBlobTrigger(conn, trigger);
242: }
243:
244: public int insertCronTrigger(Connection conn, CronTrigger trigger)
245: throws SQLException {
246: return delegate.insertCronTrigger(conn, trigger);
247: }
248:
249: public int updateTrigger(Connection conn, Trigger trigger,
250: String state, JobDetail jobDetail) throws SQLException,
251: IOException {
252: return delegate.updateTrigger(conn, trigger, state, jobDetail);
253: }
254:
255: public int updateSimpleTrigger(Connection conn,
256: SimpleTrigger trigger) throws SQLException {
257: return delegate.updateSimpleTrigger(conn, trigger);
258: }
259:
260: public int updateCronTrigger(Connection conn, CronTrigger trigger)
261: throws SQLException {
262: return delegate.updateCronTrigger(conn, trigger);
263: }
264:
265: public int updateBlobTrigger(Connection conn, Trigger trigger)
266: throws SQLException, IOException {
267: return delegate.updateBlobTrigger(conn, trigger);
268: }
269:
270: public boolean triggerExists(Connection conn, String triggerName,
271: String groupName) throws SQLException {
272: return delegate.triggerExists(conn, triggerName, groupName);
273: }
274:
275: public int updateTriggerState(Connection conn, String triggerName,
276: String groupName, String state) throws SQLException {
277: return delegate.updateTriggerState(conn, triggerName,
278: groupName, state);
279: }
280:
281: public int updateTriggerStateFromOtherState(Connection conn,
282: String triggerName, String groupName, String newState,
283: String oldState) throws SQLException {
284: return delegate.updateTriggerStateFromOtherState(conn,
285: triggerName, groupName, newState, oldState);
286: }
287:
288: public int updateTriggerStateFromOtherStates(Connection conn,
289: String triggerName, String groupName, String newState,
290: String oldState1, String oldState2, String oldState3)
291: throws SQLException {
292: return delegate.updateTriggerStateFromOtherStates(conn,
293: triggerName, groupName, newState, oldState1, oldState2,
294: oldState3);
295: }
296:
297: public int updateTriggerStateFromOtherStatesBeforeTime(
298: Connection conn, String newState, String oldState1,
299: String oldState2, long time) throws SQLException {
300: return delegate.updateTriggerStateFromOtherStatesBeforeTime(
301: conn, newState, oldState1, oldState2, time);
302: }
303:
304: public int updateTriggerGroupStateFromOtherStates(Connection conn,
305: String groupName, String newState, String oldState1,
306: String oldState2, String oldState3) throws SQLException {
307: return delegate.updateTriggerGroupStateFromOtherStates(conn,
308: groupName, newState, oldState1, oldState2, oldState3);
309: }
310:
311: public int updateTriggerGroupStateFromOtherState(Connection conn,
312: String groupName, String newState, String oldState)
313: throws SQLException {
314: return delegate.updateTriggerGroupStateFromOtherState(conn,
315: groupName, newState, oldState);
316: }
317:
318: public int updateTriggerStatesForJob(Connection conn,
319: String jobName, String groupName, String state)
320: throws SQLException {
321: return delegate.updateTriggerStatesForJob(conn, jobName,
322: groupName, state);
323: }
324:
325: public int updateTriggerStatesForJobFromOtherState(Connection conn,
326: String jobName, String groupName, String state,
327: String oldState) throws SQLException {
328: return delegate.updateTriggerStatesForJobFromOtherState(conn,
329: jobName, groupName, state, oldState);
330: }
331:
332: public int deleteTriggerListeners(Connection conn,
333: String triggerName, String groupName) throws SQLException {
334: return delegate.deleteTriggerListeners(conn, triggerName,
335: groupName);
336: }
337:
338: public int insertTriggerListener(Connection conn, Trigger trigger,
339: String listener) throws SQLException {
340: return delegate.insertTriggerListener(conn, trigger, listener);
341: }
342:
343: public String[] selectTriggerListeners(Connection conn,
344: String triggerName, String groupName) throws SQLException {
345: return delegate.selectTriggerListeners(conn, triggerName,
346: groupName);
347: }
348:
349: public int deleteSimpleTrigger(Connection conn, String triggerName,
350: String groupName) throws SQLException {
351: return delegate.deleteSimpleTrigger(conn, triggerName,
352: groupName);
353: }
354:
355: public int deleteBlobTrigger(Connection conn, String triggerName,
356: String groupName) throws SQLException {
357: return delegate.deleteBlobTrigger(conn, triggerName, groupName);
358: }
359:
360: public int deleteCronTrigger(Connection conn, String triggerName,
361: String groupName) throws SQLException {
362: return delegate.deleteCronTrigger(conn, triggerName, groupName);
363: }
364:
365: public int deleteTrigger(Connection conn, String triggerName,
366: String groupName) throws SQLException {
367: return delegate.deleteTrigger(conn, triggerName, groupName);
368: }
369:
370: public int selectNumTriggersForJob(Connection conn, String jobName,
371: String groupName) throws SQLException {
372: return delegate.selectNumTriggersForJob(conn, jobName,
373: groupName);
374: }
375:
376: public JobDetail selectJobForTrigger(Connection conn,
377: String triggerName, String groupName,
378: ClassLoadHelper loadHelper) throws SQLException,
379: ClassNotFoundException {
380: return delegate.selectJobForTrigger(conn, triggerName,
381: groupName, loadHelper);
382: }
383:
384: public List selectStatefulJobsOfTriggerGroup(Connection conn,
385: String groupName) throws SQLException {
386: return delegate.selectStatefulJobsOfTriggerGroup(conn,
387: groupName);
388: }
389:
390: public Trigger[] selectTriggersForJob(Connection conn,
391: String jobName, String groupName) throws SQLException,
392: ClassNotFoundException, IOException {
393: return delegate.selectTriggersForJob(conn, jobName, groupName);
394: }
395:
396: public Trigger[] selectTriggersForCalendar(Connection conn,
397: String calName) throws SQLException,
398: ClassNotFoundException, IOException {
399: return delegate.selectTriggersForCalendar(conn, calName);
400: }
401:
402: public Trigger selectTrigger(Connection conn, String triggerName,
403: String groupName) throws SQLException,
404: ClassNotFoundException, IOException {
405: return delegate.selectTrigger(conn, triggerName, groupName);
406: }
407:
408: public String selectTriggerState(Connection conn,
409: String triggerName, String groupName) throws SQLException {
410: return delegate
411: .selectTriggerState(conn, triggerName, groupName);
412: }
413:
414: public TriggerStatus selectTriggerStatus(Connection conn,
415: String triggerName, String groupName) throws SQLException {
416: return delegate.selectTriggerStatus(conn, triggerName,
417: groupName);
418: }
419:
420: public int selectNumTriggers(Connection conn) throws SQLException {
421: return delegate.selectNumTriggers(conn);
422: }
423:
424: public String[] selectTriggerGroups(Connection conn)
425: throws SQLException {
426: return delegate.selectTriggerGroups(conn);
427: }
428:
429: public String[] selectTriggersInGroup(Connection conn,
430: String groupName) throws SQLException {
431: return delegate.selectTriggersInGroup(conn, groupName);
432: }
433:
434: public Key[] selectTriggersInState(Connection conn, String state)
435: throws SQLException {
436: return delegate.selectTriggersInState(conn, state);
437: }
438:
439: public int insertPausedTriggerGroup(Connection conn,
440: String groupName) throws SQLException {
441: return delegate.insertPausedTriggerGroup(conn, groupName);
442: }
443:
444: public int deletePausedTriggerGroup(Connection conn,
445: String groupName) throws SQLException {
446: return delegate.deletePausedTriggerGroup(conn, groupName);
447: }
448:
449: public int deleteAllPausedTriggerGroups(Connection conn)
450: throws SQLException {
451: return delegate.deleteAllPausedTriggerGroups(conn);
452: }
453:
454: public boolean isTriggerGroupPaused(Connection conn,
455: String groupName) throws SQLException {
456: return delegate.isTriggerGroupPaused(conn, groupName);
457: }
458:
459: public Set selectPausedTriggerGroups(Connection conn)
460: throws SQLException {
461: return delegate.selectPausedTriggerGroups(conn);
462: }
463:
464: public boolean isExistingTriggerGroup(Connection conn,
465: String groupName) throws SQLException {
466: return delegate.isExistingTriggerGroup(conn, groupName);
467: }
468:
469: public int insertCalendar(Connection conn, String calendarName,
470: Calendar calendar) throws IOException, SQLException {
471: return delegate.insertCalendar(conn, calendarName, calendar);
472: }
473:
474: public int updateCalendar(Connection conn, String calendarName,
475: Calendar calendar) throws IOException, SQLException {
476: return delegate.updateCalendar(conn, calendarName, calendar);
477: }
478:
479: public boolean calendarExists(Connection conn, String calendarName)
480: throws SQLException {
481: return delegate.calendarExists(conn, calendarName);
482: }
483:
484: public Calendar selectCalendar(Connection conn, String calendarName)
485: throws ClassNotFoundException, IOException, SQLException {
486: return delegate.selectCalendar(conn, calendarName);
487: }
488:
489: public boolean calendarIsReferenced(Connection conn,
490: String calendarName) throws SQLException {
491: return delegate.calendarIsReferenced(conn, calendarName);
492: }
493:
494: public int deleteCalendar(Connection conn, String calendarName)
495: throws SQLException {
496: return delegate.deleteCalendar(conn, calendarName);
497: }
498:
499: public int selectNumCalendars(Connection conn) throws SQLException {
500: return delegate.selectNumCalendars(conn);
501: }
502:
503: public String[] selectCalendars(Connection conn)
504: throws SQLException {
505: return delegate.selectCalendars(conn);
506: }
507:
508: public long selectNextFireTime(Connection conn) throws SQLException {
509: return delegate.selectNextFireTime(conn);
510: }
511:
512: public Key selectTriggerForFireTime(Connection conn, long fireTime)
513: throws SQLException {
514: return delegate.selectTriggerForFireTime(conn, fireTime);
515: }
516:
517: public int insertFiredTrigger(Connection conn, Trigger trigger,
518: String state, JobDetail jobDetail) throws SQLException {
519: return delegate.insertFiredTrigger(conn, trigger, state,
520: jobDetail);
521: }
522:
523: public List selectFiredTriggerRecords(Connection conn,
524: String triggerName, String groupName) throws SQLException {
525: return delegate.selectFiredTriggerRecords(conn, triggerName,
526: groupName);
527: }
528:
529: public List selectFiredTriggerRecordsByJob(Connection conn,
530: String jobName, String groupName) throws SQLException {
531: return delegate.selectFiredTriggerRecordsByJob(conn, jobName,
532: groupName);
533: }
534:
535: public List selectInstancesFiredTriggerRecords(Connection conn,
536: String instanceName) throws SQLException {
537: return delegate.selectInstancesFiredTriggerRecords(conn,
538: instanceName);
539: }
540:
541: public int deleteFiredTrigger(Connection conn, String entryId)
542: throws SQLException {
543: return delegate.deleteFiredTrigger(conn, entryId);
544: }
545:
546: public int selectJobExecutionCount(Connection conn, String jobName,
547: String jobGroup) throws SQLException {
548: return delegate
549: .selectJobExecutionCount(conn, jobName, jobGroup);
550: }
551:
552: public int insertSchedulerState(Connection conn, String instanceId,
553: long checkInTime, long interval, String recoverer)
554: throws SQLException {
555: return delegate.insertSchedulerState(conn, instanceId,
556: checkInTime, interval, recoverer);
557: }
558:
559: public int deleteSchedulerState(Connection conn, String instanceId)
560: throws SQLException {
561: return delegate.deleteSchedulerState(conn, instanceId);
562: }
563:
564: public List selectSchedulerStateRecords(Connection conn,
565: String instanceId) throws SQLException {
566: return delegate.selectSchedulerStateRecords(conn, instanceId);
567: }
568:
569: public JobDataMap selectTriggerJobDataMap(Connection conn,
570: String triggerName, String groupName) throws SQLException,
571: ClassNotFoundException, IOException {
572: return delegate.selectTriggerJobDataMap(conn, triggerName,
573: groupName);
574: }
575:
576: public int updateSchedulerState(Connection conn, String instanceId,
577: long checkInTime, String recoverer) throws SQLException {
578: return delegate.updateSchedulerState(conn, instanceId,
579: checkInTime, recoverer);
580: }
581: }
|