001: /*
002: LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
003:
004:
005: Copyright (C) 2003 Together
006:
007: This library is free software; you can redistribute it and/or
008: modify it under the terms of the GNU Lesser General Public
009: License as published by the Free Software Foundation; either
010: version 2.1 of the License, or (at your option) any later version.
011:
012: This library is distributed in the hope that it will be useful,
013: but WITHOUT ANY WARRANTY; without even the implied warranty of
014: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: Lesser General Public License for more details.
016:
017: You should have received a copy of the GNU Lesser General Public
018: License along with this library; if not, write to the Free Software
019: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: package org.webdocwf.util.loader;
023:
024: import java.util.*;
025: import java.sql.*;
026: import org.webdocwf.util.loader.logging.*;
027:
028: /**
029: *
030: * QueryWhereSet class creates the where condition in sql statement
031: * @author Radoslav Dutina
032: * @version 1.0
033: */
034: public class QueryWhereSet {
035:
036: private String strQueryWhere = " where ";
037: private Vector vecColumnNames = null;
038: private Vector vecColumnTypes = null;
039: private String tableName = null;
040: private String tableID = null;
041: private Vector indexDummyValue = new Vector();
042: private Vector indexDummyRelationValue = new Vector();
043: private Vector indexDummyConstantValue = new Vector();
044: private Vector indexDummyVariableValue = new Vector();
045: private Vector indexDummyTransformationValue = new Vector();
046:
047: /**
048: * Construct object of QueryWhereSet class with associated parameters
049: * @param vecColumnNames is vector which contain column names
050: * @param vecColumnTypes is vector which contain column types
051: * @param tableName is the current table name
052: * @param tableID is ID of current table
053: */
054: public QueryWhereSet(Vector vecColumnNames, Vector vecColumnTypes,
055: String tableName, String tableID) {
056: this .vecColumnNames = vecColumnNames;
057: this .vecColumnTypes = vecColumnTypes;
058: this .tableName = tableName;
059: this .tableID = tableID;
060: }
061:
062: /**
063: * This method read the value of vecTempKeyColumns and sets the parameter strQueryWhere
064: * @param vecTempKeyColumns is the value of parameter
065: * @param configReaderTarget is ConfigReader object for target database
066: */
067: public void getKeyColumns(Vector vecTempKeyColumns,
068: ConfigReader configReaderTarget) throws LoaderException {
069:
070: for (int k = 0; k < vecTempKeyColumns.size(); k++) {
071: if (vecColumnNames.size() != 0) {
072: for (int l = 0; l < vecColumnNames.size(); l++) {
073: if (vecTempKeyColumns.get(k).toString()
074: .equalsIgnoreCase(
075: vecColumnNames.get(l).toString())) {
076: // int counter=l;
077: strQueryWhere += vecColumnNames.get(l)
078: .toString();
079: //ZK change this from CheckType to configReaderTarget
080: try {
081: if (!configReaderTarget
082: .isNumber(vecColumnTypes.get(l)
083: .toString())) {
084: strQueryWhere += " = '" + "dummyValue"
085: + "' and ";
086: indexDummyValue.add(String.valueOf(l));
087: } else {
088: strQueryWhere += " = " + "dummyValue"
089: + " and ";
090: indexDummyValue.add(String.valueOf(l));
091: }
092: } catch (LoaderException e) {
093: LoaderException le = new LoaderException(
094: "Exception:Type not present in conf file for target database, add it into conf file.",
095: (Throwable) e);
096: throw le;
097: }
098: }
099: }
100: }
101: }
102: }
103:
104: /**
105: * This method read the value of vecTempKeyTransformation and sets the parameter strQueryWhere
106: * @param transformationTargetColumns is Vector with target columns in for this transformation
107: * @param vecTempKeyTransformation is Vector with key columns
108: * @param transformationColumnTypes is Vector with target with column types
109: * @param configReaderTarget is ConfigReader object for target database
110: */
111: //ZK added this method for Transformations
112: public void getTransformationKeyColumns(
113: Vector transformationTargetColumns,
114: Vector vecTempKeyTransformation,
115: Vector transformationColumnTypes,
116: ConfigReader configReaderTarget) throws LoaderException {
117:
118: for (int k = 0; k < vecTempKeyTransformation.size(); k++) {
119: if (transformationTargetColumns.size() != 0) {
120: for (int l = 0; l < transformationTargetColumns.size(); l++) {
121: if (vecTempKeyTransformation.get(k).toString()
122: .equalsIgnoreCase(
123: transformationTargetColumns.get(l)
124: .toString())) {
125: strQueryWhere += transformationTargetColumns
126: .get(l).toString();
127: //ZK change this 7.5.2004 from CheckType to configReaderTarget
128: try {
129: if (!configReaderTarget
130: .isNumber(transformationColumnTypes
131: .get(l).toString())) {
132: strQueryWhere += " = '"
133: + "dummyTransformationValue"
134: + "' and ";
135: indexDummyTransformationValue
136: .add(String.valueOf(l));
137: } else {
138: strQueryWhere += " = "
139: + "dummyTransformationValue"
140: + " and ";
141: indexDummyTransformationValue
142: .add(String.valueOf(l));
143: }
144: } catch (LoaderException e) {
145: LoaderException le = new LoaderException(
146: "Exception:Type not present in conf file for target database, add it into conf file.",
147: (Throwable) e);
148: throw le;
149: }
150: }
151: }
152: }
153: }
154: }
155:
156: /**
157: * This method read the input parameters and sets the parameter strQueryWhere
158: * @param vecRelationKeyColumns is input parameter
159: * @param iRelationColumns is input parameter
160: * @param vecRelationColumnTargetTableName is input parameter
161: * @param vecRelationColumnTargetTableID is input parameter
162: * @param vecRelationColumnTargetColumnName is input parameter
163: * @param vecRelationKeyTypes is input parameter
164: * @param configReaderTarget is input parameter
165: */
166: public void getRelationKeyColumns(Vector vecRelationKeyColumns,
167: int iRelationColumns,
168: Vector vecRelationColumnTargetTableName,
169: Vector vecRelationColumnTargetTableID,
170: Vector vecRelationColumnTargetColumnName,
171: Vector vecRelationKeyTypes, ConfigReader configReaderTarget)
172: throws LoaderException {
173:
174: for (int k = 0; k < vecRelationKeyColumns.size(); k++) {
175: int counter = 0;
176: int iNumRelation = -1;
177: for (int p = 0; p < iRelationColumns; p++) {
178: if (vecRelationColumnTargetTableName.get(p).toString()
179: .equalsIgnoreCase(tableName)
180: && vecRelationColumnTargetTableID.get(p)
181: .toString().equalsIgnoreCase(tableID)
182: && vecRelationColumnTargetColumnName.get(p)
183: .toString().equalsIgnoreCase(
184: vecRelationKeyColumns.get(k)
185: .toString())) {
186: iNumRelation = p;
187: counter = p;
188: }
189: }
190: strQueryWhere += vecRelationKeyColumns.get(k).toString();
191: //ZK change this 7.5.2004 from CheckType to configReaderTarget
192: //TODO ZK change 11.6.2004 from vecRelationKeyColumns to vecRelationKeyTypes
193:
194: try {
195: if (configReaderTarget.isNumber(vecRelationKeyTypes
196: .get(k).toString())) {
197: strQueryWhere += " = " + "dummyRelationValue "
198: + " and ";
199: indexDummyRelationValue
200: .add(String.valueOf(counter));
201: } else {
202: strQueryWhere += " = '" + "dummyRelationValue"
203: + "' and ";
204: indexDummyRelationValue
205: .add(String.valueOf(counter));
206: }
207: } catch (LoaderException e) {
208: LoaderException le = new LoaderException(
209: "Exception:Type not present in conf file for target database, add it into conf file.",
210: (Throwable) e);
211: throw le;
212: }
213: }
214: }
215:
216: /**
217: * This method read the input parameters and sets the parameter strQueryWhere
218: * @param vecTempConstantColumns is input parameter
219: * @param vecTempConstantMode is input parameter
220: * @param vecTempConstantType is input parameter
221: * @param configReaderTarget is input parameter
222: */
223: public void getConstantKeyColumns(Vector vecTempConstantColumns,
224: Vector vecTempConstantMode, Vector vecTempConstantType,
225: ConfigReader configReaderTarget) throws LoaderException {
226:
227: int counter = 0;
228: for (int k = 0; k < vecTempConstantColumns.size(); k++) {
229: counter = k;
230: if (vecTempConstantMode.get(k).toString().equalsIgnoreCase(
231: "Key")) {
232: strQueryWhere += vecTempConstantColumns.get(k)
233: .toString();
234: //ZK change this 7.5.2004 from CheckType to configReaderTarget
235: try {
236: if (configReaderTarget.isNumber(vecTempConstantType
237: .get(k).toString())) {
238: strQueryWhere += " = " + "dummyConstantValue"
239: + " and ";
240: indexDummyConstantValue.add(String
241: .valueOf(counter));
242:
243: } else {
244: strQueryWhere += " = '" + "dummyConstantValue"
245: + "' and ";
246: indexDummyConstantValue.add(String
247: .valueOf(counter));
248:
249: }
250: } catch (LoaderException e) {
251: LoaderException le = new LoaderException(
252: "Exception:Type not present in conf file for target database, add it into conf file.",
253: (Throwable) e);
254: throw le;
255: }
256: }
257: }
258: }
259:
260: /**
261: ** This method read the input parameters and sets the parameter strQueryWhere
262: * @param vecVariableColumnTargetTableName is input parameter
263: * @param vecVariableColumnTargetTableID is input parameter
264: * @param vecVariableColumnValueMode is input parameter
265: * @param vecVariableName is input parameter
266: * @param vecVariableColumnName is input parameter
267: * @param vecVariableColumnTargetColumnName is input parameter
268: * @param vecVariableColumnTypes is input parameter
269: * @param logger is input parameter
270: * @param configReader is input parameter
271: * @throws LoaderException
272: */
273: public void getVariableKeyColumns(
274: Vector vecVariableColumnTargetTableName,
275: Vector vecVariableColumnTargetTableID,
276: Vector vecVariableColumnValueMode, Vector vecVariableName,
277: Vector vecVariableColumnName,
278: Vector vecVariableColumnTargetColumnName,
279: Vector vecVariableColumnTypes, Logger logger,
280: ConfigReader configReader) throws LoaderException {
281:
282: int counter = 0;
283: for (int i = 0; i < vecVariableColumnTargetTableName.size(); i++) {
284: if (vecVariableColumnTargetTableName.get(i).toString()
285: .equalsIgnoreCase(tableName)
286: && vecVariableColumnTargetTableID.get(i).toString()
287: .equalsIgnoreCase(tableID)
288: && vecVariableColumnValueMode.get(i).toString()
289: .equalsIgnoreCase("Key")) {
290: int iPositionInVector = vecVariableName
291: .indexOf(vecVariableColumnName.get(i)
292: .toString());
293: if (iPositionInVector != -1) {
294: counter = iPositionInVector;
295: strQueryWhere += vecVariableColumnTargetColumnName
296: .get(i).toString();
297: //ZK change this 7.5.2004 from CheckType to configReaderTarget
298: if (!configReader.isNumber(vecVariableColumnTypes
299: .get(i).toString())) {
300: strQueryWhere += "= '" + "dummyVariableValue"
301: + "' and ";
302: indexDummyVariableValue.add(String
303: .valueOf(counter));
304: } else {
305: strQueryWhere += " = " + "dummyVariableValue"
306: + " and ";
307: indexDummyVariableValue.add(String
308: .valueOf(counter));
309:
310: }
311: } else {
312: logger.write("normal",
313: "\tError: Cannot find value for variable column :"
314: + vecVariableColumnName.get(i)
315: .toString());
316: LoaderException le = new LoaderException(
317: "Exception: ",
318: (Throwable) (new Exception(
319: "Error: Cannot find value for variable column :")));
320: throw le;
321: }
322: }
323: }
324: }
325:
326: /**
327: * This method read the value of strQueryWhere parameter
328: * @return value of parameter
329: */
330: public String getQueryWhere() {
331: return strQueryWhere;
332: }
333:
334: /**
335: * This method read the value of indexDummyValue parameter
336: * @return value of parameter
337: */
338: public Vector getIndexDummyValue() {
339: return indexDummyValue;
340: }
341:
342: /**
343: * This method read the value of indexDummyTransformationValue parameter
344: * @return value of parameter
345: */
346: //ZK added this for transformations
347: public Vector getTransformationKeyColumns() {
348: return indexDummyTransformationValue;
349: }
350:
351: /**
352: * This method read the value of indexDummyRelationValue parameter
353: * @return value of parameter
354: */
355: public Vector getIndexDummyRelationValue() {
356: return indexDummyRelationValue;
357: }
358:
359: /**
360: * This method read the value of indexDummyConstantValue parameter
361: * @return value of parameter
362: */
363: public Vector getIndexDummyConstantValue() {
364: return indexDummyConstantValue;
365: }
366:
367: /**
368: * This method read the value of indexDummyVariableValue parameter
369: * @return value of parameter
370: */
371: public Vector getIndexDummyVariableValue() {
372: return indexDummyVariableValue;
373: }
374:
375: }
|