org.apache.torque.mojo
Class AbstractSQLExecutorMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.apache.torque.mojo.BaseMojo
          extended by org.apache.torque.mojo.AbstractSQLExecutorMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
AbstractDBACommandMojo, ImportMojo

public abstract class AbstractSQLExecutorMojo
extends BaseMojo

Abstract mojo for making use of SQLExecutor


Field Summary
(package private)  boolean append
          If writing output to a file, append to an existing file or overwrite it?
(package private)  boolean autocommit
          Set to true to execute non-transactional SQL.
(package private)  Connection conn
          Database connection
(package private)  ConnectionHandler connectionHandler
           
(package private)  Credentials credentials
          The credentials to use for database access
(package private)  String delimiter
          Set the delimiter that separates SQL statements.
(package private)  String delimiterType
          The delimiter type takes two values - "normal" and "row".
(package private)  String driver
          Database driver classname.
static String DRIVER_INFO_PROPERTIES_PASSWORD
           
static String DRIVER_INFO_PROPERTIES_USER
           
(package private)  String driverProperties
          Additional key=value pairs separated by a comma to be passed to JDBC driver.
(package private)  boolean enableAnonymousPassword
          Ignore the password and use anonymous access.
(package private)  boolean enableAnonymousUsername
          Ignore the username and use anonymous access.
(package private)  boolean escapeProcessing
          Argument to Statement.setEscapeProcessing If you want the driver to use regular SQL syntax then set this to false.
static String FILE_SORTING_ASC
          Call #setOrder(String) with this value to sort in ascendant order the sql files.
static String FILE_SORTING_DSC
          Call #setOrder(String) with this value to sort in descendant order the sql files.
(package private)  org.apache.maven.shared.filtering.MavenFileFilter fileFilter
           
(package private)  JDBCUtils jdbcUtils
           
(package private)  boolean keepFormat
          Keep the format of an SQL block.
(package private)  String onError
          Action to perform if an error is found.
(package private)  String password
          Database password.
(package private)  Platform platform
           
(package private)  String settingsKey
          The id of the server in settings.xml containing the username/password to use.
(package private)  boolean showheaders
          Print header columns.
(package private)  boolean showPassword
          If set to true the password being used to connect to the database will be displayed in log messages.
(package private)  boolean skipOnConnectionError
          Skip execution if there is an error obtaining a connection.
(package private)  String sqlCommand
          SQL input commands separated by ${delimiter}.
(package private)  File[] srcFiles
          List of files containing SQL statements to load.
(package private)  int successfulStatements
          number of successful executed statements
(package private)  String targetDatabase
          The type of database we are targeting (eg oracle, mysql).
(package private)  int totalStatements
          number of total executed statements
(package private)  Vector<Transaction> transactions
          SQL transactions to perform
(package private)  String url
          Database URL.
(package private)  String username
          Database username.
(package private)  Utils utils
           
 
Fields inherited from class org.apache.torque.mojo.BaseMojo
FS, SKIP_PACKAGING_TYPE
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
AbstractSQLExecutorMojo()
           
 
Method Summary
 void addText(String sql)
          Set an inline SQL command to execute.
protected  void configureTransactions()
           
protected  String convertNullToEmpty(String s)
           
 void executeMojo()
          Validate our configuration and execute SQL as appropriate
 Connection getConn()
           
protected  Connection getConnection()
          Creates a new Connection as using the driver, url, userid and password specified.
protected  Properties getContextProperties()
           
 Credentials getCredentials()
           
 String getDelimiter()
           
 String getDelimiterType()
           
protected  String getDisplayPassword(String password)
           
 String getDriver()
           
protected  Properties getDriverProperties()
          parse driverProperties into Properties set
 org.apache.maven.shared.filtering.MavenFileFilter getFileFilter()
           
protected  ConnectionHandler getNewConnectionHandler()
           
protected  Credentials getNewCredentials()
           
 String getOnError()
           
 String getPassword()
           
protected  org.apache.maven.settings.Server getServerFromSettingsKey()
           
 String getSettingsKey()
           
 String getSqlCommand()
           
protected  SQLExecutor getSqlExecutor()
           
 File[] getSrcFiles()
           
 int getSuccessfulStatements()
          Number of SQL statements executed so far that caused errors.
 String getTargetDatabase()
           
 int getTotalStatements()
          Number of SQL statements executed so far, including the ones that caused errors.
 Vector<Transaction> getTransactions()
           
protected  String getUpdatedPassword(org.apache.maven.settings.Server server, String password)
           
protected  String getUpdatedUsername(org.apache.maven.settings.Server server, String username)
           
 String getUrl()
           
 String getUsername()
           
 boolean isAppend()
           
 boolean isAutocommit()
           
 boolean isEnableAnonymousPassword()
           
 boolean isEscapeProcessing()
           
 boolean isKeepFormat()
           
protected  boolean isNullOrEmpty(Collection<?> c)
           
 boolean isShowheaders()
           
 boolean isShowPassword()
           
 boolean isSkipOnConnectionError()
           
 void setAppend(boolean append)
          whether output should be appended to or overwrite an existing file.
 void setAutocommit(boolean autocommit)
           
 void setConn(Connection conn)
           
 void setCredentials(Credentials credentials)
           
 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 setEnableAnonymousPassword(boolean enableAnonymousPassword)
           
 void 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 setPassword(String password)
           
 void setSettingsKey(String key)
           
 void setShowheaders(boolean showheaders)
          Print headers for result sets from the statements; optional, default true.
 void setShowPassword(boolean showPassword)
           
 void setSkipOnConnectionError(boolean skipOnConnectionError)
           
 void setSqlCommand(String sqlCommand)
           
 void setSrcFiles(File[] files)
           
 void setSuccessfulStatements(int successfulStatements)
           
 void setTargetDatabase(String targetDatabase)
           
 void setTotalStatements(int totalStatements)
           
 void setTransactions(Vector<Transaction> transactions)
           
 void setUrl(String url)
           
 void setUsername(String username)
           
protected  void updateConfiguration()
          Attempt to automatically detect the correct JDBC driver and database type (oracle, mysql, h2, derby, etc) given a JDBC url
protected  void updateCredentials(Credentials credentials)
          Load username/password from settings.xml if user has not set them in JVM properties
protected  void validateConfiguration()
          Validate that some essential configuration items are present
protected  void validateCredentials(Credentials credentials)
           
protected  void validateCredentials(Credentials credentials, boolean anonymousAccessAllowed, String validationFailureMessage)
           
 
Methods inherited from class org.apache.torque.mojo.BaseMojo
afterExecution, beforeExecution, execute, getEncoding, getMavenSession, getProject, getSettings, isForceMojoExecution, isSkip, isStartMavenLogger, setEncoding, setForceMojoExecution, setMavenSession, setProject, setSettings, setSkip, setStartMavenLogger, skipMojo
 
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

utils

Utils utils

jdbcUtils

JDBCUtils jdbcUtils

connectionHandler

ConnectionHandler connectionHandler

platform

Platform platform

DRIVER_INFO_PROPERTIES_USER

public static final String DRIVER_INFO_PROPERTIES_USER
See Also:
Constant Field Values

DRIVER_INFO_PROPERTIES_PASSWORD

public static final String DRIVER_INFO_PROPERTIES_PASSWORD
See Also:
Constant Field Values

FILE_SORTING_ASC

public static final String FILE_SORTING_ASC
Call #setOrder(String) with this value to sort in ascendant order the sql files.

See Also:
Constant Field Values

FILE_SORTING_DSC

public static final String FILE_SORTING_DSC
Call #setOrder(String) with this value to sort in descendant order the sql files.

See Also:
Constant Field Values

targetDatabase

String targetDatabase
The type of database we are targeting (eg oracle, mysql). This is optional if url is supplied as the database type will be automatically detected based on the url. If targetDatabase is explicitly supplied it will override the type selected by the automatic detection logic.


username

String username
Database username. If not given, it will be looked up through settings.xml's server with ${settingsKey} as key.


password

String password
Database password. If not given, it will be looked up through settings.xml's server with ${settingsKey} as key.


enableAnonymousPassword

boolean enableAnonymousPassword
Ignore the password and use anonymous access.


enableAnonymousUsername

boolean enableAnonymousUsername
Ignore the username and use anonymous access.


driverProperties

String driverProperties
Additional key=value pairs separated by a comma to be passed to JDBC driver.


showPassword

boolean showPassword
If set to true the password being used to connect to the database will be displayed in log messages.


settingsKey

String settingsKey
The id of the server in settings.xml containing the username/password to use.


skipOnConnectionError

boolean skipOnConnectionError
Skip execution if there is an error obtaining a connection. If this is set to true, the build will continue even if there is an error obtaining a connection


sqlCommand

String sqlCommand
SQL input commands separated by ${delimiter}.


srcFiles

File[] srcFiles
List of files containing SQL statements to load.


url

String url
Database URL.


driver

String driver
Database driver classname. This parameter is optional, as the correct JDBC driver to use is detected from the url in almost all cases (works for Oracle, MySQL, Derby, PostGresSQL, DB2, H2, HSQL, SQL Server). If a driver is explicitly supplied, it will be used in place of the JDBC driver the automatic detection logic would have chosen.


autocommit

boolean autocommit
Set to true to execute non-transactional SQL.


onError

String onError
Action to perform if an error is found. Possible values are abort and continue.


delimiter

String delimiter
Set the delimiter that separates SQL statements.


delimiterType

String delimiterType
The delimiter type takes two values - "normal" and "row". Normal means that any occurrence of the delimiter terminates the SQL command whereas with row, only a line containing just the delimiter is recognized as the end of the command.

For example, set delimiterType to "row" and delimiter to "/" for Oracle


keepFormat

boolean keepFormat
Keep the format of an SQL block.


showheaders

boolean showheaders
Print header columns.


append

boolean append
If writing output to a file, append to an existing file or overwrite it?


escapeProcessing

boolean escapeProcessing
Argument to Statement.setEscapeProcessing If you want the driver to use regular SQL syntax then set this to false.


successfulStatements

int successfulStatements
number of successful executed statements


totalStatements

int totalStatements
number of total executed statements


conn

Connection conn
Database connection


transactions

Vector<Transaction> transactions
SQL transactions to perform


fileFilter

org.apache.maven.shared.filtering.MavenFileFilter fileFilter

credentials

Credentials credentials
The credentials to use for database access

Constructor Detail

AbstractSQLExecutorMojo

public AbstractSQLExecutorMojo()
Method Detail

configureTransactions

protected void configureTransactions()
                              throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

getContextProperties

protected Properties getContextProperties()

getNewCredentials

protected Credentials getNewCredentials()

getNewConnectionHandler

protected ConnectionHandler getNewConnectionHandler()
                                             throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

executeMojo

public void executeMojo()
                 throws org.apache.maven.plugin.MojoExecutionException
Validate our configuration and execute SQL as appropriate

Specified by:
executeMojo in class BaseMojo
Throws:
org.apache.maven.plugin.MojoExecutionException

addText

public void addText(String sql)
Set an inline SQL command to execute.

Parameters:
sql - the sql statement to add

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

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

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

getSqlExecutor

protected SQLExecutor getSqlExecutor()
                              throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

updateConfiguration

protected void updateConfiguration()
                            throws org.apache.maven.plugin.MojoExecutionException
Attempt to automatically detect the correct JDBC driver and database type (oracle, mysql, h2, derby, etc) given a JDBC url

Throws:
org.apache.maven.plugin.MojoExecutionException

validateConfiguration

protected void validateConfiguration()
                              throws org.apache.maven.plugin.MojoExecutionException
Validate that some essential configuration items are present

Throws:
org.apache.maven.plugin.MojoExecutionException

validateCredentials

protected void validateCredentials(Credentials credentials,
                                   boolean anonymousAccessAllowed,
                                   String validationFailureMessage)
                            throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

validateCredentials

protected void validateCredentials(Credentials credentials)
                            throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

isNullOrEmpty

protected boolean isNullOrEmpty(Collection<?> c)

convertNullToEmpty

protected String convertNullToEmpty(String s)

updateCredentials

protected void updateCredentials(Credentials credentials)
Load username/password from settings.xml if user has not set them in JVM properties

Throws:
org.apache.maven.plugin.MojoExecutionException

getServerFromSettingsKey

protected org.apache.maven.settings.Server getServerFromSettingsKey()

getUpdatedPassword

protected String getUpdatedPassword(org.apache.maven.settings.Server server,
                                    String password)

getDisplayPassword

protected String getDisplayPassword(String password)

getUpdatedUsername

protected String getUpdatedUsername(org.apache.maven.settings.Server server,
                                    String username)

getConnection

protected Connection getConnection()
                            throws org.apache.maven.plugin.MojoExecutionException
Creates a new Connection as using the driver, url, userid and password specified. The calling method is responsible for closing the connection.

Returns:
Connection the newly created connection.
Throws:
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 url

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

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)

setAutocommit

public void setAutocommit(boolean autocommit)

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)

setSettingsKey

public void setSettingsKey(String key)

setDriverProperties

public void setDriverProperties(String driverProperties)

getSqlCommand

public String getSqlCommand()

setSqlCommand

public void setSqlCommand(String sqlCommand)

getTransactions

public Vector<Transaction> getTransactions()

setTransactions

public void setTransactions(Vector<Transaction> transactions)

setFileFilter

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

getTargetDatabase

public String getTargetDatabase()

setTargetDatabase

public void setTargetDatabase(String targetDatabase)

getConn

public Connection getConn()

setConn

public void setConn(Connection conn)

getDelimiter

public String getDelimiter()

getDelimiterType

public String getDelimiterType()

isKeepFormat

public boolean isKeepFormat()

isShowheaders

public boolean isShowheaders()

isAppend

public boolean isAppend()

isEscapeProcessing

public boolean isEscapeProcessing()

isSkipOnConnectionError

public boolean isSkipOnConnectionError()

setSkipOnConnectionError

public void setSkipOnConnectionError(boolean skipOnConnectionError)

getFileFilter

public org.apache.maven.shared.filtering.MavenFileFilter getFileFilter()

isShowPassword

public boolean isShowPassword()

setShowPassword

public void setShowPassword(boolean showPassword)

isEnableAnonymousPassword

public boolean isEnableAnonymousPassword()

setEnableAnonymousPassword

public void setEnableAnonymousPassword(boolean enableAnonymousPassword)

getSettingsKey

public String getSettingsKey()

isAutocommit

public boolean isAutocommit()

setSuccessfulStatements

public void setSuccessfulStatements(int successfulStatements)

setTotalStatements

public void setTotalStatements(int totalStatements)

setCredentials

public void setCredentials(Credentials credentials)

getCredentials

public Credentials getCredentials()


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