1 2 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 35 public class QueryWhereSet { 36 37 private String strQueryWhere=" where "; 38 private Vector vecColumnNames=null; 39 private Vector vecColumnTypes=null; 40 private String tableName=null; 41 private String 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 54 public QueryWhereSet(Vector vecColumnNames,Vector vecColumnTypes, 55 String tableName, String tableID ) { 56 this.vecColumnNames=vecColumnNames; 57 this.vecColumnTypes=vecColumnTypes; 58 this.tableName=tableName; 59 this.tableID=tableID; 60 } 61 62 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 strQueryWhere += vecColumnNames.get(l).toString(); 75 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 )e); 88 throw le; 89 } 90 } 91 } 92 } 93 } 94 } 95 102 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 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 )e); 124 throw le; 125 } 126 } 127 } 128 } 129 } 130 } 131 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 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 )e); 176 throw le; 177 } 178 } 179 } 180 181 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 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 )e); 211 throw le; 212 } 213 } 214 } 215 } 216 217 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 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 )(new Exception ("Error: Cannot find value for variable column :"))); 264 throw le; 265 } 266 } 267 } 268 } 269 270 271 272 273 277 public String getQueryWhere(){ 278 return strQueryWhere; 279 } 280 281 285 public Vector getIndexDummyValue(){ 286 return indexDummyValue; 287 } 288 289 293 public Vector getTransformationKeyColumns(){ 295 return indexDummyTransformationValue; 296 } 297 301 public Vector getIndexDummyRelationValue(){ 302 return indexDummyRelationValue; 303 } 304 305 309 public Vector getIndexDummyConstantValue(){ 310 return indexDummyConstantValue; 311 } 312 313 317 public Vector getIndexDummyVariableValue(){ 318 return indexDummyVariableValue; 319 } 320 321 322 } | Popular Tags |