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 Details

  • 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

      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
    • 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 - true to keep the format false otherwise.
    • setEscapeProcessing

      public void setEscapeProcessing(boolean enable)
      Set escape processing for statements.
      Parameters:
      enable - true to escape, otherwise false
    • skipMojo

      protected boolean skipMojo()

      Determine if the mojo execution should get skipped.

      This is the case if:
      • skip is true
      • if the mojo gets executed on a project with packaging type 'pom' and forceMojoExecution is false
      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
    • executeSqlCore

      protected void executeSqlCore() 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
    • printResultSet

      protected void printResultSet(ResultSet rs, PrintStream out) throws SQLException
      print any results in the result set.
      Parameters:
      rs - the resultset to print information about
      out - the place to print results
      Throws:
      SQLException - on SQL problems.
    • printResultSetCount

      protected void printResultSetCount(int updateCountTotal, PrintStream out)
    • 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)
    • setRollbackTransactions

      public void setRollbackTransactions(boolean rollbackTransactions)
    • getSrcFiles

      public File[] getSrcFiles()
    • setSrcFiles

      public void setSrcFiles(File[] files)
    • getOrderFile

      public String getOrderFile()
    • setOrderFile

      public void setOrderFile(String orderFile)
    • 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)
    • validateConnection

      protected void validateConnection(Connection conn) throws SQLException
      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, otherwise false
    • clear

      protected void clear()
    • getConnectionRetryAttempts

      protected int getConnectionRetryAttempts()
    • setConnectionValidationSqls

      public void setConnectionValidationSqls(List<String> connectionValidationSql)
    • setConnectionRetryCount

      public void setConnectionRetryCount(int connectionRetryCount)
    • setConnectionRetryInterval

      public void setConnectionRetryInterval(int connectionRetryInterval)
    • setSkipMissingFiles

      public void setSkipMissingFiles(boolean skipMissingFiles)
    • setDriverProperties

      public void setDriverProperties(String driverProperties)
    • getSqlCommand

      public String getSqlCommand()
    • setSqlCommand

      public void setSqlCommand(String sqlCommand)
    • getTransactions

      public List<org.codehaus.mojo.sql.SqlExecMojo.Transaction> getTransactions()
    • setTransactions

      public void setTransactions(List<org.codehaus.mojo.sql.SqlExecMojo.Transaction> transactions)
    • setFileFilter

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

      public void setSecurityDispatcher(org.sonatype.plexus.components.sec.dispatcher.SecDispatcher securityDispatcher)
    • setOutputDelimiter

      public void setOutputDelimiter(String outputDelimiter)
    • setOutputEncoding

      public void setOutputEncoding(String outputEncoding)
    • setShowFooter

      public void setShowFooter(boolean showFooter)