org.apache.tools.ant.taskdefs
Class SQLExec

java.lang.Object
  |
  +--org.apache.tools.ant.ProjectComponent
        |
        +--org.apache.tools.ant.Task
              |
              +--org.apache.tools.ant.taskdefs.SQLExec

public class SQLExec
extends Task

Reads in a text file containing SQL statements seperated with semicolons and executes it in a given db. Comments may be created with REM -- or //.

Author:
Jeff Martin, Michael McCallum, Tim Stephenson

Inner Class Summary
static class SQLExec.DelimiterType
           
static class SQLExec.OnError
          Enumerated attribute with the values "continue", "stop" and "abort" for the onerror attribute.
 class SQLExec.Transaction
          Contains the definition of a new transaction element.
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
SQLExec()
           
 
Method Summary
 void addFileset(FileSet set)
          Adds a set of files (nested fileset attribute).
 void addText(java.lang.String sql)
          Set the sql command to execute
 Path createClasspath()
          Create the classpath for loading the driver.
 SQLExec.Transaction createTransaction()
          Set the sql command to execute
protected  void execSQL(java.lang.String sql, java.io.PrintStream out)
          Exec the sql statement.
 void execute()
          Load the sql file and then execute it
protected  boolean isValidRdbms(java.sql.Connection conn)
          Verify if connected to the correct RDBMS
protected  void printResults(java.io.PrintStream out)
          print any results in the statement.
protected  void runStatements(java.io.Reader reader, java.io.PrintStream out)
           
 void setAutocommit(boolean autocommit)
          Set the autocommit flag for the DB connection.
 void setClasspath(Path classpath)
          Set the classpath for loading the driver.
 void setClasspathRef(Reference r)
          Set the classpath for loading the driver using the classpath reference.
 void setDelimiter(java.lang.String delimiter)
          Set the statement delimiter.
 void setDelimiterType(SQLExec.DelimiterType delimiterType)
          Set the Delimiter type for this sql task.
 void setDriver(java.lang.String driver)
          Set the JDBC driver to be used.
 void setOnerror(SQLExec.OnError action)
          Set the action to perform onerror
 void setOutput(java.io.File output)
          Set the output file.
 void setPassword(java.lang.String password)
          Set the password for the DB connection.
 void setPrint(boolean print)
          Set the print flag.
 void setRdbms(java.lang.String vendor)
          Set the rdbms required
 void setShowheaders(boolean showheaders)
          Set the showheaders flag.
 void setSrc(java.io.File srcFile)
          Set the name of the sql file to be run.
 void setUrl(java.lang.String url)
          Set the DB connection url.
 void setUserid(java.lang.String userId)
          Set the user name for the DB connection.
 void setVersion(java.lang.String version)
          Set the version required
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, init, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLExec

public SQLExec()
Method Detail

setClasspath

public void setClasspath(Path classpath)
Set the classpath for loading the driver.

createClasspath

public Path createClasspath()
Create the classpath for loading the driver.

setClasspathRef

public void setClasspathRef(Reference r)
Set the classpath for loading the driver using the classpath reference.

setSrc

public void setSrc(java.io.File srcFile)
Set the name of the sql file to be run.

addText

public void addText(java.lang.String sql)
Set the sql command to execute

addFileset

public void addFileset(FileSet set)
Adds a set of files (nested fileset attribute).

createTransaction

public SQLExec.Transaction createTransaction()
Set the sql command to execute

setDriver

public void setDriver(java.lang.String driver)
Set the JDBC driver to be used.

setUrl

public void setUrl(java.lang.String url)
Set the DB connection url.

setUserid

public void setUserid(java.lang.String userId)
Set the user name for the DB connection.

setPassword

public void setPassword(java.lang.String password)
Set the password for the DB connection.

setAutocommit

public void setAutocommit(boolean autocommit)
Set the autocommit flag for the DB connection.

setDelimiter

public void setDelimiter(java.lang.String delimiter)
Set the statement delimiter.

For example, set this to "go" and delimitertype to "ROW" for Sybase ASE or MS SQL Server.


setDelimiterType

public void setDelimiterType(SQLExec.DelimiterType delimiterType)
Set the Delimiter type for this sql task. The delimiter type takes two values - normal and row. Normal means that any occurence of the delimiter terminate the SQL command whereas with row, only a line containing just the delimiter is recognized as the end of the command.

setPrint

public void setPrint(boolean print)
Set the print flag.

setShowheaders

public void setShowheaders(boolean showheaders)
Set the showheaders flag.

setOutput

public void setOutput(java.io.File output)
Set the output file.

setRdbms

public void setRdbms(java.lang.String vendor)
Set the rdbms required

setVersion

public void setVersion(java.lang.String version)
Set the version required

setOnerror

public void setOnerror(SQLExec.OnError action)
Set the action to perform onerror

execute

public void execute()
             throws BuildException
Load the sql file and then execute it
Overrides:
execute in class Task
Following copied from class: org.apache.tools.ant.Task
Throws:
BuildException - if someting goes wrong with the build

runStatements

protected void runStatements(java.io.Reader reader,
                             java.io.PrintStream out)
                      throws java.sql.SQLException,
                             java.io.IOException

isValidRdbms

protected boolean isValidRdbms(java.sql.Connection conn)
Verify if connected to the correct RDBMS

execSQL

protected void execSQL(java.lang.String sql,
                       java.io.PrintStream out)
                throws java.sql.SQLException
Exec the sql statement.

printResults

protected void printResults(java.io.PrintStream out)
                     throws java.sql.SQLException
print any results in the statement.


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.