1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.sourceforge.addam.ddlrun.runners;
23
24
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.Map;
30
31 import net.sourceforge.addam.ddlrun.filters.Filter;
32 import net.sourceforge.addam.ddlrun.utils.DRVParser;
33 import net.sourceforge.addam.ddlrun.utils.ResourceReaderFactory;
34 import net.sourceforge.addam.ddlrun.utils.RunLogger;
35
36 /**
37 * Determines which groups to run, and executes them.
38 *
39 * @author TIM3
40 * @since Mar 5, 2005
41 */
42 public class DeploymentRunner implements Runner {
43
44 /**
45 * Constructs a DeploymentRunner.
46 *
47 * @param readerFactory used to locate and read scripts
48 * @param groupFilter used to determine which groups to run
49 * @param scriptFilter passed to ScriptGroupRunner to determine which scripts to run
50 * @param scriptRunnerMap used to determine which JDBCScriptRunner to use for each script
51 * @param version
52 */
53
54 public DeploymentRunner(ResourceReaderFactory readerFactory,
55 Filter groupFilter,
56 Filter scriptFilter,
57 Map scriptRunnerMap,
58 String version) {
59 this.readerFactory = readerFactory;
60 this.scriptFilter = scriptFilter;
61 this.groupFilter = groupFilter;
62 this.scriptRunnerMap = scriptRunnerMap;
63 this.runLoggers = new ArrayList();
64 }
65
66 /**
67 * all registered loggers will be notified of successful and unsuccessful scripts
68 *
69 * @param logger
70 */
71 public void addRunLogger(RunLogger logger) {
72 this.runLoggers.add(logger);
73 }
74
75 /**
76 * @param resource the resource that contains the list of scripts to run
77 * @throws IOException
78 */
79 public void run(String resource) throws Exception {
80 DRVParser drvParser = new DRVParser(resource, readerFactory);
81 List allGroups = drvParser.parseFilesToExecute();
82 for (Iterator it = groupFilter.getIterator(allGroups); it.hasNext();) {
83 String group = it.next().toString();
84 ScriptGroupRunner groupRunner = new ScriptGroupRunner(readerFactory, scriptFilter, scriptRunnerMap);
85 for (Iterator it2 = this.runLoggers.iterator(); it2.hasNext();) {
86 groupRunner.addRunLogger((RunLogger) it2.next());
87 }
88 groupRunner.run(group);
89 }
90 }
91
92 private final ResourceReaderFactory readerFactory;
93 private final Filter groupFilter;
94 private final Filter scriptFilter;
95 private final Map scriptRunnerMap;
96 private final ArrayList runLoggers;
97 }