com.clickntap.tool.setup.DatabaseStep Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Stripecube Show documentation
Show all versions of Stripecube Show documentation
Stripecube is an open source Java framework for Web Applications
package com.clickntap.tool.setup;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Element;
public class DatabaseStep extends AbstractStep {
private String description;
private String sqlSkip;
private String preAction;
private String postAction;
private List sqlSetup;
public String getPostAction() {
return postAction;
}
public String getPreAction() {
return preAction;
}
public void setPreAction(String preAction) {
this.preAction = preAction;
}
public void setPostAction(String postAction) {
this.postAction = postAction;
}
public String getDescription() {
return description;
}
public DatabaseStep(Element step) {
this.description = step.attributeValue("name");
this.preAction = step.attributeValue("pre-action");
this.postAction = step.attributeValue("post-action");
try {
this.sqlSkip = step.element("sql-skip").getTextTrim();
} catch (Exception e) {
this.sqlSkip = null;
}
this.sqlSetup = new ArrayList();
for (Element element : (List) step.elements("sql")) {
sqlSetup.add(element.getTextTrim());
}
}
public boolean isSkipable() throws Exception {
if (sqlSkip == null || sqlSkip.isEmpty())
return false;
long count = getDb().queryForObject(sqlSkip.replaceAll("SCHEMA", getSchema()), Number.class).intValue();
return count > 0;
}
public void setup() throws Exception {
if (sqlSetup.size() > 0) {
getDb().batchUpdate(sqlSetup.toArray(new String[sqlSetup.size()]));
}
}
}