View Javadoc

1   //
2   // Copyright (c) 2004, International Decision Systems
3   // all rights reserved
4   /*
5    * Copyright (c) 2004 International Decision Systems, Inc.  All Rights Reserved.
6    *
7    * By using this Software, You acknowledge that the Software is a valuable asset
8    * and trade secret of either International Decision Systems, Inc. ("IDSI") or a
9    * third party supplier of IDSI and constitutes confidential and proprietary
10   * information.
11   *
12   * NEITHER IDSI NOR ANY AGENT OR PERSON ACTING FOR OR WITH IDSI HAS MADE OR DOES
13   * MAKE ANY STATEMENTS, AFFIRMATIONS, REPRESENTATIONS OR WARRANTIES WHATSOEVER
14   * TO YOU, WHETHER EXPRESS OR IMPLIED, AS TO THE SOFTWARE, THE QUALITY OR
15   * CONDITION OF THE SOFTWARE, OR THE OPERATING CHARACTERISTICS OR RELIABILITY OF
16   * THE SOFTWARE, OR ITS SUITABILITY FOR ANY GENERAL OR PARTICULAR PURPOSE, OR AS
17   * TO ANY OTHER MATTER WHATSOEVER; ANY AND ALL OTHER WARRANTIES INCLUDING
18   * WITHOUT LIMITATION ANY WARRANTIES IMPLIED BY LAW, SUCH AS THE IMPLIED
19   * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND TITLE,
20   * USE AND NON-INFRINGEMENT; ARE HEREBY EXPRESSLY DISCLAIMED AND EXCLUDED.
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  }