01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: DatabaseScheduler.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.scheduler.schedulermanagers;
09:
10: import com.uwyn.rife.database.Datasource;
11: import com.uwyn.rife.database.DbQueryManager;
12: import com.uwyn.rife.scheduler.Scheduler;
13: import com.uwyn.rife.scheduler.SchedulerFactory;
14: import com.uwyn.rife.scheduler.exceptions.SchedulerException;
15: import com.uwyn.rife.scheduler.exceptions.SchedulerManagerException;
16: import com.uwyn.rife.scheduler.schedulermanagers.exceptions.InstallSchedulerErrorException;
17: import com.uwyn.rife.scheduler.schedulermanagers.exceptions.RemoveSchedulerErrorException;
18: import com.uwyn.rife.scheduler.taskmanagers.DatabaseTasks;
19: import com.uwyn.rife.scheduler.taskmanagers.DatabaseTasksFactory;
20: import com.uwyn.rife.scheduler.taskoptionmanagers.DatabaseTaskoptions;
21: import com.uwyn.rife.scheduler.taskoptionmanagers.DatabaseTaskoptionsFactory;
22:
23: public abstract class DatabaseScheduler extends DbQueryManager
24: implements SchedulerFactory {
25: protected DatabaseScheduler(Datasource datasource) {
26: super (datasource);
27: }
28:
29: public Scheduler getScheduler() {
30: return new Scheduler(DatabaseTasksFactory
31: .getInstance(getDatasource()),
32: DatabaseTaskoptionsFactory.getInstance(getDatasource()));
33: }
34:
35: public abstract boolean install() throws SchedulerManagerException;
36:
37: public abstract boolean remove() throws SchedulerManagerException;
38:
39: protected boolean _install() throws SchedulerManagerException {
40: try {
41: DatabaseTasks tasks_manager = DatabaseTasksFactory
42: .getInstance(getDatasource());
43: DatabaseTaskoptions taskoptions_manager = DatabaseTaskoptionsFactory
44: .getInstance(getDatasource());
45:
46: tasks_manager.install();
47: taskoptions_manager.install();
48: } catch (SchedulerException e) {
49: throw new InstallSchedulerErrorException(e);
50: }
51:
52: return true;
53: }
54:
55: protected boolean _remove() throws SchedulerManagerException {
56: try {
57: DatabaseTasks tasks_manager = DatabaseTasksFactory
58: .getInstance(getDatasource());
59: DatabaseTaskoptions taskoptions_manager = DatabaseTaskoptionsFactory
60: .getInstance(getDatasource());
61:
62: taskoptions_manager.remove();
63: tasks_manager.remove();
64: } catch (SchedulerException e) {
65: throw new RemoveSchedulerErrorException(e);
66: }
67:
68: return true;
69: }
70: }
|