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
FieldsModifier and TypeFieldDescriptionstatic final StringThe default SQL delimiter which is used to separate statements.static final StringCallsetOrderFile(String)with this value to sort in ascendant order the sql files.static final StringCallsetOrderFile(String)with this value to sort in descendant order the sql files.static final StringCallsetOnError(String)with this value to abort SQL command execution if an error is found.static final StringCallsetOnError(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 StringCallsetOnError(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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSet an inline SQL command to execute.protected voidclear()org.codehaus.mojo.sql.SqlExecMojo.TransactionAdd a SQL transaction to executevoidexecute()Load the sql file and then execute itprotected voidprotected intprotected Propertiesparse driverProperties into Properties setFile[]intNumber of SQL statements executed so far that caused errors.intNumber of SQL statements executed so far, including the ones that caused errors.List<org.codehaus.mojo.sql.SqlExecMojo.Transaction> getUrl()protected booleanCheck is the database connection closed.protected voidprintResultSet(ResultSet rs, PrintStream out) print any results in the result set.protected voidprintResultSetCount(int updateCountTotal, PrintStream out) voidsetAppend(boolean append) whether output should be appended to or overwrite an existing file.voidsetConnectionRetryCount(int connectionRetryCount) voidsetConnectionRetryInterval(int connectionRetryInterval) voidsetConnectionValidationSqls(List<String> connectionValidationSql) voidsetDelimiter(String delimiter) Set the delimiter that separates SQL statements.voidsetDelimiterType(String delimiterType) Set the delimiter type: "normal" or "row" (default "normal").voidvoidsetDriverProperties(String driverProperties) voidsetEncoding(String encoding) Set the file encoding to use on the SQL files read invoidsetEscapeProcessing(boolean enable) Set escape processing for statements.voidsetFileFilter(org.apache.maven.shared.filtering.MavenFileFilter filter) voidsetKeepFormat(boolean keepformat) whether or not format should be preserved.voidsetOnError(String action) voidsetOrderFile(String orderFile) voidsetOutputDelimiter(String outputDelimiter) voidsetOutputEncoding(String outputEncoding) voidsetOutputFile(File output) Set the output file;voidsetPassword(String password) voidsetPrintResultSet(boolean print) Print result sets from the statements; optional, default falsevoidsetRollbackTransactions(boolean rollbackTransactions) voidsetSecurityDispatcher(org.sonatype.plexus.components.sec.dispatcher.SecDispatcher securityDispatcher) voidsetShowFooter(boolean showFooter) voidsetShowHeaders(boolean showHeaders) Print headers for result sets from the statements; optional, default true.voidsetSkipMissingFiles(boolean skipMissingFiles) voidsetSqlCommand(String sqlCommand) voidsetSrcFiles(File[] files) voidsetTransactions(List<org.codehaus.mojo.sql.SqlExecMojo.Transaction> transactions) voidvoidsetUsername(String username) protected booleanskipMojo()Determine if the mojo execution should get skipped.protected voidvalidateConnection(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-trueto print the resultset, otherwisefalse
-
setShowHeaders
public void setShowHeaders(boolean showHeaders) Print headers for result sets from the statements; optional, default true.- Parameters:
showHeaders-trueto 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-trueto append, otherwisefalseto overwrite
-
setKeepFormat
public void setKeepFormat(boolean keepformat) whether or not format should be preserved. Defaults to false.- Parameters:
keepformat-trueto keep the formatfalseotherwise.
-
setEscapeProcessing
public void setEscapeProcessing(boolean enable) Set escape processing for statements.- Parameters:
enable-trueto escape, otherwisefalse
-
skipMojo
protected boolean skipMojo()Determine if the mojo execution should get skipped.
This is the case if:skipistrue- if the mojo gets executed on a project with packaging type 'pom' and
forceMojoExecutionisfalse
- Returns:
trueif 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:
trueif 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
-