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 class
AbstractSQLChange.NormalizingStream
-
Nested classes/interfaces inherited from interface liquibase.serializer.LiquibaseSerializable
LiquibaseSerializable.SerializationType
-
-
Field Summary
Fields Modifier and Type Field Description protected String
encoding
-
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 protected
AbstractSQLChange()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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 theSqlGenerator.generateRollbackStatementsIsVolatile(Database)
method on theSqlStatement
objects 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.boolean
generateStatementsVolatile(Database database)
Implementation delegates logic to theSqlGenerator.generateStatementsIsVolatile(Database)
method on theSqlStatement
objects returned byChange.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 ChangeBoolean
isIgnoreOriginalSplitStatements()
Deprecated.Boolean
isSplitStatements()
Return if the SQL should be split into multiple statements before passing it to the database.boolean
isSplitStatementsSet()
Deprecated.To be removed when splitStatements is changed to be Boolean typeBoolean
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)
Sets the end delimiter for splitting SQL statements.void
setIgnoreOriginalSplitStatements(Boolean ignoreOriginalSplitStatements)
Deprecated.void
setOriginalSplitStatements(Boolean originalSplitStatements)
Deprecated.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 theSqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
.ValidationErrors
validate(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 theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
.Warnings
warn(Database database)
Implementation delegates logic to theSqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
.-
Methods inherited from class liquibase.change.AbstractChange
createAlternateParameterNames, 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:
getDbms
in 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:
setDbms
in interfaceDbmsTargetedChange
-
supports
public boolean supports(Database database)
Implementation delegates logic to theSqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database)
method on theSqlStatement
objects 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:
supports
in interfaceChange
- Overrides:
supports
in classAbstractChange
- Parameters:
database
-- Returns:
- always true (in AbstractSQLChange)
-
warn
public Warnings warn(Database database)
Description copied from class:AbstractChange
Implementation delegates logic to theSqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)
method on theSqlStatement
objects 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:
warn
in interfaceChange
- Overrides:
warn
in classAbstractChange
-
validate
public ValidationErrors validate(Database database)
Description copied from class:AbstractChange
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 theSqlStatement
objects 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:
validate
in interfaceChange
- Overrides:
validate
in 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 tonull
to 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:
generateCheckSum
in interfaceChange
- Overrides:
generateCheckSum
in 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:
generateStatements
in interfaceChange
-
generateStatementsVolatile
public boolean generateStatementsVolatile(Database database)
Description copied from class:AbstractChange
Implementation delegates logic to theSqlGenerator.generateStatementsIsVolatile(Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
. If zero or null SqlStatements are returned by generateStatements then this method returns false.- Specified by:
generateStatementsVolatile
in interfaceChange
- Overrides:
generateStatementsVolatile
in classAbstractChange
-
generateRollbackStatementsVolatile
public boolean generateRollbackStatementsVolatile(Database database)
Description copied from class:AbstractChange
Implementation delegates logic to theSqlGenerator.generateRollbackStatementsIsVolatile(Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
If no or null SqlStatements are returned by generateRollbackStatements then this method returns false.- Specified by:
generateRollbackStatementsVolatile
in interfaceChange
- Overrides:
generateRollbackStatementsVolatile
in classAbstractChange
-
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 interfaceChange
- Overrides:
checkStatus
in classAbstractChange
-
-