Package liquibase.change
Class AbstractChange
java.lang.Object
liquibase.AbstractExtensibleObject
liquibase.plugin.AbstractPlugin
liquibase.change.AbstractChange
- All Implemented Interfaces:
Cloneable
,Change
,ExtensibleObject
,Plugin
,LiquibaseSerializable
- Direct Known Subclasses:
AbstractModifyDataChange
,AbstractSQLChange
,AbstractTableChange
,AddAutoIncrementChange
,AddColumnChange
,AddDefaultValueChange
,AddForeignKeyConstraintChange
,AddLookupTableChange
,AddNotNullConstraintChange
,AddPrimaryKeyChange
,AddUniqueConstraintChange
,AlterSequenceChange
,CreateIndexChange
,CreateProcedureChange
,CreateSequenceChange
,CreateTableChange
,CreateViewChange
,CustomChangeWrapper
,DropAllForeignKeyConstraintsChange
,DropColumnChange
,DropDefaultValueChange
,DropForeignKeyConstraintChange
,DropIndexChange
,DropNotNullConstraintChange
,DropPrimaryKeyChange
,DropProcedureChange
,DropSequenceChange
,DropTableChange
,DropUniqueConstraintChange
,DropViewChange
,EmptyChange
,ExecuteShellCommandChange
,InsertDataChange
,MergeColumnChange
,ModifyDataTypeChange
,OutputChange
,RenameColumnChange
,RenameSequenceChange
,RenameTableChange
,RenameViewChange
,SetColumnRemarksChange
,SetTableRemarksChange
,StopChange
,TagDatabaseChange
Standard superclass to simplify
Change
implementations. You can implement Change directly, this class is
purely for convenience but recommended.
By default, this base class relies on annotations such as DatabaseChange
and DatabaseChangeProperty
and delegating logic to the SqlGenerator
objects created to do the actual change work.
Place the @DatabaseChangeProperty annotations on the read "get" methods to control property metadata.-
Nested Class Summary
Nested classes/interfaces inherited from interface liquibase.serializer.LiquibaseSerializable
LiquibaseSerializable.SerializationType
-
Field Summary
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
-
Method Summary
Modifier and TypeMethodDescriptioncheckStatus
(Database database) Validate that this change executed successfully against the given database.protected String[]
createAlternateParameterNames
(DatabaseChangeProperty changePropertyAnnotation) Generate the ChangeMetaData for this class.protected ChangeParameterMetaData
createChangeParameterMetadata
(String parameterName) Called bycreateChangeMetaData()
to create metadata for a given parameter.protected String
createDescriptionMetaData
(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"description" value.protected ColumnConfig
createEmptyColumnConfig
(Class collectionType) createExampleValueMetaData
(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"example" value.protected Change[]
Create inverse changes that can roll back this change.protected String
createMustEqualExistingMetaData
(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"mustEqual" value.protected String[]
createRequiredDatabasesMetaData
(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"requiredDatabases" value.protected LiquibaseSerializable.SerializationType
createSerializationTypeMetaData
(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"serializationType" value.protected String
createSinceMetaData
(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"since" value.protected String[]
createSupportedDatabasesMetaData
(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"supportedDatabase" value.protected void
customLoadLogic
(ParsedNode parsedNode, ResourceAccessor resourceAccessor) boolean
Default implementation counts objects equal if their describe() methods return equal strings.void
Default implementation is a no-opImplementation generates checksum by serializing the change withStringChangeLogSerializer
generateRollbackStatements
(Database database) Implementation relies on value returned fromcreateInverses()
.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.boolean
generateStatementsVolatile
(Database database) Implementation delegates logic to theSqlGenerator.generateStatementsIsVolatile(Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
.getAffectedDatabaseObjects
(Database database) Implementation delegates logic to theSqlGeneratorFactory.getAffectedDatabaseObjects(liquibase.statement.SqlStatement, liquibase.database.Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
Returns empty set if change is not supported for the passed databaseReturns the changeSet this Change is part of.Short, scannable description for the DATABASECHANGELOG.DESCRIPTION columnString[]
getExcludedFieldFilters
(ChecksumVersion version) Deprecated.Returns the fields on this change that are serializable.getSerializableFieldType
(String field) getSerializableFieldValue
(String field) int
hashCode()
protected boolean
isInvalidProperty
(PropertyDescriptor property) void
load
(ParsedNode parsedNode, ResourceAccessor resourceAccessor) void
modify
(ChangeVisitor changeVisitor) protected Object
serializeValue
(Object value) void
setChangeSet
(ChangeSet changeSet) Sets the changeSet this Change is a part of.void
setResourceAccessor
(ResourceAccessor resourceAccessor) Sets theResourceAccessor
that should be used for any file and/or resource loading needed by this Change.boolean
shouldExecuteChange
(Database database) Return if this change should executeboolean
Implementation delegates logic to theSqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
.boolean
supportsRollback
(Database database) Implementation returns true ifcreateInverses()
returns a non-null value.toString()
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)
.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.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
generateStatements, getConfirmationMessage
Methods inherited from interface liquibase.ExtensibleObject
clone, describe, get, get, getAttributes, getObjectMetaData, getValuePath, has, set
-
Field Details
-
NODENAME_COLUMN
- See Also:
-
-
Constructor Details
-
AbstractChange
public AbstractChange()
-
-
Method Details
-
finishInitialization
Default implementation is a no-op- Specified by:
finishInitialization
in interfaceChange
- Throws:
SetupException
-
createChangeMetaData
Generate the ChangeMetaData for this class. Default implementation reads from the @DatabaseChange
annotation and calls out tocreateChangeParameterMetadata(String)
for each property.- Specified by:
createChangeMetaData
in interfaceChange
- Throws:
UnexpectedLiquibaseException
- if no @DatabaseChange annotation on this Change class
-
isInvalidProperty
-
createChangeParameterMetadata
Called bycreateChangeMetaData()
to create metadata for a given parameter. It finds the method that corresponds to the parameter and calls the corresponding create*MetaData methods such ascreateRequiredDatabasesMetaData(String, DatabaseChangeProperty)
to determine the correct values for the ChangeParameterMetaData fields.- Throws:
UnexpectedLiquibaseException
- if the passed parameter does not exist
-
createSinceMetaData
protected String createSinceMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"since" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default. -
createDescriptionMetaData
protected String createDescriptionMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"description" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default. -
createSerializationTypeMetaData
protected LiquibaseSerializable.SerializationType createSerializationTypeMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"serializationType" value. Uses the value on the DatabaseChangeProperty annotation or returnsLiquibaseSerializable.SerializationType.NAMED_FIELD
as a default. -
createMustEqualExistingMetaData
protected String createMustEqualExistingMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"mustEqual" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default. -
createExampleValueMetaData
protected Map<String,Object> createExampleValueMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"example" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default. Returns map with key=database short name, value=example. Use short-name "all" as the fallback. -
createRequiredDatabasesMetaData
protected String[] createRequiredDatabasesMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"requiredDatabases" value. Uses the value on the DatabaseChangeProperty annotation or returns an array containing the string "COMPUTE" as a default. "COMPUTE" will cause ChangeParameterMetaData to attempt to determine the required databases based on the generated Statements -
createSupportedDatabasesMetaData
protected String[] createSupportedDatabasesMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData
"supportedDatabase" value. Uses the value on the DatabaseChangeProperty annotation or returns an array containing the string "COMPUTE" as a default. "COMPUTE" will cause ChangeParameterMetaData to attempt to determine the required databases based on the generated Statements -
createAlternateParameterNames
-
getChangeSet
Returns the changeSet this Change is part of. Will return null if this instance was not constructed as part of a changelog file.- Specified by:
getChangeSet
in interfaceChange
-
setChangeSet
Sets the changeSet this Change is a part of. Called automatically by Liquibase during the changelog parsing process.- Specified by:
setChangeSet
in interfaceChange
-
generateStatementsVolatile
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
-
generateRollbackStatementsVolatile
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
-
supports
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. IfgenerateStatementsVolatile(liquibase.database.Database)
returns true, we cannot call generateStatements and so assume true. -
warn
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. -
validate
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 -
checkStatus
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
-
shouldExecuteChange
Return if this change should execute- Parameters:
database
- Database we are working on- Returns:
- boolean
-
generateRollbackStatements
public SqlStatement[] generateRollbackStatements(Database database) throws RollbackImpossibleException Implementation relies on value returned fromcreateInverses()
.- Specified by:
generateRollbackStatements
in interfaceChange
- Throws:
RollbackImpossibleException
- if rollback is not supported for this change
-
supportsRollback
Implementation returns true ifcreateInverses()
returns a non-null value.- Specified by:
supportsRollback
in interfaceChange
-
generateCheckSum
Implementation generates checksum by serializing the change withStringChangeLogSerializer
- Specified by:
generateCheckSum
in interfaceChange
-
getExcludedFieldFilters
-
createInverses
Create inverse changes that can roll back this change. This method is intended to be overridden by Change implementations that have a logical inverse operation. Default implementation returns null. IfgenerateRollbackStatements(liquibase.database.Database)
is overridden, this method may not be called.- Returns:
- Return null if there is no corresponding inverse and therefore automatic rollback is not possible. Return an empty array to have a no-op rollback.
- See Also:
-
getResourceAccessor
Deprecated. -
setResourceAccessor
Description copied from interface:Change
Sets theResourceAccessor
that should be used for any file and/or resource loading needed by this Change. Called automatically by Liquibase during the changelog parsing process.- Specified by:
setResourceAccessor
in interfaceChange
-
getAffectedDatabaseObjects
Implementation delegates logic to theSqlGeneratorFactory.getAffectedDatabaseObjects(liquibase.statement.SqlStatement, liquibase.database.Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
Returns empty set if change is not supported for the passed database- Specified by:
getAffectedDatabaseObjects
in interfaceChange
-
getSerializableFields
Returns the fields on this change that are serializable.- Specified by:
getSerializableFields
in interfaceLiquibaseSerializable
-
getSerializableFieldValue
- Specified by:
getSerializableFieldValue
in interfaceLiquibaseSerializable
-
getSerializedObjectName
- Specified by:
getSerializedObjectName
in interfaceLiquibaseSerializable
-
getSerializableFieldType
- Specified by:
getSerializableFieldType
in interfaceLiquibaseSerializable
-
getSerializedObjectNamespace
- Specified by:
getSerializedObjectNamespace
in interfaceLiquibaseSerializable
-
getSerializableFieldNamespace
- Specified by:
getSerializableFieldNamespace
in interfaceLiquibaseSerializable
-
toString
- Overrides:
toString
in classAbstractExtensibleObject
-
load
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException - Specified by:
load
in interfaceLiquibaseSerializable
- Throws:
ParsedNodeException
-
createEmptyColumnConfig
protected ColumnConfig createEmptyColumnConfig(Class collectionType) throws ReflectiveOperationException - Throws:
ReflectiveOperationException
-
customLoadLogic
protected void customLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException - Throws:
ParsedNodeException
-
serialize
- Specified by:
serialize
in interfaceLiquibaseSerializable
- Throws:
ParsedNodeException
-
serializeValue
- Throws:
ParsedNodeException
-
getDescription
Description copied from interface:Change
Short, scannable description for the DATABASECHANGELOG.DESCRIPTION column- Specified by:
getDescription
in interfaceChange
-
modify
- Specified by:
modify
in interfaceChange
- Throws:
ParsedNodeException
- if there is an error processing ChangeVisitor
-
equals
Description copied from class:AbstractExtensibleObject
Default implementation counts objects equal if their describe() methods return equal strings.- Overrides:
equals
in classAbstractExtensibleObject
-
hashCode
public int hashCode()- Overrides:
hashCode
in classAbstractExtensibleObject
-