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

📄 countercolumns.java

📁 数据仓库工具
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  }

  /**
   * This method read value of counterStartValue parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return Vector of start values for all counter columns in table tableName.
   */
  public Vector getCounterStartValue(String tableName, String tableID) {
    return (Vector)this.counterStartValue.get(tableName + "_" + tableID);
  }

  /**
   * This method read value of targetColumnName parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return Vector of counter column names for all counter columns in table tableName.
   */
  public Vector getTargetColumnName(String tableName, String tableID) {
    return (Vector)this.targetColumnName.get(tableName + "_" + tableID);

  }

  /**
   * This method read value of targetColumnTyp parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return Vector of counter column types for all counter columns in table tableName.
   */
  public Vector getTargetColumnTyp(String tableName, String tableID) {
    return (Vector)this.targetColumnTyp.get(tableName + "_" + tableID);

  }

  /**
   * This method read value of valueMode parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getValueMode(String tableName, String tableID) {
    return (Vector)this.valueMode.get(tableName + "_" + tableID);
  }

  /**
   * This method read value of counterStartValueReset parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getCounterStartValueReset(String tableName, String tableID) {
    return (Vector)this.counterStartValueReset.get(tableName + "_" + tableID);
  }

//subCounter columns
  /**
   * This method read value of subCounterName parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getSubCounterName(String tableName, String tableID) {
    return (Vector)this.subCounterName.get(tableName + "_" + tableID);
  }

  /**
   * This method read value of getSubCounterIncrement parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getSubCounterIncrement(String tableName, String tableID) {
    return (Vector)this.subCounterIncrement.get(tableName + "_" + tableID);
  }

  /**
   * This method read value of getSubCounterStartValue parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getSubCounterStartValue(String tableName, String tableID) {
    return (Vector)this.subCounterStartValue.get(tableName + "_" + tableID);
  }

  /**
   * This method read value of subTargetColumnName parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getSubTargetColumnName(String tableName, String tableID) {
    return (Vector)this.subTargetColumnName.get(tableName + "_" + tableID);

  }

  /**
   * This method read value of subTargetColumnTyp parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getSubTargetColumnTyp(String tableName, String tableID) {
    return (Vector)this.subTargetColumnTyp.get(tableName + "_" + tableID);

  }

  /**
   * This method read value of subValueMode parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getSubValueMode(String tableName, String tableID) {
    return (Vector)this.subValueMode.get(tableName + "_" + tableID);
  }

  /**
   * This method read value of subCounterKeyColumns parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getSubCounterKeyColumns(String tableName, String tableID) {
    return (Vector)this.subCounterKeyColumns.get(tableName + "_" + tableID);
  }

  /**
   * This method read value of subCounterKeyColumnsTyp parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getSubCounterKeyColumnsTyp(String tableName, String tableID) {
    return (Vector)this.subCounterKeyColumnsTyp.get(tableName + "_" + tableID);
  }

  /**
   * This method read value of subCounterKeyValues parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return vector
   */
  public Vector getSubCounterKeyValues(String tableName, String tableID) {
    return (Vector)this.subCounterKeyValues.get(tableName + "_" + tableID);
  }

  /**
   * This method set value of subCounterKeyValues parameter
   * @param tableName defines table name
   * @param tableID defines table ID
   * @param values is hashtable new key values
   */
  public void setSubCounterKeyValues(String tableName, String tableID, Hashtable values) {

    Enumeration keys = values.keys();
    Vector vecColumns = (Vector)this.subCounterKeyColumns.get(tableName + "_" + tableID);
    Vector vecValues = new Vector(vecColumns.size());

    String column;
    for (int i = 0; i < vecColumns.size(); i++) {
      Vector subValues = new Vector();
      for (int j = 0; j < ( (Vector)vecColumns.get(i)).size(); j++) {
        column = ( (Vector)vecColumns.get(i)).get(j).toString();
        subValues.add(values.get(column));
      }
      vecValues.add(subValues);
    }
    this.subCounterKeyValues.put(tableName + "_" + tableID, vecValues);
  }

  /**
   * This method set values for Counter columns
   * @param tableName is table name
   * @param tableID is table ID
   */
  public void setCounterValue(String tableName, String tableID) {
    Vector targetCounterValue = new Vector();
    Vector oldValues = getCounterValue(tableName, tableID);
    Vector counterIncrement = getCounterIncrement(tableName, tableID);
    for (int i = 0; i < counterIncrement.size(); i++) {
      BigDecimal newValue = new BigDecimal(oldValues.get(i).toString());
      newValue = newValue.add(new BigDecimal(counterIncrement.get(i).toString()));
      targetCounterValue.addElement(newValue);
    }
    this.currentCounterValue.put(tableName + "_" + tableID, targetCounterValue);
  }

  /**
   * This method set values for currentCounterValue parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @return Vector of current counter values for table - tableName
   */
  public Vector getCounterValue(String tableName, String tableID) {
    return (Vector)this.currentCounterValue.get(tableName + "_" + tableID);
  }

  /**
   * This method set values for currentCounterValue parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @param conn is connection to target database
   * @param firstColumn is first column
   * @throws SQLException
   */
  public void setTargetColumnStartValues(String tableName, String tableID, Connection conn,
      int firstColumn) throws SQLException {
    Vector values = new Vector();
    //TODO ZORAN
	  Vector valuesFromTable = readCounter(tableName, tableID, conn, firstColumn);
    for (int i = 0; i < this.getCounterName(tableName, tableID).size(); i++) {
      if (this.getCounterStartValueReset(tableName,
          tableID).get(i).toString().equalsIgnoreCase("true")) {
        if (this.getCounterStartValue(tableName, tableID).get(i) != null) {
          BigDecimal newValue = new BigDecimal( (this.getCounterStartValue(tableName,
                                tableID)).get(i).toString());
          values.addElement(newValue);
        } else
          values.addElement(null);
      } else if (this.getCounterStartValueReset(tableName,
          tableID).get(i).toString().equalsIgnoreCase("false")) {
        if (this.getCounterStartValue(tableName, tableID).get(i) != null) {
          BigDecimal newValue = new BigDecimal(valuesFromTable.get(i).toString());
          values.addElement(newValue);
        } else
          values.addElement(null);
      }
    }
    this.currentCounterValue.put(tableName + "_" + tableID, values);
  }

  /**
   * Method importValue reads values from desired XML tag and puts them into Vector.
   * @param doc Parsed import XML file.
   * @param tagName The name of XML tag.
   * @param strAttrName The name of tag attribute which reads input strValue.
   * @param iImportJobItem Number of ImportDefinition tag which is processed.
   * @param defaultValue The default value of strattrname attribute.
   * @return Vector of importing values.
   */
  private Vector importValue(Document doc, String tagName, String strAttrName,
      int iImportJobItem, String defaultValue) {
    Vector strValue = new Vector();
    NodeList tagBasic = doc.getElementsByTagName("importDefinition");
    if (tagBasic.getLength() != 0) {
      Element docFragment = (Element)tagBasic.item(iImportJobItem);
      NodeList tag = docFragment.getElementsByTagName(tagName);
      for (int i = 0; i < tag.getLength(); i++) {
        String nodeValue = "";
        if (strAttrName != null) {
          NamedNodeMap attrs = tag.item(i).getAttributes();
          Node nodeResult = attrs.getNamedItem(strAttrName);
          if (nodeResult != null)
            nodeValue = nodeResult.getNodeValue();
          else
            nodeValue = defaultValue;
          strValue.addElement(nodeValue);
        } else {
          NodeList nodeText = tag.item(i).getChildNodes();
          if (nodeText.item(0) != null) {
            nodeValue = nodeText.item(0).getNodeValue();
            strValue.addElement(nodeValue);
          }
        }
      }
    }
    return strValue;
  }

  /**
   * Method importSubCounterKeyValue reads values from strAttrName attribute
   * XML tag and puts them into Vector.
   * @param doc Parsed import XML file.
   * @param strAttrName The name of tag attribute which reads input strValue.
   * @param iImportJobItem Number of ImportDefinition tag which is processed.
   * @param iSubCounterItem Number of subCounterColumn tag which is processed.
   * @return Vector of importing values.
   */
  private Vector importSubCounterKeyValue(Document doc, String strAttrName,
      int iImportJobItem, int iSubCounterItem) {
    Vector strValue = null;
    NodeList tagBasic = doc.getElementsByTagName("importDefinition");
    if (tagBasic.getLength() != 0) {
      Element docFragment = (Element)tagBasic.item(iImportJobItem);
      NodeList tag = docFragment.getElementsByTagName("subCounterColumn");
      if (tag.getLength() != 0) {
        Element docCounterColumn = (Element)tag.item(iSubCounterItem);
        NodeList tagSubCounterColumn = docCounterColumn.getElementsByTagName("subCounterKeyColumn");
        strValue = new Vector();
        for (int i = 0; i < tagSubCounterColumn.getLength(); i++) {
          String nodeValue = "";
          if (strAttrName != null) {
            NamedNodeMap attrs = tagSubCounterColumn.item(i).getAttributes();
            Node nodeResult = attrs.getNamedItem(strAttrName);
            if (nodeResult != null) {
              nodeValue = nodeResult.getNodeValue();
            } else
              nodeValue = null;
            strValue.addElement(nodeValue);

          } else {
            NodeList nodeText = tag.item(i).getChildNodes();
            if (nodeText.item(0) != null) {
              nodeValue = nodeText.item(0).getNodeValue();
              strValue.addElement(nodeValue);
            }
          }
        }
      }
    }
    return strValue;
  }

//  /**
//   * This method check the update operation
//   * @param tableName is table name
//   * @param tableID is table ID
//   * @param conn is connection
//   * @return true if update operation OK, false otherwise
//   * @throws SQLException
//   */
//  public boolean updateCounter(String tableName, String tableID,
//      Connection conn) throws SQLException {
//
//    String strQuery = null;
//
//    Vector counterNames = this.getCounterName(tableName, tableID);
//    Vector counterValues = this.getCounterValue(tableName, tableID);
//    Vector counterIncrements = this.getCounterIncrement(tableName, tableID);
//    for (int i = 0; i < counterNames.size(); i++) {
//      Statement stmt = conn.createStatement();
//      BigDecimal newValue = new BigDecimal(counterValues.get(i).toString());
//      strQuery = queryUpdateCounter(counterNames.get(i).toString(), newValue);
//      stmt.executeUpdate(strQuery);
//      stmt.close();
//    }
//    return true;
//  }

	/**
	  * This method check the update operation
	  * @param conn is connection
	  * @throws SQLException
	  */    
  public void updateCounter(Connection conn) throws SQLException{
  	String strQuery = "";
  	for (int i=0;i<this.vecTargetTableName.size();i++){
  		String tableName = this.vecTargetTableName.get(i).toString();
			String tableID = this.vecTargetTableID.get(i).toString();
			Vector counterNames = this.getCounterName(tableName, tableID);
			Vector counterValues = this.getCounterValue(tableName, tableID);
			Vector counterIncrements = this.getCounterIncrement(tableName, tableID);
			for (int j = 0; j < counterNames.size(); j++) {
	 			Statement stmt = conn.createStatement();
	 			BigDecimal newValue = new BigDecimal(counterValues.get(i).toString());
	 			strQuery = queryUpdateCounter(counterNames.get(i).toString(), newValue);
	 			stmt.executeUpdate(strQuery);
	 			stmt.close();
			}
  	}	
  }

  /**
   * This method sets the value of counter parameter
   * @param tableName is table name
   * @param tableID is table ID
   * @param conn is connection
   * @return true
   * @throws SQLException
   */
  private boolean insertCounter(String tableName, String tableID,
      Connection conn) throws SQLException {

    String strQuery = null;

    Vector counterNames = this.getCounterName(tableName, tableID);
    Vector startValues = this.getCounterIncrement(tableName, tableID);
    for (int i = 0; i < counterNames.size(); i++) {

⌨️ 快捷键说明

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