Coverage Report - net.sourceforge.addam.ddlrun.UpgradeTask
 
Classes in this File Line Coverage Branch Coverage Complexity
UpgradeTask
0%
0/31
0%
0/1
1.571
 
 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.custom.IDSCompletedScriptRetriever;
 22  
 import net.sourceforge.addam.ddlrun.custom.IDSRunLogger;
 23  
 import net.sourceforge.addam.ddlrun.custom.IDSStartFolderRetriever;
 24  
 import net.sourceforge.addam.ddlrun.grammars.ScriptGrammar;
 25  
 import net.sourceforge.addam.ddlrun.grammars.ScriptGrammarManager;
 26  
 import net.sourceforge.addam.ddlrun.runners.DeploymentRunner;
 27  
 import net.sourceforge.addam.ddlrun.runners.DeploymentRunnerFactory;
 28  
 import net.sourceforge.addam.ddlrun.utils.FileSystemReaderFactory;
 29  
 import net.sourceforge.addam.ddlrun.utils.ResourceReaderFactory;
 30  
 import net.sourceforge.addam.ddlrun.utils.RunLogger;
 31  
 
 32  
 import org.apache.tools.ant.BuildException;
 33  
 import org.apache.tools.ant.taskdefs.JDBCTask;
 34  
 
 35  
 import java.io.File;
 36  
 import java.sql.Connection;
 37  
 
 38  
 /**
 39  
  * Implementation of the ant deployment task.
 40  
  * This is NOT generic - it assumes specific database structure for tracking the scripts already run.
 41  
  */
 42  
 public class UpgradeTask extends JDBCTask implements RunLogger {
 43  
 
 44  0
     public UpgradeTask() {
 45  0
     }
 46  
 
 47  
     public void setScript(File script) {
 48  0
         this.script = script;
 49  0
     }
 50  
 
 51  
     public void setVersion(String version) {
 52  0
         this.dbversion = version;
 53  0
     }
 54  
 
 55  
     public void execute() throws BuildException {
 56  0
         Connection connection = getConnection();
 57  0
         ResourceReaderFactory factory = new FileSystemReaderFactory(script.getParentFile());
 58  0
         ScriptGrammar grammar = new ScriptGrammarManager().getGrammar(connection);
 59  0
         if (grammar == null) {
 60  0
             throw new BuildException("" + connection + " does not use a supported database driver");
 61  
         }
 62  
         try {
 63  0
             DeploymentRunner runner = DeploymentRunnerFactory.getInstance().getUpgradeRunner(factory,
 64  0
                     connection,
 65  0
                     grammar,
 66  0
                     new IDSStartFolderRetriever(connection),
 67  0
                     new IDSCompletedScriptRetriever(connection));
 68  0
             runner.addRunLogger(new IDSRunLogger(connection, dbversion));
 69  0
             runner.addRunLogger(this);
 70  0
             runner.run(script.getName());
 71  0
         } catch (Exception e) {
 72  0
             throw new BuildException(e);
 73  0
         }
 74  0
     }
 75  
 
 76  
     public void logRunScript(String script, long time) throws Exception {
 77  0
         this.log("executed " + script + " (" + time + "ms)");
 78  0
     }
 79  
 
 80  
     public void logRunComplete(String group, long time) throws Exception {
 81  0
         this.log("completed execution of available scripts in " + group + " (" + time + "ms)");
 82  0
     }
 83  
 
 84  
     public void logRunFailure(String group, String script, Exception e) throws Exception {
 85  0
         this.log(group + "/" + script + " failed!");
 86  0
     }
 87  
 
 88  0
     private File script = null;
 89  0
     private String dbversion = null;
 90  
 }