liquibase.change.custom
Class CustomChangeWrapper

java.lang.Object
  extended by liquibase.change.AbstractChange
      extended by liquibase.change.custom.CustomChangeWrapper
All Implemented Interfaces:
Change, LiquibaseSerializable

public class CustomChangeWrapper
extends AbstractChange

Adapts CustomChange implementations to the standard change system used by Liquibase. Custom change implementations should implement CustomSqlChange or CustomTaskChange

See Also:
CustomSqlChange, CustomTaskChange

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
CustomChangeWrapper()
           
 
Method Summary
 void customLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor)
           
 SqlStatement[] generateRollbackStatements(Database database)
          Finishes configuring the CustomChange based on the values passed to setParam(String, String) then calls CustomSqlRollback.generateRollbackStatements(liquibase.database.Database) or CustomTaskRollback.rollback(liquibase.database.Database) depending on the CustomChange implementation.
 SqlStatement[] generateStatements(Database database)
          Finishes configuring the CustomChange based on the values passed to setParam(String, String) then calls CustomSqlChange.generateStatements(liquibase.database.Database) or CustomTaskChange.execute(liquibase.database.Database) depending on the CustomChange implementation.
 boolean generateStatementsVolatile(Database database)
          Implementation delegates logic to the SqlGenerator.generateStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database).
 ClassLoader getClassLoader()
          Returns the classloader to use when creating the CustomChange instance in setClass(String).
 String getClassName()
          Return the name of the custom class set in setClass(String)
 String getConfirmationMessage()
          Return the customChange's CustomChange.getConfirmationMessage() message as the Change's message.
 CustomChange getCustomChange()
          Return the CustomChange instance created by the call to setClass(String).
 SortedSet<String> getParams()
          Returns the parameters set by setParam(String, String).
 String getParamValue(String key)
          Get the value of a parameter set by setParam(String, String).
 Set<String> getSerializableFields()
          Returns the fields on this change that are serializable.
 LiquibaseSerializable.SerializationType getSerializableFieldType(String field)
           
 Object getSerializableFieldValue(String field)
           
 String getSerializedObjectNamespace()
           
 void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor)
           
 CustomChangeWrapper setClass(String className)
          Specify the name of the class to use as the CustomChange.
 void setClassLoader(ClassLoader classLoader)
           
 void setParam(String name, String value)
          Specify a parameter on the CustomChange object to set before executing Change.generateStatements(liquibase.database.Database) or generateRollbackStatements(liquibase.database.Database) on it.
 boolean supportsRollback(Database database)
          Returns true if the customChange supports rolling back.
 ValidationErrors validate(Database database)
          Call the CustomChange.validate(liquibase.database.Database) method and return the result.
 Warnings warn(Database database)
          Required for the Change interface, but not supported by CustomChanges.
 
Methods inherited from class liquibase.change.AbstractChange
checkStatus, createChangeMetaData, createChangeParameterMetadata, createDescriptionMetaData, createExampleValueMetaData, createInverses, createMustEqualExistingMetaData, createRequiredDatabasesMetaData, createSerializationTypeMetaData, createSinceMetaData, createSupportedDatabasesMetaData, finishInitialization, generateCheckSum, generateRollbackStatementsVolatile, getAffectedDatabaseObjects, getChangeSet, getResourceAccessor, getSerializableFieldNamespace, getSerializedObjectName, isInvalidProperty, serialize, serializeValue, setChangeSet, setResourceAccessor, supports, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CustomChangeWrapper

public CustomChangeWrapper()
Method Detail

generateStatementsVolatile

public boolean generateStatementsVolatile(Database database)
Description copied from class: AbstractChange
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
Overrides:
generateStatementsVolatile in class AbstractChange

getCustomChange

public CustomChange getCustomChange()
Return the CustomChange instance created by the call to setClass(String).


getClassLoader

public ClassLoader getClassLoader()
Returns the classloader to use when creating the CustomChange instance in setClass(String).


setClassLoader

public void setClassLoader(ClassLoader classLoader)

setClass

public CustomChangeWrapper setClass(String className)
                             throws CustomChangeException
Specify the name of the class to use as the CustomChange. This method instantiates the class using getClassLoader() or fallback methods and assigns it to getCustomChange(). setClassLoader(ClassLoader) must be called before this method. The passed class is constructed, but no parameters are set. They are set in Change.generateStatements(liquibase.database.Database)

Throws:
CustomChangeException

getClassName

public String getClassName()
Return the name of the custom class set in setClass(String)

Returns:

setParam

public void setParam(String name,
                     String value)
Specify a parameter on the CustomChange object to set before executing Change.generateStatements(liquibase.database.Database) or generateRollbackStatements(liquibase.database.Database) on it. The CustomChange class must have a set method for the given parameter. For example, to call setParam("lastName", "X") you must have a method setLastName(String val) on your class.


getParams

public SortedSet<String> getParams()
Returns the parameters set by setParam(String, String). If no parameters are set, an empty set will be returned


getParamValue

public String getParamValue(String key)
Get the value of a parameter set by setParam(String, String). If the parameter was not set, null will be returned.


validate

public ValidationErrors validate(Database database)
Call the CustomChange.validate(liquibase.database.Database) method and return the result.

Specified by:
validate in interface Change
Overrides:
validate in class AbstractChange

warn

public Warnings warn(Database database)
Required for the Change interface, but not supported by CustomChanges. Returns an empty Warnings object.

Specified by:
warn in interface Change
Overrides:
warn in class AbstractChange

generateStatements

public SqlStatement[] generateStatements(Database database)
Finishes configuring the CustomChange based on the values passed to setParam(String, String) then calls CustomSqlChange.generateStatements(liquibase.database.Database) or CustomTaskChange.execute(liquibase.database.Database) depending on the CustomChange implementation.

If the CustomChange returns a null SqlStatement array, this method returns an empty array. If a CustomTaskChange is being used, this method will return an empty array.


generateRollbackStatements

public SqlStatement[] generateRollbackStatements(Database database)
                                          throws RollbackImpossibleException
Finishes configuring the CustomChange based on the values passed to setParam(String, String) then calls CustomSqlRollback.generateRollbackStatements(liquibase.database.Database) or CustomTaskRollback.rollback(liquibase.database.Database) depending on the CustomChange implementation.

If the CustomChange returns a null SqlStatement array, this method returns an empty array. If a CustomTaskChange is being used, this method will return an empty array. Any RollbackImpossibleException exceptions thrown by the CustomChange will thrown by this method.

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

supportsRollback

public boolean supportsRollback(Database database)
Returns true if the customChange supports rolling back. generateRollbackStatements(liquibase.database.Database) may still trow a RollbackImpossibleException when it is actually exectued, even if this method returns true. Currently only checks if the customChange implements CustomSqlRollback

Specified by:
supportsRollback in interface Change
Overrides:
supportsRollback in class AbstractChange

getConfirmationMessage

public String getConfirmationMessage()
Return the customChange's CustomChange.getConfirmationMessage() message as the Change's message.


getSerializableFieldType

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

getSerializableFieldValue

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

getSerializableFields

public Set<String> getSerializableFields()
Description copied from class: AbstractChange
Returns the fields on this change that are serializable.

Specified by:
getSerializableFields in interface LiquibaseSerializable
Overrides:
getSerializableFields in class AbstractChange

getSerializedObjectNamespace

public String getSerializedObjectNamespace()
Specified by:
getSerializedObjectNamespace in interface LiquibaseSerializable
Overrides:
getSerializedObjectNamespace in class AbstractChange

load

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

customLoadLogic

public void customLoadLogic(ParsedNode parsedNode,
                            ResourceAccessor resourceAccessor)
                     throws ParsedNodeException
Overrides:
customLoadLogic in class AbstractChange
Throws:
ParsedNodeException


Copyright © 2015 Liquibase.org. All rights reserved.