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
public abstract class AbstractChange extends AbstractPlugin implements Change
Standard superclass to simplifyChange
implementations. You can implement Change directly, this class is purely for convenience but recommended. By default, this base class relies on annotations such asDatabaseChange
andDatabaseChangeProperty
and delegating logic to theSqlGenerator
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 Modifier and Type Field Description protected static String
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 Constructor Description AbstractChange()
-
Method Summary
-
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 Detail
-
NODENAME_COLUMN
protected static final String NODENAME_COLUMN
- See Also:
- Constant Field Values
-
-
Method Detail
-
finishInitialization
public void finishInitialization() throws SetupException
Default implementation is a no-op- Specified by:
finishInitialization
in interfaceChange
- Throws:
SetupException
-
createChangeMetaData
public ChangeMetaData 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
protected boolean isInvalidProperty(PropertyDescriptor property)
-
createChangeParameterMetadata
protected ChangeParameterMetaData createChangeParameterMetadata(String parameterName)
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
-
getChangeSet
public ChangeSet 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
public void setChangeSet(ChangeSet changeSet)
Sets the changeSet this Change is a part of. Called automatically by Liquibase during the changelog parsing process.- Specified by:
setChangeSet
in interfaceChange
-
generateStatementsVolatile
public boolean generateStatementsVolatile(Database database)
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
public 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.- Specified by:
generateRollbackStatementsVolatile
in interfaceChange
-
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. IfgenerateStatementsVolatile(liquibase.database.Database)
returns true, we cannot call generateStatements and so assume true.
-
warn
public 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)
. 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
public 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)
. 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
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
-
shouldExecuteChange
public boolean shouldExecuteChange(Database database)
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
public boolean supportsRollback(Database database)
Implementation returns true ifcreateInverses()
returns a non-null value.- Specified by:
supportsRollback
in interfaceChange
-
generateCheckSum
public CheckSum generateCheckSum()
Implementation generates checksum by serializing the change withStringChangeLogSerializer
- Specified by:
generateCheckSum
in interfaceChange
-
getExcludedFieldFilters
public String[] getExcludedFieldFilters(ChecksumVersion version)
-
createInverses
protected Change[] 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:
#supportsRollback
-
getResourceAccessor
public ResourceAccessor getResourceAccessor()
Deprecated.
-
setResourceAccessor
public void setResourceAccessor(ResourceAccessor resourceAccessor)
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
public Set<DatabaseObject> 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 database- Specified by:
getAffectedDatabaseObjects
in interfaceChange
-
getSerializableFields
public Set<String> getSerializableFields()
Returns the fields on this change that are serializable.- Specified by:
getSerializableFields
in interfaceLiquibaseSerializable
-
getSerializableFieldValue
public Object getSerializableFieldValue(String field)
- Specified by:
getSerializableFieldValue
in interfaceLiquibaseSerializable
-
getSerializedObjectName
public String getSerializedObjectName()
- Specified by:
getSerializedObjectName
in interfaceLiquibaseSerializable
-
getSerializableFieldType
public LiquibaseSerializable.SerializationType getSerializableFieldType(String field)
- Specified by:
getSerializableFieldType
in interfaceLiquibaseSerializable
-
getSerializedObjectNamespace
public String getSerializedObjectNamespace()
- Specified by:
getSerializedObjectNamespace
in interfaceLiquibaseSerializable
-
getSerializableFieldNamespace
public String getSerializableFieldNamespace(String field)
- Specified by:
getSerializableFieldNamespace
in interfaceLiquibaseSerializable
-
toString
public String 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
public ParsedNode serialize() throws ParsedNodeException
- Specified by:
serialize
in interfaceLiquibaseSerializable
- Throws:
ParsedNodeException
-
serializeValue
protected Object serializeValue(Object value) throws ParsedNodeException
- Throws:
ParsedNodeException
-
getDescription
public String getDescription()
Description copied from interface:Change
Short, scannable description for the DATABASECHANGELOG.DESCRIPTION column- Specified by:
getDescription
in interfaceChange
-
modify
public void modify(ChangeVisitor changeVisitor) throws ParsedNodeException
- Specified by:
modify
in interfaceChange
- Throws:
ParsedNodeException
- if there is an error processing ChangeVisitor
-
equals
public boolean equals(Object reference)
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
-
-