liquibase.change
Class AbstractChange

java.lang.Object
  extended by liquibase.change.AbstractChange
All Implemented Interfaces:
Change, LiquibaseSerializable
Direct Known Subclasses:
AbstractModifyDataChange, AbstractSQLChange, 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, LoadDataChange, MergeColumnChange, ModifyDataTypeChange, OutputChange, RenameColumnChange, RenameSequenceChange, RenameTableChange, RenameViewChange, SetColumnRemarksChange, SetTableRemarksChange, StopChange, TagDatabaseChange

public abstract class AbstractChange
extends Object
implements Change

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.serializer.LiquibaseSerializable
GENERIC_CHANGELOG_EXTENSION_NAMESPACE, GENERIC_SNAPSHOT_EXTENSION_NAMESPACE, STANDARD_CHANGELOG_NAMESPACE, STANDARD_SNAPSHOT_NAMESPACE
 
Constructor Summary
AbstractChange()
           
 
Method Summary
 ChangeStatus checkStatus(Database database)
          Validate that this change executed successfully against the given database.
 ChangeMetaData createChangeMetaData()
          Generate the ChangeMetaData for this class.
protected  ChangeParameterMetaData createChangeParameterMetadata(String parameterName)
          Called by createChangeMetaData() to create metadata for a given parameter.
protected  String createDescriptionMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
          Create the ChangeParameterMetaData "description" value.
protected  ColumnConfig createEmptyColumnConfig(Class collectionType)
           
protected  Map<String,Object> createExampleValueMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
          Create the ChangeParameterMetaData "example" value.
protected  Change[] createInverses()
          Create inverse changes that can roll back this change.
protected  String createMustEqualExistingMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
          Create the ChangeParameterMetaData "mustEqual" value.
protected  String[] createRequiredDatabasesMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
          Create the ChangeParameterMetaData "requiredDatabases" value.
protected  LiquibaseSerializable.SerializationType createSerializationTypeMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
          Create the ChangeParameterMetaData "serializationType" value.
protected  String createSinceMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
          Create the ChangeParameterMetaData "since" value.
protected  String[] createSupportedDatabasesMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
          Create the ChangeParameterMetaData "supportedDatabase" value.
protected  void customLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor)
           
 void finishInitialization()
          Default implementation is a no-op
 CheckSum generateCheckSum()
          Implementation generates checksum by serializing the change with StringChangeLogSerializer
 SqlStatement[] generateRollbackStatements(Database database)
          Implementation relies on value returned from createInverses().
 boolean generateRollbackStatementsVolatile(Database database)
          Implementation delegates logic to the SqlGenerator.generateRollbackStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.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 the SqlGenerator.generateStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database).
 Set<DatabaseObject> getAffectedDatabaseObjects(Database database)
          Implementation delegates logic to the SqlGeneratorFactory.getAffectedDatabaseObjects(liquibase.statement.SqlStatement, liquibase.database.Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database) Returns empty set if change is not supported for the passed database
 ChangeSet getChangeSet()
          Returns the changeSet this Change is part of.
 String getDescription()
          Short, scannable description for the DATABASECHANGELOG.DESCRIPTION column
 ResourceAccessor getResourceAccessor()
           
 String getSerializableFieldNamespace(String field)
           
 Set<String> getSerializableFields()
          Returns the fields on this change that are serializable.
 LiquibaseSerializable.SerializationType getSerializableFieldType(String field)
           
 Object getSerializableFieldValue(String field)
           
 String getSerializedObjectName()
           
 String getSerializedObjectNamespace()
           
protected  boolean isInvalidProperty(PropertyDescriptor property)
           
 void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor)
           
 ParsedNode serialize()
           
protected  Object serializeValue(Object value)
           
 void setChangeSet(ChangeSet changeSet)
          Sets the changeSet this Change is a part of.
 void setResourceAccessor(ResourceAccessor resourceAccessor)
          Sets the ResourceAccessor that should be used for any file and/or resource loading needed by this Change.
 boolean supports(Database database)
          Implementation delegates logic to the SqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database).
 boolean supportsRollback(Database database)
          Implementation returns true if createInverses() returns a non-null value.
 String toString()
           
 ValidationErrors validate(Database database)
          Implementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to the SqlGenerator.validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database).
 Warnings warn(Database database)
          Implementation delegates logic to the SqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface liquibase.change.Change
generateStatements, getConfirmationMessage
 

Constructor Detail

AbstractChange

public AbstractChange()
Method Detail

finishInitialization

public void finishInitialization()
                          throws SetupException
Default implementation is a no-op

Specified by:
finishInitialization in interface Change
Throws:
SetupException

createChangeMetaData

public ChangeMetaData createChangeMetaData()
Generate the ChangeMetaData for this class. Default implementation reads from the @DatabaseChange annotation and calls out to createChangeParameterMetadata(String) for each property.

Specified by:
createChangeMetaData in interface Change
Throws:
UnexpectedLiquibaseException - if no @DatabaseChange annotation on this Change class

isInvalidProperty

protected boolean isInvalidProperty(PropertyDescriptor property)

createChangeParameterMetadata

protected ChangeParameterMetaData createChangeParameterMetadata(String parameterName)
Called by createChangeMetaData() to create metadata for a given parameter. It finds the method that corresponds to the parameter and calls the corresponding create*MetaData methods such as createRequiredDatabasesMetaData(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 the ChangeParameterMetaData "since" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default.


createDescriptionMetaData

protected String createDescriptionMetaData(String parameterName,
                                           DatabaseChangeProperty changePropertyAnnotation)
Create the ChangeParameterMetaData "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 the ChangeParameterMetaData "serializationType" value. Uses the value on the DatabaseChangeProperty annotation or returns SerializationType.NAMED_FIELD as a default.


createMustEqualExistingMetaData

protected String createMustEqualExistingMetaData(String parameterName,
                                                 DatabaseChangeProperty changePropertyAnnotation)
Create the ChangeParameterMetaData "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 the ChangeParameterMetaData "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 the ChangeParameterMetaData "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 the ChangeParameterMetaData "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 interface Change

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 interface Change

generateStatementsVolatile

public boolean generateStatementsVolatile(Database database)
Implementation delegates logic to the SqlGenerator.generateStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database). If zero or null SqlStatements are returned by generateStatements then this method returns false.

Specified by:
generateStatementsVolatile in interface Change

generateRollbackStatementsVolatile

public boolean generateRollbackStatementsVolatile(Database database)
Implementation delegates logic to the SqlGenerator.generateRollbackStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database) If no or null SqlStatements are returned by generateRollbackStatements then this method returns false.

Specified by:
generateRollbackStatementsVolatile in interface Change

supports

public boolean supports(Database database)
Implementation delegates logic to the SqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database). If no or null SqlStatements are returned by generateStatements then this method returns true. If generateStatementsVolatile(liquibase.database.Database) returns true, we cannot call generateStatements and so assume true.

Specified by:
supports in interface Change

warn

public Warnings warn(Database database)
Implementation delegates logic to the SqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.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 interface Change

validate

public ValidationErrors validate(Database database)
Implementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to the SqlGenerator.validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.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 interface Change

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 interface Change

generateRollbackStatements

public SqlStatement[] generateRollbackStatements(Database database)
                                          throws RollbackImpossibleException
Implementation relies on value returned from createInverses().

Specified by:
generateRollbackStatements in interface Change
Throws:
RollbackImpossibleException - if rollback is not supported for this change

supportsRollback

public boolean supportsRollback(Database database)
Implementation returns true if createInverses() returns a non-null value.

Specified by:
supportsRollback in interface Change

generateCheckSum

public CheckSum generateCheckSum()
Implementation generates checksum by serializing the change with StringChangeLogSerializer

Specified by:
generateCheckSum in interface Change

createInverses

protected Change[] createInverses()
Create inverse changes that can roll back this change. This method is intended to be overriden by Change implementations that have a logical inverse operation. Default implementation returns null.

If generateRollbackStatements(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.

setResourceAccessor

public void setResourceAccessor(ResourceAccessor resourceAccessor)
Sets the ResourceAccessor 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 interface Change

getResourceAccessor

public ResourceAccessor getResourceAccessor()

getAffectedDatabaseObjects

public Set<DatabaseObject> getAffectedDatabaseObjects(Database database)
Implementation delegates logic to the SqlGeneratorFactory.getAffectedDatabaseObjects(liquibase.statement.SqlStatement, liquibase.database.Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database) Returns empty set if change is not supported for the passed database

Specified by:
getAffectedDatabaseObjects in interface Change

getSerializableFields

public Set<String> getSerializableFields()
Returns the fields on this change that are serializable.

Specified by:
getSerializableFields in interface LiquibaseSerializable

getSerializableFieldValue

public Object getSerializableFieldValue(String field)
Specified by:
getSerializableFieldValue in interface LiquibaseSerializable

getSerializedObjectName

public String getSerializedObjectName()
Specified by:
getSerializedObjectName in interface LiquibaseSerializable

getSerializableFieldType

public LiquibaseSerializable.SerializationType getSerializableFieldType(String field)
Specified by:
getSerializableFieldType in interface LiquibaseSerializable

getSerializedObjectNamespace

public String getSerializedObjectNamespace()
Specified by:
getSerializedObjectNamespace in interface LiquibaseSerializable

getSerializableFieldNamespace

public String getSerializableFieldNamespace(String field)
Specified by:
getSerializableFieldNamespace in interface LiquibaseSerializable

toString

public String toString()
Overrides:
toString in class Object

load

public void load(ParsedNode parsedNode,
                 ResourceAccessor resourceAccessor)
          throws ParsedNodeException
Specified by:
load in interface LiquibaseSerializable
Throws:
ParsedNodeException

createEmptyColumnConfig

protected ColumnConfig createEmptyColumnConfig(Class collectionType)
                                        throws InstantiationException,
                                               IllegalAccessException
Throws:
InstantiationException
IllegalAccessException

customLoadLogic

protected void customLoadLogic(ParsedNode parsedNode,
                               ResourceAccessor resourceAccessor)
                        throws ParsedNodeException
Throws:
ParsedNodeException

serialize

public ParsedNode serialize()
                     throws ParsedNodeException
Specified by:
serialize in interface LiquibaseSerializable
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 interface Change


Copyright © 2016 Liquibase.org. All rights reserved.