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