liquibase.change
Class AbstractSQLChange

java.lang.Object
  extended by liquibase.change.AbstractChange
      extended by liquibase.change.AbstractSQLChange
All Implemented Interfaces:
Change, DbmsTargetedChange, LiquibaseSerializable
Direct Known Subclasses:
RawSQLChange, SQLFileChange

public abstract class AbstractSQLChange
extends AbstractChange
implements DbmsTargetedChange

A common parent for all raw SQL related changes regardless of where the sql was sourced from. Implements the necessary logic to choose how the SQL string should be parsed to generate the statements.


Nested Class Summary
static class AbstractSQLChange.NormalizingStream
           
 
Nested classes/interfaces inherited from interface liquibase.serializer.LiquibaseSerializable
LiquibaseSerializable.SerializationType
 
Field Summary
protected  String encoding
           
 
Fields inherited from interface liquibase.serializer.LiquibaseSerializable
GENERIC_CHANGELOG_EXTENSION_NAMESPACE, GENERIC_SNAPSHOT_EXTENSION_NAMESPACE, STANDARD_CHANGELOG_NAMESPACE, STANDARD_SNAPSHOT_NAMESPACE
 
Constructor Summary
protected AbstractSQLChange()
           
 
Method Summary
 ChangeStatus checkStatus(Database database)
          Validate that this change executed successfully against the given database.
 CheckSum generateCheckSum()
          Calculates the checksum based on the contained SQL.
 boolean generateRollbackStatementsVolatile(Database database)
          Implementation delegates logic to the SqlGenerator.generateRollbackStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database) If no or null SqlStatements are returned by generateRollbackStatements then this method returns false.
 SqlStatement[] generateStatements(Database database)
          Generates one or more SqlStatements depending on how the SQL should be parsed.
 boolean generateStatementsVolatile(Database database)
          Implementation delegates logic to the SqlGenerator.generateStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database).
 String getDbms()
           
 String getEndDelimiter()
          Set the end delimiter used to split statements.
 String getSql()
          Return the raw SQL managed by this Change
 Boolean isSplitStatements()
          Return if the SQL should be split into multiple statements before passing it to the database.
 Boolean isStripComments()
          Return if comments should be stripped from the SQL before passing it to the database.
protected  String normalizeLineEndings(String string)
           
 InputStream openSqlStream()
           
 void setDbms(String dbms)
           
 void setEndDelimiter(String endDelimiter)
          Set the end delimiter for splitting SQL statements.
 void setSplitStatements(Boolean splitStatements)
          Set whether SQL should be split into multiple statements.
 void setSql(String sql)
          Set the raw SQL managed by this Change.
 void setStripComments(Boolean stripComments)
          Return true if comments should be stripped from the SQL before passing it to the database.
 boolean supports(Database database)
          Implementation delegates logic to the SqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database).
 ValidationErrors validate(Database database)
          Implementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to the SqlGenerator.validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database).
 Warnings warn(Database database)
          Implementation delegates logic to the SqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database).
 
Methods inherited from class liquibase.change.AbstractChange
createChangeMetaData, createChangeParameterMetadata, createDescriptionMetaData, createEmptyColumnConfig, createExampleValueMetaData, createInverses, createMustEqualExistingMetaData, createRequiredDatabasesMetaData, createSerializationTypeMetaData, createSinceMetaData, createSupportedDatabasesMetaData, customLoadLogic, finishInitialization, generateRollbackStatements, getAffectedDatabaseObjects, getChangeSet, getDescription, getResourceAccessor, getSerializableFieldNamespace, getSerializableFields, getSerializableFieldType, getSerializableFieldValue, getSerializedObjectName, getSerializedObjectNamespace, isInvalidProperty, load, serialize, serializeValue, setChangeSet, setResourceAccessor, supportsRollback, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface liquibase.change.Change
getConfirmationMessage
 

Field Detail

encoding

protected String encoding
Constructor Detail

AbstractSQLChange

protected AbstractSQLChange()
Method Detail

openSqlStream

public InputStream openSqlStream()
                          throws IOException
Throws:
IOException

getDbms

public String getDbms()
Specified by:
getDbms in interface DbmsTargetedChange
Returns:
A comma separated list of dbms' that this change will be run for. Will run for all dbms' if empty or null.

setDbms

public void setDbms(String dbms)
Specified by:
setDbms in interface DbmsTargetedChange

supports

public boolean supports(Database database)
Implementation delegates logic to the SqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database). If no or null SqlStatements are returned by generateStatements then this method returns true. If AbstractChange.generateStatementsVolatile(liquibase.database.Database) returns true, we cannot call generateStatements and so assume true.

Specified by:
supports in interface Change
Overrides:
supports in class AbstractChange
Parameters:
database -
Returns:

warn

public Warnings warn(Database database)
Description copied from class: AbstractChange
Implementation delegates logic to the SqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database). If a generated statement is not supported for the given database, no warning will be added since that is a validation error. If no or null SqlStatements are returned by generateStatements then this method returns no warnings.

Specified by:
warn in interface Change
Overrides:
warn in class AbstractChange

validate

public ValidationErrors validate(Database database)
Description copied from class: AbstractChange
Implementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to the SqlGenerator.validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database). If no or null SqlStatements are returned by generateStatements then this method returns no errors. If there are no parameters than this method returns no errors

Specified by:
validate in interface Change
Overrides:
validate in class AbstractChange

isStripComments

public Boolean isStripComments()
Return if comments should be stripped from the SQL before passing it to the database.

This will always return a non-null value and should be a boolean rather than a Boolean, but that breaks the Bean Standard.


setStripComments

public void setStripComments(Boolean stripComments)
Return true if comments should be stripped from the SQL before passing it to the database. Passing null sets stripComments to the default value (false).


isSplitStatements

public Boolean isSplitStatements()
Return if the SQL should be split into multiple statements before passing it to the database. By default, statements are split around ";" and "go" delimiters.

This will always return a non-null value and should be a boolean rather than a Boolean, but that breaks the Bean Standard.


setSplitStatements

public void setSplitStatements(Boolean splitStatements)
Set whether SQL should be split into multiple statements. Passing null sets stripComments to the default value (true).


getSql

public String getSql()
Return the raw SQL managed by this Change


setSql

public void setSql(String sql)
Set the raw SQL managed by this Change. The passed sql is trimmed and set to null if an empty string is passed.


getEndDelimiter

public String getEndDelimiter()
Set the end delimiter used to split statements. Will return null if the default delimiter should be used.

See Also:
splitStatements

setEndDelimiter

public void setEndDelimiter(String endDelimiter)
Set the end delimiter for splitting SQL statements. Set to null to use the default delimiter.

Parameters:
endDelimiter -

generateCheckSum

public CheckSum generateCheckSum()
Calculates the checksum based on the contained SQL.

Specified by:
generateCheckSum in interface Change
Overrides:
generateCheckSum in class AbstractChange
See Also:
AbstractChange.generateCheckSum()

generateStatements

public SqlStatement[] generateStatements(Database database)
Generates one or more SqlStatements depending on how the SQL should be parsed. If split statements is set to true then the SQL is split and each command is made into a separate SqlStatement.

If stripping comments is true then any comments are removed before the splitting is executed. The set SQL is passed through the Connection.nativeSQL(java.lang.String) method if a connection is available.

Specified by:
generateStatements in interface Change

generateStatementsVolatile

public boolean generateStatementsVolatile(Database database)
Description copied from class: AbstractChange
Implementation delegates logic to the SqlGenerator.generateStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database). If zero or null SqlStatements are returned by generateStatements then this method returns false.

Specified by:
generateStatementsVolatile in interface Change
Overrides:
generateStatementsVolatile in class AbstractChange

generateRollbackStatementsVolatile

public boolean generateRollbackStatementsVolatile(Database database)
Description copied from class: AbstractChange
Implementation delegates logic to the SqlGenerator.generateRollbackStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database) If no or null SqlStatements are returned by generateRollbackStatements then this method returns false.

Specified by:
generateRollbackStatementsVolatile in interface Change
Overrides:
generateRollbackStatementsVolatile in class AbstractChange

checkStatus

public ChangeStatus checkStatus(Database database)
Description copied from interface: Change
Validate that this change executed successfully against the given database. This will check that the update completed at a high level plus check details of the change. For example, a change to add a column will check that the column exists plus data type, default values, etc.

Specified by:
checkStatus in interface Change
Overrides:
checkStatus in class AbstractChange

normalizeLineEndings

protected String normalizeLineEndings(String string)


Copyright © 2016 Liquibase.org. All rights reserved.