001package org.kualigan.tools.ant.tasks;
002
003import liquibase.Liquibase;
004import liquibase.integration.ant.BaseLiquibaseTask;
005import liquibase.util.StringUtils;
006import org.apache.tools.ant.BuildException;
007
008import java.util.List;
009
010public class DropAllTask extends BaseLiquibaseTask {
011
012    private String schemas;
013
014    public String getSchemas() {
015        return schemas;
016    }
017
018    public void setSchemas(String schemas) {
019        this.schemas = schemas;
020    }
021    
022    public void execute() throws BuildException {
023        Liquibase liquibase = null;
024        try {
025            liquibase = createLiquibase();
026            boolean retry = true;
027            while (retry) {
028                try {
029                    if (StringUtils.trimToNull(schemas) != null) {
030                        List<String> schemas = StringUtils.splitAndTrim(this.schemas, ",");
031                        liquibase.dropAll(schemas.toArray(new String[schemas.size()]));
032                    } else {
033                        liquibase.dropAll();
034                    }
035                    retry = false;
036                }
037                catch (Exception e2) {
038                    log(e2.getMessage());
039                    if (e2.getMessage().indexOf("ORA-02443") < 0 && e2.getCause() != null && retry) {
040                        retry = (e2.getCause().getMessage().indexOf("ORA-02443") > -1);
041                    }
042                    
043                    if (!retry) {
044                        throw e2;
045                    }
046                    else {
047                        log("Got ORA-2443. Retrying...");
048                    }
049                }
050            }       
051        } catch (Exception e) {
052            throw new BuildException(e);
053        } finally {
054            closeDatabase(liquibase);
055        }
056    }
057}