Package liquibase.change
Class AbstractSQLChange
- java.lang.Object
-
- liquibase.AbstractExtensibleObject
-
- liquibase.plugin.AbstractPlugin
-
- liquibase.change.AbstractChange
-
- liquibase.change.AbstractSQLChange
-
- All Implemented Interfaces:
Cloneable,Change,DbmsTargetedChange,ExtensibleObject,Plugin,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
Nested Classes Modifier and Type Class Description static classAbstractSQLChange.NormalizingStream-
Nested classes/interfaces inherited from interface liquibase.serializer.LiquibaseSerializable
LiquibaseSerializable.SerializationType
-
-
Field Summary
Fields Modifier and Type Field Description protected Stringencoding-
Fields inherited from class liquibase.change.AbstractChange
NODENAME_COLUMN
-
Fields inherited from interface liquibase.change.Change
EMPTY_CHANGE, SHOULD_EXECUTE
-
Fields inherited from interface liquibase.serializer.LiquibaseSerializable
GENERIC_CHANGELOG_EXTENSION_NAMESPACE, GENERIC_SNAPSHOT_EXTENSION_NAMESPACE, STANDARD_CHANGELOG_NAMESPACE, STANDARD_SNAPSHOT_NAMESPACE
-
Fields inherited from interface liquibase.plugin.Plugin
PRIORITY_DATABASE, PRIORITY_DEFAULT, PRIORITY_NOT_APPLICABLE, PRIORITY_SPECIALIZED
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSQLChange()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ChangeStatuscheckStatus(Database database)Validate that this change executed successfully against the given database.CheckSumgenerateCheckSum()Calculates the checksum based on the contained SQL.booleangenerateRollbackStatementsVolatile(Database database)Implementation delegates logic to theSqlGenerator.generateRollbackStatementsIsVolatile(Database)method on theSqlStatementobjects returned byChange.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.booleangenerateStatementsVolatile(Database database)Implementation delegates logic to theSqlGenerator.generateStatementsIsVolatile(Database)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database).StringgetDbms()StringgetEndDelimiter()Set the end delimiter used to split statements.StringgetSql()Return the raw SQL managed by this ChangeBooleanisIgnoreOriginalSplitStatements()Deprecated.BooleanisSplitStatements()Return if the SQL should be split into multiple statements before passing it to the database.booleanisSplitStatementsSet()Deprecated.To be removed when splitStatements is changed to be Boolean typeBooleanisStripComments()Return if comments should be stripped from the SQL before passing it to the database.protected StringnormalizeLineEndings(String string)InputStreamopenSqlStream()voidsetDbms(String dbms)voidsetEndDelimiter(String endDelimiter)Sets the end delimiter for splitting SQL statements.voidsetIgnoreOriginalSplitStatements(Boolean ignoreOriginalSplitStatements)Deprecated.voidsetOriginalSplitStatements(Boolean originalSplitStatements)Deprecated.voidsetSplitStatements(Boolean splitStatements)Set whether SQL should be split into multiple statements.voidsetSql(String sql)Set the raw SQL managed by this Change.voidsetStripComments(Boolean stripComments)Return true if comments should be stripped from the SQL before passing it to the database.booleansupports(Database database)Implementation delegates logic to theSqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database).ValidationErrorsvalidate(Database database)Implementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to theSqlGenerator.validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database).Warningswarn(Database database)Implementation delegates logic to theSqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database).-
Methods inherited from class liquibase.change.AbstractChange
createChangeMetaData, createChangeParameterMetadata, createDescriptionMetaData, createEmptyColumnConfig, createExampleValueMetaData, createInverses, createMustEqualExistingMetaData, createRequiredDatabasesMetaData, createSerializationTypeMetaData, createSinceMetaData, createSupportedDatabasesMetaData, customLoadLogic, equals, finishInitialization, generateRollbackStatements, getAffectedDatabaseObjects, getChangeSet, getDescription, getExcludedFieldFilters, getResourceAccessor, getSerializableFieldNamespace, getSerializableFields, getSerializableFieldType, getSerializableFieldValue, getSerializedObjectName, getSerializedObjectNamespace, hashCode, isInvalidProperty, load, modify, serialize, serializeValue, setChangeSet, setResourceAccessor, shouldExecuteChange, supportsRollback, toString
-
Methods inherited from class liquibase.AbstractExtensibleObject
clone, describe, get, get, get, getAttributes, getFieldValue, getObjectMetaData, getValuePath, has, set
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface liquibase.change.Change
getConfirmationMessage
-
Methods inherited from interface liquibase.ExtensibleObject
clone, describe, get, get, getAttributes, getObjectMetaData, getValuePath, has, set
-
-
-
-
Field Detail
-
encoding
protected String encoding
-
-
Method Detail
-
setOriginalSplitStatements
@Deprecated public void setOriginalSplitStatements(Boolean originalSplitStatements)
Deprecated.
-
setIgnoreOriginalSplitStatements
@Deprecated public void setIgnoreOriginalSplitStatements(Boolean ignoreOriginalSplitStatements)
Deprecated.isOriginalSplitStatements is used by checksums v8 calculator only to define splitStatements behavior
-
isIgnoreOriginalSplitStatements
@Deprecated public Boolean isIgnoreOriginalSplitStatements()
Deprecated.
-
openSqlStream
public InputStream openSqlStream() throws IOException
- Throws:
IOException
-
getDbms
public String getDbms()
- Specified by:
getDbmsin interfaceDbmsTargetedChange- 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:
setDbmsin interfaceDbmsTargetedChange
-
supports
public boolean supports(Database database)
Implementation delegates logic to theSqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database). If no or null SqlStatements are returned by generateStatements then this method returns true. IfAbstractChange.generateStatementsVolatile(liquibase.database.Database)returns true, we cannot call generateStatements and so assume true.- Specified by:
supportsin interfaceChange- Overrides:
supportsin classAbstractChange- Parameters:
database-- Returns:
- always true (in AbstractSQLChange)
-
warn
public Warnings warn(Database database)
Description copied from class:AbstractChangeImplementation delegates logic to theSqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)method on theSqlStatementobjects returned byChange.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:
warnin interfaceChange- Overrides:
warnin classAbstractChange
-
validate
public ValidationErrors validate(Database database)
Description copied from class:AbstractChangeImplementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to theSqlGenerator.validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)method on theSqlStatementobjects returned byChange.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:
validatein interfaceChange- Overrides:
validatein classAbstractChange
-
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).
-
isSplitStatementsSet
@Deprecated public boolean isSplitStatementsSet()
Deprecated.To be removed when splitStatements is changed to be Boolean type- Returns:
-
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)
Sets the end delimiter for splitting SQL statements. Set tonullto use the default delimiter.- Parameters:
endDelimiter- the end delimiter to set
-
generateCheckSum
public CheckSum generateCheckSum()
Calculates the checksum based on the contained SQL.- Specified by:
generateCheckSumin interfaceChange- Overrides:
generateCheckSumin classAbstractChange- See Also:
Change.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 theConnection.nativeSQL(java.lang.String)method if a connection is available.- Specified by:
generateStatementsin interfaceChange
-
generateStatementsVolatile
public boolean generateStatementsVolatile(Database database)
Description copied from class:AbstractChangeImplementation delegates logic to theSqlGenerator.generateStatementsIsVolatile(Database)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database). If zero or null SqlStatements are returned by generateStatements then this method returns false.- Specified by:
generateStatementsVolatilein interfaceChange- Overrides:
generateStatementsVolatilein classAbstractChange
-
generateRollbackStatementsVolatile
public boolean generateRollbackStatementsVolatile(Database database)
Description copied from class:AbstractChangeImplementation delegates logic to theSqlGenerator.generateRollbackStatementsIsVolatile(Database)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database)If no or null SqlStatements are returned by generateRollbackStatements then this method returns false.- Specified by:
generateRollbackStatementsVolatilein interfaceChange- Overrides:
generateRollbackStatementsVolatilein classAbstractChange
-
checkStatus
public ChangeStatus checkStatus(Database database)
Description copied from interface:ChangeValidate 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:
checkStatusin interfaceChange- Overrides:
checkStatusin classAbstractChange
-
-