liquibase.change
Interface Change

All Known Implementing Classes:
AbstractChange, AbstractSQLChange, AddAutoIncrementChange, AddColumnChange, AddDefaultValueChange, AddForeignKeyConstraintChange, AddLookupTableChange, AddNotNullConstraintChange, AddPrimaryKeyChange, AddUniqueConstraintChange, AlterSequenceChange, AnonymousChange, CreateIndexChange, CreateProcedureChange, CreateSequenceChange, CreateTableChange, CreateViewChange, CustomChangeWrapper, DeleteDataChange, DropAllForeignKeyConstraintsChange, DropColumnChange, DropDefaultValueChange, DropForeignKeyConstraintChange, DropIndexChange, DropNotNullConstraintChange, DropPrimaryKeyChange, DropSequenceChange, DropTableChange, DropUniqueConstraintChange, DropViewChange, EmptyChange, ExecuteShellCommandChange, InsertDataChange, LoadDataChange, LoadUpdateDataChange, MergeColumnChange, ModifyDataTypeChange, RawSQLChange, RenameColumnChange, RenameTableChange, RenameViewChange, SQLFileChange, StopChange, TagDatabaseChange, UpdateDataChange

public interface Change

Interface all changes (refactorings) implement.

How changes are constructed and run when reading changelogs:

  1. As the changelog handler gets to each element inside a changeSet, it passes the tag name to liquibase.change.ChangeFactory which looks through all the registered changes until it finds one with matching specified tag name
  2. The ChangeFactory then constructs a new instance of the change
  3. For each attribute in the XML node, reflection is used to call a corresponding set* method on the change class
  4. The correct generateStatements(*) method is called for the current database

To implement a new change:

  1. Create a new class that implements Change (normally extend AbstractChange)
  2. Implement the abstract generateStatements(*) methods which return the correct SQL calls for each database
  3. Implement the createMessage() method to create a descriptive message for logs and dialogs
  4. Implement the createNode() method to generate an XML element based on the values in this change
  5. Add the new class to the liquibase.change.ChangeFactory

Implementing automatic rollback support

The easiest way to allow automatic rollback support is by overriding the createInverses() method. If there are no corresponding inverse changes, you can override the generateRollbackStatements(*) and canRollBack() methods.

Notes for generated SQL:
Because migration and rollback scripts can be generated for execution at a different time, or against a different database, changes you implement cannot directly reference data in the database. For example, you cannot implement a change that selects all rows from a database and modifies them based on the primary keys you find because when the SQL is actually run, those rows may not longer exist and/or new rows may have been added.

We chose the name "change" over "refactoring" because changes will sometimes change functionality whereas true refactoring will not.

See Also:
ChangeFactory, Database

Method Summary
 CheckSum generateCheckSum()
          Calculates the checksum (currently MD5 hash) for the current configuration of this change.
 SqlStatement[] generateRollbackStatements(Database database)
          Generates the SQL statements required to roll back the change
 SqlStatement[] generateStatements(Database database)
          Generates the SQL statements required to run the change
 Set<DatabaseObject> getAffectedDatabaseObjects(Database database)
           
 ChangeMetaData getChangeMetaData()
           
 ChangeSet getChangeSet()
           
 String getConfirmationMessage()
           
 void init()
          This method will be called after the no arg constructor and all of the properties have been set to allow the task to do any heavy tasks or more importantly generate any exceptions to report to the user about the settings provided.
 boolean requiresUpdatedDatabaseMetadata(Database database)
          Does this change require access to the database metadata? If true, the change cannot be used in an updateSql-style command.
 void setChangeLogParameters(ChangeLogParameters changeLogParameters)
           
 void setChangeSet(ChangeSet changeSet)
           
 void setResourceAccessor(ResourceAccessor resourceAccessor)
          Sets the fileOpener that should be used for any file loading and resource finding for files that are provided by the user.
 boolean supports(Database database)
           
 boolean supportsRollback(Database database)
          Can this change be rolled back
 ValidationErrors validate(Database database)
           
 Warnings warn(Database database)
           
 

Method Detail

getChangeMetaData

ChangeMetaData getChangeMetaData()

getChangeSet

ChangeSet getChangeSet()

setChangeSet

void setChangeSet(ChangeSet changeSet)

setResourceAccessor

void setResourceAccessor(ResourceAccessor resourceAccessor)
Sets the fileOpener that should be used for any file loading and resource finding for files that are provided by the user.


init

void init()
          throws SetupException
This method will be called after the no arg constructor and all of the properties have been set to allow the task to do any heavy tasks or more importantly generate any exceptions to report to the user about the settings provided.

Throws:
SetupException

supports

boolean supports(Database database)

warn

Warnings warn(Database database)

validate

ValidationErrors validate(Database database)

getAffectedDatabaseObjects

Set<DatabaseObject> getAffectedDatabaseObjects(Database database)

generateCheckSum

CheckSum generateCheckSum()
Calculates the checksum (currently MD5 hash) for the current configuration of this change.


getConfirmationMessage

String getConfirmationMessage()
Returns:
Confirmation message to be displayed after the change is executed

generateStatements

SqlStatement[] generateStatements(Database database)
Generates the SQL statements required to run the change

Parameters:
database - databasethe target Database associated to this change's statements
Returns:
an array of Strings with the statements

supportsRollback

boolean supportsRollback(Database database)
Can this change be rolled back

Parameters:
database -
Returns:
true if rollback is supported, false otherwise

generateRollbackStatements

SqlStatement[] generateRollbackStatements(Database database)
                                          throws UnsupportedChangeException,
                                                 RollbackImpossibleException
Generates the SQL statements required to roll back the change

Parameters:
database - database databasethe target Database associated to this change's rollback statements
Returns:
an array of Strings with the rollback statements
Throws:
UnsupportedChangeException - if this change is not supported by the Database passed as argument
RollbackImpossibleException - if rollback is not supported for this change

requiresUpdatedDatabaseMetadata

boolean requiresUpdatedDatabaseMetadata(Database database)
Does this change require access to the database metadata? If true, the change cannot be used in an updateSql-style command.


setChangeLogParameters

void setChangeLogParameters(ChangeLogParameters changeLogParameters)
Parameters:
changeLogParameters -


Copyright © 2012 Liquibase.org. All Rights Reserved.