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
FieldsFields inherited from interface liquibase.change.Change
EMPTY_CHANGE, SHOULD_EXECUTEFields inherited from interface liquibase.serializer.LiquibaseSerializable
GENERIC_CHANGELOG_EXTENSION_NAMESPACE, GENERIC_SNAPSHOT_EXTENSION_NAMESPACE, STANDARD_CHANGELOG_NAMESPACE, STANDARD_SNAPSHOT_NAMESPACEFields inherited from interface liquibase.plugin.Plugin
PRIORITY_DATABASE, PRIORITY_DEFAULT, PRIORITY_NOT_APPLICABLE, PRIORITY_SPECIALIZED -
Constructor Summary
Constructors -
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 ChangeParameterMetaDatacreateChangeParameterMetadata(String parameterName) Called bycreateChangeMetaData()to create metadata for a given parameter.protected StringcreateDescriptionMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData"description" value.protected ColumnConfigcreateEmptyColumnConfig(Class collectionType) createExampleValueMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData"example" value.protected Change[]Create inverse changes that can roll back this change.protected StringcreateMustEqualExistingMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData"mustEqual" value.protected String[]createRequiredDatabasesMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData"requiredDatabases" value.protected LiquibaseSerializable.SerializationTypecreateSerializationTypeMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData"serializationType" value.protected StringcreateSinceMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData"since" value.protected String[]createSupportedDatabasesMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation) Create theChangeParameterMetaData"supportedDatabase" value.protected voidcustomLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor) booleanDefault implementation counts objects equal if their describe() methods return equal strings.voidDefault implementation is a no-opImplementation generates checksum by serializing the change withStringChangeLogSerializergenerateRollbackStatements(Database database) Implementation relies on value returned fromcreateInverses().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.booleangenerateStatementsVolatile(Database database) Implementation delegates logic to theSqlGenerator.generateStatementsIsVolatile(Database)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database).getAffectedDatabaseObjects(Database database) Implementation delegates logic to theSqlGeneratorFactory.getAffectedDatabaseObjects(liquibase.statement.SqlStatement, liquibase.database.Database)method on theSqlStatementobjects 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) inthashCode()protected booleanisInvalidProperty(PropertyDescriptor property) voidload(ParsedNode parsedNode, ResourceAccessor resourceAccessor) voidmodify(ChangeVisitor changeVisitor) protected ObjectserializeValue(Object value) voidsetChangeSet(ChangeSet changeSet) Sets the changeSet this Change is a part of.voidsetResourceAccessor(ResourceAccessor resourceAccessor) Sets theResourceAccessorthat should be used for any file and/or resource loading needed by this Change.booleanshouldExecuteChange(Database database) Return if this change should executebooleanImplementation delegates logic to theSqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database).booleansupportsRollback(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 theSqlStatementobjects returned byChange.generateStatements(liquibase.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.AbstractExtensibleObject
clone, describe, get, get, get, getAttributes, getFieldValue, getObjectMetaData, getValuePath, has, setMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface liquibase.change.Change
generateStatements, getConfirmationMessage, shouldRunOnOsMethods 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:
finishInitializationin interfaceChange- Throws:
SetupException
-
createChangeMetaData
Generate the ChangeMetaData for this class. Default implementation reads from the @DatabaseChangeannotation and calls out tocreateChangeParameterMetadata(String)for each property.- Specified by:
createChangeMetaDatain 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_FIELDas 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:
getChangeSetin interfaceChange
-
setChangeSet
Sets the changeSet this Change is a part of. Called automatically by Liquibase during the changelog parsing process.- Specified by:
setChangeSetin interfaceChange
-
generateStatementsVolatile
Implementation 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
-
generateRollbackStatementsVolatile
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.- Specified by:
generateRollbackStatementsVolatilein interfaceChange
-
supports
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. 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 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. -
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 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 -
checkStatus
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
-
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:
generateRollbackStatementsin interfaceChange- Throws:
RollbackImpossibleException- if rollback is not supported for this change
-
supportsRollback
Implementation returns true ifcreateInverses()returns a non-null value.- Specified by:
supportsRollbackin interfaceChange
-
generateCheckSum
Implementation generates checksum by serializing the change withStringChangeLogSerializer- Specified by:
generateCheckSumin 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:ChangeSets theResourceAccessorthat 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:
setResourceAccessorin interfaceChange
-
getAffectedDatabaseObjects
Implementation delegates logic to theSqlGeneratorFactory.getAffectedDatabaseObjects(liquibase.statement.SqlStatement, liquibase.database.Database)method on theSqlStatementobjects returned byChange.generateStatements(liquibase.database.Database)Returns empty set if change is not supported for the passed database- Specified by:
getAffectedDatabaseObjectsin interfaceChange
-
getSerializableFields
Returns the fields on this change that are serializable.- Specified by:
getSerializableFieldsin interfaceLiquibaseSerializable
-
getSerializableFieldValue
- Specified by:
getSerializableFieldValuein interfaceLiquibaseSerializable
-
getSerializedObjectName
- Specified by:
getSerializedObjectNamein interfaceLiquibaseSerializable
-
getSerializableFieldType
- Specified by:
getSerializableFieldTypein interfaceLiquibaseSerializable
-
getSerializedObjectNamespace
- Specified by:
getSerializedObjectNamespacein interfaceLiquibaseSerializable
-
getSerializableFieldNamespace
- Specified by:
getSerializableFieldNamespacein interfaceLiquibaseSerializable
-
toString
- Overrides:
toStringin classAbstractExtensibleObject
-
load
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException - Specified by:
loadin 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:
serializein interfaceLiquibaseSerializable- Throws:
ParsedNodeException
-
serializeValue
- Throws:
ParsedNodeException
-
getDescription
Description copied from interface:ChangeShort, scannable description for the DATABASECHANGELOG.DESCRIPTION column- Specified by:
getDescriptionin interfaceChange
-
modify
- Specified by:
modifyin interfaceChange- Throws:
ParsedNodeException- if there is an error processing ChangeVisitor
-
equals
Description copied from class:AbstractExtensibleObjectDefault implementation counts objects equal if their describe() methods return equal strings.- Overrides:
equalsin classAbstractExtensibleObject
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractExtensibleObject
-