KickJava   Java API By Example, From Geeks To Geeks.

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


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  @authors:
20  Milosevic Sinisa sinisa@prozone.yu
21  Radoslav Dutina rale@prozone.co.yu
22  */

23
24 package org.webdocwf.util.loader;
25
26 import java.io.ByteArrayInputStream JavaDoc;
27 import java.io.ByteArrayOutputStream JavaDoc;
28 import java.io.File JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.InputStream JavaDoc;
31 import java.math.BigDecimal JavaDoc;
32 import java.net.URL JavaDoc;
33 import java.sql.Connection JavaDoc;
34 import java.sql.DriverManager JavaDoc;
35 import java.sql.PreparedStatement JavaDoc;
36 import java.sql.ResultSet JavaDoc;
37 import java.sql.ResultSetMetaData JavaDoc;
38 import java.sql.SQLException JavaDoc;
39 import java.sql.Statement JavaDoc;
40 import java.text.DateFormat JavaDoc;
41 import java.text.SimpleDateFormat JavaDoc;
42 import java.util.ArrayList JavaDoc;
43 import java.util.Date JavaDoc;
44 import java.util.HashMap JavaDoc;
45 import java.util.Hashtable JavaDoc;
46 import java.util.Iterator JavaDoc;
47 import java.util.List JavaDoc;
48 import java.util.Map JavaDoc;
49 import java.util.StringTokenizer JavaDoc;
50 import java.util.Vector JavaDoc;
51
52 import javax.xml.parsers.DocumentBuilder JavaDoc;
53 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
54
55 import org.w3c.dom.Document JavaDoc;
56 import org.w3c.dom.Element JavaDoc;
57 import org.w3c.dom.NamedNodeMap JavaDoc;
58 import org.w3c.dom.Node JavaDoc;
59 import org.w3c.dom.NodeList JavaDoc;
60 import org.webdocwf.util.loader.logging.Logger;
61 import org.webdocwf.util.loader.logging.StandardLogger;
62 import org.webdocwf.util.loader.transformation.QueryTransformationSet;
63 import org.webdocwf.util.loader.transformation.Transformation;
64 import org.webdocwf.util.loader.transformation.Transformations;
65 import org.xml.sax.SAXException JavaDoc;
66
67 /**
68  * <p>
69  * Loader class loads data from source database into target database using criteria
70  * set in XML file which is used as parameter. Also Loader can execute SQL statements
71  * which import from XML file. <br>
72  * All loading rolls are set in XML file. Some capabilities of this loader are:
73  * there could be more then one importDefinition and number of them is not limited, source
74  * and target database could be different, source database could be ASCII,Excel or Access file too,
75  * operator (the person or application which starts Loader) have to define.
76  * Restart mode with second parameter (optional).
77  * </p>
78  * <p>
79  * There are two possible ways to start Loader. The first is as stand alone application,
80  * the sintaxs is: <br>
81  * <code><B>java org.webdocwf.util.loader.Loader [-options] urlOfTheXmlFile.xml</B></code> <br>
82  * urlOfTheXmlFile.xml is URL of the XML file with loading criteria,<br>
83  * </p>
84  * <p>
85  * The second way is to start Loader as package, the sintax is:<br>
86  * <code><B>public Loader(String loadJobFileName, String mode, String userID, String logDirName,
87  * String logFileName, boolean restartIndicator, Map variableValues, String vendorFileName,
88  * boolean onErrorContinue, String additionalPaths, int commitCount, int returnCode);
89  * </code><br>
90  * ldr.load();</B>
91  * <br>
92  * If we want to execute Loader class without last for parameters, we must put null as these arguments
93  * </p>
94  * <p>
95  * When the Loader is started the log file is generated. Log file is txt file and its
96  * name defines date and time when the Loader is started. There are three Log modes:
97  * none - report only begining and finishing the application, and exceptions if there
98  * are any, normal - add to log importing blocks and full - with detailed report to
99  * operator.
100  * </p>
101  * <p>
102  * Another big adventage of Loader is its possibility to execute any SQL statements in target database.
103  * (creating database; creating, modifying and deleting tables...)
104  * </p>
105  * <p>
106  * XML file is the key part for loading criteria. XML tags define how the loading job will
107  * be done.
108  * </p>
109  */

110 public class Loader {
111 //-u admin -r -v defaultsprache=DE_AT ObjectLoader\DataCleaningExample.xml
112
int iValueColumns;
113   Vector JavaDoc vecValueColumnsTargetTables = new Vector JavaDoc();
114   //Vector vecTransformColumnsTargetTables = new Vector();
115
Vector JavaDoc vecSourceColumnName = new Vector JavaDoc();
116   Vector JavaDoc vecTargetColumnName = new Vector JavaDoc();
117   Vector JavaDoc vecValueMode = new Vector JavaDoc();
118   Vector JavaDoc vecTargetColumnValue = new Vector JavaDoc();
119   Vector JavaDoc vecTargetKeyColumnName = new Vector JavaDoc();
120   Vector JavaDoc vecVariableUseIDTableName = new Vector JavaDoc();
121   Vector JavaDoc vecVariableUseIDTableID = new Vector JavaDoc();
122   Vector JavaDoc vecVariableUseIDColumnName = new Vector JavaDoc();
123   Vector JavaDoc vecVariableUseIDValueMode = new Vector JavaDoc();
124   Vector JavaDoc vecVariableColumnName = new Vector JavaDoc();
125   Vector JavaDoc vecVariableColumnTargetTableName = new Vector JavaDoc();
126   Vector JavaDoc vecVariableColumnTargetTableID = new Vector JavaDoc();
127   Vector JavaDoc vecVariableColumnTargetColumnName = new Vector JavaDoc();
128   Vector JavaDoc vecVariableColumnValueMode = new Vector JavaDoc();
129   Vector JavaDoc vecVariableColumnTypes = new Vector JavaDoc();
130   Vector JavaDoc vecVariableTimesTableName = new Vector JavaDoc();
131   Vector JavaDoc vecVariableTimesTableID = new Vector JavaDoc();
132   Vector JavaDoc vecVariableTimesColumnName = new Vector JavaDoc();
133   Vector JavaDoc vecVariableTimesValueMode = new Vector JavaDoc();
134   int iConstantColumns;
135   Vector JavaDoc vecConstantTargetColumnName = new Vector JavaDoc();
136   Vector JavaDoc vecConstantValueMode = new Vector JavaDoc();
137   Vector JavaDoc vecConstantConstantValue = new Vector JavaDoc();
138   Vector JavaDoc vecConstantColumnTargetTableName = new Vector JavaDoc();
139   Vector JavaDoc vecConstantColumnTargetTableID = new Vector JavaDoc();
140   int iRelationColumns;
141   Vector JavaDoc vecRelationColumnSourceTableName = new Vector JavaDoc();
142   Vector JavaDoc vecRelationColumnSourceTableID = new Vector JavaDoc();
143   Vector JavaDoc vecRelationColumnSourceColumnName = new Vector JavaDoc();
144   Vector JavaDoc vecRelationColumnTargetTableName = new Vector JavaDoc();
145   Vector JavaDoc vecRelationColumnTargetColumnName = new Vector JavaDoc();
146   Vector JavaDoc vecRelationColumnTargetTableID = new Vector JavaDoc();
147   Vector JavaDoc vecRelationColumnRelationMode = new Vector JavaDoc();
148   int iTables;
149   Vector JavaDoc vecTableTableName = new Vector JavaDoc();
150   Vector JavaDoc vecTableTableID = new Vector JavaDoc();
151   Vector JavaDoc vecTableInsert = new Vector JavaDoc();
152   Vector JavaDoc vecTableTableMode = new Vector JavaDoc();
153   Vector JavaDoc vecTableOidLogic = new Vector JavaDoc();
154   Vector JavaDoc vecRelationSourceValue = new Vector JavaDoc();
155   Vector JavaDoc vecRelationSourceType = new Vector JavaDoc();
156   Vector JavaDoc vecTargetColumnType = new Vector JavaDoc();
157   Vector JavaDoc vecConstantColumnType = new Vector JavaDoc();
158   BigDecimal JavaDoc bdecOidNumber = new BigDecimal JavaDoc(0);
159   BigDecimal JavaDoc bdecOidNumber2000 = new BigDecimal JavaDoc(0);
160   String JavaDoc strLoaderJobFileName = "";
161   boolean bRestartIndicator;
162   Map JavaDoc mapVariableValues = new HashMap JavaDoc();
163   boolean bOnErrorContinue;
164   String JavaDoc strUserID = "";
165   String JavaDoc strLogDirName = "";
166   String JavaDoc strLogFileName = "";
167   String JavaDoc strVendorFileName = "";
168   String JavaDoc strAdditionalPaths = "";
169   String JavaDoc confJarStructure = "";
170
171   //interne Sinisa
172
boolean hasRestartCounter;
173   boolean hasUserID;
174   Vector JavaDoc vecRelationKeyColumns = new Vector JavaDoc();
175   Vector JavaDoc vecRelationKeyTypes = new Vector JavaDoc();
176   Vector JavaDoc vecSortValues = new Vector JavaDoc();
177
178   Vector JavaDoc vecSqlStmt = new Vector JavaDoc();
179   String JavaDoc strSourceDriverName = "";
180   String JavaDoc strTargetDriverName = "";
181
182   //conf file default
183
int iFirstColumnResult = 1;
184   int iTargetFirstColumnResult = 1;
185   //
186
Vector JavaDoc vecVariableName = new Vector JavaDoc();
187   Vector JavaDoc vecVariableValue = new Vector JavaDoc();
188   Vector JavaDoc vecVariablePrefix = new Vector JavaDoc();
189   Vector JavaDoc vecVariableSufix = new Vector JavaDoc();
190   Vector JavaDoc vecVariableOverride = new Vector JavaDoc();
191   Vector JavaDoc vecReplaceInConstants = new Vector JavaDoc();
192   Vector JavaDoc vecReplaceInSQL = new Vector JavaDoc();
193   Vector JavaDoc vecReplaceInData = new Vector JavaDoc();
194   Vector JavaDoc vecReplaceInJDBC = new Vector JavaDoc();
195   public static final String JavaDoc LOGMODE_NONE = "none";
196   public static final String JavaDoc LOGMODE_NORMAL = "normal";
197   public static final String JavaDoc LOGMODE_FULL = "full";
198   ByteArrayOutputStream JavaDoc foStreamTmp = new ByteArrayOutputStream JavaDoc();
199   boolean bReplaceInData = false;
200   int iColumnsInSourceTable = 0;
201   boolean isDefaultJdbc = false;
202   private String JavaDoc defaultLogMode = LOGMODE_NORMAL;
203   ArrayList JavaDoc logModes = new ArrayList JavaDoc();
204
205   private Cache cacheValues;
206 // private EchoElement echo;
207
private Logger logger;
208   private CounterColumns counterColumns;
209   private TimeWatch timeCounter;
210   private Transformations transformations;
211
212   //NEW CLASSES
213
private JdbcParametersElement jdbcParametersElement = new JdbcParametersElement();
214   private SqlElement sqlElement = new SqlElement();
215   private ConfigReader configReaderSource = new ConfigReader();
216   private ConfigReader configReaderTarget = new ConfigReader();
217   private LoaderJobAttrReader loaderJobReader = new LoaderJobAttrReader();
218   private ImportDefinitionElement importDefinitionElement = new ImportDefinitionElement();
219   private DataCleaning dataCleaning = new DataCleaning(configReaderTarget);
220
221   //rale
222
private String JavaDoc strQuerySet = "";
223   QueryWhereSet queryWhereSet = null;
224   QueryConstantSet queryConstantSet = null;
225   QueryTransformationSet queryTransformationSet = null;
226   
227   Hashtable JavaDoc queryStatement = new Hashtable JavaDoc();
228   Hashtable JavaDoc indexDValue = new Hashtable JavaDoc();
229   Hashtable JavaDoc indexDRelationValue = new Hashtable JavaDoc();
230   Hashtable JavaDoc indexConstantDValue = new Hashtable JavaDoc();
231   Hashtable JavaDoc indexDVariableValue = new Hashtable JavaDoc();
232   Hashtable JavaDoc indexDTransformationValue = new Hashtable JavaDoc();
233
234   Hashtable JavaDoc updateStatement = new Hashtable JavaDoc();
235   Hashtable JavaDoc indexDOverwrite = new Hashtable JavaDoc();
236   Hashtable JavaDoc indexDSetNull = new Hashtable JavaDoc();
237
238   Hashtable JavaDoc updateConstantStatement = new Hashtable JavaDoc();
239   Hashtable JavaDoc indexDConstantOver = new Hashtable JavaDoc();
240   Hashtable JavaDoc indexDConstantNull = new Hashtable JavaDoc();
241   //zk added this
242
Hashtable JavaDoc resultVector = new Hashtable JavaDoc();
243   Hashtable JavaDoc updateTransformationStatement = new Hashtable JavaDoc();
244   Hashtable JavaDoc indexDTransformationOver = new Hashtable JavaDoc();
245   Hashtable JavaDoc indexDTransformationNull = new Hashtable JavaDoc();
246   Hashtable JavaDoc indexDTransformationUpdate = new Hashtable JavaDoc();
247   //insert row
248
Hashtable JavaDoc queryInsertRow = new Hashtable JavaDoc();
249   Hashtable JavaDoc indexIsNotRelationsColumns = new Hashtable JavaDoc();
250   Hashtable JavaDoc pstmtForInsert = new Hashtable JavaDoc();
251   Hashtable JavaDoc pstmtColumnNames = new Hashtable JavaDoc();
252 // Hashtable pstmtColumnTypes = new Hashtable();
253

254   Vector JavaDoc pstmtKeys = new Vector JavaDoc();
255
256   //default value
257
Vector JavaDoc vecDefaultValue = new Vector JavaDoc();
258   Vector JavaDoc vecDefaultVariableValue = new Vector JavaDoc();
259   Vector JavaDoc vecDefaultVariableName = new Vector JavaDoc();
260   Vector JavaDoc vecDefaultRelationValue = new Vector JavaDoc();
261   Vector JavaDoc vecTempUserID = new Vector JavaDoc();
262   boolean userIDExists = false;
263   private int currentRow = 0;
264
265   //coy table
266
//source data which are not maped in to target data
267
Hashtable JavaDoc allSourceColumnNameNoMap = new Hashtable JavaDoc();
268   Hashtable JavaDoc allSourceColumnValueNoMap = new Hashtable JavaDoc();
269   Hashtable JavaDoc allSourceColumnTypeNoMap = new Hashtable JavaDoc();
270   Vector JavaDoc ImportDefinitionSourceColumnName = new Vector JavaDoc();
271   Vector JavaDoc ImportDefinitionTargetColumnName = new Vector JavaDoc();
272   private String JavaDoc currentJobName = "";
273   Vector JavaDoc vecCTAutoMapp = new Vector JavaDoc();
274   Vector JavaDoc vecCTDefaultMode = new Vector JavaDoc();
275   Vector JavaDoc vecBlobVector = new Vector JavaDoc();
276   Vector JavaDoc vecToHex = new Vector JavaDoc();
277   Vector JavaDoc vecFromHex = new Vector JavaDoc();
278
279   //caching the relations
280
RelationsCache relationsCache = new RelationsCache();
281   private Vector JavaDoc includeTables = new Vector JavaDoc();
282
283   //caching the 'row check' query
284
CheckRowCache checkRowCache = new CheckRowCache();
285
286   //restart counter
287
DataTransmition dataTransmition = new DataTransmition(importDefinitionElement);
288
289   //oid and version column name
290
private String JavaDoc currentOidColumnName = "oid";
291   private String JavaDoc currentVersionColumnName = "version";
292
293 // private PreparedStatementMethods pstmtMethods=new PreparedStatementMethods();
294
private Vector JavaDoc transformationsColumnNames = new Vector JavaDoc();
295   private Vector JavaDoc transformationsValueModes = new Vector JavaDoc();
296   private Vector JavaDoc transformationsColumnValueMode = new Vector JavaDoc();
297   private Vector JavaDoc transformationsColumnTypes = new Vector JavaDoc();
298   private Vector JavaDoc transformationsResultVectorTypes = new Vector JavaDoc();
299   private Vector JavaDoc resultVectorTypes = new Vector JavaDoc();
300   //ValidateSelectStmt validStmt = new ValidateSelectStmt();
301

302   //number of columns before transformation values from source query
303
private int iOffsetForTransColumns = 0;
304     
305   //values for transformations, used from source ResultSet for all transformation
306
//source coulmns
307
Vector JavaDoc transformationValues = new Vector JavaDoc();
308
309  
310   
311
312   /**
313    * Construct object Loader with an associated parameters.
314    * @param loadJobFileName defines xml input file.
315    * @param mode defines the default logmode. Possible values are "none", "normal" (is the default) and "full". Is "normal" otherwise -m none
316    * @param userID String which is name of user. This argument is used for writing userID into variable columns.
317    * If it is 'null' there is no define userID columns.
318    * @param logDirName defines the logfile directory. The default is the current working directory.
319        * @param logFileName defines the logfile name. The default is "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
320    * @param restartIndicator which is true if "restart" mode and false if "new" mode.
321    * @param variableValues Map defines variables used in variable columns.
322    * @param vendorFileName the filename of the XML DB-vendor configuration file. The default is "OctopusDBVendors.xml".
323    * @param onErrorContinue defines to set the default of "onErrorContinue" to "true". Is false otherwise.
324    * @param additionalPaths Extend the classpath with additional paths.
325    * @param commitCount Sets the default commit count. System default is "100".
326    * @param returnCode Sets the default error return code. System default is "1".
327    * @param includeTables defines tables which will be processed
328    */

329   public Loader(String JavaDoc loadJobFileName, String JavaDoc mode, String JavaDoc userID,
330       String JavaDoc logDirName, String JavaDoc logFileName, boolean restartIndicator,
331       Map JavaDoc variableValues, String JavaDoc vendorFileName, boolean onErrorContinue,
332       String JavaDoc additionalPaths, int commitCount, int returnCode,
333       String JavaDoc[] includeTables, String JavaDoc confJarStructure) {
334     this.strLoaderJobFileName = loadJobFileName;
335     //defines the log mode,
336
if (mode != null) {
337       if ( mode.equalsIgnoreCase("none") ||
338           mode.equalsIgnoreCase("normal") ||
339            mode.equalsIgnoreCase("full") )
340       {
341 // importDefinitionElement.strLogMode = mode;
342
this.defaultLogMode = mode;
343 // sqlElement.strLogMode = mode;
344
} //else {
345
// importDefinitionElement.strLogMode = "";
346
// sqlElement.strLogMode = "";
347
}
348
349     if (userID != null) {
350       this.strUserID = userID;
351       this.hasUserID = true;
352     } else
353       this.hasUserID = false;
354     if (logDirName != null)
355       this.strLogDirName = logDirName;
356     else {
357       File JavaDoc fCurrent = new File JavaDoc("");
358       this.strLogDirName = fCurrent.getAbsolutePath();
359     }
360     if (logFileName != null) {
361       this.strLogFileName = logFileName;
362     } else
363       this.strLogFileName = "default";
364     this.bRestartIndicator = restartIndicator;
365     if (this.bRestartIndicator == true)
366       this.hasRestartCounter = true;
367     else
368       this.hasRestartCounter = false;
369     this.mapVariableValues = variableValues;
370     if (vendorFileName != null) {
371       this.strVendorFileName = vendorFileName;
372     }
373     this.bOnErrorContinue = onErrorContinue;
374     if (additionalPaths != null) {
375       try {
376         this.strAdditionalPaths = additionalPaths;
377         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(this.strAdditionalPaths, ";");
378         URL JavaDoc[] urls = new URL JavaDoc[st.countTokens()];
379         int count = 0;
380         while (st.hasMoreTokens()) {
381           urls[count] = new File JavaDoc(st.nextElement().toString()).toURL();
382           count++;
383         }
384         for (int i = 0; i < urls.length; i++) {
385           OctopusClassLoader.addURL(urls[i]);
386         }
387       }
388       catch (Exception JavaDoc ne) {
389         ne.printStackTrace();
390       }
391     }
392     if (includeTables != null) {
393       for (int i = 0; i < includeTables.length; i++) {
394         this.includeTables.add(includeTables[i]);
395       }
396     }
397     importDefinitionElement.iCommitCount = commitCount;
398     ReturnCode.setDefaultErrorReturnCode(returnCode);
399     this.confJarStructure = confJarStructure;
400   }
401
402   /**
403    * Construct object Loader with an associated parameters.
404    * @param loadJobFileName defines xml input file.
405    * @param mode defines the default logmode. Possible values are "none", "normal" (is the default) and "full". Is "normal" otherwise -m none
406    * @param userID String which is name of user. This argument is used for writing userID into variable columns.
407    * If it is 'null' there is no define userID columns.
408    * @param logDirName defines the logfile directory. The default is the current working directory.
409        * @param logFileName defines the logfile name. The default is "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
410    * @param restartIndicator which is true if "restart" mode and false if "new" mode.
411    * @param variableValues Map defines variables used in variable columns.
412    * @param vendorFileName the filename of the XML DB-vendor configuration file. The default is "OctopusDBVendors.xml".
413    * @param onErrorContinue defines to set the default of "onErrorContinue" to "true". Is false otherwise.
414    * @param additionalPaths Extend the classpath with additional paths.
415    * @param commitCount Sets the default commit count. System default is "100".
416    * @param returnCode Sets the default error return code. System default is "1".
417    */

418   public Loader(String JavaDoc loadJobFileName, String JavaDoc mode, String JavaDoc userID,
419       String JavaDoc logDirName,
420       String JavaDoc logFileName, boolean restartIndicator,
421       Map JavaDoc variableValues,
422       String JavaDoc vendorFileName, boolean onErrorContinue,
423       String JavaDoc additionalPaths,
424       int commitCount, int returnCode) {
425
426     this(loadJobFileName, mode, userID, logDirName, logFileName, restartIndicator,
427         variableValues, vendorFileName, onErrorContinue, additionalPaths,
428         commitCount, returnCode, null, null);
429
430   }
431
432   /**
433    * Construct object Loader with an associated parameters.
434    * @param loadJobFileName defines xml input file.
435    * @param mode defines the default logmode. Possible values are "none", "normal" (is the default) and "full". Is "normal" otherwise -m none
436    * @param userID String which is name of user. This argument is used for writing userID into variable columns.
437    * If it is 'null' there is no define userID columns.
438    * @param logDirName defines the logfile directory. The default is the current working directory.
439        * @param logFileName defines the logfile name. The default is "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
440    * @param restartIndicator which is true if "restart" mode and false if "new" mode.
441    * @param variableValues Map defines variables used in variable columns.
442    * @param vendorFileName the filename of the XML DB-vendor configuration file. The default is "OctopusDBVendors.xml".
443    * @param onErrorContinue defines to set the default of "onErrorContinue" to "true". Is false otherwise.
444    * @param additionalPaths Extend the classpath with additional paths.
445    * @param commitCount Sets the default commit count. System default is "100".
446    * @param returnCode Sets the default error return code. System default is "1".
447    */

448   public Loader(String JavaDoc loadJobFileName, String JavaDoc mode, String JavaDoc userID,
449       String JavaDoc logDirName,
450       String JavaDoc logFileName, boolean restartIndicator,
451       Map JavaDoc variableValues,
452       String JavaDoc vendorFileName, boolean onErrorContinue,
453       String JavaDoc additionalPaths,
454       int commitCount, int returnCode, String JavaDoc[] includeTables) {
455
456     this(loadJobFileName, mode, userID, logDirName, logFileName, restartIndicator,
457         variableValues, vendorFileName, onErrorContinue, additionalPaths,
458         commitCount, returnCode, includeTables, null);
459
460   }
461
462   /**
463    * Construct object Loader with an associated parameters.
464    * @param loadJobFileName defines xml input file.
465    * @param mode defines the default logmode. Possible values are "none", "normal" (is the default) and "full". Is "normal" otherwise -m none
466    * @param userID String which is name of user. This argument is used for writing userID into variable columns.
467    * If it is 'null' there is no define userID columns.
468    * @param logDirName defines the logfile directory. The default is the current working directory.
469        * @param logFileName defines the logfile name. The default is "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
470    * @param restartIndicator which is true if "restart" mode and false if "new" mode.
471    * @param variableValues Map defines variables used in variable columns.
472    * @param vendorFileName the filename of the XML DB-vendor configuration file. The default is "OctopusDBVendors.xml".
473    * @param onErrorContinue defines to set the default of "onErrorContinue" to "true". Is false otherwise.
474    * @param additionalPaths Extend the classpath with additional paths.
475    * @param commitCount Sets the default commit count. System default is "100".
476    * @param returnCode Sets the default error return code. System default is "1".
477    */

478   public Loader(String JavaDoc loadJobFileName, String JavaDoc mode, String JavaDoc userID,
479       String JavaDoc logDirName,
480       String JavaDoc logFileName, boolean restartIndicator,
481       Map JavaDoc variableValues,
482       String JavaDoc vendorFileName, boolean onErrorContinue,
483       String JavaDoc additionalPaths,
484       int commitCount, int returnCode, String JavaDoc confJarStructure) {
485
486     this(loadJobFileName, mode, userID, logDirName, logFileName, restartIndicator,
487         variableValues, vendorFileName, onErrorContinue, additionalPaths,
488         commitCount, returnCode, null, confJarStructure);
489
490   }
491
492   /**
493    * Method addClassPath adds additional class paths into system classpath property
494    * @param oldClassPath - System classpath;
495    * @param add - additional class paths.
496    * @return value of parameter classPath
497    */

498   private String JavaDoc addClassPath(String JavaDoc oldClassPath, String JavaDoc add) {
499
500     String JavaDoc classPath = oldClassPath;
501     if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
502       if (!classPath.trim().endsWith(";"))
503         classPath += ";";
504       add = add.replace('\n', '\\');
505       add = add.replace('\t', '\\');
506       add = add.replace('\b', '\\');
507       add = add.replace('\r', '\\');
508       add = add.replace('\f', '\\');
509       classPath = classPath.concat(add);
510     } else {
511       if (!classPath.trim().endsWith(":"))
512         classPath += ":";
513       add = add.replace('\n', '/');
514       add = add.replace('\t', '/');
515       add = add.replace('\b', '/');
516       add = add.replace('\r', '/');
517       add = add.replace('\f', '/');
518       classPath = classPath.concat(add);
519
520     }
521     return classPath;
522   }
523
524   /**
525    * Public constructor of Loader class. Constructor set value for loadJobFileName attribute.
526    * Class set all other attributes to the default values.
527    * @param loadJobFileName Name of loadJob import XML file.
528    *
529    */

530   public Loader(String JavaDoc loadJobFileName) {
531     this(loadJobFileName, null);
532   }
533
534   /**
535    * Public constructor of Loader class. Constructor set value for loadJobFileName attribute.
536    * Class set all other attributes to the default values.
537    * @param loadJobFileName Name of loadJob import XML file.
538    *
539    */

540   public Loader(String JavaDoc loadJobFileName, String JavaDoc confJarStructure) {
541     this.strLoaderJobFileName = loadJobFileName;
542 // importDefinitionElement.strLogMode = "";
543
this.hasUserID = false;
544     File JavaDoc fCurrent = new File JavaDoc("");
545     this.strLogDirName = fCurrent.getAbsolutePath();
546     this.strLogFileName = "default";
547     this.bRestartIndicator = false;
548     this.hasRestartCounter = false;
549     this.bOnErrorContinue = false;
550     importDefinitionElement.iCommitCount = 100;
551     ReturnCode.setDefaultErrorReturnCode(1);
552     this.confJarStructure = confJarStructure;
553   }
554
555   /**
556    * Read value of loadJobFileName attribute.
557    * @return String value of loadFileName attribute
558    */

559   public String JavaDoc getLoadJobFileName() {
560     return this.strLoaderJobFileName;
561   }
562
563   /**
564    * This method sets value of loadJobFileName attribute.
565    * @param loadJobFileName loadJob XML file name
566    */

567   public void setLoadJobFileName(String JavaDoc loadJobFileName) {
568     this.strLoaderJobFileName = loadJobFileName;
569   }
570
571   /**
572    * Read value of Mode(LogMode) attribute.
573    * @return value of attribute.
574    */

575 // public String getMode() {
576
// return importDefinitionElement.strLogMode;
577
// }
578

579   /**
580    * This method sets value of Mode attribute.
581    * @param mode define Log mode. Possible values are:
582    * Loader.LOGMODE_NONE, Loader.LOGMODE_NORMAL, Loader.LOGMODE_FULL.
583    */

584 // public void setMode(String mode) {
585
// importDefinitionElement.strLogMode = mode;
586
// }
587

588   /**
589    * Read value of userID attribute.
590    * @return value of attribute.
591    */

592   public String JavaDoc getUserID() {
593     return this.strUserID;
594   }
595
596   /**
597    * This method sets value of userID attribute.
598    * @param userID attribute.
599    */

600   public void setUserID(String JavaDoc userID) {
601     this.strUserID = userID;
602   }
603
604   /**
605    * Read value of logDirName attribute
606    * @return value of attribute
607    */

608   public String JavaDoc getLogDirName() {
609     return this.strLogDirName;
610   }
611
612   /**
613    * This method sets value of logDirName attribute.
614    * @param logDirName value of attribute.
615    */

616   public void setLogDirName(String JavaDoc logDirName) {
617     this.strLogDirName = logDirName;
618   }
619
620   /**
621    * Read value of logFileName attribute.
622    * @return value of attribute.
623    */

624   public String JavaDoc getLogFileName() {
625     return this.strLogFileName;
626   }
627
628   /**
629    * This method sets value of logFileName attribute.
630    * @param logFileName value of attribute.
631    */

632   public void setLogFileName(String JavaDoc logFileName) {
633     this.strLogFileName = logFileName;
634   }
635
636   /**
637    * Read value of restartIndicator attribute.
638    * @return value of attribute.
639    */

640   public boolean getRestartIndicator() {
641     return this.bRestartIndicator;
642   }
643
644   /**
645    * This method sets value of restartIndicator attribute.
646    * @param restartIndicator value of attribute.
647    */

648   public void setRestartIndicator(boolean restartIndicator) {
649     this.bRestartIndicator = restartIndicator;
650   }
651
652   /**
653    * Read value of variableValues attribute.
654    * @return value of attribute.
655    */

656   public Map JavaDoc getVariableValues() {
657     return this.mapVariableValues;
658   }
659
660   /**
661    * This method sets value of variableValues attribute.
662    * @param variableValue value of attribute.
663    */

664   public void setVariableValues(Map JavaDoc variableValue) {
665     this.mapVariableValues = variableValue;
666   }
667
668   /**
669    * Read value of vendorFileName.
670    * @return value of attribute.
671    */

672   public String JavaDoc getVendorFileName() {
673     return this.strVendorFileName;
674   }
675
676   /**
677    * This method sets value of vendorFileName attribute.
678    * @param vendorFileName value of attribute.
679    */

680   public void setVendorFileName(String JavaDoc vendorFileName) {
681     this.strVendorFileName = vendorFileName;
682   }
683
684   /**
685    * read value of onErrorContinue attribute.
686    * @return value of attribute.
687    */

688   public boolean getOnErrorContinue() {
689     return this.bOnErrorContinue;
690   }
691
692   /**
693    * This method sets value of onErrorContinue attribute.
694    * @param onErrorContinue value of attribute.
695    */

696   public void setOnErrorContinue(boolean onErrorContinue) {
697     this.bOnErrorContinue = onErrorContinue;
698   }
699
700   /**
701    * Read value of additionalPaths attribute.
702    * @return value of attribute.
703    */

704   public String JavaDoc getAdditionalPaths() {
705     return this.strAdditionalPaths;
706   }
707
708   /**
709    * This method sets value of additionalPaths attribute.
710    * @param additionalPaths value of attribute.
711    */

712   public void setAdditionalPaths(String JavaDoc additionalPaths) {
713     this.strAdditionalPaths = additionalPaths;
714     String JavaDoc strClassPath = System.getProperty("java.class.path");
715     strClassPath = this.addClassPath(strClassPath, this.strAdditionalPaths);
716     try {
717       this.getClass().getClassLoader().loadClass(strClassPath);
718     }
719     catch (ClassNotFoundException JavaDoc ne) {
720       ne.printStackTrace();
721     }
722 // System.setProperty("java.class.path", strClassPath);
723
}
724
725   /**
726    * Read value of commitCount attribute.
727    * @return value of attribute.
728    */

729   public int getCommitCount() {
730     return importDefinitionElement.iCommitCount;
731   }
732
733   /**
734    * This method sets value of commitCount attribute.
735    * @param commitCount value of attribute.
736    */

737   public void setCommitCount(int commitCount) {
738     importDefinitionElement.iCommitCount = commitCount;
739   }
740
741   /**
742    * Read value of default error return code attribute.
743    * @return value of attribute.
744    */

745   public int getDefaultReturnCode() {
746     return ReturnCode.getDefaultErrorReturnCode();
747   }
748
749   /**
750    * This method sets value of default error return code attribute.
751    * @param code is value of attribute.
752    */

753   public void setDefaultReturnCode(int code) {
754     ReturnCode.setDefaultErrorReturnCode(code);
755   }
756
757   /**
758    * This method set value of includeJobs parameter
759    * @param include_Tables is value of parameter
760    */

761   public void setIncludedJobs(String JavaDoc include_Tables[]) {
762     for (int i = 0; i < include_Tables.length; i++) {
763       includeTables.add(include_Tables[i]);
764     }
765   }
766
767   /**
768    * This method read value of includeJobs parameter
769    * @return value of parameter
770    */

771   public String JavaDoc[] getIncludedJobs() {
772     String JavaDoc ret[] = new String JavaDoc[this.includeTables.size()];
773     for (int i = 0; i < includeTables.size(); i++) {
774       ret[i] = includeTables.get(i).toString();
775     }
776     return ret;
777   }
778   /**
779      * This method read value of confJarStructure parameter
780      * @return value of parameter
781      */

782   public String JavaDoc getConfJarStructure(){
783   
784      return this.confJarStructure;
785   }
786   /**
787    * This method read value of defaultLogMode parameter
788    * @return value of parameter
789    */

790   public String JavaDoc getDefaultLogMode(){
791   
792        return this.defaultLogMode;
793   }
794   /**
795    * Main method Loader with an associated XML, restart mode (optional) i user (optional).
796    * Main method controls parameters, it they are OK starts load method, but if
797    * they aren't makes alert.
798    * Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
799    * Options:
800        * -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.
801    * -r starts the Loader in restart mode after abnormal termination in a prior execution.
802    * -u defines the current UserID used in UserID value columns.
803    * -v defines variables used in variable columns.
804    * -l defines the logfile directory. The default is the current working directory.
805    * -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'.
806        * -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'.
807    * -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise.
808    * -p Extend the classpath with additional paths.
809    * -c Sets the default commit count. System default is '100'.
810    * -rc Sets the default error return code. System default is '1'.
811    * -it Sets the table names which will be proccesed
812    * @param argv represents input parmeters
813    */

814   public static void main(String JavaDoc argv[]) {
815     String JavaDoc loadJobFileName = null;
816     String JavaDoc mode = null;
817     String JavaDoc userID = null;
818     String JavaDoc logDirName = null;
819     String JavaDoc logFileName = null;
820     boolean restartIndicator = false;
821     Map JavaDoc variableValues = null;
822     String JavaDoc strVariableValues = null;
823     String JavaDoc vendorFileName = null;
824     boolean onErrorContinue = false;
825     String JavaDoc additionalPaths = null;
826     int defaultReturnCode = 1;
827     int commitCount = 0;
828     String JavaDoc[] includeTables = null;
829     String JavaDoc confJarStructure = null;
830
831     if (argv.length > 0 && argv.length < 26) {
832       loadJobFileName = argv[argv.length - 1];
833       for (int i = 0; i < argv.length - 1; i = i + 1) {
834         if (argv[i].equalsIgnoreCase("-m"))
835           mode = argv[++i];
836         else if (argv[i].equalsIgnoreCase("-r"))
837           restartIndicator = true;
838         else if (argv[i].equalsIgnoreCase("-u"))
839           userID = argv[++i];
840         else if (argv[i].equalsIgnoreCase("-l"))
841           logDirName = argv[++i];
842         else if (argv[i].equalsIgnoreCase("-f"))
843           logFileName = argv[++i];
844         else if (argv[i].equalsIgnoreCase("-d"))
845           vendorFileName = argv[++i];
846         else if (argv[i].equalsIgnoreCase("-e"))
847           onErrorContinue = true;
848         else if (argv[i].equalsIgnoreCase("-p"))
849           additionalPaths = argv[++i];
850         else if (argv[i].equalsIgnoreCase("-c"))
851           commitCount = (new Integer JavaDoc(argv[++i])).intValue();
852         else if (argv[i].equalsIgnoreCase("-v")) {
853           strVariableValues = argv[++i];
854           variableValues = new HashMap JavaDoc(convertToMap(strVariableValues));
855         } else if (argv[i].equalsIgnoreCase("-rc")) {
856           defaultReturnCode = (new Integer JavaDoc(argv[++i])).intValue();
857           ReturnCode.isParameter = true;
858         } else if (argv[i].equalsIgnoreCase("-it")) {
859           String JavaDoc array = argv[++i];
860           StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(array, ";");
861           includeTables = new String JavaDoc[st.countTokens()];
862           int pos = 0;
863           while (st.hasMoreTokens()) {
864             includeTables[pos] = st.nextToken();
865             pos++;
866           }
867         } else if (argv[i].equalsIgnoreCase("-cjs")) {
868           confJarStructure = argv[++i];
869         }
870       }
871     } else
872       printUsage();
873     Loader l = new Loader(loadJobFileName, mode, userID, logDirName,
874                logFileName, restartIndicator, variableValues, vendorFileName,
875                onErrorContinue, additionalPaths, commitCount, defaultReturnCode,
876                includeTables, confJarStructure);
877     try {
878       l.load();
879       BufferOctopusClass.getInstance().writeToBuffer(String.valueOf(ReturnCode.getOKReturnCode()));
880     }
881     catch (LoaderException le) {
882       BufferOctopusClass.getInstance().writeToBuffer(le.getCause() + "\n");
883       BufferOctopusClass.getInstance().writeToBuffer(String.valueOf(ReturnCode.getErrorReturnCode()));
884       System.exit(ReturnCode.getErrorReturnCode());
885     }
886   }
887
888   /**
889    * put your documentation comment here
890    */

891   static void printUsage() {
892     System.out.println("Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
893     System.out.println(" Options:");
894     System.out.println(
895         " -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.");
896     System.out.println(
897         " -r starts the Loader in restart mode after abnormal termination in a prior execution. \n");
898     System.out.println(" -u defines the current UserID used in UserID value columns. \n");
899     System.out.println(" -v defines variables used in variable columns. \n");
900     System.out.println(
901         " -l defines the logfile directory. The default is the current working directory. \n");
902     System.out.println(
903         " -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n");
904     System.out.println(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n");
905     System.out.println(
906         " -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n");
907     System.out.println(" -p Extend the classpath with additional paths \n");
908     System.out.println(" -c Sets the default commit count. System default is '100'. \n");
909     System.out.println(" -rc Sets the default error return code. System default is '1'. \n");
910     System.out.println(" -it Sets the table names which will be proccesed ");
911     System.exit(ReturnCode.getErrorReturnCode());
912   }
913
914   /**
915    * Method load is main method in class Loader. It is used to load data from the source table into
916    * target tables and(or) execute SQL statements. Loading parameters are set in XML file. During loading,
917    * load status is printed on the screen and also put into log file.
918    * If there is an error Exception "LoaderException" is thrown.
919    * @throws LoaderException
920    */

921   public void load() throws LoaderException {
922     int iImportJobs = 0;
923     int iCopyTable = 0;
924     int iConnection = 0;
925     int iSqlTags = 0;
926     int iEchoElements = 0;
927     int iLastImportDefinition = 0;
928     Vector JavaDoc vecXmlElements = new Vector JavaDoc();
929     Vector JavaDoc vecJDBCTargetConnections = new Vector JavaDoc();
930
931     //initializing logger
932
//videti jos oko ulaznih parametara, iz main methode ili is xml fajla
933
ParseLoggerParam loggerParam = new ParseLoggerParam(this.strLoaderJobFileName);
934     String JavaDoc logClassName = loggerParam.getLogClassName();
935     
936     String JavaDoc pathToLoggerConf = loggerParam.getPathToLoggerConf();
937     String JavaDoc strLoggerParam = "";
938     boolean standardLogger = false;
939     try {
940       this.logger = (org.webdocwf.util.loader.logging.Logger)Class.forName(logClassName).
941                     newInstance();
942       if (pathToLoggerConf != null && pathToLoggerConf.length() != 0)
943         strLoggerParam = pathToLoggerConf;
944       else
945         strLoggerParam = this.strLogDirName + ";" + this.strLogFileName;
946     }
947     catch (Exception JavaDoc e) {
948       this.logger = new StandardLogger();
949       strLoggerParam = this.strLogDirName + ";" + this.strLogFileName;
950       standardLogger = true;
951     }
952
953     try {
954       logger.configure(strLoggerParam);
955       logger.setEnabledLogLevels(this.defaultLogMode);
956       if (standardLogger == true) {
957 // if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
958
this.logger.write("normal", "Default (Standard) Logger is load.");
959 // }
960
}
961
962     }
963     catch (Exception JavaDoc ex) {
964       String JavaDoc msg = "Error while configuring logger.";
965       LoaderException le = new LoaderException(msg + "\n" + ex.getMessage(), (Throwable JavaDoc)ex);
966       BufferOctopusClass.getInstance().writeToBuffer(msg + "\n" + ex.getMessage() + "\n");
967       //this.logger.write("normal", msg + "\n" + ex.getMessage() + "\n");
968
this.logger.write("full", le.getStackTraceAsString());
969       throw le;
970     }
971
972     this.timeCounter = new TimeWatch();
973
974 // if (!this.echo.createLog(this.strLogDirName, this.strLogFileName))
975
// this.echo.setLogFile(new File(this.strLogDirName, this.strLogFileName));
976
// this.createLog(this.strLogFileName);
977

978     jdbcParametersElement.setLogger(this.logger);
979     jdbcParametersElement.setConfigReaderSource(this.configReaderSource);
980     jdbcParametersElement.setLoaderJobPath(this.strLoaderJobFileName);
981
982     configReaderSource.setLogger(this.logger);
983     configReaderTarget.setLogger(this.logger);
984     configReaderSource.setConfJarStructure(this.confJarStructure);
985     configReaderTarget.setConfJarStructure(this.confJarStructure);
986
987     loaderJobReader.setLogger(this.logger);
988     loaderJobReader.setDefaultOnErrorContinue(this.bOnErrorContinue);
989     sqlElement.setLogger(this.logger);
990     sqlElement.setLoaderJob(this.loaderJobReader);
991     sqlElement.setConfigReader(this.configReaderTarget);
992     sqlElement.setJdbcParametersElement(this.jdbcParametersElement);
993     checkRowCache.setLogger(this.logger);
994     dataTransmition.setLogger(this.logger);
995
996     
997 // if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
998
this.logger.write("normal", "\nApplication is started.");
999 // }
1000

1001    this.timeCounter.setStartTime();
1002    ByteArrayInputStream JavaDoc inStream = null;
1003    ByteArrayOutputStream JavaDoc foStream = new ByteArrayOutputStream JavaDoc();
1004    // Loading XML file and replacing include tags
1005
LoaderXIncluder loaderInclude = new LoaderXIncluder(foStream);
1006    LocationOfException locationOfException = new LocationOfException(this.strLoaderJobFileName);
1007    loaderInclude.parseURI(this.strLoaderJobFileName);
1008    inStream = new ByteArrayInputStream JavaDoc(foStream.toByteArray());
1009
1010//for test only
1011
// try {
1012
// File file=new File("c:/Users/Rale/Octopus/ObjectLoader/InputStream.txt");
1013
// FileOutputStream fileLogr=new FileOutputStream(file);
1014
// if(file.exists())
1015
// file.delete();
1016
// fileLogr.write(foStream.toByteArray());
1017
// fileLogr.close();
1018
// } catch(Exception e) { System.out.println("File error"); }
1019

1020//part for validating input xml file
1021
try {
1022      OctopusValidator validator = new OctopusValidator();
1023      validator.validate(new ByteArrayInputStream JavaDoc(foStream.toByteArray()));
1024    }
1025    catch (Exception JavaDoc e) {
1026      this.logger.write("normal", "Sorry, validation error occurred . Message was: " + e.getMessage());
1027      
1028      BufferOctopusClass.getInstance().writeToBuffer(
1029          "Sorry, validation error occurred . Message was: " + e.getMessage());
1030      LoaderException le = new LoaderException("Exception:"+e.getMessage(),(Throwable JavaDoc)e);
1031            this.logger.write("full", le.getStackTraceAsString());
1032            throw le;
1033     
1034    }
1035// if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
1036
this.logger.write("normal", "\nXML document is valid.");
1037    
1038// }
1039

1040    // Import attribute values from variable tags from XML
1041
this.importVariable(inStream);
1042    // Setting bReplaceInData if there is even one ReplaceInData attribut
1043
// in variable tags
1044
for (int i = 0; i < this.vecReplaceInData.size(); i++) {
1045      if (this.vecReplaceInData.get(i).toString().equalsIgnoreCase("true"))
1046        bReplaceInData = true;
1047    }
1048    // Change variable values in SQL, JDBC and Constants Tags in XML
1049
this.foStreamTmp = foStream;
1050    foStream = new ByteArrayOutputStream JavaDoc();
1051    LoadVariable loadVariable = new LoadVariable(foStream, this);
1052    loadVariable.parseURI();
1053    //refresh inStream with replaced variables
1054
inStream = new ByteArrayInputStream JavaDoc(foStream.toByteArray());
1055    loaderJobReader.setDefaultLogMode(this.defaultLogMode);
1056    loaderJobReader.importLoaderJobAttributes(inStream);
1057    iImportJobs = this.parseImportJob(inStream);
1058    iCopyTable = this.parseCopyTable(inStream);
1059    iSqlTags = sqlElement.parseSql(inStream);
1060    iEchoElements = this.parseEcho(inStream);
1061    this.importRestartCounter(inStream);
1062    vecXmlElements = this.parseMainElements(inStream);
1063
1064    //setting the last number of importDefinition tag
1065
iLastImportDefinition = 0;
1066    for (int i = 0; i < vecXmlElements.size(); i++) {
1067      if (vecXmlElements.get(i).toString().equalsIgnoreCase("importDefinition"))
1068        iLastImportDefinition = i;
1069    }
1070    jdbcParametersElement.parseTargetJDBCParameters(inStream);
1071    DBConnectionManager connManager = new DBConnectionManager(jdbcParametersElement.
1072                                      getTargetConnections());
1073    Connection JavaDoc connToPools = null;
1074
1075    try {
1076      this.isDefaultJdbc = jdbcParametersElement.parseImportJDBCDefaultParameters(inStream);
1077
1078      if (this.strVendorFileName != null && !this.strVendorFileName.equals(""))
1079        configReaderTarget.setVendorFileName(this.strVendorFileName);
1080        //this can be erased!!!?
1081
configReaderTarget.readConfigValues(jdbcParametersElement.getTargetDBVendor(),
1082          jdbcParametersElement.getTargetDriverName(), "target");
1083      this.currentOidColumnName = configReaderTarget.getOidColumnName();
1084      this.currentVersionColumnName = configReaderTarget.getVersionColumnName();
1085
1086      if (jdbcParametersElement.getJDBCTargetParameterDriver().equals("") ||
1087          jdbcParametersElement.getJDBCTargetParameterDriver() == null)
1088        jdbcParametersElement.setJDBCTargetParameterDriver(configReaderTarget.getDriverClassName());
1089      Class.forName(jdbcParametersElement.getJDBCTargetParameterDriver());
1090
1091      int iImport = 0;
1092      int iCopy = 0;
1093      int iSql = 0;
1094      int iEcho = 0;
1095      //main loop
1096
for (int l = 0; l < (iImportJobs + iCopyTable + iSqlTags + iEchoElements); l++) {
1097        Object JavaDoc tempLogMode = this.logModes.get(l);
1098        if( tempLogMode != null && !tempLogMode.equals("") )
1099            this.logger.setEnabledLogLevels(tempLogMode.toString());
1100          else
1101           this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
1102          //reset global variables
1103
this.resetGlobalVariables();
1104        relationsCache.resetRelationsCache();
1105        checkRowCache.resetCheckRowCache();
1106// if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
1107
this.logger.write("normal",
1108              "\nImport job No. " + (iImport + iCopy + iSql + 1) + " is started.");
1109// }
1110

1111        if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) {
1112          this.logger.write("full", "Importing and parsing XML file is started.");
1113          //importing specific jdbc parameters if any exist
1114
this.parseAndImport(inStream, iImport);
1115          jdbcParametersElement.parseImportJDBCParameters(inStream, iImport + 1, "importDefinition");
1116
1117          configReaderSource.readConfigValues(jdbcParametersElement.getDbVendor(),
1118              jdbcParametersElement.getDriverName(), "source");
1119          configReaderTarget.readConfigValues(jdbcParametersElement.getTargetDBVendor(),
1120              jdbcParametersElement.getTargetDriverName(), "target");
1121// validStmt.setConfigReader(configReaderSource);
1122
this.currentOidColumnName = configReaderTarget.getOidColumnName();
1123          this.currentVersionColumnName = configReaderTarget.getVersionColumnName();
1124            
1125        }
1126        //rale 24.10.2003
1127
else if (vecXmlElements.get(l).toString().equalsIgnoreCase("copyTable")) {
1128          this.logger.write("full", "Importing and parsing XML file is started.");
1129          this.parseAndImport(inStream, iCopy);
1130          //this.logger.setEnabledLogLevels(importDefinitionElement.strCopyTableLogMode);
1131
jdbcParametersElement.parseImportJDBCParameters(inStream, iCopy + 1, "copyTable");
1132
1133          configReaderSource.readConfigValues(jdbcParametersElement.getDbVendor(),
1134              jdbcParametersElement.getDriverName(),
1135              "source");
1136          configReaderTarget.readConfigValues(jdbcParametersElement.getTargetDBVendor(),
1137              jdbcParametersElement.getTargetDriverName(),
1138              "target");
1139          this.currentOidColumnName = configReaderTarget.getOidColumnName();
1140          this.currentVersionColumnName = configReaderTarget.getVersionColumnName();
1141        } else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
1142          configReaderTarget.readConfigValues(jdbcParametersElement.getTargetDBVendor(),
1143              jdbcParametersElement.getTargetDriverName(), "target");
1144
1145          this.currentOidColumnName = configReaderTarget.getOidColumnName();
1146          this.currentVersionColumnName = configReaderTarget.getVersionColumnName();
1147
1148          //this don't send enything to logger (importSQLStatement)
1149
this.logger.write("full", "Importing and parsing XML file is started.");
1150          this.vecSqlStmt = sqlElement.importSQLStatement(inStream, iSql);
1151          //defining the log mode
1152
// if (!sqlElement.getSqlLogMode().equals("") && sqlElement.getSqlLogMode() != null)
1153
//this.logger.setEnabledLogLevels(sqlElement.getSqlLogMode());
1154
// else
1155
// this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
1156

1157          //importing specific jdbc parameters if any exist
1158
this.logger.write("full", "Importing and parsing XML file is started.");
1159          jdbcParametersElement.parseImportJDBCParameters(inStream, iSql + 1, "sql");
1160        }
1161        if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition") ||
1162            vecXmlElements.get(l).toString().equalsIgnoreCase("sql") ||
1163            vecXmlElements.get(l).toString().equalsIgnoreCase("copyTable")) {
1164
1165          if (jdbcParametersElement.getJDBCSourceParameterDriver().equals("") ||
1166              jdbcParametersElement.getJDBCSourceParameterDriver() == null)
1167            jdbcParametersElement.setJDBCSourceParameterDriver(configReaderSource.
1168                getDriverClassName());
1169
1170          if (jdbcParametersElement.getJDBCTargetParameterDriver().equals("") ||
1171              jdbcParametersElement.getJDBCTargetParameterDriver() == null)
1172            jdbcParametersElement.setJDBCTargetParameterDriver(configReaderTarget.
1173                getDriverClassName());
1174        }
1175        this.logger.write("full", "Importing and parsing XML file is finished.");
1176
1177        connManager.setLoaderJobPath(this.strLoaderJobFileName);
1178        connManager.setConnectionPrefix(configReaderTarget.getConnectionPrefix());
1179        connManager.setParsePermission(configReaderTarget.getFileSystemDatabase());
1180        
1181                try {
1182            connToPools = connManager.getConnection(jdbcParametersElement.
1183                      getJDBCTargetParameterConnection());
1184          //TODO ZK 17.6 2004. This make problem with Excel jdbc-odbc.
1185
connToPools.setAutoCommit(false);
1186        }catch (Exception JavaDoc ex) {
1187          String JavaDoc message = "Can't get connection to Target Database." + "\n" +
1188                           "Maybe connection "
1189                           + jdbcParametersElement.getJDBCTargetParameterConnection()
1190                           + " is wrong. ";
1191          LoaderException le = new LoaderException("SQLException: " + message + "\n" +
1192                               ex.getMessage() + "\n", (Throwable JavaDoc)ex);
1193                    this.logger.write("full", le.getStackTraceAsString());
1194          throw le;
1195        }
1196        if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) {
1197          if (importDefinitionElement.bRestartAutoCreate == true) {
1198            dataTransmition.createRestartCounterTable(connToPools);
1199          }
1200          this.currentJobName = "importDefinition";
1201          String JavaDoc importName = importDefinitionElement.strImportDefinitionName;
1202          boolean doJob = true;
1203          for (int i = 0; i < this.includeTables.size(); i++) {
1204            if (importName.equalsIgnoreCase(this.includeTables.get(i).toString())) {
1205              doJob = true;
1206              break;
1207            } else {
1208              doJob = false;
1209            }
1210          }
1211          if (doJob) {
1212            try {
1213              this.loadSource(connToPools);
1214             
1215            }
1216            catch (Exception JavaDoc ex) {
1217              //this.logger.write("normal", "\t" + ex.getMessage().toString());
1218
LoaderException le = new LoaderException("SQLException: ", (Throwable JavaDoc)ex);
1219                            this.logger.write("full", le.getStackTraceAsString());
1220              if (importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("true")) {
1221                this.logger.write("normal",
1222                    "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'");
1223              } else {
1224                this.logger.write("normal",
1225                    "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'");
1226                connManager.release("true");
1227                throw le;
1228              }
1229            }
1230            //release resources
1231
finally {
1232                for (int i = 0; i < pstmtForInsert.size(); i++) {
1233                  String JavaDoc key = pstmtKeys.get(i).toString();
1234                  PreparedStatement JavaDoc pstmt = (PreparedStatement JavaDoc)pstmtForInsert.get(key);
1235                  pstmt.close();
1236                }
1237                pstmtKeys.clear();
1238                pstmtForInsert.clear();
1239                //release transformations
1240
List JavaDoc transformations = this.transformations.getTransformations();
1241                for(int iCount = 0; iCount < transformations.size(); iCount++ ) {
1242                    ((Transformation)transformations.get(iCount)).release();
1243                }
1244            }
1245          } else
1246            this.logger.write("normal",
1247                "\tImportDefinition " + importName + " is excluded from process");
1248          //this.logger.setEnabledLogLevels("none");
1249
iImport++;
1250        }
1251        //rale 24.10.2003
1252
else if (vecXmlElements.get(l).toString().equalsIgnoreCase("copyTable")) {
1253          if (importDefinitionElement.bRestartAutoCreate == true) {
1254            dataTransmition.createRestartCounterTable(connToPools);
1255          }
1256          this.currentJobName = "copyTable";
1257          String JavaDoc importName = importDefinitionElement.strCopyTableName;
1258          boolean doJob = true;
1259          for (int i = 0; i < this.includeTables.size(); i++) {
1260            if (importName.equalsIgnoreCase(this.includeTables.get(i).toString())) {
1261              doJob = true;
1262              break;
1263            } else {
1264              doJob = false;
1265            }
1266          }
1267          if (doJob) {
1268            try {
1269              this.loadSourceCT(connToPools);
1270            }
1271            catch (Exception JavaDoc e) {
1272              //this.logger.write("normal", "\t" + e.getMessage());
1273
LoaderException le = new LoaderException("SQLException: ", (Throwable JavaDoc)e);
1274                            this.logger.write("full", le.getStackTraceAsString());
1275              if (importDefinitionElement.strCopyTableOnErrorContinue.equalsIgnoreCase("true")) {
1276                this.logger.write("normal",
1277                    "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'");
1278              } else {
1279                this.logger.write("normal",
1280                    "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'");
1281                connManager.release("true");
1282                throw le;
1283              }
1284            }
1285          } else {
1286            this.logger.write("normal", "\tCopyTable " + importName + " is excluded from process");
1287          }
1288// this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
1289
iCopy++;
1290        } else if (vecXmlElements.get(l).toString().equalsIgnoreCase("echo")) {
1291          this.currentJobName = "echo";
1292          logger.writeEcho(this.logger.getMessage(new Integer JavaDoc(iEcho).toString()));
1293          iEcho++;
1294        } else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
1295          this.currentJobName = "sql";
1296          String JavaDoc sqlName = sqlElement.getSqlName();
1297          boolean doJob = true;
1298          for (int i = 0; i < this.includeTables.size(); i++) {
1299            if (sqlName.equalsIgnoreCase(this.includeTables.get(i).toString())) {
1300              doJob = true;
1301              break;
1302            } else {
1303              doJob = false;
1304            }
1305          }
1306          if (doJob) {
1307            try {
1308              if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) {
1309                connToPools.setAutoCommit(true);
1310//ZK change this because of problems with onErrorContinue="true" and commit="true" in <sql ...> tag
1311
try{
1312                    this.executeSQLStatement(connToPools);
1313                }catch(Exception JavaDoc e){
1314                    throw e;
1315                }
1316                finally{
1317                    connToPools.setAutoCommit(false);
1318                }
1319              } else
1320                this.executeSQLStatement(connToPools);
1321            }
1322            catch (Exception JavaDoc e) {
1323              LoaderException le = new LoaderException("SQLException: ",
1324                                   (Throwable JavaDoc)e);
1325              //this.logger.write("normal", "\t" + e.getMessage());
1326
this.logger.write("full", le.getStackTraceAsString());
1327              if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase("true")) {
1328                this.logger.write("normal",
1329                    "\tError : Because OnErrorContinue Attribute is true application is not terminated");
1330              }
1331              else if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase("")&&
1332                  loaderJobReader.getDefaultOnErrorContinue()==true) {
1333
1334                this.logger.write("normal",
1335                    "\tError : Because OnErrorContinue Attribute is true application is not terminated");
1336              }
1337              else {
1338                this.logger.write("normal",
1339                    "\tError : Because OnErrorContinue Attribute is false application is terminated");
1340                connManager.release("true");
1341                throw le;
1342              }
1343            }
1344          } else {
1345            this.logger.write("normal", "\tSql statement " + sqlName + " is excluded from process");
1346          }
1347          iSql++;
1348// this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
1349
} else {
1350          //this.logger.write("normal",
1351
// "Error : Loader supports loading data up to maximum 3 SQL database");
1352
LoaderException le = new LoaderException("SQLException: ",
1353                               (Throwable JavaDoc) (new SQLException JavaDoc(
1354                               "Error : Loader supports loading data up to maximum 3 SQL database")));
1355              this.logger.write("full", le.getStackTraceAsString());
1356          if (connToPools != null)
1357            connManager.release("true");
1358          throw le;
1359        }
1360        
1361        if (!this.hasRestartCounter && iLastImportDefinition == l) {
1362          if (connToPools!=null && !connToPools.isClosed())
1363                 
1364            connToPools.commit();
1365        }
1366       
1367      }
1368       this.logger.setEnabledLogLevels(this.defaultLogMode);
1369       connManager.release("false");
1370        this.logger.write("normal", "All rows are commited.");
1371        this.logger.write("normal", "Application is finished.");
1372        this.logger.write("normal", "All jobs duration: " + this.timeCounter.getTotalTime());
1373    }
1374    catch (IOException JavaDoc e) {
1375      LoaderException le = new LoaderException("IOException: ", (Throwable JavaDoc)e);
1376      //this.logger.write("normal", e.getMessage());
1377
this.logger.write("full", le.getStackTraceAsString());
1378      throw le;
1379    }
1380    catch (ClassNotFoundException JavaDoc e) {
1381      LoaderException le = new LoaderException("ClassNotFoundException: ",
1382                           (Throwable JavaDoc)e);
1383      //this.logger.write("normal", le.getCause().toString());
1384
this.logger.write("full", le.getStackTraceAsString());
1385      
1386      throw le;
1387    }
1388    catch (SQLException JavaDoc e) {
1389      LoaderException le = new LoaderException("SQLException: ", (Throwable JavaDoc)e);
1390      //this.logger.write("normal", le.getCause().toString());
1391
this.logger.write("full", le.getStackTraceAsString());
1392      throw le;
1393    }
1394    catch (NullPointerException JavaDoc e) {
1395      LoaderException le = new LoaderException("NullPointerException: " +
1396                           e.getMessage(),
1397                           (Throwable JavaDoc)e);
1398      //this.logger.write("normal", le.getCause().toString());
1399
this.logger.write("full", le.getStackTraceAsString());
1400      throw le;
1401    }
1402    catch (SAXException JavaDoc e) {
1403      LoaderException le = new LoaderException("SAXException: ", (Throwable JavaDoc)e);
1404      //this.logger.write("normal", le.getCause().toString());
1405
this.logger.write("full", le.getStackTraceAsString());
1406      throw le;
1407    }
1408    catch (Exception JavaDoc e) {
1409      LoaderException le = new LoaderException("Exception: ", (Throwable JavaDoc)e);
1410      //this.logger.write("normal", le.getCause().toString());
1411
this.logger.write("full", le.getStackTraceAsString());
1412      throw le;
1413    }
1414    finally {
1415      try {
1416        if (connToPools != null && !connToPools.isClosed())
1417          connToPools.close();
1418        this.logger.close();
1419      }
1420      catch (SQLException JavaDoc e) {
1421        LoaderException le = new LoaderException("SQLException: ",
1422                             (Throwable JavaDoc)e);
1423        //this.logger.write("normal", le.getCause().toString());
1424
this.logger.write("full", le.getStackTraceAsString());
1425        throw le;
1426      }
1427    }
1428  }
1429
1430  /**
1431   * Method loadSourceCT is used to load data from the source table (Csv, MySql, MsSql, Exel...)
1432   * into target tables.
1433   * @param connTarget is connection object to target database
1434   * @throws java.lang.Exception
1435   */

1436  private void loadSourceCT(Connection JavaDoc connTarget) throws Exception JavaDoc {
1437
1438    this.timeCounter.setStartJobTime();
1439    DateFormat JavaDoc dfNow = DateFormat.getDateTimeInstance();
1440    Date JavaDoc currentDate = new Date JavaDoc();
1441
1442    this.logger.write("full", "\tloadSourceCT method is started.");
1443    this.logger.write("normal", "Copy Table " +
1444        importDefinitionElement.strCopyTableName
1445        + " is started at " + dfNow.format(currentDate) + ".");
1446
1447    Connection JavaDoc connSource = null;
1448    ResultSet JavaDoc rsetSource = null;
1449    ResultSet JavaDoc rsetTarget = null;
1450    Statement JavaDoc stmtSource = null;
1451    Statement JavaDoc stmtTarget = null;
1452        String JavaDoc logStatement = "";
1453    String JavaDoc strQuery = "";
1454    Vector JavaDoc vecNewColumnNames = new Vector JavaDoc();
1455    Vector JavaDoc vecNewColumnTypes = new Vector JavaDoc();
1456    Hashtable JavaDoc tmpColumnReader = new Hashtable JavaDoc();
1457
1458    boolean bOidLogicCurrentTable = new Boolean JavaDoc(importDefinitionElement.strCopyTableOidLogic).
1459                                    booleanValue();
1460    boolean isTOS = ! (importDefinitionElement.strObjectIDNameColumnName.equals(
1461                    "") || importDefinitionElement.strObjectIDNameColumnValue.equals(""));
1462    try {
1463      this.checkOidLogic(connTarget);
1464      if (configReaderSource.getRequiredUser()) {
1465        if (jdbcParametersElement.getJDBCSourceParameterUser().equals(""))
1466          this.inputUser(true);
1467        Class.forName(jdbcParametersElement.getJDBCSourceParameterDriver());
1468        connSource = DriverManager.getConnection(jdbcParametersElement.
1469                     getJDBCSourceParameterConnection(),
1470                     jdbcParametersElement.
1471                     getJDBCSourceParameterUser(),
1472                     jdbcParametersElement.
1473                     getJDBCSourceParameterPassword());
1474      } else {
1475        Class.forName(jdbcParametersElement.getJDBCSourceParameterDriver());
1476        connSource = DriverManager.getConnection(jdbcParametersElement.
1477                     getJDBCSourceParameterConnection());
1478      }
1479
1480      int iRowNumber = 0;
1481      boolean isEndFlag = false;
1482      stmtSource = connSource.createStatement();
1483      stmtTarget = connTarget.createStatement();
1484
1485      //setCursorName
1486
boolean setCursorName = false;
1487      if (!importDefinitionElement.setCursorNameCT.equalsIgnoreCase(""))
1488        setCursorName = new Boolean JavaDoc(importDefinitionElement.setCursorNameCT).booleanValue();
1489      else
1490        setCursorName = configReaderSource.getSetCursorNameEnabled();
1491
1492      if (setCursorName) {
1493        long cursorName = System.currentTimeMillis();
1494        stmtSource.setCursorName(String.valueOf(cursorName));
1495      }
1496      //setFetchSize
1497
boolean setFetchSize = false;
1498      if (!importDefinitionElement.setFetchSizeCT.equalsIgnoreCase(""))
1499        setFetchSize = new Boolean JavaDoc(importDefinitionElement.setFetchSizeCT).booleanValue();
1500      else
1501        setFetchSize = configReaderSource.getSetFetchSizeEnabled();
1502
1503      if (setFetchSize)
1504        stmtSource.setFetchSize(importDefinitionElement.iCopyTableCommitCount);
1505//ZK added this 5.4 2004
1506
//begin
1507
//next line will give me parameter getColumnsSupported from *conf.xml. It describe is getColumns() method is suported
1508
//by used driver
1509

1510       boolean columnsSuportedTarget = configReaderTarget.getColumnsSupported();
1511       boolean columnsSuportedSource = configReaderSource.getColumnsSupported();
1512
1513       strQuery = "select * from ";
1514
1515// sourceColumnCount is used out of try block also
1516
rsetSource = stmtSource.executeQuery(strQuery + importDefinitionElement.strCopyTableSourceTableName);
1517       int sourceColumnCount = rsetSource.getMetaData().getColumnCount();
1518       try {
1519          if (columnsSuportedSource){
1520            ResultSet JavaDoc rsetSourceTemp = connSource.getMetaData().
1521            getColumns( connSource.getCatalog(), null, importDefinitionElement.strCopyTableSourceTableName, "%" );
1522              while(rsetSourceTemp.next()){
1523                    vecNewColumnNames.add(rsetSourceTemp.getString(4));
1524              }
1525            rsetSourceTemp.close();
1526
1527         }else{
1528                //rsetSource and source column count are already maked above try block
1529
for (int i = 1; i < sourceColumnCount + 1; i++) {
1530                                vecNewColumnNames.add(rsetSource.getMetaData().getColumnName(i));
1531                    }
1532         }
1533
1534         if (columnsSuportedTarget){
1535            ResultSet JavaDoc rsetTargetTemp = connTarget.getMetaData().
1536                getColumns( connTarget.getCatalog(), null, importDefinitionElement.strCopyTableTargetTableName, "%" );
1537
1538            while (rsetTargetTemp.next()) {
1539                                String JavaDoc targetColumnName = rsetTargetTemp.getString(4);
1540                                String JavaDoc targetColumnType = rsetTargetTemp.getString(6);
1541                                tmpColumnReader.put(targetColumnName.toUpperCase(), targetColumnType);
1542                            }
1543            rsetTargetTemp.close();
1544
1545         }else{
1546                if (configReaderTarget.getMaxRowsSupported()){
1547                        stmtTarget.setMaxRows(1);
1548                }
1549                
1550                rsetTarget = stmtTarget.executeQuery(strQuery +
1551                                importDefinitionElement.strCopyTableTargetTableName);
1552                int targetColumnCount=0;
1553                targetColumnCount = rsetTarget.getMetaData().getColumnCount();
1554                for (int i = 1; i < targetColumnCount + 1; i++) {
1555                              String JavaDoc targetColumnName = rsetTarget.getMetaData().getColumnName(i);
1556                              String JavaDoc targetColumnType = rsetTarget.getMetaData().getColumnTypeName(i);
1557                              tmpColumnReader.put(targetColumnName.toUpperCase(), targetColumnType);
1558                          }
1559                rsetTarget.close();
1560         }
1561
1562
1563//same for both cases
1564
for (int i = 0; i < vecNewColumnNames.size(); i++) {
1565                 String JavaDoc columnName=vecNewColumnNames.get(i).toString().toUpperCase();
1566                 String JavaDoc tmpTargetColumnType = tmpColumnReader.get(columnName).toString();
1567                 vecNewColumnTypes.add(tmpTargetColumnType);
1568              }
1569
1570     }
1571
1572
1573
1574      catch (Exception JavaDoc ex) {
1575
1576        String JavaDoc msg = "In copy table job '" + importDefinitionElement.strCopyTableName + "'," +
1577                     " Source and Target table are not compatibile.";
1578        Exception JavaDoc e = new Exception JavaDoc(msg + "\n" + ex.getMessage());
1579        throw e;
1580      }
1581
1582      int currentBlock = 0;
1583      int blockNumber = 0;
1584      int bdecRowCount = 0;
1585      int currentVersion = 0;
1586      BigDecimal JavaDoc bdecCounter = new BigDecimal JavaDoc(0);
1587
1588      if (configReaderSource.getRowCountEnabled()) {
1589          String JavaDoc countSQL = "";
1590          try {
1591// countSQL = " select count(*) as \"counter\" from "
1592
// + importDefinitionElement.strCopyTableName;
1593
countSQL = " select count(*) from "
1594                  + importDefinitionElement.strCopyTableName;
1595              Statement JavaDoc stmtSourceCount = connSource.createStatement();
1596              ResultSet JavaDoc rsetSourceCount = stmtSourceCount.executeQuery(countSQL);
1597              rsetSourceCount.next();
1598// iRowNumber = rsetSourceCount.getInt("counter");
1599
iRowNumber = rsetSourceCount.getInt(configReaderSource.getFirstColumnResult());
1600              blockNumber = iRowNumber / importDefinitionElement.iCopyTableCommitCount + 1;
1601              rsetSourceCount.close();
1602              stmtSourceCount.close();
1603          }catch(Exception JavaDoc e) {
1604              this.logger.write(Logger.LOGMODE_NORMAL, "Error while execute count sql: "+countSQL);
1605          }
1606      }
1607
1608      boolean main = true;
1609      if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
1610        if (this.hasRestartCounter) {
1611          bdecCounter = dataTransmition.checkDataTransmition(connTarget, rsetSource,
1612                        this.currentJobName, configReaderTarget.getFirstColumnResult());
1613
1614          if (bdecCounter != null) {
1615            if (bdecCounter.toString().equalsIgnoreCase("0")) {
1616              //if is mycounter=0 in myrestart table escape this importdefinition
1617
main = false;
1618            }
1619          } else {
1620            bdecCounter = new BigDecimal JavaDoc(0);
1621          }
1622        }
1623      }
1624
1625      while (main) {
1626        //iCopyTableCommitCount (ImportDefinition or default (100))
1627
this.logger.write("normal", "Import block is started.");
1628        currentBlock++;
1629        if (configReaderSource.getRowCountEnabled()) {
1630          this.logger.write("normal", "Working... " + currentBlock + ". block of " + blockNumber);
1631        } else {
1632          this.logger.write("normal", "Working... " + currentBlock + ". block");
1633        }
1634        this.logger.write("full", "\tStarted from the " + bdecCounter.add(
1635            new BigDecimal JavaDoc(1)).toString() + ". row.");
1636        iRowNumber = 0;
1637
1638        QueryInsertRowCt queryInsertRowCt = new QueryInsertRowCt(
1639                                            bOidLogicCurrentTable,
1640                                            isTOS,
1641                                            vecNewColumnNames,
1642                                            vecNewColumnTypes,
1643                                            importDefinitionElement.strCopyTableTargetTableName,
1644                                            this.bdecOidNumber,
1645                                            this.currentOidColumnName,
1646                                            this.currentVersionColumnName,
1647                                            configReaderTarget.getOidDbType(),
1648                                            configReaderTarget.getVersionDbType(),
1649                                            configReaderTarget.getJavaTypeMapings());
1650
1651        String JavaDoc pstmtInsert = queryInsertRowCt.getPreperedStatementForInsert();
1652        PreparedStatement JavaDoc pstmt = connTarget.prepareStatement(pstmtInsert);
1653
1654        while (iRowNumber < importDefinitionElement.iCopyTableCommitCount) {
1655          if (!rsetSource.next()) {
1656            isEndFlag = true;
1657            break;
1658          }
1659          currentRow = iRowNumber;
1660          if (bOidLogicCurrentTable) {
1661            if (this.bdecOidNumber.compareTo(this.bdecOidNumber2000) == 0) {
1662              this.checkOidLogic(connTarget);
1663              this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal JavaDoc(1));
1664            } else {
1665              this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal JavaDoc(1));
1666            }
1667          }
1668          try {
1669            int mnemonic = -1;
1670            String JavaDoc insertForOut = pstmtInsert;
1671            for (int i = 1; i < sourceColumnCount + 1; i++) {
1672              String JavaDoc columnType=vecNewColumnTypes.get(i - 1).toString();
1673              String JavaDoc javaType =(String JavaDoc)configReaderTarget.getJavaTypeMapings().get(columnType.toUpperCase());
1674
1675              if(javaType == null) {
1676                                this.logger.write("normal", "There is no java type defined for sql type "+columnType.toUpperCase());
1677                                LoaderException le = new LoaderException("Exception:",new Exception JavaDoc("There is no java type defined for sql type "+columnType.toUpperCase()));
1678                                this.logger.write("full", le.getStackTraceAsString());
1679                                throw le;
1680              }
1681
1682
1683              int javaTypeInt=Integer.parseInt(javaType);
1684              if (javaTypeInt==1) {
1685                byte[] isBlob = rsetSource.getBytes(i);
1686                if (isBlob == null || isBlob.length == 0) {
1687                  pstmt.setBytes(i, null);
1688                  mnemonic = insertForOut.indexOf("?");
1689                  insertForOut = insertForOut.substring(0, mnemonic) + "BinaryObject(null)" +
1690                                 insertForOut.substring(mnemonic + 1);
1691                } else {
1692                  ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(isBlob);
1693                  //TODO see how to solve this on general way,best to make configurable which method will be called
1694
pstmt.setBytes(i, isBlob);
1695// pstmt.setBinaryStream(i,bais,isBlob.length);
1696

1697                  mnemonic = insertForOut.indexOf("?");
1698                  insertForOut = insertForOut.substring(0, mnemonic) + "BinaryObject" +
1699                                 insertForOut.substring(mnemonic + 1);
1700                }
1701              } else {
1702                String JavaDoc value = rsetSource.getString(i);
1703                if (value == null)
1704                  value = "null";
1705                if (bReplaceInData)
1706                  value = this.replaceInData(value);
1707
1708                if (javaTypeInt == 2) { //java.math.BigDecimal
1709
if (!value.equalsIgnoreCase("null")) {
1710                    BigDecimal JavaDoc number = new BigDecimal JavaDoc(0);
1711                    if (!value.equalsIgnoreCase(""))
1712                      number = new BigDecimal JavaDoc(value);
1713                    pstmt.setBigDecimal(i, number);
1714                  } else {
1715                    pstmt.setNull(i, java.sql.Types.DECIMAL);
1716                  }
1717                } else if (javaTypeInt == 3) { //java.lang.Double
1718
if (!value.equalsIgnoreCase("null")) {
1719                    double number = 0;
1720                    if (!value.equalsIgnoreCase(""))
1721                      number = Double.parseDouble(value);
1722                    pstmt.setDouble(i, number);
1723                  } else {
1724                    pstmt.setNull(i, java.sql.Types.DOUBLE);
1725                  }
1726                } else if (javaTypeInt == 4) { //java.lang.Float
1727
if (!value.equalsIgnoreCase("null")) {
1728                    float number = 0;
1729                    if (!value.equalsIgnoreCase(""))
1730                      number = Float.parseFloat(value);
1731                    pstmt.setFloat(i, number);
1732                  } else {
1733                    pstmt.setNull(i, java.sql.Types.FLOAT);
1734                  }
1735                } else if (javaTypeInt == 5) { //java.lang.Integer
1736
if (!value.equalsIgnoreCase("null")) {
1737                    int number = 0;
1738                    if (!value.equalsIgnoreCase(""))
1739                      number = Integer.parseInt(value);
1740                    pstmt.setInt(i, number);
1741                  } else {
1742                    pstmt.setNull(i, java.sql.Types.INTEGER);
1743                  }
1744
1745                } else if (javaTypeInt == 6) { //java.lang.Long
1746
if (!value.equalsIgnoreCase("null")) {
1747                    long number = 0;
1748                    if (!value.equalsIgnoreCase(""))
1749                      number = Long.parseLong(value);
1750                    pstmt.setLong(i , number);
1751                  } else {
1752                    pstmt.setNull(i, java.sql.Types.DOUBLE);
1753                  }
1754                } else if (javaTypeInt == 7) { //java.lang.Short
1755
if (!value.equalsIgnoreCase("null")) {
1756                    short number = 0;
1757                    if (!value.equalsIgnoreCase(""))
1758                      number = Short.parseShort(value);
1759                    pstmt.setShort(i , number);
1760                  } else {
1761                    pstmt.setNull(i , java.sql.Types.SMALLINT);
1762                  }
1763                } else if (javaTypeInt == 8) { //java.lang.String
1764
if (!value.equalsIgnoreCase("null")) {
1765                    //all '' back to ' (original value)
1766
if (value.indexOf("''") != -1) {
1767                      value = Utils.replaceAll(value, "''", "'");
1768                    }
1769                    pstmt.setString(i, value);
1770                  } else {
1771                    pstmt.setNull(i , java.sql.Types.VARCHAR);
1772                  }
1773                } else if (javaTypeInt == 9) { //java.sql.Date
1774
if (!value.equalsIgnoreCase("null")) {
1775                    pstmt.setString(i, value);
1776                  } else {
1777                    pstmt.setNull(i , java.sql.Types.DATE);
1778                  }
1779                } else if (javaTypeInt == 10) { //java.sql.Time
1780
if (!value.equalsIgnoreCase("null")) {
1781                    pstmt.setString(i, value);
1782                  } else {
1783                    pstmt.setNull(i, java.sql.Types.TIME);
1784                  }
1785
1786                } else if (javaTypeInt == 11) { //java.sql.Timestamp
1787
if (!value.equalsIgnoreCase("null")) {
1788                    pstmt.setString(i, value);
1789                  } else {
1790                    pstmt.setNull(i , java.sql.Types.TIMESTAMP);
1791                  }
1792
1793                } else if (javaTypeInt == 12) { //java.lang.Boolean
1794
if (!value.equalsIgnoreCase("null")) {
1795                    boolean bool = Boolean.getBoolean(value);
1796                    pstmt.setBoolean(i, bool);
1797                  } else {
1798                    //TODO test this peace of code
1799
pstmt.setNull(i , java.sql.Types.BIT);
1800                  }
1801                } else if (javaTypeInt == 13) { //java.lang.Byte
1802
if (!value.equalsIgnoreCase("null")) {
1803                    pstmt.setString(i, value);
1804                  } else {
1805                    pstmt.setNull(i, java.sql.Types.BIT);
1806                  }
1807                } else if (javaTypeInt == 14) { //java.lang.Object
1808
if (!value.equalsIgnoreCase("null")) {
1809                    pstmt.setString(i, value);
1810                  } else {
1811                    //TODO zoran pogledati ovo
1812
pstmt.setNull(i, java.sql.Types.NULL);
1813                    //pstmt.setString(i, null);
1814
}
1815                }
1816
1817                mnemonic = insertForOut.indexOf("?");
1818                insertForOut = insertForOut.substring(0, mnemonic) + value +
1819                               insertForOut.substring(mnemonic + 1);
1820
1821
1822
1823              } //end of main else
1824
} //end of for loop
1825
logStatement = insertForOut;
1826            this.logger.write("full", "\tQuery '" + insertForOut + "' will be executed");
1827            pstmt.executeUpdate();
1828            pstmt.clearParameters();
1829          }
1830          catch (Exception JavaDoc ex) {
1831            if (importDefinitionElement.strCopyTableOnErrorContinue.equalsIgnoreCase("true")) {
1832              dataCleaning.cleaningInsert(importDefinitionElement.strCopyTableTargetTableName,
1833                  connTarget, currentRow, "INSERT", ex.getMessage(),
1834                  "COPY TABLE", logStatement);
1835            } else {
1836              throw ex;
1837            }
1838          }
1839          this.logger.write("full", "\tinsertRow method is finished.");
1840          iRowNumber++;
1841        } // iRowNumber < importDefinitionElement.iCopyTableCommitCount
1842

1843        //restart counter table
1844
if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
1845          if (this.hasRestartCounter) {
1846            bdecCounter = bdecCounter.add(new BigDecimal JavaDoc(iRowNumber));
1847            dataTransmition.insertCounter(this.currentJobName, bdecCounter, connTarget);
1848          }
1849        }
1850        if (this.hasRestartCounter) {
1851       
1852          connTarget.commit();
1853          this.logger.write("normal", "Imported block is commited.");
1854          this.logger.write("full", Integer.toString(iRowNumber) + " rows are commited.");
1855        }
1856
1857        iRowNumber = 0;
1858        if (isEndFlag) {
1859          break;
1860        }
1861        pstmt.close();
1862      } //while(true)
1863

1864      strQuery = "";
1865      rsetSource.close();
1866// rsetTarget.close();
1867
stmtSource.close();
1868      stmtTarget.close();
1869      if (!connSource.isClosed())
1870        connSource.close();
1871
1872        //seting mycounter=0 in myrestart table (success)
1873
if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
1874        if (this.hasRestartCounter) {
1875          dataTransmition.resetRestartCounter(connTarget, this.currentJobName);
1876        }
1877      }
1878      currentDate = new Date JavaDoc();
1879      dfNow = DateFormat.getDateTimeInstance();
1880      this.logger.write("normal", "Copy table " + importDefinitionElement.strCopyTableName
1881          + " is finished at " + dfNow.format(currentDate) + ".");
1882      this.logger.write("normal", " Duration of copyTable:" +
1883          this.timeCounter.getJobTime());
1884    }
1885    catch (Exception JavaDoc e) {
1886      throw e;
1887    }
1888  }
1889
1890  /**
1891   * Method loadSource is used to load data from the source table (Csv, MySql, MsSql, Exel...)
1892   * into target tables. This method uses configuration file OctopusDbVendors.xml. Loading parameters are set in XML file. During loading,
1893   * load status is printed on the screen and also put into log file.
1894   * This method is used for loading data by rules which is defined in a single importDefinition.
1895   * If there is an error Exception "LoaderException" is thrown.
1896   * @param connTarget represents connection of target table.
1897   * @throws LoaderException
1898   */

1899  private void loadSource(Connection JavaDoc connTarget) throws LoaderException {
1900    int iRowNumber = 0;
1901    BigDecimal JavaDoc bdecCounter = new BigDecimal JavaDoc(0);
1902    BigDecimal JavaDoc k = new BigDecimal JavaDoc(0);
1903    Date JavaDoc currentDate = new Date JavaDoc();
1904    DateFormat JavaDoc dfNow = DateFormat.getDateTimeInstance();
1905    boolean columnsSuportedTarget = configReaderTarget.getColumnsSupported();
1906    this.timeCounter.setStartJobTime();
1907    this.logger.write("full", "\tloadSource method is started.");
1908    this.logger.write("normal", "Import definition " +
1909        importDefinitionElement.strImportDefinitionName
1910        + " is started at " + dfNow.format(currentDate) + ".");
1911    Connection JavaDoc connSource = null;
1912
1913    try {
1914
1915      for (int i = 0; i < this.iTables; i++) {
1916        this.counterColumns.setTargetColumnStartValues(this.vecTableTableName.
1917            get(i).toString(),
1918            this.vecTableTableID.get(i).toString(), connTarget,
1919            this.iTargetFirstColumnResult);
1920        this.counterColumns.counterColumnTypes(this.vecTableTableName.get(i).
1921            toString(),
1922            this.vecTableTableID.get(i).
1923            toString(),
1924            connTarget,
1925            this.iTargetFirstColumnResult, columnsSuportedTarget, configReaderTarget);
1926
1927      }
1928
1929      //source
1930
if (configReaderSource.getRequiredUser()) {
1931        if (jdbcParametersElement.getJDBCSourceParameterUser().equals(""))
1932          this.inputUser(true);
1933        Class.forName(jdbcParametersElement.getJDBCSourceParameterDriver());
1934        connSource = DriverManager.getConnection(jdbcParametersElement.
1935                     getJDBCSourceParameterConnection(),
1936                     jdbcParametersElement.getJDBCSourceParameterUser(),
1937                     jdbcParametersElement.getJDBCSourceParameterPassword());
1938
1939      } else {
1940        Class.forName(jdbcParametersElement.getJDBCSourceParameterDriver());
1941        connSource = DriverManager.getConnection(jdbcParametersElement.
1942                     getJDBCSourceParameterConnection());
1943      }
1944
1945      Statement JavaDoc stmtSource = null;
1946      stmtSource = connSource.createStatement();
1947
1948      //target
1949
if (importDefinitionElement.bObjectIDAutoCreate == true) {
1950        createObjectIDTable(connTarget);
1951        connTarget.commit();
1952      }
1953// Statement stmtTarget = connTarget.createStatement();
1954

1955      this.constantColumnTypes(connTarget);
1956      this.targetColumnTypes(connTarget);
1957      this.checkOidLogic(connTarget);
1958
1959      int currentBlock = 0;
1960      String JavaDoc strQueryWhere = "";
1961
1962      for (int i = 0; i < this.iTables; i++) {
1963        //ZK added 18.5.2004
1964
// QueryTransformationSet queryTransformationSet = null;
1965
// this.indexDTransformationOver = new Hashtable();
1966
// this.indexDTransformationOver = new Hashtable();
1967
// this.updateTransformationStatement = new Hashtable();
1968
//// end
1969
//ZK added this for transformations - 27.04.2004.
1970
ArrayList JavaDoc trans = this.transformations.getTransformations();
1971              Iterator JavaDoc iTrans = trans.iterator();
1972             
1973              while(iTrans.hasNext()) {
1974                  Transformation temp = (Transformation)iTrans.next();
1975            
1976                  //temp.setTargetParameters(this.vecTableTableName.get(i).toString(),this.vecTableTableID.get(i).toString());
1977
temp.transformationColumnTypes(connTarget,
1978                                                 this.iTargetFirstColumnResult,
1979                                                                                    columnsSuportedTarget, configReaderTarget);
1980                                  
1981              }
1982//end
1983
//ZK added this for transormations
1984
Vector JavaDoc pomTypes;
1985            Vector JavaDoc pomNames;
1986            Vector JavaDoc pomValueModes;
1987            Vector JavaDoc targetKeyColumnNames;
1988            Vector JavaDoc targetColumnNames;
1989            Vector JavaDoc targetColumnTypes;
1990            targetColumnNames = new Vector JavaDoc();
1991            targetKeyColumnNames = new Vector JavaDoc();
1992            Vector JavaDoc targetValueModes = new Vector JavaDoc();
1993            targetColumnTypes = new Vector JavaDoc();
1994            pomNames = new Vector JavaDoc();
1995            pomTypes = new Vector JavaDoc();
1996            pomValueModes = new Vector JavaDoc();
1997
1998                String JavaDoc tableId = this.vecTableTableID.get(i).toString();
1999                ArrayList JavaDoc transTableIDs = this.transformations.getTransformationsTableIDs();
2000                if (transTableIDs.contains(tableId)){
2001  
2002                     for (int j=0; j < trans.size();j++){
2003                         Transformation pom = (Transformation)trans.get(j);
2004                       targetColumnNames = pom.getTargetColumnNames(i);
2005                        targetColumnTypes = pom.getTargetColumnTypes(i);
2006                      targetKeyColumnNames = pom.getTargetKeyColumnNames(i);
2007                        targetValueModes = pom.getTargetValueModes(i);
2008                         
2009                         for (int o=0; o < targetColumnTypes.size();o++){
2010                            pomTypes.add(targetColumnTypes.get(o).toString());
2011                         }
2012                         for (int o=0; o < targetColumnNames.size();o++){
2013                            pomNames.add(targetColumnNames.get(o).toString());
2014                         }
2015                         for (int o=0; o < targetValueModes.size();o++){
2016                            pomValueModes.add(targetValueModes.get(o).toString());
2017                         }
2018                    }
2019                                          
2020                }
2021
2022            this.transformationsColumnTypes.add(pomTypes);
2023            this.transformationsColumnNames.add(pomNames);
2024            this.transformationsValueModes.add(pomValueModes);
2025//end
2026
boolean bOidLogicCurrentTable = new Boolean JavaDoc(this.vecTableOidLogic.get(i).
2027                                        toString()).booleanValue();
2028        boolean isTOS = ! (importDefinitionElement.strObjectIDNameColumnName.
2029                        equals("") ||
2030                        importDefinitionElement.strObjectIDNameColumnValue.
2031                        equals(""));
2032        boolean oid = false;
2033        if (bOidLogicCurrentTable && !isTOS)
2034          oid = true;
2035
2036          //source column data which are not maped to targetdatabase
2037
LoadAllSourceData allSourceData = null;
2038        Vector JavaDoc vecRelationColumns = this.vecRelationColumnTargetColumnName;
2039        Vector JavaDoc vecVariableColumns = this.vecVariableColumnTargetColumnName;
2040        Vector JavaDoc vecConstantColumns = (Vector JavaDoc)this.vecConstantTargetColumnName.get(i);
2041
2042        Vector JavaDoc vecUseIDColumns = this.vecVariableUseIDColumnName;
2043        Vector JavaDoc vecTimesColumns = this.vecVariableTimesColumnName;
2044
2045        String JavaDoc ctAutoMapColumns = this.vecCTAutoMapp.get(i).toString();
2046        String JavaDoc ctDefaultMode = this.vecCTDefaultMode.get(i).toString();
2047        String JavaDoc sourceTableName = importDefinitionElement.strImportDefinitionTableName;
2048//ZK change this. Added new parameter columnsSuportedTarget.
2049

2050          if (ctAutoMapColumns.equalsIgnoreCase("true")) {
2051          allSourceData = new LoadAllSourceData(connSource, sourceTableName,
2052                          ImportDefinitionSourceColumnName,
2053                          vecTableTableName.get(i).toString(),
2054                          connTarget, logger, vecRelationColumns,
2055                          vecVariableColumns, vecConstantColumns,
2056                          vecUseIDColumns, vecTimesColumns, columnsSuportedTarget,configReaderTarget);
2057        } else {
2058// stmtTarget.close();
2059
}
2060
2061        //source column data which are not maped to targetdatabase
2062
if (allSourceData != null) {
2063          String JavaDoc keySource = String.valueOf(i);
2064          allSourceColumnNameNoMap.put(keySource, allSourceData.getNoMapSourceColumnName());
2065          allSourceColumnTypeNoMap.put(keySource, allSourceData.getNoMapSourceColumnType());
2066          allSourceColumnValueNoMap.put(keySource, allSourceData.getNoMapSourceColumnValue());
2067        }
2068
2069        //set new column names, column types and value modes for column which are not maped in to
2070
//target columns
2071
if (allSourceData != null) {
2072          if (allSourceData.getNoMapSourceColumnName().size() > 0) {
2073            for (int o = 0; o < allSourceData.getNoMapSourceColumnName().size(); o++) {
2074              ( (Vector JavaDoc)this.vecTargetColumnName.get(i)).add(allSourceData.
2075                  getNoMapSourceColumnName().get(o).toString());
2076              ( (Vector JavaDoc)this.vecSourceColumnName.get(i)).add(allSourceData.
2077                  getNoMapSourceColumnName().get(o).toString());
2078              ( (Vector JavaDoc)this.vecToHex.get(i)).add("");
2079              ( (Vector JavaDoc)this.vecFromHex.get(i)).add("");
2080              ( (Vector JavaDoc)this.vecDefaultValue.get(i)).add("");
2081            }
2082            int map = Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString());
2083            int noMap = allSourceData.getNoMapSourceColumnName().size();
2084            int all = map + noMap;
2085            this.vecValueColumnsTargetTables.set(i, new Integer JavaDoc(all));
2086          }
2087        }
2088        if (allSourceData != null) {
2089          if (allSourceData.getNoMapSourceColumnName().size() > 0) {
2090            for (int o = 0; o < allSourceData.getNoMapSourceColumnName().size(); o++) {
2091              ( (Vector JavaDoc)this.vecValueMode.get(i)).add(ctDefaultMode);
2092            }
2093          }
2094        }
2095        if (allSourceData != null) {
2096          if (allSourceData.getNoMapSourceColumnType().size() > 0) {
2097            for (int o = 0; o < allSourceData.getNoMapSourceColumnType().size(); o++) {
2098              ( (Vector JavaDoc)this.vecTargetColumnType.get(i)).add(allSourceData.
2099                  getNoMapSourceColumnType().get(o).toString());
2100            }
2101          }
2102        }
2103
2104        Vector JavaDoc vecColumnNames = (Vector JavaDoc)this.vecTargetColumnName.get(i);
2105        Vector JavaDoc vecColumnTypes = (Vector JavaDoc)this.vecTargetColumnType.get(i);
2106        Vector JavaDoc vecValueModes = (Vector JavaDoc)this.vecValueMode.get(i);
2107
2108        //set query statement
2109
QuerySet querySet = new QuerySet(i, bOidLogicCurrentTable, isTOS,
2110                            vecColumnNames, vecTableTableName,
2111                            this.currentOidColumnName,
2112                            this.currentVersionColumnName);
2113
2114        //set query where statement
2115
queryWhereSet = new QueryWhereSet(vecColumnNames, vecColumnTypes,
2116                        vecTableTableName.get(i).toString(),
2117                        vecTableTableID.get(i).toString());
2118
2119        //set query update statement
2120
QueryUpdateSet queryUpdateSet = new QueryUpdateSet(vecColumnNames,
2121                                        vecColumnTypes,
2122                                        vecValueModes, vecTableTableName.get(i).toString(), oid,
2123                                        this.currentVersionColumnName, configReaderTarget);
2124
2125        if ( ( (Vector JavaDoc)this.vecTargetKeyColumnName.get(i)).size() > 0)
2126//ZK change this 7.5.2004. Because of new parameter in getKeyColumns
2127
queryWhereSet.getKeyColumns( (Vector JavaDoc)this.vecTargetKeyColumnName.get(
2128              i), configReaderTarget);
2129              
2130////ZK added this for transformations
2131
if ( targetKeyColumnNames.size() > 0)
2132                  queryWhereSet.getTransformationKeyColumns(targetColumnNames,
2133                                                            targetKeyColumnNames,
2134                                                            targetColumnTypes,
2135                                                            configReaderTarget);
2136////ZK end
2137

2138        
2139        if ( ( (Vector JavaDoc)this.vecRelationKeyColumns.get(i)).size() > 0)
2140          queryWhereSet.getRelationKeyColumns( (Vector JavaDoc)vecRelationKeyColumns.
2141              get(i), iRelationColumns,
2142              vecRelationColumnTargetTableName,
2143              vecRelationColumnTargetTableID,
2144              vecRelationColumnTargetColumnName,
2145              //TODO zoran, try this change, vecRelationKeyTypes to (Vector)vecRelationKeyTypes.get(i)
2146
(Vector JavaDoc)vecRelationKeyTypes.get(i), configReaderTarget);
2147        if ( ( (Vector JavaDoc)this.vecConstantTargetColumnName.get(i)).size() > 0)
2148          queryWhereSet.getConstantKeyColumns( (Vector JavaDoc)this.
2149              vecConstantTargetColumnName.get(i),
2150              (Vector JavaDoc)this.vecConstantValueMode.
2151              get(i),
2152              (Vector JavaDoc)this.
2153              vecConstantColumnType.get(i),
2154              configReaderTarget);
2155
2156        if (vecVariableColumnTargetTableName.size() > 0)
2157          queryWhereSet.getVariableKeyColumns(vecVariableColumnTargetTableName,
2158              vecVariableColumnTargetTableID,
2159              vecVariableColumnValueMode,
2160              vecVariableName,
2161              vecVariableColumnName,
2162              vecVariableColumnTargetColumnName,
2163              vecVariableColumnTypes, logger, configReaderTarget);
2164          //set insert row
2165

2166        InsertRowQuerySet insertRowQuerySet = new InsertRowQuerySet(connTarget,
2167                                              (Vector JavaDoc)this.vecTargetColumnName.get(i),
2168                                              (Vector JavaDoc)this.vecValueMode.get(i),
2169                                              vecTableTableName.get(i).toString(),
2170                                              vecTableTableID.get(i).toString(),
2171                                              i,
2172                                              (Vector JavaDoc)this.vecConstantTargetColumnName.get(i),
2173                                              vecVariableTimesTableName,
2174                                              vecVariableTimesTableID,
2175                                              vecVariableTimesColumnName,
2176                                              vecVariableColumnTargetTableName,
2177                                              vecVariableColumnTargetTableID,
2178                                              vecVariableColumnTargetColumnName,
2179                                              vecRelationColumnTargetColumnName,
2180                                              vecRelationColumnTargetTableName,
2181                                              vecRelationColumnTargetTableID,
2182                                              vecRelationColumnRelationMode,
2183                                              counterColumns,
2184                                              transformations,
2185                                              bOidLogicCurrentTable, isTOS,
2186                                              this.currentOidColumnName,
2187                                              this.currentVersionColumnName);
2188
2189        //set query constant statement
2190
if ( ( (Vector JavaDoc)this.vecConstantTargetColumnName.get(i)).size() > 0)
2191          queryConstantSet = new QueryConstantSet(vecTableTableName.get(i).
2192                             toString(),
2193                             (Vector JavaDoc)this.
2194                             vecConstantTargetColumnName.
2195                             get(i),
2196                             (Vector JavaDoc)this.
2197                             vecConstantValueMode.
2198                             get(i),
2199                             (Vector JavaDoc)this.
2200                             vecConstantColumnType.get(i),
2201                             configReaderTarget);
2202        strQuerySet = querySet.getQuerySet();
2203        strQueryWhere = queryWhereSet.getQueryWhere();
2204
2205        if (! (strQueryWhere.length() < 8)) {
2206          strQueryWhere = strQueryWhere.substring(0, strQueryWhere.length() - 4);
2207        } else {
2208          strQueryWhere = "";
2209        }
2210
2211
2212     if ( ( ((Vector JavaDoc)this.transformationsColumnNames).size() > 0))
2213            queryTransformationSet = new QueryTransformationSet(vecTableTableName.get(i).toString(),
2214                                                               (Vector JavaDoc)this.transformationsColumnNames.get(i),
2215                                                               (Vector JavaDoc)this.transformationsValueModes.get(i),
2216                                                               (Vector JavaDoc)this.transformationsColumnTypes.get(i),
2217                                                               configReaderTarget);
2218
2219//} //querySet+queryWhere
2220
String JavaDoc strQueryTarget = strQuerySet + strQueryWhere;
2221        String JavaDoc key = String.valueOf(i);
2222        Vector JavaDoc indexDommyValue = queryWhereSet.getIndexDummyValue();
2223        Vector JavaDoc indexDommyRelationValue = queryWhereSet.
2224                                         getIndexDummyRelationValue();
2225        Vector JavaDoc indexDommyConstantValue = queryWhereSet.
2226                                         getIndexDummyConstantValue();
2227        Vector JavaDoc indexDommyVariableValue = queryWhereSet.
2228                                         getIndexDummyVariableValue();
2229                                         
2230//ZK added this 28.4.2004 for transformations
2231
Vector JavaDoc indexDummyTransformationValue = queryWhereSet.
2232                                         getTransformationKeyColumns();
2233//ZK end
2234
queryStatement.put(key, strQueryTarget);
2235        indexDValue.put(key, indexDommyValue);
2236        indexDRelationValue.put(key, indexDommyRelationValue);
2237        indexConstantDValue.put(key, indexDommyConstantValue);
2238        indexDVariableValue.put(key, indexDommyVariableValue);
2239//ZK added this 28.4.2004 for transformations
2240
indexDTransformationValue.put(key, indexDummyTransformationValue);
2241//end
2242
//query update
2243
String JavaDoc strUpdateTarget = queryUpdateSet.getQueryUpdate();
2244        Vector JavaDoc indexDommyOverwrite = queryUpdateSet.getIndexDummyOverwrite();
2245        Vector JavaDoc indexDommySetNull = queryUpdateSet.getIndexDummySetNull();
2246          
2247        updateStatement.put(key, strUpdateTarget);
2248        indexDOverwrite.put(key, indexDommyOverwrite);
2249        indexDSetNull.put(key, indexDommySetNull);
2250        
2251        //query update constant columns
2252
if (queryConstantSet != null) {
2253          String JavaDoc strUpdateConstant = queryConstantSet.getQueryConstant();
2254          Vector JavaDoc indexConstantOver = queryConstantSet.getIndexDummyOverwrite();
2255          Vector JavaDoc indexConstantNull = queryConstantSet.getIndexDummyNull();
2256
2257          updateConstantStatement.put(key, strUpdateConstant);
2258          indexDConstantOver.put(key, indexConstantOver);
2259          indexDConstantNull.put(key, indexConstantNull);
2260        }
2261        
2262        if (queryTransformationSet != null) {
2263    
2264          String JavaDoc strUpdateTransformation = queryTransformationSet.getQueryTransformation();
2265          Vector JavaDoc indexTransformationOver = queryTransformationSet.getIndexDummyOverwrite();
2266          Vector JavaDoc indexTransformationNull = queryTransformationSet.getIndexDummyNull();
2267          Vector JavaDoc indexTransformationUpdate = queryTransformationSet.getIndexDummyUpdate();
2268          
2269          updateTransformationStatement.put(key, strUpdateTransformation);
2270          indexDTransformationOver.put(key, indexTransformationOver);
2271          indexDTransformationNull.put(key, indexTransformationNull);
2272          indexDTransformationUpdate.put(key, indexTransformationUpdate);
2273        }
2274        //query insert row
2275
String JavaDoc strInsertRow = insertRowQuerySet.getStrQuery();
2276        Vector JavaDoc indexRelations = insertRowQuerySet.getIndexDummyIsNotRelationsColumn();
2277        //prepare statement
2278
PreparedStatement JavaDoc pstmt = insertRowQuerySet.getPreparedStatementForInsert();
2279        Vector JavaDoc pstmtCNames = insertRowQuerySet.getColumnNames();
2280// Hashtable pstmtCTypes=insertRowQuerySet.getPreparedStatemetTypes();
2281

2282        //this vector keep tracking about key for prepareStmt...
2283
pstmtKeys.add(key);
2284        queryInsertRow.put(key, strInsertRow);
2285        indexIsNotRelationsColumns.put(key, indexRelations);
2286        pstmtForInsert.put(key, pstmt);
2287        pstmtColumnNames.put(key, pstmtCNames);
2288// pstmtColumnTypes.put(key,pstmtCTypes);
2289
}
2290
2291      String JavaDoc strQuery = "";
2292      // if we have select statement insted of table name
2293
if (importDefinitionElement.strImportDefinitionSelectStatement != null &&
2294          !importDefinitionElement.strImportDefinitionSelectStatement.equals("")) {
2295        strQuery = importDefinitionElement.strImportDefinitionSelectStatement;
2296// strQuery = this.replaceInSelectStatement(strQuery);
2297
//TODO Allow different order of columns which should be transformed
2298
//this part is for determine where columns for transformation are started in
2299
//source result set
2300
//In selectStatement, columns for transformation should be on the end, and they must
2301
//be in order same as in sourceColumn tags in all transformations.
2302
if(this.transformations.getTransformations().size() > 0) {
2303            SqlParser parser = new SqlParser();
2304            try {
2305                parser.parse(strQuery);
2306            } catch (Throwable JavaDoc e) {
2307                this.logger.write("full","Unable to parse sql query from 'selectStatement' attribute. This is needed by transformations if they exists.");
2308            }
2309            String JavaDoc[] columnNames = parser.getColumnNames();
2310            List JavaDoc allSourceColNames = this.transformations.getAllTransformationSourceColNames();
2311            for(int br1 = 0; br1 < columnNames.length; br1++) {
2312                for(int br2 = 0; br2 < allSourceColNames.size(); br2++) {
2313                    if( allSourceColNames.get(br2).toString().toUpperCase().equals( columnNames[br1] ) )
2314                        this.iOffsetForTransColumns = br1;
2315                        break;
2316                }
2317            }
2318        }
2319        
2320        if (!configReaderSource.getReadingOrderRelevant()) {
2321          int in = 0;
2322          int jn = 0;
2323          Vector JavaDoc vecVector = new Vector JavaDoc();
2324          while (in < this.iTables) {
2325            vecVector = (Vector JavaDoc)this.vecSourceColumnName.get(in);
2326            while (jn <
2327                Integer.parseInt(this.vecValueColumnsTargetTables.get(in).toString())) {
2328              jn++;
2329              this.iColumnsInSourceTable++;
2330            }
2331            jn = 0;
2332            in++;
2333          }
2334        }
2335      } else {
2336        //when table name is defined
2337
strQuery = this.querySource();
2338      }
2339
2340      if (strQuery.indexOf("order by") != -1) {
2341        if (checkSortColumns(connSource)) {
2342          this.logger.write("normal",
2343              "Error : Sort columns have more rows with equals values.");
2344          LoaderException le = new LoaderException("SQLException: ",
2345                               (Throwable JavaDoc) (new SQLException JavaDoc(
2346                               "Error : Sort columns have more rows with equals values.")));
2347            this.logger.write("full", le.getStackTraceAsString());
2348          throw le;
2349        }
2350      }
2351
2352      ResultSet JavaDoc rsetSource = null;
2353      int blockNumber = 0;
2354      boolean usingSelectStmt = false;
2355      if (importDefinitionElement.strImportDefinitionSelectStatement != null &&
2356          !importDefinitionElement.strImportDefinitionSelectStatement.equals("")) {
2357        usingSelectStmt = true;
2358      } else {
2359        if (configReaderSource.getRowCountEnabled()) {
2360          String JavaDoc countSQL = " select count(*) as \"counter\" from " +
2361                            importDefinitionElement.strImportDefinitionTableName;
2362          Statement JavaDoc stmtSourceCount = connSource.createStatement();
2363          ResultSet JavaDoc rsetSourceCount = stmtSourceCount.executeQuery(countSQL);
2364          rsetSourceCount.next();
2365          iRowNumber = rsetSourceCount.getInt("counter");
2366          blockNumber = iRowNumber / importDefinitionElement.iImportDefinitionCommitCount + 1;
2367          rsetSourceCount.close();
2368          stmtSourceCount.close();
2369        }
2370      }
2371      iRowNumber = 0;
2372
2373      //set the number of rows in result set
2374
//setCursorName
2375
boolean setCursorName = false;
2376      if (!importDefinitionElement.setCursorNameID.equalsIgnoreCase(""))
2377        setCursorName = new Boolean JavaDoc(importDefinitionElement.setCursorNameID).booleanValue();
2378      else
2379        setCursorName = configReaderSource.getSetCursorNameEnabled();
2380
2381      if (setCursorName) {
2382        long cursorName = System.currentTimeMillis();
2383        stmtSource.setCursorName(String.valueOf(cursorName));
2384      }
2385      //setFetchSize
2386
boolean setFetchSize = false;
2387      if (!importDefinitionElement.setFetchSizeID.equalsIgnoreCase(""))
2388        setFetchSize = new Boolean JavaDoc(importDefinitionElement.setFetchSizeID).booleanValue();
2389      else
2390        setFetchSize = configReaderSource.getSetFetchSizeEnabled();
2391
2392      if (setFetchSize)
2393        stmtSource.setFetchSize(importDefinitionElement.iImportDefinitionCommitCount);
2394
2395      this.logger.write("full", "\tQuery '" + strQuery + "' will be executed");
2396      rsetSource = stmtSource.executeQuery(strQuery);
2397
2398      //this parameter defines if restartCounter has seccessfuly ended
2399
boolean main = true;
2400      if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
2401        if (this.hasRestartCounter) {
2402          bdecCounter = dataTransmition.checkDataTransmition(connTarget, rsetSource,
2403                        this.currentJobName, configReaderTarget.getFirstColumnResult());
2404
2405          if (bdecCounter != null) {
2406            if (bdecCounter.toString().equalsIgnoreCase("0")) {
2407              //if is mycounter=0 in myrestart table escape this importdefinition
2408
main = false;
2409            }
2410          } else {
2411            bdecCounter = new BigDecimal JavaDoc(0);
2412          }
2413        }
2414
2415        if (!bdecCounter.toString().equalsIgnoreCase("0")) {
2416          int num1 = Integer.parseInt(bdecCounter.toString());
2417          int num2 = Integer.parseInt(this.bdecOidNumber.toString());
2418          this.bdecOidNumber = new BigDecimal JavaDoc(num1 + num2);
2419        }
2420      }
2421
2422      while (main) {
2423        boolean isEndFlag = false;
2424        this.logger.write("normal", "Import block is started.");
2425        currentBlock++;
2426        if (configReaderSource.getRowCountEnabled()) {
2427          if (!usingSelectStmt)
2428            this.logger.write("normal", "Working... " + currentBlock + ". block of " +
2429                blockNumber);
2430          else
2431            this.logger.write("normal", "Working... " + currentBlock + ". block");
2432        } else
2433          this.logger.write("normal", "Working... " + currentBlock + ". block");
2434        this.logger.write("full", "\tStarted from the " + bdecCounter.add(
2435            new BigDecimal JavaDoc(1)).toString() + ". row.");
2436        int bdecRowCount = 0;
2437        while (iRowNumber < importDefinitionElement.iImportDefinitionCommitCount) {
2438          if (!rsetSource.next()) {
2439            isEndFlag = true;
2440            break;
2441          }
2442          currentRow = iRowNumber;
2443          boolean readingOrderRelevant = false;
2444          if (configReaderSource.getReadingOrderRelevant())
2445            readingOrderRelevant = true;
2446
2447          for (int i = 0; i < this.iTables; i++) {
2448            Vector JavaDoc vecVektor = new Vector JavaDoc();
2449            this.vecBlobVector.clear();
2450
2451//only for microsoft driver
2452
Hashtable JavaDoc orderRelevantColumnValues = new Hashtable JavaDoc();
2453            if (readingOrderRelevant) {
2454              int orderRelevantColumnCount = rsetSource.getMetaData().getColumnCount();
2455              for (int j = 1; j < orderRelevantColumnCount + 1; j++) {
2456                String JavaDoc orderRelevantColumnName = rsetSource.getMetaData().getColumnName(j);
2457                orderRelevantColumnName = orderRelevantColumnName.toUpperCase();
2458                    Object JavaDoc orderRelevantColumnValue;
2459                if( configReaderSource.isDate( rsetSource.getMetaData().getColumnTypeName(j) ) ) {
2460                    orderRelevantColumnValue = rsetSource.getDate(j);
2461                }else if( configReaderSource.isBinaryObject( rsetSource.getMetaData().getColumnTypeName(j) ) ) {
2462                        orderRelevantColumnValue = rsetSource.getBytes(j);
2463                    }
2464                 else {
2465                        orderRelevantColumnValue = rsetSource.getString(j);
2466                }
2467                if (orderRelevantColumnValue == null) {
2468                  orderRelevantColumnValues.put(orderRelevantColumnName, "null");
2469                } else {
2470                  orderRelevantColumnValues.put(orderRelevantColumnName, orderRelevantColumnValue);
2471                }
2472              }
2473            }
2474            //Read data from source
2475
//selectStatement=XXX
2476
if (importDefinitionElement.strImportDefinitionSelectStatement != null &&
2477                !importDefinitionElement.strImportDefinitionSelectStatement.equals("")) {
2478              //for value columns
2479
Vector JavaDoc srcNames = new Vector JavaDoc();
2480              srcNames = (Vector JavaDoc)this.vecSourceColumnName.get(i);
2481              String JavaDoc readValue = "";
2482              for (int s = 0; s < srcNames.size(); s++) {
2483                if (srcNames.get(s) != null) {
2484                  String JavaDoc columnName = srcNames.get(s).toString();
2485                  if (!readingOrderRelevant)
2486                    readValue = rsetSource.getString(columnName);
2487                  else {
2488                    columnName = columnName.toUpperCase();
2489                    //TODO Should readValue be String or Object
2490
readValue = orderRelevantColumnValues.get(columnName).toString();
2491                  }
2492                  parseInputData(readValue, vecVektor, rsetSource, i, columnName, s + 1,
2493                      readingOrderRelevant, orderRelevantColumnValues);
2494                }
2495              }
2496// orderRelevantColumnValues.clear();
2497
//for transformations
2498
this.transformationValues.clear();
2499                    for (int j = this.iOffsetForTransColumns+1; j < (this.iOffsetForTransColumns +
2500                           this.transformations.getTransformationSourceColumsCnt() + 1
2501                           ); j++) {
2502                Object JavaDoc value = "";
2503                String JavaDoc columnName = rsetSource.getMetaData().getColumnName(j);
2504                if (!readingOrderRelevant) {
2505                  if (this.iFirstColumnResult == 0) {
2506                    value = rsetSource.getString(j - 1);
2507                  } else {
2508                    value = rsetSource.getString(j);
2509                  }
2510                } else {
2511                  columnName = columnName.toUpperCase();
2512                  value = orderRelevantColumnValues.get(columnName);
2513                }
2514                        this.transformationValues.add(value);
2515              }
2516              orderRelevantColumnValues.clear();
2517            } else {
2518              //When tableName is defined, tableName=XXX
2519
//skip previous tables
2520
int iCounterCol = 0;
2521              for (int m = 0; m < i; m++) {
2522                iCounterCol = iCounterCol +
2523                              Integer.parseInt(this.vecValueColumnsTargetTables.get(m).toString())
2524                              //+
2525
//Integer.parseInt(this.vecTransformColumnsTargetTables.get(m).toString())
2526
;
2527              }
2528              iCounterCol++;
2529                  //for value columns
2530
for (int j = iCounterCol; j < (iCounterCol +
2531                           Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString())
2532                                    //+
2533
//Integer.parseInt(this.vecTransformColumnsTargetTables.get(i).toString())
2534
); j++) {
2535                String JavaDoc readValue = "";
2536                String JavaDoc columnName = rsetSource.getMetaData().getColumnName(j);
2537                if (!readingOrderRelevant) {
2538                  if (this.iFirstColumnResult == 0) {
2539                    readValue = rsetSource.getString(j - 1);
2540                  } else {
2541                    readValue = rsetSource.getString(j);
2542                  }
2543                } else {
2544                  columnName = columnName.toUpperCase();
2545                  readValue = orderRelevantColumnValues.get(columnName).toString();
2546                }
2547                parseInputData(readValue, vecVektor, rsetSource, i, columnName, j - iCounterCol + 1,
2548                    readingOrderRelevant, orderRelevantColumnValues);
2549              }
2550                   //for transformations
2551
this.transformationValues.clear();
2552                    for (int j = this.iOffsetForTransColumns+1; j < (this.iOffsetForTransColumns +
2553                           this.transformations.getTransformationSourceColumsCnt() + 1
2554                           ); j++) {
2555                Object JavaDoc value = "";
2556                String JavaDoc columnName = rsetSource.getMetaData().getColumnName(j);
2557                if (!readingOrderRelevant) {
2558                  if (this.iFirstColumnResult == 0) {
2559                            value = rsetSource.getString(j - 1);
2560                  } else {
2561                            value= rsetSource.getString(j);
2562                  }
2563                } else {
2564                  columnName = columnName.toUpperCase();
2565                        value = orderRelevantColumnValues.get(columnName);
2566                }
2567                        this.transformationValues.add(value);
2568              }
2569            }
2570            for (int l = 0; l < this.vecVariableUseIDTableName.size(); l++) {
2571              if (this.vecTableTableName.get(i).toString().equalsIgnoreCase(this.
2572                  vecVariableUseIDTableName.get(l).toString())
2573                  &&
2574                  this.vecVariableUseIDTableID.get(l).toString().
2575                  equalsIgnoreCase(this.vecTableTableID.get(i).toString()))
2576                vecVektor.add(this.strUserID);
2577            }
2578            Vector JavaDoc transformedValues = new Vector JavaDoc();
2579            Vector JavaDoc resultVectorTypes = new Vector JavaDoc();
2580            List JavaDoc trans = this.transformations.getTransformations();
2581            Vector JavaDoc vecTransformedValues = new Vector JavaDoc();
2582            Vector JavaDoc pomResultVectorTypes = new Vector JavaDoc();
2583            String JavaDoc tableId = this.vecTableTableID.get(i).toString();
2584            List JavaDoc transTableIDs = this.transformations.getTransformationsTableIDs();
2585                if (transTableIDs.contains(tableId)){
2586                    this.logger.write("full", "\ttransformation of values is started");
2587                    int offset = 0;
2588                    for( int j=0; j < trans.size(); j++ ){
2589                        Transformation transformation = (Transformation)trans.get(j);
2590                        Vector JavaDoc sourceColumnNames = transformation.getSourceColumnNames();
2591                        Vector JavaDoc valuesForTrans = new Vector JavaDoc();
2592                        for ( int n = offset; n < offset + sourceColumnNames.size(); n++ ) {
2593                                valuesForTrans.add(this.transformationValues.elementAt(n));
2594                        }
2595                        offset += sourceColumnNames.size();
2596                        vecTransformedValues = transformation.transformValues(valuesForTrans);
2597                        pomResultVectorTypes = transformation.getOrderedTargetColumnTypes(i);
2598                            if (vecTransformedValues != null){
2599                                for (int m = 0; m < vecTransformedValues.size(); m++) {
2600                                      //use only values and types for specified logic table
2601
if( pomResultVectorTypes.get(m) == null )
2602                                        continue;
2603                                    transformedValues.add(vecTransformedValues.get(m));
2604                                    resultVectorTypes.add(pomResultVectorTypes.get(m).toString());
2605                                  }
2606                            }
2607                    }
2608                    this.logger.write("full", "\ttransformation of values is finished");
2609                }
2610            
2611                //insert row into target logic table
2612
this.insertTargetTable(i,
2613                                            vecVektor,
2614                                           (Vector JavaDoc)this.vecTargetColumnName.get(i),
2615                                           (Vector JavaDoc)this.vecValueMode.get(i),
2616                                           (Vector JavaDoc)this.vecTargetColumnType.get(i),
2617                                           connTarget,
2618                                           transformedValues,
2619                                           resultVectorTypes);
2620            
2621            
2622          }
2623          iRowNumber++;
2624        }
2625        //restart counter table
2626
if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
2627          if (this.hasRestartCounter) {
2628            bdecCounter = bdecCounter.add(new BigDecimal JavaDoc(iRowNumber));
2629            dataTransmition.insertCounter(this.currentJobName, bdecCounter, connTarget);
2630          }
2631        }
2632
2633         
2634        if (this.hasRestartCounter) {
2635//TODO THIS IS WRITE PLACE:ZK added this for update of counterColumns. This will update values in CounterTable for this import job.
2636
//this.counterColumns.updateCounter(this.htValuesForCounterColumns, connTarget);
2637
this.counterColumns.updateCounter(connTarget);
2638          connTarget.commit();
2639            this.logger.write("normal", "Imported block is commited.");
2640          this.logger.write("full", Integer.toString(iRowNumber) + " rows are commited.");
2641        }
2642        iRowNumber = 0;
2643        if (isEndFlag == true)
2644          break;
2645      }//End of while(main)
2646

2647       
2648      rsetSource.close();
2649      stmtSource.close();
2650      connSource.close();
2651
2652      if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
2653        if (this.hasRestartCounter) {
2654          dataTransmition.resetRestartCounter(connTarget, this.currentJobName);
2655        }
2656      }
2657//TODO ZK added this for update of counterColumns. This will update values in CounterTable for every importDefinition.
2658
if (!this.hasRestartCounter){
2659                        this.counterColumns.updateCounter(connTarget);
2660                }
2661//end
2662
currentDate = new Date JavaDoc();
2663      dfNow = DateFormat.getDateTimeInstance();
2664      this.logger.write("normal", "Import definition " +
2665          importDefinitionElement.strImportDefinitionName
2666          + " is finished at " + dfNow.format(currentDate) + ".");
2667      this.logger.write("normal", " Duration of importDefinition:" +
2668          this.timeCounter.getJobTime());
2669    }
2670
2671    catch (Exception JavaDoc e) {
2672      try {
2673        if (connSource != null)
2674          connSource.close();
2675      }
2676      catch (Exception JavaDoc ex) {
2677        this.logger.write("normal", "\t" + ex.getMessage());
2678      }
2679      String JavaDoc msq = "Error: In import job '" + importDefinitionElement.strImportDefinitionName
2680                   + "', " +
2681                   "some error has occured:";
2682      this.logger.write("normal", "\t" + msq);
2683      LoaderException le = new LoaderException("Exception:"+e.getMessage(),(Throwable JavaDoc)e);
2684        this.logger.write("full", "\t" + le.getStackTraceAsString());
2685
2686      throw le;
2687    }
2688    finally {
2689      try {
2690        
2691        this.logger.write("full", "loadSource method is finished.");
2692        if (connSource != null && !connSource.isClosed())
2693          connSource.close();
2694      }
2695      catch (SQLException JavaDoc e) {
2696        LoaderException le = new LoaderException("SQLException: ",
2697                             (Throwable JavaDoc)e);
2698        //this.logger.write("normal", le.getCause().toString());
2699
this.logger.write("full", le.getStackTraceAsString());
2700        throw le;
2701      }
2702    }
2703  }
2704
2705  /**
2706   * This method read data from source table
2707   * @param readValue is data value which is reed
2708   * @param vecVektor defines vector
2709   * @param rsetSource defines ResultSet object
2710   * @param i is interger
2711   * @param columnName defines source column name
2712   * @param blobCount defines counter for blob object
2713   * @param isMicrosoftDriver defines if we use microsoft driver
2714   * @param columnValuesMicrosoft defines column values which is read with microsoft driver
2715   */

2716  public void parseInputData(String JavaDoc readValue, Vector JavaDoc vecVektor, ResultSet JavaDoc rsetSource,
2717      int i, String JavaDoc columnName, int blobCount, boolean isMicrosoftDriver,
2718      Hashtable JavaDoc columnValuesMicrosoft) throws LoaderException {
2719    try {
2720      if (readValue == null || readValue.equalsIgnoreCase("null")) {
2721        vecVektor.add(null);
2722      } else if (readValue.equalsIgnoreCase("")) {
2723        if (configReaderTarget.getSetEmptyStringAsNull())
2724          vecVektor.add(null);
2725        else
2726          vecVektor.add("");
2727      } else {
2728// int indexOld = ( (Vector)this.vecTargetColumnName.get(i)).indexOf(columnName);
2729
int index = blobCount-1;
2730// if (index == -1) {
2731
// if (readValue.indexOf("'") != -1)
2732
// readValue = replaceChar(readValue, '\'', "\'\'");
2733
// vecVektor.add(readValue);
2734
// } else {
2735
byte[] blob;
2736          
2737          String JavaDoc type = ( (Vector JavaDoc)this.vecTargetColumnType.get(i)).get(index).toString();
2738// //ZK Added next line because of DB2 type LONG VARCHAR
2739

2740          //type = Utils.replaceAll(type,"_"," ");
2741

2742          String JavaDoc mode = ( (Vector JavaDoc)this.vecValueMode.get(i)).get(index).toString();
2743          String JavaDoc toHex = ( (Vector JavaDoc)this.vecToHex.get(i)).get(index).toString();
2744          String JavaDoc fromHex = ( (Vector JavaDoc)this.vecFromHex.get(i)).get(index).toString();
2745          String JavaDoc blobObjectName = "binaryObject" + blobCount;
2746
2747          if (toHex.equalsIgnoreCase("true") && !fromHex.equalsIgnoreCase("true")) {
2748            if (isMicrosoftDriver)
2749              blob = (byte[])columnValuesMicrosoft.get(columnName);
2750            else
2751              blob = rsetSource.getBytes(columnName);
2752
2753            String JavaDoc toHexString = ToAndFromHex.getStringFromBlob(blob);
2754            vecVektor.add(toHexString);
2755          } else if (fromHex.equalsIgnoreCase("true") && !toHex.equalsIgnoreCase("true")) {
2756//ZK change this 7.5.2004 from CheckType to configReaderTarget
2757
if (configReaderTarget.isBinaryObject(type)) {
2758// if (javaTypeInt==1) {
2759
byte[] newBlob = ToAndFromHex.getByteArrayFromString(
2760                               readValue);
2761              if (mode.equalsIgnoreCase("Update")) {
2762                this.vecBlobVector.add(columnName);
2763                this.vecBlobVector.add(newBlob);
2764                this.vecBlobVector.add(" where " + columnName +
2765                    " is null and ");
2766                this.vecBlobVector.add(mode);
2767                this.vecBlobVector.add(blobObjectName);
2768                vecVektor.add(blobObjectName);
2769              } else {
2770                this.vecBlobVector.add(columnName);
2771                this.vecBlobVector.add(newBlob);
2772                this.vecBlobVector.add(null);
2773                this.vecBlobVector.add(mode);
2774                this.vecBlobVector.add(blobObjectName);
2775                vecVektor.add(blobObjectName);
2776              }
2777            } else {
2778              if (readValue.indexOf("'") != -1)
2779                readValue = replaceChar(readValue, '\'', "\'\'");
2780              vecVektor.add(readValue);
2781            }
2782          } else {
2783// ZK change this 7.5.2004 from CheckType to configReaderSource
2784
if (configReaderTarget.isBinaryObject(type)) {
2785// if (javaTypeInt==1) {
2786
if (isMicrosoftDriver)
2787                blob = (byte[])columnValuesMicrosoft.get(columnName);
2788              else
2789                blob = rsetSource.getBytes(columnName);
2790              if (mode.equalsIgnoreCase("Update")) {
2791                this.vecBlobVector.add(columnName);
2792                this.vecBlobVector.add(blob);
2793                this.vecBlobVector.add(" where " + columnName + " is null and ");
2794                this.vecBlobVector.add(mode);
2795                this.vecBlobVector.add(blobObjectName);
2796                vecVektor.add(blobObjectName);
2797              } else {
2798                this.vecBlobVector.add(columnName);
2799                this.vecBlobVector.add(blob);
2800                this.vecBlobVector.add(null);
2801                this.vecBlobVector.add(mode);
2802                this.vecBlobVector.add(blobObjectName);
2803                vecVektor.add(blobObjectName);
2804              }
2805            }else if(configReaderTarget.isDate(type)){ //configReaderTarget.isDate(type)
2806

2807                Date JavaDoc tmpDate = null;
2808                boolean sourceTypeIsNotDate = false;
2809                String JavaDoc tmpDateStr ="";
2810                if (isMicrosoftDriver)
2811                    tmpDate = (java.sql.Date JavaDoc)columnValuesMicrosoft.get(columnName);
2812                else{
2813                    ResultSetMetaData JavaDoc rsMetaDataSource = rsetSource.getMetaData();
2814                    int columnPos = rsetSource.findColumn(columnName);
2815                    String JavaDoc typeName = rsMetaDataSource.getColumnTypeName(columnPos);
2816                    if (!configReaderSource.isDate(typeName)){
2817                        tmpDateStr = rsetSource.getString(columnName);
2818                        sourceTypeIsNotDate = true;
2819                    }else{
2820                        tmpDate=rsetSource.getDate(columnName);
2821                    }
2822                }
2823                if (sourceTypeIsNotDate){
2824                    vecVektor.add(tmpDateStr);
2825                }else{
2826                    String JavaDoc format=this.configReaderTarget.getDateFormat();
2827                    SimpleDateFormat JavaDoc formatDate=new SimpleDateFormat JavaDoc(format);
2828                    readValue=formatDate.format(tmpDate);
2829                    vecVektor.add(readValue);
2830                }
2831               } else {
2832              if (readValue.indexOf("'") != -1)
2833                readValue = replaceChar(readValue, '\'', "\'\'");
2834              vecVektor.add(readValue);
2835            }
2836          }
2837        }
2838// }
2839
}
2840    catch (Exception JavaDoc ex) {
2841      LoaderException le = new LoaderException("Error in parseInputData.",ex);
2842      this.logger.write("full",le.getStackTraceAsString());
2843      throw le;
2844    }
2845  }
2846
2847  /**
2848   * Method parseImportJOB is used to analyse import XML file
2849   * about ImportDefinitions tags. Return number of importDefinition elements in whole xml file.
2850   * @param inStream Data from inputXML file which is converted into InputStream.
2851   * @return Number of ImportDefinitions tags in an input XML file.
2852   * @throws LoaderException
2853   */

2854  private int parseImportJob(InputStream JavaDoc inStream) throws LoaderException {
2855    int iNumTagsImportJob = 0;
2856    Document JavaDoc doc = null;
2857    this.logger.write("full", "\tparseImportJob method is started.");
2858    try {
2859
2860      DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
2861      DocumentBuilder JavaDoc db = null;
2862      db = dbf.newDocumentBuilder();
2863      doc = db.parse(inStream);
2864    }
2865    catch (Exception JavaDoc e) {
2866      this.logger.write("normal", "Sorry, an error occurred: " + e);
2867      LoaderException le = new LoaderException("Exception: ",
2868                           (Throwable JavaDoc)e);
2869      this.logger.write("full", le.getStackTraceAsString());
2870      throw le;
2871    }
2872    if (doc != null) {
2873      NodeList JavaDoc tagBasic = doc.getElementsByTagName("importDefinition");
2874      iNumTagsImportJob = tagBasic.getLength();
2875      Vector JavaDoc vecNames = new Vector JavaDoc();
2876      String JavaDoc strName = "";
2877      for (int i = 0; i < iNumTagsImportJob; i++) {
2878        strName = new String JavaDoc("");
2879        strName = OctopusXMLUtil.importAttributeValue(doc, "importDefinition",
2880                  "name", i);
2881        for (int j = 0; j < vecNames.size(); j++) {
2882          if (strName.equals("")) {
2883            this.logger.write("normal",
2884                "Sorry, an error occurred: No importDefinition name .");
2885            LoaderException le = new LoaderException("Exception: ",
2886                                 (Throwable JavaDoc) (new Exception JavaDoc(
2887                                 "Sorry, an error occurred: No importDefinition name .")));
2888                        this.logger.write("full", le.getStackTraceAsString());
2889            throw le;
2890          }
2891          if (strName.equalsIgnoreCase(vecNames.get(j).toString())) {
2892            this.logger.write("normal",
2893                "Sorry, an error occurred: More importDefinition with same name :"
2894                + strName);
2895            LoaderException le = new LoaderException("Exception: ",
2896                                 (Throwable JavaDoc) (new Exception JavaDoc(
2897                                 "Sorry, an error occurred: More importDefinition with same name :")));
2898                        this.logger.write("full", le.getStackTraceAsString());
2899            throw le;
2900          }
2901        }
2902        vecNames.addElement(strName);
2903      }
2904    }
2905    try {
2906      inStream.reset();
2907    }
2908    catch (IOException JavaDoc e) {
2909      //this.logger.write("normal", "Sorry, an error occurred: " + e);
2910
LoaderException le = new LoaderException("IOException: ",
2911                           (Throwable JavaDoc)e);
2912        this.logger.write("full", le.getStackTraceAsString());
2913      throw le;
2914    }
2915    this.logger.write("full", "\tparseImportJob method is finished.");
2916    return iNumTagsImportJob;
2917  }
2918
2919  /**
2920   * Method parseCopyTable is used to analyse import XML file
2921   * about copyTable tags. Return number of copyTable elements in whole xml file.
2922   * @param inStream Data from inputXML file which is converted into InputStream.
2923   * @return Number of iNumTagsCopyTable tags in an input XML file.
2924   * @throws LoaderException
2925   */

2926
2927  private int parseCopyTable(InputStream JavaDoc inStream) throws LoaderException {
2928    int iNumTagsCopyTable = 0;
2929    Document JavaDoc doc = null;
2930    this.logger.write("full", "\tparseCopyTable method is started.");
2931    try {
2932
2933      DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
2934      DocumentBuilder JavaDoc db = null;
2935      db = dbf.newDocumentBuilder();
2936      doc = db.parse(inStream);
2937    }
2938    catch (Exception JavaDoc e) {
2939      this.logger.write("normal", "Sorry, an error occurred: " + e);
2940      LoaderException le = new LoaderException("Exception: ",
2941                           (Throwable JavaDoc)e);
2942        this.logger.write("full", le.getStackTraceAsString());
2943      throw le;
2944    }
2945    if (doc != null) {
2946      NodeList JavaDoc tagCopyTable = doc.getElementsByTagName("copyTable");
2947      iNumTagsCopyTable = tagCopyTable.getLength();
2948      Vector JavaDoc vecNames = new Vector JavaDoc();
2949      String JavaDoc strName = "";
2950      for (int i = 0; i < iNumTagsCopyTable; i++) {
2951        strName = new String JavaDoc("");
2952        strName = OctopusXMLUtil.importAttributeValue(doc, "copyTable", "name", i);
2953        for (int j = 0; j < vecNames.size(); j++) {
2954          if (strName.equals("")) {
2955            this.logger.write("normal", "Sorry, an error occurred: No copyTable name .");
2956            LoaderException le = new LoaderException("Exception: ",
2957                                 (Throwable JavaDoc) (new Exception JavaDoc(
2958                                 "Sorry, an error occurred: No copyTable name .")));
2959                        this.logger.write("full", le.getStackTraceAsString());
2960            throw le;
2961          }
2962          if (strName.equalsIgnoreCase(vecNames.get(j).toString())) {
2963            this.logger.write("normal",
2964                "Sorry, an error occurred: More copyTable with same name :"
2965                + strName);
2966            LoaderException le = new LoaderException("Exception: ",
2967                                 (Throwable JavaDoc) (new Exception JavaDoc(
2968                                 "Sorry, an error occurred: More copyTable with same name :")));
2969                        this.logger.write("full", le.getStackTraceAsString());
2970            throw le;
2971          }
2972        }
2973        vecNames.addElement(strName);
2974      }
2975    }
2976    try {
2977      inStream.reset();
2978    }
2979    catch (IOException JavaDoc e) {
2980      this.logger.write("normal", "Sorry, an error occurred: " + e);
2981      LoaderException le = new LoaderException("IOException: ",
2982                           (Throwable JavaDoc)e);
2983        this.logger.write("full", le.getStackTraceAsString());
2984      throw le;
2985    }
2986    this.logger.write("full", "\tparseImportJob method is finished.");
2987    return iNumTagsCopyTable;
2988  }
2989
2990  /**
2991   * Method parseEchoElement is used to analyse import XML file
2992   * about echo tags. Return number of echo elements in a whole xml input file.
2993   * @param inStream Data from inputXML file which is converted into InputStream.
2994   * @return Number of echo tags in an input XML file.
2995   * @throws LoaderException
2996   */

2997  private int parseEcho(InputStream JavaDoc inStream) throws LoaderException {
2998    int iNumTagsEcho = 0;
2999    Document JavaDoc doc = null;
3000    this.logger.write("full", "\tparseEcho method is started.");
3001    try {
3002      DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
3003      DocumentBuilder JavaDoc db = null;
3004      db = dbf.newDocumentBuilder();
3005      doc = db.parse(inStream);
3006    }
3007    catch (Exception JavaDoc e) {
3008      this.logger.write("normal", "Sorry, an error occurred: " + e);
3009      LoaderException le = new LoaderException("Exception: ",
3010                           (Throwable JavaDoc)e);
3011        this.logger.write("full", le.getStackTraceAsString());
3012      throw le;
3013    }
3014    if (doc != null) {
3015      NodeList JavaDoc tagBasic = doc.getElementsByTagName("echo");
3016      iNumTagsEcho = tagBasic.getLength();
3017      String JavaDoc strMessage = "";
3018      for (int i = 0; i < iNumTagsEcho; i++) {
3019        strMessage = new String JavaDoc("");
3020        strMessage = OctopusXMLUtil.importAttributeValue(doc, "echo", "message", i);
3021        if (strMessage != null)
3022          logger.setMessage( (new Integer JavaDoc(i)).toString(), strMessage);
3023      }
3024    }
3025    try {
3026      inStream.reset();
3027    }
3028    catch (IOException JavaDoc e) {
3029      this.logger.write("normal", "Sorry, an error occurred: " + e);
3030      LoaderException le = new LoaderException("IOxception: ",
3031                           (Throwable JavaDoc)e);
3032        this.logger.write("full", le.getStackTraceAsString());
3033      throw le;
3034// System.exit(1);
3035
}
3036    this.logger.write("full", "\tparseSql method is finished.");
3037    return iNumTagsEcho;
3038  }
3039
3040  /**
3041   * Method parseMainElements is used to analyse import XML file
3042   * about main elements (sql and importDefinition). Puts names of elements (sql or importDefinition) in Vector.
3043   * @param inStream Data from inputXML file which is converted into InputStream.
3044   * @return Vector which elements are names of main elements in the same order as in XML import file .
3045   * @throws LoaderException
3046   */

3047  private Vector JavaDoc parseMainElements(InputStream JavaDoc inStream) throws LoaderException {
3048
3049    Vector JavaDoc vecLoaderElements = new Vector JavaDoc();
3050    Vector JavaDoc vecLoaderNamesOfElements = new Vector JavaDoc();
3051
3052    Document JavaDoc doc = null;
3053    this.logger.write("full", "\tparseMainElements method is started.");
3054    try {
3055      DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
3056      DocumentBuilder JavaDoc db = null;
3057      db = dbf.newDocumentBuilder();
3058      doc = db.parse(inStream);
3059    }
3060    catch (Exception JavaDoc e) {
3061      this.logger.write("normal", "Sorry, an error occurred: " + e);
3062      LoaderException le = new LoaderException("Exception: ",
3063                           (Throwable JavaDoc)e);
3064        this.logger.write("full", le.getStackTraceAsString());
3065      throw le;
3066    }
3067    if (doc != null) {
3068      NodeList JavaDoc tagBasic = doc.getElementsByTagName("loaderJob");
3069      NodeList JavaDoc nlMainElements = tagBasic.item(0).getChildNodes();
3070      for (int i = 0; i < nlMainElements.getLength(); i++) {
3071        String JavaDoc strTagName = nlMainElements.item(i).getNodeName();
3072        if (strTagName.equalsIgnoreCase("sql") ||
3073            strTagName.equalsIgnoreCase("importDefinition") ||
3074            strTagName.equalsIgnoreCase("echo") ||
3075            strTagName.equalsIgnoreCase("copyTable"))
3076        if (nlMainElements.item(i).getNodeType() == Node.ELEMENT_NODE) {
3077          String JavaDoc strTagJobName = ( ( (Element JavaDoc)nlMainElements.item(i)).getAttribute("name"));
3078            String JavaDoc strLogMode = ( ( (Element JavaDoc)nlMainElements.item(i)).getAttribute("logMode"));
3079             vecLoaderElements.addElement(strTagName);
3080            this.logModes.add(strLogMode);
3081          boolean addJobName = true;
3082          if (!strTagJobName.equalsIgnoreCase("")) {
3083            for (int j = 0; j < vecLoaderNamesOfElements.size(); j++) {
3084              if (strTagJobName.equalsIgnoreCase(vecLoaderNamesOfElements.get(j).toString())) {
3085                addJobName = false;
3086                break;
3087              }
3088            }
3089            if (addJobName) {
3090              vecLoaderNamesOfElements.add(strTagJobName);
3091            } else {
3092              String JavaDoc msg = "Sorry, an error occurred: More import jobs with same name :"
3093                           + strTagJobName;
3094              LoaderException le = new LoaderException("Exception:", new Exception JavaDoc(msg));
3095              
3096              throw le;
3097            }
3098          }
3099        }
3100      }
3101    }
3102    try {
3103      inStream.reset();
3104    }
3105    catch (IOException JavaDoc e) {
3106      this.logger.write("normal", "Sorry, an error occurred: " + e.getMessage());
3107      LoaderException le = new LoaderException("IOException: ",
3108                           (Throwable JavaDoc)e);
3109            this.logger.write("full", le.getStackTraceAsString());
3110      throw le;
3111    }
3112    this.logger.write("full", "\tparseMainElements method is finished.");
3113    return vecLoaderElements;
3114  }
3115
3116  /**
3117   * Method importRestartCounter is used to analyse import XML file
3118   * and read restart counter attributes. Values of these attributes puts in Vectors
3119   * @param inStream Data from inputXML file which is converted into InputStream.
3120   * @throws LoaderException
3121   */

3122  private void importRestartCounter(InputStream JavaDoc inStream) throws
3123      LoaderException {
3124    Document JavaDoc doc = null;
3125    this.logger.write("full", "\timportRestartCounter method is started.");
3126    try {
3127      DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
3128      DocumentBuilder JavaDoc db = null;
3129      db = dbf.newDocumentBuilder();
3130      doc = db.parse(inStream);
3131    }
3132    catch (Exception JavaDoc e) {
3133      this.logger.write("normal", "Sorry, an error occurred: " + e);
3134      LoaderException le = new LoaderException("Exception: ",
3135                           (Throwable JavaDoc)e);
3136      this.logger.write("full", le.getStackTraceAsString());
3137      throw le;
3138// System.exit(1);
3139
}
3140    if (doc != null) {
3141      NodeList JavaDoc tagRestartCounter = doc.getElementsByTagName("restartCounter");
3142      if (tagRestartCounter.getLength() != 0) {
3143        this.hasRestartCounter = true;
3144        NamedNodeMap JavaDoc attrs = tagRestartCounter.item(0).getAttributes();
3145        Node JavaDoc nodeResult = attrs.getNamedItem("tableName");
3146        if (nodeResult != null)
3147          importDefinitionElement.strRestartCounterTableName = nodeResult.
3148                                                               getNodeValue();
3149        else
3150          importDefinitionElement.strRestartCounterTableName = "LOADERRESTART";
3151        nodeResult = attrs.getNamedItem("importDefinitionColumnName");
3152        if (nodeResult != null)
3153          importDefinitionElement.strRestartCounterImportDefinitionName =
3154              nodeResult.getNodeValue();
3155        else
3156          importDefinitionElement.strRestartCounterImportDefinitionName =
3157              "IMPORTDEFINITION";
3158        nodeResult = attrs.getNamedItem("restartCounterColumnName");
3159        if (nodeResult != null)
3160          importDefinitionElement.strRestartCounterValue = nodeResult.
3161                                                           getNodeValue();
3162        else
3163          importDefinitionElement.strRestartCounterValue = "RESTARTCOUNTER";
3164        nodeResult = attrs.getNamedItem("restartAutoCreate");
3165        if (nodeResult != null)
3166          importDefinitionElement.bRestartAutoCreate = (new Boolean JavaDoc(nodeResult.
3167                                                       getNodeValue())).booleanValue();
3168        else
3169          importDefinitionElement.bRestartAutoCreate = false;
3170      }
3171    }
3172    try {
3173      inStream.reset();
3174    }
3175    catch (IOException JavaDoc e) {
3176      this.logger.write("normal", "Sorry, an error occurred: " + e);
3177      LoaderException le = new LoaderException("IOException: ",
3178                           (Throwable JavaDoc)e);
3179      this.logger.write("full", le.getStackTraceAsString());
3180      throw le;
3181// System.exit(1);
3182
}
3183    this.logger.write("full", "\timportRestartCounter method is finished.");
3184  }
3185
3186  /**
3187       * Method importVariable imports sql attributes from xml file and puts them in the global variables.
3188   * Return Vector. It's elements are strings which represents sql statements.
3189   * @param inStream Data from inputXML file which is converted into InputStream.
3190   * @throws LoaderException
3191   */

3192  private void importVariable(InputStream JavaDoc inStream) throws LoaderException {
3193    Document JavaDoc doc = null;
3194    String JavaDoc strNodeValue = "";
3195    String JavaDoc strDefaultVariableOverride = "";
3196    String JavaDoc strDefaultReplaceInConstants = "";
3197    String JavaDoc strDefaultReplaceInSQL = "";
3198    String JavaDoc strDefaultReplaceInData = "";
3199    String JavaDoc strDefaultReplaceInJDBC = "";
3200    String JavaDoc strDefaultVariablePrefix = "";
3201    String JavaDoc strDefaultVariableSufix = "";
3202    this.logger.write("full", "\timportVariable method is started.");
3203    try {
3204      DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
3205      DocumentBuilder JavaDoc db = null;
3206      db = dbf.newDocumentBuilder();
3207      doc = db.parse(inStream);
3208      if (doc != null) {
3209        NodeList JavaDoc tagBasic = doc.getElementsByTagName("variables");
3210        if (tagBasic.getLength() != 0) {
3211          Element JavaDoc docFragment = (Element JavaDoc)tagBasic.item(0);
3212          strDefaultVariablePrefix = docFragment.getAttribute("prefix");
3213          if (strDefaultVariablePrefix.equals(""))
3214            strDefaultVariablePrefix = "%";
3215          strDefaultVariableSufix = docFragment.getAttribute("suffix");
3216          if (strDefaultVariableSufix.equals(""))
3217            strDefaultVariableSufix = "%";
3218          strDefaultVariableOverride = docFragment.getAttribute("override");
3219          if (strDefaultVariableOverride.equals(""))
3220            strDefaultVariableOverride = "true";
3221          strDefaultReplaceInConstants = docFragment.getAttribute(
3222                                         "replaceInConstants");
3223          if (strDefaultReplaceInConstants.equals(""))
3224            strDefaultReplaceInConstants = "false";
3225          strDefaultReplaceInSQL = docFragment.getAttribute("replaceInSQL");
3226          if (strDefaultReplaceInSQL.equals(""))
3227            strDefaultReplaceInSQL = "false";
3228          strDefaultReplaceInData = docFragment.getAttribute("replaceInData");
3229          if (strDefaultReplaceInData.equals(""))
3230            strDefaultReplaceInData = "false";
3231          strDefaultReplaceInJDBC = docFragment.getAttribute("replaceInJDBC");
3232          if (strDefaultReplaceInJDBC.equals(""))
3233            strDefaultReplaceInJDBC = "false";
3234          NodeList JavaDoc tag = docFragment.getElementsByTagName("variable");
3235          this.vecVariableName = OctopusXMLUtil.getAttributeValues(tag, "name", null);
3236          this.vecVariableValue = OctopusXMLUtil.getAttributeValues(tag,
3237                                  "value", null);
3238          this.vecVariablePrefix = OctopusXMLUtil.getAttributeValues(tag,
3239                                   "prefix",
3240                                   strDefaultVariablePrefix);
3241          this.vecVariableSufix = OctopusXMLUtil.getAttributeValues(tag,
3242                                  "suffix",
3243                                  strDefaultVariableSufix);
3244          this.vecVariableOverride = OctopusXMLUtil.getAttributeValues(tag,
3245                                     "override",
3246                                     strDefaultVariableOverride);
3247          this.vecReplaceInConstants = OctopusXMLUtil.getAttributeValues(tag,
3248                                       "replaceInConstants",
3249                                       strDefaultReplaceInConstants);
3250          this.vecReplaceInSQL = OctopusXMLUtil.getAttributeValues(tag,
3251                                 "replaceInSQL",
3252                                 strDefaultReplaceInSQL);
3253          this.vecReplaceInData = OctopusXMLUtil.getAttributeValues(tag,
3254                                  "replaceInData",
3255                                  strDefaultReplaceInData);
3256          this.vecReplaceInJDBC = OctopusXMLUtil.getAttributeValues(tag,
3257                                  "replaceInJDBC",
3258                                  strDefaultReplaceInJDBC);
3259          for (int i = 0; i < this.vecVariableOverride.size(); i++) {
3260            if (this.vecVariableOverride.get(i).toString().equalsIgnoreCase(
3261                "true")) {
3262              if (this.mapVariableValues.get(this.vecVariableName.get(i)) == null)
3263                this.vecVariableValue.setElementAt(null, i);
3264              else
3265                this.vecVariableValue.setElementAt(this.mapVariableValues.get(this.
3266                    vecVariableName.get(i).toString()).toString(),
3267                    i);
3268            }
3269          }
3270        }
3271      }
3272    }
3273    catch (Exception JavaDoc e) {
3274      this.logger.write("normal",
3275          "Sorry, an error with the variables occurred: " + e);
3276      LoaderException le = new LoaderException("Exception: ", (Throwable JavaDoc)e);
3277      this.logger.write("full", le.getStackTraceAsString());
3278      throw le;
3279    }
3280    try {
3281      inStream.reset();
3282    }
3283    catch (IOException JavaDoc e) {
3284      this.logger.write("normal", "Sorry, an error occurred: " + e);
3285      LoaderException le = new LoaderException("IOException: ",
3286                           (Throwable JavaDoc)e);
3287      this.logger.write("full", le.getStackTraceAsString());
3288      throw le;
3289    }
3290    this.logger.write("full", "\timportVariable method is finished.");
3291  }
3292
3293  /**
3294   * Method parseAndImport is used to analyse the importDefinition no. l in xml file and
3295   * input all values and puts them into global variables.
3296   * If there is an error, Exception "SAXException" is thrown.
3297   * @param inStream Data from inputXML file which is converted into InputStream.
3298   * @param l Number of ImportDefinition tag which is processed.
3299   * @throws SAXException Constructs an JAXP 1.1 Exception with the specified detail message.
3300   * @throws Exception Constructs an Exception with the specified detail message.
3301   * @throws LoaderException
3302   */

3303  private void parseAndImport(InputStream JavaDoc inStream, int l) throws SAXException JavaDoc,
3304      LoaderException,
3305      Exception JavaDoc {
3306    this.logger.write("full", "\tparseAndImport method is started.");
3307    Document JavaDoc doc = null;
3308    try {
3309      DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
3310      DocumentBuilder JavaDoc db = null;
3311      db = dbf.newDocumentBuilder();
3312      doc = db.parse(inStream);
3313    }
3314    catch (SAXException JavaDoc e) {
3315      throw e;
3316    }
3317    catch (Exception JavaDoc e) {
3318      throw e;
3319    }
3320    if (doc != null)
3321      this.importXMLFile(doc, l);
3322    try {
3323      inStream.reset();
3324    }
3325    catch (IOException JavaDoc e) {
3326      this.logger.write("normal", "Sorry, an error occurred: " + e);
3327      LoaderException le = new LoaderException("IOException: ",
3328                           (Throwable JavaDoc)e);
3329      this.logger.write("full", le.getStackTraceAsString());
3330      throw le;
3331    }
3332    this.logger.write("full", "\tparseAndImport method is finished.");
3333  }
3334
3335  /**
3336   * Method importXMLFile is used for setting of global variables
3337   * during importing values from XML file.
3338   * This method validates the imported data from XML file.
3339   * If there is an error Exception "NullPointerException" or "Exception" is thrown.
3340   * @param doc Parsed imports XML file.
3341   * @param iJobNumber Number of ImportJob tag which is processed.
3342       * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
3343   * @throws Exception Constructs an Exception with the specified detail message.
3344   */

3345  private void importXMLFile(Document JavaDoc doc, int iJobNumber) throws
3346      NullPointerException JavaDoc,
3347      Exception JavaDoc {
3348    this.logger.write("full", "\timportXMLFile method is started.");
3349    Vector JavaDoc vecValueColumnSourceColumnName = new Vector JavaDoc();
3350    Vector JavaDoc vecValueColumnTargetTableName = new Vector JavaDoc();
3351    Vector JavaDoc vecValueColumnTargetColumnName = new Vector JavaDoc();
3352    Vector JavaDoc vecValueColumnTargetTableID = new Vector JavaDoc();
3353    Vector JavaDoc vecValueColumnValueMode = new Vector JavaDoc();
3354    Vector JavaDoc vecConstantColumnTargetColumnName = new Vector JavaDoc();
3355    Vector JavaDoc vecConstantColumnValueMode = new Vector JavaDoc();
3356    Vector JavaDoc vecConstantColumnConstantValue = new Vector JavaDoc();
3357    Vector JavaDoc vecRestartCounterVector = new Vector JavaDoc();
3358    Vector JavaDoc vecJDBCSourceName = new Vector JavaDoc();
3359    Vector JavaDoc vecJDBCSourceValue = new Vector JavaDoc();
3360    Vector JavaDoc vecJDBCTargetName = new Vector JavaDoc();
3361    Vector JavaDoc vecJDBCTargetValue = new Vector JavaDoc();
3362    //vector for default values of columns
3363
Vector JavaDoc vecDefaultValueTemp = new Vector JavaDoc();
3364    this.vecDefaultValue = new Vector JavaDoc();
3365    this.vecDefaultRelationValue = null;
3366    this.vecDefaultVariableValue = null;
3367    this.vecDefaultVariableName = null;
3368    this.vecTempUserID = null;
3369    int iNumberOfColumns = 0;
3370    // to and form hex
3371
Vector JavaDoc vecToHexTemp = new Vector JavaDoc();
3372    Vector JavaDoc vecFromHexTemp = new Vector JavaDoc();
3373    this.vecToHex = new Vector JavaDoc();
3374    this.vecFromHex = new Vector JavaDoc();
3375
3376    try {
3377
3378      importDefinitionElement.setLogger(this.logger);
3379      dataCleaning.setLogger(this.logger);
3380
3381      if (!this.loaderJobReader.getLogTableName().equalsIgnoreCase(""))
3382        dataCleaning.setLogTableName(this.loaderJobReader.getLogTableName());
3383
3384      if (!this.loaderJobReader.getLogTable().equalsIgnoreCase(""))
3385        dataCleaning.setLogTable(this.loaderJobReader.getLogTable());
3386
3387      if (!this.loaderJobReader.getLogColumnName().equalsIgnoreCase(""))
3388        dataCleaning.setLogColumnName(this.loaderJobReader.getLogColumnName());
3389
3390      if (!this.loaderJobReader.getLogRowNumber().equalsIgnoreCase(""))
3391        dataCleaning.setLogRowNumber(this.loaderJobReader.getLogRowNumber());
3392
3393      if (!this.loaderJobReader.getLogOriginalValue().equalsIgnoreCase(""))
3394        dataCleaning.setLogOriginalValue(this.loaderJobReader.
3395            getLogOriginalValue());
3396
3397      if (!this.loaderJobReader.getLogNewValue().equalsIgnoreCase(""))
3398        dataCleaning.setLogNewValue(this.loaderJobReader.getLogNewValue());
3399
3400      if (!this.loaderJobReader.getLogImportDefinitionName().equalsIgnoreCase(
3401          ""))
3402        dataCleaning.setLogImportDefinitionName(this.loaderJobReader.
3403            getLogImportDefinitionName());
3404
3405      if (!this.loaderJobReader.getLogOperationName().equalsIgnoreCase(""))
3406        dataCleaning.setLogOperationName(this.loaderJobReader.
3407            getLogOperationName());
3408            if (!this.loaderJobReader.getLogTime().equalsIgnoreCase(""))
3409                dataCleaning.setLogTime(this.loaderJobReader.getLogTime());
3410                
3411            if (!this.loaderJobReader.getLogFailedStatement().equalsIgnoreCase(""))
3412                dataCleaning.setLogPrimaryKeyValue(this.loaderJobReader.getLogFailedStatement());
3413
3414      if (!this.loaderJobReader.getLogTypeName().equalsIgnoreCase(""))
3415        dataCleaning.setLogTypeName(this.loaderJobReader.getLogTypeName());
3416
3417      importDefinitionElement.setLoaderJob(this.loaderJobReader);
3418// sqlElement.setLoaderJob(this.loaderJobReader);
3419
importDefinitionElement.importXMLFile(doc, iJobNumber);
3420
3421      //set data cut off parameter based on priority
3422
if (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase(""))
3423        importDefinitionElement.strDefaultCutOffData = loaderJobReader.
3424                                                       getDefaultDataCutOff();
3425
3426        //set onErrorContinue parameter based on priority for xml
3427
if (importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase(""))
3428        importDefinitionElement.strOnErrorContinueXml = "" +
3429                                                        loaderJobReader.getDefaultOnErrorContinue();
3430
3431      if (importDefinitionElement.strCopyTableOnErrorContinue.equalsIgnoreCase(
3432          ""))
3433        importDefinitionElement.strCopyTableOnErrorContinue = "" +
3434                                                              loaderJobReader.
3435                                                              getDefaultOnErrorContinue();
3436
3437      vecJDBCSourceValue = OctopusXMLUtil.importValue(doc,
3438                           "jdbcSourceParameter",
3439                           "value", iJobNumber);
3440      vecJDBCSourceName = OctopusXMLUtil.importValue(doc, "jdbcSourceParameter",
3441                          "name", iJobNumber);
3442      if (vecJDBCSourceValue.size() != 0) {
3443        for (int i = 0; i < vecJDBCSourceValue.size(); i++) {
3444          if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
3445            jdbcParametersElement.setJDBCSourceParameterDriver(
3446                vecJDBCSourceValue.get(i).toString());
3447          else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase(
3448              "Connection.Url")) {
3449            //Testing SelectMethod parameter in microsoft MSSQL driver
3450
if (vecJDBCSourceValue.get(i).toString().indexOf(
3451                "jdbc:microsoft:sqlserver") != -1) {
3452              if (vecJDBCSourceValue.get(i).toString().indexOf("SelectMethod") ==
3453                  -1) {
3454                jdbcParametersElement.setJDBCSourceParameterConnection(
3455                    vecJDBCSourceValue.get(i).toString() +
3456                    ";SelectMethod=cursor");
3457              } else if (vecJDBCSourceValue.get(i).toString().indexOf("cursor") !=
3458                  -1) {
3459                jdbcParametersElement.setJDBCSourceParameterConnection(
3460                    vecJDBCSourceValue.get(i).toString());
3461              } else {
3462                this.logger.write("normal",
3463                    "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor");
3464                LoaderException le = new LoaderException(
3465                    "Exception:", new Exception JavaDoc("Value of Connection.Url perameter SelectMethod has to be cursor"));
3466                this.logger.write("full", le.getStackTraceAsString());
3467                throw le;
3468              }
3469            } else {
3470              jdbcParametersElement.setJDBCSourceParameterConnection(
3471                  vecJDBCSourceValue.get(i).toString());
3472            }
3473          } else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("User"))
3474            jdbcParametersElement.setJDBCSourceParameterUser(vecJDBCSourceValue.
3475                get(i).toString());
3476          else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase(
3477              "Password"))
3478            jdbcParametersElement.setJDBCSourceParameterPassword(
3479                vecJDBCSourceValue.get(i).toString());
3480        }
3481      }
3482      vecJDBCTargetValue = OctopusXMLUtil.importValue(doc,
3483                           "jdbcTargetParameter",
3484                           "value", iJobNumber);
3485      vecJDBCTargetName = OctopusXMLUtil.importValue(doc, "jdbcTargetParameter",
3486                          "name", iJobNumber);
3487
3488      if (vecJDBCTargetValue.size() != 0) {
3489        for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
3490          if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
3491            jdbcParametersElement.setJDBCTargetParameterDriver(
3492                vecJDBCTargetValue.get(i).toString());
3493          else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase(
3494              "Connection.Url")) {
3495            //Testing SelectMethod parameter in microsoft MSSQL driver
3496
if (vecJDBCTargetValue.get(i).toString().indexOf(
3497                "jdbc:microsoft:sqlserver") != -1) {
3498              if (vecJDBCTargetValue.get(i).toString().indexOf("SelectMethod") ==
3499                  -1) {
3500                jdbcParametersElement.setJDBCTargetParameterConnection(
3501                    vecJDBCTargetValue.get(i).toString() +
3502                    ";SelectMethod=cursor");
3503              } else if (vecJDBCTargetValue.get(i).toString().indexOf("cursor") !=
3504                  -1) {
3505                jdbcParametersElement.setJDBCTargetParameterConnection(
3506                    vecJDBCTargetValue.get(i).toString());
3507              } else {
3508                this.logger.write("normal",
3509                    "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor");
3510                LoaderException le = new LoaderException(
3511                    "Exception:",new Exception JavaDoc("value of Connection.Url parameter SelectMethod has to be cursor"));
3512                this.logger.write("full", le.getStackTraceAsString());
3513                throw le;
3514              }
3515            } else {
3516              jdbcParametersElement.setJDBCTargetParameterConnection(
3517                  vecJDBCTargetValue.get(i).toString());
3518            }
3519          } else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("User"))
3520            jdbcParametersElement.setJDBCTargetParameterUser(vecJDBCTargetValue.
3521                get(i).toString());
3522          else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase(
3523              "Password"))
3524            jdbcParametersElement.setJDBCTargetParameterPassword(
3525                vecJDBCTargetValue.get(i).toString());
3526        }
3527      }
3528      // to and form hex
3529
vecToHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn",
3530                     "toHex", iJobNumber);
3531      vecFromHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn",
3532                       "fromHex", iJobNumber);
3533      // defalut values
3534
vecDefaultValueTemp = OctopusXMLUtil.importValue(doc, "valueColumn",
3535                            "defaultValue", iJobNumber);
3536      this.vecDefaultVariableValue = OctopusXMLUtil.importValue(doc,
3537                                     "variableColumn",
3538                                     "defaultValue", iJobNumber);
3539      this.vecDefaultVariableName = OctopusXMLUtil.importValue(doc,
3540                                    "variableColumn",
3541                                    "name", iJobNumber);
3542      this.vecDefaultRelationValue = OctopusXMLUtil.importValue(doc,
3543                                     "relationColumn",
3544                                     "defaultValue", iJobNumber);
3545      this.vecTempUserID = OctopusXMLUtil.importValue(doc, "userIDColumn",
3546                           "defaultValue", iJobNumber);
3547      vecValueColumnSourceColumnName = OctopusXMLUtil.importValue(doc,
3548                                       "valueColumn",
3549                                       "sourceColumnName", iJobNumber);
3550      vecValueColumnTargetTableName = OctopusXMLUtil.importValue(doc,
3551                                      "valueColumn",
3552                                      "targetTableName", iJobNumber);
3553      this.iValueColumns = vecValueColumnTargetTableName.size();
3554      vecValueColumnTargetColumnName = OctopusXMLUtil.importValue(doc,
3555                                       "valueColumn",
3556                                       "targetColumnName", iJobNumber);
3557      vecValueColumnTargetTableID = OctopusXMLUtil.importValue(doc,
3558                                    "valueColumn",
3559                                    "targetTableID", iJobNumber);
3560      vecValueColumnValueMode = OctopusXMLUtil.importValue(doc, "valueColumn",
3561                                "valueMode", iJobNumber);
3562      this.vecVariableColumnName = OctopusXMLUtil.importValue(doc,
3563                                   "variableColumn",
3564                                   "name", iJobNumber);
3565      this.vecVariableColumnTargetTableName = OctopusXMLUtil.importValue(doc,
3566                                              "variableColumn",
3567                                              "targetTableName", iJobNumber);
3568      this.vecVariableColumnTargetColumnName = OctopusXMLUtil.importValue(doc,
3569                                               "variableColumn", "targetColumnName", iJobNumber);
3570      this.vecVariableColumnTargetTableID = OctopusXMLUtil.importValue(doc,
3571                                            "variableColumn",
3572                                            "targetTableID", iJobNumber);
3573      this.vecVariableColumnValueMode = OctopusXMLUtil.importValue(doc,
3574                                        "variableColumn",
3575                                        "valueMode", iJobNumber);
3576      this.vecVariableUseIDTableName = OctopusXMLUtil.importValue(doc,
3577                                       "userIDColumn",
3578                                       "targetTableName", iJobNumber);
3579      this.vecVariableUseIDColumnName = OctopusXMLUtil.importValue(doc,
3580                                        "userIDColumn",
3581                                        "targetColumnName", iJobNumber);
3582      this.vecVariableUseIDTableID = OctopusXMLUtil.importValue(doc,
3583                                     "userIDColumn",
3584                                     "targetTableID", iJobNumber);
3585      this.vecVariableUseIDValueMode = OctopusXMLUtil.importValue(doc,
3586                                       "userIDColumn",
3587                                       "valueMode", iJobNumber);
3588      this.vecVariableTimesTableName = OctopusXMLUtil.importValue(doc,
3589                                       "timeStampColumn",
3590                                       "targetTableName", iJobNumber);
3591      this.vecVariableTimesColumnName = OctopusXMLUtil.importValue(doc,
3592                                        "timeStampColumn",
3593                                        "targetColumnName", iJobNumber);
3594      this.vecVariableTimesTableID = OctopusXMLUtil.importValue(doc,
3595                                     "timeStampColumn",
3596                                     "targetTableID", iJobNumber);
3597      this.vecVariableTimesValueMode = OctopusXMLUtil.importValue(doc,
3598                                       "timeStampColumn",
3599                                       "valueMode", iJobNumber);
3600      this.vecConstantColumnTargetTableName = OctopusXMLUtil.importValue(doc,
3601                                              "constantColumn",
3602                                              "targetTableName", iJobNumber);
3603      this.iConstantColumns = this.vecConstantColumnTargetTableName.size();
3604      vecConstantColumnTargetColumnName = OctopusXMLUtil.importValue(doc,
3605                                          "constantColumn",
3606                                          "targetColumnName", iJobNumber);
3607      this.vecConstantColumnTargetTableID = OctopusXMLUtil.importValue(doc,
3608                                            "constantColumn",
3609                                            "targetTableID", iJobNumber);
3610      vecConstantColumnValueMode = OctopusXMLUtil.importValue(doc,
3611                                   "constantColumn", "valueMode", iJobNumber);
3612
3613      vecConstantColumnConstantValue = OctopusXMLUtil.importValue(doc,
3614                                       "constantColumn",
3615                                       "constantValue", iJobNumber, null);
3616      this.vecRelationColumnSourceTableName = OctopusXMLUtil.importValue(doc,
3617                                              "relationColumn",
3618                                              "relationSourceTableName", iJobNumber);
3619      this.iRelationColumns = this.vecRelationColumnSourceTableName.size();
3620      this.vecRelationColumnSourceTableID = OctopusXMLUtil.importValue(doc,
3621                                            "relationColumn",
3622                                            "relationSourceTableID", iJobNumber);
3623      this.vecRelationColumnSourceColumnName = OctopusXMLUtil.importValue(doc,
3624                                               "relationColumn", "relationSourceColumnName",
3625                                               iJobNumber);
3626      this.vecRelationColumnTargetTableName = OctopusXMLUtil.importValue(doc,
3627                                              "relationColumn",
3628                                              "relationTargetTableName", iJobNumber);
3629      this.vecRelationColumnTargetColumnName = OctopusXMLUtil.importValue(doc,
3630                                               "relationColumn", "relationTargetColumnName",
3631                                               iJobNumber);
3632      this.vecRelationColumnTargetTableID = OctopusXMLUtil.importValue(doc,
3633                                            "relationColumn",
3634                                            "relationTargetTableID", iJobNumber);
3635      this.vecRelationColumnRelationMode = OctopusXMLUtil.importValue(doc,
3636                                           "relationColumn",
3637                                           "relationMode", iJobNumber);
3638//rale
3639

3640      ImportDefinitionSourceColumnName = vecValueColumnSourceColumnName;
3641      ImportDefinitionTargetColumnName = vecValueColumnTargetColumnName;
3642
3643//sinisa 02.03.2003. Add counterColumns
3644
this.counterColumns = new CounterColumns();
3645      this.counterColumns.setLogger(this.logger);
3646      this.counterColumns.resetSubCounterCache();
3647      this.counterColumns.readConstantColumnAttributes(doc, iJobNumber);
3648      this.counterColumns.readConstantColumnsParameters(doc, iJobNumber);
3649//end sinisa
3650

3651//sinisa 02.03.2003. Add transformations
3652
this.transformations = new Transformations(this.logger);
3653      //ArrayList transTableNamesIDs = this.transformations.getTransformationsTableNamesAndIDs();
3654
this.transformations.createTransformationElements(doc, iJobNumber);
3655      ArrayList JavaDoc trans = this.transformations.getTransformations();
3656      Iterator JavaDoc iTrans = trans.iterator();
3657      
3658      
3659      while(iTrans.hasNext()) {
3660            Transformation temp = (Transformation)iTrans.next();
3661            temp.setLogger(this.logger);
3662            
3663            //temp.readSourceColumns(doc, iJobNumber);
3664
//temp.readTargetColumns(doc, iJobNumber);
3665
//temp.readSourceColumns();
3666
//temp.readTargetColumns();
3667

3668        }
3669      
3670//end sinisa
3671

3672      this.vecTableTableName = OctopusXMLUtil.importValue(doc, "table",
3673                               "tableName",
3674                               iJobNumber);
3675      this.iTables = this.vecTableTableName.size();
3676      this.vecTableTableID = OctopusXMLUtil.importValue(doc, "table", "tableID",
3677                             iJobNumber);
3678      this.vecTableInsert = OctopusXMLUtil.importValue(doc, "table", "insert",
3679                            iJobNumber);
3680      this.vecTableTableMode = OctopusXMLUtil.importValue(doc, "table",
3681                               "tableMode", iJobNumber, loaderJobReader.getDefaultTableMode());
3682      this.vecTableOidLogic = OctopusXMLUtil.importValue(doc, "table",
3683                              "oidLogic",
3684                              iJobNumber,
3685                              (new Boolean JavaDoc(loaderJobReader.getDefaultOidLogic())).toString());
3686
3687      this.vecCTAutoMapp = OctopusXMLUtil.importValue(doc, "table",
3688                           "autoMapColumns", iJobNumber);
3689      this.vecCTDefaultMode = OctopusXMLUtil.importValue(doc, "table",
3690                              "defaultMode", iJobNumber);
3691
3692      if (this.vecRelationColumnSourceTableName.size() != 0) {
3693        this.changeRelationsOrder();
3694        this.changeTableOrder();
3695      }
3696      this.vecRelationKeyColumns.setSize(this.iTables);
3697      this.vecRelationKeyTypes.setSize(this.iTables);
3698      this.vecConstantTargetColumnName.setSize(this.iTables);
3699//ZK added this
3700
// this.transformationsColumnNames.setSize(this.iTables);
3701

3702      this.vecConstantValueMode.setSize(this.iTables);
3703      this.vecConstantConstantValue.setSize(this.iTables);
3704      this.vecConstantColumnType.setSize(this.iTables);
3705      for (int k = 0; k < vecValueColumnTargetTableName.size(); k++) {
3706        boolean isImportColumn = false;
3707        for (int l = 0; l < this.iTables; l++) {
3708          if (vecValueColumnTargetTableName.get(k).toString().equalsIgnoreCase(this.
3709              vecTableTableName.get(l).toString())
3710              &&
3711              vecValueColumnTargetTableID.get(k).toString().equalsIgnoreCase(this.
3712              vecTableTableID.
3713              get(l).toString())) {
3714            isImportColumn = true;
3715          }
3716        }
3717        if (!isImportColumn) {
3718          this.logger.write("normal",
3719              "Incorrect XML import variables - TABLE ID");
3720          LoaderException le = new LoaderException("Exception: ",
3721                               (Throwable JavaDoc) (new Exception JavaDoc(
3722                               "Incorrect XML import variables - TABLE ID")));
3723          this.logger.write("full", le.getStackTraceAsString());
3724          throw le;
3725        }
3726      }
3727
3728      if (this.vecVariableUseIDTableName.size() != 0) {
3729        String JavaDoc tempUserID = this.vecTempUserID.get(0).toString();
3730        if (userIDExists)
3731          this.strUserID = "";
3732        if (this.strUserID.equals("")) {
3733          if (!tempUserID.equalsIgnoreCase("")) {
3734            this.strUserID = tempUserID;
3735            this.userIDExists = true;
3736          } else {
3737            this.logger.write("normal", "Error : User parametar missing");
3738            LoaderException le = new LoaderException("Exception: ",
3739                                 (Throwable JavaDoc) (new Exception JavaDoc("Error : User parametar missing")));
3740                        this.logger.write("full", le.getStackTraceAsString());
3741            throw le;
3742          }
3743        }
3744      }
3745      for (int k = 0; k < this.iTables; k++) {
3746        iNumberOfColumns = 0;
3747        Vector JavaDoc vecTargetTable1 = new Vector JavaDoc();
3748        Vector JavaDoc vecTargetTable2 = new Vector JavaDoc();
3749        Vector JavaDoc vecTargetTable3 = new Vector JavaDoc();
3750        Vector JavaDoc vecTargetTable4 = new Vector JavaDoc();
3751        Vector JavaDoc vecTargetTable5 = new Vector JavaDoc();
3752        Vector JavaDoc vecTargetTable6 = new Vector JavaDoc();
3753        Vector JavaDoc vecTargetTable7 = new Vector JavaDoc();
3754        Vector JavaDoc vecTargetTable8 = new Vector JavaDoc();
3755        Vector JavaDoc vecTargetTable9 = new Vector JavaDoc();
3756        Vector JavaDoc vecTargetTable10 = new Vector JavaDoc();
3757        Vector JavaDoc vecTargetTable11 = new Vector JavaDoc();
3758
3759        for (int l = 0; l < this.iValueColumns; l++) {
3760          if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(
3761              vecValueColumnTargetTableName.get(l).toString())
3762              &&
3763              vecValueColumnTargetTableID.get(l).toString().equalsIgnoreCase(this.
3764              vecTableTableID.
3765              get(k).toString())) {
3766            iNumberOfColumns++;
3767            vecTargetTable1.addElement(vecValueColumnSourceColumnName.get(l).
3768                toString());
3769            vecTargetTable2.addElement(vecValueColumnTargetColumnName.get(l).
3770                toString());
3771            vecTargetTable4.addElement(vecValueColumnValueMode.get(l).toString());
3772            //rale
3773
vecTargetTable9.addElement(vecDefaultValueTemp.get(l).toString());
3774            vecTargetTable10.addElement(vecToHexTemp.get(l).toString());
3775            vecTargetTable11.addElement(vecFromHexTemp.get(l).toString());
3776            if (vecValueColumnValueMode.get(l).toString().equalsIgnoreCase(
3777                "Key"))
3778              vecTargetTable5.addElement(vecValueColumnTargetColumnName.get(l).
3779                  toString());
3780          }
3781        }
3782        for (int l = 0; l < this.vecVariableUseIDTableName.size(); l++) {
3783          if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(this.
3784              vecVariableUseIDTableName.get(l).toString())
3785              &&
3786              this.vecVariableUseIDTableID.get(l).toString().
3787              equalsIgnoreCase(this.vecTableTableID.get(k).toString())) {
3788            vecTargetTable2.addElement(this.vecVariableUseIDColumnName.get(l).
3789                toString());
3790            vecTargetTable4.addElement(this.vecVariableUseIDValueMode.get(l).
3791                toString());
3792            //rale
3793
// vecTargetTable9.addElement(vecDefaultValueTemp.get(l).toString());
3794
// vecTargetTable10.addElement(vecToHexTemp.get(l).toString());
3795
// vecTargetTable11.addElement(vecFromHexTemp.get(l).toString());
3796

3797            if (this.vecVariableUseIDValueMode.get(l).toString().
3798                equalsIgnoreCase("Key"))
3799              vecTargetTable5.addElement(this.vecVariableUseIDColumnName.get(l).
3800                  toString());
3801          }
3802        }
3803        for (int l = 0; l < this.vecRelationColumnSourceColumnName.size(); l++) {
3804          if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(this.
3805              vecRelationColumnTargetTableName.get(l).toString())
3806              &&
3807              this.vecRelationColumnTargetTableID.get(l).toString().
3808              equalsIgnoreCase(this.vecTableTableID.get(k).toString())
3809              &&
3810              this.vecRelationColumnRelationMode.get(l).toString().
3811              equalsIgnoreCase("Key")) {
3812            vecTargetTable3.addElement(this.vecRelationColumnTargetColumnName.get(l).toString());
3813          }
3814        }
3815
3816        //rale
3817
this.vecToHex.addElement(vecToHexTemp);
3818        this.vecFromHex.addElement(vecFromHexTemp);
3819        this.vecDefaultValue.addElement(vecTargetTable9);
3820        this.vecSourceColumnName.addElement(vecTargetTable1);
3821        this.vecTargetColumnName.addElement(vecTargetTable2);
3822        this.vecRelationKeyColumns.setElementAt(vecTargetTable3, k);
3823        this.vecValueMode.addElement(vecTargetTable4);
3824        this.vecTargetKeyColumnName.addElement(vecTargetTable5);
3825        this.vecValueColumnsTargetTables.addElement(new Integer JavaDoc(
3826            iNumberOfColumns));
3827        for (int p = 0; p < this.iConstantColumns; p++) {
3828          if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(this.
3829              vecConstantColumnTargetTableName.get(p).toString())
3830              &&
3831              this.vecConstantColumnTargetTableID.get(p).toString().
3832              equalsIgnoreCase(this.vecTableTableID.get(k).toString())) {
3833            vecTargetTable6.addElement(vecConstantColumnTargetColumnName.get(p).
3834                toString());
3835            vecTargetTable7.addElement(vecConstantColumnValueMode.get(p).
3836                toString());
3837            if (vecConstantColumnConstantValue.get(p) == null)
3838              vecTargetTable8.addElement(null);
3839            else
3840              vecTargetTable8.addElement(vecConstantColumnConstantValue.get(p).
3841                  toString());
3842          }
3843        }
3844        this.vecConstantTargetColumnName.setElementAt(vecTargetTable6,
3845            k);
3846        this.vecConstantValueMode.setElementAt(vecTargetTable7, k);
3847        this.vecConstantConstantValue.setElementAt(vecTargetTable8,
3848            k);
3849
3850//sinisa 02.03.2003. Add counterColumns
3851

3852        this.counterColumns.setConstantColumnsParameters(this.vecTableTableName.
3853            get(k).toString(), this.vecTableTableID.get(k).toString());
3854//end sinisa
3855
}
3856
3857      for (int i = 0; i < this.vecRelationColumnSourceColumnName.size(); i++) {
3858        if (this.vecRelationColumnSourceColumnName.get(i).toString().equals("")) {
3859          for (int k = 0; k < this.vecTableTableName.size(); k++) {
3860            if (this.vecRelationColumnSourceTableName.get(i).toString().
3861                equalsIgnoreCase(this.vecTableTableName.get(k).toString())
3862                &&
3863                this.vecRelationColumnSourceTableID.get(i).toString().
3864                equalsIgnoreCase(this.vecTableTableID.get(k).toString())) {
3865              if (this.vecTableOidLogic.get(k).toString().equalsIgnoreCase("true"))
3866                this.vecRelationColumnSourceColumnName.setElementAt(this.currentOidColumnName, i);
3867// this.vecRelationColumnSourceColumnName.setElementAt("oid",i);
3868
}
3869          }
3870        }
3871      }
3872      this.vecRelationSourceValue.setSize(this.iRelationColumns);
3873      this.vecRelationSourceType.setSize(this.iRelationColumns);
3874    }
3875    catch (NullPointerException JavaDoc ex) {
3876      throw ex;
3877    }
3878    catch (Exception JavaDoc ex) {
3879      throw ex;
3880    }
3881    this.logger.write("full", "\timportXMLFile method is finished.");
3882  }
3883
3884  /**
3885   * Method updateCurrentTime write system time into timeStamp variable columns
3886   * @param c Connection to the target table.
3887   * @param iTable Number of target table.
3888   * @param strQueryWhereSQL Part of SQL query - where clause.
3889   * @param currentVersion represents current version of insert/update
3890   * @param oid repersents if the oid logic is present
3891   * @throws SQLException
3892   * @throws NullPointerException
3893   * @return true if something is written to database
3894   */

3895  private boolean updateCurrentTime(Connection JavaDoc c, int iTable,
3896      String JavaDoc strQueryWhereSQL,
3897      int currentVersion, boolean oid) throws
3898      SQLException JavaDoc, NullPointerException JavaDoc {
3899    String JavaDoc strQueryInsertTime = "";
3900    boolean bWriteData = false;
3901    String JavaDoc oidVersion = "";
3902// if (oid)
3903
// oidVersion = ", version=" + currentVersion;
3904
if (oid)
3905      oidVersion = ", " + this.currentVersionColumnName + "=" + currentVersion;
3906    this.logger.write("full", "\t updateCurrentTime method is started.");
3907    try {
3908      for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
3909        if (this.vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(this.
3910            vecTableTableName.get(iTable).toString())
3911            &&
3912            this.vecVariableTimesTableID.get(i).toString().equalsIgnoreCase(this.
3913            vecTableTableID.
3914            get(iTable).toString())) {
3915          Statement JavaDoc stmtRelations = c.createStatement();
3916          strQueryInsertTime = "update " +
3917                               this.vecVariableTimesTableName.get(i).toString()
3918                               + " set " + this.vecVariableTimesColumnName.get(i).toString()
3919                               + " = ";
3920          if (this.vecVariableTimesValueMode.get(i).toString().equalsIgnoreCase(
3921              "Overwrite"))
3922
3923            //&& bWriteData == true)
3924
strQueryInsertTime += " '" + this.createCurrentDate() +
3925                "'" + oidVersion + " where " + strQueryWhereSQL;
3926          else
3927            strQueryInsertTime += " '" + this.createCurrentDate()
3928                + "'" + oidVersion + " where " +
3929                this.vecVariableTimesColumnName.get(i).toString()
3930                + " is null and " + strQueryWhereSQL;
3931          this.logger.write("full", "\tQuery '" + strQueryInsertTime
3932              + "' will be executed");
3933          if (bReplaceInData) {
3934            strQueryInsertTime = this.replaceInData(strQueryInsertTime);
3935          }
3936          int num = stmtRelations.executeUpdate(strQueryInsertTime);
3937          if (num != 0) {
3938            bWriteData = true;
3939          }
3940          stmtRelations.close();
3941        }
3942      }
3943    }
3944    catch (SQLException JavaDoc ex) {
3945      throw ex;
3946    }
3947    catch (NullPointerException JavaDoc ex) {
3948      throw ex;
3949    }
3950    this.logger.write("full", "\tupdateCurrentTime method is finished.");
3951    return bWriteData;
3952  }
3953
3954  /**
3955   * Method updateNameValue writes nameValue value (Loader's argument) into variable columns
3956   * @param c Connection to the target table.
3957   * @param iTable Number of target table.
3958   * @param strQueryWhereSQL Part of SQL query - where clause.
3959   * @param currentVersion represents current version of insert/update
3960   * @param oid define if oid logic is present
3961   * @throws SQLException
3962   * @throws NullPointerException
3963   * @throws LoaderException
3964   * @return true if something is written to database
3965   */

3966  private boolean updateNameValue(Connection JavaDoc c, int iTable,
3967      String JavaDoc strQueryWhereSQL, int currentVersion,
3968      boolean oid) throws SQLException JavaDoc,
3969      NullPointerException JavaDoc, LoaderException {
3970
3971    String JavaDoc strQueryInsertName = "";
3972    boolean bWriteData = false;
3973    String JavaDoc oidVersion = "";
3974// if (oid)
3975
// oidVersion = ", version=" + currentVersion;
3976
if (oid)
3977      oidVersion = ", " + this.currentVersionColumnName + "=" + currentVersion;
3978
3979    this.logger.write("full", "\t updateNameValue method is started.");
3980    try {
3981      for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
3982        boolean bInsert = true;
3983        if (this.vecVariableColumnTargetTableName.get(i).toString().
3984            equalsIgnoreCase(this.vecTableTableName.get(iTable).toString())
3985            &&
3986            this.vecVariableColumnTargetTableID.get(i).toString().
3987            equalsIgnoreCase(this.vecTableTableID.get(iTable).toString())) {
3988          int iPositionInVector = this.vecVariableName.indexOf(this.
3989                                  vecVariableColumnName.get(i).toString());
3990          if (iPositionInVector != -1) {
3991            Statement JavaDoc stmtRelations = c.createStatement();
3992            strQueryInsertName = "update " +
3993                                 this.vecVariableColumnTargetTableName.get(i).toString()
3994                                 + " set " +
3995                                 this.vecVariableColumnTargetColumnName.get(i).toString()
3996                                 + " = ";
3997            if (this.vecVariableColumnValueMode.get(i).toString().
3998                equalsIgnoreCase("Overwrite")) {
3999              if (this.vecVariableValue.get(iPositionInVector) == null) {
4000                String JavaDoc variableName = this.vecVariableColumnName.get(i).
4001                                      toString();
4002                for (int k = 0; k < this.vecDefaultVariableName.size(); k++) {
4003                  if (this.vecDefaultVariableName.get(k).toString().
4004                      equalsIgnoreCase(variableName)) {
4005                    if (!this.vecDefaultVariableValue.get(k).toString().
4006                        equalsIgnoreCase("")) {
4007// if (!CheckType.isNumber(this.vecVariableColumnTypes.get(i).
4008
// toString()))
4009
//ZK change this from CheckType to configReaderTarget this 7.5.2004
4010

4011                            if (!configReaderTarget.isNumber(this.vecVariableColumnTypes.get(i).
4012                                                                            toString()))
4013                                                                            
4014                                 strQueryInsertName += " '" +
4015                                 this.vecDefaultVariableValue.get(k).toString() +
4016                                                        "' " +
4017                                 oidVersion + " where " + strQueryWhereSQL;
4018                            else
4019                                 strQueryInsertName += " " +
4020                                 this.vecDefaultVariableValue.get(k) + " " +
4021                                 oidVersion + " where " + strQueryWhereSQL;
4022                      
4023                    } else {
4024                      strQueryInsertName += " null" + oidVersion + " where " +
4025                          strQueryWhereSQL;
4026                    }
4027                    break;
4028                  }
4029                }
4030              } else {
4031//ZK change this from CheckType to configReaderTarget this 7.5.2004
4032
if (!configReaderTarget.isNumber(this.vecVariableColumnTypes.get(i).
4033                    toString()))
4034                  strQueryInsertName += " '" +
4035                      this.vecVariableValue.get(iPositionInVector).toString()
4036                      + "'" + oidVersion + " where " + strQueryWhereSQL;
4037                else
4038                  strQueryInsertName +=
4039                      this.vecVariableValue.get(iPositionInVector).toString()
4040                      + oidVersion + " where " + strQueryWhereSQL;
4041              }
4042            } else if (this.vecVariableColumnValueMode.get(i).toString().
4043                equalsIgnoreCase("SetNull")) {
4044              if (this.vecVariableValue.get(iPositionInVector) == null)
4045                strQueryInsertName += " null" + oidVersion + " where " +
4046                    strQueryWhereSQL;
4047              else
4048                bInsert = false;
4049            } else {
4050              if (this.vecVariableValue.get(iPositionInVector) == null) {
4051                String JavaDoc variableName = this.vecVariableColumnName.get(i).
4052                                      toString();
4053                for (int k = 0; k < this.vecDefaultVariableName.size(); k++) {
4054                  if (this.vecDefaultVariableName.get(k).toString().
4055                      equalsIgnoreCase(variableName)) {
4056                    if (!this.vecDefaultVariableValue.get(k).toString().
4057                        equalsIgnoreCase("")) {
4058//ZK change this from CheckType to configReaderTarget this 7.5.2004
4059
if (!configReaderTarget.isNumber(this.vecVariableColumnTypes.get(i).
4060                          toString()))
4061                        strQueryInsertName += " '" +
4062                            this.vecDefaultVariableValue.get(k).toString() +
4063                            "' " +
4064                            oidVersion + " where " +
4065                            this.vecVariableColumnTargetColumnName.get(i).
4066                            toString()
4067                            + " is null and " + strQueryWhereSQL;
4068                      else
4069                        strQueryInsertName += " " +
4070                            this.vecDefaultVariableValue.get(k) + " " +
4071                            oidVersion + " where " +
4072                            this.vecVariableColumnTargetColumnName.get(i).
4073                            toString()
4074                            + " is null and " + strQueryWhereSQL;
4075                    } else {
4076                      strQueryInsertName += " null" + oidVersion + " where " +
4077                          this.vecVariableColumnTargetColumnName.get(i).
4078                          toString()
4079                          + " is null and " + strQueryWhereSQL;
4080                    }
4081                    break;
4082                  }
4083                }
4084              } else {
4085//ZK change this from CheckType to configReaderTarget this 7.5.2004
4086
if (!configReaderTarget.isNumber(this.vecVariableColumnTypes.get(i).
4087                    toString()))
4088                  strQueryInsertName += " '" +
4089                      this.vecVariableValue.get(iPositionInVector).toString()
4090                      + "'" + oidVersion + " where " +
4091                      this.vecVariableColumnTargetColumnName.get(i).toString()
4092                      + " is null and " + strQueryWhereSQL;
4093                else
4094                  strQueryInsertName +=
4095                      this.vecVariableValue.get(iPositionInVector).toString()
4096                      + oidVersion + " where " +
4097                      this.vecVariableColumnTargetColumnName.get(i).toString()
4098                      + " is null and " + strQueryWhereSQL;
4099              }
4100            }
4101            if (bInsert)
4102              this.logger.write("full", "\tQuery '" + strQueryInsertName
4103                  + "' will be executed");
4104
4105            if (bReplaceInData) {
4106              strQueryInsertName = this.replaceInData(strQueryInsertName);
4107            }
4108            if (bInsert) {
4109              int num = 0;
4110              try {
4111                num = stmtRelations.executeUpdate(strQueryInsertName);
4112              }
4113              catch (SQLException JavaDoc ex) {
4114                stmtRelations.close();
4115                stmtRelations = c.createStatement();
4116                if ( (importDefinitionElement.strDefaultCutOffData.
4117                    equalsIgnoreCase("true"))) {
4118                  dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName.
4119                      get(iTable).toString(), c,
4120                      "", currentRow, strQueryInsertName,
4121                      importDefinitionElement.strOnErrorContinueXml,
4122                      importDefinitionElement.strImportDefinitionName, strQueryInsertName);
4123                } else
4124                  throw ex;
4125              }
4126            }
4127// stmtRelations.close();
4128
} else {
4129            this.logger.write("normal",
4130                "\tError: Cannot find value for variable column :"
4131                + this.vecVariableColumnName.get(i).toString());
4132            LoaderException le = new LoaderException("Exception: ",
4133                                 (Throwable JavaDoc) (new Exception JavaDoc(
4134                                 "Error: Cannot find value for variable column :")));
4135                        this.logger.write("full", le.getStackTraceAsString());
4136            throw le;
4137          }
4138        }
4139      }
4140    }
4141    catch (SQLException JavaDoc ex) {
4142      throw ex;
4143    }
4144    catch (NullPointerException JavaDoc ex) {
4145      throw ex;
4146    }
4147    this.logger.write("full", "\tupdateNameValue method is finished.");
4148    return bWriteData;
4149  }
4150
4151  /**
4152   * Method queryRelations is used to make SQL query for reading source value for relations between target tables.
4153   * It puts the value from the source column in source relation
4154   * table to the target column in target relation table. If there
4155   * is an error, Exception "SQLException" or NullPointerException is thrown.
4156   * @param iTableInt Number of target table.
4157   * @param iNumberOfRelationColumn Number of relation tag.
4158   * @param strQueryWhere Part of SQL query - where clause.
4159   * @param conn represents connection to target database
4160   * @param currentVersion represents currnet version of insert/update
4161   * @param oid define if oid logic is present
4162   * @return String which will be executed for update or insert relation columns into target tables
4163       * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
4164   * @throws LoaderException
4165   */

4166  private String JavaDoc queryRelations(int iTableInt, int iNumberOfRelationColumn,
4167      String JavaDoc strQueryWhere, Connection JavaDoc conn,
4168      int currentVersion,
4169      boolean oid) throws NullPointerException JavaDoc,
4170      LoaderException {
4171    this.logger.write("full", "\tqueryRelations method is started.");
4172    String JavaDoc strQueryRelations = "";
4173    String JavaDoc oidVersion = "";
4174    String JavaDoc selectValueInRel = "";
4175    String JavaDoc currentValueInRel = "";
4176// if (oid)
4177
// oidVersion = ", version=" + currentVersion;
4178
if (oid)
4179      oidVersion = ", " + this.currentVersionColumnName + "=" + currentVersion;
4180
4181    try {
4182      strQueryRelations = "update " +
4183                          this.vecRelationColumnTargetTableName.get(iNumberOfRelationColumn).
4184                          toString() + " set " +
4185                          this.vecRelationColumnTargetColumnName.get(iNumberOfRelationColumn).
4186                          toString();
4187      if (this.vecRelationSourceValue.get(iNumberOfRelationColumn) == null) {
4188        String JavaDoc replacementValueInRel = vecDefaultRelationValue.get(
4189                                       iNumberOfRelationColumn).toString();
4190        if (!replacementValueInRel.equalsIgnoreCase("")) {
4191          try {
4192            Statement JavaDoc stmt = conn.createStatement();
4193            ResultSet JavaDoc newRelationValue;
4194            String JavaDoc relationValue;
4195            boolean isFull = false;
4196            if (!replacementValueInRel.equalsIgnoreCase(selectValueInRel)) {
4197              selectValueInRel = replacementValueInRel;
4198              newRelationValue = stmt.executeQuery(replacementValueInRel);
4199              isFull = newRelationValue.next();
4200              if (isFull) {
4201                relationValue = newRelationValue.getString(1);
4202                currentValueInRel = relationValue;
4203              } else {
4204                relationValue = "";
4205                currentValueInRel = "";
4206              }
4207              newRelationValue.close();
4208            } else {
4209              if (!currentValueInRel.equalsIgnoreCase("") && currentValueInRel != null) {
4210                relationValue = currentValueInRel;
4211                isFull = true;
4212              } else {
4213                relationValue = "";
4214              }
4215            }
4216            if (isFull) {
4217              strQueryRelations +=
4218                  dataCleaning.cleaningRelationValues(this.vecTableTableName.
4219                  get(iTableInt).toString(),
4220                  this.vecRelationColumnTargetColumnName.get(
4221                  iNumberOfRelationColumn).toString(), relationValue,
4222                  this.vecRelationSourceType.get(iNumberOfRelationColumn).
4223                  toString(),
4224                  currentRow, conn, "UPDATE", currentVersion, oid,
4225                  importDefinitionElement.strImportDefinitionName,
4226                  this.currentVersionColumnName, replacementValueInRel);
4227
4228            } else {
4229              dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).
4230                  toString(), conn, currentRow, "UPDATE",
4231                  "Default value '" + replacementValueInRel +
4232                  "' for relations is not valid.",
4233                  importDefinitionElement.strImportDefinitionName,replacementValueInRel);
4234              strQueryRelations += " = null " + oidVersion + " where ";
4235            }
4236          }
4237          catch (SQLException JavaDoc ex) {
4238            String JavaDoc msg = "Default value for foreign key(" +
4239                         replacementValueInRel +
4240                         ") is not valid. Import definition name: " +
4241                         importDefinitionElement.strImportDefinitionName;
4242            LoaderException le = new LoaderException("SQLException: " + msg,
4243                                 (Throwable JavaDoc)ex);
4244                        this.logger.write("full", le.getStackTraceAsString());
4245            throw le;
4246          }
4247
4248        } else
4249          strQueryRelations += " = null " + oidVersion + " where ";
4250      } else {
4251          //TODO Check this part of code. ZK change from configReaderSource to configReaderTarget because of problems with relation columns.
4252
if (configReaderTarget.isNumber(this.vecRelationSourceType.get(
4253                  iNumberOfRelationColumn).
4254                  toString())) {
4255              strQueryRelations += " = " +
4256              this.vecRelationSourceValue.get(iNumberOfRelationColumn).toString()
4257              + oidVersion + " where ";
4258          }
4259          else {
4260              strQueryRelations += " = ";
4261              if(configReaderTarget.isWithN(
4262                      this.vecRelationSourceType.get(
4263                      iNumberOfRelationColumn).
4264                      toString())) {
4265                  strQueryRelations += "N";
4266              }
4267              strQueryRelations += "'" +
4268              this.vecRelationSourceValue.get(iNumberOfRelationColumn).toString() +
4269              "'"
4270              + oidVersion + " where ";
4271          }
4272          
4273      }
4274      strQueryRelations += strQueryWhere;
4275      if (strQueryRelations.trim().endsWith("where"))
4276        strQueryRelations = strQueryRelations.substring(0,
4277                            strQueryRelations.length()
4278                            - 6);
4279      else {
4280        if (!this.vecRelationColumnRelationMode.get(iNumberOfRelationColumn).
4281            toString().equalsIgnoreCase("overwrite")) {
4282// ||
4283
// !this.vecRelationColumnRelationMode.get(iNumberOfRelationColumn).toString().
4284
// equalsIgnoreCase("SetIfCreated")) {
4285

4286          strQueryRelations += " and " +
4287              this.vecRelationColumnTargetColumnName.
4288              get(iNumberOfRelationColumn).toString()
4289              + " is null";
4290        }
4291      }
4292    }
4293    catch (NullPointerException JavaDoc ex) {
4294      throw ex;
4295    }
4296    this.logger.write("full", "\tqueryRelations method is finished.");
4297    return strQueryRelations;
4298  }
4299
4300  /**
4301   * Method insertTargetTable is used to put one row of data from columns
4302   * of source tables into target table ordered by column modes.
4303   * If there is an error, Exception "SQLException, "NullPointerException"
4304   * or "Exception" is thrown.
4305   * @param iTableInt Number of the target table which is processed.
4306   * @param vecColumnValues One row of values from the source table.
4307   * @param vecColumnNames Vector of column names in a target table.
4308   * @param vecColumnMode Modes of columns in the target table.
4309   * @param vecColumnTypes Types of columns in the target table.
4310   * @param c Connection to the target database.
4311   * @throws SQLException Constructs an SQLException object with a reason.
4312       * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
4313   * @throws Exception Constructs an Exception with the specified detail message.
4314   */

4315  private void insertTargetTable(int iTableInt, Vector JavaDoc vecColumnValues,
4316      Vector JavaDoc vecColumnNames,
4317      Vector JavaDoc vecColumnMode, Vector JavaDoc vecColumnTypes,
4318      Connection JavaDoc c, Vector JavaDoc vecTransformationValue, Vector JavaDoc transTargetColumnTypes) throws SQLException JavaDoc,
4319      NullPointerException JavaDoc, Exception JavaDoc {
4320
4321    this.logger.write("full", "\tinsertTargetTable method is started.");
4322    boolean bInsertTable = false;
4323    int iVersionValue = 0;
4324    int iVersionMax = 0;
4325    boolean bWriteData = false;
4326    String JavaDoc strQueryWhere = "";
4327    String JavaDoc strQuery = new String JavaDoc("select ");
4328    //for handling exception in FK (data cleanining)
4329
String JavaDoc exceptionInRelations = "";
4330    String JavaDoc replacementValueInRel = "";
4331    String JavaDoc replacementTable = "";
4332    String JavaDoc replacementColumn = "";
4333// String replacementColumnType = "";
4334
boolean relationIsOk = false;
4335    boolean updateQueryIsOk = false;
4336    boolean updateConstantIsOk = false;
4337    String JavaDoc strQueryConstantApendix = "";
4338
4339    boolean bOidLogicCurrentTable = new Boolean JavaDoc(this.vecTableOidLogic.get(
4340                                    iTableInt).toString()).booleanValue();
4341    boolean isTOS = ! (importDefinitionElement.strObjectIDNameColumnName.equals(
4342                    "") || importDefinitionElement.strObjectIDNameColumnValue.equals(""));
4343    boolean oid = false;
4344    if (bOidLogicCurrentTable && !isTOS)
4345      oid = true;
4346
4347    Vector JavaDoc vecTempKeyColumns = (Vector JavaDoc)this.vecTargetKeyColumnName.get(iTableInt);
4348
4349    String JavaDoc key = String.valueOf(iTableInt);
4350    String JavaDoc query = (String JavaDoc)queryStatement.get(key);
4351    //System.out.println("query="+query);
4352
String JavaDoc update = (String JavaDoc)updateStatement.get(key);
4353    String JavaDoc updateConstant = (String JavaDoc)updateConstantStatement.get(key);
4354
4355    String JavaDoc updateTransformation = (String JavaDoc)updateTransformationStatement.get(key);
4356     
4357    //updateTransformation = (String)this.updateTransformationStatement.get(key);
4358
Statement JavaDoc stmtTarget = null;
4359// ZK added this. If (select something from ... )is valid (contains oid, version and more) then do insert
4360
// String query1 = (String)queryStatement.get(key);
4361
// System.out.println("query="+query);
4362
// boolean isValidStmt = validStmt.checkStatement(query);
4363
// System.out.println("isValidStmt="+isValidStmt);
4364
String JavaDoc logStatement = "";
4365    try {
4366// if (isValidStmt){
4367
if (query.indexOf(" where ") == -1) {
4368        this.insertRow(c, vecColumnValues, vecColumnTypes, vecColumnNames,
4369            vecColumnMode, bOidLogicCurrentTable, iTableInt, vecTransformationValue, transTargetColumnTypes);
4370        bInsertTable = true;
4371      } else {
4372        Vector JavaDoc dv = (Vector JavaDoc)indexDValue.get(key);
4373        Vector JavaDoc drv = (Vector JavaDoc)indexDRelationValue.get(key);
4374        Vector JavaDoc dcv = (Vector JavaDoc)indexConstantDValue.get(key);
4375        Vector JavaDoc dvv = (Vector JavaDoc)indexDVariableValue.get(key);
4376        Vector JavaDoc dtv = (Vector JavaDoc)indexDTransformationValue.get(key);
4377        
4378        if (dv.size() > 0) {
4379          for (int i = 0; i < dv.size(); i++) {
4380            int index = Integer.parseInt(dv.get(i).toString());
4381            if (vecColumnValues.get(index) == null) {
4382              int str = query.indexOf("'dummyValue'");
4383              int num = query.indexOf("dummyValue");
4384              if (str != -1 && (num == -1 || str < num))
4385                query = replaceFirst(query, "= 'dummyValue'", " is null ");
4386              else
4387                query = replaceFirst(query, "= dummyValue", " is null ");
4388            } else {
4389              query = replaceFirst(query, "dummyValue",
4390                      vecColumnValues.get(index).toString());
4391            }
4392          }
4393        }
4394        if (drv.size() > 0) {
4395          for (int i = 0; i < drv.size(); i++) {
4396            int index = Integer.parseInt(drv.get(i).toString());
4397            if (this.vecRelationSourceValue.get(index) == null) {
4398              int str = query.indexOf("'dummyRelationValue'");
4399              int num = query.indexOf("dummyRelationValue");
4400              if (str != -1 && (num == -1 || str < num))
4401                query = replaceFirst(query, "= 'dummyRelationValue'",
4402                        " is null ");
4403              else
4404                query = replaceFirst(query, "= dummyRelationValue", " is null ");
4405            } else {
4406              query = replaceFirst(query, "dummyRelationValue",
4407                      this.vecRelationSourceValue.get(index).
4408                      toString());
4409            }
4410          }
4411        }
4412
4413        Vector JavaDoc vecTempConstantColumns = (Vector JavaDoc)this.vecConstantTargetColumnName.get(iTableInt);
4414        Vector JavaDoc vecTempConstantValues = (Vector JavaDoc)this.vecConstantConstantValue.get(iTableInt);
4415        Vector JavaDoc vecTempConstantMode = (Vector JavaDoc)this.vecConstantValueMode.get(iTableInt);
4416        Vector JavaDoc vecTempConstantType = (Vector JavaDoc)this.vecConstantColumnType.get(iTableInt);
4417//ZK added 19.4.2004
4418

4419// Vector vecTempTransformationValues = (Vector) vecTransformationValue.get(iTableInt);
4420

4421        if (dcv.size() > 0) {
4422          for (int i = 0; i < dcv.size(); i++) {
4423            int index = Integer.parseInt(dcv.get(i).toString());
4424            if (vecTempConstantValues.get(index) == null) {
4425              int str = query.indexOf("'dummyConstantValue'");
4426              int num = query.indexOf("dummyConstantValue");
4427              if (str != -1 && (num == -1 || str < num))
4428                query = replaceFirst(query, "= 'dummyConstantValue'",
4429                        " is null ");
4430              else
4431                query = replaceFirst(query, "= dummyConstantValue", " is null ");
4432            } else {
4433              query = replaceFirst(query, "dummyConstantValue",
4434                      vecTempConstantValues.get(index).toString());
4435            }
4436          }
4437        }
4438
4439        if (dvv.size() > 0) {
4440          for (int i = 0; i < dvv.size(); i++) {
4441            int index = Integer.parseInt(dvv.get(i).toString());
4442            if (vecVariableValue.get(index) == null) {
4443              int str = query.indexOf("'dummyVariableValue'");
4444              int num = query.indexOf("dummyVariableValue");
4445              if (str != -1 && (num == -1 || str < num))
4446                query = replaceFirst(query, "= 'dummyVariableValue'",
4447                        " is null ");
4448              else
4449                query = replaceFirst(query, "= dummyVariableValue", " is null ");
4450            } else {
4451              query = replaceFirst(query, "dummyVariableValue",
4452                      vecVariableValue.get(index).toString());
4453            }
4454          }
4455        }
4456//ZK added this for transformation. Key colona.
4457
if (dtv.size() > 0) {
4458          for (int i = 0; i < dtv.size(); i++) {
4459            int index = Integer.parseInt(dtv.get(i).toString());
4460            if (vecTransformationValue.get(index) == null) {
4461              int str = query.indexOf("'dummyTransformationValue'");
4462              int num = query.indexOf("dummyTransformationValue");
4463              if (str != -1 && (num == -1 || str < num))
4464                query = replaceFirst(query, "= 'dummyTransformationValue'",
4465                        " is null ");
4466              else
4467                query = replaceFirst(query, "= dummyTransformationValue", " is null ");
4468            } else {
4469              query = replaceFirst(query, "dummyTransformationValue",
4470                      vecTransformationValue.get(index).toString());
4471            }
4472          }
4473        }
4474//ZK end
4475
if (query.indexOf("where") != -1)
4476          strQueryWhere = query.substring(query.indexOf("where") + 5);
4477
4478        stmtTarget = c.createStatement();
4479        boolean rowExist;
4480        if (bOidLogicCurrentTable && !isTOS)
4481          rowExist = this.checkRowCache.getCheckRowValue(query, c, this.iTargetFirstColumnResult,
4482                     this.currentVersionColumnName);
4483        else
4484          rowExist = this.checkRowCache.getCheckRowValue(query, c, 100,
4485                     this.currentVersionColumnName);
4486
4487        if (!rowExist) {
4488          this.insertRow(c, vecColumnValues, vecColumnTypes, vecColumnNames,
4489              vecColumnMode, bOidLogicCurrentTable, iTableInt, vecTransformationValue, transTargetColumnTypes);
4490          bInsertTable = true;
4491        } else { //row exist = true
4492
if (bOidLogicCurrentTable && !isTOS) {
4493            iVersionValue = this.checkRowCache.getCheckRowVersionValue();
4494            if (iVersionValue > iVersionMax)
4495              iVersionMax = iVersionValue;
4496          }
4497          if (!bInsertTable) {
4498            Vector JavaDoc dOverwrite = (Vector JavaDoc)indexDOverwrite.get(key);
4499            Vector JavaDoc dSetNull = (Vector JavaDoc)indexDSetNull.get(key);
4500
4501            if ( ( (update + strQueryWhere).indexOf("update") != -1 ||
4502                (update + strQueryWhere).indexOf("UPDATE") != -1)) {
4503              if (dOverwrite.size() > 0) {
4504                int start = 0;
4505                for (int i = 0; i < dOverwrite.size(); i++) {
4506                  Vector JavaDoc replacedValue = (Vector JavaDoc)vecDefaultValue.get(iTableInt);
4507                  int index = Integer.parseInt(dOverwrite.get(i).toString());
4508                  if (vecColumnValues.get(index) == null) {
4509                    int str = update.indexOf("'dummyOverwrite'");
4510                    int num = update.indexOf("dummyOverwrite");
4511                    if (replacedValue.get(index) != "") {
4512                      if (str != -1 && (num == -1 || str < num))
4513                        update = replaceFirst(update, "'dummyOverwrite'", " '" +
4514                                 replacedValue.get(index).toString() + "' ");
4515                      else
4516                        update = replaceFirst(update, "dummyOverwrite", " " +
4517                                 replacedValue.get(index).toString() + " ");
4518
4519                      dataCleaning.cleaningColumnValues(this.vecTableTableName.
4520                          get(iTableInt).toString(),
4521                          vecColumnNames.get(index).toString(),
4522                          replacedValue.get(index).toString(),
4523                          currentRow, c, "UPDATE",
4524                          importDefinitionElement.strImportDefinitionName);
4525                    } else {
4526                      if (str != -1 && (num == -1 || str < num)) {
4527                        String JavaDoc forReplace = "'dummyOverwrite'";
4528                        if(update.indexOf("N'dummyOverwrite'") != -1)
4529                            forReplace = "N'dummyOverwrite'";
4530                        update = replaceFirst(update, forReplace, " null ");
4531                      }
4532                      else {
4533                        update = replaceFirst(update, "dummyOverwrite", " null ");
4534                      }
4535                    }
4536                  } else {
4537                    String JavaDoc replacement = vecColumnValues.get(index).toString();
4538                    start = update.indexOf("dummyOverwrite", start);
4539                    update = update.substring(0, start) + replacement + update.substring(start + 14);
4540                    start = replacement.length();
4541                  }
4542                }
4543              }
4544              if (dSetNull.size() > 0) {
4545                for (int j = 0; j < dSetNull.size(); j++) {
4546                  int index = Integer.parseInt(dSetNull.get(j).toString());
4547                  if (vecColumnValues.get(index) == null) {
4548                    update = replaceFirst(update, "dummySetNull",
4549                             vecColumnNames.get(index).toString() + "=" + " null ");
4550                  } else {
4551                    update = replaceFirst(update, "dummySetNull,", "");
4552                  }
4553                }
4554              }
4555              if (dOverwrite.size() > 0 || dSetNull.size() > 0) {
4556                if (bWriteData)
4557                  update = replaceFirst(update, "dummyVersionOverwrite",
4558                           String.valueOf(iVersionMax));
4559                else
4560                  update = replaceFirst(update, "dummyVersionOverwrite",
4561                           String.valueOf(iVersionMax + 1));
4562                if (bReplaceInData) {
4563                  update = this.replaceInData(update);
4564                  strQueryWhere = this.replaceInData(strQueryWhere);
4565                }
4566                relationIsOk = true;
4567                updateConstantIsOk = true;
4568                updateQueryIsOk = false;
4569                int iNumRowUp = 0;
4570// int ver = update.indexOf("version");
4571
int ver = update.indexOf(this.currentVersionColumnName);
4572                int equals = update.indexOf("=");
4573                try {
4574                  if (equals != ver + 8) { // update set version=1 where x=x
4575
this.logger.write("full",
4576                        "\tQuery '" + update + strQueryWhere +
4577                        "' will be executed");
4578                        logStatement = update + strQueryWhere;
4579                    iNumRowUp = stmtTarget.executeUpdate(update + strQueryWhere);
4580                  }
4581                  if (iNumRowUp != 0) {
4582                    if (!bWriteData)
4583                      iVersionMax = iVersionMax + 1;
4584                    bWriteData = true;
4585                  }
4586                  String JavaDoc tableName = this.vecTableTableName.get(iTableInt).
4587                                     toString();
4588                  for (int i = 0; i < this.vecBlobVector.size(); i = i + 5) {
4589                    if (!this.vecBlobVector.get(i + 3).toString().
4590                        equalsIgnoreCase("update")) {
4591                      String JavaDoc version = "";
4592                      if (oid) {
4593                        if (bWriteData) {
4594// version += ", version = " + iVersionMax;
4595
version += ", " + this.currentVersionColumnName + " = " + iVersionMax;
4596                        } else {
4597// version += ", version = " + (iVersionMax + 1);
4598
version += ", " + this.currentVersionColumnName + "= " + (iVersionMax + 1);
4599                        }
4600                      }
4601                      String JavaDoc columnName = this.vecBlobVector.get(i).toString();
4602                      byte[] isBlob = (byte[])this.vecBlobVector.get(i + 1);
4603                      if (isBlob != null) {
4604                        ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(
4605                                                    isBlob);
4606                        logStatement = "update " +
4607                                                                                tableName + " set " + columnName + "=(?)"
4608                                                                                + version + " where " + columnName + " is null";
4609                        PreparedStatement JavaDoc pstmt = c.prepareStatement("update " +
4610                                                  tableName + " set " + columnName + "=(?)"
4611                                                  + version + " where " + columnName + " is null");
4612                        pstmt.setBytes(1, isBlob);
4613                        int intRowStmt = pstmt.executeUpdate();
4614                        pstmt.close();
4615                        if (intRowStmt != 0) {
4616                          if (!bWriteData)
4617                            iVersionMax = iVersionMax + 1;
4618                          bWriteData = true;
4619                        }
4620                      }
4621                    }
4622                  }
4623                }
4624                catch (SQLException JavaDoc ex) {
4625                  stmtTarget.close();
4626                  stmtTarget = c.createStatement();
4627                 
4628                  if ( (importDefinitionElement.strDefaultCutOffData.
4629                      equalsIgnoreCase("true"))) {
4630                    dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName.
4631                        get(iTableInt).toString(), c,
4632                        strQueryWhere, currentRow, update,
4633                        importDefinitionElement.strOnErrorContinueXml,
4634                        importDefinitionElement.strImportDefinitionName, update + strQueryWhere);
4635                  } else
4636                
4637                    throw ex;
4638                }
4639              }
4640              for (int j = 0; j < vecColumnNames.size(); j++) {
4641                if (vecColumnMode.get(j).toString().equalsIgnoreCase("Update")) {
4642// String javaType = configReaderTarget.getJavaTypeMapings()
4643
// .get(vecColumnTypes.get(j).toString().toUpperCase()).toString();
4644
//ZK change this 7.5.2004 from CheckType to configReaderSource
4645
if (configReaderTarget.isBinaryObject(vecColumnTypes.get(j).toString())) {
4646// int javaTypeInt=Integer.parseInt(javaType);
4647
// if (javaTypeInt==1) {
4648
for (int i = 0; i < vecBlobVector.size(); i = i + 5) {
4649                      if (vecBlobVector.get(i + 3).toString().equalsIgnoreCase(
4650                          "update")) {
4651                        if (vecBlobVector.get(i).toString().equalsIgnoreCase(
4652                            vecColumnNames.get(j).toString())) {
4653                          String JavaDoc version = "";
4654                          if (oid) {
4655                            if (bWriteData) {
4656// version += ", version = " + (iVersionMax);
4657
version += ", " + this.currentVersionColumnName + " = "
4658                                  + (iVersionMax);
4659                            } else {
4660// version += ", version = " + (iVersionMax + 1);
4661
version += ", " + this.currentVersionColumnName + " = "
4662                                  + (iVersionMax + 1);
4663                            }
4664                          }
4665                          String JavaDoc tableName = this.vecTableTableName.get(
4666                                             iTableInt).
4667                                             toString();
4668                          String JavaDoc columnName = this.vecBlobVector.get(i).
4669                                              toString();
4670                          byte[] isBlob = (byte[])this.vecBlobVector.get(i + 1);
4671                          String JavaDoc condition = this.vecBlobVector.get(i + 2).
4672                                             toString();
4673                          if (isBlob != null) {
4674                            ByteArrayInputStream JavaDoc bais = new
4675                                                        ByteArrayInputStream JavaDoc(
4676                                                        isBlob);
4677                            PreparedStatement JavaDoc pstmt = c.prepareStatement(
4678                                                      "update " + tableName + " set "
4679                                                      + columnName +
4680                                                      "=(?)"
4681                                                      + version + condition + strQueryWhere);
4682                            pstmt.setBytes(1, isBlob);
4683                            this.logger.write("full",
4684                                "\tQuery '" + "update " +
4685                                tableName +
4686                                " set "
4687                                + columnName + "=BlobObject" +
4688                                version + condition +
4689                                " where " +
4690                                strQueryWhere +
4691                                "' will be executed");
4692                            int intRowStmt = 0;
4693                            logStatement = "update " +
4694                                                                                        tableName +
4695                                                                                        " set "
4696                                                                                        + columnName + "=BlobObject" +
4697                                                                                        version + condition +
4698                                                                                        " where " +
4699                                                                                        strQueryWhere;
4700                            intRowStmt = pstmt.executeUpdate();
4701                            pstmt.close();
4702                            if (intRowStmt != 0) {
4703                              if (!bWriteData)
4704                                iVersionMax = iVersionMax + 1;
4705                              bWriteData = true;
4706                            }
4707                          }
4708                        }
4709                      }
4710                    } //for petlja za blob
4711
} else {
4712                    String JavaDoc strQueryUpdate = "update " +
4713                                            this.vecTableTableName.get(iTableInt).toString()
4714                                            + " set ";
4715                    strQueryUpdate += vecColumnNames.get(j).toString()
4716                        + "=";
4717                    if (vecColumnValues.get(j) == null)
4718                      strQueryUpdate += " null ";
4719                    else {
4720//ZK change this from CheckType to configReaderTarget this 7.5.2004
4721
if (!configReaderTarget.isNumber(vecColumnTypes.get(j).toString()))
4722                        strQueryUpdate += "'" + vecColumnValues.get(j).toString()
4723                            + "' ";
4724                      else
4725                        strQueryUpdate += vecColumnValues.get(j).toString() + " ";
4726                    }
4727                    if (oid) {
4728                      if (bWriteData) {
4729// strQueryUpdate += ", version = " + (iVersionMax) + " where ";
4730
strQueryUpdate += ", " + this.currentVersionColumnName + " = "
4731                            + (iVersionMax) + " where ";
4732                      } else {
4733// strQueryUpdate += ", version = " + (iVersionMax + 1) + " where ";
4734
strQueryUpdate += ", " + this.currentVersionColumnName + " = "
4735                            + (iVersionMax + 1) + " where ";
4736                      }
4737                    } else
4738                      strQueryUpdate += " where ";
4739                    strQueryUpdate += vecColumnNames.get(j).toString()
4740                        + " is null and ";
4741                    if (bReplaceInData) {
4742                      strQueryUpdate = this.replaceInData(strQueryUpdate);
4743                      strQueryWhere = this.replaceInData(strQueryWhere);
4744                    }
4745                    this.logger.write("full", "\tQuery '" +
4746                        strQueryUpdate + strQueryWhere +
4747                        "' will be executed");
4748                    int iNumRow = 0;
4749                    try {
4750                      iNumRow = stmtTarget.executeUpdate(strQueryUpdate + strQueryWhere);
4751                    }
4752                    catch (SQLException JavaDoc ex) {
4753                      stmtTarget.close();
4754                      stmtTarget = c.createStatement();
4755                      if ( (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("true"))) {
4756                        dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName.get(iTableInt).
4757                            toString(), c, strQueryWhere, currentRow, update,
4758                            importDefinitionElement.strOnErrorContinueXml,
4759                            importDefinitionElement.strImportDefinitionName,strQueryUpdate + strQueryWhere);
4760                      } else
4761                        throw ex;
4762                    }
4763                    if (iNumRow != 0) {
4764                      if (!bWriteData)
4765                        iVersionMax = iVersionMax + 1;
4766                      bWriteData = true;
4767                    }
4768                  }
4769                } //end of main if loop
4770
}
4771            }
4772            for (int i = 0; i < this.iRelationColumns; i++) {
4773              outLoop:if (this.vecRelationColumnSourceTableName.get(i).toString().
4774                  equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4775                  &&
4776                  this.vecRelationColumnSourceTableID.get(i).toString().
4777                  equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4778                for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) {
4779                  if (this.vecRelationColumnSourceTableName.get(i).toString().
4780                      equalsIgnoreCase(this.vecVariableUseIDTableName.get(m).toString())
4781                      &&
4782                      this.vecRelationColumnSourceTableID.get(i).toString().
4783                      equalsIgnoreCase(this.vecVariableUseIDTableID.get(m).toString())) {
4784                    String JavaDoc strQueryRelations = "select " +
4785                                               this.vecRelationColumnSourceColumnName.get(i).
4786                                               toString() + " from " +
4787                                               this.vecRelationColumnSourceTableName.get(i).
4788                                               toString() + " where ";
4789                    strQueryRelations += vecTempKeyColumns.get(0).toString() + " = ";
4790//ZK change this from CheckType to configReaderTarget this 7.5.2004
4791
if (!configReaderTarget.isNumber(vecColumnTypes.get(0).toString()))
4792                      strQueryRelations += "'" + this.strUserID + "'";
4793                    else
4794                      strQueryRelations += this.strUserID;
4795
4796                    if (this.vecTableTableMode.get(iTableInt).toString().equalsIgnoreCase("cache")) {
4797                      Object JavaDoc obj = relationsCache.getRelationsCacheValue(strQueryRelations);
4798                      if (obj != null) {
4799                        if (!obj.toString().equalsIgnoreCase("#$Together#$")) {
4800                          this.vecRelationSourceValue.setElementAt(obj, i);
4801                          String JavaDoc type = relationsCache.getRelationsCachType(strQueryRelations);
4802                          this.vecRelationSourceType.setElementAt(type, i);
4803                        }
4804                      } else {
4805                        Statement JavaDoc stmtForUserID1 = c.createStatement();
4806                        ResultSet JavaDoc rsForUserID1 = null;
4807                        try {
4808                          this.logger.write("full",
4809                              "\tQuery '" + strQueryRelations + "' will be executed");
4810                          rsForUserID1 = stmtForUserID1.executeQuery(strQueryRelations);
4811                        }
4812                        catch (SQLException JavaDoc ex) {
4813                          rsForUserID1.close();
4814                          stmtForUserID1.close();
4815                          dataCleaning.cutingDataLenghtUpdate(this.
4816                              vecTableTableName.
4817                              get(iTableInt).toString(), c,
4818                              strQueryWhere, currentRow, update,
4819                              importDefinitionElement.strOnErrorContinueXml,
4820                              importDefinitionElement.strImportDefinitionName, strQueryRelations);
4821                        }
4822                        if (rsForUserID1.next()) {
4823                          if (this.iTargetFirstColumnResult == 1) {
4824                            this.vecRelationSourceValue.setElementAt(rsForUserID1.getObject(1), i);
4825                            this.vecRelationSourceType.setElementAt(rsForUserID1.getMetaData().
4826                                getColumnTypeName(1), i);
4827                            relationsCache.setRelationsCacheValue(strQueryRelations,
4828                                rsForUserID1.getObject(1));
4829                            relationsCache.setRelationsCacheType(strQueryRelations,
4830                                rsForUserID1.getMetaData().getColumnTypeName(1));
4831                          }
4832                        } else {
4833                          relationsCache.setRelationsCacheValue(strQueryRelations, "#$Together#$");
4834                          relationsCache.setRelationsCacheType(strQueryRelations, "#$Together#$");
4835                        }
4836                        rsForUserID1.close();
4837                        stmtForUserID1.close();
4838                        break outLoop;
4839                      }
4840                    } else { //tableMode=Query
4841
this.logger.write("full",
4842                          "\tQuery '" + strQueryRelations + "' will be executed");
4843                      Statement JavaDoc stmtForUserID2 = c.createStatement();
4844                      ResultSet JavaDoc rsForUserID2 = null;
4845                      try {
4846                        rsForUserID2 = stmtForUserID2.executeQuery(strQueryRelations);
4847                      }
4848                      catch (SQLException JavaDoc ex) {
4849                        rsForUserID2.close();
4850                        stmtForUserID2.close();
4851                        dataCleaning.cutingDataLenghtUpdate(this.
4852                            vecTableTableName.
4853                            get(iTableInt).toString(), c,
4854                            strQueryWhere, currentRow, update,
4855                            importDefinitionElement.strOnErrorContinueXml,
4856                            importDefinitionElement.strImportDefinitionName, strQueryRelations);
4857
4858                      }
4859                      if (rsForUserID2.next()) {
4860                        if (this.iTargetFirstColumnResult == 1) {
4861                          this.vecRelationSourceValue.setElementAt(rsForUserID2.getObject(1), i);
4862                          this.vecRelationSourceType.setElementAt(rsForUserID2.getMetaData().
4863                              getColumnTypeName(1), i);
4864                                                          
4865                        } else {
4866                          this.vecRelationSourceValue.setElementAt(rsForUserID2.getObject(0), i);
4867                          this.vecRelationSourceType.setElementAt(rsForUserID2.getMetaData().
4868                              getColumnTypeName(0), i);
4869                        }
4870                      }
4871                      rsForUserID2.close();
4872                      stmtForUserID2.close();
4873                      break outLoop;
4874                    }
4875                  }
4876                } //end of vecVariableUseIDTableName loop
4877
String JavaDoc strQueryRelations = "select " +
4878                                           this.vecRelationColumnSourceColumnName.get(i).toString()
4879                                           + " from " +
4880                                           this.vecRelationColumnSourceTableName.get(i).toString()
4881                                           + " where " + strQueryWhere;
4882                if (this.vecTableTableMode.get(iTableInt).toString().equalsIgnoreCase("cache")) {
4883                  Object JavaDoc obj = relationsCache.getRelationsCacheValue(strQueryRelations);
4884                  if (obj != null) {
4885                    if (!obj.toString().equalsIgnoreCase("#$Together#$")) {
4886                      this.vecRelationSourceValue.setElementAt(obj, i);
4887                      String JavaDoc type = relationsCache.getRelationsCachType(
4888                                    strQueryRelations);
4889                      this.vecRelationSourceType.setElementAt(type, i);
4890                    }
4891                  } else {
4892                    Statement JavaDoc stmtForRel1 = c.createStatement();
4893                    ResultSet JavaDoc rsForRel1 = null;
4894                    try {
4895                      this.logger.write("full", "\tQuery '" + strQueryRelations +
4896                          "' will be executed");
4897                      rsForRel1 = stmtForRel1.executeQuery(strQueryRelations);
4898                    }
4899                    catch (SQLException JavaDoc ex) {
4900                      rsForRel1.close();
4901                      stmtForRel1.close();
4902                      dataCleaning.cutingDataLenghtUpdate(this.
4903                          vecTableTableName.
4904                          get(iTableInt).toString(), c,
4905                          strQueryWhere, currentRow, update,
4906                          importDefinitionElement.strOnErrorContinueXml,
4907                          importDefinitionElement.strImportDefinitionName, strQueryRelations);
4908                    }
4909
4910                    if (rsForRel1.next()) {
4911                      if (this.iTargetFirstColumnResult == 1) {
4912                        this.vecRelationSourceValue.setElementAt(rsForRel1.getObject(1), i);
4913                        this.vecRelationSourceType.setElementAt(rsForRel1.getMetaData().
4914                            getColumnTypeName(1), i);
4915                        relationsCache.setRelationsCacheValue(strQueryRelations,
4916                            rsForRel1.getObject(1));
4917                        relationsCache.setRelationsCacheType(strQueryRelations,
4918                            rsForRel1.getMetaData().getColumnTypeName(1));
4919                      } else {
4920                        this.vecRelationSourceValue.setElementAt(rsForRel1.getObject(0), i);
4921                        this.vecRelationSourceType.setElementAt(rsForRel1.getMetaData().
4922                            getColumnTypeName(0), i);
4923                        relationsCache.setRelationsCacheValue(strQueryRelations,
4924                            rsForRel1.getObject(0));
4925                        relationsCache.setRelationsCacheType(strQueryRelations,
4926                            rsForRel1.getMetaData().getColumnTypeName(0));
4927                      }
4928                    } else {
4929                      relationsCache.setRelationsCacheValue(strQueryRelations, "#$Together#$");
4930                      relationsCache.setRelationsCacheType(strQueryRelations, "#$Together#$");
4931                    }
4932                    rsForRel1.close();
4933                    stmtForRel1.close();
4934                  }
4935                } else { //tableMode=Query
4936

4937                  Statement JavaDoc stmtForRel2 = c.createStatement();
4938                  ResultSet JavaDoc rsForRel2 = null;
4939                  try {
4940                    this.logger.write("full",
4941                        "\tQuery '" + strQueryRelations + "' will be executed");
4942                    rsForRel2 = stmtForRel2.executeQuery(strQueryRelations);
4943                  }
4944                  catch (SQLException JavaDoc ex) {
4945                    rsForRel2.close();
4946                    stmtForRel2.close();
4947                    dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName.
4948                        get(iTableInt).toString(), c,
4949                        strQueryWhere, currentRow, update,
4950                        importDefinitionElement.strOnErrorContinueXml,
4951                        importDefinitionElement.strImportDefinitionName, strQueryRelations);
4952                  }
4953                  if (rsForRel2.next()) {
4954                    if (this.iTargetFirstColumnResult == 1) {
4955                      this.vecRelationSourceValue.setElementAt(rsForRel2.getObject(1), i);
4956                      this.vecRelationSourceType.setElementAt(rsForRel2.getMetaData().
4957                          getColumnTypeName(1), i);
4958                    } else {
4959                      this.vecRelationSourceValue.setElementAt(rsForRel2.getObject(0), i);
4960                      this.vecRelationSourceType.setElementAt(rsForRel2.getMetaData().
4961                          getColumnTypeName(0), i);
4962                    }
4963                  }
4964                  rsForRel2.close();
4965                  stmtForRel2.close();
4966                }
4967              }
4968            }
4969
4970            for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) {
4971              if (this.vecRelationColumnTargetTableName.get(i).toString().
4972                  equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4973                  &&
4974                  this.vecRelationColumnTargetTableID.get(i).toString().
4975                  equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4976                int currentVersion = 0;
4977                if (bWriteData)
4978                  currentVersion = iVersionMax;
4979                else
4980                  currentVersion = iVersionMax + 1;
4981
4982                if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("SetNull")) {
4983                  if (this.vecRelationSourceValue.get(i) == null) {
4984                    String JavaDoc strUpdateRelations = this.queryRelations(iTableInt,
4985                                                i, strQueryWhere, c, currentVersion, oid);
4986                    this.logger.write("full", "\tQuery '" + strUpdateRelations +
4987                        "' will be executed");
4988                    if (bReplaceInData) {
4989                      strUpdateRelations = this.replaceInData(
4990                                           strUpdateRelations);
4991                    }
4992                    int iNumRow = 0;
4993                    logStatement = strUpdateRelations;
4994                    iNumRow = stmtTarget.executeUpdate(strUpdateRelations);
4995                    this.vecRelationSourceValue.setElementAt(null, i);
4996// this.vecRelationSourceType.setElementAt(null,i);
4997
if (iNumRow != 0) {
4998                      if (!bWriteData)
4999                        iVersionMax = iVersionMax + 1;
5000                      bWriteData = true;
5001                    }
5002                  }
5003                } else if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase(
5004                    "Overwrite") ||
5005                    (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("Update"))) {
5006
5007                  //for handling exception in FK
5008
replacementValueInRel = vecDefaultRelationValue.get(i).toString();
5009                  replacementTable = vecRelationColumnTargetTableName.get(i).toString();
5010                  replacementColumn = vecRelationColumnTargetColumnName.get(i).toString();
5011// replacementColumnType = this.vecRelationSourceType.get(i).toString();
5012
String JavaDoc strUpdateRelations = this.queryRelations(iTableInt, i,
5013                                              strQueryWhere, c, currentVersion, oid);
5014                  this.logger.write("full", "\tQuery '" + strUpdateRelations +
5015                      "' will be executed");
5016                  if (bReplaceInData) {
5017                    strUpdateRelations = this.replaceInData(strUpdateRelations);
5018                  }
5019                  //only for catch exceptions in foreign keys statement
5020
exceptionInRelations = strUpdateRelations;
5021                  updateQueryIsOk = true;
5022                  updateConstantIsOk = true;
5023                  relationIsOk = false;
5024                  int iNumRow = 0;
5025                  try {
5026                    logStatement = strUpdateRelations;
5027                    iNumRow = stmtTarget.executeUpdate(strUpdateRelations);
5028                    this.vecRelationSourceValue.setElementAt(null, i);
5029// this.vecRelationSourceType.setElementAt(null,i);
5030
}
5031                  catch (SQLException JavaDoc ex) {
5032                    stmtTarget.close();
5033                    
5034                    stmtTarget = c.createStatement();
5035                    if ( (importDefinitionElement.strDefaultCutOffData.
5036                        equalsIgnoreCase("true"))) {
5037                      dataCleaning.cutingDataLenghtUpdate(this.
5038                          vecTableTableName.get(iTableInt).toString(), c,
5039                          strQueryWhere, currentRow, update,
5040                          importDefinitionElement.strOnErrorContinueXml,
5041                          importDefinitionElement.strImportDefinitionName, strUpdateRelations);
5042                    } else
5043                      throw ex;
5044                  }
5045                  if (iNumRow != 0) {
5046                    if (!bWriteData)
5047                      iVersionMax = iVersionMax + 1;
5048                    bWriteData = true;
5049                  }
5050                }
5051              }
5052            }
5053
5054            if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
5055              if ( ( (update + strQueryWhere).indexOf("update") != -1 ||
5056                  (update + strQueryWhere).indexOf("UPDATE") != -1)) {
5057                if (vecTempConstantColumns.size() > 0) {
5058                  if (updateConstant.indexOf(",") != -1)
5059                    updateConstant = updateConstant.substring(0,updateConstant.lastIndexOf(","));
5060
5061                  Vector JavaDoc cOverwrite = (Vector JavaDoc)indexDConstantOver.get(key);
5062                  Vector JavaDoc cNull = (Vector JavaDoc)indexDConstantNull.get(key);
5063                  strQueryConstantApendix = "";
5064                  if (cOverwrite.size() > 0) {
5065                    int startOver = 0;
5066                    for (int i = 0; i < cOverwrite.size(); i++) {
5067                      int index = Integer.parseInt(cOverwrite.get(i).toString());
5068                      if (vecTempConstantValues.get(index) == null) {
5069                        int str = updateConstant.indexOf("'dummyConstantOver'");
5070                        int num = updateConstant.indexOf("dummyConstantOver");
5071                        if (str != -1 && (num == -1 || str < num))
5072                          updateConstant = replaceFirst(updateConstant,
5073                                           "'dummyConstantOver'", " null ");
5074                        else
5075                          updateConstant = replaceFirst(updateConstant,
5076                                           "dummyConstantOver", " null ");
5077                      } else {
5078                        String JavaDoc replacement = vecTempConstantValues.get(index).
5079                                             toString();
5080                        startOver = updateConstant.indexOf("dummyConstantOver",
5081                                    startOver);
5082                        updateConstant = updateConstant.substring(0, startOver) +
5083                                         replacement +
5084                                         updateConstant.substring(startOver + 17);
5085                        startOver = replacement.length();
5086                      }
5087                    }
5088                  }
5089                  if (cNull.size() > 0) {
5090                    int startNull = 0;
5091                    for (int i = 0; i < cNull.size(); i++) {
5092                      int index = Integer.parseInt(cNull.get(i).toString());
5093                      if (vecTempConstantValues.get(index) == null) {
5094                        int str = updateConstant.indexOf("'dummyConstantNull'");
5095                        int num = updateConstant.indexOf("dummyConstantNull");
5096                        if (str != -1 && (num == -1 || str < num))
5097                          updateConstant = replaceFirst(updateConstant,
5098                                           "'dummyConstantNull'", " null ");
5099                        else
5100                          updateConstant = replaceFirst(updateConstant,
5101                                           "dummyConstantNull", " null ");
5102
5103                        strQueryConstantApendix += " and " +
5104                            vecTempConstantColumns.get(index).toString() +
5105                            " is null ";
5106                      } else {
5107                        String JavaDoc replacement = vecTempConstantValues.get(index).
5108                                             toString();
5109                        startNull = updateConstant.indexOf("dummyConstantNull",
5110                                    startNull);
5111                        updateConstant = updateConstant.substring(0, startNull) +
5112                                         replacement +
5113                                         updateConstant.substring(startNull + 17);
5114                        startNull = replacement.length();
5115                      }
5116                    }
5117                  }
5118
5119                  if (bReplaceInData) {
5120// System.out.println("bReplaceInData: " + bReplaceInData);
5121
updateConstant = this.replaceInData(updateConstant);
5122                    strQueryWhere = this.replaceInData(strQueryWhere);
5123                  }
5124
5125                  if (oid) {
5126                    if (bWriteData) {
5127// updateConstant += ", version = " + (iVersionMax);
5128
updateConstant += ", " + this.currentVersionColumnName + " = " + (iVersionMax);
5129                    } else {
5130// updateConstant += ", version = " + (iVersionMax + 1);
5131
updateConstant += ", " + this.currentVersionColumnName + " = " + (iVersionMax
5132                          + 1);
5133                    }
5134                  }
5135                  updateQueryIsOk = true;
5136                  relationIsOk = true;
5137                  updateConstantIsOk = false;
5138                  int iNumRow = 0;
5139                  try {
5140                    if (!updateConstant.endsWith(" set ")) {
5141                      this.logger.write("full", "\tQuery '" + updateConstant + " where " +
5142                          strQueryWhere + strQueryConstantApendix + "' will be executed");
5143                                                    logStatement = updateConstant + " where " + strQueryWhere;
5144                      iNumRow = stmtTarget.executeUpdate(updateConstant + " where " + strQueryWhere +
5145                                strQueryConstantApendix);
5146                    }
5147                  }
5148                  catch (SQLException JavaDoc ex) {
5149                    stmtTarget.close();
5150                
5151                    stmtTarget = c.createStatement();
5152                    if ( (importDefinitionElement.strDefaultCutOffData.
5153                        equalsIgnoreCase("true"))) {
5154                      dataCleaning.cutingDataLenghtUpdate(this.
5155                          vecTableTableName.get(iTableInt).toString(), c,
5156                          " where " + strQueryWhere + strQueryConstantApendix,
5157                          currentRow, updateConstant,
5158                          importDefinitionElement.strOnErrorContinueXml,
5159                          importDefinitionElement.strImportDefinitionName,
5160                          updateConstant + " where " +
5161                          strQueryWhere + strQueryConstantApendix);
5162                    } else
5163                      throw ex;
5164                  }
5165                  if (iNumRow != 0) {
5166                    if (!bWriteData)
5167                      iVersionMax = iVersionMax + 1;
5168                    bWriteData = true;
5169                  }
5170                }
5171                if (this.vecVariableTimesTableName.size() != 0) {
5172                  int currentVersion = 0;
5173                  boolean bool = false;
5174                  if (!bWriteData)
5175                    currentVersion = iVersionMax + 1;
5176                  else
5177                    currentVersion = iVersionMax;
5178                  bool = this.updateCurrentTime(c, iTableInt, strQueryWhere,
5179                         currentVersion, oid);
5180                  if (bool) {
5181                    if (!bWriteData)
5182                      iVersionMax = iVersionMax + 1;
5183                    bWriteData = true;
5184                  }
5185                }
5186                if (this.vecVariableColumnTargetTableName.size() != 0) {
5187                  int currentVersion = 0;
5188                  boolean bool = false;
5189                  if (!bWriteData)
5190                    currentVersion = iVersionMax + 1;
5191                  else
5192                    currentVersion = iVersionMax;
5193                  try {
5194                    bool = this.updateNameValue(c, iTableInt, strQueryWhere,
5195                           currentVersion, oid);
5196                  }
5197                  catch (SQLException JavaDoc ex) {
5198                    throw ex;
5199                  }
5200                  if (bool) {
5201                    if (!bWriteData)
5202                      iVersionMax = iVersionMax + 1;
5203                    bWriteData = true;
5204                  }
5205                }
5206              }
5207            } //insertTable=true
5208
//ZK added this 17.5.2004
5209
// System.out.println("iTableInt="+iTableInt);
5210
// System.out.println("update + strQueryWhere="+update + strQueryWhere);
5211

5212        if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
5213            if (((update + strQueryWhere).indexOf("update") != -1 ||
5214                 (update + strQueryWhere).indexOf("UPDATE") != -1)) {
5215
5216                //if(((Vector)transformationsColumnNames.get(iTableInt)).size() > 0){
5217

5218
5219//System.out.println("updateTransformation = "+updateTransformation);
5220
//System.out.println("transformedValues="+transformedValues);
5221

5222                            
5223                    Vector JavaDoc tOverwrite = (Vector JavaDoc)indexDTransformationOver.get(key);
5224                    Vector JavaDoc tNull = (Vector JavaDoc)indexDTransformationNull.get(key);
5225                    
5226                    if ((updateTransformation.indexOf(",") != -1))
5227                      updateTransformation = updateTransformation.substring(0,updateTransformation.lastIndexOf(","));
5228                    
5229                    if (tOverwrite.size() > 0) {
5230                        int startOver = 0;
5231                        for (int i = 0; i < tOverwrite.size(); i++) {
5232                        int index = Integer.parseInt(tOverwrite.get(i).toString());
5233                        if (vecTransformationValue.get(index) == null) {
5234                            
5235                            int str = updateTransformation.indexOf("'dummyTransformationOver'");
5236                            int num = updateTransformation.indexOf("dummyTransformationOver");
5237                            if (str != -1 && (num == -1 || str < num))
5238                                updateTransformation = replaceFirst(updateTransformation,
5239                                "'dummyTransformationOver'", " null ");
5240                            else
5241                            updateTransformation = replaceFirst(updateTransformation,
5242                                "dummyTransformationOver", " null ");
5243                        } else {
5244                            String JavaDoc replacement = vecTransformationValue.get(index).toString();
5245                            startOver = updateTransformation.indexOf("dummyTransformationOver",
5246                            startOver);
5247                            updateTransformation = updateTransformation.substring(0, startOver) +
5248                            replacement +
5249                            updateTransformation.substring(startOver + 23);
5250                            startOver = replacement.length();
5251                            
5252                        }
5253                                
5254                        }
5255                    }
5256                    
5257                    if (tNull.size() > 0) {
5258                        int startNull = 0;
5259                        for (int i = 0; i < tNull.size(); i++) {
5260                          int index = Integer.parseInt(tNull.get(i).toString());
5261                          String JavaDoc colName=((Vector JavaDoc)transformationsColumnNames.get(iTableInt)).get(index).toString();
5262                          if (vecTransformationValue.get(index) == null) {
5263                            updateTransformation = replaceFirst(updateTransformation,
5264                                               "dummyTransformationNull",
5265                                                colName+ " = null ");
5266                          } else {
5267                            updateTransformation = replaceFirst(updateTransformation,
5268                                               "dummyTransformationNull,", " ");
5269                          }
5270                        }
5271                    }
5272                    
5273
5274                if ((tOverwrite.size() > 0) || (tNull.size() > 0)){
5275                
5276                    
5277                    if (bReplaceInData) {
5278                        updateTransformation = this.replaceInData(updateTransformation);
5279                        strQueryWhere = this.replaceInData(strQueryWhere);
5280                      }
5281                      
5282                    if (oid) {
5283                        if (bWriteData) {
5284                            updateTransformation += ", " + this.currentVersionColumnName + " = " + (iVersionMax);
5285                        } else {
5286                            updateTransformation += ", " + this.currentVersionColumnName + " = " + (iVersionMax
5287                        + 1);
5288                        }
5289                        }
5290                        
5291                    int iNumRow = 0;
5292                    try {
5293                        if (!updateTransformation.endsWith(" set ")) {
5294                        this.logger.write("full", "\tQuery '" + updateTransformation + " where " +
5295                        strQueryWhere + "' will be executed");
5296                        logStatement = updateTransformation + " where " + strQueryWhere;
5297                        iNumRow = stmtTarget.executeUpdate(updateTransformation + " where " +
5298                        strQueryWhere);
5299                        }
5300                        }
5301                        catch (SQLException JavaDoc ex) {
5302                            stmtTarget.close();
5303                            throw ex;
5304                        }
5305                        
5306                        if (iNumRow != 0) {
5307                        if (!bWriteData)
5308                            iVersionMax = iVersionMax + 1;
5309                            bWriteData = true;
5310                        }
5311                        
5312                }
5313                        
5314                    
5315                    
5316                
5317                
5318                
5319                              
5320                              
5321                }//this is my
5322
}//END IF
5323
//ZK added 20.5 2004 for "Update" mode
5324
if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
5325          if (((update + strQueryWhere).indexOf("update") != -1 ||
5326               (update + strQueryWhere).indexOf("UPDATE") != -1)) {
5327
5328              //if(((Vector)transformationsColumnNames.get(iTableInt)).size() > 0){
5329
Vector JavaDoc tUpdate = (Vector JavaDoc) indexDTransformationUpdate.get(key);
5330                if(tUpdate.size() > 0){
5331               //int startUpdate = 0;
5332
for (int j = 0; j < tUpdate.size(); j++) {
5333                   int index = Integer.parseInt(tUpdate.get(j).toString());
5334                     Vector JavaDoc tempTransValueModes = (Vector JavaDoc)transformationsValueModes.get(iTableInt);
5335                     Vector JavaDoc tempTransColumnNames = (Vector JavaDoc)transformationsColumnNames.get(iTableInt);
5336                     Vector JavaDoc tempTransColumnTypes = (Vector JavaDoc)transformationsColumnTypes.get(iTableInt);
5337                       if (tempTransValueModes.get(index).toString().equalsIgnoreCase("Update")) {
5338    
5339                           String JavaDoc strQueryUpdate = "update " +
5340                                                   this.vecTableTableName.get(iTableInt).toString()
5341                                                   + " set ";
5342                           strQueryUpdate += tempTransColumnNames.get(index).toString()
5343                               + "=";
5344                           if (vecTransformationValue.get(index) == null)
5345                             strQueryUpdate += " null ";
5346                           else {
5347    
5348                             if (!configReaderTarget.isNumber(tempTransColumnTypes.get(index).toString()))
5349                               strQueryUpdate += "'" + vecTransformationValue.get(index).toString()
5350                                   + "' ";
5351                             else
5352                               strQueryUpdate += vecTransformationValue.get(index).toString() + " ";
5353                           }
5354                           if (oid) {
5355                                  if (bWriteData) {
5356
5357                                    strQueryUpdate += ", " + this.currentVersionColumnName + " = "
5358                                        + (iVersionMax) + " where ";
5359                                  } else {
5360
5361                                    strQueryUpdate += ", " + this.currentVersionColumnName + " = "
5362                                        + (iVersionMax + 1) + " where ";
5363                                  }
5364                           }
5365                              //strQueryUpdate += " where ";
5366
strQueryUpdate += tempTransColumnNames.get(j).toString()
5367                                + " is null and ";
5368                                         
5369                           if (bReplaceInData) {
5370                              strQueryUpdate = this.replaceInData(strQueryUpdate);
5371                              strQueryWhere = this.replaceInData(strQueryWhere);
5372                           }
5373                           this.logger.write("full", "\tQuery '" +
5374                            strQueryUpdate + strQueryWhere + "' will be executed");
5375                            int iNumRow = 0;
5376                           try {
5377                            logStatement = strQueryUpdate + strQueryWhere;
5378                                 iNumRow = stmtTarget.executeUpdate(strQueryUpdate + strQueryWhere);
5379                           }
5380                           catch (SQLException JavaDoc ex) {
5381                             stmtTarget.close();
5382                             stmtTarget = c.createStatement();
5383                             if ( (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("true"))) {
5384                               dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName.get(iTableInt).
5385                                   toString(), c, strQueryWhere, currentRow, update,
5386                                   importDefinitionElement.strOnErrorContinueXml,
5387                                   importDefinitionElement.strImportDefinitionName, strQueryUpdate + strQueryWhere);
5388                             } else
5389                               throw ex;
5390                           }
5391                           if (iNumRow != 0) {
5392                             if (!bWriteData)
5393                               iVersionMax = iVersionMax + 1;
5394                             bWriteData = true;
5395                           }
5396                
5397                       }
5398               //}
5399
}
5400        }
5401    }
5402  }
5403    
5404//ZK END
5405
}
5406          
5407          checkRowCache.setCheckRowVersionValue(String.valueOf(iVersionMax - 1));
5408        }
5409        stmtTarget.close();
5410        
5411      }
5412    }
5413// }
5414
catch (SQLException JavaDoc ex) {
5415
5416      if (stmtTarget != null)
5417        stmtTarget.close();
5418      if ( (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("true"))) {
5419        dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).toString(),
5420            c, currentRow, "UPDATE", ex.getMessage(),
5421            importDefinitionElement.strImportDefinitionName,logStatement);
5422// } else if ( (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("false") ||
5423
// importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("")) &&
5424
// importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("true")) {
5425
// dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).toString(),
5426
// c, currentRow, "UPDATE", ex.getMessage(),
5427
// importDefinitionElement.strImportDefinitionName);
5428
} else {
5429        this.logger.write("normal", "\tDataCleaning features is not turn on.");
5430        throw ex;
5431      }
5432    }
5433    catch (NullPointerException JavaDoc ex) {
5434      throw ex;
5435    }
5436    catch (Exception JavaDoc ex) {
5437
5438      throw ex;
5439    }
5440    this.logger.write("full", "\tinsertTargetTable method is finished.");
5441  }
5442
5443  /**
5444   * Method insertRow is used to insert new row in the target table.
5445       * Also includes inserting values into constant, variable and relation columns of the target table.
5446   * If there is an error, Exception "SQLException" or "NullPointerException" or
5447   * "Exception" is thrown.
5448   * @param c Connection to the target database.
5449   * @param vecColumnValues One row of values from source table.
5450   * @param vecColumnNamesTypes Types of columns in a target table.
5451   * @param vecColumnNames Vector of column names in a target table.
5452   * @param bOIDlogicValue true if oid column exists in the target table.
5453   * @param iTableInt Number of target table which is processed.
5454   * @param vecColumnMode represents vector of table modes for currnet table
5455   * @throws SQLException Constructs an SQLException object with a reason.
5456       * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
5457   * @throws Exception Constructs an Exception with the specified detail message.
5458   */

5459  private void insertRow(Connection JavaDoc c, Vector JavaDoc vecColumnValues,
5460      Vector JavaDoc vecColumnNamesTypes,
5461      Vector JavaDoc vecColumnNames, Vector JavaDoc vecColumnMode,
5462      boolean bOIDlogicValue,
5463      int iTableInt, Vector JavaDoc vecTransformationValue,Vector JavaDoc transformationTargetColumnTypes) throws SQLException JavaDoc,NullPointerException JavaDoc, Exception JavaDoc {
5464
5465    String JavaDoc key = String.valueOf(iTableInt);
5466    String JavaDoc strInsertRow = (String JavaDoc)queryInsertRow.get(key);
5467    Vector JavaDoc indexOfNotRelationColumns = (Vector JavaDoc)indexIsNotRelationsColumns.get(key);
5468
5469    PreparedStatement JavaDoc pstmt = (PreparedStatement JavaDoc)pstmtForInsert.get(key);
5470
5471    Vector JavaDoc pstmtColNames = (Vector JavaDoc)pstmtColumnNames.get(key);
5472    Vector JavaDoc pstmtValues = new Vector JavaDoc();
5473    Vector JavaDoc pstmtTypes = new Vector JavaDoc();
5474    //hendling select statement in relation tag!
5475
String JavaDoc selectValueInRel = "";
5476    String JavaDoc currentValueInRel = "";
5477
5478    this.logger.write("full", "\tinsertRow method is started.");
5479    String JavaDoc strQuery = "";
5480    boolean isTOS = ! (importDefinitionElement.strObjectIDNameColumnName.equals(
5481                    "") || importDefinitionElement.strObjectIDNameColumnValue.equals(""));
5482//sinisa 15.03.2003. Add subCouterColumns
5483
Vector JavaDoc subCounterKeyColumns = this.counterColumns.getSubCounterKeyColumns(
5484                                  this.vecTableTableName.get(iTableInt).toString(),
5485                                  this.vecTableTableID.get(iTableInt).toString());
5486   
5487    Hashtable JavaDoc subKeyValues = new Hashtable JavaDoc();
5488    try {
5489      Vector JavaDoc vecTempConstantColumns = (Vector JavaDoc)this.vecConstantTargetColumnName.
5490                                      get(iTableInt);
5491      Vector JavaDoc vecTempConstantValues = (Vector JavaDoc)this.vecConstantConstantValue.get(
5492                                     iTableInt);
5493      strInsertRow = strInsertRow.trim();
5494      int comma = strInsertRow.lastIndexOf(",");
5495      if (comma == (strInsertRow.length() - 1))
5496        strQuery = strInsertRow.substring(0, strInsertRow.length() - 1);
5497      else
5498        strQuery = strInsertRow;
5499      if (bOIDlogicValue) {
5500        if (isTOS) {
5501          pstmtValues.add(this.bdecOidNumber);
5502          pstmtTypes.add("java.math.BigDecimal");
5503        } else {
5504          pstmtValues.add(this.bdecOidNumber);
5505          pstmtValues.add(String.valueOf(0));
5506          pstmtTypes.add("java.math.BigDecimal");
5507          pstmtTypes.add("java.lang.Integer");
5508        }
5509      }
5510        
5511        strQuery = strQuery + ") VALUES (";
5512
5513      if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
5514        if (indexOfNotRelationColumns.size() > 0) {
5515          for (int k = 0; k < indexOfNotRelationColumns.size(); k++) {
5516            int index = Integer.parseInt(indexOfNotRelationColumns.get(k).
5517                        toString());
5518            Vector JavaDoc replacedValue = (Vector JavaDoc)vecDefaultValue.get(iTableInt);
5519            if (vecColumnValues.get(index) == null) {
5520              if (replacedValue.get(index) != "") {
5521                pstmtValues.add(replacedValue.get(index).toString());
5522                pstmtTypes.add(vecColumnNamesTypes.get(index).toString());
5523                dataCleaning.cleaningColumnValues(this.vecTableTableName.get(
5524                    iTableInt).toString(), vecColumnNames.get(index).toString(),
5525                    replacedValue.get(index).toString(), currentRow, c, "INSERT",
5526                    importDefinitionElement.strImportDefinitionName);
5527              } else {
5528                pstmtValues.add("null");
5529                pstmtTypes.add(vecColumnNamesTypes.get(index).toString());
5530              }
5531            } else {
5532              pstmtValues.add(vecColumnValues.get(index).toString());
5533              pstmtTypes.add(vecColumnNamesTypes.get(index).toString());
5534            }
5535
5536// sinisa 15.03 Add subCounter columns
5537
for (int l = 0; l < subCounterKeyColumns.size(); l++) {
5538              if (subCounterKeyColumns.get(l) != null &&
5539                  ( (Vector JavaDoc)subCounterKeyColumns.get(l)).size() != 0 &&
5540                  ( (Vector JavaDoc)subCounterKeyColumns.get(l)).contains(
5541                  vecColumnNames.get(index).toString())) {
5542                if (vecColumnValues.get(index) != null) {
5543                  subKeyValues.put(vecColumnNames.get(index).toString(),
5544                      vecColumnValues.get(index).toString());
5545                }
5546              }
5547            }
5548          }
5549        }
5550      }
5551      if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
5552        for (int p = 0; p < vecTempConstantValues.size(); p++) {
5553          if (vecTempConstantValues.get(p) == null) {
5554            pstmtValues.add("null");
5555            pstmtTypes.add( ( (Vector JavaDoc)this.vecConstantColumnType.get(iTableInt)).get(p).toString());
5556          } else {
5557            pstmtValues.add(vecTempConstantValues.get(p).toString());
5558            pstmtTypes.add( ( (Vector JavaDoc)this.vecConstantColumnType.get(iTableInt)).get(p).toString());
5559
5560          }
5561// sinisa 15.03 Add subCounter columns
5562
for (int l = 0; l < subCounterKeyColumns.size(); l++) {
5563            if (subCounterKeyColumns.get(l) != null &&
5564                ( (Vector JavaDoc)subCounterKeyColumns.get(l)).size() != 0 &&
5565                ( (Vector JavaDoc)subCounterKeyColumns.get(l)).contains(
5566                vecTempConstantColumns.get(p))) {
5567              if (vecTempConstantValues.get(p) != null)
5568                subKeyValues.put(vecTempConstantColumns.get(p).toString(),
5569                    vecTempConstantValues.get(p).toString());
5570            }
5571          }
5572        }
5573      }
5574      if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
5575        for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
5576          if (this.vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(this.
5577              vecTableTableName.get(iTableInt).toString())
5578              &&
5579              this.vecVariableTimesTableID.get(i).toString().
5580              equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
5581            pstmtValues.add(createCurrentDate());
5582            pstmtTypes.add("java.sql.Date");
5583          }
5584        }
5585        for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
5586          if (this.vecVariableColumnTargetTableName.get(i).toString().
5587              equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
5588              &&
5589              this.vecVariableColumnTargetTableID.get(i).toString().
5590              equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
5591            int iPositionInVector = this.vecVariableName.indexOf(this.
5592                                    vecVariableColumnName.get(i).toString());
5593            if (iPositionInVector != -1) {
5594              if (this.vecVariableValue.get(iPositionInVector) == null) {
5595                String JavaDoc variableName = this.vecVariableColumnName.get(i).
5596                                      toString();
5597                for (int k = 0; k < this.vecDefaultVariableName.size(); k++) {
5598                  if (this.vecDefaultVariableName.get(k).toString().
5599                      equalsIgnoreCase(variableName)) {
5600                    if (!this.vecDefaultVariableValue.get(k).toString().equalsIgnoreCase("")) {
5601                      pstmtValues.add(this.vecDefaultVariableValue.get(k).toString());
5602                      pstmtTypes.add(this.vecVariableColumnTypes.get(i).toString());
5603                    } else {
5604                      pstmtValues.add("null");
5605                      pstmtTypes.add(this.vecVariableColumnTypes.get(i).toString());
5606                    }
5607                    break;
5608                  }
5609                }
5610              } else {
5611                pstmtValues.add(this.vecVariableValue.get(iPositionInVector).toString());
5612                pstmtTypes.add(this.vecVariableColumnTypes.get(i).toString());
5613              }
5614            } else {
5615              this.logger.write("normal", "\tError: Cannot find value for variable column :"
5616                  + this.vecVariableColumnName.get(i).toString());
5617              LoaderException le = new LoaderException("Exception: ", (Throwable JavaDoc) (new Exception JavaDoc(
5618                                   "Error: Cannot find value for variable column :")));
5619                            this.logger.write("full", le.getStackTraceAsString());
5620              throw le;
5621            }
5622// sinisa 15.03 Add subCounter columns
5623
for (int l = 0; l < subCounterKeyColumns.size(); l++) {
5624              if (subCounterKeyColumns.get(l) != null &&
5625                  ( (Vector JavaDoc)subCounterKeyColumns.get(l)).size() != 0 &&
5626                  ( (Vector JavaDoc)subCounterKeyColumns.get(l)).contains(this.
5627                  vecVariableColumnName.get(iPositionInVector))) {
5628                if (this.vecVariableValue.get(iPositionInVector) != null)
5629                  subKeyValues.put(this.vecVariableColumnName.get(
5630                      iPositionInVector).toString(),
5631                      this.vecVariableValue.get(iPositionInVector).
5632                      toString());
5633              }
5634            }
5635          }
5636        }
5637      }
5638//find value for relation column - userID
5639
for (int i = 0; i < this.iRelationColumns; i++) {
5640        outLoop1:if (this.vecRelationColumnSourceTableName.get(i).toString().
5641            equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
5642            &&
5643            this.vecRelationColumnSourceTableID.get(i).toString().
5644            equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
5645          for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) {
5646            if (this.vecRelationColumnSourceTableName.get(i).toString().
5647                equalsIgnoreCase(this.vecVariableUseIDTableName.get(m).toString())
5648                &&
5649                this.vecRelationColumnSourceTableID.get(i).toString().
5650                equalsIgnoreCase(this.vecVariableUseIDTableID.get(m).toString())) {
5651              String JavaDoc strQueryRelations = "select " +
5652                                         this.vecRelationColumnSourceColumnName.get(i).toString()
5653                                         + " from " +
5654                                         this.vecRelationColumnSourceTableName.get(i).toString()
5655                                         + " where ";
5656              strQueryRelations +=
5657                  ( (Vector JavaDoc)this.vecTargetKeyColumnName.get(iTableInt)).get(0).
5658                  toString()
5659                  + " = ";
5660//ZK change this from CheckType to configReaderTarget this 7.5.2004
5661
if (!configReaderTarget.isNumber(vecColumnNamesTypes.get(0).toString()))
5662                strQueryRelations += "'" + this.strUserID
5663                    + "'";
5664              else
5665                strQueryRelations += this.strUserID;
5666              this.logger.write("full", "\tQuery '" + strQueryRelations
5667                  + "' will be executed");
5668              Statement JavaDoc stmt = c.createStatement();
5669              ResultSet JavaDoc rsetTarget = stmt.executeQuery(strQueryRelations);
5670              if (rsetTarget.next()) {
5671                if (this.iTargetFirstColumnResult == 1) {
5672                  this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(1), i);
5673                  this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().
5674                      getColumnTypeName(
5675                      1), i);
5676                } else {
5677                  this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(0), i);
5678                  this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().
5679                      getColumnTypeName(
5680                      0), i);
5681                }
5682              }
5683              rsetTarget.close();
5684              stmt.close();
5685              break outLoop1;
5686            }
5687          }
5688          if (bOIDlogicValue) {
5689            String JavaDoc oidType = configReaderTarget.getOidDbType();
5690            int end = oidType.indexOf("(");
5691            if (end != -1)
5692              oidType = (oidType.substring(0, end)).trim();
5693            else
5694              oidType = oidType.trim();
5695            if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
5696              //insertTable=true
5697
this.vecRelationSourceValue.setElementAt(this.bdecOidNumber, i);
5698              this.vecRelationSourceType.setElementAt(oidType.toLowerCase(), i);
5699
5700            } else {
5701              //insertTable=false
5702
this.vecRelationSourceValue.setElementAt(null, i);
5703              this.vecRelationSourceType.setElementAt(oidType.toLowerCase(), i);
5704
5705            }
5706          } else { //bOIDlogicValue=false
5707
if (this.iRelationColumns > 0) {
5708              for (int j = 0; j < vecColumnNames.size(); j++) {
5709                if (this.vecRelationColumnSourceColumnName.get(i).toString().
5710                    equalsIgnoreCase(vecColumnNames.get(j).toString())) {
5711                  if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
5712                    //insertTable=true
5713
this.vecRelationSourceValue.setElementAt(vecColumnValues.get(
5714                        j).toString(), i);
5715                    this.vecRelationSourceType.setElementAt(vecColumnNamesTypes.
5716                        get(j).toString(), i);
5717                  } else {
5718                    //insertTable=false;
5719
this.vecRelationSourceValue.setElementAt(null, i);
5720                    this.vecRelationSourceType.setElementAt(vecColumnNamesTypes.
5721                        get(j).toString(), i);
5722                  }
5723                }
5724              } //end vecColumnNames.size()
5725
}
5726          }
5727        }
5728      }
5729
5730      for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) {
5731        String JavaDoc tmpRelationForCount = "";
5732        if (this.vecRelationColumnTargetTableName.get(i).toString().
5733            equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
5734            &&
5735            this.vecRelationColumnTargetTableID.get(i).toString().
5736            equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
5737          if (this.vecRelationSourceValue.get(i) == null) {
5738            String JavaDoc replacementValueInRel = vecDefaultRelationValue.get(i).toString();
5739            if (!replacementValueInRel.equalsIgnoreCase("")) {
5740              //default value for relation exists
5741
try {
5742                Object JavaDoc obj = relationsCache.getRelationsCacheValue(replacementValueInRel);
5743                String JavaDoc relationValue;
5744                String JavaDoc relationType;
5745                if (obj != null) {
5746                  // relation (default value) is cached
5747
relationValue = obj.toString();
5748                  relationType = relationsCache.getRelationsCachType(replacementValueInRel);
5749                  pstmtValues.add(relationValue);
5750                  pstmtTypes.add(relationType);
5751                } else {
5752                  // relation (default value) isn't cached
5753
ResultSet JavaDoc newRelationValue = null;
5754                  Statement JavaDoc newRelationsStmt = c.createStatement();
5755                  try {
5756                    this.logger.write("full",
5757                        "\tQuery '" + replacementValueInRel + "' will be executed");
5758                    newRelationValue = newRelationsStmt.executeQuery(replacementValueInRel);
5759                    if (newRelationValue.next()) {
5760                      relationValue = newRelationValue.getString(1);
5761                      relationsCache.setRelationsCacheValue(replacementValueInRel, relationValue);
5762                      relationType = newRelationValue.getMetaData().getColumnTypeName(1);
5763                      relationsCache.setRelationsCacheType(replacementValueInRel, relationType);
5764
5765                      newRelationValue.close();
5766                      newRelationsStmt.close();
5767
5768                      String JavaDoc strDataCleaning = dataCleaning.cleaningRelationValues(this.
5769                                               vecTableTableName.get(iTableInt).toString(),
5770                                               this.vecRelationColumnTargetColumnName.get(i).
5771                                               toString(),
5772                                               relationValue,
5773                                               relationType, currentRow,
5774                                               c, "INSERT", 0, false,
5775                                               importDefinitionElement.strImportDefinitionName,
5776                                               this.currentVersionColumnName, replacementValueInRel);
5777                      pstmtValues.add(strDataCleaning);
5778                      pstmtTypes.add(relationType);
5779                    } else { //newRelationValue.next()=false
5780
newRelationValue.close();
5781                      newRelationsStmt.close();
5782                      relationValue = "null";
5783                      dataCleaning.cleaningInsert(this.vecTableTableName.get(
5784                          iTableInt).toString(), c, currentRow, "INSERT",
5785                          "Default value '" + replacementValueInRel
5786                          + "' for relations is not valid.",
5787                          importDefinitionElement.strImportDefinitionName, replacementValueInRel);
5788
5789                      pstmtValues.add("null");
5790                      pstmtTypes.add(this.vecRelationSourceType.get(i).toString());
5791                    }
5792                  }
5793                  catch (SQLException JavaDoc ex) {
5794                    newRelationValue.close();
5795                    newRelationsStmt.close();
5796                    LoaderException le = new LoaderException("\n" + "SQLException: "
5797                                         + ex.getMessage(),
5798                                         (Throwable JavaDoc)ex);
5799                                        this.logger.write("full", le.getStackTraceAsString());
5800                    throw le;
5801                  }
5802                }
5803
5804              }
5805              catch (SQLException JavaDoc ex) {
5806                String JavaDoc msg = "Default value for foreign key(" + replacementValueInRel +
5807                             ") is not valid. Import definition name: " +
5808                             importDefinitionElement.strImportDefinitionName;
5809                LoaderException le = new LoaderException("SQLException: " + msg,
5810                                     (Throwable JavaDoc)ex);
5811                                this.logger.write("full", le.getStackTraceAsString());
5812                throw le;
5813              }
5814
5815            } else { //default value for relations doesn't exsist
5816
pstmtValues.add("null");
5817              if (this.vecRelationSourceType.get(i) != null)
5818                pstmtTypes.add(this.vecRelationSourceType.get(i).toString());
5819              else
5820                pstmtTypes.add("java.lang.Object");
5821            }
5822          } else { //this.vecRelationSourceType.get(i)!=null
5823
pstmtValues.add(this.vecRelationSourceValue.get(i).toString());
5824            pstmtTypes.add(this.vecRelationSourceType.get(i).toString());
5825
5826            tmpRelationForCount=this.vecRelationSourceValue.get(i).toString();//
5827
this.vecRelationSourceValue.setElementAt(null,i);
5828
5829          }
5830
5831// sinisa 15.03 Add subCounter columns
5832
for (int l = 0; l < subCounterKeyColumns.size(); l++) {
5833            if (subCounterKeyColumns.get(l) != null &&
5834                ( (Vector JavaDoc)subCounterKeyColumns.get(l)).size() != 0 &&
5835                ( (Vector JavaDoc)subCounterKeyColumns.get(l)).contains(this.
5836                vecRelationColumnTargetColumnName.get(i))) {
5837              if (tmpRelationForCount != null) {
5838                subKeyValues.put(this.vecRelationColumnTargetColumnName.get(i).toString(),
5839                    tmpRelationForCount);
5840              }
5841            }
5842          }
5843        }
5844      }
5845
5846//sinisa 02.03.2003. Add couterColumns
5847
Vector JavaDoc counterColValues = this.counterColumns.getCounterValue(
5848                                this.vecTableTableName.get(iTableInt).toString(),
5849                                this.vecTableTableID.get(iTableInt).toString());
5850      for (int i = 0; i < counterColValues.size(); i++) {
5851        if (counterColValues.get(i) != null) {
5852          int strInt = new BigDecimal JavaDoc(counterColValues.get(i).toString()).
5853                       intValue();
5854          pstmtValues.add(String.valueOf(strInt));
5855          pstmtTypes.add("java.lang.Integer");
5856        } else {
5857          pstmtValues.add("null");
5858          pstmtTypes.add("java.lang.Integer");
5859        }
5860      }
5861      this.counterColumns.setCounterValue(this.vecTableTableName.get(iTableInt).
5862          toString(),
5863          this.vecTableTableID.get(iTableInt).
5864          toString());
5865//end sinisa
5866

5867//sinisa 15.03.2003. Add counterColumns
5868
if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
5869        this.counterColumns.setSubCounterKeyValues(
5870            this.vecTableTableName.get(iTableInt).toString(),
5871            this.vecTableTableID.get(iTableInt).toString(), subKeyValues);
5872        Vector JavaDoc subCounterColValues = this.counterColumns.readSubCounterValue(
5873                                     this.vecTableTableName.get(iTableInt).toString(),
5874                                     this.vecTableTableID.get(iTableInt).toString(), c,
5875                                     this.iTargetFirstColumnResult,
5876                                     this.vecTableTableMode.get(iTableInt).toString(), configReaderTarget);
5877        for (int i = 0; i < subCounterColValues.size(); i++) {
5878          if (subCounterColValues.get(i) != null) {
5879            pstmtValues.add(new BigDecimal JavaDoc(subCounterColValues.get(i).toString()));
5880            pstmtTypes.add("java.math.BigDecimal");
5881          } else {
5882            pstmtValues.add("null");
5883            pstmtTypes.add("java.math.BigDecimal");
5884          }
5885        }
5886        if (bOIDlogicValue) {
5887          if (this.bdecOidNumber.compareTo(this.bdecOidNumber2000) == 0) {
5888            this.checkOidLogic(c);
5889            this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal JavaDoc(1));
5890          } else
5891            this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal JavaDoc(1));
5892        }
5893        
5894// ZK added this for transormations
5895
for (int i = 0; i < vecTransformationValue.size(); i++) {
5896            if ((vecTransformationValue.get(i))== null){
5897                String JavaDoc valueForPstmt = "null";
5898                pstmtValues.add(valueForPstmt);
5899            }else{
5900                pstmtValues.add(vecTransformationValue.get(i).toString());
5901            }
5902            
5903            pstmtTypes.add(transformationTargetColumnTypes.get(i).toString());
5904            
5905        }
5906        
5907    
5908// String tableNameId= this.vecTableTableName.get(iTableInt).toString()+this.vecTableTableID.get(iTableInt).toString();
5909
// if (transTableNamesIDs.contains(tableNameId)){
5910
// for (int i=0; i < trans.size();i++){
5911
// Transformation pom = (Transformation)trans.get(i);
5912
// Vector sourceColumnNames = pom.getSourceColumnNames();
5913
// Vector targetColumnNames = pom.getTargetColumnNames(this.vecTableTableName.get(iTableInt).toString(),
5914
// this.vecTableTableID.get(iTableInt).toString());
5915
//
5916
// Vector resultVector = pom.readTransformationValues(sourceColumnNames,
5917
// this.vecTableTableName.get(iTableInt).toString(),
5918
// this.vecTableTableID.get(iTableInt).toString());
5919
// Vector resultVectorTypes = pom.getTargetColumnTypes(this.vecTableTableName.get(iTableInt).toString(),
5920
// this.vecTableTableID.get(iTableInt).toString());
5921
// for(int j=0;j < resultVector.size();j++) {
5922
// pstmtValues.add(resultVector.get(j));
5923
// pstmtTypes.add(resultVectorTypes.get(j));
5924
// }
5925
// }
5926
// }
5927
//end
5928

5929        //handling blob object
5930
//strQuery = strQuery + ") VALUES (";
5931
String JavaDoc pstmtColumnValue;
5932        for (int i = 0; i < pstmtValues.size(); i++) {
5933            
5934          String JavaDoc javaType = pstmtTypes.get(i).toString().toUpperCase();
5935          if (javaType.indexOf("JAVA") == -1){
5936// //ZK Added next line because of DB2 type LONG VARCHAR
5937
javaType = Utils.replaceAll(javaType," ","_");
5938            javaType = (String JavaDoc)configReaderTarget.getJavaTypeMapings().get(javaType.toUpperCase());
5939            if (javaType == null){
5940                                    LoaderException le = new LoaderException("Exception:",new Exception JavaDoc("This type of data "+pstmtTypes.get(i).toString().toUpperCase()+" doesn't exists in the target table conf file!"));
5941                                    this.logger.write("full", le.getStackTraceAsString());
5942                                    throw le;
5943            }
5944          } else {
5945            if (javaType.equalsIgnoreCase("java.math.BigDecimal"))
5946              javaType = "2";
5947            else if (javaType.equalsIgnoreCase("java.lang.Integer"))
5948              javaType = "5";
5949            else if (javaType.equalsIgnoreCase("java.sql.Date"))
5950              javaType = "9";
5951            else if (javaType.equalsIgnoreCase("java.lang.Object"))
5952              javaType = "14";
5953            
5954          }
5955            
5956          int javaTypeInt=Integer.parseInt(javaType);
5957                    pstmtColumnValue = pstmtValues.get(i).toString();
5958//ZK changed this 17.6 2004 because of problems with null binary object.
5959
// if (pstmtColumnValue.startsWith("binaryObject")) {
5960
if (javaTypeInt == 1){
5961                if (!pstmtColumnValue.equalsIgnoreCase("null")){
5962                String JavaDoc binaryName = pstmtValues.get(i).toString();
5963                for (int j = 0; j < vecBlobVector.size(); j = j + 5) {
5964                  if (binaryName.equalsIgnoreCase(vecBlobVector.get(j + 4).toString())) {
5965                    byte[] isBlob = (byte[])this.vecBlobVector.get(j + 1);
5966                    strQuery = strQuery + binaryName + ",";
5967                    pstmt.setBytes(i + 1, isBlob);
5968                    strQuery = strQuery + "BlobObject"+i + ",";
5969                    break;
5970                  }
5971                }
5972                }else{
5973                            pstmt.setNull(i + 1, java.sql.Types.BINARY);
5974                          strQuery = strQuery + "null" + ",";
5975                }
5976          } else {
5977            if (javaTypeInt == 2) { //java.math.BigDecimal
5978
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
5979                BigDecimal JavaDoc number = new BigDecimal JavaDoc(0);
5980                if (!pstmtColumnValue.equalsIgnoreCase(""))
5981                  number = new BigDecimal JavaDoc(pstmtColumnValue);
5982                strQuery = strQuery + pstmtColumnValue + ",";
5983                pstmt.setBigDecimal(i + 1, number);
5984              } else {
5985                pstmt.setNull(i + 1, java.sql.Types.DECIMAL);
5986                strQuery = strQuery + "null" + ",";
5987              }
5988            } else if (javaTypeInt == 3) { //java.lang.Double
5989
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
5990                double number = 0;
5991                if (!pstmtColumnValue.equalsIgnoreCase(""))
5992                  number = Double.parseDouble(pstmtColumnValue);
5993                strQuery = strQuery + pstmtColumnValue + ",";
5994                pstmt.setDouble(i + 1, number);
5995              } else {
5996                strQuery = strQuery + "null" + ",";
5997                pstmt.setNull(i + 1, java.sql.Types.DOUBLE);
5998              }
5999            } else if (javaTypeInt == 4) { //java.lang.Float
6000
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6001                float number = 0;
6002                if (!pstmtColumnValue.equalsIgnoreCase(""))
6003                  number = Float.parseFloat(pstmtColumnValue);
6004                pstmt.setFloat(i + 1, number);
6005                strQuery = strQuery + pstmtColumnValue + ",";
6006              } else {
6007                pstmt.setNull(i + 1, java.sql.Types.FLOAT);
6008                strQuery = strQuery + "null" + ",";
6009              }
6010            } else if (javaTypeInt == 5) { //java.lang.Integer
6011
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6012                int number = 0;
6013                if (!pstmtColumnValue.equalsIgnoreCase(""))
6014                  number = Integer.parseInt(pstmtColumnValue);
6015                pstmt.setInt(i + 1, number);
6016                strQuery = strQuery + pstmtColumnValue + ",";
6017              } else {
6018                pstmt.setNull(i + 1, java.sql.Types.INTEGER);
6019                strQuery = strQuery + "null" + ",";
6020              }
6021
6022            } else if (javaTypeInt == 6) { //java.lang.Long
6023
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6024                long number = 0;
6025                if (!pstmtColumnValue.equalsIgnoreCase(""))
6026                  number = Long.parseLong(pstmtColumnValue);
6027                pstmt.setLong(i + 1, number);
6028                strQuery = strQuery + pstmtColumnValue + ",";
6029              } else {
6030                pstmt.setNull(i + 1, java.sql.Types.DOUBLE);
6031                strQuery = strQuery + "null" + ",";
6032              }
6033            } else if (javaTypeInt == 7) { //java.lang.Short
6034
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6035                short number = 0;
6036                if (!pstmtColumnValue.equalsIgnoreCase(""))
6037                  number = Short.parseShort(pstmtColumnValue);
6038                pstmt.setShort(i + 1, number);
6039                strQuery = strQuery + pstmtColumnValue + ",";
6040              } else {
6041                pstmt.setNull(i + 1, java.sql.Types.SMALLINT);
6042                strQuery = strQuery + "null" + ",";
6043              }
6044            } else if (javaTypeInt == 8) { //java.lang.String
6045
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6046                //all '' back to ' (original value)
6047
if (pstmtColumnValue.indexOf("''") != -1) {
6048                  pstmtColumnValue = Utils.replaceAll(pstmtColumnValue, "''", "'");
6049                }
6050                pstmt.setString(i + 1, pstmtColumnValue);
6051                strQuery = strQuery + "'"+pstmtColumnValue+"'" + ",";
6052              } else {
6053                pstmt.setNull(i + 1, java.sql.Types.VARCHAR);
6054                strQuery = strQuery + "null" + ",";
6055                
6056                    
6057              }
6058            } else if (javaTypeInt == 9) { //java.sql.Date
6059
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6060                pstmt.setString(i + 1, pstmtColumnValue);
6061                strQuery = strQuery + "'"+pstmtColumnValue+"'" + ",";
6062              } else {
6063                pstmt.setNull(i + 1, java.sql.Types.DATE);
6064                strQuery = strQuery + "null" + ",";
6065              }
6066            } else if (javaTypeInt == 10) { //java.sql.Time
6067
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6068                pstmt.setString(i + 1, pstmtColumnValue);
6069                strQuery = strQuery + "'"+pstmtColumnValue+"'" + ",";
6070              } else {
6071                pstmt.setNull(i + 1, java.sql.Types.TIME);
6072                strQuery = strQuery + "null" + ",";
6073              }
6074
6075            } else if (javaTypeInt == 11) { //java.sql.Timestamp
6076
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6077                pstmt.setString(i + 1, pstmtColumnValue);
6078                strQuery = strQuery + "'"+pstmtColumnValue+"'" + ",";
6079              } else {
6080                pstmt.setNull(i + 1, java.sql.Types.TIMESTAMP);
6081                strQuery = strQuery + "null" + ",";
6082              }
6083
6084            } else if (javaTypeInt == 12) { //java.lang.Boolean
6085
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6086                boolean bool = Boolean.getBoolean(pstmtColumnValue);
6087                pstmt.setBoolean(i + 1, bool);
6088                strQuery = strQuery + pstmtColumnValue + ",";
6089              } else {
6090                pstmt.setNull(i + 1, java.sql.Types.BIT);
6091                strQuery = strQuery + "null" + ",";
6092              }
6093            } else if (javaTypeInt == 13) { //java.lang.Byte
6094
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6095                pstmt.setString(i + 1,pstmtColumnValue);
6096                strQuery = strQuery + "'"+pstmtColumnValue+"'" + ",";
6097              } else {
6098                pstmt.setNull(i + 1, java.sql.Types.BIT);
6099                strQuery = strQuery + "null" + ",";
6100              }
6101            } else if (javaTypeInt == 14) { //java.lang.Object
6102
if (!pstmtColumnValue.equalsIgnoreCase("null")) {
6103                pstmt.setString(i + 1, pstmtColumnValue);
6104                strQuery = strQuery + "'"+pstmtColumnValue+"'" + ",";
6105              } else {
6106                //TODO zoran pogledati ovo
6107
pstmt.setNull(i + 1, java.sql.Types.NULL);
6108                        //pstmt.setString(i + 1, null);
6109
strQuery = strQuery + "null" + ",";
6110              }
6111            }else{
6112                LoaderException le = new LoaderException("Exception:",new Exception JavaDoc("This java type is not supported!"));
6113                            this.logger.write("full", le.getStackTraceAsString());
6114                            throw le;
6115            }
6116          }//end of else (not blob)
6117
pstmtColumnValue=null;
6118        }
6119        strQuery = strQuery.substring(0, strQuery.length() - 1) + ")";
6120        this.logger.write("full", "\tQuery '" + strQuery + "' will be executed");
6121
6122        int pstmtInsert = 0;
6123        pstmtInsert = pstmt.executeUpdate();
6124        //setting the cache value for inseted row
6125
if (pstmtInsert != 0)
6126          this.checkRowCache.setCheckRowValue();
6127        pstmt.clearParameters();
6128        pstmtValues.clear();
6129        pstmtTypes.clear();
6130                
6131//TODO 14.6.2004 ZK Comented this because of problems with update on counters table which are not needed.
6132
//this.counterColumns.updateCounter(this.vecTableTableName.get(iTableInt).toString(),
6133
//this.vecTableTableID.get(iTableInt).toString(), c);
6134

6135      } else {
6136        this.checkRowCache.setCheckRowValue();
6137      }
6138   }
6139    catch (SQLException JavaDoc ex) {
6140      pstmt.clearParameters();
6141      pstmtValues.clear();
6142      pstmtTypes.clear();
6143      LoaderException le = new LoaderException("SQLException: ", (Throwable JavaDoc)ex);
6144      if (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("true")) {
6145        dataCleaning.cutingDataLenght(this.vecTableTableName.get(iTableInt).
6146            toString(), c,
6147            strQuery, currentRow,
6148            importDefinitionElement.
6149            strOnErrorContinueXml,
6150            ex.getMessage(),
6151            importDefinitionElement.strImportDefinitionName, strQuery);
6152      } else if (importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("true")) {
6153        pstmt.clearParameters();
6154        pstmtValues.clear();
6155        pstmtTypes.clear();
6156        //this.logger.write("full", "\tError in SQL statement: " + le.getStackCause());
6157
this.logger.write("full", "\tError in SQL statement: " +le.getStackTraceAsString());
6158        dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).toString(),
6159            c, currentRow, "INSERT", ex.getMessage(),
6160            importDefinitionElement.strImportDefinitionName,strQuery);
6161      } else {
6162        pstmt.clearParameters();
6163        pstmtValues.clear();
6164        pstmtTypes.clear();
6165        this.logger.write("normal", "\tError in SQL statement: " + le.getCause());
6166                this.logger.write("full", le.getStackTraceAsString());
6167        //throw ex;
6168
throw le;
6169      }
6170    }
6171    catch (NullPointerException JavaDoc ex) {
6172      throw ex;
6173    }
6174    catch (Exception JavaDoc ex) {
6175      throw ex;
6176    }
6177    this.logger.write("full", "\tinsertRow method is finished.");
6178  }
6179
6180  /**
6181   * Method isRelationColumn checkes if the column(strColumnName) in target table(iTable)
6182   * is mentioned in relation tags (target column name). If it is, return true, else return false.
6183   * @param strColumnName - Name of target column
6184   * @param iTable - Number of target table
6185   * @return boolean - true if strColumnName is relation target column, false if it is not.
6186   */

6187  private boolean isRelationColumn(String JavaDoc strColumnName, int iTable) {
6188    boolean bFind = false;
6189    endFor:for (int i = 0; i < this.vecRelationColumnTargetTableName.size(); i++) {
6190      if (this.vecRelationColumnTargetTableName.get(i).toString().
6191          equalsIgnoreCase(this.vecTableTableName.get(iTable).toString())
6192          &&
6193          this.vecRelationColumnTargetTableID.get(i).toString().
6194          equalsIgnoreCase(this.vecTableTableID.get(iTable).toString())
6195          &&
6196          this.vecRelationColumnTargetColumnName.get(i).toString().
6197          equalsIgnoreCase(strColumnName)) {
6198        bFind = true;
6199        break endFor;
6200      }
6201    }
6202    return bFind;
6203  }
6204
6205  /**
6206       * Method checkOidLogic is used to increase the ObjectID value with adding iObjectIDIncrement value.
6207   * Method puts new value in ObjectID table for current importDefinition.
6208   * If there is an error, Exception "SQLException" or NullPointerException is thrown.
6209   * @param c Connection to target database.
6210   * @throws SQLException Constructs an SQLException object with a reason.
6211       * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
6212   */

6213  private void checkOidLogic(Connection JavaDoc c) throws SQLException JavaDoc,
6214      NullPointerException JavaDoc {
6215    String JavaDoc strQuery = "";
6216    this.logger.write("full", "\tcheckOidLogic method is started.");
6217    Boolean JavaDoc bTemp = new Boolean JavaDoc("false");
6218
6219    if (currentJobName.equalsIgnoreCase("importDefinition")) {
6220      for (int i = 0; i < this.iTables; i++) {
6221        if (this.vecTableOidLogic.get(i).toString().equalsIgnoreCase("true")) {
6222          bTemp = new Boolean JavaDoc("true");
6223        }
6224      }
6225    } else if (currentJobName.equalsIgnoreCase("copyTable")) {
6226      if (importDefinitionElement.strCopyTableOidLogic.equalsIgnoreCase("true")) {
6227        bTemp = new Boolean JavaDoc("true");
6228      }
6229    }
6230
6231    if (bTemp.booleanValue()) {
6232      try {
6233        if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") ||
6234            importDefinitionElement.strObjectIDNameColumnValue.equals(""))) {
6235          strQuery = new String JavaDoc("SELECT " +
6236                     importDefinitionElement.strObjectIDColumnName
6237                     + " FROM " +
6238                     importDefinitionElement.strObjectIDTableName +
6239                     " WHERE "
6240                     +
6241                     importDefinitionElement.
6242                     strObjectIDNameColumnName +
6243                     " = '" +
6244                     importDefinitionElement.
6245                     strObjectIDNameColumnValue +
6246                     "'");
6247        } else {
6248          strQuery = new String JavaDoc("SELECT " +
6249                     importDefinitionElement.strObjectIDColumnName
6250                     + " FROM " +
6251                     importDefinitionElement.strObjectIDTableName);
6252        }
6253        this.logger.write("full","\tQuery '" + strQuery + "' will be executed");
6254        Statement JavaDoc stmtOid = c.createStatement();
6255        ResultSet JavaDoc rsetOid = stmtOid.executeQuery(strQuery);
6256        if (rsetOid.next()) {
6257          if (this.iTargetFirstColumnResult == 1)
6258            this.bdecOidNumber = new BigDecimal JavaDoc(Integer.parseInt(rsetOid.
6259                                 getString(1)));
6260          else
6261            this.bdecOidNumber = new BigDecimal JavaDoc(Integer.parseInt(rsetOid.
6262                                 getString(0)));
6263        } else {
6264          if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") ||
6265              importDefinitionElement.strObjectIDNameColumnValue.equals(""))) {
6266            String JavaDoc insert = "insert into " +
6267                            importDefinitionElement.strObjectIDTableName + " (" +
6268                            importDefinitionElement.strObjectIDNameColumnName + "," +
6269                            importDefinitionElement.strObjectIDColumnName + ") values ('" +
6270                            importDefinitionElement.strObjectIDNameColumnValue
6271                            + "','" + importDefinitionElement.iObjectIDStartValue + "');";
6272            stmtOid.execute(insert);
6273          }
6274        }
6275        rsetOid.close();
6276        stmtOid.close();
6277
6278        if (currentJobName.equalsIgnoreCase("copyTable")) {
6279          this.bdecOidNumber2000 = this.bdecOidNumber.add(new BigDecimal JavaDoc(
6280                                   importDefinitionElement.iObjectIDCT));
6281        } else {
6282          this.bdecOidNumber2000 = this.bdecOidNumber.add(new BigDecimal JavaDoc(
6283                                   importDefinitionElement.iObjectID));
6284        }
6285        Statement JavaDoc stmtOid2 = c.createStatement();
6286        if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") ||
6287            importDefinitionElement.strObjectIDNameColumnValue.equals(""))) {
6288          this.logger.write("full",
6289              "\tQuery '" + "UPDATE " +
6290              importDefinitionElement.strObjectIDTableName
6291              + " SET " +
6292              importDefinitionElement.strObjectIDColumnName +
6293              " = " + this.bdecOidNumber2000
6294              + " where " +
6295              importDefinitionElement.
6296              strObjectIDNameColumnName +
6297              " = '" +
6298              importDefinitionElement.
6299              strObjectIDNameColumnValue +
6300              "'' will be executed");
6301          stmtOid2.executeUpdate("UPDATE " +
6302              importDefinitionElement.strObjectIDTableName
6303              + " SET " +
6304              importDefinitionElement.strObjectIDColumnName +
6305              " = " + this.bdecOidNumber2000
6306              + " where " +
6307              importDefinitionElement.
6308              strObjectIDNameColumnName +
6309              " = '" +
6310              importDefinitionElement.
6311              strObjectIDNameColumnValue +
6312              "'");
6313        } else {
6314          this.logger.write("full",
6315              "\tQuery '" + "UPDATE " +
6316              importDefinitionElement.strObjectIDTableName
6317              + " SET " +
6318              importDefinitionElement.strObjectIDColumnName +
6319              " = " + this.bdecOidNumber2000
6320              + " where " +
6321              importDefinitionElement.strObjectIDColumnName +
6322              " = " +
6323              this.bdecOidNumber + "' will be executed");
6324          stmtOid2.executeUpdate("UPDATE " +
6325              importDefinitionElement.strObjectIDTableName
6326              + " SET " +
6327              importDefinitionElement.strObjectIDColumnName +
6328              " = " + this.bdecOidNumber2000
6329              + " where " +
6330              importDefinitionElement.strObjectIDColumnName +
6331              " = " +
6332              this.bdecOidNumber);
6333        }
6334        stmtOid2.close();
6335      }
6336      catch (SQLException JavaDoc ex) {
6337        throw ex;
6338      }
6339      catch (NullPointerException JavaDoc ex) {
6340        throw ex;
6341      }
6342    }
6343    this.logger.write("full", "\tcheckOidLogic method is finished.");
6344  }
6345
6346  /**
6347   * Method querySource is used to make SQL query to source table and to
6348   * sort columns from source table ordered by sortColumns.
6349   * @return SQL Query to source table.
6350   * @throws LoaderException
6351   */

6352  private String JavaDoc querySource() throws LoaderException {
6353    int i = 0;
6354    int j = 0;
6355    this.logger.write("full", "\tquerySource method is started.");
6356    Vector JavaDoc vecVektor = new Vector JavaDoc();
6357    String JavaDoc strQuery = "select ";
6358     //this is pointer where transformations columns starts within result set
6359
this.iOffsetForTransColumns = 0;
6360    while (i < this.iTables) {
6361      vecVektor = (Vector JavaDoc)this.vecSourceColumnName.get(i);
6362        this.iOffsetForTransColumns += vecVektor.size();
6363      while (j <
6364          Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString())) {
6365        strQuery = strQuery + vecVektor.get(j).toString() + ", ";
6366        j++;
6367        this.iColumnsInSourceTable++;
6368      }
6369      j = 0;
6370      i++;
6371    }
6372    ArrayList JavaDoc trans = this.transformations.getTransformations();
6373    //int numTransSourceColumns = 0;
6374
//read all source columns for all transformations
6375
//i = 0;
6376
//while (i < this.iTables) {
6377
for( int k = 0; k < trans.size(); k++ ) {
6378            Transformation transformation = (Transformation)trans.get(k);
6379// if( i != Integer.parseInt( transformation.getTargetTableID() ) )
6380
// continue;
6381
Vector JavaDoc sourceColumnNames = transformation.getSourceColumnNames();
6382            for( int kk = 0 ; kk < sourceColumnNames.size(); kk++ ) {
6383                strQuery = strQuery + sourceColumnNames.get(kk).toString() + ", ";
6384                //numTransSourceColumns++;
6385
}
6386        }
6387        //this.vecTransformColumnsTargetTables.add( String.valueOf(numTransSourceColumns) );
6388
//numTransSourceColumns=0;
6389
//i++;
6390
//}
6391
strQuery = strQuery.substring(0, strQuery.length() - 2);
6392    strQuery += " from " + importDefinitionElement.strImportDefinitionTableName;
6393    if (importDefinitionElement.vecRestartCounterSortColumn.size() != 0) {
6394      if (configReaderSource.getEnableOrderBy()) {
6395        strQuery += " order by ";
6396        for (j = 0;
6397                 j < importDefinitionElement.vecRestartCounterSortColumn.size(); j++) {
6398          strQuery += importDefinitionElement.vecRestartCounterSortColumn.get(j).
6399              toString() + ", ";
6400        }
6401        strQuery = strQuery.substring(0, strQuery.length() - 2);
6402      }
6403    }
6404
6405    this.logger.write("full", "\tquerySource method is finished.");
6406    return strQuery;
6407  }
6408
6409  /**
6410   * Method targetColumnTypes is used to put source table column types
6411   * into Vector "vecSourceColumnType". This includes columns from the querySource
6412   * method. If there is an error, Exception "SQLException" or NullPointerException
6413   * is thrown.
6414   * @param connTarget Connection to the target table.
6415   * @throws SQLException Constructs an SQLException object with a reason.
6416       * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
6417   */

6418  private void targetColumnTypes(Connection JavaDoc connTarget) throws SQLException JavaDoc,
6419      NullPointerException JavaDoc {
6420    int iColumn;
6421    String JavaDoc strQueryTypes = "";
6422    this.logger.write("full", "\ttargetColumnTypes method is started.");
6423    try {
6424      for (int i = 0; i < this.iTables; i++) {
6425        Vector JavaDoc vecKeyTypesRelations = new Vector JavaDoc();
6426        Vector JavaDoc vecVektor = new Vector JavaDoc();
6427        iColumn = 0;
6428                Statement JavaDoc stmtTypes = connTarget.createStatement();
6429//ZK added 11.6.2004 because of new parameter GetMaxRowsSupported
6430
if (this.configReaderTarget.getMaxRowsSupported()){
6431                    stmtTypes.setMaxRows(1);
6432        }
6433       
6434        
6435        strQueryTypes = "select ";
6436        for (int j = 0; j < ( (Vector JavaDoc)this.vecTargetColumnName.get(i)).size();
6437                     j++) {
6438          strQueryTypes +=
6439              ( ( (Vector JavaDoc)this.vecTargetColumnName.get(i)).get(j).toString())
6440              + ",";
6441        }
6442        for (int j = 0; j < ( (Vector JavaDoc)this.vecRelationKeyColumns.get(i)).size();
6443                     j++) {
6444          strQueryTypes +=
6445              ( ( (Vector JavaDoc)this.vecRelationKeyColumns.get(i)).get(j).toString())
6446              + ",";
6447        }
6448        strQueryTypes = strQueryTypes.substring(0, strQueryTypes.length() - 1);
6449        strQueryTypes += " from ";
6450        strQueryTypes += " " + this.vecTableTableName.get(i).toString();
6451
6452
6453        if ( ( (Vector JavaDoc)this.vecTargetColumnName.get(i)).size() != 0 ||
6454            ( (Vector JavaDoc)this.vecRelationKeyColumns.get(i)).size() != 0) {
6455
6456          this.logger.write("full", "\tQuery '" + strQueryTypes +
6457              "' will be executed");
6458          ResultSet JavaDoc rsetTypes = stmtTypes.executeQuery(strQueryTypes);
6459          for (int j = 0; j < ( (Vector JavaDoc)this.vecValueMode.get(i)).size(); j++) {
6460            iColumn++;
6461            if (this.iTargetFirstColumnResult == 1)
6462              vecVektor.add(rsetTypes.getMetaData().getColumnTypeName(iColumn));
6463            else
6464              vecVektor.add(rsetTypes.getMetaData().getColumnTypeName(iColumn -
6465                  1));
6466          }
6467          for (int j = 0; j < ( (Vector JavaDoc)this.vecRelationKeyColumns.get(i)).size();
6468                       j++) {
6469            iColumn++;
6470            if (this.iTargetFirstColumnResult == 1)
6471              vecKeyTypesRelations.add(rsetTypes.getMetaData().
6472                  getColumnTypeName(iColumn));
6473            else
6474              vecKeyTypesRelations.add(rsetTypes.getMetaData().
6475                  getColumnTypeName(iColumn - 1));
6476          }
6477          rsetTypes.close();
6478        }
6479        stmtTypes.close();
6480        this.vecRelationKeyTypes.setElementAt(vecKeyTypesRelations, i);
6481        this.vecTargetColumnType.add(vecVektor);
6482      }
6483      Statement JavaDoc stmtVariableTypes = connTarget.createStatement();
6484        if (this.configReaderTarget.getMaxRowsSupported()){
6485                    stmtVariableTypes.setMaxRows(1);
6486            }
6487      for (int j = 0; j < this.vecVariableColumnTargetTableName.size(); j++) {
6488        strQueryTypes = "select ";
6489        strQueryTypes += this.vecVariableColumnTargetColumnName.get(j).toString()
6490            + " from ";
6491        strQueryTypes += this.vecVariableColumnTargetTableName.get(j).toString();
6492        ResultSet JavaDoc rsetVariableTypes;
6493        this.logger.write("full",
6494            "\tQuery '" + strQueryTypes + "' will be executed");
6495        rsetVariableTypes = stmtVariableTypes.executeQuery(strQueryTypes);
6496        if (this.iTargetFirstColumnResult == 1)
6497          this.vecVariableColumnTypes.add(rsetVariableTypes.getMetaData().
6498              getColumnTypeName(1));
6499        else
6500          this.vecVariableColumnTypes.add(rsetVariableTypes.getMetaData().
6501              getColumnTypeName(0));
6502        rsetVariableTypes.close();
6503      }
6504      stmtVariableTypes.close();
6505    }
6506    catch (SQLException JavaDoc ex) {
6507      throw ex;
6508    }
6509    catch (NullPointerException JavaDoc ex) {
6510      throw ex;
6511    }
6512    this.logger.write("full", "\ttargetColumnTypes method is finished.");
6513  }
6514
6515  /**
6516   * Metod createCurrentDate is used to create current date and time in format that supported by SQL server.
6517   * Format of date : MM-DD-YYYY HH:MM:SS:mmm.
6518   * @return String representation of current date and time.
6519   */

6520  private String JavaDoc createCurrentDate() {
6521    
6522    String JavaDoc strDateTimeFormat=this.configReaderTarget.getDateFormat();
6523    SimpleDateFormat JavaDoc tmpDate=new SimpleDateFormat JavaDoc(strDateTimeFormat);
6524    String JavaDoc strDate=tmpDate.format(new Date JavaDoc(System.currentTimeMillis()));
6525    return strDate;
6526    
6527// int iYear, iMonth, iDate, iHour, iMinute, iSecond, iMillisecond;
6528
// String strDateTime = "";
6529
// Calendar calendar = Calendar.getInstance();
6530
// Date currentDate = new Date();
6531
// calendar.setTime(currentDate);
6532
// iYear = calendar.get(Calendar.YEAR);
6533
// iMonth = calendar.get(Calendar.MONTH) + 1;
6534
// iDate = calendar.get(Calendar.DAY_OF_MONTH);
6535
// iHour = calendar.get(Calendar.HOUR_OF_DAY);
6536
// iMinute = calendar.get(Calendar.MINUTE);
6537
// iSecond = calendar.get(Calendar.SECOND);
6538
// iMillisecond = calendar.get(Calendar.MILLISECOND);
6539
//
6540
// String strMonth;
6541
// String strDate;
6542
// String strSecond;
6543
// String strMinute;
6544
// String strHour;
6545
//
6546
// if (iMonth < 10)
6547
// strMonth = "0" + iMonth;
6548
// else
6549
// strMonth = String.valueOf(iMonth);
6550
//
6551
// if (iDate < 10)
6552
// strDate = "0" + iDate;
6553
// else
6554
// strDate = String.valueOf(iDate);
6555
//
6556
// if (iHour < 10)
6557
// strHour = "0" + iHour;
6558
// else
6559
// strHour = String.valueOf(iHour);
6560
//
6561
// if (iMinute < 10)
6562
// strMinute = "0" + iMinute;
6563
// else
6564
// strMinute = String.valueOf(iMinute);
6565
//
6566
// if (iSecond < 10)
6567
// strSecond = "0" + iSecond;
6568
// else
6569
// strSecond = String.valueOf(iSecond);
6570
//
6571
// strDateTime = iYear + "-" + strMonth + "-" + strDate + " " + strHour + ":" + strMinute + ":" +
6572
// strSecond + "." + iMillisecond;
6573
//
6574
// return strDateTime;
6575
}
6576
6577  /**
6578   * Method constantColumnTypes is used to put types of constant columns into
6579   * global vector sorted in target tables.If there is an error, Exception
6580   * "SQLException" or "NullPointerException" is thrown.
6581   * @param c Connection to target database.
6582   * @throws SQLException Constructs an SQLException object with a reason.
6583       * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
6584   */

6585  private void constantColumnTypes(Connection JavaDoc c) throws SQLException JavaDoc,
6586      NullPointerException JavaDoc {
6587    int iCnt = 0;
6588    this.logger.write("full", "\tconstantColumnTypes method is started.");
6589    try {
6590      for (int i = 0; i < this.iTables; i++) {
6591        Vector JavaDoc vecTempConstantType = new Vector JavaDoc();
6592        Vector JavaDoc vecTempConstantName = new Vector JavaDoc();
6593        String JavaDoc strQuery = "select ";
6594        vecTempConstantName = (Vector JavaDoc)this.vecConstantTargetColumnName.get(i);
6595        if (vecTempConstantName.size() != 0) {
6596          Statement JavaDoc stmtConstant = c.createStatement();
6597          for (int j = 0; j < vecTempConstantName.size(); j++)
6598            strQuery += vecTempConstantName.get(j).toString() +
6599                ", ";
6600          strQuery = strQuery.substring(0, strQuery.length() - 2);
6601          strQuery += " from " + this.vecTableTableName.get(i).toString();
6602          this.logger.write("full",
6603              "\tQuery '" + strQuery + "' will be executed");
6604          ResultSet JavaDoc rsetConstant = stmtConstant.executeQuery(strQuery);
6605          iCnt = vecTempConstantName.size();
6606          for (int k = 0; k < iCnt; k++) {
6607            if (this.iTargetFirstColumnResult == 1)
6608              vecTempConstantType.add(rsetConstant.getMetaData().
6609                  getColumnTypeName(k + 1));
6610            else
6611              vecTempConstantType.add(rsetConstant.getMetaData().
6612                  getColumnTypeName(k));
6613          }
6614          rsetConstant.close();
6615          stmtConstant.close();
6616        }
6617        this.vecConstantColumnType.setElementAt(vecTempConstantType, i);
6618      }
6619    }
6620    catch (SQLException JavaDoc ex) {
6621      throw ex;
6622    }
6623    catch (NullPointerException JavaDoc ex) {
6624      throw ex;
6625    }
6626    this.logger.write("full", "\tconstantColumnTypes method is finished.");
6627  }
6628
6629  /**
6630   * Method inputUser is used to give a user the possibility to connect to
6631   * Source and Target database using user name and password.
6632   * If missing, user and password parameters for database in XML file,
6633   * Loader asks user for these parameters.
6634   * If there is an error, Exception "IOException" is thrown.
6635   * @param b Boolean type. If b is true- source database, false- target database
6636   * @throws IOException Constructs an IOException with the specified detail message.
6637   */

6638  private void inputUser(boolean b) throws java.io.IOException JavaDoc {
6639    if (b) {
6640      if (BufferOctopusClass.getInstance().IsUsed())
6641        throw new IOException JavaDoc(
6642            "Missing user name and password for the Source DB. Check LoaderJob.olj file!");
6643      else
6644        this.logger.write("normal",
6645            "Missing user name and password for the Source DB.");
6646    } else {
6647      if (BufferOctopusClass.getInstance().IsUsed())
6648        throw new IOException JavaDoc(
6649            "Missing user name and password for the Target DB. Check LoaderJob.olj file!");
6650      else
6651        this.logger.write("normal",
6652            "Missing user name and password for the Target DB.");
6653    }
6654    String JavaDoc strUserName;
6655    String JavaDoc strPassword;
6656    char cu;
6657    char cp;
6658    StringBuffer JavaDoc bufu = new StringBuffer JavaDoc();
6659    StringBuffer JavaDoc bufp = new StringBuffer JavaDoc();
6660    System.out.println("User name: ");
6661    try {
6662      while ( (cu = (char)System.in.read()) != '\n')
6663        bufu.append(cu);
6664      strUserName = bufu.toString();
6665      strUserName = strUserName.substring(0, strUserName.length() - 1);
6666      System.out.println("Password: ");
6667      while ( (cp = (char)System.in.read()) != '\n')
6668        bufp.append(cp);
6669      strPassword = bufp.toString();
6670      if (strPassword.length() != 0)
6671        strPassword = strPassword.substring(0, strPassword.length() - 1);
6672      if (b) {
6673        jdbcParametersElement.setJDBCSourceParameterUser(strUserName);
6674        jdbcParametersElement.setJDBCSourceParameterPassword(strPassword);
6675      } else {
6676        jdbcParametersElement.setJDBCTargetParameterUser(strUserName);
6677        jdbcParametersElement.setJDBCTargetParameterPassword(strPassword);
6678      }
6679    }
6680    catch (IOException JavaDoc ex) {
6681      throw ex;
6682    }
6683  }
6684
6685  /**
6686   * Method changeTableOrder change order of Tables into public Vector vecTableTableName
6687   * Relation source tables puts before the others target tables.
6688   */

6689  private void changeTableOrder() {
6690    Vector JavaDoc vecTempTableTableName = new Vector JavaDoc();
6691    Vector JavaDoc vecTempTableTableID = new Vector JavaDoc();
6692    Vector JavaDoc vecTempTableInsert = new Vector JavaDoc();
6693    Vector JavaDoc vecTempTableTableMode = new Vector JavaDoc();
6694    Vector JavaDoc vecTempTableOidLogic = new Vector JavaDoc();
6695    Vector JavaDoc vecNumberOfTable = new Vector JavaDoc();
6696    for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
6697      int iNumberOfTable = 0;
6698      for (int j = 0; j < this.vecTableTableName.size(); j++) {
6699        if (this.vecTableTableName.get(j).toString().equalsIgnoreCase(this.
6700            vecRelationColumnSourceTableName.get(i).toString())
6701            &&
6702            this.vecTableTableID.get(j).toString().equalsIgnoreCase(this.
6703            vecRelationColumnSourceTableID.
6704            get(i).toString())) {
6705          iNumberOfTable = j;
6706          boolean bEqualsRelationSource = false;
6707          for (int k = 0; k < vecNumberOfTable.size(); k++) {
6708            if (j == (new Integer JavaDoc(vecNumberOfTable.get(k).toString())).intValue())
6709              bEqualsRelationSource = true;
6710          }
6711          if (!bEqualsRelationSource) {
6712            vecTempTableTableName.addElement(this.vecTableTableName.get(j).
6713                toString());
6714            vecTempTableTableID.addElement(this.vecTableTableID.get(j).toString());
6715            vecTempTableInsert.addElement(this.vecTableInsert.get(j).toString());
6716            vecTempTableTableMode.addElement(this.vecTableTableMode.get(j).
6717                toString());
6718            vecTempTableOidLogic.addElement(this.vecTableOidLogic.get(j).
6719                toString());
6720            vecNumberOfTable.addElement(new Integer JavaDoc(iNumberOfTable));
6721          }
6722        }
6723      }
6724    }
6725    if (this.vecRelationColumnSourceTableName.size() != 0) {
6726      for (int i = 0; i < this.vecTableTableName.size(); i++) {
6727        boolean bEquals = false;
6728        for (int j = 0; j < vecNumberOfTable.size(); j++) {
6729          if (i == (new Integer JavaDoc(vecNumberOfTable.get(j).toString())).intValue()) {
6730            bEquals = true;
6731          }
6732        }
6733        if (!bEquals) {
6734          vecTempTableTableName.addElement(this.vecTableTableName.get(i).
6735              toString());
6736          vecTempTableTableID.addElement(this.vecTableTableID.get(i).toString());
6737          vecTempTableInsert.addElement(this.vecTableInsert.get(i).toString());
6738          vecTempTableTableMode.addElement(this.vecTableTableMode.get(i).
6739              toString());
6740          vecTempTableOidLogic.addElement(this.vecTableOidLogic.get(i).toString());
6741        }
6742      }
6743      this.vecTableTableName = new Vector JavaDoc();
6744      this.vecTableTableID = new Vector JavaDoc();
6745      this.vecTableInsert = new Vector JavaDoc();
6746      this.vecTableTableMode = new Vector JavaDoc();
6747      this.vecTableOidLogic = new Vector JavaDoc();
6748      for (int i = 0; i < vecTempTableTableName.size(); i++) {
6749        this.vecTableTableName.addElement(vecTempTableTableName.get(i).toString());
6750        this.vecTableTableID.addElement(vecTempTableTableID.get(i).toString());
6751        this.vecTableInsert.addElement(vecTempTableInsert.get(i).toString());
6752        this.vecTableTableMode.addElement(vecTempTableTableMode.get(i).toString());
6753        this.vecTableOidLogic.addElement(vecTempTableOidLogic.get(i).toString());
6754      }
6755    }
6756  }
6757
6758  /**
6759   * Method changeRelationsOrder change order of relation tags.
6760   * Order of relation tags depends of 'complex relations'. Method puts at the begining of relation global Vectors
6761   * relations which is used only to read source values for another relation.
6762   *
6763   */

6764  private void changeRelationsOrder() {
6765    Vector JavaDoc vecTempSourceTableName = new Vector JavaDoc();
6766    Vector JavaDoc vecTempSourceTableID = new Vector JavaDoc();
6767    Vector JavaDoc vecTempSourceColumnName = new Vector JavaDoc();
6768    Vector JavaDoc vecTempTargetTableName = new Vector JavaDoc();
6769    Vector JavaDoc vecTempTargetTableID = new Vector JavaDoc();
6770    Vector JavaDoc vecTempTargetColumnName = new Vector JavaDoc();
6771    Vector JavaDoc vecTempRelationMode = new Vector JavaDoc();
6772    Vector JavaDoc vecRelationsOrder = new Vector JavaDoc();
6773    vecRelationsOrder.setSize(this.vecRelationColumnSourceTableName.size());
6774    for (int i = 0; i < vecRelationsOrder.size(); i++)
6775      vecRelationsOrder.setElementAt(new Integer JavaDoc(i), i);
6776    for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
6777      if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase(
6778          "Key")) {
6779        for (int j = 0; j < this.vecRelationColumnSourceTableName.size(); j++) {
6780          if (this.vecRelationColumnSourceTableName.get(i).toString().
6781              equalsIgnoreCase(this.vecRelationColumnTargetTableName.get(j).
6782              toString())
6783              &&
6784              this.vecRelationColumnSourceTableID.get(i).toString().
6785              equalsIgnoreCase(this.vecRelationColumnTargetTableID.get(j).
6786              toString()))
6787            vecRelationsOrder = this.setAfter(vecRelationsOrder,
6788                                i, j);
6789        }
6790      } else {
6791        vecRelationsOrder = this.setLast(vecRelationsOrder, i);
6792      }
6793    }
6794    for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
6795      vecTempSourceTableName.add(this.vecRelationColumnSourceTableName.get(i));
6796      vecTempSourceTableID.add(this.vecRelationColumnSourceTableID.get(i));
6797      vecTempSourceColumnName.add(this.vecRelationColumnSourceColumnName.get(i));
6798      vecTempTargetTableName.add(this.vecRelationColumnTargetTableName.get(i));
6799      vecTempTargetTableID.add(this.vecRelationColumnTargetTableID.get(i));
6800      vecTempTargetColumnName.add(this.vecRelationColumnTargetColumnName.get(i));
6801      vecTempRelationMode.add(this.vecRelationColumnRelationMode.get(i));
6802    }
6803    for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
6804      this.vecRelationColumnSourceTableName.setElementAt(vecTempSourceTableName.
6805          get(Integer.parseInt(vecRelationsOrder.get(i).toString())),
6806          i);
6807      this.vecRelationColumnSourceTableID.setElementAt(vecTempSourceTableID.get(
6808          Integer.parseInt(vecRelationsOrder.get(i).toString())),
6809          i);
6810      this.vecRelationColumnSourceColumnName.setElementAt(
6811          vecTempSourceColumnName.get(Integer.parseInt(vecRelationsOrder.get(i).
6812          toString())),
6813          i);
6814      this.vecRelationColumnTargetTableName.setElementAt(vecTempTargetTableName.
6815          get(Integer.parseInt(vecRelationsOrder.get(i).toString())),
6816          i);
6817      this.vecRelationColumnTargetTableID.setElementAt(vecTempTargetTableID.get(
6818          Integer.parseInt(vecRelationsOrder.get(i).toString())),
6819          i);
6820      this.vecRelationColumnTargetColumnName.setElementAt(
6821          vecTempTargetColumnName.get(Integer.parseInt(vecRelationsOrder.get(i).
6822          toString())),
6823          i);
6824      this.vecRelationColumnRelationMode.setElementAt(vecTempRelationMode.get(
6825          Integer.parseInt(vecRelationsOrder.get(i).toString())),
6826          i);
6827    }
6828  }
6829
6830  /**
6831   * Method setLast changes order of vecOrder's elements. Element at iRelationTag position will be removed
6832   * and inserted at the end of Vector.
6833   * @param vecOrder Vector - order of relation tags
6834   * @param iRelationTag integer - position of element in Vector which changes its position.
6835   * @return Vector - order of relation tags after changing positions of elements.
6836   */

6837  private Vector JavaDoc setLast(Vector JavaDoc vecOrder, int iRelationTag) {
6838    int iLast = vecOrder.indexOf(new Integer JavaDoc(iRelationTag));
6839    vecOrder.remove(iLast);
6840    vecOrder.add(new Integer JavaDoc(iRelationTag));
6841    return vecOrder;
6842  }
6843
6844  /**
6845   * Method setAfter changes order of vecOrder's elements. Element at iIndexCurrent position will be removed
6846   * and inserted after element at iIndexTarget position.
6847   * @param vecOrder Vector - order of relation tags
6848   * @param iIndexCurrent integer - position of element in Vector which changes its position.
6849   * @param iIndexTarget integer - position of 'target' element in Vector .
6850   * @return Vector - order of relation tags after changing element's positions.
6851   */

6852  Vector JavaDoc setAfter(Vector JavaDoc vecOrder, int iIndexCurrent, int iIndexTarget) {
6853    if (iIndexCurrent < iIndexTarget) {
6854      int iCurrent = vecOrder.indexOf(new Integer JavaDoc(iIndexCurrent));
6855      vecOrder.remove(iCurrent);
6856      int iTarget = vecOrder.indexOf(new Integer JavaDoc(iIndexTarget));
6857      vecOrder.insertElementAt(new Integer JavaDoc(iIndexCurrent), iTarget +
6858          1);
6859    }
6860    return vecOrder;
6861  }
6862
6863  /**
6864   * Method executeSQLStatement is used to execute SQL statement. This method
6865   * executes and commit changes immediately. JDBC parameters, Continue on Error parameters
6866   * and SQL statements are set in XML file.
6867   * If there is an error Exception "Exception" is thrown.
6868   * @throws Exception
6869   */

6870  private void executeSQLStatement() throws Exception JavaDoc {
6871    Connection JavaDoc conn = null;
6872    try {
6873      this.logger.write("full", "\tmethod executeSQLStatement is started");
6874// this.logger.write("normal", "SQL statement " + this.strSqlName +
6875
// " is started");
6876
Class.forName(jdbcParametersElement.getJDBCTargetParameterDriver());
6877      conn = DriverManager.getConnection(jdbcParametersElement.
6878             getJDBCTargetParameterConnection(),
6879             jdbcParametersElement.
6880             getJDBCTargetParameterUser(),
6881             jdbcParametersElement.
6882             getJDBCTargetParameterPassword());
6883      Statement JavaDoc stmtSeparate = conn.createStatement();
6884      for (int i = 0; i < this.vecSqlStmt.size(); i++) {
6885        this.logger.write("full", "\tSQL_stmt : '" + this.vecSqlStmt.get(i).toString()
6886            + "' will be executed");
6887        Vector JavaDoc vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt.get(i).toString());
6888        for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
6889          executeSql(stmtSeparate, vecSingleSqlStmt.get(j).toString(), 0);
6890        }
6891      }
6892      stmtSeparate.close();
6893      conn.close();
6894    }
6895    catch (SQLException JavaDoc e) {
6896      throw e;
6897    }
6898    finally {
6899      if (conn != null && !conn.isClosed())
6900        conn.close();
6901    }
6902  }
6903
6904  /**
6905   * Method executeSQLStatement is used to execute SQL statement. This method
6906   * commit changes immediately only if is commit paremeter true. If it is false commit changes after all aql stetements.
6907   * JDBC parameters, Continue on Error parameters
6908   * and SQL statements are set in XML file.
6909   * If there is an error Exception "Exception" is thrown.
6910   * @param conn represents connection to target table
6911   * @throws Exception
6912   */

6913  private void executeSQLStatement(Connection JavaDoc conn) throws Exception JavaDoc {
6914    try {
6915      this.timeCounter.setStartJobTime();
6916      this.logger.write("full", "\tmethod executeSQLStatement is started");
6917      this.logger.write("normal", "SQL statement " + sqlElement.getSqlName() +
6918          " is started");
6919      boolean isCreateDatabaseStatement = false;
6920      out:
6921          for (int i = 0; i < this.vecSqlStmt.size(); i++) {
6922        if (this.vecSqlStmt.get(i).toString().toUpperCase().trim().startsWith(
6923            "CREATE DATABASE") ||
6924            this.vecSqlStmt.get(i).toString().toUpperCase().trim().startsWith(
6925            "DROP DATABASE")) {
6926          isCreateDatabaseStatement = true;
6927          break out;
6928        }
6929      }
6930      if (isCreateDatabaseStatement) {
6931        executeSQLStatement();
6932      } else {
6933
6934        Statement JavaDoc stmtSeparate = conn.createStatement();
6935        for (int i = 0; i < this.vecSqlStmt.size(); i++) {
6936          this.logger.write("full", "\tSQL_stmt : '" + this.vecSqlStmt.get(i).toString()
6937              + "' will be executed");
6938          Vector JavaDoc vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt.get(i).toString());
6939          for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
6940            executeSql(stmtSeparate, vecSingleSqlStmt.get(j).toString(), j + 1);
6941          }
6942        }
6943        if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) {
6944          if (!conn.getAutoCommit())
6945            conn.commit();
6946        }
6947        stmtSeparate.close();
6948      }
6949
6950      this.logger.write("normal", "SQL statement " + sqlElement.getSqlName() + " is finished");
6951      this.logger.write("full", "\tmethod executeSQLStatement is finished");
6952      this.logger.write("normal", " Duration :" + this.timeCounter.getJobTime());
6953    }
6954    catch (SQLException JavaDoc e) {
6955      throw e;
6956    }
6957  }
6958
6959  /**
6960   * Method sqlStringToVector is used to cut Sql string with number of statements
6961   * into vector whose elements are single Sql statemnets.
6962   * @param sql Sql string with number of statements.
6963   * @return vector of sql statemetns
6964   */

6965  private Vector JavaDoc sqlStringToVector(String JavaDoc sql) {
6966    Vector JavaDoc vecSqlString = new Vector JavaDoc();
6967    int i = sql.indexOf(";");
6968    if (i != -1) {
6969      while (i != -1) {
6970        //vecSqlString.add(sql.substring(0, i + 1));
6971
vecSqlString.add(sql.substring(0, i));
6972        sql = sql.substring(i + 1);
6973        i = sql.indexOf(";");
6974      }
6975    } else
6976
6977      //vecSqlString.add(sql.trim() + ";");
6978
vecSqlString.add(sql.trim());
6979    return vecSqlString;
6980  }
6981
6982  /**
6983   * Method executeSql is used to execute singl Sql statement. If there is an error
6984   * depends on OnErrorContinue parameter throws exception or not. Error message is
6985   * always shown. If there is an error, message with the error message,
6986   * statement and number of statement is shown.
6987   * @param stmtSql Statement.
6988   * @param sqlStmt Sql statement to execute.
6989   * @param i Number of the Sql statement.
6990   * @throws SQLException
6991   */

6992  private void executeSql(Statement JavaDoc stmtSql, String JavaDoc sqlStmt, int i) throws
6993      SQLException JavaDoc {
6994    try {
6995      if (bReplaceInData) {
6996        sqlStmt = this.replaceInData(sqlStmt);
6997      }
6998      sqlStmt.trim();
6999      if (sqlStmt.length() != 0)
7000        stmtSql.execute(sqlStmt);
7001    }
7002    catch (SQLException JavaDoc e) {
7003      if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase("true")) {
7004        if (sqlElement.getSqlCommit().equalsIgnoreCase("true"))
7005          this.logger.write("normal", "\t Error in SQL statement: " + sqlStmt +
7006              " executing SQL statements continue...");
7007        else
7008          this.logger.write("normal", "\t Error in SQL statement: " + sqlStmt +
7009              " \n\tStatement is number: " + i
7010              + " all statements before it is not commited, executing SQL statements continue...");
7011        LoaderException le = new LoaderException("SQLException: ",
7012                             (Throwable JavaDoc)e);
7013                this.logger.write("full", le.getStackTraceAsString());
7014        //this.logger.write("normal", "\t " + e.getMessage());
7015
} else {
7016        this.logger.write("normal", "\t Error in SQL statement: " + sqlStmt);
7017        throw e;
7018      }
7019    }
7020  }
7021
7022  /**
7023   * Method checkSortColumns checks if sort columns in source table have unique values.
7024       * If source table have more rows with equal values in sort columns return true, if not return false.
7025   * @param connSource - Connection to the source table.
7026   * @return boolean - true - source table has more rows with equal values in sort columns,
7027   * false - if source table has unique values in sort columns.
7028   * @throws LoaderException with the specified detail message.
7029   */

7030  private boolean checkSortColumns(Connection JavaDoc connSource) throws
7031      LoaderException {
7032    boolean isEqualValues = false;
7033    String JavaDoc strQuery = "select ";
7034    try {
7035      this.logger.write("full", "\tmethod checkSortColumns is started");
7036      for (int i = 0;
7037                   i < importDefinitionElement.vecRestartCounterSortColumn.size(); i++)
7038        strQuery += importDefinitionElement.vecRestartCounterSortColumn.get(i).
7039            toString()
7040            + ",";
7041      strQuery = strQuery.substring(0, strQuery.length() - 1);
7042      strQuery += " from " +
7043          importDefinitionElement.strImportDefinitionTableName;
7044      strQuery += " order by ";
7045      for (int j = 0;
7046                   j < importDefinitionElement.vecRestartCounterSortColumn.size(); j++)
7047        strQuery += importDefinitionElement.vecRestartCounterSortColumn.get(j).
7048            toString()
7049            + ", ";
7050      strQuery = strQuery.substring(0, strQuery.length() - 2);
7051      this.logger.write("full", "\tQuery '" + strQuery + "' executes");
7052      Statement JavaDoc stmtSort = connSource.createStatement();
7053      ResultSet JavaDoc rsetSort = stmtSort.executeQuery(strQuery);
7054      endWhile:while (rsetSort.next()) {
7055        Vector JavaDoc vecSortNewValues = new Vector JavaDoc();
7056        for (int i = 0;
7057                     i < importDefinitionElement.vecRestartCounterSortColumn.size(); i++)
7058          vecSortNewValues.add(rsetSort.getString(i + 1));
7059        if (vecSortNewValues.equals(this.vecSortValues)) {
7060          isEqualValues = true;
7061          break endWhile;
7062        } else {
7063          this.vecSortValues = new Vector JavaDoc();
7064          for (int i = 0;
7065                       i < importDefinitionElement.vecRestartCounterSortColumn.size();
7066                       i++)
7067            this.vecSortValues.add(vecSortNewValues.get(i));
7068        }
7069      }
7070      rsetSort.close();
7071      stmtSort.close();
7072    }
7073    catch (SQLException JavaDoc e) {
7074      LoaderException le = new LoaderException("SQLException: ", (Throwable JavaDoc)e);
7075      //this.logger.write("normal", le.getCause().toString());
7076
this.logger.write("full", le.getStackTraceAsString());
7077      throw le;
7078    }
7079    this.logger.write("full", "\tmethod checkSortColumns is finished");
7080    return isEqualValues;
7081  }
7082
7083  /**
7084   * put your documentation comment here
7085   * @param conn represents connection
7086   * @exception LoaderException
7087   */

7088  private void createObjectIDTable(Connection JavaDoc conn) throws LoaderException {
7089    try {
7090      Statement JavaDoc stmt = conn.createStatement();
7091      String JavaDoc sqlStmt = "";
7092      if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") ||
7093          importDefinitionElement.strObjectIDNameColumnValue.equals(""))) {
7094        sqlStmt = "create table " +
7095                  importDefinitionElement.strObjectIDTableName +
7096                  " (" + importDefinitionElement.strObjectIDColumnName +
7097                  " VARCHAR(30) ,"
7098                  + importDefinitionElement.strObjectIDNameColumnName +
7099                  " VARCHAR(30)) NOT NULL;";
7100
7101      } else {
7102        sqlStmt = "create table " +
7103                  importDefinitionElement.strObjectIDTableName +
7104                  " (" + importDefinitionElement.strObjectIDColumnName +
7105                  " DECIMAL(19,0) NOT NULL);";
7106      }
7107      stmt.execute(sqlStmt);
7108      String JavaDoc insert = "";
7109      if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") ||
7110          importDefinitionElement.strObjectIDNameColumnValue.equals(""))) {
7111        insert = "insert " + importDefinitionElement.strObjectIDTableName +
7112                 " (" +
7113                 importDefinitionElement.strObjectIDNameColumnName + "," +
7114                 importDefinitionElement.strObjectIDColumnName + ") values ('" +
7115                 importDefinitionElement.strObjectIDNameColumnValue
7116                 + "','" + importDefinitionElement.iObjectIDStartValue + "');";
7117      } else {
7118        insert = "insert " + importDefinitionElement.strObjectIDTableName +
7119                 " (" +
7120                 importDefinitionElement.strObjectIDColumnName + ") values (" +
7121                 importDefinitionElement.iObjectIDStartValue
7122                 + ");";
7123      }
7124      if (bReplaceInData) {
7125        insert = this.replaceInData(insert);
7126      }
7127      stmt.execute(insert);
7128      conn.commit();
7129      stmt.close();
7130    }
7131    catch (SQLException JavaDoc e) {
7132      LoaderException le = new LoaderException("SQLException: ", (Throwable JavaDoc)e);
7133      //this.logger.write("normal", le.getCause().toString());
7134
this.logger.write("full", le.getStackTraceAsString());
7135      throw le;
7136    }
7137  }
7138
7139  /**
7140   * put your documentation comment here
7141   * @param values represents map values
7142   * @return those values
7143   */

7144  private static Map JavaDoc convertToMap(String JavaDoc values) {
7145    Map JavaDoc mapValues = new HashMap JavaDoc();
7146    int i = values.indexOf(";");
7147    int k = 0;
7148    String JavaDoc part = new String JavaDoc(values);
7149    if (i != -1) {
7150      while (i != -1) {
7151        part = new String JavaDoc(values.substring(k, k + i));
7152        int j = part.indexOf("=");
7153        String JavaDoc strObject = part.substring(0, j);
7154        String JavaDoc strValue = part.substring(j + 1);
7155        if (strValue.equals(""))
7156          strValue = null;
7157        mapValues.put(strObject, strValue);
7158        k += i + 1;
7159        i = values.substring(k).indexOf(";");
7160      }
7161      if (! (values.substring(k).trim().equals("") ||
7162          values.substring(k).trim().equals(";"))) {
7163        part = new String JavaDoc(values.substring(k));
7164        int j = part.indexOf("=");
7165        String JavaDoc strObject = part.substring(0, j);
7166        String JavaDoc strValue = part.substring(j + 1);
7167        if (strValue.equals(""))
7168          strValue = null;
7169        mapValues.put(strObject, strValue);
7170      }
7171    } else {
7172      int j = values.indexOf("=");
7173      String JavaDoc strObject = values.substring(k, j);
7174      String JavaDoc strValue = values.substring(j + 1);
7175      if (strValue.equals(""))
7176        strValue = null;
7177      mapValues.put(strObject, strValue);
7178    }
7179    return mapValues;
7180  }
7181
7182  /**
7183   * Method replaceInData replace data in string if there is the same variable as
7184   * in attribut prefix+name+suffix in variable tag.
7185   * @param s - String to replace.
7186   * @return s
7187   */

7188  private String JavaDoc replaceInData(String JavaDoc s) {
7189    // going throw vector
7190
for (int k = 0; k < this.vecReplaceInData.size(); k++) {
7191      // if this is to change...
7192
if (this.vecReplaceInData.get(k).toString().equalsIgnoreCase("true")) {
7193        String JavaDoc sPreNameSu = this.vecVariablePrefix.get(k).toString()
7194                            + this.vecVariableName.get(k).toString() +
7195                            this.vecVariableSufix.get(k).toString();
7196        int j = s.indexOf(sPreNameSu);
7197        // if costant is variable
7198
while (j != -1) {
7199          s = s.substring(0, j) + this.vecVariableValue.get(k).toString()
7200              + s.substring(j + sPreNameSu.length(), s.length());
7201          j = s.indexOf(sPreNameSu);
7202        }
7203      }
7204    }
7205    return s;
7206  }
7207  
7208  /**
7209     * Method replaceInSelectStatement replace data in string if there is the same variable as
7210     * in attribut prefix+name+suffix in variable tag.
7211     * @param s - String to replace.
7212     * @return s
7213     */

7214// private String replaceInSelectStatement(String s) {
7215
// // going throw vector
7216
// for (int k = 0; k < this.vecVariableValue.size(); k++) {
7217
// if( this.vecReplaceInSQL.get(k).toString().equalsIgnoreCase("false"))
7218
// continue;
7219
// String sPreNameSu = this.vecVariablePrefix.get(k).toString()
7220
// + this.vecVariableName.get(k).toString() +
7221
// this.vecVariableSufix.get(k).toString();
7222
// int j = s.indexOf(sPreNameSu);
7223
//
7224
// while (j != -1) {
7225
// s = s.substring(0, j) + this.vecVariableValue.get(k).toString()
7226
// + s.substring(j + sPreNameSu.length(), s.length());
7227
// j = s.indexOf(sPreNameSu);
7228
// }
7229
// }
7230
// return s;
7231
// }
7232

7233  /**
7234   * @param s - String to replace.
7235   * @param oldChar - Char
7236   * @param newValue - String
7237   * @return s
7238   */

7239  private String JavaDoc replaceChar(String JavaDoc s, char oldChar, String JavaDoc newValue) {
7240
7241    int j = s.indexOf(oldChar);
7242    String JavaDoc replacedString = "";
7243    while (j != -1) {
7244      replacedString = replacedString + s.substring(0, j) + newValue;
7245      s = s.substring(j + 1);
7246      j = s.indexOf(oldChar);
7247    }
7248    replacedString = replacedString + s;
7249    return replacedString;
7250  }
7251
7252  /**
7253   * Method resetGlobalVariables reset all global variables to the start values
7254   * after each importDefinition job.
7255   */

7256  private void resetGlobalVariables() {
7257    importDefinitionElement.strImportDefinitionName = "";
7258    importDefinitionElement.strImportDefinitionTableName = "";
7259    importDefinitionElement.iImportDefinitionCommitCount = 0;
7260    //importDefinitionElement.strImportDefinitionLogMode = "normal";
7261
importDefinitionElement.strImportDefinitionSelectStatement = "";
7262    importDefinitionElement.bObjectIDAutoCreate = loaderJobReader.
7263                                                  getDefaultObjectIDAutoCreate();
7264    importDefinitionElement.iObjectIDStartValue = loaderJobReader.
7265                                                  getDefaultObjectIDStartValue();
7266
7267    importDefinitionElement.vecRestartCounterSortColumn = new Vector JavaDoc();
7268    this.iValueColumns = 0;
7269    this.vecValueColumnsTargetTables = new Vector JavaDoc();
7270     //this.vecTransformColumnsTargetTables = new Vector();
7271
this.vecSourceColumnName = new Vector JavaDoc();
7272    this.vecTargetColumnName = new Vector JavaDoc();
7273    this.vecValueMode = new Vector JavaDoc();
7274    this.vecTargetColumnValue = new Vector JavaDoc();
7275    this.vecTargetKeyColumnName = new Vector JavaDoc();
7276    this.iConstantColumns = 0;
7277    this.vecConstantTargetColumnName = new Vector JavaDoc();
7278    this.vecConstantValueMode = new Vector JavaDoc();
7279    this.vecConstantConstantValue = new Vector JavaDoc();
7280    this.vecConstantColumnTargetTableName = new Vector JavaDoc();
7281    this.vecConstantColumnTargetTableID = new Vector JavaDoc();
7282    this.iRelationColumns = 0;
7283    this.vecRelationColumnSourceTableName = new Vector JavaDoc();
7284    this.vecRelationColumnSourceTableID = new Vector JavaDoc();
7285    this.vecRelationColumnSourceColumnName = new Vector JavaDoc();
7286    this.vecRelationColumnTargetTableName = new Vector JavaDoc();
7287    this.vecRelationColumnTargetColumnName = new Vector JavaDoc();
7288    this.vecRelationColumnTargetTableID = new Vector JavaDoc();
7289    this.vecRelationColumnRelationMode = new Vector JavaDoc();
7290    this.iTables = 0;
7291    this.vecTableTableName = new Vector JavaDoc();
7292    this.vecTableTableID = new Vector JavaDoc();
7293    this.vecTableInsert = new Vector JavaDoc();
7294    this.vecTableTableMode = new Vector JavaDoc();
7295    this.vecTableOidLogic = new Vector JavaDoc();
7296    this.vecRelationSourceValue = new Vector JavaDoc();
7297    this.vecRelationSourceType = new Vector JavaDoc();
7298    this.vecTargetColumnType = new Vector JavaDoc();
7299    this.vecConstantColumnType = new Vector JavaDoc();
7300    this.bdecOidNumber = new BigDecimal JavaDoc(0);
7301    this.bdecOidNumber2000 = new BigDecimal JavaDoc(0);
7302    importDefinitionElement.iObjectID = 0;
7303    importDefinitionElement.iObjectIDCT = 0;
7304    importDefinitionElement.strObjectIDTableName = "";
7305    importDefinitionElement.strObjectIDColumnName = "";
7306// TOS
7307
importDefinitionElement.strObjectIDNameColumnName = "";
7308    importDefinitionElement.strObjectIDNameColumnValue = "";
7309
7310    this.vecVariableUseIDTableName = new Vector JavaDoc();
7311    this.vecVariableUseIDTableID = new Vector JavaDoc();
7312    this.vecVariableUseIDColumnName = new Vector JavaDoc();
7313    this.vecVariableUseIDValueMode = new Vector JavaDoc();
7314    this.vecVariableColumnName = new Vector JavaDoc();
7315    this.vecVariableColumnTargetTableName = new Vector JavaDoc();
7316    this.vecVariableColumnTargetTableID = new Vector JavaDoc();
7317    this.vecVariableColumnTargetColumnName = new Vector JavaDoc();
7318    this.vecVariableColumnValueMode = new Vector JavaDoc();
7319    this.vecVariableColumnTypes = new Vector JavaDoc();
7320    this.vecVariableTimesTableName = new Vector JavaDoc();
7321    this.vecVariableTimesTableID = new Vector JavaDoc();
7322    this.vecVariableTimesColumnName = new Vector JavaDoc();
7323    this.vecVariableTimesValueMode = new Vector JavaDoc();
7324    this.vecRelationKeyColumns = new Vector JavaDoc();
7325    this.vecRelationKeyTypes = new Vector JavaDoc();
7326    this.vecSortValues = new Vector JavaDoc();
7327    this.vecSqlStmt = new Vector JavaDoc();
7328    this.strSourceDriverName = "";
7329    this.strTargetDriverName = "";
7330    this.iFirstColumnResult = 1;
7331    this.iTargetFirstColumnResult = 1;
7332    this.iColumnsInSourceTable = 0;
7333// copy table
7334
this.vecCTAutoMapp = new Vector JavaDoc();
7335    this.vecCTDefaultMode = new Vector JavaDoc();
7336    this.vecBlobVector = new Vector JavaDoc();
7337//added for transformations
7338
this.transformationsColumnNames = new Vector JavaDoc();
7339        this.indexDTransformationOver = new Hashtable JavaDoc();
7340        this.indexDTransformationNull = new Hashtable JavaDoc();
7341        this.transformationsValueModes = new Vector JavaDoc();
7342        this.transformationsColumnTypes = new Vector JavaDoc();
7343        this.transformationValues = new Vector JavaDoc();
7344        
7345  }
7346
7347  private String JavaDoc replaceFirst(String JavaDoc input, String JavaDoc forReplace,
7348      String JavaDoc replaceWith) {
7349    String JavaDoc retVal = input;
7350    int start = input.indexOf(forReplace);
7351    int end = start + forReplace.length();
7352    if (start != -1) {
7353      retVal = input.substring(0, start) + replaceWith + input.substring(end);
7354    }
7355    return retVal;
7356  }
7357  /**
7358   * This method write values for all input parameters to log file when log level is full
7359   * @throws LoaderException
7360   */

7361  public String JavaDoc inputToString() throws LoaderException{
7362      String JavaDoc resString = "";
7363      try {
7364          logger.write("full","Log mode ="+getDefaultLogMode());
7365          logger.write("full","Restart indicator ="+getRestartIndicator());
7366          logger.write("full","UserID ="+getUserID());
7367          Hashtable JavaDoc resHashtable = new Hashtable JavaDoc();
7368          resHashtable = (Hashtable JavaDoc)getVariableValues();
7369          String JavaDoc pom2 ="";
7370          
7371          if (resHashtable != null){
7372            logger.write("full","Variables ="+resHashtable.toString());
7373            pom2 = "Variables ="+resHashtable.toString();
7374          }else{
7375            logger.write("full","Variables = null");
7376            pom2 = "Variables = null";
7377          }
7378          logger.write("full","Log directory ="+getLogDirName());
7379          logger.write("full","Log file name ="+getLogFileName());
7380          logger.write("full","LoadJob file name ="+getLoadJobFileName());
7381          logger.write("full","On error continue ="+getOnErrorContinue());
7382          logger.write("full","Commit count ="+getCommitCount());
7383          logger.write("full","Return code ="+getDefaultReturnCode());
7384          logger.write("full","Vendor conf file ="+getVendorFileName());
7385        
7386          logger.write("full","Include list =");
7387          String JavaDoc pom1="";
7388          pom1 = "Include list =";
7389          String JavaDoc[] listOfJobs = getIncludedJobs();
7390          for (int j=0; j < listOfJobs.length;j++){
7391            logger.write("full",listOfJobs[j].toString());
7392            pom1 +=listOfJobs[j].toString()+"\n";
7393          }
7394          logger.write("full","Path to conf files in jar ="+getConfJarStructure());
7395          logger.write("full","Additional paths ="+getAdditionalPaths());
7396          resString = "Log mode ="+getDefaultLogMode()+"\n"+
7397                    "Restart indicator ="+getRestartIndicator()+"\n"+
7398                    "UserID ="+getUserID()+"\n"
7399                    +pom2+"\n"+
7400                    "Log directory ="+getLogDirName()+"\n"+
7401                    "Log file name ="+getLogFileName()+"\n"+
7402                    "LoadJob file name ="+getLoadJobFileName()+"\n"+
7403                    "On error continue ="+getOnErrorContinue()+"\n"+
7404                    "Commit count ="+getCommitCount()+"\n"+
7405                    "Return code ="+getDefaultReturnCode()+"\n"+
7406                    "Vendor conf file ="+getVendorFileName()+"\n"+pom1+"\n"+
7407                    "Path to conf files in jar ="+getConfJarStructure()+"\n"+
7408                    "Additional paths ="+getAdditionalPaths()+"\n";
7409                    
7410        
7411        return resString;
7412    } catch (Exception JavaDoc e) {
7413        
7414        LoaderException le = new LoaderException("Exception:"+e.getMessage(),e);
7415        this.logger.write("full", le.getStackTraceAsString());
7416        throw le;
7417    }
7418      
7419  }
7420  
7421    
7422}
7423
Popular Tags