Browse files

Merge pull request #120 from jwcarman/master

CORE-1279: Generate Rollback Script File With SpringLiquibase
  • Loading branch information...
2 parents 790dd3f + 054fe68 commit 552501ac8bf8bb6d744a020fce040e1a5109e8dd @nvoxland nvoxland committed Mar 18, 2013
Showing with 18 additions and 3 deletions.
  1. +18 −3 liquibase-core/src/main/java/liquibase/integration/spring/SpringLiquibase.java
View
21 liquibase-core/src/main/java/liquibase/integration/spring/SpringLiquibase.java
@@ -1,8 +1,6 @@
package liquibase.integration.spring;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.net.URL;
import java.sql.Connection;
import java.sql.SQLException;
@@ -139,6 +137,8 @@ public ClassLoader toClassLoader() {
private boolean shouldRun = true;
+ private File rollbackFile;
+
public SpringLiquibase() {
super();
}
@@ -251,6 +251,7 @@ public void afterPropertiesSet() throws LiquibaseException {
try {
c = getDataSource().getConnection();
liquibase = createLiquibase(c);
+ generateRollbackFile(liquibase);
performUpdate(liquibase);
} catch (SQLException e) {
throw new DatabaseException(e);
@@ -267,6 +268,16 @@ public void afterPropertiesSet() throws LiquibaseException {
}
+ private void generateRollbackFile(Liquibase liquibase) throws LiquibaseException {
+ if(rollbackFile != null) {
+ try {
+ liquibase.futureRollbackSQL(getContexts(), new FileWriter(rollbackFile));
+ } catch (IOException e) {
+ throw new LiquibaseException("Unable to generate rollback file.", e);
+ }
+ }
+ }
+
protected void performUpdate(Liquibase liquibase) throws LiquibaseException {
liquibase.update(getContexts());
}
@@ -336,6 +347,10 @@ public ResourceLoader getResourceLoader() {
return resourceLoader;
}
+ public void setRollbackFile(File rollbackFile) {
+ this.rollbackFile = rollbackFile;
+ }
+
@Override
public String toString() {
return getClass().getName()+"("+this.getResourceLoader().toString()+")";

0 comments on commit 552501a

Please sign in to comment.