liquibase.change.core.DeleteDataChange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-core Show documentation
Show all versions of liquibase-core Show documentation
Liquibase is a tool for managing and executing database changes.
The newest version!
package liquibase.change.core;
import liquibase.change.ChangeMetaData;
import liquibase.change.ColumnConfig;
import liquibase.change.DatabaseChange;
import liquibase.database.Database;
import liquibase.parser.core.ParsedNode;
import liquibase.parser.core.ParsedNodeException;
import liquibase.resource.ResourceAccessor;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.DeleteStatement;
@DatabaseChange(name = "delete", description = "Deletes data from an existing table", priority = ChangeMetaData.PRIORITY_DEFAULT, appliesTo = "table")
public class DeleteDataChange extends AbstractModifyDataChange {
@Override
public SqlStatement[] generateStatements(Database database) {
DeleteStatement statement = new DeleteStatement(getCatalogName(), getSchemaName(), getTableName());
statement.setWhere(where);
for (ColumnConfig whereParam : whereParams) {
if (whereParam.getName() != null) {
statement.addWhereColumnName(whereParam.getName());
}
statement.addWhereParameter(whereParam.getValueObject());
}
return new SqlStatement[]{
statement
};
}
@Override
public String getConfirmationMessage() {
return "Data deleted from " + getTableName();
}
@Override
public String getSerializedObjectNamespace() {
return STANDARD_CHANGELOG_NAMESPACE;
}
@Override
protected void customLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
ParsedNode whereParams = parsedNode.getChild(null, "whereParams");
if (whereParams != null) {
for (ParsedNode param : whereParams.getChildren(null, "param")) {
ColumnConfig columnConfig = new ColumnConfig();
try {
columnConfig.load(param, resourceAccessor);
} catch (ParsedNodeException e) {
e.printStackTrace();
}
addWhereParam(columnConfig);
}
}
}
}