1
22
23 package com.liferay.portal.scheduler.quartz;
24
25 import com.liferay.portal.dao.db.DB2DB;
26 import com.liferay.portal.dao.db.DerbyDB;
27 import com.liferay.portal.dao.db.HypersonicDB;
28 import com.liferay.portal.dao.db.PostgreSQLDB;
29 import com.liferay.portal.dao.db.SQLServerDB;
30 import com.liferay.portal.dao.db.SybaseDB;
31 import com.liferay.portal.kernel.dao.db.DB;
32 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
33 import com.liferay.portal.kernel.log.LogFactoryUtil;
34
35 import java.io.IOException;
36
37 import java.lang.reflect.Constructor;
38
39 import java.sql.Connection;
40 import java.sql.SQLException;
41
42 import java.util.List;
43 import java.util.Set;
44
45 import org.apache.commons.logging.Log;
46
47 import org.quartz.Calendar;
48 import org.quartz.CronTrigger;
49 import org.quartz.JobDataMap;
50 import org.quartz.JobDetail;
51 import org.quartz.SimpleTrigger;
52 import org.quartz.Trigger;
53 import org.quartz.impl.jdbcjobstore.CloudscapeDelegate;
54 import org.quartz.impl.jdbcjobstore.DB2v7Delegate;
55 import org.quartz.impl.jdbcjobstore.HSQLDBDelegate;
56 import org.quartz.impl.jdbcjobstore.MSSQLDelegate;
57 import org.quartz.impl.jdbcjobstore.PostgreSQLDelegate;
58 import org.quartz.impl.jdbcjobstore.StdJDBCDelegate;
59 import org.quartz.spi.ClassLoadHelper;
60 import org.quartz.utils.Key;
61 import org.quartz.utils.TriggerStatus;
62
63
68 public class DynamicDriverDelegate extends StdJDBCDelegate {
69
70 public DynamicDriverDelegate(
71 Log logger, String tablePrefix, String instanceId) {
72
73 super(logger, tablePrefix, instanceId);
74
75 try {
76 Class<?> driverDelegateClass = getDriverDelegateClass();
77
78 Constructor<?> driverDelegateConstructor =
79 driverDelegateClass.getConstructor(
80 Log.class, String.class, String.class);
81
82 _jdbcDelegate =
83 (StdJDBCDelegate)driverDelegateConstructor.newInstance(
84 logger, tablePrefix, instanceId);
85 }
86 catch (Exception e) {
87 _log.error(e, e);
88 }
89 }
90
91 public DynamicDriverDelegate(
92 Log logger, String tablePrefix, String instanceId,
93 Boolean useProperties) {
94
95 super(logger, tablePrefix, instanceId, useProperties);
96
97 try {
98 Class<?> driverDelegateClass = getDriverDelegateClass();
99
100 Constructor<?> driverDelegateConstructor =
101 driverDelegateClass.getConstructor(
102 Log.class, String.class, String.class, Boolean.class);
103
104 _jdbcDelegate =
105 (StdJDBCDelegate)driverDelegateConstructor.newInstance(
106 logger, tablePrefix, instanceId, useProperties);
107 }
108 catch (Exception e) {
109 _log.error(e, e);
110 }
111 }
112
113 public boolean calendarExists(Connection conn, String calendarName)
114 throws SQLException {
115
116 return _jdbcDelegate.calendarExists(conn, calendarName);
117 }
118
119 public boolean calendarIsReferenced(Connection conn, String calendarName)
120 throws SQLException {
121
122 return _jdbcDelegate.calendarIsReferenced(conn, calendarName);
123 }
124
125 public int countMisfiredTriggersInStates(
126 Connection conn, String state1, String state2, long ts)
127 throws SQLException {
128
129 return _jdbcDelegate.countMisfiredTriggersInStates(
130 conn, state1, state2, ts);
131 }
132
133 public int deleteAllPausedTriggerGroups(Connection arg0)
134 throws SQLException {
135
136 return _jdbcDelegate.deleteAllPausedTriggerGroups(arg0);
137 }
138
139 public int deleteBlobTrigger(
140 Connection conn, String triggerName, String groupName)
141 throws SQLException {
142
143 return _jdbcDelegate.deleteBlobTrigger(conn, triggerName, groupName);
144 }
145
146 public int deleteCalendar(Connection conn, String calendarName)
147 throws SQLException {
148
149 return _jdbcDelegate.deleteCalendar(conn, calendarName);
150 }
151
152 public int deleteCronTrigger(
153 Connection conn, String triggerName, String groupName)
154 throws SQLException {
155
156 return _jdbcDelegate.deleteCronTrigger(conn, triggerName, groupName);
157 }
158
159 public int deleteFiredTrigger(Connection conn, String entryId)
160 throws SQLException {
161
162 return _jdbcDelegate.deleteFiredTrigger(conn, entryId);
163 }
164
165 public int deleteFiredTriggers(Connection conn) throws SQLException {
166 return _jdbcDelegate.deleteFiredTriggers(conn);
167 }
168
169 public int deleteFiredTriggers(Connection conn, String instanceId)
170 throws SQLException {
171
172 return _jdbcDelegate.deleteFiredTriggers(conn, instanceId);
173 }
174
175 public int deleteJobDetail(
176 Connection conn, String jobName, String groupName)
177 throws SQLException {
178
179 return _jdbcDelegate.deleteJobDetail(conn, jobName, groupName);
180 }
181
182 public int deleteJobListeners(
183 Connection conn, String jobName, String groupName)
184 throws SQLException {
185
186 return _jdbcDelegate.deleteJobListeners(conn, jobName, groupName);
187 }
188
189 public int deletePausedTriggerGroup(Connection arg0, String arg1)
190 throws SQLException {
191
192 return _jdbcDelegate.deletePausedTriggerGroup(arg0, arg1);
193 }
194
195 public int deleteSchedulerState(Connection conn, String instanceId)
196 throws SQLException {
197
198 return _jdbcDelegate.deleteSchedulerState(conn, instanceId);
199 }
200
201 public int deleteSimpleTrigger(
202 Connection conn, String triggerName, String groupName)
203 throws SQLException {
204
205 return _jdbcDelegate.deleteSimpleTrigger(conn, triggerName, groupName);
206 }
207
208 public int deleteTrigger(
209 Connection conn, String triggerName, String groupName)
210 throws SQLException {
211
212 return _jdbcDelegate.deleteTrigger(conn, triggerName, groupName);
213 }
214
215 public int deleteTriggerListeners(
216 Connection conn, String triggerName, String groupName)
217 throws SQLException {
218
219 return _jdbcDelegate.deleteTriggerListeners(
220 conn, triggerName, groupName);
221 }
222
223 public int deleteVolatileFiredTriggers(Connection conn)
224 throws SQLException {
225
226 return _jdbcDelegate.deleteVolatileFiredTriggers(conn);
227 }
228
229 public int insertBlobTrigger(Connection arg0, Trigger arg1)
230 throws SQLException, IOException {
231
232 return _jdbcDelegate.insertBlobTrigger(arg0, arg1);
233 }
234
235 public int insertCalendar(
236 Connection conn, String calendarName, Calendar calendar)
237 throws IOException, SQLException {
238
239 return _jdbcDelegate.insertCalendar(conn, calendarName, calendar);
240 }
241
242 public int insertCronTrigger(Connection conn, CronTrigger trigger)
243 throws SQLException {
244
245 return _jdbcDelegate.insertCronTrigger(conn, trigger);
246 }
247
248 public int insertFiredTrigger(
249 Connection conn, Trigger trigger, String state, JobDetail job)
250 throws SQLException {
251
252 return _jdbcDelegate.insertFiredTrigger(conn, trigger, state, job);
253 }
254
255 public int insertJobDetail(Connection arg0, JobDetail arg1)
256 throws IOException, SQLException {
257
258 return _jdbcDelegate.insertJobDetail(arg0, arg1);
259 }
260
261 public int insertJobListener(
262 Connection conn, JobDetail job, String listener)
263 throws SQLException {
264
265 return _jdbcDelegate.insertJobListener(conn, job, listener);
266 }
267
268 public int insertPausedTriggerGroup(Connection arg0, String arg1)
269 throws SQLException {
270
271 return _jdbcDelegate.insertPausedTriggerGroup(arg0, arg1);
272 }
273
274 public int insertSchedulerState(
275 Connection conn, String instanceId, long checkInTime, long interval)
276 throws SQLException {
277
278 return _jdbcDelegate.insertSchedulerState(
279 conn, instanceId, checkInTime, interval);
280 }
281
282 public int insertSimpleTrigger(Connection conn, SimpleTrigger trigger)
283 throws SQLException {
284
285 return _jdbcDelegate.insertSimpleTrigger(conn, trigger);
286 }
287
288 public int insertTrigger(
289 Connection arg0, Trigger arg1, String arg2, JobDetail arg3)
290 throws SQLException, IOException {
291
292 return _jdbcDelegate.insertTrigger(arg0, arg1, arg2, arg3);
293 }
294
295 public int insertTriggerListener(
296 Connection conn, Trigger trigger, String listener)
297 throws SQLException {
298
299 return _jdbcDelegate.insertTriggerListener(conn, trigger, listener);
300 }
301
302 public boolean isExistingTriggerGroup(Connection conn, String groupName)
303 throws SQLException {
304
305 return _jdbcDelegate.isExistingTriggerGroup(conn, groupName);
306 }
307
308 public boolean isJobStateful(
309 Connection conn, String jobName, String groupName)
310 throws SQLException {
311
312 return _jdbcDelegate.isJobStateful(conn, jobName, groupName);
313 }
314
315 public boolean isTriggerGroupPaused(Connection conn, String groupName)
316 throws SQLException {
317
318 return _jdbcDelegate.isTriggerGroupPaused(conn, groupName);
319 }
320
321 public boolean jobExists(Connection conn, String jobName, String groupName)
322 throws SQLException {
323
324 return _jdbcDelegate.jobExists(conn, jobName, groupName);
325 }
326
327 public Calendar selectCalendar(Connection arg0, String arg1)
328 throws ClassNotFoundException, IOException, SQLException {
329
330 return _jdbcDelegate.selectCalendar(arg0, arg1);
331 }
332
333 public String[] selectCalendars(Connection arg0) throws SQLException {
334 return _jdbcDelegate.selectCalendars(arg0);
335 }
336
337 public Set selectFiredTriggerInstanceNames(Connection arg0)
338 throws SQLException {
339
340 return _jdbcDelegate.selectFiredTriggerInstanceNames(arg0);
341 }
342
343 public List selectFiredTriggerRecords(
344 Connection arg0, String arg1, String arg2)
345 throws SQLException {
346
347 return _jdbcDelegate.selectFiredTriggerRecords(arg0, arg1, arg2);
348 }
349
350 public List selectFiredTriggerRecordsByJob(
351 Connection arg0, String arg1, String arg2)
352 throws SQLException {
353
354 return _jdbcDelegate.selectFiredTriggerRecordsByJob(arg0, arg1, arg2);
355 }
356
357 public List selectInstancesFiredTriggerRecords(Connection arg0, String arg1)
358 throws SQLException {
359
360 return _jdbcDelegate.selectInstancesFiredTriggerRecords(arg0, arg1);
361 }
362
363 public JobDetail selectJobDetail(
364 Connection arg0, String arg1, String arg2, ClassLoadHelper arg3)
365 throws ClassNotFoundException, IOException, SQLException {
366
367 return _jdbcDelegate.selectJobDetail(arg0, arg1, arg2, arg3);
368 }
369
370 public int selectJobExecutionCount(
371 Connection conn, String jobName, String jobGroup)
372 throws SQLException {
373
374 return _jdbcDelegate.selectJobExecutionCount(conn, jobName, jobGroup);
375 }
376
377 public JobDetail selectJobForTrigger(
378 Connection arg0, String arg1, String arg2, ClassLoadHelper arg3)
379 throws ClassNotFoundException, SQLException {
380
381 return _jdbcDelegate.selectJobForTrigger(arg0, arg1, arg2, arg3);
382 }
383
384 public String[] selectJobGroups(Connection arg0) throws SQLException {
385 return _jdbcDelegate.selectJobGroups(arg0);
386 }
387
388 public String[] selectJobListeners(
389 Connection arg0, String arg1, String arg2)
390 throws SQLException {
391
392 return _jdbcDelegate.selectJobListeners(arg0, arg1, arg2);
393 }
394
395 public String[] selectJobsInGroup(Connection arg0, String arg1)
396 throws SQLException {
397
398 return _jdbcDelegate.selectJobsInGroup(arg0, arg1);
399 }
400
401 public Key[] selectMisfiredTriggers(Connection arg0, long arg1)
402 throws SQLException {
403
404 return _jdbcDelegate.selectMisfiredTriggers(arg0, arg1);
405 }
406
407 public Key[] selectMisfiredTriggersInGroupInState(
408 Connection arg0, String arg1, String arg2, long arg3)
409 throws SQLException {
410
411 return _jdbcDelegate.selectMisfiredTriggersInGroupInState(
412 arg0, arg1, arg2, arg3);
413 }
414
415 public Key[] selectMisfiredTriggersInState(
416 Connection arg0, String arg1, long arg2)
417 throws SQLException {
418
419 return _jdbcDelegate.selectMisfiredTriggersInState(arg0, arg1, arg2);
420 }
421
422 public boolean selectMisfiredTriggersInStates(
423 Connection arg0, String arg1, String arg2, long arg3, int arg4,
424 List arg5)
425 throws SQLException {
426
427 return _jdbcDelegate.selectMisfiredTriggersInStates(
428 arg0, arg1, arg2, arg3, arg4, arg5);
429 }
430
431
434 public long selectNextFireTime(Connection conn) throws SQLException {
435 return _jdbcDelegate.selectNextFireTime(conn);
436 }
437
438 public int selectNumCalendars(Connection arg0) throws SQLException {
439 return _jdbcDelegate.selectNumCalendars(arg0);
440 }
441
442 public int selectNumJobs(Connection arg0) throws SQLException {
443 return _jdbcDelegate.selectNumJobs(arg0);
444 }
445
446 public int selectNumTriggers(Connection arg0) throws SQLException {
447 return _jdbcDelegate.selectNumTriggers(arg0);
448 }
449
450 public int selectNumTriggersForJob(
451 Connection conn, String jobName, String groupName)
452 throws SQLException {
453
454 return _jdbcDelegate.selectNumTriggersForJob(conn, jobName, groupName);
455 }
456
457 public Set selectPausedTriggerGroups(Connection arg0) throws SQLException {
458 return _jdbcDelegate.selectPausedTriggerGroups(arg0);
459 }
460
461 public List selectSchedulerStateRecords(Connection arg0, String arg1)
462 throws SQLException {
463
464 return _jdbcDelegate.selectSchedulerStateRecords(arg0, arg1);
465 }
466
467 public List selectStatefulJobsOfTriggerGroup(
468 Connection conn, String groupName)
469 throws SQLException {
470
471 return _jdbcDelegate.selectStatefulJobsOfTriggerGroup(conn, groupName);
472 }
473
474 public Trigger selectTrigger(Connection arg0, String arg1, String arg2)
475 throws SQLException, ClassNotFoundException, IOException {
476
477 return _jdbcDelegate.selectTrigger(arg0, arg1, arg2);
478 }
479
480 public Key selectTriggerForFireTime(Connection conn, long fireTime)
481 throws SQLException {
482
483 return _jdbcDelegate.selectTriggerForFireTime(conn, fireTime);
484 }
485
486 public String[] selectTriggerGroups(Connection arg0)
487 throws SQLException {
488
489 return _jdbcDelegate.selectTriggerGroups(arg0);
490 }
491
492 public JobDataMap selectTriggerJobDataMap(
493 Connection arg0, String arg1, String arg2)
494 throws SQLException, ClassNotFoundException, IOException {
495
496 return _jdbcDelegate.selectTriggerJobDataMap(arg0, arg1, arg2);
497 }
498
499 public String[] selectTriggerListeners(
500 Connection arg0, String arg1, String arg2)
501 throws SQLException {
502
503 return _jdbcDelegate.selectTriggerListeners(arg0, arg1, arg2);
504 }
505
506 public Key[] selectTriggerNamesForJob(
507 Connection arg0, String arg1, String arg2)
508 throws SQLException {
509
510 return _jdbcDelegate.selectTriggerNamesForJob(arg0, arg1, arg2);
511 }
512
513 public Trigger[] selectTriggersForCalendar(Connection conn, String calName)
514 throws SQLException, ClassNotFoundException, IOException {
515
516 return _jdbcDelegate.selectTriggersForCalendar(conn, calName);
517 }
518
519 public Trigger[] selectTriggersForJob(
520 Connection arg0, String arg1, String arg2)
521 throws SQLException, ClassNotFoundException, IOException {
522
523 return _jdbcDelegate.selectTriggersForJob(arg0, arg1, arg2);
524 }
525
526 public Trigger[] selectTriggersForRecoveringJobs(Connection arg0)
527 throws SQLException, IOException, ClassNotFoundException {
528
529 return _jdbcDelegate.selectTriggersForRecoveringJobs(arg0);
530 }
531
532 public String[] selectTriggersInGroup(Connection arg0, String arg1)
533 throws SQLException {
534
535 return _jdbcDelegate.selectTriggersInGroup(arg0, arg1);
536 }
537
538 public Key[] selectTriggersInState(Connection arg0, String arg1)
539 throws SQLException {
540
541 return _jdbcDelegate.selectTriggersInState(arg0, arg1);
542 }
543
544 public String selectTriggerState(Connection arg0, String arg1, String arg2)
545 throws SQLException {
546
547 return _jdbcDelegate.selectTriggerState(arg0, arg1, arg2);
548 }
549
550 public TriggerStatus selectTriggerStatus(
551 Connection arg0, String arg1, String arg2)
552 throws SQLException {
553
554 return _jdbcDelegate.selectTriggerStatus(arg0, arg1, arg2);
555 }
556
557 public Key selectTriggerToAcquire(
558 Connection conn, long noLaterThan, long noEarlierThan)
559 throws SQLException {
560
561 return _jdbcDelegate.selectTriggerToAcquire(
562 conn, noLaterThan, noEarlierThan);
563 }
564
565 public Key[] selectVolatileJobs(Connection arg0) throws SQLException {
566 return _jdbcDelegate.selectVolatileJobs(arg0);
567 }
568
569 public Key[] selectVolatileTriggers(Connection arg0) throws SQLException {
570 return _jdbcDelegate.selectVolatileTriggers(arg0);
571 }
572
573 public boolean triggerExists(
574 Connection conn, String triggerName, String groupName)
575 throws SQLException {
576
577 return _jdbcDelegate.triggerExists(conn, triggerName, groupName);
578 }
579
580 public int updateBlobTrigger(Connection arg0, Trigger arg1)
581 throws SQLException, IOException {
582
583 return _jdbcDelegate.updateBlobTrigger(arg0, arg1);
584 }
585
586 public int updateCalendar(
587 Connection conn, String calendarName, Calendar calendar)
588 throws IOException, SQLException {
589
590 return _jdbcDelegate.updateCalendar(conn, calendarName, calendar);
591 }
592
593 public int updateCronTrigger(Connection conn, CronTrigger trigger)
594 throws SQLException {
595
596 return _jdbcDelegate.updateCronTrigger(conn, trigger);
597 }
598
599 public int updateJobData(Connection conn, JobDetail job)
600 throws IOException, SQLException {
601
602 return _jdbcDelegate.updateJobData(conn, job);
603 }
604
605 public int updateJobDetail(Connection arg0, JobDetail arg1)
606 throws IOException, SQLException {
607
608 return _jdbcDelegate.updateJobDetail(arg0, arg1);
609 }
610
611 public int updateSchedulerState(
612 Connection conn, String instanceId, long checkInTime)
613 throws SQLException {
614
615 return _jdbcDelegate.updateSchedulerState(
616 conn, instanceId, checkInTime);
617 }
618
619 public int updateSimpleTrigger(Connection conn, SimpleTrigger trigger)
620 throws SQLException {
621
622 return _jdbcDelegate.updateSimpleTrigger(conn, trigger);
623 }
624
625 public int updateTrigger(
626 Connection arg0, Trigger arg1, String arg2, JobDetail arg3)
627 throws SQLException, IOException {
628
629 return _jdbcDelegate.updateTrigger(arg0, arg1, arg2, arg3);
630 }
631
632 public int updateTriggerGroupStateFromOtherState(
633 Connection conn, String groupName, String newState, String oldState)
634 throws SQLException {
635
636 return _jdbcDelegate.updateTriggerGroupStateFromOtherState(
637 conn, groupName, newState, oldState);
638 }
639
640 public int updateTriggerGroupStateFromOtherStates(
641 Connection conn, String groupName, String newState,
642 String oldState1, String oldState2, String oldState3)
643 throws SQLException {
644
645 return _jdbcDelegate.updateTriggerGroupStateFromOtherStates(
646 conn, groupName, newState, oldState1, oldState2, oldState3);
647 }
648
649 public int updateTriggerState(
650 Connection conn, String triggerName, String groupName, String state)
651 throws SQLException {
652
653 return _jdbcDelegate.updateTriggerState(
654 conn, triggerName, groupName, state);
655 }
656
657 public int updateTriggerStateFromOtherState(
658 Connection conn, String triggerName, String groupName,
659 String newState, String oldState)
660 throws SQLException {
661
662 return _jdbcDelegate.updateTriggerStateFromOtherState(
663 conn, triggerName, groupName, newState, oldState);
664 }
665
666 public int updateTriggerStateFromOtherStates(
667 Connection conn, String triggerName, String groupName,
668 String newState, String oldState1, String oldState2,
669 String oldState3)
670 throws SQLException {
671
672 return _jdbcDelegate.updateTriggerStateFromOtherStates(
673 conn, triggerName, groupName, newState, oldState1, oldState2,
674 oldState3);
675 }
676
677 public int updateTriggerStateFromOtherStatesBeforeTime(
678 Connection conn, String newState, String oldState1,
679 String oldState2, long time)
680 throws SQLException {
681
682 return _jdbcDelegate.updateTriggerStateFromOtherStatesBeforeTime(
683 conn, newState, oldState1, oldState2, time);
684 }
685
686 public int updateTriggerStatesForJob(
687 Connection conn, String jobName, String groupName, String state)
688 throws SQLException {
689
690 return _jdbcDelegate.updateTriggerStatesForJob(
691 conn, jobName, groupName, state);
692 }
693
694 public int updateTriggerStatesForJobFromOtherState(
695 Connection conn, String jobName, String groupName, String state,
696 String oldState)
697 throws SQLException {
698
699 return _jdbcDelegate.updateTriggerStatesForJobFromOtherState(
700 conn, jobName, groupName, state, oldState);
701 }
702
703 public int updateTriggerStatesFromOtherStates(
704 Connection conn, String newState, String oldState1,
705 String oldState2)
706 throws SQLException {
707
708 return _jdbcDelegate.updateTriggerStatesFromOtherStates(
709 conn, newState, oldState1, oldState2);
710 }
711
712 protected Class<?> getDriverDelegateClass() {
713 Class<?> driverDelegateClass = StdJDBCDelegate.class;
714
715 DB db = DBFactoryUtil.getDB();
716
717 if (db instanceof DB2DB) {
718 driverDelegateClass = DB2v7Delegate.class;
719 }
720 else if (db instanceof DerbyDB) {
721 driverDelegateClass = CloudscapeDelegate.class;
722 }
723 else if (db instanceof HypersonicDB) {
724 driverDelegateClass = HSQLDBDelegate.class;
725 }
726 else if (db instanceof PostgreSQLDB) {
727 driverDelegateClass = PostgreSQLDelegate.class;
728 }
729 else if (db instanceof SQLServerDB) {
730 driverDelegateClass = MSSQLDelegate.class;
731 }
732 else if (db instanceof SybaseDB) {
733 driverDelegateClass = MSSQLDelegate.class;
734 }
735
736 return driverDelegateClass;
737 }
738
739 private com.liferay.portal.kernel.log.Log _log =
740 LogFactoryUtil.getLog(DynamicDriverDelegate.class);
741
742 private StdJDBCDelegate _jdbcDelegate;
743
744 }