1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.changelog.ChangeSet; |
4 | |
import liquibase.changelog.RanChangeSet; |
5 | |
import liquibase.database.Database; |
6 | |
import liquibase.exception.ValidationErrors; |
7 | |
import liquibase.sql.Sql; |
8 | |
import liquibase.sqlgenerator.SqlGenerator; |
9 | |
import liquibase.sqlgenerator.SqlGeneratorChain; |
10 | |
import liquibase.sqlgenerator.SqlGeneratorFactory; |
11 | |
import liquibase.statement.SqlStatement; |
12 | |
import liquibase.statement.core.UpdateChangeSetChecksumStatement; |
13 | |
import liquibase.statement.core.UpdateStatement; |
14 | |
|
15 | 10 | public class UpdateChangeSetChecksumGenerator extends AbstractSqlGenerator<UpdateChangeSetChecksumStatement> { |
16 | |
public ValidationErrors validate(UpdateChangeSetChecksumStatement statement, Database database, |
17 | |
SqlGeneratorChain sqlGeneratorChain) { |
18 | 0 | ValidationErrors validationErrors = new ValidationErrors(); |
19 | 0 | validationErrors.checkRequiredField("changeSet", statement.getChangeSet()); |
20 | |
|
21 | 0 | return validationErrors; |
22 | |
} |
23 | |
|
24 | |
public Sql[] generateSql(UpdateChangeSetChecksumStatement statement, Database database, |
25 | |
SqlGeneratorChain sqlGeneratorChain) { |
26 | 0 | ChangeSet changeSet = statement.getChangeSet(); |
27 | |
|
28 | 0 | SqlStatement runStatement = null; |
29 | 0 | runStatement = new UpdateStatement(database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName()) |
30 | |
.addNewColumnValue("MD5SUM", changeSet.generateCheckSum().toString()) |
31 | |
.setWhereClause("ID=? AND AUTHOR=? AND FILENAME=?") |
32 | |
.addWhereParameters(changeSet.getId(), changeSet.getAuthor(), changeSet.getFilePath()); |
33 | |
|
34 | 0 | return SqlGeneratorFactory.getInstance().generateSql(runStatement, database); |
35 | |
} |
36 | |
} |