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

📄 queryinsertrowct.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.math.*;
import java.sql.*;

/**
 *
 * QueryInsertRowCt class is used for creating string representation of
 * prepereStatement for inserting the tables (<copyTable> tag)
 * @author Radoslav Dutina
 * @version 1.0
 */
public class QueryInsertRowCt {
  private String tableName="";
  private Vector columnNamesPstmt=new Vector();
  private BigDecimal bdecOidNumber;
  private boolean bOidLogicCurrentTable=false;
  private boolean isTOS=false;
  private String oidColumnName="oid";
  private String versionColumnName="version";
  private String oidType="decimal";
  private String versionType="bigint";
  private Hashtable sqlToJavaMap=new Hashtable();

  /**
   * Public constructor of QueryInsertRowCt class. Construct object QueryInsertRowCt with
   * an associated parameters.
   * @param bOidLogicCurrentTable is boolean object, which decide is oid logic true or false
   * @param isTOS is boolean object, which decide is oid logic true or false
   * @param vecNewColumnNames defines Vector object of column names
   * @param vecNewColumnTypes defines Vector object of column types
   * @param tableName defines current table name
   * @param bdecOidNumber defines value of oid column
   */
  public QueryInsertRowCt( boolean bOidLogicCurrentTable, boolean isTOS, Vector vecNewColumnNames,
			   Vector vecNewColumnTypes,String tableName,
                           BigDecimal bdecOidNumber,String oidColumnName,
                           String versionColumnName, String oidType,
                           String versionType,Hashtable sqlToJavaMap) {

    this.tableName=tableName;
    this.oidColumnName=oidColumnName;
    this.versionColumnName=versionColumnName;
    this.oidType=oidType;
    this.versionType=versionType;
    this.sqlToJavaMap=sqlToJavaMap;
    this.bOidLogicCurrentTable=bOidLogicCurrentTable;
    this.bdecOidNumber=bdecOidNumber;
    this.isTOS=isTOS;
    if(bOidLogicCurrentTable){
      if(isTOS){
        columnNamesPstmt.add(this.oidColumnName);
      }else{
        columnNamesPstmt.add(this.oidColumnName);
        columnNamesPstmt.add(this.versionColumnName);
      }
    }

    for (int i = 0; i < vecNewColumnNames.size(); i++) {
      columnNamesPstmt.add(vecNewColumnNames.get(i).toString());
    }

  }

  /**
   * This method read value of pstmt parameter, which represent prepereStatement
   * @return value of parameter
   */
  public String getPreperedStatementForInsert(){
    String pstmt="insert into "+tableName+" (";
    int count=columnNamesPstmt.size();
    for (int i = 0; i < count; i++) {
      if(i!=count-1)
        pstmt+=columnNamesPstmt.get(i).toString()+",";
      else
        pstmt+=columnNamesPstmt.get(i).toString()+")";
    }
    pstmt+=" VALUES (";
    for (int i = 0; i < count; i++) {
      if(i!=count-1){
        pstmt+="?,";
      }else{
        pstmt += "?)";
      }
    }
    if(bOidLogicCurrentTable){
      if (isTOS) {
        int oid= pstmt.indexOf("?");
        pstmt=pstmt.substring(0,oid)+"'"+bdecOidNumber+"'"+pstmt.substring(oid+1);
      }
      else {
        int oid= pstmt.indexOf("?");
        pstmt=pstmt.substring(0,oid)+bdecOidNumber.toString()+pstmt.substring(oid+1);
        int version=pstmt.indexOf("?");
        pstmt=pstmt.substring(0,version)+String.valueOf(0)+pstmt.substring(version+1);
      }
    }

    return pstmt;
  }

}

⌨️ 快捷键说明

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