View Javadoc

1   /*
2    * Copyright (c) 2004 International Decision Systems, Inc.  All Rights Reserved.
3    *
4    * By using this Software, You acknowledge that the Software is a valuable asset
5    * and trade secret of either International Decision Systems, Inc. ("IDSI") or a
6    * third party supplier of IDSI and constitutes confidential and proprietary
7    * information.
8    *
9    * NEITHER IDSI NOR ANY AGENT OR PERSON ACTING FOR OR WITH IDSI HAS MADE OR DOES
10   * MAKE ANY STATEMENTS, AFFIRMATIONS, REPRESENTATIONS OR WARRANTIES WHATSOEVER
11   * TO YOU, WHETHER EXPRESS OR IMPLIED, AS TO THE SOFTWARE, THE QUALITY OR
12   * CONDITION OF THE SOFTWARE, OR THE OPERATING CHARACTERISTICS OR RELIABILITY OF
13   * THE SOFTWARE, OR ITS SUITABILITY FOR ANY GENERAL OR PARTICULAR PURPOSE, OR AS
14   * TO ANY OTHER MATTER WHATSOEVER; ANY AND ALL OTHER WARRANTIES INCLUDING
15   * WITHOUT LIMITATION ANY WARRANTIES IMPLIED BY LAW, SUCH AS THE IMPLIED
16   * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND TITLE,
17   * USE AND NON-INFRINGEMENT; ARE HEREBY EXPRESSLY DISCLAIMED AND EXCLUDED.
18  */
19  package net.sourceforge.addam.ddlrun;
20  
21  import net.sourceforge.addam.ddlrun.grammars.ScriptGrammar;
22  import net.sourceforge.addam.ddlrun.grammars.ScriptGrammarManager;
23  import net.sourceforge.addam.ddlrun.runners.DeploymentRunner;
24  import net.sourceforge.addam.ddlrun.runners.DeploymentRunnerFactory;
25  import net.sourceforge.addam.ddlrun.utils.FileSystemReaderFactory;
26  import net.sourceforge.addam.ddlrun.utils.ResourceReaderFactory;
27  import net.sourceforge.addam.ddlrun.utils.RunLogger;
28  
29  import org.apache.tools.ant.BuildException;
30  import org.apache.tools.ant.taskdefs.JDBCTask;
31  
32  import java.io.File;
33  import java.sql.Connection;
34  
35  /**
36   * Implementation of the ant deployment task
37   */
38  public class InstallTask extends JDBCTask implements RunLogger {
39  
40      public InstallTask() {
41      }
42  
43      public void setScript(File script) {
44          this.script = script;
45      }
46  
47      public void execute() throws BuildException {
48          Connection connection = getConnection();
49          ResourceReaderFactory factory = new FileSystemReaderFactory(script.getParentFile());
50          ScriptGrammar grammar = new ScriptGrammarManager().getGrammar(connection);
51          if (grammar == null) {
52              throw new BuildException("" + connection + " does not use a supported database driver");
53          }
54          try {
55              DeploymentRunner runner = DeploymentRunnerFactory.getInstance().getInstallRunner(factory,
56                      connection,
57                      grammar);
58              runner.addRunLogger(this);
59              System.out.println("running script " + script.getName());
60              runner.run(script.getName());
61          } catch (Exception e) {
62              throw new BuildException(e);
63          }
64      }
65  
66      public void logRunScript(String script, long time) throws Exception {
67          this.log("executed " + script + " (" + time + "ms)");
68      }
69  
70      public void logRunComplete(String group, long time) throws Exception {
71          this.log("completed execution of available scripts in " + group + " (" + time + "ms)");
72      }
73  
74      public void logRunFailure(String group, String script, Exception e) throws Exception {
75          this.log(group + "/" + script + " failed!");
76      }
77  
78      private File script = null;
79  }