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

📄 checkrowcache.java

📁 数据仓库工具
💻 JAVA
字号:
/*
  Loader - tool for transfering data from one JDBC source to another and
  doing transformations during copy.
    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
 Loader.java
 Date: 03.03.2003.
 @version 2.1 alpha
 @author:
 Radoslav Dutina rale@prozone.co.yu
 */

package org.webdocwf.util.loader;

import java.util.*;
import java.sql.*;
import org.webdocwf.util.loader.logging.*;

/**
 *
 * CheckRowCache class is used to cache queries which will be sent to target
 * database to check if some row exists
 * @author Radoslav Dutina
 * @version 1.0
 */
public class CheckRowCache {
  private Hashtable rowExist = new Hashtable();
  private Hashtable rowVersionValue = new Hashtable();

  private static String currentKey = "";
  private Logger logger;
  private int currentVersion = 0;

  /**
   * Empty constructor
   */
  public CheckRowCache() {
  }

  /**
   * This method is use to mark row if he is cahced
   */
  public void setCheckRowValue() {
    if (!this.currentKey.equalsIgnoreCase(""))
      rowExist.put(this.currentKey, "true");
  }

  /**
   * This method set value of cached row
   * @param val is value of cached row
   */
  public void setCheckRowVersionValue(String val) {
    if (!this.currentKey.equalsIgnoreCase("")) {
      if (rowVersionValue.get(this.currentKey) != null)
        rowVersionValue.remove(this.currentKey);
      rowVersionValue.put(this.currentKey, val);
    }
  }

  /**
   * This method is use to retrive value of cached row
   * @return value of cache row
   */
  public int getCheckRowVersionValue() {
    String ret = (String)rowVersionValue.get(this.currentKey);
    return Integer.parseInt(ret);
  }

  /**
   * This method is use to retrive query string
   * @return query string
   */
  public static String getKey() {
    return currentKey;
  }

  /**
   * This method is use to retrive value of some sql query object
   * @param key defines string representation of query object
   * @param conn defines connection to target database
   * @param iTargetFirstColumnResult is configuration parameter
   * @return value of selected row
   * @throws java.lang.Exception
   */
  public boolean getCheckRowValue(String key, Connection conn,
      int iTargetFirstColumnResult, String versionColumnName) throws Exception {

    this.currentKey = key;
    Object obj = rowExist.get(key);
    if (obj == null) {
      this.logger.write("full", "\tQuery '" + key + "' will be executed");
      try {
        Statement stmtCheckTarget = conn.createStatement();
        ResultSet rsetCheckTarget = stmtCheckTarget.executeQuery(key);
        if (rsetCheckTarget.next()) { //update row mode
          this.setCheckRowValue();
          if (iTargetFirstColumnResult != 100) {
//            this.currentVersion = rsetCheckTarget.getInt("version");
            this.currentVersion = rsetCheckTarget.getInt(versionColumnName);
            this.setCheckRowVersionValue(String.valueOf(this.currentVersion));
          }
          rsetCheckTarget.close();
          stmtCheckTarget.close();
          return true;
        } else {//insert row mode
          this.setCheckRowVersionValue(String.valueOf(0));
          rsetCheckTarget.close();
          stmtCheckTarget.close();
        }
        return false;
      }
      catch (Exception ex) {
        this.logger.write("full", ex.getMessage());
        throw ex;
      }
    } else { //update row mode
      return true;
    }
  }

  /**
   * This method is use to reset all parameters which are used in this class
   */
  public void resetCheckRowCache() {
    rowExist.clear();
    rowVersionValue.clear();
    currentKey = "";
  }

  /**
   * This method is use to set logger object
   * @param logger is current logger
   */
  public void setLogger(Logger logger) {
    this.logger = logger;
  }

  /**
   * This method is use to retrive value of currentVersion parameter
   * @return value of parameter
   */
  public int getCurrentVersion() {
    return this.currentVersion;
  }

}

⌨️ 快捷键说明

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