KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.webdocwf.util.loader.logging.*;
28
29 /**
30  *
31  * QueryWhereSet class creates the where condition in sql statement
32  * @author Radoslav Dutina
33  * @version 1.0
34  */

35 public class QueryWhereSet {
36
37   private String JavaDoc strQueryWhere=" where ";
38   private Vector vecColumnNames=null;
39   private Vector vecColumnTypes=null;
40   private String JavaDoc tableName=null;
41   private String JavaDoc tableID=null;
42   private Vector indexDummyValue=new Vector();
43   private Vector indexDummyRelationValue=new Vector();
44   private Vector indexDummyConstantValue=new Vector();
45   private Vector indexDummyVariableValue=new Vector();
46   private Vector indexDummyTransformationValue=new Vector();
47   /**
48    * Construct object of QueryWhereSet class with associated parameters
49    * @param vecColumnNames is vector which contain column names
50    * @param vecColumnTypes is vector which contain column types
51    * @param tableName is the current table name
52    * @param tableID is ID of current table
53    */

54   public QueryWhereSet(Vector vecColumnNames,Vector vecColumnTypes,
55                        String JavaDoc tableName, String JavaDoc tableID ) {
56     this.vecColumnNames=vecColumnNames;
57     this.vecColumnTypes=vecColumnTypes;
58     this.tableName=tableName;
59     this.tableID=tableID;
60   }
61
62   /**
63    * This method read the value of vecTempKeyColumns and sets the parameter strQueryWhere
64    * @param vecTempKeyColumns is the value of parameter
65    * @param configReaderTarget is ConfigReader object for target database
66    */

67   public void getKeyColumns(Vector vecTempKeyColumns,ConfigReader configReaderTarget) throws LoaderException{
68
69     for (int k = 0; k < vecTempKeyColumns.size(); k++) {
70       if (vecColumnNames.size() != 0) {
71         for (int l = 0; l < vecColumnNames.size(); l++) {
72           if (vecTempKeyColumns.get(k).toString().equalsIgnoreCase(vecColumnNames.get(l).toString())) {
73 // int counter=l;
74
strQueryWhere += vecColumnNames.get(l).toString();
75 //ZK change this from CheckType to configReaderTarget
76
try {
77                 if (!configReaderTarget.isNumber(vecColumnTypes.get(l).toString())) {
78                   strQueryWhere += " = '" + "dummyValue"
79                                  + "' and ";
80                   indexDummyValue.add(String.valueOf(l));
81                 }else {
82                   strQueryWhere += " = " + "dummyValue"
83                                  + " and ";
84                   indexDummyValue.add(String.valueOf(l));
85                 }
86             } catch (LoaderException e) {
87                                 LoaderException le = new LoaderException("Exception:Type not present in conf file for target database, add it into conf file.",(Throwable JavaDoc)e);
88                             throw le;
89             }
90           }
91         }
92       }
93     }
94   }
95   /**
96    * This method read the value of vecTempKeyTransformation and sets the parameter strQueryWhere
97    * @param transformationTargetColumns is Vector with target columns in for this transformation
98    * @param vecTempKeyTransformation is Vector with key columns
99    * @param transformationColumnTypes is Vector with target with column types
100    * @param configReaderTarget is ConfigReader object for target database
101    */

102 //ZK added this method for Transformations
103
public void getTransformationKeyColumns(Vector transformationTargetColumns, Vector vecTempKeyTransformation,
104                                           Vector transformationColumnTypes, ConfigReader configReaderTarget) throws LoaderException{
105
106     for (int k = 0; k < vecTempKeyTransformation.size(); k++) {
107       if (transformationTargetColumns.size() != 0) {
108         for (int l = 0; l < transformationTargetColumns.size(); l++) {
109           if (vecTempKeyTransformation.get(k).toString().equalsIgnoreCase(transformationTargetColumns.get(l).toString())) {
110             strQueryWhere += transformationTargetColumns.get(l).toString();
111 //ZK change this 7.5.2004 from CheckType to configReaderTarget
112
try {
113                 if (!configReaderTarget.isNumber(transformationColumnTypes.get(l).toString())) {
114                   strQueryWhere += " = '" + "dummyTransformationValue"
115                                  + "' and ";
116                     indexDummyTransformationValue.add(String.valueOf(l));
117                 }else {
118                   strQueryWhere += " = " + "dummyTransformationValue"
119                                  + " and ";
120                   indexDummyTransformationValue.add(String.valueOf(l));
121                 }
122             } catch (LoaderException e) {
123                                 LoaderException le = new LoaderException("Exception:Type not present in conf file for target database, add it into conf file.",(Throwable JavaDoc)e);
124                             throw le;
125             }
126           }
127         }
128       }
129     }
130   }
131   /**
132    * This method read the input parameters and sets the parameter strQueryWhere
133    * @param vecRelationKeyColumns is input parameter
134    * @param iRelationColumns is input parameter
135    * @param vecRelationColumnTargetTableName is input parameter
136    * @param vecRelationColumnTargetTableID is input parameter
137    * @param vecRelationColumnTargetColumnName is input parameter
138    * @param vecRelationKeyTypes is input parameter
139    * @param configReaderTarget is input parameter
140    */

141   public void getRelationKeyColumns(Vector vecRelationKeyColumns,int iRelationColumns,
142                                     Vector vecRelationColumnTargetTableName,Vector vecRelationColumnTargetTableID,
143                                     Vector vecRelationColumnTargetColumnName,Vector vecRelationKeyTypes,
144                                     ConfigReader configReaderTarget) throws LoaderException{
145
146     for (int k = 0; k < vecRelationKeyColumns.size(); k++) {
147       int counter=0;
148       int iNumRelation = -1;
149       for (int p = 0; p < iRelationColumns; p++) {
150         if (vecRelationColumnTargetTableName.get(p).toString().equalsIgnoreCase(
151             tableName)
152             && vecRelationColumnTargetTableID.get(p).toString().equalsIgnoreCase(
153             tableID)
154             && vecRelationColumnTargetColumnName.get(p).toString().equalsIgnoreCase(
155             vecRelationKeyColumns.get(k).toString())) {
156         iNumRelation = p;
157         counter=p;
158       }
159       }
160       strQueryWhere += vecRelationKeyColumns.get(k).toString();
161 //ZK change this 7.5.2004 from CheckType to configReaderTarget
162
//TODO ZK change 11.6.2004 from vecRelationKeyColumns to vecRelationKeyTypes
163

164       try {
165         if (configReaderTarget.isNumber(vecRelationKeyTypes.get(k).toString())){
166             strQueryWhere += " = " + "dummyRelationValue "
167                            +" and ";
168             indexDummyRelationValue.add(String.valueOf(counter));
169           }else{
170             strQueryWhere += " = '" + "dummyRelationValue"
171                            +"' and ";
172             indexDummyRelationValue.add(String.valueOf(counter));
173           }
174     } catch (LoaderException e) {
175                 LoaderException le = new LoaderException("Exception:Type not present in conf file for target database, add it into conf file.",(Throwable JavaDoc)e);
176                 throw le;
177     }
178     }
179   }
180
181   /**
182    * This method read the input parameters and sets the parameter strQueryWhere
183    * @param vecTempConstantColumns is input parameter
184    * @param vecTempConstantMode is input parameter
185    * @param vecTempConstantType is input parameter
186    * @param configReaderTarget is input parameter
187    */

188   public void getConstantKeyColumns(Vector vecTempConstantColumns, Vector vecTempConstantMode,
189                                     Vector vecTempConstantType, ConfigReader configReaderTarget) throws LoaderException{
190
191     int counter=0;
192     for (int k = 0; k < vecTempConstantColumns.size(); k++) {
193       counter=k;
194       if (vecTempConstantMode.get(k).toString().equalsIgnoreCase("Key")) {
195         strQueryWhere += vecTempConstantColumns.get(k).toString();
196 //ZK change this 7.5.2004 from CheckType to configReaderTarget
197
try {
198             if (configReaderTarget.isNumber(vecTempConstantType.get(k).toString())){
199               strQueryWhere += " = "+ "dummyConstantValue"
200                              + " and ";
201               indexDummyConstantValue.add(String.valueOf(counter));
202             
203             }else{
204               strQueryWhere += " = '"+ "dummyConstantValue"
205                              +"' and ";
206               indexDummyConstantValue.add(String.valueOf(counter));
207             
208             }
209         } catch (LoaderException e) {
210                         LoaderException le = new LoaderException("Exception:Type not present in conf file for target database, add it into conf file.",(Throwable JavaDoc)e);
211                         throw le;
212         }
213       }
214     }
215   }
216
217   /**
218    ** This method read the input parameters and sets the parameter strQueryWhere
219    * @param vecVariableColumnTargetTableName is input parameter
220    * @param vecVariableColumnTargetTableID is input parameter
221    * @param vecVariableColumnValueMode is input parameter
222    * @param vecVariableName is input parameter
223    * @param vecVariableColumnName is input parameter
224    * @param vecVariableColumnTargetColumnName is input parameter
225    * @param vecVariableColumnTypes is input parameter
226    * @param logger is input parameter
227    * @param configReader is input parameter
228    * @throws LoaderException
229    */

230   public void getVariableKeyColumns(Vector vecVariableColumnTargetTableName,
231                                     Vector vecVariableColumnTargetTableID, Vector vecVariableColumnValueMode,
232                                     Vector vecVariableName, Vector vecVariableColumnName,
233                                     Vector vecVariableColumnTargetColumnName,
234                                     Vector vecVariableColumnTypes, Logger logger,
235                                     ConfigReader configReader) throws LoaderException{
236
237     int counter=0;
238     for (int i = 0; i < vecVariableColumnTargetTableName.size(); i++) {
239       if (vecVariableColumnTargetTableName.get(i).toString().equalsIgnoreCase(
240           tableName)
241           && vecVariableColumnTargetTableID.get(i).toString().equalsIgnoreCase(
242           tableID)
243           && vecVariableColumnValueMode.get(i).toString().equalsIgnoreCase("Key")) {
244       int iPositionInVector = vecVariableName.indexOf(vecVariableColumnName.get(i).toString());
245       if (iPositionInVector != -1) {
246         counter=iPositionInVector;
247         strQueryWhere += vecVariableColumnTargetColumnName.get(i).toString();
248 //ZK change this 7.5.2004 from CheckType to configReaderTarget
249
if (!configReader.isNumber(vecVariableColumnTypes.get(i).toString())){
250           strQueryWhere += "= '" + "dummyVariableValue"
251                          +"' and ";
252           indexDummyVariableValue.add(String.valueOf(counter));
253         }else{
254           strQueryWhere += " = "+ "dummyVariableValue"
255                          + " and ";
256           indexDummyVariableValue.add(String.valueOf(counter));
257
258         }
259       }else {
260         logger.write("normal", "\tError: Cannot find value for variable column :"
261                         + vecVariableColumnName.get(i).toString());
262         LoaderException le = new LoaderException("Exception: ",
263                                                  (Throwable JavaDoc)(new Exception JavaDoc("Error: Cannot find value for variable column :")));
264         throw le;
265       }
266     }
267     }
268   }
269
270
271
272
273   /**
274    * This method read the value of strQueryWhere parameter
275    * @return value of parameter
276    */

277   public String JavaDoc getQueryWhere(){
278     return strQueryWhere;
279   }
280
281   /**
282    * This method read the value of indexDummyValue parameter
283    * @return value of parameter
284    */

285   public Vector getIndexDummyValue(){
286     return indexDummyValue;
287   }
288
289   /**
290     * This method read the value of indexDummyTransformationValue parameter
291     * @return value of parameter
292     */

293 //ZK added this for transformations
294
public Vector getTransformationKeyColumns(){
295      return indexDummyTransformationValue;
296    }
297   /**
298    * This method read the value of indexDummyRelationValue parameter
299    * @return value of parameter
300    */

301   public Vector getIndexDummyRelationValue(){
302     return indexDummyRelationValue;
303   }
304
305   /**
306    * This method read the value of indexDummyConstantValue parameter
307    * @return value of parameter
308    */

309   public Vector getIndexDummyConstantValue(){
310     return indexDummyConstantValue;
311   }
312
313   /**
314    * This method read the value of indexDummyVariableValue parameter
315    * @return value of parameter
316    */

317   public Vector getIndexDummyVariableValue(){
318     return indexDummyVariableValue;
319   }
320
321
322 }
Popular Tags