1 16 package org.apache.cocoon.components.cron; 17 18 import org.apache.avalon.framework.context.Context; 19 import org.apache.avalon.framework.logger.Logger; 20 import org.apache.avalon.framework.service.ServiceManager; 21 22 import org.quartz.Calendar; 23 import org.quartz.CronTrigger; 24 import org.quartz.JobDataMap; 25 import org.quartz.JobDetail; 26 import org.quartz.SimpleTrigger; 27 import org.quartz.Trigger; 28 import org.quartz.impl.jdbcjobstore.DriverDelegate; 29 import org.quartz.spi.ClassLoadHelper; 30 import org.quartz.utils.Key; 31 import org.quartz.utils.TriggerStatus; 32 33 import java.io.IOException ; 34 import java.sql.Connection ; 35 import java.sql.SQLException ; 36 import java.util.List ; 37 import java.util.Set ; 38 39 55 public class QuartzDriverDelegate implements DriverDelegate { 56 private Logger logger; 57 private ServiceManager manager; 58 private Context context; 59 private DriverDelegate delegate; 60 61 public QuartzDriverDelegate(Logger logger, ServiceManager manager, Context context, DriverDelegate delegate) { 62 this.logger = logger; 63 this.manager = manager; 64 this.context = context; 65 this.delegate = delegate; 66 } 67 68 public int insertJobDetail(Connection conn, JobDetail job) 69 throws IOException , SQLException { 70 removeTransientData(job); 71 return delegate.insertJobDetail(conn, job); 72 } 73 74 public int updateJobDetail(Connection conn, JobDetail job) 75 throws IOException , SQLException { 76 removeTransientData(job); 77 return delegate.updateJobDetail(conn, job); 78 } 79 80 public int updateJobData(Connection conn, JobDetail job) 81 throws IOException , SQLException { 82 removeTransientData(job); 83 return delegate.updateJobData(conn, job); 84 } 85 86 private void removeTransientData(JobDetail job) { 87 JobDataMap map = job.getJobDataMap(); 88 if (map != null) { 89 this.logger.debug("QuartzDriverDelegate: Removing transient data"); 90 map.remove(QuartzJobScheduler.DATA_MAP_LOGGER); 91 map.remove(QuartzJobScheduler.DATA_MAP_CONTEXT); 92 map.remove(QuartzJobScheduler.DATA_MAP_MANAGER); 93 } 94 } 95 96 97 public JobDetail selectJobDetail(Connection conn, String jobName, 98 String groupName, ClassLoadHelper loadHelper) 99 throws ClassNotFoundException , IOException , SQLException { 100 JobDetail job = delegate.selectJobDetail(conn, jobName, groupName, loadHelper); 101 if (job != null) { 102 JobDataMap map = job.getJobDataMap(); 103 if (map != null) { 104 this.logger.debug("QuartzDriverDelegate: Adding transient data"); 105 map.put(QuartzJobScheduler.DATA_MAP_LOGGER, this.logger); 106 map.put(QuartzJobScheduler.DATA_MAP_CONTEXT, this.context); 107 map.put(QuartzJobScheduler.DATA_MAP_MANAGER, this.manager); 108 } 109 } 110 return job; 111 } 112 113 114 118 public int updateTriggerStatesFromOtherStates(Connection conn, 119 String newState, String oldState1, String oldState2) 120 throws SQLException { 121 return delegate.updateTriggerStatesFromOtherStates(conn, newState, oldState1, oldState2); 122 } 123 124 public Key[] selectMisfiredTriggers(Connection conn, long ts) 125 throws SQLException { 126 return delegate.selectMisfiredTriggers(conn, ts); 127 } 128 129 public Key[] selectMisfiredTriggersInState(Connection conn, String state, 130 long ts) throws SQLException { 131 return delegate.selectMisfiredTriggersInState(conn, state, ts); 132 } 133 134 public Key[] selectMisfiredTriggersInGroupInState(Connection conn, 135 String groupName, String state, long ts) throws SQLException { 136 return delegate.selectMisfiredTriggersInGroupInState(conn, groupName, state, ts); 137 } 138 139 public Trigger[] selectTriggersForRecoveringJobs(Connection conn) 140 throws SQLException , IOException , ClassNotFoundException { 141 return delegate.selectTriggersForRecoveringJobs(conn); 142 } 143 144 public int deleteFiredTriggers(Connection conn) throws SQLException { 145 return delegate.deleteFiredTriggers(conn); 146 } 147 148 public int deleteFiredTriggers(Connection conn, String instanceId) 149 throws SQLException { 150 return delegate.deleteFiredTriggers(conn, instanceId); 151 } 152 153 public int deleteVolatileFiredTriggers(Connection conn) throws SQLException { 154 return delegate.deleteVolatileFiredTriggers(conn); 155 } 156 157 public Key[] selectVolatileTriggers(Connection conn) throws SQLException { 158 return delegate.selectVolatileTriggers(conn); 159 } 160 161 public Key[] selectVolatileJobs(Connection conn) throws SQLException { 162 return delegate.selectVolatileJobs(conn); 163 } 164 165 public Key[] selectTriggerNamesForJob(Connection conn, String jobName, 166 String groupName) throws SQLException { 167 return delegate.selectTriggerNamesForJob(conn, jobName, groupName); 168 } 169 170 public int deleteJobListeners(Connection conn, String jobName, 171 String groupName) throws SQLException { 172 return delegate.deleteJobListeners(conn, jobName, groupName); 173 } 174 175 public int deleteJobDetail(Connection conn, String jobName, String groupName) 176 throws SQLException { 177 return delegate.deleteJobDetail(conn, jobName, groupName); 178 } 179 180 public boolean isJobStateful(Connection conn, String jobName, 181 String groupName) throws SQLException { 182 return delegate.isJobStateful(conn, jobName, groupName); 183 } 184 185 public boolean jobExists(Connection conn, String jobName, String groupName) 186 throws SQLException { 187 return delegate.jobExists(conn, jobName, groupName); 188 } 189 190 public int insertJobListener(Connection conn, JobDetail job, String listener) 191 throws SQLException { 192 return delegate.insertJobListener(conn, job, listener); 193 } 194 195 public String [] selectJobListeners(Connection conn, String jobName, 196 String groupName) throws SQLException { 197 return delegate.selectJobListeners(conn, jobName, groupName); 198 } 199 200 public int selectNumJobs(Connection conn) throws SQLException { 201 return delegate.selectNumJobs(conn); 202 } 203 204 public String [] selectJobGroups(Connection conn) throws SQLException { 205 return delegate.selectJobGroups(conn); 206 } 207 208 public String [] selectJobsInGroup(Connection conn, String groupName) 209 throws SQLException { 210 return delegate.selectJobsInGroup(conn, groupName); 211 } 212 213 public int insertTrigger(Connection conn, Trigger trigger, String state, 214 JobDetail jobDetail) throws SQLException , IOException { 215 return delegate.insertTrigger(conn, trigger, state, jobDetail); 216 } 217 218 public int insertSimpleTrigger(Connection conn, SimpleTrigger trigger) 219 throws SQLException { 220 return delegate.insertSimpleTrigger(conn, trigger); 221 } 222 223 public int insertBlobTrigger(Connection conn, Trigger trigger) 224 throws SQLException , IOException { 225 return delegate.insertBlobTrigger(conn, trigger); 226 } 227 228 public int insertCronTrigger(Connection conn, CronTrigger trigger) 229 throws SQLException { 230 return delegate.insertCronTrigger(conn, trigger); 231 } 232 233 public int updateTrigger(Connection conn, Trigger trigger, String state, 234 JobDetail jobDetail) throws SQLException , IOException { 235 return delegate.updateTrigger(conn, trigger, state, jobDetail); 236 } 237 238 public int updateSimpleTrigger(Connection conn, SimpleTrigger trigger) 239 throws SQLException { 240 return delegate.updateSimpleTrigger(conn, trigger); 241 } 242 243 public int updateCronTrigger(Connection conn, CronTrigger trigger) 244 throws SQLException { 245 return delegate.updateCronTrigger(conn, trigger); 246 } 247 248 public int updateBlobTrigger(Connection conn, Trigger trigger) 249 throws SQLException , IOException { 250 return delegate.updateBlobTrigger(conn, trigger); 251 } 252 253 public boolean triggerExists(Connection conn, String triggerName, 254 String groupName) throws SQLException { 255 return delegate.triggerExists(conn, triggerName, groupName); 256 } 257 258 public int updateTriggerState(Connection conn, String triggerName, 259 String groupName, String state) throws SQLException { 260 return delegate.updateTriggerState(conn, triggerName, groupName, state); 261 } 262 263 public int updateTriggerStateFromOtherState(Connection conn, 264 String triggerName, String groupName, String newState, 265 String oldState) throws SQLException { 266 return delegate.updateTriggerStateFromOtherState(conn, triggerName, groupName, newState, oldState); 267 } 268 269 public int updateTriggerStateFromOtherStates(Connection conn, 270 String triggerName, String groupName, String newState, 271 String oldState1, String oldState2, String oldState3) 272 throws SQLException { 273 return delegate.updateTriggerStateFromOtherStates(conn, triggerName, groupName, newState, oldState1, oldState2, oldState3); 274 } 275 276 public int updateTriggerStateFromOtherStatesBeforeTime(Connection conn, 277 String newState, String oldState1, String oldState2, long time) 278 throws SQLException { 279 return delegate.updateTriggerStateFromOtherStatesBeforeTime(conn, newState, oldState1, oldState2, time); 280 } 281 282 public int updateTriggerGroupStateFromOtherStates(Connection conn, 283 String groupName, String newState, String oldState1, 284 String oldState2, String oldState3) throws SQLException { 285 return delegate.updateTriggerGroupStateFromOtherStates(conn, groupName, newState, oldState1, oldState2, oldState3); 286 } 287 288 public int updateTriggerGroupStateFromOtherState(Connection conn, 289 String groupName, String newState, String oldState) 290 throws SQLException { 291 return delegate.updateTriggerGroupStateFromOtherState(conn, groupName, newState, oldState); 292 } 293 294 public int updateTriggerStatesForJob(Connection conn, String jobName, 295 String groupName, String state) throws SQLException { 296 return delegate.updateTriggerStatesForJob(conn, jobName, groupName, state); 297 } 298 299 public int updateTriggerStatesForJobFromOtherState(Connection conn, 300 String jobName, String groupName, String state, String oldState) 301 throws SQLException { 302 return delegate.updateTriggerStatesForJobFromOtherState(conn, jobName, groupName, state, oldState); 303 } 304 305 public int deleteTriggerListeners(Connection conn, String triggerName, 306 String groupName) throws SQLException { 307 return delegate.deleteTriggerListeners(conn, triggerName, groupName); 308 } 309 310 public int insertTriggerListener(Connection conn, Trigger trigger, 311 String listener) throws SQLException { 312 return delegate.insertTriggerListener(conn, trigger, listener); 313 } 314 315 public String [] selectTriggerListeners(Connection conn, String triggerName, 316 String groupName) throws SQLException { 317 return delegate.selectTriggerListeners(conn, triggerName, groupName); 318 } 319 320 public int deleteSimpleTrigger(Connection conn, String triggerName, 321 String groupName) throws SQLException { 322 return delegate.deleteSimpleTrigger(conn, triggerName, groupName); 323 } 324 325 public int deleteBlobTrigger(Connection conn, String triggerName, 326 String groupName) throws SQLException { 327 return delegate.deleteBlobTrigger(conn, triggerName, groupName); 328 } 329 330 public int deleteCronTrigger(Connection conn, String triggerName, 331 String groupName) throws SQLException { 332 return delegate.deleteCronTrigger(conn, triggerName, groupName); 333 } 334 335 public int deleteTrigger(Connection conn, String triggerName, 336 String groupName) throws SQLException { 337 return delegate.deleteTrigger(conn, triggerName, groupName); 338 } 339 340 public int selectNumTriggersForJob(Connection conn, String jobName, 341 String groupName) throws SQLException { 342 return delegate.selectNumTriggersForJob(conn, jobName, groupName); 343 } 344 345 public JobDetail selectJobForTrigger(Connection conn, String triggerName, 346 String groupName, ClassLoadHelper loadHelper) throws SQLException , ClassNotFoundException { 347 return delegate.selectJobForTrigger(conn, triggerName, groupName, loadHelper); 348 } 349 350 public List selectStatefulJobsOfTriggerGroup(Connection conn, 351 String groupName) throws SQLException { 352 return delegate.selectStatefulJobsOfTriggerGroup(conn, groupName); 353 } 354 355 public Trigger[] selectTriggersForJob(Connection conn, String jobName, 356 String groupName) throws SQLException , ClassNotFoundException , 357 IOException { 358 return delegate.selectTriggersForJob(conn, jobName, groupName); 359 } 360 361 public Trigger[] selectTriggersForCalendar(Connection conn, String calName) 362 throws SQLException , ClassNotFoundException , IOException { 363 return delegate.selectTriggersForCalendar(conn, calName); 364 } 365 366 public Trigger selectTrigger(Connection conn, String triggerName, 367 String groupName) throws SQLException , ClassNotFoundException , 368 IOException { 369 return delegate.selectTrigger(conn, triggerName, groupName); 370 } 371 372 public String selectTriggerState(Connection conn, String triggerName, 373 String groupName) throws SQLException { 374 return delegate.selectTriggerState(conn, triggerName, groupName); 375 } 376 377 public TriggerStatus selectTriggerStatus(Connection conn, 378 String triggerName, String groupName) throws SQLException { 379 return delegate.selectTriggerStatus(conn, triggerName, groupName); 380 } 381 382 public int selectNumTriggers(Connection conn) throws SQLException { 383 return delegate.selectNumTriggers(conn); 384 } 385 386 public String [] selectTriggerGroups(Connection conn) throws SQLException { 387 return delegate.selectTriggerGroups(conn); 388 } 389 390 public String [] selectTriggersInGroup(Connection conn, String groupName) 391 throws SQLException { 392 return delegate.selectTriggersInGroup(conn, groupName); 393 } 394 395 public Key[] selectTriggersInState(Connection conn, String state) 396 throws SQLException { 397 return delegate.selectTriggersInState(conn, state); 398 } 399 400 public int insertPausedTriggerGroup(Connection conn, String groupName) 401 throws SQLException { 402 return delegate.insertPausedTriggerGroup(conn, groupName); 403 } 404 405 public int deletePausedTriggerGroup(Connection conn, String groupName) 406 throws SQLException { 407 return delegate.deletePausedTriggerGroup(conn, groupName); 408 } 409 410 public int deleteAllPausedTriggerGroups(Connection conn) 411 throws SQLException { 412 return delegate.deleteAllPausedTriggerGroups(conn); 413 } 414 415 public boolean isTriggerGroupPaused(Connection conn, String groupName) 416 throws SQLException { 417 return delegate.isTriggerGroupPaused(conn, groupName); 418 } 419 420 public Set selectPausedTriggerGroups(Connection conn) 421 throws SQLException { 422 return delegate.selectPausedTriggerGroups(conn); 423 } 424 425 public boolean isExistingTriggerGroup(Connection conn, String groupName) 426 throws SQLException { 427 return delegate.isExistingTriggerGroup(conn, groupName); 428 } 429 430 public int insertCalendar(Connection conn, String calendarName, 431 Calendar calendar) throws IOException , SQLException { 432 return delegate.insertCalendar(conn, calendarName, calendar); 433 } 434 435 public int updateCalendar(Connection conn, String calendarName, 436 Calendar calendar) throws IOException , SQLException { 437 return delegate.updateCalendar(conn, calendarName, calendar); 438 } 439 440 public boolean calendarExists(Connection conn, String calendarName) 441 throws SQLException { 442 return delegate.calendarExists(conn, calendarName); 443 } 444 445 public Calendar selectCalendar(Connection conn, String calendarName) 446 throws ClassNotFoundException , IOException , SQLException { 447 return delegate.selectCalendar(conn, calendarName); 448 } 449 450 public boolean calendarIsReferenced(Connection conn, String calendarName) 451 throws SQLException { 452 return delegate.calendarIsReferenced(conn, calendarName); 453 } 454 455 public int deleteCalendar(Connection conn, String calendarName) 456 throws SQLException { 457 return delegate.deleteCalendar(conn, calendarName); 458 } 459 460 public int selectNumCalendars(Connection conn) throws SQLException { 461 return delegate.selectNumCalendars(conn); 462 } 463 464 public String [] selectCalendars(Connection conn) throws SQLException { 465 return delegate.selectCalendars(conn); 466 } 467 468 public long selectNextFireTime(Connection conn) throws SQLException { 469 return delegate.selectNextFireTime(conn); 470 } 471 472 public Key selectTriggerForFireTime(Connection conn, long fireTime) 473 throws SQLException { 474 return delegate.selectTriggerForFireTime(conn, fireTime); 475 } 476 477 public int insertFiredTrigger(Connection conn, Trigger trigger, 478 String state, JobDetail jobDetail) throws SQLException { 479 return delegate.insertFiredTrigger(conn, trigger, state, jobDetail); 480 } 481 482 public List selectFiredTriggerRecords(Connection conn, String triggerName, 483 String groupName) throws SQLException { 484 return delegate.selectFiredTriggerRecords(conn, triggerName, groupName); 485 } 486 487 public List selectFiredTriggerRecordsByJob(Connection conn, String jobName, 488 String groupName) throws SQLException { 489 return delegate.selectFiredTriggerRecordsByJob(conn, jobName, groupName); 490 } 491 492 public List selectInstancesFiredTriggerRecords(Connection conn, 493 String instanceName) throws SQLException { 494 return delegate.selectInstancesFiredTriggerRecords(conn, instanceName); 495 } 496 497 public int deleteFiredTrigger(Connection conn, String entryId) 498 throws SQLException { 499 return delegate.deleteFiredTrigger(conn, entryId); 500 } 501 502 public int selectJobExecutionCount(Connection conn, String jobName, 503 String jobGroup) throws SQLException { 504 return delegate.selectJobExecutionCount(conn, jobName, jobGroup); 505 } 506 507 public int insertSchedulerState(Connection conn, String instanceId, 508 long checkInTime, long interval, String recoverer) 509 throws SQLException { 510 return delegate.insertSchedulerState(conn, instanceId, checkInTime, interval, recoverer); 511 } 512 513 public int deleteSchedulerState(Connection conn, String instanceId) 514 throws SQLException { 515 return delegate.deleteSchedulerState(conn, instanceId); 516 } 517 518 public List selectSchedulerStateRecords(Connection conn, String instanceId) 519 throws SQLException { 520 return delegate.selectSchedulerStateRecords(conn, instanceId); 521 } 522 523 public JobDataMap selectTriggerJobDataMap(Connection conn, String triggerName, String groupName) throws SQLException , ClassNotFoundException , IOException { 524 return delegate.selectTriggerJobDataMap(conn, triggerName, groupName); 525 } 526 } 527 | Popular Tags |