1 | |
package liquibase.integration.ant; |
2 | |
|
3 | |
import liquibase.Liquibase; |
4 | |
import liquibase.util.ui.UIFactory; |
5 | |
import org.apache.tools.ant.BuildException; |
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | 0 | public class DatabaseUpdateTestingRollbackTask extends BaseLiquibaseTask { |
11 | 0 | private boolean dropFirst = false; |
12 | |
|
13 | |
public boolean isDropFirst() { |
14 | 0 | return dropFirst; |
15 | |
} |
16 | |
|
17 | |
public void setDropFirst(boolean dropFirst) { |
18 | 0 | this.dropFirst = dropFirst; |
19 | 0 | } |
20 | |
|
21 | |
@Override |
22 | |
public void execute() throws BuildException { |
23 | 0 | if (!shouldRun()) { |
24 | 0 | return; |
25 | |
} |
26 | |
|
27 | 0 | super.execute(); |
28 | |
|
29 | 0 | Liquibase liquibase = null; |
30 | |
try { |
31 | 0 | liquibase = createLiquibase(); |
32 | |
|
33 | 0 | if (isPromptOnNonLocalDatabase() && !liquibase.isSafeToRunMigration() |
34 | |
&& UIFactory.getInstance().getFacade().promptForNonLocalDatabase(liquibase.getDatabase())) { |
35 | 0 | throw new BuildException("Chose not to run against non-production database"); |
36 | |
} |
37 | |
|
38 | 0 | if (isDropFirst()) { |
39 | 0 | liquibase.dropAll(); |
40 | |
} |
41 | |
|
42 | 0 | liquibase.updateTestingRollback(getContexts()); |
43 | |
|
44 | 0 | } catch (Exception e) { |
45 | 0 | throw new BuildException(e); |
46 | |
} finally { |
47 | 0 | closeDatabase(liquibase); |
48 | 0 | } |
49 | 0 | } |
50 | |
} |