org.codehaus.mojo.sql
Class SqlExecMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.codehaus.mojo.sql.SqlExecMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

public class SqlExecMojo
extends org.apache.maven.plugin.AbstractMojo

Executes SQL against a database.


Field Summary
static String ON_ERROR_ABORT
          Call setOnError(String) with this value to abort SQL command execution if an error is found.
static String ON_ERROR_ABORT_AFTER
          Call setOnError(String) with this value to continue SQL command execution until all commands have been attempted, then abort the build if an SQL error occurred in any of the commands.
static String ON_ERROR_CONTINUE
          Call setOnError(String) with this value to continue SQL command execution if an error is found.
protected  org.apache.maven.project.MavenProject project
          The Maven Project Object
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
SqlExecMojo()
           
 
Method Summary
 void addText(String sql)
          Set an inline SQL command to execute.
protected  void copy(org.springframework.core.io.Resource resource, File file)
           
 org.codehaus.mojo.sql.SqlExecMojo.Transaction createTransaction()
          Add a SQL transaction to execute
 void execute()
          Load the sql file and then execute it
 String getDriver()
           
protected  Driver getDriverInstance()
           
protected  Properties getDriverProperties()
          parse driverProperties into Properties set
 String getOnError()
           
 Order getOrderFile()
           
 String getPassword()
           
protected  Properties getProperties()
           
 String[] getResourceLocations()
           
protected  org.springframework.core.io.Resource[] getResources(String[] locations)
           
 String getSqlCommand()
           
 File[] getSrcFiles()
           
 int getSuccessfulStatements()
          Number of SQL statements executed so far that caused errors.
 int getTotalStatements()
          Number of SQL statements executed so far, including the ones that caused errors.
 Vector<org.codehaus.mojo.sql.SqlExecMojo.Transaction> getTransactions()
           
 String getUrl()
           
 String getUsername()
           
protected  boolean isBlankOrNone(String s)
           
 boolean isEnableBlockMode()
           
protected  boolean isEnd(String line)
           
 boolean isExecuteTrailingSQL()
           
protected  boolean isSkipPassword()
           
 void setAppend(boolean append)
          whether output should be appended to or overwrite an existing file.
 void setDelimiter(String delimiter)
          Set the delimiter that separates SQL statements.
 void setDelimiterType(String delimiterType)
          Set the delimiter type: "normal" or "row" (default "normal").
 void setDriver(String driver)
           
 void setDriverProperties(String driverProperties)
           
 void setEnableBlockMode(boolean enableBlockMode)
           
 void setEncoding(String encoding)
          Set the file encoding to use on the SQL files read in
 void setEscapeProcessing(boolean enable)
          Set escape processing for statements.
 void setExecuteTrailingSQL(boolean executeTrailingSQL)
           
 void setFileFilter(org.apache.maven.shared.filtering.MavenFileFilter filter)
           
 void setKeepFormat(boolean keepformat)
          whether or not format should be preserved.
 void setOnError(String action)
           
 void setOrderFile(String orderFile)
           
 void setOutputFile(File output)
          Set the output file;
 void setPassword(String password)
           
 void setPrintResultSet(boolean print)
          Print result sets from the statements; optional, default false
 void setPrintResutlSet(boolean print)
          Deprecated. typo, use setPrintResultSet()
 void setResourceLocations(String[] resourceLocations)
           
 void setShowheaders(boolean showheaders)
          Print headers for result sets from the statements; optional, default true.
 void setSqlCommand(String sqlCommand)
           
 void setSrcFiles(File[] files)
           
 void setTransactions(Vector<org.codehaus.mojo.sql.SqlExecMojo.Transaction> transactions)
           
 void setUrl(String url)
           
 void setUsername(String username)
           
protected  boolean skipMojo()
           Determine if the mojo execution should get skipped.
protected  void sortTransactions()
          Sort the transaction list.
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ON_ERROR_ABORT

public static final String ON_ERROR_ABORT
Call setOnError(String) with this value to abort SQL command execution if an error is found.

See Also:
Constant Field Values

ON_ERROR_ABORT_AFTER

public static final String ON_ERROR_ABORT_AFTER
Call setOnError(String) with this value to continue SQL command execution until all commands have been attempted, then abort the build if an SQL error occurred in any of the commands.

See Also:
Constant Field Values

ON_ERROR_CONTINUE

public static final String ON_ERROR_CONTINUE
Call setOnError(String) with this value to continue SQL command execution if an error is found.

See Also:
Constant Field Values

project

protected org.apache.maven.project.MavenProject project
The Maven Project Object

Constructor Detail

SqlExecMojo

public SqlExecMojo()
Method Detail

createTransaction

public org.codehaus.mojo.sql.SqlExecMojo.Transaction createTransaction()
Add a SQL transaction to execute

Returns:
a new SqlExecMojo.Transaction

addText

public void addText(String sql)
Set an inline SQL command to execute. NB: Properties are not expanded in this text.

Parameters:
sql - the sql statement to add

setEncoding

public void setEncoding(String encoding)
Set the file encoding to use on the SQL files read in

Parameters:
encoding - the encoding to use on the files

setDelimiter

public void setDelimiter(String delimiter)
Set the delimiter that separates SQL statements. Defaults to ";";

Parameters:
delimiter - the new delimiter

setDelimiterType

public void setDelimiterType(String delimiterType)
Set the delimiter type: "normal" or "row" (default "normal").

Parameters:
delimiterType - the new delimiterType

setPrintResutlSet

@Deprecated
public void setPrintResutlSet(boolean print)
Deprecated. typo, use setPrintResultSet()

Print result sets from the statements; optional, default false

Parameters:
print - true to print the resultset, otherwise false

setPrintResultSet

public void setPrintResultSet(boolean print)
Print result sets from the statements; optional, default false

Parameters:
print - true to print the resultset, otherwise false

setShowheaders

public void setShowheaders(boolean showheaders)
Print headers for result sets from the statements; optional, default true.

Parameters:
showheaders - true to show the headers, otherwise false

setOutputFile

public void setOutputFile(File output)
Set the output file;

Parameters:
output - the output file

setAppend

public void setAppend(boolean append)
whether output should be appended to or overwrite an existing file. Defaults to false.

Parameters:
append - true to append, otherwise false to overwrite

setKeepFormat

public void setKeepFormat(boolean keepformat)
whether or not format should be preserved. Defaults to false.

Parameters:
keepformat - The keepformat to set

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
Set escape processing for statements.

Parameters:
enable - true to escape, otherwiser false

skipMojo

protected boolean skipMojo()

Determine if the mojo execution should get skipped.

This is the case if:

Returns:
true if the mojo execution should be skipped.

execute

public void execute()
             throws org.apache.maven.plugin.MojoExecutionException
Load the sql file and then execute it

Throws:
org.apache.maven.plugin.MojoExecutionException

getResources

protected org.springframework.core.io.Resource[] getResources(String[] locations)
                                                       throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

copy

protected void copy(org.springframework.core.io.Resource resource,
                    File file)
             throws IOException
Throws:
IOException

sortTransactions

protected void sortTransactions()
Sort the transaction list.


isBlankOrNone

protected boolean isBlankOrNone(String s)

isSkipPassword

protected boolean isSkipPassword()

getProperties

protected Properties getProperties()
                            throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

getDriverInstance

protected Driver getDriverInstance()
                            throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

getDriverProperties

protected Properties getDriverProperties()
                                  throws org.apache.maven.plugin.MojoExecutionException
parse driverProperties into Properties set

Returns:
the driver properties
Throws:
org.apache.maven.plugin.MojoExecutionException

isEnd

protected boolean isEnd(String line)

getUsername

public String getUsername()

setUsername

public void setUsername(String username)

getPassword

public String getPassword()

setPassword

public void setPassword(String password)

getUrl

public String getUrl()

setUrl

public void setUrl(String url)

getDriver

public String getDriver()

setDriver

public void setDriver(String driver)

getSrcFiles

public File[] getSrcFiles()

setSrcFiles

public void setSrcFiles(File[] files)

getSuccessfulStatements

public int getSuccessfulStatements()
Number of SQL statements executed so far that caused errors.

Returns:
the number

getTotalStatements

public int getTotalStatements()
Number of SQL statements executed so far, including the ones that caused errors.

Returns:
the number

getOnError

public String getOnError()

setOnError

public void setOnError(String action)

setDriverProperties

public void setDriverProperties(String driverProperties)

isEnableBlockMode

public boolean isEnableBlockMode()

setEnableBlockMode

public void setEnableBlockMode(boolean enableBlockMode)

getSqlCommand

public String getSqlCommand()

setSqlCommand

public void setSqlCommand(String sqlCommand)

getTransactions

public Vector<org.codehaus.mojo.sql.SqlExecMojo.Transaction> getTransactions()

setTransactions

public void setTransactions(Vector<org.codehaus.mojo.sql.SqlExecMojo.Transaction> transactions)

setFileFilter

public void setFileFilter(org.apache.maven.shared.filtering.MavenFileFilter filter)

getResourceLocations

public String[] getResourceLocations()

setResourceLocations

public void setResourceLocations(String[] resourceLocations)

isExecuteTrailingSQL

public boolean isExecuteTrailingSQL()

setExecuteTrailingSQL

public void setExecuteTrailingSQL(boolean executeTrailingSQL)

getOrderFile

public Order getOrderFile()

setOrderFile

public void setOrderFile(String orderFile)


Copyright © 2006-2011 The Kuali Foundation. All Rights Reserved.