CustomTaskChange在调用updateSQL时实际执行

时间:2014-06-06 11:35:12

标签: java liquibase

我在Liquibase中有一个CustomTaskChange(除了其他ChangeSet之外)。 我希望我的应用程序在实际执行之前显示所有ChangeSet的SQL。根据我的理解,updateSQL应预览SQL并不执行任何操作。然而,CustomTaskChange会立即执行。我打算在调用CustomTaskChange时忽略updateSQL

ChangeSet:

<changeSet id="2" author="clu">
    <comment>Print out 'helloworld'.</comment>
    <customChange class="path.to.HelloWorldUpdate">
</customChange>
</changeSet>

CustomTaskChange:

public class HelloWorldUpdate implements CustomTaskChange {
    @Override
public void execute(Database database) throws CustomChangeException {
    System.out.println("HELLO WORLD!!");
}
}

当呼叫updateSQL时,控制台会打印&#34; HELLO WORLD !!&#34;

这是一个错误吗?有解决方法吗?

谢谢!

[编辑]

1 个答案:

答案 0 :(得分:0)

CustomTaskChange的说明:

Interface to implement when creating a custom change that does not actually
generate SQL. If you are updating a database through SQL, 
implementing CustomSqlChange is preferred because the SQL can either 
be executed directly or saved to a text file for later use depending 
on the migration mode used.

所以请改用CustomSqlChange

generateStatements()方法中,您还可以在返回SqlStatement[]数组之前打印出sql。 println每次都会运行。但是,您创建的语句将不会应用于数据库,而是在您选择使用updateSQL运行时将其打印到std out。