All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickntap.tool.setup.DatabaseStep Maven / Gradle / Ivy

The newest version!
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 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 String getPostAction() {
    return postAction;
  }

  public void setPostAction(String postAction) {
    this.postAction = postAction;
  }

  public String getPreAction() {
    return preAction;
  }

  public void setPreAction(String preAction) {
    this.preAction = preAction;
  }

  public String getDescription() {
    return description;
  }

  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()]));
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy