liquibase.change.Change Interface Reference

Inheritance diagram for liquibase.change.Change:
[legend]

List of all members.


Detailed Description

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

Definition at line 51 of file Change.java.


Public Member Functions

String getChangeName ()
 Returns the name of this change.
String getTagName ()
 Returns the tag name of this change.
void executeStatements (Database database) throws JDBCException, UnsupportedChangeException
 Executes the statements in this change against the database passed in the argument.
void saveStatements (Database database, Writer writer) throws IOException, UnsupportedChangeException, StatementNotSupportedOnDatabaseException
 Outputs the SQL statements generated by this change.
void executeRollbackStatements (Database database) throws JDBCException, UnsupportedChangeException, RollbackImpossibleException
 Rolls back the statements in this change against the Database passed as argument.
void saveRollbackStatement (Database database, Writer writer) throws IOException, UnsupportedChangeException, RollbackImpossibleException, StatementNotSupportedOnDatabaseException
 Outputs the statements necessary to roll back this change.
SqlStatement[] generateStatements (Database database) throws UnsupportedChangeException
 Generates the SQL statements required to run the change.
SqlStatement[] generateRollbackStatements (Database database) throws UnsupportedChangeException, RollbackImpossibleException
 Generates the SQL statements required to roll back the change.
boolean canRollBack ()
 Can this change be rolled back.
String getConfirmationMessage ()
 Confirmation message to be displayed after the change is executed.
Element createNode (Document currentChangeLogDOM)
 Creates an XML element (of type Element) of the change object, and adds it to the Document object passed as argument.
String getMD5Sum ()
 Calculates the MD5 hash for the string representation of the XML element of this change.
void setFileOpener (FileOpener fileOpener)
 Sets the fileOpener that should be used for any file loading and resource finding for files that are provided by the user.
void setUp () 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.

Member Function Documentation

String liquibase.change.Change.getChangeName (  ) 

Returns the name of this change.

Returns:
the name of the change

Implemented in liquibase.change.AbstractChange.

String liquibase.change.Change.getTagName (  ) 

Returns the tag name of this change.

Returns:
the tag name of the change

Implemented in liquibase.change.AbstractChange.

void liquibase.change.Change.executeStatements ( Database  database  )  throws JDBCException, UnsupportedChangeException

Executes the statements in this change against the database passed in the argument.

Parameters:
database the reference to the target Database to which the statements are executed
Exceptions:
JDBCException if there were problems executing the statements
UnsupportedChangeException if this change is not supported by the Database passed as argument

Implemented in liquibase.change.AbstractChange.

void liquibase.change.Change.saveStatements ( Database  database,
Writer  writer 
) throws IOException, UnsupportedChangeException, StatementNotSupportedOnDatabaseException

Outputs the SQL statements generated by this change.

Parameters:
database the target Database associated to this change's statements
writer the target Writer to which the statements are appended
Exceptions:
IOException if there were problems appending the statements to the writer
UnsupportedChangeException if this change is not supported by the Database passed as argument

Implemented in liquibase.change.AbstractChange.

void liquibase.change.Change.executeRollbackStatements ( Database  database  )  throws JDBCException, UnsupportedChangeException, RollbackImpossibleException

Rolls back the statements in this change against the Database passed as argument.

Parameters:
database the target Database associated to this change's rollback statements
Exceptions:
JDBCException if there were problems executing the rollback statements
UnsupportedChangeException if this change is not supported by the Database passed as argument
RollbackImpossibleException if rollback is not supported for this change

Implemented in liquibase.change.AbstractChange.

void liquibase.change.Change.saveRollbackStatement ( Database  database,
Writer  writer 
) throws IOException, UnsupportedChangeException, RollbackImpossibleException, StatementNotSupportedOnDatabaseException

Outputs the statements necessary to roll back this change.

Parameters:
database the target Database associated to this change's rollback statements
writer writer the target Writer to which the rollback statements are appended
Exceptions:
IOException if there were problems appending the rollback statements to the writer
UnsupportedChangeException if this change is not supported by the Database passed as argument
RollbackImpossibleException if rollback is not supported for this change

Implemented in liquibase.change.AbstractChange.

SqlStatement [] liquibase.change.Change.generateStatements ( Database  database  )  throws UnsupportedChangeException

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
Exceptions:
UnsupportedChangeException if this change is not supported by the Database passed as argument

Implemented in liquibase.change.AbstractSQLChange, liquibase.change.AddAutoIncrementChange, liquibase.change.AddColumnChange, liquibase.change.AddDefaultValueChange, liquibase.change.AddForeignKeyConstraintChange, liquibase.change.AddLookupTableChange, liquibase.change.AddNotNullConstraintChange, liquibase.change.AddPrimaryKeyChange, liquibase.change.AddUniqueConstraintChange, liquibase.change.AlterSequenceChange, liquibase.change.CreateIndexChange, liquibase.change.CreateSequenceChange, liquibase.change.CreateTableChange, liquibase.change.CreateViewChange, liquibase.change.custom.CustomChangeWrapper, liquibase.change.DropColumnChange, liquibase.change.DropDefaultValueChange, liquibase.change.DropForeignKeyConstraintChange, liquibase.change.DropIndexChange, liquibase.change.DropNotNullConstraintChange, liquibase.change.DropPrimaryKeyChange, liquibase.change.DropSequenceChange, liquibase.change.DropTableChange, liquibase.change.DropUniqueConstraintChange, liquibase.change.DropViewChange, liquibase.change.ExecuteShellCommandChange, liquibase.change.InsertDataChange, liquibase.change.MergeColumnChange, liquibase.change.ModifyColumnChange, liquibase.change.RenameColumnChange, liquibase.change.RenameTableChange, and liquibase.change.RenameViewChange.

Referenced by liquibase.change.AbstractChange.executeStatements(), and liquibase.change.AbstractChange.saveStatements().

SqlStatement [] liquibase.change.Change.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
Exceptions:
UnsupportedChangeException if this change is not supported by the Database passed as argument
RollbackImpossibleException if rollback is not supported for this change

Implemented in liquibase.change.AbstractChange, and liquibase.change.custom.CustomChangeWrapper.

boolean liquibase.change.Change.canRollBack (  ) 

Can this change be rolled back.

Returns:
true if rollback is supported, false otherwise

Implemented in liquibase.change.AbstractChange, and liquibase.change.custom.CustomChangeWrapper.

String liquibase.change.Change.getConfirmationMessage (  ) 

Element liquibase.change.Change.createNode ( Document  currentChangeLogDOM  ) 

Creates an XML element (of type Element) of the change object, and adds it to the Document object passed as argument.

Parameters:
currentChangeLogDOM the current Document where this element is being added
Returns:
the Element object created

Implemented in liquibase.change.AddAutoIncrementChange, liquibase.change.AddColumnChange, liquibase.change.AddDefaultValueChange, liquibase.change.AddForeignKeyConstraintChange, liquibase.change.AddLookupTableChange, liquibase.change.AddNotNullConstraintChange, liquibase.change.AddPrimaryKeyChange, liquibase.change.AddUniqueConstraintChange, liquibase.change.AlterSequenceChange, liquibase.change.CreateIndexChange, liquibase.change.CreateSequenceChange, liquibase.change.CreateTableChange, liquibase.change.CreateViewChange, liquibase.change.custom.CustomChangeWrapper, liquibase.change.DropColumnChange, liquibase.change.DropDefaultValueChange, liquibase.change.DropForeignKeyConstraintChange, liquibase.change.DropIndexChange, liquibase.change.DropNotNullConstraintChange, liquibase.change.DropPrimaryKeyChange, liquibase.change.DropSequenceChange, liquibase.change.DropTableChange, liquibase.change.DropUniqueConstraintChange, liquibase.change.DropViewChange, liquibase.change.ExecuteShellCommandChange, liquibase.change.InsertDataChange, liquibase.change.MergeColumnChange, liquibase.change.ModifyColumnChange, liquibase.change.RawSQLChange, liquibase.change.RenameColumnChange, liquibase.change.RenameTableChange, liquibase.change.RenameViewChange, and liquibase.change.SQLFileChange.

Referenced by liquibase.change.AbstractChange.getMD5Sum().

String liquibase.change.Change.getMD5Sum (  ) 

Calculates the MD5 hash for the string representation of the XML element of this change.

Returns:
the MD5 hash

Implemented in liquibase.change.AbstractChange, and liquibase.change.SQLFileChange.


The documentation for this interface was generated from the following file:

doxygen