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

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

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.


Field Summary
protected static java.lang.String DEFAULT_STATEMENT_DELIMITER
          The default Statement delimiter.
 
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 changeDelimiterIfNecessary(java.lang.String statement, java.lang.String line, java.lang.String delimiter)
          Checks whether this line in the sql script indicates that the statement delimiter will be different from the current one.
protected  boolean endsWithOpenMultilineStringLiteral(java.lang.String statement)
          Checks whether the statement we have assembled so far ends with an open multi-line string literal (which will be continued on the next line).
 void execute(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
          Executes this script against the database.
 java.util.List<SqlStatement> getSqlStatements()
           
protected  boolean isCommentDirective(java.lang.String line)
          Checks whether this line is in fact a directive disguised as a comment.
protected  boolean isDelimiterChangeExplicit()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STATEMENT_DELIMITER

protected static final java.lang.String DEFAULT_STATEMENT_DELIMITER
The default Statement delimiter.

See Also:
Constant Field Values
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.

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.

execute

public void execute(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
Executes this script against the database.

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

changeDelimiterIfNecessary

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

Parameters:
statement - The statement assembled so far, reduced to a single line with all linebreaks replaced by spaces.
line - The line to analyse.
delimiter - The current delimiter.
Returns:
The new delimiter to use (can be the same as the current one) or null for no delimiter.

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.

isCommentDirective

protected boolean isCommentDirective(java.lang.String line)
Checks whether this line is in fact a directive disguised as a comment.

Parameters:
line - The line to analyse.
Returns:
true if it is a directive that should be processed by the database, false if not.

endsWithOpenMultilineStringLiteral

protected boolean endsWithOpenMultilineStringLiteral(java.lang.String statement)
Checks whether the statement we have assembled so far ends with an open multi-line string literal (which will be continued on the next line).

Parameters:
statement - The current statement, assembled from the lines we have parsed so far. May not yet be complete.
Returns:
true if the statement is unfinished and the end is currently in the middle of a multi-line string literal. false if not.


Copyright © 2011. All Rights Reserved.