⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlelement.java

📁 数据仓库工具
💻 JAVA
字号:
/**
  SqlElement - Sql element in xml file.
    Copyright (C) 2002-2003  Together
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 SqlElement.java
 Date: 20.5.2003.
 @version 1.0.0
 @author: Zoran Milakovic zoran@prozone.co.yu
 */

package org.webdocwf.util.loader;

import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.webdocwf.util.loader.logging.*;

/**
 * Class is wrapper for SqlElement tag in XML file.
 *
 * @author     Zoran Milakovic
 * @version    1.1
 */
public class SqlElement {

  private String strSqlName = "";
  //private String strSqlLogMode = "";
  private String strSqlOnErrorContinue = "";
  private String strSqlCommit = "";

//  String strLogMode = "";
  private String strDefaultLogMode = "";
  private boolean bOnErrorContinue;
  private boolean bDefaultOnErrorContinue = false;
  private boolean bDefaultCommit = true;
//  private String strTargetDbVendor = "";
//  private String strTargetDriverName = "";

//  private String strJDBCTargetParameterDriver = "";
//  private String strJDBCTargetParameterConnection = "";
//  private String strJDBCTargetParameterUser = "";
//  private String strJDBCTargetParameterPassword = "";
//  private String strTargetDriverClassName = "";

  private JdbcParametersElement jdbcParametersElement;
  private ConfigReader configReader;
  private Logger logger;
  private LoaderJobAttrReader loaderJobReader;

  /**
   * Method parseSql is used to analyse import XML file
   * about sql tags. Return number of sql elements in a whole xml input file.
   * @param inStream Data from inputXML file which is converted into InputStream.
   * @return Number of sql tags in an input XML file.
   * @throws LoaderException
   */
  public int parseSql(InputStream inStream) throws LoaderException {
    int iNumTagsImportJob = 0;
    Document doc = null;
    this.logger.write("full", "\tparseSql method is started.");
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = null;
      db = dbf.newDocumentBuilder();
      doc = db.parse(inStream);
    }
    catch (Exception e) {
      this.logger.write("normal", "Sorry, an error occurred: " + e);
      LoaderException le = new LoaderException("Exception: ",
                                               (Throwable) e);
      throw le;
//            System.exit(1);
    }
    if (doc != null) {
      NodeList tagBasic = doc.getElementsByTagName("sql");
      iNumTagsImportJob = tagBasic.getLength();
        Vector vecNames = new Vector();
        String strName = "";
        for (int i = 0; i < iNumTagsImportJob; i++) {
          strName = new String("");
          strName = OctopusXMLUtil.importAttributeValue(doc, "sql","name",i);
          for (int j = 0; j < vecNames.size(); j++) {
            if (strName.equals("")) {
              this.logger.write("normal",
                  "Sorry, an error occurred: No Sql statement name .");
              LoaderException le = new LoaderException("Exception: ",
                  (Throwable) (new Exception(
                  "Sorry, an error occurred: No Sql statement name .")));
              throw le;
            }
            if (strName.equalsIgnoreCase(vecNames.get(j).toString())) {
              this.logger.write("normal",
                  "Sorry, an error occurred: More Sql statements with same name :"
                  + strName);
              LoaderException le = new LoaderException("Exception: ",
                  (Throwable) (new Exception(
                  "Sorry, an error occurred: More Sql statements with same name :")));
              throw le;
            }
          }
          vecNames.addElement(strName);
        }
    }
    try {
      inStream.reset();
    }
    catch (IOException e) {
      this.logger.write("normal", "Sorry, an error occurred: " + e);
      LoaderException le = new LoaderException("IOxception: ",
                                               (Throwable) e);
      throw le;
//            System.exit(1);
    }
    this.logger.write("full", "\tparseSql method is finished.");
    return iNumTagsImportJob;
  }

  /**
   * This method set value of logger parameter
   * @param logger is value of parameter
   */
  public void setLogger(Logger logger) {
    this.logger = logger;
  }

  /**
   * This method set value of echo parameter
   * @param reader is value of parameter
   */
  public void setConfigReader(ConfigReader reader) {
    this.configReader = reader;
  }

  /**
   * This method set value of jdbcParametersElement parameter
   * @param jdbc is value of parameter
   */
  public void setJdbcParametersElement(JdbcParametersElement jdbc) {
    this.jdbcParametersElement = jdbc;
  }

  /**
   * Method importSQLStatement imports sql attributes from xml file and puts them in the global variables.
   * Return Vector. It's elements are strings which represents sql statements.
   * @param inStream Data from inputXML file which is converted into InputStream.
   * @param iSqlItem Number of sql tag in XML file which will be analised.
   * @return vector
   * @throws LoaderException
   */
  public Vector importSQLStatement(InputStream inStream, int iSqlItem) throws LoaderException {
    Vector strValue = new Vector();
    Vector vecJDBCTargetValue = new Vector();
    Vector vecJDBCTargetName = new Vector();
    Document doc = null;
    String strNodeValue = "";
    this.logger.write("full", "\timportSQLStatement  method is started.");
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = null;
      db = dbf.newDocumentBuilder();
      doc = db.parse(inStream);
      if (doc != null) {
        NodeList tagBasic = doc.getElementsByTagName("sql");
        if (tagBasic.getLength() != 0) {
          Element docFragment = (Element) tagBasic.item(iSqlItem);
          this.strSqlName = docFragment.getAttribute("name");
/*
          this.strSqlLogMode = docFragment.getAttribute("logMode");
          if (this.strSqlLogMode.equals("")) {
              this.strSqlLogMode = loaderJobReader.getDefaultLogMode();
          }
*/
          this.strSqlOnErrorContinue = docFragment.getAttribute("onErrorContinue");
//          if (this.strSqlOnErrorContinue.equals("")) {
//            if (this.bOnErrorContinue == true)
//              this.strSqlOnErrorContinue = "true";
//            else
//              this.strSqlOnErrorContinue = (new Boolean(this.bDefaultOnErrorContinue)).toString();
//          }


          this.strSqlCommit = docFragment.getAttribute("commit");
          if (this.strSqlCommit.equals("")) {
            this.strSqlCommit = (new Boolean(this.bDefaultCommit)).toString();
          }
          String strReturnCode = docFragment.getAttribute("returnCode");
          if (!strReturnCode.equals("")) {
            ReturnCode.setErrorReturnCode(Integer.parseInt(strReturnCode));
          }
          else
            ReturnCode.setErrorReturnCode(ReturnCode.getDefaultErrorReturnCode());

          NodeList targetTag = docFragment.getElementsByTagName("sqlStmt");
          for (int i = 0; i < targetTag.getLength(); i++) {
            NodeList nodeText = targetTag.item(i).getChildNodes();
            if (nodeText.item(0) != null) {
              strNodeValue = nodeText.item(0).getNodeValue();
              strValue.addElement(strNodeValue);
            }
          }
        }
      }
    }
    catch (Exception e) {
      this.logger.write("normal", "Sorry, an error occurred: " + e);
      LoaderException le = new LoaderException("Exception: ",
                                               (Throwable) e);
      throw le;
//            System.exit(1);
    }
    try {
      inStream.reset();
    }
    catch (IOException e) {
      this.logger.write("normal", "Sorry, an error occurred: " + e);
      LoaderException le = new LoaderException("IOException: ",
                                               (Throwable) e);
      throw le;
//            System.exit(1);
    }
    this.logger.write("full", "\timportSQLStatement  method is finished.");
    return strValue;
  }

//  public String getTargetDriverClassName() {
//    return this.strTargetDriverClassName;
//  }
//  public String getJDBCTargetParameterPassword() {
//    return this.strJDBCTargetParameterPassword;
//  }
//
//  public String getJDBCTargetParameterUser() {
//    return this.strJDBCTargetParameterUser;
//  }
//
//  public String getJDBCTargetParameterConnection() {
//    return this.strJDBCTargetParameterConnection;
//  }
//
//  public String getJDBCTargetParameterDriver() {
//    return this.strJDBCTargetParameterDriver;
//  }

//  public String getTargetDriverName() {
//    return this.strTargetDriverName;
//  }
//
//  public String getTargetDbVendor() {
//    return this.strTargetDbVendor;
//  }

  /**
   * This method read value of bDefaultCommit parameter
   * @return default value for attribute Commit
   */
  public boolean getDefaultCommit() {
    return this.bDefaultCommit;
  }

  /**
   * This method read value of bDefaultOnErrorContinue parameter
   * @return default value for attribute OnErrorContinue
   */
  public boolean getDefaultOnErrorContinue() {
    return this.bDefaultOnErrorContinue;
  }

  /**
   * This method read value of bOnErrorContinue parameter
   * @return value for attribute OnErrorContinue
   */
  public boolean getOnErrorContinue() {
    return this.bOnErrorContinue;
  }

  /**
   * This method read value of strDefaultLogMode parameter
   * @return default value for attribute LogMode
   */
  public String getDefaultLogMode() {
    return this.strDefaultLogMode;
  }

  /**
   * This method read value of strLogMode parameter
   * @return value for attribute LogMode
   */
//  public String getLogMode() {
//    return this.strLogMode;
//  }

  /**
   * This method read value of strSqlCommit parameter
   * @return value for attribute SqlCommit
   */
  public String getSqlCommit() {
    return this.strSqlCommit;
  }

  /**
   * This method read value of strSqlOnErrorContinue parameter
   * @return value for attribute SqlOnErrorContinue
   */
  public String getSqlOnErrorContinue() {
    return this.strSqlOnErrorContinue;
  }

  /**
   * This method read value of strSqlLogMode parameter
   * @return value for attribute SqlLogMode
   */
//  public String getSqlLogMode() {
//    return this.strSqlLogMode;
//  }

  /**
   * This method read value of strSqlName parameter
   * @return value for attribute SqlName
   */
  public String getSqlName() {
    return this.strSqlName;
  }

  /**
    * Set LoaderJobAttrReader object
    * @param loader LoaderJobAttrReader object,which stores loaderJob tag attributes
    */
   public void setLoaderJob(LoaderJobAttrReader loader) {
     this.loaderJobReader = loader;
   }



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -