Package org.codehaus.mojo.sql
Class SqlExecMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.codehaus.mojo.sql.SqlExecMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
@Mojo(name="execute",
requiresProject=true,
threadSafe=true)
public class SqlExecMojo
extends org.apache.maven.plugin.AbstractMojo
Executes SQL against a database.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The default SQL delimiter which is used to separate statements.static final String
CallsetOrderFile(String)
with this value to sort in ascendant order the sql files.static final String
CallsetOrderFile(String)
with this value to sort in descendant order the sql files.static final String
CallsetOnError(String)
with this value to abort SQL command execution if an error is found.static final String
CallsetOnError(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 final String
CallsetOnError(String)
with this value to continue SQL command execution if an error is found.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Set an inline SQL command to execute.protected void
clear()
org.codehaus.mojo.sql.SqlExecMojo.Transaction
Add a SQL transaction to executevoid
execute()
Load the sql file and then execute itprotected void
protected int
protected Properties
parse driverProperties into Properties setFile[]
int
Number of SQL statements executed so far that caused errors.int
Number of SQL statements executed so far, including the ones that caused errors.List
<org.codehaus.mojo.sql.SqlExecMojo.Transaction> getUrl()
protected boolean
Check is the database connection closed.protected void
printResultSet
(ResultSet rs, PrintStream out) print any results in the result set.protected void
printResultSetCount
(int updateCountTotal, PrintStream out) void
setAppend
(boolean append) whether output should be appended to or overwrite an existing file.void
setConnectionRetryCount
(int connectionRetryCount) void
setConnectionRetryInterval
(int connectionRetryInterval) void
setConnectionValidationSqls
(List<String> connectionValidationSql) 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
void
setDriverProperties
(String driverProperties) void
setEncoding
(String encoding) Set the file encoding to use on the SQL files read invoid
setEscapeProcessing
(boolean enable) Set escape processing for statements.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
setOutputDelimiter
(String outputDelimiter) void
setOutputEncoding
(String outputEncoding) void
setOutputFile
(File output) Set the output file;void
setPassword
(String password) void
setPrintResultSet
(boolean print) Print result sets from the statements; optional, default falsevoid
setRollbackTransactions
(boolean rollbackTransactions) void
setSecurityDispatcher
(org.sonatype.plexus.components.sec.dispatcher.SecDispatcher securityDispatcher) void
setShowFooter
(boolean showFooter) void
setShowHeaders
(boolean showHeaders) Print headers for result sets from the statements; optional, default true.void
setSkipMissingFiles
(boolean skipMissingFiles) void
setSqlCommand
(String sqlCommand) void
setSrcFiles
(File[] files) void
setTransactions
(List<org.codehaus.mojo.sql.SqlExecMojo.Transaction> transactions) void
void
setUsername
(String username) protected boolean
skipMojo()
Determine if the mojo execution should get skipped.protected void
validateConnection
(Connection conn) Validate the database connection by executing all validation SQLs.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
ON_ERROR_ABORT
CallsetOnError(String)
with this value to abort SQL command execution if an error is found.- See Also:
-
ON_ERROR_ABORT_AFTER
CallsetOnError(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:
-
ON_ERROR_CONTINUE
CallsetOnError(String)
with this value to continue SQL command execution if an error is found.- See Also:
-
FILE_SORTING_ASC
CallsetOrderFile(String)
with this value to sort in ascendant order the sql files.- See Also:
-
FILE_SORTING_DSC
CallsetOrderFile(String)
with this value to sort in descendant order the sql files.- See Also:
-
DEFAULT_DELIMITER
The default SQL delimiter which is used to separate statements.- See Also:
-
-
Constructor Details
-
SqlExecMojo
public SqlExecMojo()
-
-
Method Details
-
createTransaction
public org.codehaus.mojo.sql.SqlExecMojo.Transaction createTransaction()Add a SQL transaction to execute- Returns:
- a new SqlExecMojo.Transaction
-
addText
Set an inline SQL command to execute. NB: Properties are not expanded in this text.- Parameters:
sql
- the sql statement to add
-
setEncoding
Set the file encoding to use on the SQL files read in- Parameters:
encoding
- the encoding to use on the files
-
setDelimiter
Set the delimiter that separates SQL statements. Defaults to ";";- Parameters:
delimiter
- the new delimiter
-
setDelimiterType
Set the delimiter type: "normal" or "row" (default "normal").- Parameters:
delimiterType
- the new delimiterType
-
setPrintResultSet
public void setPrintResultSet(boolean print) Print result sets from the statements; optional, default false- Parameters:
print
-true
to print the resultset, otherwisefalse
-
setShowHeaders
public void setShowHeaders(boolean showHeaders) Print headers for result sets from the statements; optional, default true.- Parameters:
showHeaders
-true
to show the headers, otherwisefalse
-
setOutputFile
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, otherwisefalse
to overwrite
-
setKeepFormat
public void setKeepFormat(boolean keepformat) whether or not format should be preserved. Defaults to false.- Parameters:
keepformat
-true
to keep the formatfalse
otherwise.
-
setEscapeProcessing
public void setEscapeProcessing(boolean enable) Set escape processing for statements.- Parameters:
enable
-true
to escape, otherwisefalse
-
skipMojo
protected boolean skipMojo()Determine if the mojo execution should get skipped.
This is the case if:skip
istrue
- if the mojo gets executed on a project with packaging type 'pom' and
forceMojoExecution
isfalse
- Returns:
true
if the mojo execution should be skipped.
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionExceptionLoad the sql file and then execute it- Throws:
org.apache.maven.plugin.MojoExecutionException
-
executeSqlCore
protected void executeSqlCore() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getDriverProperties
parse driverProperties into Properties set- Returns:
- the driver properties
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
printResultSet
print any results in the result set.- Parameters:
rs
- the resultset to print information aboutout
- the place to print results- Throws:
SQLException
- on SQL problems.
-
printResultSetCount
-
getUsername
-
setUsername
-
getPassword
-
setPassword
-
getUrl
-
setUrl
-
getDriver
-
setDriver
-
setRollbackTransactions
public void setRollbackTransactions(boolean rollbackTransactions) -
getSrcFiles
-
setSrcFiles
-
getOrderFile
-
setOrderFile
-
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
-
setOnError
-
validateConnection
Validate the database connection by executing all validation SQLs.- Parameters:
conn
- the open database connection- Throws:
SQLException
- if SQL execution fails
-
isConnectionClosed
protected boolean isConnectionClosed()Check is the database connection closed.- Returns:
true
if the connection is closed, otherwisefalse
-
clear
protected void clear() -
getConnectionRetryAttempts
protected int getConnectionRetryAttempts() -
setConnectionValidationSqls
-
setConnectionRetryCount
public void setConnectionRetryCount(int connectionRetryCount) -
setConnectionRetryInterval
public void setConnectionRetryInterval(int connectionRetryInterval) -
setSkipMissingFiles
public void setSkipMissingFiles(boolean skipMissingFiles) -
setDriverProperties
-
getSqlCommand
-
setSqlCommand
-
getTransactions
-
setTransactions
-
setSecurityDispatcher
public void setSecurityDispatcher(org.sonatype.plexus.components.sec.dispatcher.SecDispatcher securityDispatcher) -
setOutputDelimiter
-
setOutputEncoding
-