| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 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 | |
|
| 37 | |
|
| 38 | |
public class InstallTask extends JDBCTask implements RunLogger { |
| 39 | |
|
| 40 | 0 | public InstallTask() { |
| 41 | 0 | } |
| 42 | |
|
| 43 | |
public void setScript(File script) { |
| 44 | 0 | this.script = script; |
| 45 | 0 | } |
| 46 | |
|
| 47 | |
public void execute() throws BuildException { |
| 48 | 0 | Connection connection = getConnection(); |
| 49 | 0 | ResourceReaderFactory factory = new FileSystemReaderFactory(script.getParentFile()); |
| 50 | 0 | ScriptGrammar grammar = new ScriptGrammarManager().getGrammar(connection); |
| 51 | 0 | if (grammar == null) { |
| 52 | 0 | throw new BuildException("" + connection + " does not use a supported database driver"); |
| 53 | |
} |
| 54 | |
try { |
| 55 | 0 | DeploymentRunner runner = DeploymentRunnerFactory.getInstance().getInstallRunner(factory, |
| 56 | 0 | connection, |
| 57 | 0 | grammar); |
| 58 | 0 | runner.addRunLogger(this); |
| 59 | 0 | System.out.println("running script " + script.getName()); |
| 60 | 0 | runner.run(script.getName()); |
| 61 | 0 | } catch (Exception e) { |
| 62 | 0 | throw new BuildException(e); |
| 63 | 0 | } |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
public void logRunScript(String script, long time) throws Exception { |
| 67 | 0 | this.log("executed " + script + " (" + time + "ms)"); |
| 68 | 0 | } |
| 69 | |
|
| 70 | |
public void logRunComplete(String group, long time) throws Exception { |
| 71 | 0 | this.log("completed execution of available scripts in " + group + " (" + time + "ms)"); |
| 72 | 0 | } |
| 73 | |
|
| 74 | |
public void logRunFailure(String group, String script, Exception e) throws Exception { |
| 75 | 0 | this.log(group + "/" + script + " failed!"); |
| 76 | 0 | } |
| 77 | |
|
| 78 | 0 | private File script = null; |
| 79 | |
} |