1 /*
2 Loader - tool for transfering data from one JDBC source to another and
3 doing transformations during copy.
4 Copyright (C) 2002-2003 Together
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13 You should have received a copy of the GNU Lesser General Public
14 License along with this library; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 Loader.java
17 Date: 03.03.2003.
18 @version 2.1 alpha
19 @author:
20 Radoslav Dutina rale@prozone.co.yu
21 */
22
23 package org.webdocwf.util.loader;
24
25 import java.util.*;
26 import java.math.*;
27 import java.sql.*;
28
29 /***
30 *
31 * QueryInsertRowCt class is used for creating string representation of
32 * prepereStatement for inserting the tables (<copyTable> tag)
33 * @author Radoslav Dutina
34 * @version 1.0
35 */
36 public class QueryInsertRowCt {
37 private String tableName="";
38 private Vector columnNamesPstmt=new Vector();
39 private BigDecimal bdecOidNumber;
40 private boolean bOidLogicCurrentTable=false;
41 private boolean isTOS=false;
42 private String oidColumnName="oid";
43 private String versionColumnName="version";
44 private String oidType="decimal";
45 private String versionType="bigint";
46 private Hashtable sqlToJavaMap=new Hashtable();
47
48 /***
49 * Public constructor of QueryInsertRowCt class. Construct object QueryInsertRowCt with
50 * an associated parameters.
51 * @param bOidLogicCurrentTable is boolean object, which decide is oid logic true or false
52 * @param isTOS is boolean object, which decide is oid logic true or false
53 * @param vecNewColumnNames defines Vector object of column names
54 * @param vecNewColumnTypes defines Vector object of column types
55 * @param tableName defines current table name
56 * @param bdecOidNumber defines value of oid column
57 */
58 public QueryInsertRowCt( boolean bOidLogicCurrentTable, boolean isTOS, Vector vecNewColumnNames,
59 Vector vecNewColumnTypes,String tableName,
60 BigDecimal bdecOidNumber,String oidColumnName,
61 String versionColumnName, String oidType,
62 String versionType,Hashtable sqlToJavaMap) {
63
64 this.tableName=tableName;
65 this.oidColumnName=oidColumnName;
66 this.versionColumnName=versionColumnName;
67 this.oidType=oidType;
68 this.versionType=versionType;
69 this.sqlToJavaMap=sqlToJavaMap;
70 this.bOidLogicCurrentTable=bOidLogicCurrentTable;
71 this.bdecOidNumber=bdecOidNumber;
72 this.isTOS=isTOS;
73 if(bOidLogicCurrentTable){
74 if(isTOS){
75 columnNamesPstmt.add(this.oidColumnName);
76 }else{
77 columnNamesPstmt.add(this.oidColumnName);
78 columnNamesPstmt.add(this.versionColumnName);
79 }
80 }
81
82 for (int i = 0; i < vecNewColumnNames.size(); i++) {
83 columnNamesPstmt.add(vecNewColumnNames.get(i).toString());
84 }
85
86 }
87
88 /***
89 * This method read value of pstmt parameter, which represent prepereStatement
90 * @return value of parameter
91 */
92 public String getPreperedStatementForInsert(){
93 String pstmt="insert into "+tableName+" (";
94 int count=columnNamesPstmt.size();
95 for (int i = 0; i < count; i++) {
96 if(i!=count-1)
97 pstmt+=columnNamesPstmt.get(i).toString()+",";
98 else
99 pstmt+=columnNamesPstmt.get(i).toString()+")";
100 }
101 pstmt+=" VALUES (";
102 for (int i = 0; i < count; i++) {
103 if(i!=count-1){
104 pstmt+="?,";
105 }else{
106 pstmt += "?)";
107 }
108 }
109 if(bOidLogicCurrentTable){
110 if (isTOS) {
111 int oid= pstmt.indexOf("?");
112 pstmt=pstmt.substring(0,oid)+"'"+bdecOidNumber+"'"+pstmt.substring(oid+1);
113 }
114 else {
115 int oid= pstmt.indexOf("?");
116 pstmt=pstmt.substring(0,oid)+bdecOidNumber.toString()+pstmt.substring(oid+1);
117 int version=pstmt.indexOf("?");
118 pstmt=pstmt.substring(0,version)+String.valueOf(0)+pstmt.substring(version+1);
119 }
120 }
121
122 return pstmt;
123 }
124
125 }
This page was automatically generated by Maven