public abstract class AbstractChange extends Object implements Change
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.LiquibaseSerializable.SerializationType
GENERIC_CHANGELOG_EXTENSION_NAMESPACE, GENERIC_SNAPSHOT_EXTENSION_NAMESPACE, STANDARD_CHANGELOG_NAMESPACE, STANDARD_SNAPSHOT_NAMESPACE
Constructor and Description |
---|
AbstractChange() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
generateStatements, getConfirmationMessage
public void finishInitialization() throws SetupException
finishInitialization
in interface Change
SetupException
public ChangeMetaData createChangeMetaData()
DatabaseChange
annotation
and calls out to createChangeParameterMetadata(String)
for each property.createChangeMetaData
in interface Change
UnexpectedLiquibaseException
- if no @DatabaseChange annotation on this Change classprotected boolean isInvalidProperty(PropertyDescriptor property)
protected ChangeParameterMetaData createChangeParameterMetadata(String parameterName)
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.UnexpectedLiquibaseException
- if the passed parameter does not existprotected String createSinceMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
ChangeParameterMetaData
"since" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default.protected String createDescriptionMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
ChangeParameterMetaData
"description" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default.protected LiquibaseSerializable.SerializationType createSerializationTypeMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
ChangeParameterMetaData
"serializationType" value. Uses the value on the DatabaseChangeProperty annotation or returns SerializationType
.NAMED_FIELD as a default.protected String createMustEqualExistingMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
ChangeParameterMetaData
"mustEqual" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default.protected Map<String,Object> createExampleValueMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
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.protected String[] createRequiredDatabasesMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
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 Statementsprotected String[] createSupportedDatabasesMetaData(String parameterName, DatabaseChangeProperty changePropertyAnnotation)
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 Statementspublic ChangeSet getChangeSet()
getChangeSet
in interface Change
public void setChangeSet(ChangeSet changeSet)
setChangeSet
in interface Change
public boolean generateStatementsVolatile(Database database)
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.generateStatementsVolatile
in interface Change
public boolean generateRollbackStatementsVolatile(Database database)
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.generateRollbackStatementsVolatile
in interface Change
public boolean supports(Database database)
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.public Warnings warn(Database database)
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.public ValidationErrors validate(Database database)
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 errorspublic ChangeStatus checkStatus(Database database)
Change
checkStatus
in interface Change
public SqlStatement[] generateRollbackStatements(Database database) throws RollbackImpossibleException
createInverses()
.generateRollbackStatements
in interface Change
RollbackImpossibleException
- if rollback is not supported for this changepublic boolean supportsRollback(Database database)
createInverses()
returns a non-null value.supportsRollback
in interface Change
public CheckSum generateCheckSum()
StringChangeLogSerializer
generateCheckSum
in interface Change
protected Change[] createInverses()
generateRollbackStatements(liquibase.database.Database)
is overridden, this method may not be called.public void setResourceAccessor(ResourceAccessor resourceAccessor)
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.setResourceAccessor
in interface Change
public ResourceAccessor getResourceAccessor()
public Set<DatabaseObject> getAffectedDatabaseObjects(Database database)
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 databasegetAffectedDatabaseObjects
in interface Change
public Set<String> getSerializableFields()
getSerializableFields
in interface LiquibaseSerializable
public Object getSerializableFieldValue(String field)
getSerializableFieldValue
in interface LiquibaseSerializable
public String getSerializedObjectName()
getSerializedObjectName
in interface LiquibaseSerializable
public LiquibaseSerializable.SerializationType getSerializableFieldType(String field)
getSerializableFieldType
in interface LiquibaseSerializable
public String getSerializedObjectNamespace()
getSerializedObjectNamespace
in interface LiquibaseSerializable
public String getSerializableFieldNamespace(String field)
getSerializableFieldNamespace
in interface LiquibaseSerializable
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException
load
in interface LiquibaseSerializable
ParsedNodeException
protected ColumnConfig createEmptyColumnConfig(Class collectionType) throws InstantiationException, IllegalAccessException
protected void customLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException
ParsedNodeException
public ParsedNode serialize() throws ParsedNodeException
serialize
in interface LiquibaseSerializable
ParsedNodeException
protected Object serializeValue(Object value) throws ParsedNodeException
ParsedNodeException
public String getDescription()
Change
getDescription
in interface Change
Copyright © 2016 Liquibase.org. All rights reserved.