public abstract class AbstractChange extends java.lang.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() |
Modifier and Type | Method and Description |
---|---|
ChangeMetaData |
createChangeMetaData()
Generate the ChangeMetaData for this class.
|
protected ChangeParameterMetaData |
createChangeParameterMetadata(java.lang.String parameterName)
Called by
createChangeMetaData() to create metadata for a given parameter. |
protected java.lang.String |
createDescriptionMetaData(java.lang.String parameterName,
DatabaseChangeProperty changePropertyAnnotation)
Create the
ChangeParameterMetaData "description" value. |
protected java.lang.String |
createExampleValueMetaData(java.lang.String parameterName,
DatabaseChangeProperty changePropertyAnnotation)
Create the
ChangeParameterMetaData "example" value. |
protected Change[] |
createInverses()
Create inverse changes that can roll back this change.
|
protected java.lang.String |
createMustEqualExistingMetaData(java.lang.String parameterName,
DatabaseChangeProperty changePropertyAnnotation)
Create the
ChangeParameterMetaData "mustEqual" value. |
protected java.lang.String[] |
createRequiredDatabasesMetaData(java.lang.String parameterName,
DatabaseChangeProperty changePropertyAnnotation)
Create the
ChangeParameterMetaData "requiredDatabases" value. |
protected LiquibaseSerializable.SerializationType |
createSerializationTypeMetaData(java.lang.String parameterName,
DatabaseChangeProperty changePropertyAnnotation)
Create the
ChangeParameterMetaData "serializationType" value. |
protected java.lang.String |
createSinceMetaData(java.lang.String parameterName,
DatabaseChangeProperty changePropertyAnnotation)
Create the
ChangeParameterMetaData "since" value. |
protected java.lang.String[] |
createSupportedDatabasesMetaData(java.lang.String parameterName,
DatabaseChangeProperty changePropertyAnnotation)
Create the
ChangeParameterMetaData "supportedDatabase" value. |
void |
finishInitialization()
Default implementation is a no-op
|
CheckSum |
generateCheckSum()
Implementation generates checksum by serializing the change with
StringChangeLogSerializer |
SqlStatement[] |
generateRollbackStatements(Database database)
Implementation relies on value returned from
createInverses() . |
boolean |
generateRollbackStatementsVolatile(Database database)
Implementation delegates logic to the
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. |
boolean |
generateStatementsVolatile(Database database)
Implementation delegates logic to the
SqlGenerator.generateStatementsIsVolatile(Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database) . |
java.util.Set<DatabaseObject> |
getAffectedDatabaseObjects(Database database)
Implementation delegates logic to the
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 database |
ChangeSet |
getChangeSet()
Returns the changeSet this Change is part of.
|
ResourceAccessor |
getResourceAccessor() |
java.util.Set<java.lang.String> |
getSerializableFields()
Returns the fields on this change that are serializable.
|
LiquibaseSerializable.SerializationType |
getSerializableFieldType(java.lang.String field) |
java.lang.Object |
getSerializableFieldValue(java.lang.String field) |
java.lang.String |
getSerializedObjectName() |
java.lang.String |
getSerializedObjectNamespace() |
void |
setChangeSet(ChangeSet changeSet)
Sets the changeSet this Change is a part of.
|
void |
setResourceAccessor(ResourceAccessor resourceAccessor)
Sets the
ResourceAccessor that should be used for any file and/or resource loading needed by this Change. |
boolean |
supports(Database database)
Implementation delegates logic to the
SqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database) . |
boolean |
supportsRollback(Database database)
Implementation returns true if
createInverses() returns a non-null value. |
ValidationErrors |
validate(Database database)
Implementation checks the ChangeParameterMetaData for declared required fields
and also delegates logic to the
SqlGenerator.validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database) . |
Warnings |
warn(Database database)
Implementation delegates logic to the
SqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain) method on the SqlStatement objects returned by Change.generateStatements(liquibase.database.Database) . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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 ChangeParameterMetaData createChangeParameterMetadata(java.lang.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 java.lang.String createSinceMetaData(java.lang.String parameterName, DatabaseChangeProperty changePropertyAnnotation)
ChangeParameterMetaData
"since" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default.protected java.lang.String createDescriptionMetaData(java.lang.String parameterName, DatabaseChangeProperty changePropertyAnnotation)
ChangeParameterMetaData
"description" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default.protected LiquibaseSerializable.SerializationType createSerializationTypeMetaData(java.lang.String parameterName, DatabaseChangeProperty changePropertyAnnotation)
ChangeParameterMetaData
"serializationType" value. Uses the value on the DatabaseChangeProperty annotation or returns SerializationType
.NAMED_FIELD as a default.protected java.lang.String createMustEqualExistingMetaData(java.lang.String parameterName, DatabaseChangeProperty changePropertyAnnotation)
ChangeParameterMetaData
"mustEqual" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default.protected java.lang.String createExampleValueMetaData(java.lang.String parameterName, DatabaseChangeProperty changePropertyAnnotation)
ChangeParameterMetaData
"example" value. Uses the value on the DatabaseChangeProperty annotation or returns null as a default.protected java.lang.String[] createRequiredDatabasesMetaData(java.lang.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 java.lang.String[] createSupportedDatabasesMetaData(java.lang.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 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 java.util.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 java.util.Set<java.lang.String> getSerializableFields()
getSerializableFields
in interface LiquibaseSerializable
public java.lang.Object getSerializableFieldValue(java.lang.String field)
getSerializableFieldValue
in interface LiquibaseSerializable
public java.lang.String getSerializedObjectName()
getSerializedObjectName
in interface LiquibaseSerializable
public LiquibaseSerializable.SerializationType getSerializableFieldType(java.lang.String field)
getSerializableFieldType
in interface LiquibaseSerializable
public java.lang.String getSerializedObjectNamespace()
getSerializedObjectNamespace
in interface LiquibaseSerializable