|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.maven.plugin.AbstractMojo org.codehaus.mojo.sql.SqlExecMojo
public class SqlExecMojo
Executes SQL against a database.
Nested Class Summary | |
---|---|
private class |
SqlExecMojo.Transaction
Contains the definition of a new transaction element. |
Field Summary | |
---|---|
private boolean |
append
Append to an existing file or overwrite it? |
private boolean |
autocommit
Set to true to execute none-transactional SQL. |
private Connection |
conn
Database connection |
private String |
delimiter
Set the delimiter that separates SQL statements. |
private String |
delimiterType
The delimiter type takes two values - "normal" and "row". |
private String |
driver
Database driver classname. |
private String |
driverProperties
Additional key=value pairs separated by comma to be passed into JDBC driver. |
private boolean |
enableAnonymousPassword
Ignore the password and use anonymous access. |
private boolean |
enableBlockMode
Deprecated. used delimiterType instead. |
private boolean |
enableFiltering
Set to true if you want to filter the srcFiles using system-, user- and project properties |
private String |
encoding
Encoding to use when reading SQL statements from a file. |
private boolean |
escapeProcessing
Argument to Statement.setEscapeProcessing If you want the driver to use regular SQL syntax then set this to false. |
private boolean |
executeTrailingSQL
Set to false to disable executing SQL that appears without a delimiter at the end of a file (is enabled by default for backwards compatibility) |
private org.apache.maven.shared.filtering.MavenFileFilter |
fileFilter
|
private Fileset |
fileset
File(s) containing SQL statements to load. |
private boolean |
forceMojoExecution
Setting this parameter to true will force the execution of this mojo, even if it would get skipped
usually. |
private boolean |
keepFormat
Keep the format of an SQL block. |
private org.apache.maven.execution.MavenSession |
mavenSession
|
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. |
private String |
onError
Action to perform if an error is found. |
private Order |
orderFile
Set the order in which the SQL files will be executed. |
private String |
outputDelimiter
|
private File |
outputFile
Dump the SQL exection's output to a file. |
private String |
password
Database password. |
private boolean |
printResultSet
Print SQL results. |
protected org.apache.maven.project.MavenProject |
project
The Maven Project Object |
private String[] |
resourceLocations
List of resources containing SQL statements |
private org.apache.maven.settings.Settings |
settings
|
private String |
settingsKey
Server's id in settings.xml to look up username and password. |
private boolean |
showheaders
Print header columns. |
private boolean |
skip
When true , skip the execution. |
private boolean |
skipOnConnectionError
Skip execution when there is an error obtaining a connection. |
private String |
sqlCommand
SQL input commands separated by ${delimiter} . |
private File[] |
srcFiles
List of files containing SQL statements to load. |
private Statement |
statement
SQL statement |
private int |
successfulStatements
number of successful executed statements |
private int |
totalStatements
number of total executed statements |
private Vector<SqlExecMojo.Transaction> |
transactions
SQL transactions to perform |
private String |
url
Database URL. |
private String |
username
Database username. |
Fields inherited from interface org.apache.maven.plugin.Mojo |
---|
ROLE |
Constructor Summary | |
---|---|
SqlExecMojo()
|
Method Summary | |
---|---|
private void |
addCommandToTransactions()
Add sql command to transactions list. |
private void |
addFileSetToTransactions()
Add user sql fileset to transation list |
private void |
addFilesToTransactions()
Add user input of srcFiles to transaction list. |
private void |
addResourcesToTransactions()
Add user input of srcFiles to transaction list. |
void |
addText(String sql)
Set an inline SQL command to execute. |
protected void |
copy(org.springframework.core.io.Resource resource,
File file)
|
SqlExecMojo.Transaction |
createTransaction()
Add a SQL transaction to execute |
private void |
execSQL(String sql,
PrintStream out)
Exec the sql statement. |
void |
execute()
Load the sql file and then execute it |
private Connection |
getConnection()
Creates a new Connection as using the driver, url, userid and password specified. |
String |
getDriver()
|
protected Properties |
getDriverProperties()
parse driverProperties into Properties set |
(package private) int |
getGoodSqls()
Deprecated. use getSuccessfulStatements() |
String |
getOnError()
|
Order |
getOrderFile()
|
String |
getPassword()
|
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<SqlExecMojo.Transaction> |
getTransactions()
|
String |
getUrl()
|
String |
getUsername()
|
boolean |
isEnableBlockMode()
|
protected boolean |
isEnd(String line)
|
boolean |
isExecuteTrailingSQL()
|
private void |
loadUserInfoFromSettings()
Load username password from settings if user has not set them in JVM properties |
private void |
printResultSet(ResultSet rs,
PrintStream out)
print any results in the result set. |
private void |
runStatements(Reader reader,
PrintStream out)
read in lines and execute them |
void |
setAppend(boolean append)
whether output should be appended to or overwrite an existing file. |
(package private) void |
setAutocommit(boolean autocommit)
|
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)
|
(package private) void |
setFileset(Fileset fileset)
|
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)
|
(package private) void |
setSettings(org.apache.maven.settings.Settings settings)
|
(package private) void |
setSettingsKey(String key)
|
void |
setShowheaders(boolean showheaders)
Print headers for result sets from the statements; optional, default true. |
(package private) void |
setSkip(boolean skip)
|
void |
setSqlCommand(String sqlCommand)
|
void |
setSrcFiles(File[] files)
|
void |
setTransactions(Vector<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 |
---|
public static final String ON_ERROR_ABORT
setOnError(String)
with this value to abort SQL command execution if an error is found.
public static final String ON_ERROR_ABORT_AFTER
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.
public static final String ON_ERROR_CONTINUE
setOnError(String)
with this value to continue SQL command execution if an error is found.
private String username
settings.xml
's server with
${settingsKey}
as key.
private String password
settings.xml
's server with
${settingsKey}
as key.
private boolean enableAnonymousPassword
private String driverProperties
private org.apache.maven.settings.Settings settings
private String settingsKey
id
in settings.xml
to look up username and password. Defaults to
${url}
if not given.
private boolean skipOnConnectionError
shutdown=true
).
private boolean forceMojoExecution
true
will force the execution of this mojo, even if it would get skipped
usually.
protected org.apache.maven.project.MavenProject project
private org.apache.maven.execution.MavenSession mavenSession
private String sqlCommand
${delimiter}
.
private File[] srcFiles
private String[] resourceLocations
private Fileset fileset
private boolean skip
true
, skip the execution.
private String url
private String driver
private boolean autocommit
true
to execute none-transactional SQL.
private String onError
abort
and continue
.
private String delimiter
private String delimiterType
The delimiter type takes two values - "normal" and "row". Normal means that any occurrence 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.
For example, set this to "go" and delimiterType to "row" for Sybase ASE or MS SQL Server.
private Order orderFile
ASCENDING
and
DESCENDING
and NONE
.
@Deprecated private boolean enableBlockMode
true
, the whole SQL content in sqlCommand
, srcFiles
and
fileset
are sent directly to JDBC in one SQL statement. This option is for executing database stored
procedures/functions.
private boolean keepFormat
private boolean printResultSet
private boolean showheaders
private File outputFile
private String outputDelimiter
private String encoding
private boolean append
private boolean escapeProcessing
private int successfulStatements
private int totalStatements
private Connection conn
private Statement statement
private Vector<SqlExecMojo.Transaction> transactions
private org.apache.maven.shared.filtering.MavenFileFilter fileFilter
private boolean enableFiltering
private boolean executeTrailingSQL
Constructor Detail |
---|
public SqlExecMojo()
Method Detail |
---|
public SqlExecMojo.Transaction createTransaction()
public void addText(String sql)
sql
- the sql statement to addpublic void setEncoding(String encoding)
encoding
- the encoding to use on the filespublic void setDelimiter(String delimiter)
delimiter
- the new delimiterpublic void setDelimiterType(String delimiterType)
delimiterType
- the new delimiterType@Deprecated public void setPrintResutlSet(boolean print)
print
- true
to print the resultset, otherwise false
public void setPrintResultSet(boolean print)
print
- true
to print the resultset, otherwise false
public void setShowheaders(boolean showheaders)
showheaders
- true
to show the headers, otherwise false
public void setOutputFile(File output)
output
- the output filepublic void setAppend(boolean append)
append
- true
to append, otherwise false
to overwritepublic void setKeepFormat(boolean keepformat)
keepformat
- The keepformat to setpublic void setEscapeProcessing(boolean enable)
enable
- true
to escape, otherwiser false
protected boolean skipMojo()
Determine if the mojo execution should get skipped.
This is the case if:skip
is true
forceMojoExecution
is
false
true
if the mojo execution should be skipped.public void execute() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
private void addCommandToTransactions()
private void addFileSetToTransactions()
protected org.springframework.core.io.Resource[] getResources(String[] locations) throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
protected void copy(org.springframework.core.io.Resource resource, File file) throws IOException
IOException
private void addResourcesToTransactions() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
private void addFilesToTransactions() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
protected void sortTransactions()
private void loadUserInfoFromSettings() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
private Connection getConnection() throws org.apache.maven.plugin.MojoExecutionException, SQLException
org.apache.maven.plugin.MojoExecutionException
- if the UserId/Password/Url is not set or there is no suitable driver or the driver fails to load.
SQLException
- if there is problem getting connection with valid urlprotected Properties getDriverProperties() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
private void runStatements(Reader reader, PrintStream out) throws SQLException, IOException
reader
- the readerout
- the outputstream
SQLException
IOException
protected boolean isEnd(String line)
private void execSQL(String sql, PrintStream out) throws SQLException
sql
- query to executeout
- the outputstream
SQLException
private void printResultSet(ResultSet rs, PrintStream out) throws SQLException
rs
- the resultset to print information aboutout
- the place to print results
SQLException
- on SQL problems.public String getUsername()
public void setUsername(String username)
public String getPassword()
public void setPassword(String password)
public String getUrl()
public void setUrl(String url)
public String getDriver()
public void setDriver(String driver)
void setAutocommit(boolean autocommit)
void setFileset(Fileset fileset)
public File[] getSrcFiles()
public void setSrcFiles(File[] files)
@Deprecated int getGoodSqls()
getSuccessfulStatements()
public int getSuccessfulStatements()
public int getTotalStatements()
public String getOnError()
public void setOnError(String action)
void setSettings(org.apache.maven.settings.Settings settings)
void setSettingsKey(String key)
void setSkip(boolean skip)
public void setDriverProperties(String driverProperties)
public boolean isEnableBlockMode()
public void setEnableBlockMode(boolean enableBlockMode)
public String getSqlCommand()
public void setSqlCommand(String sqlCommand)
public Vector<SqlExecMojo.Transaction> getTransactions()
public void setTransactions(Vector<SqlExecMojo.Transaction> transactions)
public void setFileFilter(org.apache.maven.shared.filtering.MavenFileFilter filter)
public String[] getResourceLocations()
public void setResourceLocations(String[] resourceLocations)
public boolean isExecuteTrailingSQL()
public void setExecuteTrailingSQL(boolean executeTrailingSQL)
public Order getOrderFile()
public void setOrderFile(String orderFile)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |