com.googlecode.flyway.core.migration.sql
Class SqlScript

java.lang.Object
  extended by com.googlecode.flyway.core.migration.sql.SqlScript
Direct Known Subclasses:
MySQLSqlScript, OracleSqlScript

public class SqlScript
extends java.lang.Object

Sql script containing a series of statements terminated by semi-columns (;). Single-line (--) and multi-line (/* * /) comments are stripped and ignored.


Constructor Summary
protected SqlScript()
          Dummy constructor to increase testability.
  SqlScript(java.util.List<SqlStatement> sqlStatements)
          Creates a new SqlScript with these statements and this name.
  SqlScript(java.lang.String sqlScriptSource, PlaceholderReplacer placeholderReplacer)
          Creates a new sql script from this source with these placeholders to replace.
 
Method Summary
protected  java.lang.String checkForNewDelimiter(java.lang.String line)
          Checks whether this line in the sql script indicates that the statement delimiter will be different from the default one.
 void execute(org.springframework.transaction.support.TransactionTemplate transactionTemplate, org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
          Executes this script against the database.
 java.lang.Long getChecksum()
           
 java.util.List<SqlStatement> getSqlStatements()
           
protected  boolean isDelimiterChangeExplicit()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlScript

public SqlScript(java.lang.String sqlScriptSource,
                 PlaceholderReplacer placeholderReplacer)
Creates a new sql script from this source with these placeholders to replace.

Parameters:
sqlScriptSource - The sql script as a text block with all placeholders still present.
placeholderReplacer - The placeholder replacer to apply to sql migration scripts.
Throws:
java.lang.IllegalStateException - Thrown when the script could not be read from this resource.

SqlScript

public SqlScript(java.util.List<SqlStatement> sqlStatements)
Creates a new SqlScript with these statements and this name.

Parameters:
sqlStatements - The statements of the script.

SqlScript

protected SqlScript()
Dummy constructor to increase testability.

Method Detail

getSqlStatements

public java.util.List<SqlStatement> getSqlStatements()
Returns:
The sql statements contained in this script.

getChecksum

public java.lang.Long getChecksum()

execute

public void execute(org.springframework.transaction.support.TransactionTemplate transactionTemplate,
                    org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
Executes this script against the database.

Parameters:
transactionTemplate - The transaction template to use.
jdbcTemplate - The jdbc template to use to execute this script.

checkForNewDelimiter

protected java.lang.String checkForNewDelimiter(java.lang.String line)
Checks whether this line in the sql script indicates that the statement delimiter will be different from the default one. Useful for database-specific stored procedures and block constructs.

Parameters:
line - The line to analyse.
Returns:
The new delimiter to use or null if no change in delimiter is required.

isDelimiterChangeExplicit

protected boolean isDelimiterChangeExplicit()
Returns:
true if this database uses an explicit delimiter change statement. false if a delimiter change is implied by certain statements.


Copyright © 2010. All Rights Reserved.