liquibase.change
Class AbstractChange

java.lang.Object
  extended by liquibase.change.AbstractChange
All Implemented Interfaces:
Change
Direct Known Subclasses:
AbstractSQLChange, AddAutoIncrementChange, AddColumnChange, AddDefaultValueChange, AddForeignKeyConstraintChange, AddLookupTableChange, AddNotNullConstraintChange, AddPrimaryKeyChange, AddUniqueConstraintChange, AlterSequenceChange, CreateIndexChange, CreateProcedureChange, CreateSequenceChange, CreateTableChange, CreateViewChange, CustomChangeWrapper, DeleteDataChange, DropAllForeignKeyConstraintsChange, DropColumnChange, DropDefaultValueChange, DropForeignKeyConstraintChange, DropIndexChange, DropNotNullConstraintChange, DropPrimaryKeyChange, DropSequenceChange, DropTableChange, DropUniqueConstraintChange, DropViewChange, EmptyChange, ExecuteShellCommandChange, InsertDataChange, LoadDataChange, MergeColumnChange, ModifyColumnChange, RenameColumnChange, RenameTableChange, RenameViewChange, StopChange, TagDatabaseChange, UpdateDataChange

public abstract class AbstractChange
extends java.lang.Object
implements Change

Standard superclass for Changes to implement. This is a skeletal implementation, as defined in Effective Java#16.

See Also:
Change

Field Summary
protected  java.util.logging.Logger log
           
 
Constructor Summary
protected AbstractChange(java.lang.String tagName, java.lang.String changeName)
          Constructor with tag name and name
 
Method Summary
 boolean canRollBack()
          Can this change be rolled back
protected  Change[] createInverses()
           
 void executeRollbackStatements(Database database, java.util.List<SqlVisitor> sqlVisitors)
          Rolls back the statements in this change against the Database passed as argument
 void executeStatements(Database database, java.util.List<SqlVisitor> sqlVisitors)
          Executes the statements in this change against the database passed in the argument
 SqlStatement[] generateRollbackStatements(Database database)
          Generates the SQL statements required to roll back the change
 java.lang.String getChangeName()
          Returns the name of this change
 ChangeSet getChangeSet()
           
 FileOpener getFileOpener()
          Returns the FileOpen as provided by the creating ChangeLog.
 java.lang.String getMD5Sum()
          Calculates the MD5 hash for the string representation of the XML element of this change
 java.lang.String getTagName()
          Returns the tag name of this change
 void saveRollbackStatement(Database database, java.util.List<SqlVisitor> sqlVisitors, java.io.Writer writer)
          Outputs the statements necessary to roll back this change
 void saveStatements(Database database, java.util.List<SqlVisitor> sqlVisitors, java.io.Writer writer)
          Outputs the SQL statements generated by this change
 void setChangeSet(ChangeSet changeSet)
           
 void setFileOpener(FileOpener fileOpener)
          Default implementation that stores the file opener provided when the Change was created.
 void setUp()
          Most Changes don't need to do any setup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface liquibase.change.Change
createNode, generateStatements, getAffectedDatabaseObjects, getConfirmationMessage, validate
 

Field Detail

log

protected java.util.logging.Logger log
Constructor Detail

AbstractChange

protected AbstractChange(java.lang.String tagName,
                         java.lang.String changeName)
Constructor with tag name and name

Parameters:
tagName - the tag name for this change
changeName - the name for this change
Method Detail

getChangeSet

public ChangeSet getChangeSet()
Specified by:
getChangeSet in interface Change

setChangeSet

public void setChangeSet(ChangeSet changeSet)
Specified by:
setChangeSet in interface Change

getChangeName

public java.lang.String getChangeName()
Description copied from interface: Change
Returns the name of this change

Specified by:
getChangeName in interface Change
Returns:
the name of the change
See Also:
Change.getChangeName()

getTagName

public java.lang.String getTagName()
Description copied from interface: Change
Returns the tag name of this change

Specified by:
getTagName in interface Change
Returns:
the tag name of the change
See Also:
Change.getTagName()

executeStatements

public void executeStatements(Database database,
                              java.util.List<SqlVisitor> sqlVisitors)
                       throws JDBCException,
                              UnsupportedChangeException
Description copied from interface: Change
Executes the statements in this change against the database passed in the argument

Specified by:
executeStatements in interface Change
Parameters:
database - the reference to the target Database to which the statements are executed
Throws:
JDBCException - if there were problems executing the statements
UnsupportedChangeException - if this change is not supported by the Database passed as argument
See Also:
Change.executeStatements(liquibase.database.Database, List sqlVisitors)

saveStatements

public void saveStatements(Database database,
                           java.util.List<SqlVisitor> sqlVisitors,
                           java.io.Writer writer)
                    throws java.io.IOException,
                           UnsupportedChangeException,
                           StatementNotSupportedOnDatabaseException
Description copied from interface: Change
Outputs the SQL statements generated by this change

Specified by:
saveStatements in interface Change
Parameters:
database - the target Database associated to this change's statements
writer - the target Writer to which the statements are appended
Throws:
java.io.IOException - if there were problems appending the statements to the writer
UnsupportedChangeException - if this change is not supported by the Database passed as argument
StatementNotSupportedOnDatabaseException
See Also:
Change.saveStatements(liquibase.database.Database, List sqlVisitors, java.io.Writer)

executeRollbackStatements

public void executeRollbackStatements(Database database,
                                      java.util.List<SqlVisitor> sqlVisitors)
                               throws JDBCException,
                                      UnsupportedChangeException,
                                      RollbackImpossibleException
Description copied from interface: Change
Rolls back the statements in this change against the Database passed as argument

Specified by:
executeRollbackStatements in interface Change
Parameters:
database - the target Database associated to this change's rollback statements
Throws:
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
See Also:
Change.executeRollbackStatements(liquibase.database.Database, List sqlVisitor)

saveRollbackStatement

public void saveRollbackStatement(Database database,
                                  java.util.List<SqlVisitor> sqlVisitors,
                                  java.io.Writer writer)
                           throws java.io.IOException,
                                  UnsupportedChangeException,
                                  RollbackImpossibleException,
                                  StatementNotSupportedOnDatabaseException
Description copied from interface: Change
Outputs the statements necessary to roll back this change

Specified by:
saveRollbackStatement in interface 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
Throws:
java.io.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
StatementNotSupportedOnDatabaseException
See Also:
Change.saveRollbackStatement(liquibase.database.Database, List sqlVisitor, java.io.Writer)

generateRollbackStatements

public SqlStatement[] generateRollbackStatements(Database database)
                                          throws UnsupportedChangeException,
                                                 RollbackImpossibleException
Description copied from interface: Change
Generates the SQL statements required to roll back the change

Specified by:
generateRollbackStatements in interface 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
See Also:
Change.generateRollbackStatements(liquibase.database.Database)

canRollBack

public boolean canRollBack()
Description copied from interface: Change
Can this change be rolled back

Specified by:
canRollBack in interface Change
Returns:
true if rollback is supported, false otherwise
See Also:
Change.canRollBack()

getMD5Sum

public java.lang.String getMD5Sum()
Description copied from interface: Change
Calculates the MD5 hash for the string representation of the XML element of this change

Specified by:
getMD5Sum in interface Change
Returns:
the MD5 hash
See Also:
Change.getMD5Sum()

createInverses

protected Change[] createInverses()

setFileOpener

public void setFileOpener(FileOpener fileOpener)
Default implementation that stores the file opener provided when the Change was created.

Specified by:
setFileOpener in interface Change

getFileOpener

public FileOpener getFileOpener()
Returns the FileOpen as provided by the creating ChangeLog.

Returns:
The file opener

setUp

public void setUp()
           throws SetupException
Most Changes don't need to do any setup. This implements a no-op

Specified by:
setUp in interface Change
Throws:
SetupException