001: /*
002: Loader - tool for transfering data from one JDBC source to another and
003: doing transformations during copy.
004: Copyright (C) 2002-2003 Together
005: This library is free software; you can redistribute it and/or
006: modify it under the terms of the GNU Lesser General Public
007: License as published by the Free Software Foundation; either
008: version 2.1 of the License, or (at your option) any later version.
009: This library is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: Lesser General Public License for more details.
013: You should have received a copy of the GNU Lesser General Public
014: License along with this library; if not, write to the Free Software
015: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
016: Loader.java
017: Date: 03.03.2003.
018: @version 2.1 alpha
019: @author:
020: Radoslav Dutina rale@prozone.co.yu
021: */
022:
023: package org.webdocwf.util.loader;
024:
025: import java.util.*;
026: import java.math.*;
027: import java.sql.*;
028:
029: /**
030: *
031: * QueryInsertRowCt class is used for creating string representation of
032: * prepereStatement for inserting the tables (<copyTable> tag)
033: * @author Radoslav Dutina
034: * @version 1.0
035: */
036: public class QueryInsertRowCt {
037: private String tableName = "";
038: private Vector columnNamesPstmt = new Vector();
039: private BigDecimal bdecOidNumber;
040: private boolean bOidLogicCurrentTable = false;
041: private boolean isTOS = false;
042: private String oidColumnName = "oid";
043: private String versionColumnName = "version";
044: private String oidType = "decimal";
045: private String versionType = "bigint";
046: private Hashtable sqlToJavaMap = new Hashtable();
047:
048: /**
049: * Public constructor of QueryInsertRowCt class. Construct object QueryInsertRowCt with
050: * an associated parameters.
051: * @param bOidLogicCurrentTable is boolean object, which decide is oid logic true or false
052: * @param isTOS is boolean object, which decide is oid logic true or false
053: * @param vecNewColumnNames defines Vector object of column names
054: * @param vecNewColumnTypes defines Vector object of column types
055: * @param tableName defines current table name
056: * @param bdecOidNumber defines value of oid column
057: */
058: public QueryInsertRowCt(boolean bOidLogicCurrentTable,
059: boolean isTOS, Vector vecNewColumnNames,
060: Vector vecNewColumnTypes, String tableName,
061: BigDecimal bdecOidNumber, String oidColumnName,
062: String versionColumnName, String oidType,
063: String versionType, Hashtable sqlToJavaMap) {
064:
065: this .tableName = tableName;
066: this .oidColumnName = oidColumnName;
067: this .versionColumnName = versionColumnName;
068: this .oidType = oidType;
069: this .versionType = versionType;
070: this .sqlToJavaMap = sqlToJavaMap;
071: this .bOidLogicCurrentTable = bOidLogicCurrentTable;
072: this .bdecOidNumber = bdecOidNumber;
073: this .isTOS = isTOS;
074: if (bOidLogicCurrentTable) {
075: if (isTOS) {
076: columnNamesPstmt.add(this .oidColumnName);
077: } else {
078: columnNamesPstmt.add(this .oidColumnName);
079: columnNamesPstmt.add(this .versionColumnName);
080: }
081: }
082:
083: for (int i = 0; i < vecNewColumnNames.size(); i++) {
084: columnNamesPstmt.add(vecNewColumnNames.get(i).toString());
085: }
086:
087: }
088:
089: /**
090: * This method read value of pstmt parameter, which represent prepereStatement
091: * @return value of parameter
092: */
093: public String getPreperedStatementForInsert() {
094: String pstmt = "insert into " + tableName + " (";
095: int count = columnNamesPstmt.size();
096: for (int i = 0; i < count; i++) {
097: if (i != count - 1)
098: pstmt += columnNamesPstmt.get(i).toString() + ",";
099: else
100: pstmt += columnNamesPstmt.get(i).toString() + ")";
101: }
102: pstmt += " VALUES (";
103: for (int i = 0; i < count; i++) {
104: if (i != count - 1) {
105: pstmt += "?,";
106: } else {
107: pstmt += "?)";
108: }
109: }
110: if (bOidLogicCurrentTable) {
111: if (isTOS) {
112: int oid = pstmt.indexOf("?");
113: pstmt = pstmt.substring(0, oid) + "'" + bdecOidNumber
114: + "'" + pstmt.substring(oid + 1);
115: } else {
116: int oid = pstmt.indexOf("?");
117: pstmt = pstmt.substring(0, oid)
118: + bdecOidNumber.toString()
119: + pstmt.substring(oid + 1);
120: int version = pstmt.indexOf("?");
121: pstmt = pstmt.substring(0, version) + String.valueOf(0)
122: + pstmt.substring(version + 1);
123: }
124: }
125:
126: return pstmt;
127: }
128:
129: }
|