KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > QueryUpdateSet


1
2 /*
3 LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
4
5
6     Copyright (C) 2003 Together
7
8     This library is free software; you can redistribute it and/or
9     modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12
13     This library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16     Lesser General Public License for more details.
17
18     You should have received a copy of the GNU Lesser General Public
19     License along with this library; if not, write to the Free Software
20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */

22
23 package org.webdocwf.util.loader;
24
25 import java.util.*;
26 import java.sql.*;
27
28 /**
29  *
30  * QueryUpdateSet class creates the update sql statement
31  * @author Radoslav Dutina
32  * @version 1.0
33  */

34 public class QueryUpdateSet {
35
36   private String JavaDoc strQueryUpdate=null;
37   private Vector indexDummyOverwrite=new Vector();
38 // private Vector indexDummyUpdate=new Vector();
39
private Vector indexDummySetNull=new Vector();
40   private String JavaDoc versionName="version";
41
42   /**
43    * Construct the object of QueryUpdateSet class with associated parameter
44    * @param vecColumnNames is vector which contain column names
45    * @param vecColumnTypes is vector which contain column types
46    * @param vecColumnMode is vector which contain column mode
47    * @param tableName is the current table name
48    * @param oid is boolean parameter
49    */

50   public QueryUpdateSet(Vector vecColumnNames, Vector vecColumnTypes, Vector vecColumnMode,
51                         String JavaDoc tableName, boolean oid, String JavaDoc versionName, ConfigReader configReaderTarget) throws LoaderException {
52
53     this.versionName=versionName;
54 // this.strQueryUpdate=strQueryUpdate;
55
strQueryUpdate="update " + tableName + " set ";
56     int counter=0;
57     for (int j = 0; j < vecColumnNames.size(); j++) {
58       counter=j;
59       if (vecColumnMode.get(j).toString().equalsIgnoreCase("Overwrite")) {
60         indexDummyOverwrite.add(String.valueOf(counter));
61         strQueryUpdate+=vecColumnNames.get(j).toString()+"=";
62 //ZK change this 7.5.3004 from CheckType to configReaderSource
63
try {
64             //ZK Added next line because of DB2 type LONG VARCHAR
65
String JavaDoc columnType = Utils.replaceAll(vecColumnTypes.get(j).toString()," ","_");
66             if(!configReaderTarget.isNumber(columnType)){
67                 if(configReaderTarget.isWithN(columnType)){
68                     strQueryUpdate+="N";
69                 }
70                 strQueryUpdate+="'dummyOverwrite'"+", ";
71             }else{
72                 strQueryUpdate+="dummyOverwrite"+", ";
73             }
74         } catch (LoaderException e) {
75             LoaderException le = new LoaderException("Exception:Type not present in conf file for target database, add it into conf file.",(Throwable JavaDoc)e);
76                     throw le;
77         }
78       }else if (vecColumnMode.get(j).toString().equalsIgnoreCase("SetNull")) {
79         strQueryUpdate +="dummySetNull"+", ";
80         indexDummySetNull.add(String.valueOf(counter));
81       }
82     }
83     if(oid)
84       strQueryUpdate += " "+this.versionName+" = " + "dummyVersionOverwrite" + " where ";
85     else{
86       int start=strQueryUpdate.lastIndexOf(",");
87       if(start<strQueryUpdate.length()-1&&start!=-1)
88         strQueryUpdate=strQueryUpdate.substring(0,strQueryUpdate.lastIndexOf(","));
89       strQueryUpdate += " where ";
90     }
91   }
92
93   /**
94    * This method read the value of strQueryUpdate parameter
95    * @return value of parameter
96    */

97   public String JavaDoc getQueryUpdate(){
98     return this.strQueryUpdate ;
99   }
100
101   /**
102    * This method read the value of indexDummyOverwrite parameter
103    * @return value of parameter
104    */

105   public Vector getIndexDummyOverwrite(){
106     return indexDummyOverwrite;
107   }
108
109   /**
110    * This method read the value of indexDummySetNull parameter
111    * @return value of parameter
112    */

113   public Vector getIndexDummySetNull(){
114     return indexDummySetNull;
115   }
116
117
118 }
Popular Tags