1 /*
2
3 Loader - tool for transfering data from one JDBC source to another and
4 doing transformations during copy.
5
6 Copyright (C) 2002-2003 Together
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Loader.java
23 Date: 03.03.2003.
24 @version 2.1 alpha
25 @authors:
26 Milosevic Sinisa sinisami@eunet.yu
27 Radeka Dusan diradeka@neobee.net
28 Radeka Dragan dradeka@eunet.yu
29 */
30
31 package org.webdocwf.util.loader;
32
33 import java.io.PrintWriter;
34 import java.io.File;
35 import java.io.FileReader;
36 import java.io.FileWriter;
37 import java.io.BufferedReader;
38 import java.io.BufferedWriter;
39 import org.xml.sax.helpers.XMLReaderFactory;
40 import org.xml.sax.XMLReader;
41 import java.io.ByteArrayOutputStream;
42 import java.io.ObjectOutputStream;
43 import java.io.ByteArrayInputStream;
44 import java.io.InputStream;
45 import java.io.RandomAccessFile;
46 import org.xml.sax.InputSource;
47 import org.w3c.dom.Document;
48 import org.w3c.dom.DocumentFragment;
49 import org.w3c.dom.NamedNodeMap;
50 import org.w3c.dom.Node;
51 import org.w3c.dom.NodeList;
52 import org.w3c.dom.Element;
53 import javax.xml.parsers.DocumentBuilder;
54 import javax.xml.parsers.DocumentBuilderFactory;
55 import org.xml.sax.SAXException;
56 import java.lang.Integer;
57 import java.util.Vector;
58 import java.util.Date;
59 import java.util.Calendar;
60 import java.util.Map;
61 import java.util.HashMap;
62 import java.util.Hashtable;
63 import java.sql.*;
64 import java.lang.Object;
65 import java.math.BigDecimal;
66 import java.text.DateFormat;
67 import java.io.IOException;
68 import java.io.FileNotFoundException;
69 import java.io.InterruptedIOException;
70 import org.webdocwf.util.loader.LoaderException;
71 import org.webdocwf.util.loader.LoaderXIncluder;
72
73
74 /***
75 * <p>
76 * Loader class loads data from source database into target database using criteria
77 * set in XML file which is used as parameter. Also Loader can execute SQL statements
78 * which import from XML file. <br>
79 * All loading rolls are set in XML file. Some capabilities of this loader are:
80 * there could be more then one importDefinition and number of them is not limited, source
81 * and target database could be different, source database could be ASCII,Excel or Access file too,
82 * operator (the person or application which starts Loader) have to define.
83 * Restart mode with second parameter (optional).
84 * </p>
85 * <p>
86 * There are two possible ways to start Loader. The first is as stand alone application,
87 * the sintaxs is: <br>
88 * <code><B>java org.webdocwf.util.loader.Loader [-options] urlOfTheXmlFile.xml</B></code> <br>
89 * urlOfTheXmlFile.xml is URL of the XML file with loading criteria,<br>
90 * </p>
91 * <p>
92 * The second way is to start Loader as package, the sintax is:<br>
93 * <code><B>public Loader(String loadJobFileName, String mode, String userID, String logDirName,
94 * String logFileName, boolean restartIndicator, Map variableValues, String vendorFileName,
95 * boolean onErrorContinue, String additionalPaths, int commitCount, int returnCode) ;</code><br>
96 * ldr.load();</B>
97 * <br>
98 * If we want to execute Loader class without last for parameters, we must put null as these arguments
99 * </p>
100 * <p>
101 * When the Loader is started the log file is generated. Log file is txt file and its
102 * name defines date and time when the Loader is started. There are three Log modes:
103 * none - report only begining and finishing the application, and exceptions if there
104 * are any, normal - add to log importing blocks and full - with detailed report to
105 * operator.
106 * </p>
107 * <p>
108 * Another big adventage of Loader is its possibility to execute any SQL statements in target database.
109 * (creating database; creating, modifying and deleting tables...)
110 * </p>
111 * <p>
112 * XML file the key part for loading criteria. XML tags define how the loading job will
113 * be done.
114 * </p>
115 */
116 public class Loader {
117 String strImportDefinitionName = "";
118 String strImportDefinitionTableName = "";
119 int iImportDefinitionCommitCount;
120 String strImportDefinitionLogMode = "normal";
121 String strImportDefinitionSelectStatement = "";
122 String strRestartCounterTableName = "";
123 String strRestartCounterImportDefinitionName = "";
124 String strRestartCounterValue = "";
125 boolean bRestartAutoCreate = false;
126 Vector vecRestartCounterSortColumn = new Vector();
127 String strDbVendor = "";
128 String strTargetDbVendor = "";
129 String strDbVendorDefault = "";
130 String strTargetDbVendorDefault = "";
131 String strTargetDriverNameDefault = "";
132 String strDriverNameDefault = "";
133 String strJDBCSourceParameterDriver = "";
134 String strJDBCTargetParameterDriver = "";
135 String strJDBCSourceParameterConnection = "";
136 String strJDBCTargetParameterConnection = "";
137 String strJDBCSourceParameterUser = "";
138 String strJDBCTargetParameterUser = "";
139 String strJDBCSourceParameterPassword = "";
140 String strJDBCTargetParameterPassword = "";
141 String strJDBCDefaultSourceParameterDriver = "";
142 String strJDBCDefaultTargetParameterDriver = "";
143 String strJDBCDefaultSourceParameterConnection = "";
144 String strJDBCDefaultTargetParameterConnection = "";
145 String strJDBCDefaultSourceParameterUser = "";
146 String strJDBCDefaultTargetParameterUser = "";
147 String strJDBCDefaultSourceParameterPassword = "";
148 String strJDBCDefaultTargetParameterPassword = "";
149 int iValueColumns;
150 Vector vecValueColumnsTargetTables = new Vector();
151 Vector vecSourceColumnName = new Vector();
152 Vector vecTargetColumnName = new Vector();
153 Vector vecValueMode = new Vector();
154 Vector vecTargetColumnValue = new Vector();
155 Vector vecTargetKeyColumnName = new Vector();
156 Vector vecVariableUseIDTableName = new Vector();
157 Vector vecVariableUseIDTableID = new Vector();
158 Vector vecVariableUseIDColumnName = new Vector();
159 Vector vecVariableUseIDValueMode = new Vector();
160 Vector vecVariableColumnName = new Vector();
161 Vector vecVariableColumnTargetTableName = new Vector();
162 Vector vecVariableColumnTargetTableID = new Vector();
163 Vector vecVariableColumnTargetColumnName = new Vector();
164 Vector vecVariableColumnValueMode = new Vector();
165 Vector vecVariableColumnTypes = new Vector();
166 Vector vecVariableTimesTableName = new Vector();
167 Vector vecVariableTimesTableID = new Vector();
168 Vector vecVariableTimesColumnName = new Vector();
169 Vector vecVariableTimesValueMode = new Vector();
170 int iConstantColumns;
171 Vector vecConstantTargetColumnName = new Vector();
172 Vector vecConstantValueMode = new Vector();
173 Vector vecConstantConstantValue = new Vector();
174 Vector vecConstantColumnTargetTableName = new Vector();
175 Vector vecConstantColumnTargetTableID = new Vector();
176 int iRelationColumns;
177 Vector vecRelationColumnSourceTableName = new Vector();
178 Vector vecRelationColumnSourceTableID = new Vector();
179 Vector vecRelationColumnSourceColumnName = new Vector();
180 Vector vecRelationColumnTargetTableName = new Vector();
181 Vector vecRelationColumnTargetColumnName = new Vector();
182 Vector vecRelationColumnTargetTableID = new Vector();
183 Vector vecRelationColumnRelationMode = new Vector();
184 int iTables;
185 Vector vecTableTableName = new Vector();
186 Vector vecTableTableID = new Vector();
187 Vector vecTableInsert = new Vector();
188 Vector vecTableTableMode = new Vector();
189 Vector vecTableOidLogic = new Vector();
190 Vector vecRelationSourceValue = new Vector();
191 Vector vecRelationSourceType = new Vector();
192 Vector vecSourceColumnType = new Vector();
193 Vector vecConstantColumnType = new Vector();
194 BigDecimal bdecOidNumber = new BigDecimal(0);
195 BigDecimal bdecOidNumber2000 = new BigDecimal(0);
196 int iObjectID = 0;
197 String strObjectIDTableName = "";
198 String strObjectIDColumnName = "";
199
200 // TOS
201 String strObjectIDNameColumnName = "";
202 String strObjectIDNameColumnValue = "";
203
204 String strDefaultLogMode = "normal";
205 int iDefaultObjectIDIncrement = 20;
206 String strDefaultObjectIDTableName = "objectid";
207 String strDefaultObjectIDColumnName = "next";
208 // TOS
209 String strDefaultObjectIDNameColumnName = "";
210 String strDefaultObjectIDNameColumnValue = "";
211
212 boolean bDefaultOnErrorContinue = false;
213 boolean bDefaultCommit = true;
214 String strDefaultUserID = "";
215 String strDefaultLogDir = "";
216 String strDefaultLogFile = "default";
217 String strDefaultVendorConfig = "OctopusDBVendors.xml";
218 boolean bDefaultObjectIDAutoCreate = false;
219 int iDefaultObjectIDStartValue = 1;
220 int iDefaultCommitCount = 100;
221 boolean bDefaultOidLogic = true;
222 boolean bObjectIDAutoCreate;
223 int iObjectIDStartValue;
224 String strDefaultTableMode = "Query";
225 String strFilePath;
226 String strLoaderJobFileName = "";
227 boolean bRestartIndicator;
228 Map mapVariableValues = new HashMap();
229 boolean bOnErrorContinue;
230 String strUserID = "";
231 String strLogDirName = "";
232 String strLogFileName = "";
233 String strVendorFileName = "";
234 String strLogMode = "";
235 String strAdditionalPaths = "";
236 int iCommitCount = 0;
237 boolean hasRestartCounter;
238 boolean hasUserID;
239 Vector vecRelationKeyColumns = new Vector();
240 Vector vecRelationKeyTypes = new Vector();
241 Vector vecQueryWhere = new Vector();
242 Vector vecSortValues = new Vector();
243 String strSqlName = "";
244 String strSqlLogMode = "";
245 String strSqlOnErrorContinue = "";
246 String strSqlCommit = "";
247 Vector vecSqlStmt = new Vector();
248 String strSourceDriverName = "";
249 String strSourceDriverClassName = "";
250 String strTargetDriverName = "";
251 String strTargetDriverClassName = "";
252 boolean bRequiredUser = false;
253 boolean bTargetRequiredUser = false;
254 boolean bEnableJumpResult = false;
255 boolean bEnablePreviousRecord = false;
256 boolean bBeforeFirstRow = true;
257 boolean bAfterLastRow = true;
258 boolean bEnableOrderBy = false;
259 int iFirstColumnResult = 1;
260 int iTargetFirstColumnResult = 1;
261 Vector vecVariableName = new Vector();
262 Vector vecVariableValue = new Vector();
263 Vector vecVariablePrefix = new Vector();
264 Vector vecVariableSufix = new Vector();
265 Vector vecVariableOverride = new Vector();
266 Vector vecReplaceInConstants = new Vector();
267 Vector vecReplaceInSQL = new Vector();
268 Vector vecReplaceInData = new Vector();
269 Vector vecReplaceInJDBC = new Vector();
270 public static final String LOGMODE_NONE = "none";
271 public static final String LOGMODE_NORMAL = "normal";
272 public static final String LOGMODE_FULL = "full";
273 ByteArrayOutputStream foStreamTmp = new ByteArrayOutputStream();
274 boolean bReplaceInData = false;
275 int iColumnsInSourceTable = 0;
276 boolean isDefaultJdbc = false;
277 private Cache cacheValues;
278 private EchoElement echo;
279 private CounterColumns counterColumns;
280 private TimeWatch timeCounter;
281
282 /***
283 * Construct object Loader with an associated parameters.
284 * @param <b>loadJobFileName</b> defines xml input file.
285 * @param <b>mode</b>defines the default logmode. Possible values are "none", "normal" (is the default) and "full". Is "normal" otherwise -m none
286 * @param <b>userID</b> String which is name of user. This argument is used for writing userID into variable columns.
287 * If it is 'null' there is no define userID columns.
288 * @param <b>logDirName</b> defines the logfile directory. The default is the current working directory.
289 * @param <b>logFileName</b> defines the logfile name. The default is "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
290 * @param <b>restartIndicator</b> which is true if "restart" mode and false if "new" mode.
291 * @param <b>variableValues</b> Map defines variables used in variable columns.
292 * @param <b>vendorFileName</b> the filename of the XML DB-vendor configuration file. The default is "OctopusDBVendors.xml".
293 * @param <b>onErrorContinue</b> defines to set the default of "onErrorContinue" to "true". Is false otherwise.
294 * @param <b>additionalPaths</b> Extend the classpath with additional paths.
295 * @param <b>commitCount</b> Sets the default commit count. System default is "100".
296 * @param <b>commitCount</b> Sets the default error return code. System default is "1".
297 */
298 public Loader (String loadJobFileName, String mode, String userID, String logDirName,
299 String logFileName, boolean restartIndicator, Map variableValues,
300 String vendorFileName, boolean onErrorContinue, String additionalPaths,
301 int commitCount, int returnCode) {
302 this.strLoaderJobFileName = loadJobFileName;
303 if (mode != null) {
304 if(mode.equalsIgnoreCase("none") ||
305 mode.equalsIgnoreCase("normal") ||
306 mode.equalsIgnoreCase("full"))
307 this.strLogMode = mode;
308 else
309 // this.strLogMode = this.LOGMODE_NORMAL;
310 this.strLogMode = "";
311 }
312 else
313 // this.strLogMode = this.LOGMODE_NORMAL;
314 this.strLogMode = "";
315 if (userID != null) {
316 this.strUserID = userID;
317 this.hasUserID = true;
318 }
319 else
320 this.hasUserID = false;
321 if (logDirName != null)
322 this.strLogDirName = logDirName;
323 else {
324 File fCurrent = new File("");
325 this.strLogDirName = fCurrent.getAbsolutePath();
326 }
327 if (logFileName != null) {
328 this.strLogFileName = logFileName;
329 }
330 else
331 this.strLogFileName = "default";
332 this.bRestartIndicator = restartIndicator;
333 if (this.bRestartIndicator == true)
334 this.hasRestartCounter = true;
335 else
336 this.hasRestartCounter = false;
337 this.mapVariableValues = variableValues;
338 if (vendorFileName != null) {
339 this.strVendorFileName = vendorFileName;
340 }
341 else
342 this.strVendorFileName = "OctopusDBVendors.xml";
343 this.bOnErrorContinue = onErrorContinue;
344 if (additionalPaths != null) {
345 this.strAdditionalPaths = additionalPaths;
346 String strClassPath = System.getProperty("java.class.path");
347 strClassPath = this.addClassPath(strClassPath,this.strAdditionalPaths);
348 System.setProperty("java.class.path",strClassPath);
349 }
350 this.iCommitCount = commitCount;
351 ReturnCode.setDefaultErrorReturnCode(returnCode);
352 }
353 /***
354 * Method addClassPath adds additional class paths into system classpath property
355 * @param String oldClassPath - System classpath;
356 * @param String add - additional class paths.
357 */
358 private String addClassPath(String oldClassPath, String add) {
359
360 String classPath = oldClassPath;
361 if(System.getProperty("os.name").toLowerCase().startsWith("win")) {
362 if(!classPath.trim().endsWith(";"))
363 classPath += ";";
364 add=add.replace('\n','//');
365 add=add.replace('\t','//');
366 add=add.replace('\b','//');
367 add=add.replace('\r','//');
368 add=add.replace('\f','//');
369 classPath = classPath.concat(add);
370 }
371 else {
372 if(!classPath.trim().endsWith(":"))
373 classPath += ";";
374 add=add.replace('\n','/');
375 add=add.replace('\t','/');
376 add=add.replace('\b','/');
377 add=add.replace('\r','/');
378 add=add.replace('\f','/');
379 classPath = classPath.concat(add);
380
381 }
382 return classPath;
383 }
384
385 /***
386 * Public constructor of Loader class. Constructor set value for loadJobFileName attribute.
387 * Class set all other attributes to the default values.
388 * @param String loadJobFileName Name of loadJob import XML file.
389 *
390 */
391 public Loader (String loadJobFileName) {
392 this.strLoaderJobFileName = loadJobFileName;
393 // this.strLogMode = LOGMODE_NORMAL;
394 this.strLogMode = "";
395 this.hasUserID = false;
396 File fCurrent = new File("");
397 this.strLogDirName = fCurrent.getAbsolutePath();
398 this.strLogFileName = "default";
399 this.bRestartIndicator = false;
400 this.hasRestartCounter = false;
401 this.strVendorFileName = "OctopusDBVendors.xml";
402 this.bOnErrorContinue = false;
403 this.iCommitCount = 100;
404 ReturnCode.setDefaultErrorReturnCode(1);
405 }
406
407 /***
408 * Read value of loadJobFileName attribute.
409 * @return String value of loadFileName attribute
410 */
411 public String getLoadJobFileName () {
412 return this.strLoaderJobFileName;
413 }
414
415 /***
416 * This method sets value of loadJobFileName attribute.
417 * @param loadJobFileName loadJob XML file name
418 */
419 public void setLoadJobFileName (String loadJobFileName) {
420 this.strLoaderJobFileName = loadJobFileName;
421 }
422
423 /***
424 * Read value of Mode(LogMode) attribute.
425 * @return value of attribute.
426 */
427 public String getMode () {
428 return this.strLogMode;
429 }
430
431 /***
432 * This method sets value of Mode attribute.
433 * @param value of attribute. Possible values are:
434 * Loader.LOGMODE_NONE, Loader.LOGMODE_NORMAL, Loader.LOGMODE_FULL.
435 */
436 public void setMode (String mode) {
437 this.strLogMode = mode;
438 }
439
440 /***
441 * Read value of userID attribute.
442 * @return value of attribute.
443 */
444 public String getUserID () {
445 return this.strUserID;
446 }
447
448 /***
449 * This method sets value of userID attribute.
450 * @param value userID attribute.
451 */
452 public void setUserID (String userID) {
453 this.strUserID = userID;
454 }
455
456 /***
457 * Read value of logDirName attribute
458 * @return value of attribute
459 */
460 public String getLogDirName () {
461 return this.strLogDirName;
462 }
463
464 /***
465 * This method sets value of logDirName attribute.
466 * @param logDirName value of attribute.
467 */
468 public void setLogDirName (String logDirName) {
469 this.strLogDirName = logDirName;
470 }
471
472 /***
473 * Read value of logFileName attribute.
474 * @return value of attribute.
475 */
476 public String getLogFileName () {
477 return this.strLogFileName;
478 }
479
480 /***
481 * This method sets value of logFileName attribute.
482 * @param logFileName value of attribute.
483 */
484 public void setLogFileName (String logFileName) {
485 this.strLogFileName = logFileName;
486 }
487
488 /***
489 * Read value of restartIndicator attribute.
490 * @return value of attribute.
491 */
492 public boolean getRestartIndicator () {
493 return this.bRestartIndicator;
494 }
495
496 /***
497 * This method sets value of restartIndicator attribute.
498 * @param restartIndicator value of attribute.
499 */
500 public void setRestartIndicator (boolean restartIndicator) {
501 this.bRestartIndicator = restartIndicator;
502 }
503
504 /***
505 * Read value of variableValues attribute.
506 * @return value of attribute.
507 */
508 public Map getVariableValues () {
509 return this.mapVariableValues;
510 }
511
512 /***
513 * This method sets value of variableValues attribute.
514 * @param variableValues value of attribute.
515 */
516 public void setVariableValues (Map variableValue) {
517 this.mapVariableValues = variableValue;
518 }
519
520 /***
521 * Read value of vendorFileName.
522 * @return value of attribute.
523 */
524 public String getVendorFileName () {
525 return this.strVendorFileName;
526 }
527
528 /***
529 * This method sets value of vendorFileName attribute.
530 * @param vendorFileName value of attribute.
531 */
532 public void setVendorFileName (String vendorFileName) {
533 this.strVendorFileName = vendorFileName;
534 }
535
536 /***
537 * read value of onErrorContinue attribute.
538 * @return value of attribute.
539 */
540 public boolean getOnErrorContinue () {
541 return this.bOnErrorContinue;
542 }
543
544 /***
545 * This method sets value of onErrorContinue attribute.
546 * @param onErrorContinue value of attribute.
547 */
548 public void setOnErrorContinue (boolean onErrorContinue) {
549 this.bOnErrorContinue = onErrorContinue;
550 }
551
552 /***
553 * Read value of additionalPaths attribute.
554 * @return value of attribute.
555 */
556 public String getAdditionalPaths () {
557 return this.strAdditionalPaths;
558 }
559
560 /***
561 * This method sets value of additionalPaths attribute.
562 * @param additionalPaths value of attribute.
563 */
564 public void setAdditionalPaths (String additionalPaths) {
565 this.strAdditionalPaths = additionalPaths;
566 String strClassPath = System.getProperty("java.class.path");
567 strClassPath = this.addClassPath(strClassPath,this.strAdditionalPaths);
568 System.setProperty("java.class.path",strClassPath);
569 }
570
571 /***
572 * Read value of commitCount attribute.
573 * @return value of attribute.
574 */
575 public int getCommitCount () {
576 return this.iCommitCount;
577 }
578
579 /***
580 * This method sets value of commitCount attribute.
581 * @param commitCount value of attribute.
582 */
583 public void setCommitCount (int commitCount) {
584 this.iCommitCount = commitCount;
585 }
586
587 /***
588 * Read value of default error return code attribute.
589 * @return value of attribute.
590 */
591 public int getDefaultReturnCode () {
592 return ReturnCode.getDefaultErrorReturnCode();
593 }
594
595 /***
596 * This method sets value of default error return code attribute.
597 * @param commitCount value of attribute.
598 */
599 public void setDefaultReturnCode (int code) {
600 ReturnCode.setDefaultErrorReturnCode(code);
601 }
602
603 /***
604 * Main method Loader with an associated XML, restart mode (optional) i user (optional).
605 * Main method controls parameters, it they are OK starts load method, but if
606 * they aren't makes alert.
607 * Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
608 * Options:
609 * -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.
610 * -r starts the Loader in restart mode after abnormal termination in a prior execution.
611 * -u defines the current UserID used in UserID value columns.
612 * -v defines variables used in variable columns.
613 * -l defines the logfile directory. The default is the current working directory.
614 * -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'.
615 * -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'.
616 * -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise.
617 * -p Extend the classpath with additional paths.
618 * -c Sets the default commit count. System default is '100'.
619 * -rc Sets the default error return code. System default is '1'.
620 */
621 public static void main (String argv[]) {
622 String loadJobFileName = null;
623 String mode = null;
624 String userID = null;
625 String logDirName = null;
626 String logFileName = null;
627 boolean restartIndicator = false;
628 Map variableValues = null;
629 String strVariableValues = null;
630 String vendorFileName = null;
631 boolean onErrorContinue = true;
632 String additionalPaths = null;
633 int defaultReturnCode = 1;
634 int commitCount = 100;
635 if (argv.length > 0 && argv.length < 22) {
636 loadJobFileName = argv[argv.length - 1];
637 for (int i = 0; i < argv.length - 1; i = i + 1) {
638 if (argv[i].equalsIgnoreCase("-m"))
639 mode = argv[++i];
640 else if (argv[i].equalsIgnoreCase("-r"))
641 restartIndicator = true;
642 else if (argv[i].equalsIgnoreCase("-u"))
643 userID = argv[++i];
644 else if (argv[i].equalsIgnoreCase("-l"))
645 logDirName = argv[++i];
646 else if (argv[i].equalsIgnoreCase("-f"))
647 logFileName = argv[++i];
648 else if (argv[i].equalsIgnoreCase("-d"))
649 vendorFileName = argv[++i];
650 else if (argv[i].equalsIgnoreCase("-e"))
651 onErrorContinue = true;
652 else if (argv[i].equalsIgnoreCase("-p"))
653 additionalPaths = argv[++i];
654 else if (argv[i].equalsIgnoreCase("-c"))
655 commitCount = (new Integer(argv[++i])).intValue();
656 else if (argv[i].equalsIgnoreCase("-v")) {
657 strVariableValues = argv[++i];
658 variableValues = new HashMap(convertToMap(strVariableValues));
659 }
660 else if (argv[i].equalsIgnoreCase("-rc")) {
661 defaultReturnCode = (new Integer(argv[++i])).intValue();
662 ReturnCode.isParameter=true;
663 }
664 }
665 }
666 else
667 printUsage();
668 Loader l = new Loader(loadJobFileName, mode, userID, logDirName, logFileName,
669 restartIndicator, variableValues, vendorFileName, onErrorContinue,
670 additionalPaths, commitCount, defaultReturnCode);
671 try {
672 l.load();
673 } catch (LoaderException le) {
674 le.printStackTrace();
675 System.exit(ReturnCode.getErrorReturnCode());
676 }
677 }
678
679 /***
680 * put your documentation comment here
681 */
682 static void printUsage () {
683 System.out.println("Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
684 System.out.println(" Options:");
685 System.out.println(" -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.");
686 System.out.println(" -r starts the Loader in restart mode after abnormal termination in a prior execution. \n");
687 System.out.println(" -u defines the current UserID used in UserID value columns. \n");
688 System.out.println(" -v defines variables used in variable columns. \n");
689 System.out.println(" -l defines the logfile directory. The default is the current working directory. \n");
690 System.out.println(" -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n");
691 System.out.println(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n");
692 System.out.println(" -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n");
693 System.out.println(" -p Extend the classpath with additional paths \n");
694 System.out.println(" -c Sets the default commit count. System default is '100'. \n");
695 System.out.println(" -rc Sets the default error return code. System default is '1'. \n");
696 System.exit(ReturnCode.getErrorReturnCode());
697 }
698
699 /***
700 * Method load is main method in class Loader. It is used to load data from the source table into
701 * target tables and(or) execute SQL statements. Loading parameters are set in XML file. During loading,
702 * load status is printed on the screen and also put into log file.
703 * If there is an error Exception "LoaderException" is thrown.
704 * @throws LoaderException.
705 */
706 public void load () throws LoaderException {
707 int iImportJobs = 0;
708 int iConnection = 0;
709 int iSqlTags = 0;
710 int iEchoElements = 0;
711 int iLastImportDefinition = 0;
712 Vector vecXmlElements = new Vector();
713 Vector vecJDBCTargetConnections = new Vector();
714 this.echo = new EchoElement();
715 this.timeCounter=new TimeWatch();
716 if(!this.echo.createLog(this.strLogDirName,this.strLogFileName))
717 this.echo.setLogFile(new File(this.strLogDirName,this.strLogFileName));
718 // this.createLog(this.strLogFileName);
719 this.echo.writeToLog("none", "\nApplication is started.");
720 this.timeCounter.setStartTime();
721 ByteArrayInputStream inStream = null;
722 ByteArrayOutputStream foStream = new ByteArrayOutputStream();
723 // Loading XML file and replacing include tags
724 LoaderXIncluder loaderInclude = new LoaderXIncluder(foStream);
725 loaderInclude.parseURI(this.strLoaderJobFileName);
726 inStream = new ByteArrayInputStream(foStream.toByteArray());
727 // Import attribute values from variable tags from XML
728 this.importVariable(inStream);
729 // Setting bReplaceInData if there is even one ReplaceInData attribut
730 // in variable tags
731 for (int i = 0; i < this.vecReplaceInData.size(); i++) {
732 if (this.vecReplaceInData.get(i).toString().equalsIgnoreCase("true"))
733 bReplaceInData = true;
734 }
735 // Change variable values in SQL, JDBC and Constants Tags in XML
736 this.foStreamTmp = foStream;
737 foStream = new ByteArrayOutputStream();
738 LoadVariable loadVariable = new LoadVariable(foStream, this);
739 loadVariable.parseURI();
740 importLoaderJobAttributes(inStream);
741 iImportJobs = this.parseImportJob(inStream);
742 iSqlTags = this.parseSql(inStream);
743 iEchoElements = this.parseEcho(inStream);
744 this.importRestartCounter(inStream);
745 vecXmlElements = this.parseMainElements(inStream);
746 iLastImportDefinition = 0;
747 for (int i = 0; i < vecXmlElements.size(); i++) {
748 if (vecXmlElements.get(i).toString().equalsIgnoreCase("importDefinition"))
749 iLastImportDefinition = i;
750 }
751 // Setting LogMode depending on priority, 1.parameter-strLogMode, and
752 // 2.attribute of LoaderJob-strDefaultLogMode
753 if (!strLogMode.equals(""))
754 strImportDefinitionLogMode = strLogMode;
755 else
756 strImportDefinitionLogMode = strDefaultLogMode;
757 Connection connA = null;
758 Connection connB = null;
759 Connection connC = null;
760 try {
761 this.isDefaultJdbc = this.parseImportJDBCDefaultParameters(inStream);
762 this.parseImportJDBCParameters(inStream);
763 readConfigValues(this.strTargetDbVendor,this.strTargetDriverName, "target");
764 if(this.strJDBCTargetParameterDriver.equals("")||this.strJDBCTargetParameterDriver==null)
765 this.strJDBCTargetParameterDriver=this.strTargetDriverClassName;
766 Class.forName(this.strJDBCTargetParameterDriver);
767 int iImport = 0;
768 int iSql = 0;
769 int iEcho = 0;
770 for (int l = 0; l < (iImportJobs + iSqlTags +iEchoElements); l++) {
771 this.echo.setLogMode(strImportDefinitionLogMode);
772 this.resetGlobalVariables();
773 if (!strLogMode.equals(""))
774 strImportDefinitionLogMode = strLogMode;
775 else
776 strImportDefinitionLogMode = strDefaultLogMode;
777 this.echo.writeToLog("normal", "\nImport job No. " + (iImport+iSql + 1) + " is started.");
778 this.echo.writeToLog("full", "Importing and parsing XML file is started.");
779 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) {
780 this.parseAndImport(inStream, iImport);
781 readConfigValues(this.strDbVendor,this.strSourceDriverName, "source");
782 readConfigValues(this.strTargetDbVendor,strTargetDriverName, "target");
783 this.echo.setLogMode(strImportDefinitionLogMode);
784 }
785 else if(vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
786 this.vecSqlStmt = importSQLStatement(inStream, iSql);
787 this.echo.setLogMode(strSqlLogMode);
788 }
789 if(vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")||
790 vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
791 if(this.strJDBCSourceParameterDriver.equals("")||this.strJDBCSourceParameterDriver==null)
792 this.strJDBCSourceParameterDriver=this.strSourceDriverClassName;
793 if(this.strJDBCTargetParameterDriver.equals("")||this.strJDBCTargetParameterDriver==null)
794 this.strJDBCTargetParameterDriver=this.strTargetDriverClassName;
795 }
796 // Class.forName(this.strJDBCTargetParameterDriver);
797 this.echo.writeToLog("full", "Importing and parsing XML file is finished.");
798 boolean bNewConnection = true;
799 if(vecXmlElements.get(l).toString().equalsIgnoreCase("echo"))
800 bNewConnection=false;
801 else {
802 endConnection: for (int i = 0; i < vecJDBCTargetConnections.size(); i++) {
803 if (vecJDBCTargetConnections.get(i).toString().equalsIgnoreCase(this.strJDBCTargetParameterConnection)) {
804 bNewConnection = false;
805 iConnection = i;
806 break endConnection;
807 }
808 }
809 }
810 if (bNewConnection) {
811 vecJDBCTargetConnections.addElement(this.strJDBCTargetParameterConnection);
812 if (this.strJDBCTargetParameterUser.equals("") && this.bTargetRequiredUser)
813 this.inputUser(false);
814 Class.forName(this.strJDBCTargetParameterDriver);
815 if (vecJDBCTargetConnections.size() == 1) {
816 if (this.bTargetRequiredUser)
817 connA = DriverManager.getConnection(this.strJDBCTargetParameterConnection,
818 this.strJDBCTargetParameterUser, this.strJDBCTargetParameterPassword);
819 else
820 connA = DriverManager.getConnection(this.strJDBCTargetParameterConnection);
821 connA.setAutoCommit(false);
822 if (this.bRestartAutoCreate == true)
823 createRestartCounterTable(connA);
824 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) {
825 this.loadSource(connA);
826 iImport++;
827 }
828 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("echo")) {
829 echo.writeEcho(this.echo.getMessage(new Integer(iEcho).toString()));
830 iEcho++;
831 }
832 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
833 try {
834 if (this.strSqlCommit.equalsIgnoreCase("true")) {
835 connA.setAutoCommit(true);
836 this.executeSQLStatement(connA);
837 connA.setAutoCommit(false);
838 }
839 else
840 this.executeSQLStatement(connA);
841 } catch (Exception e) {
842 LoaderException le = new LoaderException("SQLException: ",
843 (Throwable)e);
844 this.echo.writeToLog("none", "\t" + le.getCause().toString());
845 if (this.strSqlOnErrorContinue.equalsIgnoreCase("false")) {
846 this.echo.writeToLog("none", "\tError : Because OnErrorContinue Attribute is false application is terminated");
847 // System.exit(1);
848 connA.close();
849 throw le;
850 }
851 }
852 iSql++;
853 }
854
855 }
856 else if (vecJDBCTargetConnections.size() == 2) {
857 if (this.bTargetRequiredUser)
858 connB = DriverManager.getConnection(this.strJDBCTargetParameterConnection,
859 this.strJDBCTargetParameterUser, this.strJDBCTargetParameterPassword);
860 else
861 connB = DriverManager.getConnection(this.strJDBCTargetParameterConnection);
862 connB.setAutoCommit(false);
863 if (this.bRestartAutoCreate == true)
864 createRestartCounterTable(connB);
865 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) {
866 this.loadSource(connB);
867 iImport++;
868 }
869 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("echo")) {
870 echo.writeEcho(this.echo.getMessage(new Integer(iEcho).toString()));
871 iEcho++;
872 }
873 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
874 try {
875 if (this.strSqlCommit.equalsIgnoreCase("true")) {
876 connB.setAutoCommit(true);
877
878 this.executeSQLStatement(connB);
879 connB.setAutoCommit(false);
880 }
881 else
882 this.executeSQLStatement(connB);
883 } catch (Exception e) {
884 LoaderException le = new LoaderException("SQLException: ",
885 (Throwable)e);
886 this.echo.writeToLog("none", "\t" + le.getCause().toString());
887 if (this.strSqlOnErrorContinue.equalsIgnoreCase("false")) {
888 this.echo.writeToLog("none", "\tError : Because OnErrorContinue Attribute is false application is terminated");
889 // System.exit(1);
890 if(connA!=null)
891 connA.close();
892 if(connB!=null)
893 connB.close();
894 throw le;
895 }
896 }
897 iSql++;
898 }
899 }
900 else if (vecJDBCTargetConnections.size() == 3) {
901 if (this.bTargetRequiredUser)
902 connC = DriverManager.getConnection(this.strJDBCTargetParameterConnection,
903 this.strJDBCTargetParameterUser, this.strJDBCTargetParameterPassword);
904 else
905 connC = DriverManager.getConnection(this.strJDBCTargetParameterConnection);
906 connC.setAutoCommit(false);
907 if (this.bRestartAutoCreate == true)
908 createRestartCounterTable(connC);
909 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) {
910 this.loadSource(connC);
911 iImport++;
912 }
913 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("echo")) {
914 echo.writeEcho(this.echo.getMessage(new Integer(iEcho).toString()));
915 iEcho++;
916 }
917 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
918 try {
919 if (this.strSqlCommit.equalsIgnoreCase("true")) {
920 connC.setAutoCommit(true);
921 this.executeSQLStatement(connC);
922 connC.setAutoCommit(false);
923 // connC.commit();
924 }
925 else
926 this.executeSQLStatement(connC);
927 } catch (Exception e) {
928 LoaderException le = new LoaderException("SQLException: ",
929 (Throwable)e);
930 this.echo.writeToLog("none", "\t" + le.getCause().toString());
931 if (this.strSqlOnErrorContinue.equalsIgnoreCase("false")) {
932 this.echo.writeToLog("none", "\tError : Because OnErrorContinue Attribute is false application is terminated");
933 // System.exit(1);
934 if(connA!=null)
935 connA.close();
936 if(connB!=null)
937 connB.close();
938 if(connC!=null)
939 connC.close();
940 throw le;
941 }
942 }
943 iSql++;
944 }
945 }
946 else {
947 this.echo.writeToLog("none", "Error : Loader supports loading data up to maximum 3 SQL database");
948 // System.exit(1);
949 LoaderException le = new LoaderException("SQLException: ",
950 (Throwable)(new SQLException("Error : Loader supports loading data up to maximum 3 SQL database")));
951 if(connA!=null)
952 connA.close();
953 if(connB!=null)
954 connB.close();
955 if(connC!=null)
956 connC.close();
957 throw le;
958 }
959 }
960 else {
961 if (iConnection == 0) {
962 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) {
963 this.loadSource(connA);
964 iImport++;
965 }
966 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("echo")) {
967 echo.writeEcho(this.echo.getMessage(new Integer(iEcho).toString()));
968 iEcho++;
969 }
970 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
971 try {
972 if (this.strSqlCommit.equalsIgnoreCase("true")) {
973 connA.setAutoCommit(true);
974 this.executeSQLStatement(connA);
975 connA.setAutoCommit(false);
976 }
977 else
978 this.executeSQLStatement(connA);
979 } catch (Exception e) {
980 LoaderException le = new LoaderException("SQLException: ",
981 (Throwable)e);
982 this.echo.writeToLog("none", "\t" + le.getCause().toString());
983 if (this.strSqlOnErrorContinue.equalsIgnoreCase("false")) {
984 this.echo.writeToLog("none", "\tError : Because OnErrorContinue Attribute is false application is terminated");
985 // System.exit(1);
986 if(connA!=null)
987 connA.close();
988 throw le;
989 }
990 }
991 iSql++;
992 }
993 }
994 else if (iConnection == 1) {
995 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) {
996 this.loadSource(connB);
997 iImport++;
998 }
999 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("echo")) {
1000 echo.writeEcho(this.echo.getMessage(new Integer(iEcho).toString()));
1001 iEcho++;
1002 }
1003 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
1004 try {
1005 if (this.strSqlCommit.equalsIgnoreCase("true")) {
1006 connB.setAutoCommit(true);
1007 this.executeSQLStatement(connB);
1008 connB.setAutoCommit(false);
1009 }
1010 else
1011 this.executeSQLStatement(connB);
1012 } catch (Exception e) {
1013 LoaderException le = new LoaderException("SQLException: ",
1014 (Throwable)e);
1015 this.echo.writeToLog("none", "\t" + le.getCause().toString());
1016 if (this.strSqlOnErrorContinue.equalsIgnoreCase("false")) {
1017 this.echo.writeToLog("none", "\tError : Because OnErrorContinue Attribute is false application is terminated");
1018 // System.exit(1);
1019 if(connA!=null)
1020 connA.close();
1021 if(connB!=null)
1022 connB.close();
1023 throw le;
1024 }
1025 }
1026 iSql++;
1027 }
1028 }
1029 else if (iConnection == 2) {
1030 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) {
1031 this.loadSource(connC);
1032 iImport++;
1033 }
1034 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("echo")) {
1035 echo.writeEcho(this.echo.getMessage(new Integer(iEcho).toString()));
1036 iEcho++;
1037 }
1038 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) {
1039 try {
1040 if (this.strSqlCommit.equalsIgnoreCase("true")) {
1041 connC.setAutoCommit(true);
1042 this.executeSQLStatement(connC);
1043 connC.setAutoCommit(false);
1044 }
1045 else
1046 this.executeSQLStatement(connC);
1047 } catch (Exception e) {
1048 LoaderException le = new LoaderException("SQLException: ",
1049 (Throwable)e);
1050 this.echo.writeToLog("none", "\t" + le.getCause().toString());
1051 if (this.strSqlOnErrorContinue.equalsIgnoreCase("false")) {
1052 this.echo.writeToLog("none", "\tError : Because OnErrorContinue Attribute is false application is terminated");
1053 if(connA!=null)
1054 connA.close();
1055 if(connB!=null)
1056 connB.close();
1057 if(connC!=null)
1058 connC.close();
1059 throw le;
1060
1061 // System.exit(1);
1062 }
1063 }
1064 iSql++;
1065 }
1066 }
1067 }
1068 if (!this.hasRestartCounter && iLastImportDefinition == l) {
1069 if (iConnection == 0)
1070 connA.commit();
1071 else if (iConnection == 1) {
1072 connA.commit();
1073 connB.commit();
1074 }
1075 else if (iConnection == 2) {
1076 connA.commit();
1077 connB.commit();
1078 connC.commit();
1079 }
1080 this.echo.writeToLog("normal", "All rows are commited.");
1081 }
1082 }
1083 //sinisa 22.01.2003. Commit all conections at the end of application.
1084 if (iConnection == 0)
1085 connA.commit();
1086 else if (iConnection == 1) {
1087 connA.commit();
1088 connB.commit();
1089 }
1090 else if (iConnection == 2) {
1091 connA.commit();
1092 connB.commit();
1093 connC.commit();
1094 }
1095 this.echo.writeToLog("normal", "All rows are commited.");
1096
1097 connA.close();
1098 if(connB!=null)
1099 connB.close();
1100 if(connC!=null)
1101 connC.close();
1102 this.echo.writeToLog("none", "Application is finished.");
1103 this.echo.writeToLog("normal","All jobs duration: "+ this.timeCounter.getTotalTime());
1104 } catch (IOException e) {
1105 LoaderException le = new LoaderException("IOException: ", (Throwable)e);
1106 this.echo.writeToLog("none", le.getCause().toString());
1107 throw le;
1108 } catch (ClassNotFoundException e) {
1109 LoaderException le = new LoaderException("ClassNotFoundException: ",
1110 (Throwable)e);
1111 this.echo.writeToLog("none", le.getCause().toString());
1112 throw le;
1113 } catch (SQLException e) {
1114 LoaderException le = new LoaderException("SQLException: ", (Throwable)e);
1115 this.echo.writeToLog("none", le.getCause().toString());
1116 throw le;
1117 } catch (NullPointerException e) {
1118 LoaderException le = new LoaderException("NullPointerException: ",
1119 (Throwable)e);
1120 this.echo.writeToLog("none", le.getCause().toString());
1121 throw le;
1122 } catch (SAXException e) {
1123 LoaderException le = new LoaderException("SAXException: ", (Throwable)e);
1124 this.echo.writeToLog("none", le.getCause().toString());
1125 throw le;
1126 } catch (Exception e) {
1127 LoaderException le = new LoaderException("Exception: ", (Throwable)e);
1128 this.echo.writeToLog("none", le.getCause().toString());
1129 throw le;
1130 }
1131 finally{
1132 try{
1133 if(connA!=null)
1134 connA.close();
1135 if(connB!=null)
1136 connB.close();
1137 if(connC!=null)
1138 connC.close();
1139 } catch (SQLException e) {
1140 LoaderException le = new LoaderException("SQLException: ", (Throwable)e);
1141 this.echo.writeToLog("none", le.getCause().toString());
1142 throw le;
1143 }
1144 }
1145 }
1146
1147 /***
1148 * Method loadSource is used to load data from the source table (Csv, MySql, MsSql, Exel...)
1149 * into target tables. This method uses configuration file OctopusDbVendors.xml. Loading parameters are set in XML file. During loading,
1150 * load status is printed on the screen and also put into log file.
1151 * This method is used for loading data by rules which is defined in a single importDefinition.
1152 * If there is an error Exception "LoaderException" is thrown.
1153 * @param connTarget The Connection of target table.
1154 * @throws LoaderException.
1155 */
1156 private void loadSource (Connection connTarget) throws LoaderException {
1157 int iRowNumber = 0;
1158 BigDecimal bdecCounter = new BigDecimal(0);
1159 BigDecimal k = new BigDecimal(0);
1160 Date currentDate = new Date();
1161 DateFormat dfNow = DateFormat.getDateTimeInstance();
1162
1163 this.timeCounter.setStartJobTime();
1164 this.echo.writeToLog("full", "\tloadSource method is started.");
1165 this.echo.writeToLog("normal", "Import definition " + this.strImportDefinitionName
1166 + " is started at " + dfNow.format(currentDate) + ".");
1167 Connection connSource = null;
1168
1169 //sinisa 03.03. Add counterColumns
1170 try {
1171 for(int i=0; i<this.iTables; i++) {
1172 this.counterColumns.setTargetColumnStartValues(this.vecTableTableName.get(i).toString(),
1173 this.vecTableTableID.get(i).toString(),connTarget,this.iTargetFirstColumnResult);
1174 this.counterColumns.counterColumnTypes(this.vecTableTableName.get(i).toString(),this.vecTableTableID.get(i).toString(),
1175 connTarget, this.iTargetFirstColumnResult);
1176
1177 }
1178 //end
1179 if (this.bObjectIDAutoCreate == true) {
1180 createObjectIDTable(connTarget);
1181 connTarget.commit();
1182 }
1183 if (this.bRequiredUser) {
1184 if (this.strJDBCSourceParameterUser.equals(""))
1185 this.inputUser(true);
1186 Class.forName(this.strJDBCSourceParameterDriver);
1187 connSource = DriverManager.getConnection(this.strJDBCSourceParameterConnection,
1188 this.strJDBCSourceParameterUser, this.strJDBCSourceParameterPassword);
1189 }
1190 else {
1191 Class.forName(this.strJDBCSourceParameterDriver);
1192 connSource = DriverManager.getConnection(this.strJDBCSourceParameterConnection);
1193 }
1194 this.constantColumnTypes(connTarget);
1195 String strQuery = "";
1196 if(this.strImportDefinitionSelectStatement!=null && !this.strImportDefinitionSelectStatement.equals("")) {
1197 strQuery = this.strImportDefinitionSelectStatement;
1198 int in = 0;
1199 int jn = 0;
1200 Vector vecVector = new Vector();
1201 while (in < this.iTables) {
1202 vecVector = (Vector)this.vecSourceColumnName.get(in);
1203 while (jn < Integer.parseInt(this.vecValueColumnsTargetTables.get(in).toString())) {
1204 jn++;
1205 this.iColumnsInSourceTable++;
1206 }
1207 jn = 0;
1208 in++;
1209 }
1210
1211 }
1212 else
1213 strQuery = this.querySource();
1214 if (strQuery.indexOf("order by") != -1) {
1215 if (checkSortColumns(connSource)) {
1216 this.echo.writeToLog("none", "Error : Sort columns have more rows with equals values.");
1217 LoaderException le = new LoaderException("SQLException: ",
1218 (Throwable)(new SQLException("Error : Sort columns have more rows with equals values.")));
1219 throw le;
1220 // System.exit(1);
1221 }
1222 }
1223 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
1224 Statement stmtSource = null;
1225 if (this.bEnablePreviousRecord)
1226 stmtSource = connSource.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
1227 ResultSet.CONCUR_UPDATABLE);
1228 else
1229 stmtSource = connSource.createStatement();
1230 ResultSet rsetSource;
1231 int blockNumber = 0;
1232 if(this.strImportDefinitionSelectStatement!=null && !this.strImportDefinitionSelectStatement.equals(""))
1233 iRowNumber=addToCacheUsingSelect (connSource, strQuery);
1234 else {
1235 rsetSource = stmtSource.executeQuery(strQuery);
1236 //number of rows in source table
1237
1238 // if(!this.strDbVendor.equalsIgnoreCase("csv")){
1239 // if(this.vecTableTableMode.get(i).toString().equalsIgnoreCase("Cache")) {
1240 while (rsetSource.next()) {
1241 iRowNumber++;
1242 }
1243 }
1244 blockNumber = iRowNumber/this.iImportDefinitionCommitCount + 1;
1245 iRowNumber=0;
1246 rsetSource = stmtSource.executeQuery(strQuery);
1247 // }
1248 // int colNumber = rsetSource.getMetaData().getColumnCount();
1249 if (!this.strRestartCounterTableName.equals("")) {
1250 bdecCounter = this.checkDataTransmition(this.bRestartIndicator,
1251 connTarget, rsetSource);
1252 }
1253 this.sourceColumnTypes(connTarget);
1254 this.checkOidLogic(connTarget);
1255 int currentBlock=0;
1256 while (rsetSource.next()) {
1257 if (!this.bBeforeFirstRow && this.bEnablePreviousRecord)
1258 rsetSource.previous();
1259 this.echo.writeToLog("normal", "Import block is started.");
1260 currentBlock++;
1261 if(!this.strDbVendor.equalsIgnoreCase("csv"))
1262 this.echo.writeToLog("normal", "Working... "+currentBlock+". block of "+blockNumber);
1263 else
1264 this.echo.writeToLog("normal", "Working... "+currentBlock+". block");
1265 this.echo.writeToLog("full", "\tStarted from the " + bdecCounter.add(
1266 new BigDecimal(1)).toString() + ". row.");
1267 int bdecRowCount=0;
1268 bdecRowCount = this.cache(connSource, bdecCounter, strQuery);
1269 while (iRowNumber < bdecRowCount) {
1270 for (int i = 0; i < this.iTables; i++) {
1271 Vector vecVektor = new Vector();
1272 Vector vecVektor1 = new Vector();
1273 if (this.vecTableTableMode.get(i).toString().equalsIgnoreCase("Cache")) {
1274 vecVektor1 = (Vector)this.vecTargetColumnValue.get(i);
1275 for (int j = (Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString())*iRowNumber); j < (Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString())*(
1276 iRowNumber + 1)); j++) {
1277 if (vecVektor1.get(j)==null)
1278 vecVektor.add(null);
1279 else {
1280 if (vecVektor1.get(j).equals(""))
1281 vecVektor.add(null);
1282 else
1283 vecVektor.add(vecVektor1.get(j));
1284 }
1285 }
1286 }
1287 else {
1288 if(this.strImportDefinitionSelectStatement!=null && !this.strImportDefinitionSelectStatement.equals("")) {
1289 Vector srcNames = new Vector();
1290 srcNames = (Vector)this.vecSourceColumnName.get(i);
1291 for(int s=0; s<srcNames.size(); s++) {
1292 if(srcNames.get(s)!=null) {
1293 String readValue = rsetSource.getString(srcNames.get(s).toString());
1294 if(readValue!=null){
1295 if(!readValue.equalsIgnoreCase("null")){
1296 if(readValue.indexOf("'")!=-1)
1297 readValue=replaceChar(readValue,'\'',"\'\'");
1298 vecVektor.add(readValue);
1299 }
1300 else{
1301 vecVektor.add(null);
1302 }
1303 }
1304 else{
1305 vecVektor.add(null);
1306 }
1307 }
1308 }
1309 }
1310 else {
1311 int iCounterCol = 0;
1312 for (int m = 0; m < i; m++) {
1313 iCounterCol = iCounterCol + Integer.parseInt(this.vecValueColumnsTargetTables.get(m).toString());
1314 }
1315 iCounterCol++;
1316 for (int j = iCounterCol; j < (iCounterCol + Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString())); j++) {
1317 if (this.iFirstColumnResult == 0) {
1318 String readValue = rsetSource.getString(j - 1);
1319 if(readValue==null)
1320 vecVektor.add(null);
1321 else if(readValue.equalsIgnoreCase("null"))
1322 vecVektor.add(null);
1323 else if(readValue.equals(""))
1324 vecVektor.add(null);
1325 else {
1326 if(readValue.indexOf("'")!=-1)
1327 readValue=replaceChar(readValue,'\'',"\'\'");
1328 vecVektor.add(readValue);
1329 }
1330 }
1331 else {
1332 String readValue = rsetSource.getString(j);
1333 if(readValue==null)
1334 vecVektor.add(null);
1335 else if(readValue.equalsIgnoreCase("null"))
1336 vecVektor.add(null);
1337 else if (readValue.equals(""))
1338 vecVektor.add(null);
1339 else {
1340 if(readValue.indexOf("'")!=-1)
1341 readValue=replaceChar(readValue,'\'',"\'\'");
1342 vecVektor.add(readValue);
1343 }
1344 }
1345 }
1346 }
1347 }
1348 for (int l = 0; l < this.vecVariableUseIDTableName.size(); l++) {
1349 if (this.vecTableTableName.get(i).toString().equalsIgnoreCase(this.vecVariableUseIDTableName.get(l).toString())
1350 && this.vecVariableUseIDTableID.get(l).toString().equalsIgnoreCase(this.vecTableTableID.get(i).toString()))
1351 vecVektor.add(this.strUserID);
1352 }
1353 this.insertTargetTable(i, vecVektor, (Vector)this.vecTargetColumnName.get(i),
1354 (Vector)this.vecValueMode.get(i), (Vector)this.vecSourceColumnType.get(i),
1355 connTarget);
1356 }
1357 if (iRowNumber != bdecRowCount - 1)
1358 rsetSource.next();
1359 else {
1360 if (!this.bAfterLastRow)
1361 rsetSource.next();
1362 }
1363 iRowNumber++;
1364 }
1365 if (this.hasRestartCounter)
1366 connTarget.commit();
1367 if (!this.strRestartCounterTableName.equals(""))
1368 bdecCounter = this.insertCounter(connTarget, iRowNumber,
1369 bdecCounter);
1370 else
1371 bdecCounter = bdecCounter.add(new BigDecimal(iRowNumber));
1372 if (this.hasRestartCounter) {
1373 this.echo.writeToLog("normal", "Imported block is commited.");
1374 this.echo.writeToLog("full", Integer.toString(iRowNumber) +
1375 " rows are commited.");
1376 }
1377 iRowNumber = 0;
1378 }
1379 rsetSource.close();
1380 stmtSource.close();
1381 connSource.close();
1382 if (!this.strRestartCounterTableName.equals(""))
1383 this.resetRestartCounter(connTarget, this.strImportDefinitionName);
1384 currentDate = new Date();
1385 dfNow = DateFormat.getDateTimeInstance();
1386 this.echo.writeToLog("normal", "Import definition " + this.strImportDefinitionName
1387 + " is finished at " + dfNow.format(currentDate) + ".");
1388 this.echo.writeToLog("normal"," Duration of importDefinition:"+ this.timeCounter.getJobTime());
1389 } catch (IOException e) {
1390 LoaderException le = new LoaderException("IOException: ", (Throwable)e);
1391 this.echo.writeToLog("none", le.getCause().toString());
1392 throw le;
1393 } catch (ClassNotFoundException e) {
1394 LoaderException le = new LoaderException("ClassNotFoundException: ",
1395 (Throwable)e);
1396 this.echo.writeToLog("none", le.getCause().toString());
1397 throw le;
1398 } catch (SQLException e) {
1399 LoaderException le = new LoaderException("SQLException: ", (Throwable)e);
1400 if (le.getCause().toString().equalsIgnoreCase("java.sql.SQLException"))
1401 le = new LoaderException("SQLException: ", new Throwable("Problem with source table : "+(iRowNumber+1)+". row"));
1402 this.echo.writeToLog("none", le.getCause().toString());
1403 throw le;
1404 } catch (NullPointerException e) {
1405 LoaderException le = new LoaderException("NullPointerException: ",
1406 (Throwable)e);
1407 this.echo.writeToLog("none", le.getCause().toString());
1408 throw le;
1409 } catch (SAXException e) {
1410 LoaderException le = new LoaderException("SAXException: ", (Throwable)e);
1411 this.echo.writeToLog("none", le.getCause().toString());
1412 throw le;
1413 } catch (Exception e) {
1414 LoaderException le = new LoaderException("Exception: ", (Throwable)e);
1415 this.echo.writeToLog("none", le.getCause().toString());
1416 throw le;
1417 }
1418 finally{
1419 try{
1420 this.echo.writeToLog("full", "loadSource method is finished.");
1421 if(connSource!=null)
1422 connSource.close();
1423 } catch (SQLException e) {
1424 LoaderException le = new LoaderException("SQLException: ", (Throwable)e);
1425 this.echo.writeToLog("none", le.getCause().toString());
1426 throw le;
1427 }
1428 }
1429 }
1430
1431 /***
1432 * Method parseImportJOB is used to analyse import XML file
1433 * about ImportDefinitions tags. Return number of importDefinition elements in whole xml file.
1434 * @param inStream Data from inputXML file which is converted into InputStream.
1435 * @return Number of ImportDefinitions tags in an input XML file.
1436 */
1437 private int parseImportJob (InputStream inStream) throws LoaderException {
1438 int iNumTagsImportJob = 0;
1439 Document doc = null;
1440 this.echo.writeToLog("full", "\tparseImportJob method is started.");
1441 try {
1442
1443 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
1444 DocumentBuilder db = null;
1445 db = dbf.newDocumentBuilder();
1446 doc = db.parse(inStream);
1447 } catch (Exception e) {
1448 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1449 LoaderException le = new LoaderException("Exception: ",
1450 (Throwable)e);
1451 throw le;
1452 // System.exit(1);
1453 }
1454 if (doc != null) {
1455 NodeList tagBasic = doc.getElementsByTagName("importDefinition");
1456 iNumTagsImportJob = tagBasic.getLength();
1457 Vector vecNames = new Vector();
1458 String strName = "";
1459 for (int i = 0; i < iNumTagsImportJob; i++) {
1460 strName = new String("");
1461 strName = importAttributeValue(doc, "importDefinition", "name",
1462 i);
1463 for (int j = 0; j < vecNames.size(); j++) {
1464 if (strName.equals("")) {
1465 this.echo.writeToLog("none", "Sorry, an error occurred: No importDefinition name .");
1466 LoaderException le = new LoaderException("Exception: ",
1467 (Throwable)(new Exception("Sorry, an error occurred: No importDefinition name .")));
1468 throw le;
1469 // System.exit(1);
1470 }
1471 if (strName.equalsIgnoreCase(vecNames.get(j).toString())) {
1472 this.echo.writeToLog("none", "Sorry, an error occurred: More importDefinition with same name :"
1473 + strName);
1474 LoaderException le = new LoaderException("Exception: ",
1475 (Throwable)(new Exception("Sorry, an error occurred: More importDefinition with same name :")));
1476 throw le;
1477 // System.exit(1);
1478 }
1479 }
1480 vecNames.addElement(strName);
1481 }
1482 }
1483 try {
1484 inStream.reset();
1485 } catch (IOException e) {
1486 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1487 LoaderException le = new LoaderException("IOException: ",
1488 (Throwable)e);
1489 throw le;
1490 // System.exit(1);
1491 }
1492 this.echo.writeToLog("full", "\tparseImportJob method is finished.");
1493 return iNumTagsImportJob;
1494 }
1495
1496 /***
1497 * Method parseSql is used to analyse import XML file
1498 * about sql tags. Return number of sql elements in a whole xml input file.
1499 * @param inStream Data from inputXML file which is converted into InputStream.
1500 * @return Number of sql tags in an input XML file.
1501 */
1502 private int parseSql(InputStream inStream) throws LoaderException{
1503 int iNumTagsImportJob = 0;
1504 Document doc = null;
1505 this.echo.writeToLog("full", "\tparseSql method is started.");
1506 try {
1507 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
1508 DocumentBuilder db = null;
1509 db = dbf.newDocumentBuilder();
1510 doc = db.parse(inStream);
1511 } catch (Exception e) {
1512 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1513 LoaderException le = new LoaderException("Exception: ",
1514 (Throwable)e);
1515 throw le;
1516 // System.exit(1);
1517 }
1518 if (doc != null) {
1519 NodeList tagBasic = doc.getElementsByTagName("sql");
1520 iNumTagsImportJob = tagBasic.getLength();
1521 }
1522 try {
1523 inStream.reset();
1524 } catch (IOException e) {
1525 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1526 LoaderException le = new LoaderException("IOxception: ",
1527 (Throwable)e);
1528 throw le;
1529 // System.exit(1);
1530 }
1531 this.echo.writeToLog("full", "\tparseSql method is finished.");
1532 return iNumTagsImportJob;
1533 }
1534
1535 /***
1536 * Method parseEchoElement is used to analyse import XML file
1537 * about echo tags. Return number of echo elements in a whole xml input file.
1538 * @param inStream Data from inputXML file which is converted into InputStream.
1539 * @return Number of echo tags in an input XML file.
1540 */
1541 private int parseEcho(InputStream inStream) throws LoaderException{
1542 int iNumTagsEcho = 0;
1543 Document doc = null;
1544 this.echo.writeToLog("full", "\tparseEcho method is started.");
1545 try {
1546 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
1547 DocumentBuilder db = null;
1548 db = dbf.newDocumentBuilder();
1549 doc = db.parse(inStream);
1550 } catch (Exception e) {
1551 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1552 LoaderException le = new LoaderException("Exception: ",
1553 (Throwable)e);
1554 throw le;
1555 }
1556 if (doc != null) {
1557 NodeList tagBasic = doc.getElementsByTagName("echo");
1558 iNumTagsEcho = tagBasic.getLength();
1559 String strMessage = "";
1560 for (int i = 0; i < iNumTagsEcho; i++) {
1561 strMessage = new String("");
1562 strMessage = importAttributeValue(doc, "echo", "message", i);
1563 if(strMessage!=null)
1564 echo.setMessage((new Integer(i)).toString(),strMessage);
1565 }
1566 }
1567 try {
1568 inStream.reset();
1569 } catch (IOException e) {
1570 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1571 LoaderException le = new LoaderException("IOxception: ",
1572 (Throwable)e);
1573 throw le;
1574 // System.exit(1);
1575 }
1576 this.echo.writeToLog("full", "\tparseSql method is finished.");
1577 return iNumTagsEcho;
1578 }
1579
1580 /***
1581 * Method parseMainElements is used to analyse import XML file
1582 * about main elements (sql and importDefinition). Puts names of elements (sql or importDefinition) in Vector.
1583 * @param inStream Data from inputXML file which is converted into InputStream.
1584 * @return Vector which elements are names of main elements in the same order as in XML import file .
1585 */
1586 private Vector parseMainElements (InputStream inStream) throws LoaderException{
1587 Vector vecLoaderElements = new Vector();
1588 Document doc = null;
1589 this.echo.writeToLog("full", "\tparseMainElements method is started.");
1590 try {
1591 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
1592 DocumentBuilder db = null;
1593 db = dbf.newDocumentBuilder();
1594 doc = db.parse(inStream);
1595 } catch (Exception e) {
1596 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1597 LoaderException le = new LoaderException("Exception: ",
1598 (Throwable)e);
1599 throw le;
1600 // System.exit(1);
1601 }
1602 if (doc != null) {
1603 NodeList tagBasic = doc.getElementsByTagName("loaderJob");
1604 NodeList nlMainElements = tagBasic.item(0).getChildNodes();
1605 for (int i = 0; i < nlMainElements.getLength(); i++) {
1606 String strTagName = nlMainElements.item(i).getNodeName();
1607 //Sinisa 22.02. Add EchoElement
1608 if (strTagName.equalsIgnoreCase("sql") || strTagName.equalsIgnoreCase("importDefinition") ||
1609 strTagName.equalsIgnoreCase("echo"))
1610 vecLoaderElements.addElement(strTagName);
1611 }
1612 }
1613 try {
1614 inStream.reset();
1615 } catch (IOException e) {
1616 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1617 LoaderException le = new LoaderException("IOException: ",
1618 (Throwable)e);
1619 throw le;
1620 // System.exit(1);
1621 }
1622 this.echo.writeToLog("full", "\tparseMainElements method is finished.");
1623 return vecLoaderElements;
1624 }
1625
1626 /***
1627 * Method parseImportJDBCParameters is used to analyse import XML file
1628 * about JDBC parameters tags. Puts values of first importDefinition's JDBC parameters in global variables.
1629 * @param inStream Data from inputXML file which is converted into InputStream.
1630 */
1631 private void parseImportJDBCParameters (InputStream inStream) throws LoaderException{
1632 Document doc = null;
1633 Vector vecJDBCTargetValue = new Vector();
1634 Vector vecJDBCTargetName = new Vector();
1635 this.echo.writeToLog("full", "\tparseImportJDBCParameters method is started.");
1636 try {
1637 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
1638 DocumentBuilder db = null;
1639 db = dbf.newDocumentBuilder();
1640 doc = db.parse(inStream);
1641 } catch (Exception e) {
1642 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1643 LoaderException le = new LoaderException("Exception: ",
1644 (Throwable)e);
1645 throw le;
1646 // System.exit(1);
1647 }
1648 if (doc != null) {
1649 this.strTargetDbVendor = this.importAttributeValue(doc, "jdbcTargetParameters",
1650 "dbVendor", 0);
1651 this.strTargetDriverName = this.importAttributeValue(doc, "jdbcTargetParameters",
1652 "driverName", 0);
1653 if (this.strTargetDbVendor.equals(""))
1654 this.strTargetDbVendor = this.strTargetDbVendorDefault;
1655 if (this.strTargetDbVendor.equals(""))
1656 this.strTargetDbVendor = "mssql";
1657 if (this.strTargetDriverName.equals(""))
1658 this.strTargetDriverName = this.strTargetDriverNameDefault;
1659 if (this.strTargetDriverName.equals("") && this.strTargetDbVendor.equalsIgnoreCase("mssql"))
1660 this.strTargetDriverName = "jturbo";
1661
1662 vecJDBCTargetValue = this.importValue(doc, "jdbcTargetParameter",
1663 "value", 0);
1664 vecJDBCTargetName = this.importValue(doc, "jdbcTargetParameter",
1665 "name", 0);
1666 for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
1667 if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
1668 this.strJDBCTargetParameterDriver = vecJDBCTargetValue.get(i).toString();
1669 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Connection.Url")) {
1670 //Testing SelectMethod parameter in microsoft MSSQL driver
1671 if(vecJDBCTargetValue.get(i).toString().indexOf("jdbc:microsoft:sqlserver")!=-1) {
1672 if(vecJDBCTargetValue.get(i).toString().indexOf("SelectMethod")==-1) {
1673 this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString()+";SelectMethod=cursor";
1674 } else if(vecJDBCTargetValue.get(i).toString().indexOf("cursor")!=-1) {
1675 this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
1676 } else {
1677 this.echo.writeToLog("none", "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor" );
1678 LoaderException le = new LoaderException("Exception: value of Connection.Url perameter SelectMethod has to be cursor");
1679 throw le;
1680 }
1681 }
1682 else {
1683 this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
1684 }
1685 }
1686 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("User"))
1687 this.strJDBCTargetParameterUser = vecJDBCTargetValue.get(i).toString();
1688 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Password"))
1689 this.strJDBCTargetParameterPassword = vecJDBCTargetValue.get(i).toString();
1690 }
1691
1692 if (vecJDBCTargetValue.size() == 0) {
1693 this.strJDBCTargetParameterDriver = this.strJDBCDefaultTargetParameterDriver;
1694 // if(this.strJDBCTargetParameterDriver.equals("")||this.strJDBCTargetParameterDriver==null)
1695 // this.strJDBCTargetParameterDriver=this.strTargetDriverClassName;
1696 this.strJDBCTargetParameterConnection = this.strJDBCDefaultTargetParameterConnection;
1697 this.strJDBCTargetParameterUser = this.strJDBCDefaultTargetParameterUser;
1698 this.strJDBCTargetParameterPassword = this.strJDBCDefaultTargetParameterPassword;
1699 }
1700 }
1701 try {
1702 inStream.reset();
1703 } catch (IOException e) {
1704 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1705 LoaderException le = new LoaderException("IOException: ",
1706 (Throwable)e);
1707 throw le;
1708 // System.exit(1);
1709 }
1710 this.echo.writeToLog("full", "\tparseImportJDBCParameters method is finished.");
1711 }
1712
1713 /***
1714 * Method parseImportJDBCDefaultParameters is used to analyse import XML file
1715 * about Default JDBC parameters tags.
1716 * @param inStream Data from inputXML file which is converted into InputStream.
1717 * @return boolean - true default jdbc parameters exists, false otherwise
1718 */
1719 private boolean parseImportJDBCDefaultParameters (InputStream inStream) throws LoaderException{
1720 Document doc = null;
1721 Vector vecJDBCTargetValue = new Vector();
1722 Vector vecJDBCTargetName = new Vector();
1723 Vector vecJDBCSourceValue = new Vector();
1724 Vector vecJDBCSourceName = new Vector();
1725 boolean isOK = false;
1726
1727 this.echo.writeToLog("full", "\tparseImportJDBCDefaultParameters method is started.");
1728 try {
1729 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
1730 DocumentBuilder db = null;
1731 db = dbf.newDocumentBuilder();
1732 doc = db.parse(inStream);
1733 } catch (Exception e) {
1734 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1735 LoaderException le = new LoaderException("Exception: ",
1736 (Throwable)e);
1737 throw le;
1738 // System.exit(1);
1739 }
1740 if (doc != null) {
1741 NodeList tagDefault = doc.getElementsByTagName("jdbcDefaultParameters");
1742 if (tagDefault.getLength() != 0) {
1743 Element docFragment = (Element)tagDefault.item(0);
1744 NodeList tag = docFragment.getElementsByTagName("jdbcSourceParameters");
1745 if (tag.getLength() != 0) {
1746 NamedNodeMap jdbc = tag.item(0).getAttributes();
1747 Node nodeJdbc = jdbc.getNamedItem("dbVendor");
1748 if (nodeJdbc != null)
1749 this.strDbVendorDefault = nodeJdbc.getNodeValue();
1750 nodeJdbc = jdbc.getNamedItem("driverName");
1751 if (nodeJdbc != null)
1752 this.strDriverNameDefault = nodeJdbc.getNodeValue();
1753 else {
1754 if(this.strDbVendorDefault.equalsIgnoreCase("mssql"))
1755 this.strDriverNameDefault = "jturbo";
1756 }
1757 }
1758 tag = docFragment.getElementsByTagName("jdbcTargetParameters");
1759 if (tag.getLength() != 0) {
1760 NamedNodeMap jdbc = tag.item(0).getAttributes();
1761 Node nodeJdbc = jdbc.getNamedItem("dbVendor");
1762 if (nodeJdbc != null)
1763 this.strTargetDbVendorDefault = nodeJdbc.getNodeValue();
1764 nodeJdbc = jdbc.getNamedItem("driverName");
1765 if (nodeJdbc != null)
1766 this.strTargetDriverNameDefault = nodeJdbc.getNodeValue();
1767 else {
1768 if(this.strTargetDbVendorDefault.equalsIgnoreCase("mssql"))
1769 this.strTargetDriverNameDefault = "jturbo";
1770 }
1771 }
1772 tag = docFragment.getElementsByTagName("jdbcSourceParameter");
1773 for (int i = 0; i < tag.getLength(); i++) {
1774 String nodeValueValue = "";
1775 String nodeNameValue = "";
1776 NamedNodeMap attrs = tag.item(i).getAttributes();
1777 Node nodeValue = attrs.getNamedItem("value");
1778 Node nodeName = attrs.getNamedItem("name");
1779 if (nodeValue != null && nodeName != null) {
1780 nodeValueValue = nodeValue.getNodeValue();
1781 nodeNameValue = nodeName.getNodeValue();
1782 }
1783 vecJDBCSourceValue.addElement(nodeValueValue);
1784 vecJDBCSourceName.addElement(nodeNameValue);
1785 }
1786 for (int i = 0; i < vecJDBCSourceValue.size(); i++) {
1787 if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
1788 this.strJDBCDefaultSourceParameterDriver = vecJDBCSourceValue.get(i).toString();
1789 else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("Connection.Url")) {
1790 //Testing SelectMethod parameter in microsoft MSSQL driver
1791 if(vecJDBCSourceValue.get(i).toString().indexOf("jdbc:microsoft:sqlserver")!=-1) {
1792 if(vecJDBCSourceValue.get(i).toString().indexOf("SelectMethod")==-1) {
1793 this.strJDBCDefaultSourceParameterConnection = vecJDBCSourceValue.get(i).toString()+";SelectMethod=cursor";
1794 } else {
1795 if(vecJDBCSourceValue.get(i).toString().indexOf("cursor")!=-1) {
1796 this.strJDBCDefaultSourceParameterConnection = vecJDBCSourceValue.get(i).toString();
1797 } else {
1798 this.echo.writeToLog("none", "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor" );
1799 LoaderException le = new LoaderException("Exception: value of Connection.Url perameter SelectMethod has to be cursor");
1800 throw le;
1801 }
1802 }
1803 } else {
1804 this.strJDBCDefaultSourceParameterConnection = vecJDBCSourceValue.get(i).toString();
1805 }
1806 }
1807 else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("User"))
1808 this.strJDBCDefaultSourceParameterUser = vecJDBCSourceValue.get(i).toString();
1809 else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("Password"))
1810 this.strJDBCDefaultSourceParameterPassword = vecJDBCSourceValue.get(i).toString();
1811 }
1812 tag = docFragment.getElementsByTagName("jdbcTargetParameter");
1813 for (int i = 0; i < tag.getLength(); i++) {
1814 String nodeValueValue = "";
1815 String nodeNameValue = "";
1816 NamedNodeMap attrs = tag.item(i).getAttributes();
1817 Node nodeValue = attrs.getNamedItem("value");
1818 Node nodeName = attrs.getNamedItem("name");
1819 if (nodeValueValue != null && nodeName != null) {
1820 nodeValueValue = nodeValue.getNodeValue();
1821 nodeNameValue = nodeName.getNodeValue();
1822 }
1823 vecJDBCTargetValue.addElement(nodeValueValue);
1824 vecJDBCTargetName.addElement(nodeNameValue);
1825 }
1826 for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
1827 if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
1828 this.strJDBCDefaultTargetParameterDriver = vecJDBCTargetValue.get(i).toString();
1829 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Connection.Url")) {
1830 //Testing SelectMethod parameter in microsoft MSSQL driver
1831 if(vecJDBCTargetValue.get(i).toString().indexOf("jdbc:microsoft:sqlserver")!=-1) {
1832 if(vecJDBCTargetValue.get(i).toString().indexOf("SelectMethod")==-1) {
1833 this.strJDBCDefaultTargetParameterConnection = vecJDBCTargetValue.get(i).toString()+";SelectMethod=cursor";
1834 } else {
1835 if(vecJDBCTargetValue.get(i).toString().indexOf("cursor")!=-1) {
1836 this.strJDBCDefaultTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
1837 } else {
1838 this.echo.writeToLog("none", "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor" );
1839 LoaderException le = new LoaderException("Exception: value of Connection.Url perameter SelectMethod has to be cursor");
1840 throw le;
1841 }
1842 }
1843 } else {
1844 this.strJDBCDefaultTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
1845 }
1846 }
1847 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("User"))
1848 this.strJDBCDefaultTargetParameterUser = vecJDBCTargetValue.get(i).toString();
1849 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Password"))
1850 this.strJDBCDefaultTargetParameterPassword = vecJDBCTargetValue.get(i).toString();
1851 }
1852 }
1853 isOK=true;
1854 }
1855 try {
1856 inStream.reset();
1857 } catch (IOException e) {
1858 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1859 LoaderException le = new LoaderException("IOException: ",
1860 (Throwable)e);
1861 throw le;
1862 // System.exit(1);
1863 }
1864 this.echo.writeToLog("full", "\tparseImportJDBCDefaultParameters method is finished.");
1865 return isOK;
1866 }
1867
1868 /***
1869 * Method importRestartCounter is used to analyse import XML file
1870 * and read restart counter attributes. Values of these attributes puts in Vectors
1871 * @param inStream Data from inputXML file which is converted into InputStream.
1872 */
1873 private void importRestartCounter (InputStream inStream) throws LoaderException{
1874 Document doc = null;
1875 this.echo.writeToLog("full", "\timportRestartCounter method is started.");
1876 try {
1877 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
1878 DocumentBuilder db = null;
1879 db = dbf.newDocumentBuilder();
1880 doc = db.parse(inStream);
1881 } catch (Exception e) {
1882 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1883 LoaderException le = new LoaderException("Exception: ",
1884 (Throwable)e);
1885 throw le;
1886 // System.exit(1);
1887 }
1888 if (doc != null) {
1889 NodeList tagRestartCounter = doc.getElementsByTagName("restartCounter");
1890 if (tagRestartCounter.getLength() != 0) {
1891 this.hasRestartCounter = true;
1892 NamedNodeMap attrs = tagRestartCounter.item(0).getAttributes();
1893 Node nodeResult = attrs.getNamedItem("tableName");
1894 if (nodeResult != null)
1895 this.strRestartCounterTableName = nodeResult.getNodeValue();
1896 else
1897 this.strRestartCounterTableName = "LOADERRESTART";
1898 nodeResult = attrs.getNamedItem("importDefinitionColumnName");
1899 if (nodeResult != null)
1900 this.strRestartCounterImportDefinitionName = nodeResult.getNodeValue();
1901 else
1902 this.strRestartCounterImportDefinitionName = "IMPORTDEFINITION";
1903 nodeResult = attrs.getNamedItem("restartCounterColumnName");
1904 if (nodeResult != null)
1905 this.strRestartCounterValue = nodeResult.getNodeValue();
1906 else
1907 this.strRestartCounterValue = "RESTARTCOUNTER";
1908 nodeResult = attrs.getNamedItem("restartAutoCreate");
1909 if (nodeResult != null)
1910 this.bRestartAutoCreate = (new Boolean(nodeResult.getNodeValue())).booleanValue();
1911 else
1912 this.bRestartAutoCreate = false;
1913 }
1914 }
1915 try {
1916 inStream.reset();
1917 } catch (IOException e) {
1918 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1919 LoaderException le = new LoaderException("IOException: ",
1920 (Throwable)e);
1921 throw le;
1922 // System.exit(1);
1923 }
1924 this.echo.writeToLog("full", "\timportRestartCounter method is finished.");
1925 }
1926
1927 /***
1928 * Method importLoaderJobAttributes is used to analyse import XML file
1929 * about attributes of root element(loaderJob). Values of these attributes puts in global variables.
1930 * @param inputStream Data from inputXML file which is converted into InputStream.
1931 */
1932 private void importLoaderJobAttributes (InputStream inputStream) throws LoaderException{
1933 Document doc = null;
1934 this.echo.writeToLog("full", "\timportLoaderJobAttributes method is started.");
1935 try {
1936 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
1937 DocumentBuilder db = null;
1938 db = dbf.newDocumentBuilder();
1939 doc = db.parse(inputStream);
1940 } catch (Exception e) {
1941 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
1942 LoaderException le = new LoaderException("Exception: ",
1943 (Throwable)e);
1944 throw le;
1945 // System.exit(1);
1946 }
1947 if (doc != null) {
1948 NodeList tagRestartCounter = doc.getElementsByTagName("loaderJob");
1949 if (tagRestartCounter.getLength() != 0) {
1950 NamedNodeMap attrs = tagRestartCounter.item(0).getAttributes();
1951 Node nodeResult = attrs.getNamedItem("logMode");
1952 if (nodeResult != null)
1953 this.strDefaultLogMode = nodeResult.getNodeValue();
1954 nodeResult = attrs.getNamedItem("objectIDIncrement");
1955 String strIncrement = "";
1956 if (nodeResult != null)
1957 strIncrement = nodeResult.getNodeValue();
1958 if (!strIncrement.equals(""))
1959 this.iDefaultObjectIDIncrement = Integer.parseInt(strIncrement);
1960 nodeResult = attrs.getNamedItem("objectIDTableName");
1961 if (nodeResult != null)
1962 this.strDefaultObjectIDTableName = nodeResult.getNodeValue();
1963 nodeResult = attrs.getNamedItem("objectIDColumnName");
1964 if (nodeResult != null)
1965 this.strDefaultObjectIDColumnName = nodeResult.getNodeValue();
1966
1967 nodeResult = attrs.getNamedItem("objectIDNameColumnName");
1968 if (nodeResult != null)
1969 this.strDefaultObjectIDNameColumnName = nodeResult.getNodeValue();
1970
1971 nodeResult = attrs.getNamedItem("objectIDNameColumnValue");
1972 if (nodeResult != null)
1973 this.strDefaultObjectIDNameColumnValue = nodeResult.getNodeValue();
1974
1975 nodeResult = attrs.getNamedItem("onErrorContinue");
1976 if (nodeResult != null)
1977 this.bDefaultOnErrorContinue = (new Boolean(nodeResult.getNodeValue())).booleanValue();
1978 nodeResult = attrs.getNamedItem("commit");
1979 if (nodeResult != null)
1980 this.bDefaultCommit = (new Boolean(nodeResult.getNodeValue())).booleanValue();
1981 nodeResult = attrs.getNamedItem("userID");
1982 if (nodeResult != null)
1983 this.strDefaultUserID = nodeResult.getNodeValue();
1984 nodeResult = attrs.getNamedItem("logDir");
1985 if (nodeResult != null)
1986 this.strDefaultLogDir = nodeResult.getNodeValue();
1987 nodeResult = attrs.getNamedItem("logFile");
1988 if (nodeResult != null)
1989 this.strDefaultLogFile = nodeResult.getNodeValue();
1990 nodeResult = attrs.getNamedItem("vendorConfig");
1991 if (nodeResult != null)
1992 this.strDefaultVendorConfig = nodeResult.getNodeValue();
1993 nodeResult = attrs.getNamedItem("objectIDAutoCreate");
1994 if (nodeResult != null)
1995 this.bDefaultObjectIDAutoCreate = (new Boolean(nodeResult.getNodeValue())).booleanValue();
1996 nodeResult = attrs.getNamedItem("objectIDStartValue");
1997 if (nodeResult != null)
1998 this.iDefaultObjectIDStartValue = Integer.parseInt(nodeResult.getNodeValue());
1999 nodeResult = attrs.getNamedItem("commitCount");
2000 if (nodeResult != null)
2001 this.iDefaultCommitCount = Integer.parseInt(nodeResult.getNodeValue());
2002 nodeResult = attrs.getNamedItem("oidLogic");
2003 if (nodeResult != null)
2004 this.bDefaultOidLogic = (new Boolean(nodeResult.getNodeValue())).booleanValue();
2005 nodeResult = attrs.getNamedItem("tableMode");
2006 if (nodeResult != null)
2007 this.strDefaultTableMode = nodeResult.getNodeValue();
2008 nodeResult = attrs.getNamedItem("returnCode");
2009 if (nodeResult != null) {
2010 if(!ReturnCode.isParameter)
2011 ReturnCode.setDefaultErrorReturnCode(Integer.parseInt(nodeResult.getNodeValue()));
2012 }
2013 }
2014 }
2015 try {
2016 inputStream.reset();
2017 } catch (IOException e) {
2018 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
2019 LoaderException le = new LoaderException("IOException: ",
2020 (Throwable)e);
2021 throw le;
2022 // System.exit(1);
2023 }
2024 this.echo.writeToLog("full", "\timportLoaderJobAttributes method is finished.");
2025 }
2026
2027 /***
2028 * Method importSQLStatement imports sql attributes from xml file and puts them in the global variables.
2029 * Return Vector. It's elements are strings which represents sql statements.
2030 * @param inStream Data from inputXML file which is converted into InputStream.
2031 * @param iSqlItem Number of sql tag in XML file which will be analised.
2032 */
2033 private Vector importSQLStatement (InputStream inStream, int iSqlItem)throws LoaderException {
2034 Vector strValue = new Vector();
2035 Vector vecJDBCTargetValue = new Vector();
2036 Vector vecJDBCTargetName = new Vector();
2037 Document doc = null;
2038 String strNodeValue = "";
2039 this.echo.writeToLog("full", "\timportSQLStatement method is started.");
2040 try {
2041 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
2042 DocumentBuilder db = null;
2043 db = dbf.newDocumentBuilder();
2044 doc = db.parse(inStream);
2045 if (doc != null) {
2046 NodeList tagBasic = doc.getElementsByTagName("sql");
2047 if (tagBasic.getLength() != 0) {
2048 Element docFragment = (Element)tagBasic.item(iSqlItem);
2049 this.strSqlName = docFragment.getAttribute("name");
2050 this.strSqlLogMode = docFragment.getAttribute("logMode");
2051 if (this.strSqlLogMode.equals("")) {
2052 if (this.strLogMode.equals(""))
2053 this.strSqlLogMode = this.strDefaultLogMode;
2054 else
2055 this.strSqlLogMode = this.strLogMode;
2056 }
2057 this.strSqlOnErrorContinue = docFragment.getAttribute("onErrorContinue");
2058 if (this.strSqlOnErrorContinue.equals("")) {
2059 if (this.bOnErrorContinue == true)
2060 this.strSqlOnErrorContinue = "true";
2061 else
2062 this.strSqlOnErrorContinue = (new Boolean(this.bDefaultOnErrorContinue)).toString();
2063 }
2064 this.strSqlCommit = docFragment.getAttribute("commit");
2065 if (this.strSqlCommit.equals("")) {
2066 this.strSqlCommit = (new Boolean(this.bDefaultCommit)).toString();
2067 }
2068 String strReturnCode = docFragment.getAttribute("returnCode");
2069 if (!strReturnCode.equals("")){
2070 ReturnCode.setErrorReturnCode(Integer.parseInt(strReturnCode));
2071 }
2072 else
2073 ReturnCode.setErrorReturnCode(ReturnCode.getDefaultErrorReturnCode());
2074
2075 this.strTargetDbVendor = this.importAttributeValue(docFragment.getOwnerDocument(),
2076 "jdbcTargetParameters", "dbVendor", 0);
2077 this.strTargetDriverName = this.importAttributeValue(docFragment.getOwnerDocument(),
2078 "jdbcTargetParameters", "driverName", 0);
2079 if (this.strTargetDbVendor.equals(""))
2080 this.strTargetDbVendor = this.strTargetDbVendorDefault;
2081 if (this.strTargetDbVendor.equals(""))
2082 this.strTargetDbVendor = "mssql";
2083 if (this.strTargetDriverName.equals(""))
2084 this.strTargetDriverName = this.strTargetDriverNameDefault;
2085 if (this.strTargetDriverName.equals("") && this.strTargetDbVendor.equalsIgnoreCase("mssql"))
2086 this.strTargetDriverName = "jturbo";
2087 // readConfigValues(this.strTargetDbVendor, "target");
2088 NodeList tag = docFragment.getElementsByTagName("jdbcTargetParameter");
2089 for (int i = 0; i < tag.getLength(); i++) {
2090 String nodeValueValue = "";
2091 String nodeNameValue = "";
2092 NamedNodeMap attrs = tag.item(i).getAttributes();
2093 Node nodeValue = attrs.getNamedItem("value");
2094 Node nodeName = attrs.getNamedItem("name");
2095 if (nodeValueValue != null && nodeName != null) {
2096 nodeValueValue = nodeValue.getNodeValue();
2097 nodeNameValue = nodeName.getNodeValue();
2098 }
2099 vecJDBCTargetValue.addElement(nodeValueValue);
2100 vecJDBCTargetName.addElement(nodeNameValue);
2101 }
2102 for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
2103 if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
2104 this.strJDBCTargetParameterDriver = vecJDBCTargetValue.get(i).toString();
2105 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Connection.Url")) {
2106 //Testing SelectMethod parameter in microsoft MSSQL driver
2107 if(vecJDBCTargetValue.get(i).toString().indexOf("jdbc:microsoft:sqlserver")!=-1) {
2108 if(vecJDBCTargetValue.get(i).toString().indexOf("SelectMethod")==-1) {
2109 this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString()+";SelectMethod=cursor";
2110 } else if(vecJDBCTargetValue.get(i).toString().indexOf("cursor")!=-1) {
2111 this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
2112 } else {
2113 this.echo.writeToLog("none", "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor" );
2114 LoaderException le = new LoaderException("Exception: value of Connection.Url perameter SelectMethod has to be cursor");
2115 throw le;
2116 }
2117 }
2118 else {
2119 this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
2120 }
2121 }
2122 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("User"))
2123 this.strJDBCTargetParameterUser = vecJDBCTargetValue.get(i).toString();
2124 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Password"))
2125 this.strJDBCTargetParameterPassword = vecJDBCTargetValue.get(i).toString();
2126 }
2127 if (vecJDBCTargetValue.size() == 0) {
2128 this.strJDBCTargetParameterDriver = this.strJDBCDefaultTargetParameterDriver;
2129 // if(this.strJDBCTargetParameterDriver.equals("")||this.strJDBCTargetParameterDriver==null)
2130 // this.strJDBCTargetParameterDriver=this.strTargetDriverClassName;
2131 this.strJDBCTargetParameterConnection = this.strJDBCDefaultTargetParameterConnection;
2132 this.strJDBCTargetParameterUser = this.strJDBCDefaultTargetParameterUser;
2133 this.strJDBCTargetParameterPassword = this.strJDBCDefaultTargetParameterPassword;
2134 }
2135 if(this.strJDBCTargetParameterDriver.equals("")||this.strJDBCTargetParameterDriver==null)
2136 this.strJDBCTargetParameterDriver=this.strTargetDriverClassName;
2137 readConfigValues(this.strTargetDbVendor,this.strTargetDriverName, "target");
2138 NodeList targetTag = docFragment.getElementsByTagName("sqlStmt");
2139 for (int i = 0; i < targetTag.getLength(); i++) {
2140 NodeList nodeText = targetTag.item(i).getChildNodes();
2141 if (nodeText.item(0) != null) {
2142 strNodeValue = nodeText.item(0).getNodeValue();
2143 strValue.addElement(strNodeValue);
2144 }
2145 }
2146 }
2147 }
2148 } catch (Exception e) {
2149 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
2150 LoaderException le = new LoaderException("Exception: ",
2151 (Throwable)e);
2152 throw le;
2153 // System.exit(1);
2154 }
2155 try {
2156 inStream.reset();
2157 } catch (IOException e) {
2158 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
2159 LoaderException le = new LoaderException("IOException: ",
2160 (Throwable)e);
2161 throw le;
2162 // System.exit(1);
2163 }
2164 this.echo.writeToLog("full", "\timportSQLStatement method is finished.");
2165 return strValue;
2166 }
2167
2168 /***
2169 * Method importVariable imports sql attributes from xml file and puts them in the global variables.
2170 * Return Vector. It's elements are strings which represents sql statements.
2171 * @param inStream Data from inputXML file which is converted into InputStream.
2172 * @param iSqlItem Number of sql tag in XML file which will be analised.
2173 */
2174 private void importVariable (InputStream inStream) throws LoaderException{
2175 Document doc = null;
2176 String strNodeValue = "";
2177 String strDefaultVariableOverride = "";
2178 String strDefaultReplaceInConstants = "";
2179 String strDefaultReplaceInSQL = "";
2180 String strDefaultReplaceInData = "";
2181 String strDefaultReplaceInJDBC = "";
2182 String strDefaultVariablePrefix = "";
2183 String strDefaultVariableSufix = "";
2184 this.echo.writeToLog("full", "\timportVariable method is started.");
2185 try {
2186 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
2187 DocumentBuilder db = null;
2188 db = dbf.newDocumentBuilder();
2189 doc = db.parse(inStream);
2190 if (doc != null) {
2191 NodeList tagBasic = doc.getElementsByTagName("variables");
2192 if (tagBasic.getLength() != 0) {
2193 Element docFragment = (Element)tagBasic.item(0);
2194 strDefaultVariablePrefix = docFragment.getAttribute("prefix");
2195 if (strDefaultVariablePrefix.equals(""))
2196 strDefaultVariablePrefix = "%";
2197 strDefaultVariableSufix = docFragment.getAttribute("suffix");
2198 if (strDefaultVariableSufix.equals(""))
2199 strDefaultVariableSufix = "%";
2200 strDefaultVariableOverride = docFragment.getAttribute("override");
2201 if (strDefaultVariableOverride.equals(""))
2202 strDefaultVariableOverride = "true";
2203 strDefaultReplaceInConstants = docFragment.getAttribute("replaceInConstants");
2204 if (strDefaultReplaceInConstants.equals(""))
2205 strDefaultReplaceInConstants = "false";
2206 strDefaultReplaceInSQL = docFragment.getAttribute("replaceInSQL");
2207 if (strDefaultReplaceInSQL.equals(""))
2208 strDefaultReplaceInSQL = "false";
2209 strDefaultReplaceInData = docFragment.getAttribute("replaceInData");
2210 if (strDefaultReplaceInData.equals(""))
2211 strDefaultReplaceInData = "false";
2212 strDefaultReplaceInJDBC = docFragment.getAttribute("replaceInJDBC");
2213 if (strDefaultReplaceInJDBC.equals(""))
2214 strDefaultReplaceInJDBC = "false";
2215 NodeList tag = docFragment.getElementsByTagName("variable");
2216 this.vecVariableName = getAttributeValues(tag, "name",
2217 null);
2218 this.vecVariableValue = getAttributeValues(tag, "value",
2219 null);
2220 this.vecVariablePrefix = getAttributeValues(tag, "prefix",
2221 strDefaultVariablePrefix);
2222 this.vecVariableSufix = getAttributeValues(tag, "suffix",
2223 strDefaultVariableSufix);
2224 this.vecVariableOverride = getAttributeValues(tag, "override",
2225 strDefaultVariableOverride);
2226 this.vecReplaceInConstants = getAttributeValues(tag, "replaceInConstants",
2227 strDefaultReplaceInConstants);
2228 this.vecReplaceInSQL = getAttributeValues(tag, "replaceInSQL",
2229 strDefaultReplaceInSQL);
2230 this.vecReplaceInData = getAttributeValues(tag, "replaceInData",
2231 strDefaultReplaceInData);
2232 this.vecReplaceInJDBC = getAttributeValues(tag, "replaceInJDBC",
2233 strDefaultReplaceInJDBC);
2234 for (int i = 0; i < this.vecVariableOverride.size(); i++) {
2235 if (this.vecVariableOverride.get(i).toString().equalsIgnoreCase("true")) {
2236 if (this.mapVariableValues.get(this.vecVariableName.get(i))
2237 == null)
2238 this.vecVariableValue.setElementAt(null, i);
2239 else
2240 this.vecVariableValue.setElementAt(this.mapVariableValues.get(this.vecVariableName.get(i).toString()).toString(),
2241 i);
2242 }
2243 }
2244 }
2245 }
2246 } catch (Exception e) {
2247 this.echo.writeToLog("none", "Sorry, an error with the variables occurred: "
2248 + e);
2249 LoaderException le = new LoaderException("Exception: ",
2250 (Throwable)e);
2251 throw le;
2252 // System.exit(1);
2253 }
2254 try {
2255 inStream.reset();
2256 } catch (IOException e) {
2257 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
2258 LoaderException le = new LoaderException("IOException: ",
2259 (Throwable)e);
2260 throw le;
2261 // System.exit(1);
2262 }
2263 this.echo.writeToLog("full", "\timportVariable method is finished.");
2264 }
2265
2266 /***
2267 * put your documentation comment here
2268 * @param tags
2269 * @param attrName
2270 * @param defaultValue
2271 * @return
2272 */
2273 private Vector getAttributeValues (NodeList tags, String attrName, String defaultValue) {
2274 Vector vecValues = new Vector();
2275 String nodeValue = "";
2276 if (attrName != null) {
2277 for (int i = 0; i < tags.getLength(); i++) {
2278 NamedNodeMap attrs = tags.item(i).getAttributes();
2279 Node nodeResult = attrs.getNamedItem(attrName);
2280 if (nodeResult != null)
2281 nodeValue = nodeResult.getNodeValue();
2282 else
2283 nodeValue = defaultValue;
2284 vecValues.addElement(nodeValue);
2285 }
2286 }
2287 return vecValues;
2288 }
2289
2290 /***
2291 * Method parseAndImport is used to analyse the importDefinition no. l in xml file and
2292 * input all values and puts them into global variables.
2293 * If there is an error, Exception "SAXException" is thrown.
2294 * @param inStream Data from inputXML file which is converted into InputStream.
2295 * @param l Number of ImportDefinition tag which is processed.
2296 * @throws SAXException Constructs an JAXP 1.1 Exception with the specified detail message.
2297 * @throws Exception Constructs an Exception with the specified detail message.
2298 */
2299 private void parseAndImport (InputStream inStream, int l) throws SAXException, LoaderException,
2300 Exception {
2301 this.echo.writeToLog("full", "\tparseAndImport method is started.");
2302 Document doc = null;
2303 try {
2304 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
2305 DocumentBuilder db = null;
2306 db = dbf.newDocumentBuilder();
2307 doc = db.parse(inStream);
2308 } catch (SAXException e) {
2309 throw e;
2310 } catch (Exception e) {
2311 throw e;
2312 }
2313 if (doc != null)
2314 this.importXMLFile(doc, l);
2315 try {
2316 inStream.reset();
2317 } catch (IOException e) {
2318 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
2319 LoaderException le = new LoaderException("IOException: ",
2320 (Throwable)e);
2321 throw le;
2322 // System.exit(1);
2323 }
2324 this.echo.writeToLog("full", "\tparseAndImport method is finished.");
2325 }
2326
2327 /***
2328 * Method importAttributeValue reads value for strAttrName attribute in strTagName tag.
2329 * This method return this value.
2330 * @param doc Parsed import XML file.
2331 * @param strTagName The name of tag where attribute is situated.
2332 * @param strAttrName The name of tag attribute which reads input value.
2333 * @param iImportJobItem Number of ImportDefinition tag which is processed.
2334 * @return String - importing value.
2335 */
2336 private String importAttributeValue (Document doc, String strTagName, String strAttrName,
2337 int iImportJobItem) {
2338 String strValue = "";
2339 NodeList tagBasic = doc.getElementsByTagName(strTagName);
2340 Element docFragment = (Element)tagBasic.item(iImportJobItem);
2341 if (docFragment != null)
2342 strValue = docFragment.getAttribute(strAttrName);
2343 return strValue;
2344 }
2345
2346 /***
2347 * Method importAttribute reads value for strAttrName attribute in strTagName tag.
2348 * This method return this value.
2349 * @param doc Parsed import XML file.
2350 * @param strTagName The name of tag where attribute is situated.
2351 * @param strAttrName The name of tag attribute which reads input value.
2352 * @param iImportJobItem Number of ImportDefinition tag which is processed.
2353 * @return String - importing value.
2354 */
2355 private String importAttribute(Document doc, String strTagName, String strAttrName,
2356 int iImportJobItem) {
2357 String strValue = "";
2358 NodeList tagBasic = doc.getElementsByTagName("importDefinition");
2359 if (tagBasic.getLength() != 0) {
2360 Element docFragment = (Element)tagBasic.item(iImportJobItem);
2361 // NodeList tag = docFragment.getElementsByTagName(tagName);
2362 // for (int i = 0; i < tag.getLength(); i++) {
2363
2364 tagBasic = docFragment.getElementsByTagName(strTagName);
2365 if(tagBasic.getLength()!=0) {
2366 docFragment = (Element)tagBasic.item(0);
2367 if (docFragment != null)
2368 strValue = docFragment.getAttribute(strAttrName);
2369 }
2370 }
2371 return strValue;
2372 }
2373
2374
2375
2376
2377
2378 /***
2379 * Method importValue reads values from desired XML tag and puts them into Vector.
2380 * @param doc Parsed import XML file.
2381 * @param tagName The name of XML tag.
2382 * @param strAttrName The name of tag attribute which reads input strValue.
2383 * @param iImportJobItem Number of ImportDefinition tag which is processed.
2384 * @return Vector of importing values.
2385 */
2386 private Vector importValue (Document doc, String tagName, String strAttrName,
2387 int iImportJobItem) {
2388 Vector strValue = new Vector();
2389 NodeList tagBasic = doc.getElementsByTagName("importDefinition");
2390 if (tagBasic.getLength() != 0) {
2391 Element docFragment = (Element)tagBasic.item(iImportJobItem);
2392 NodeList tag = docFragment.getElementsByTagName(tagName);
2393 for (int i = 0; i < tag.getLength(); i++) {
2394 String nodeValue = "";
2395 if (strAttrName != null) {
2396 NamedNodeMap attrs = tag.item(i).getAttributes();
2397 Node nodeResult = attrs.getNamedItem(strAttrName);
2398 if (nodeResult != null)
2399 nodeValue = nodeResult.getNodeValue();
2400 strValue.addElement(nodeValue);
2401 }
2402 else {
2403 NodeList nodeText = tag.item(i).getChildNodes();
2404 if (nodeText.item(0) != null) {
2405 nodeValue = nodeText.item(0).getNodeValue();
2406 strValue.addElement(nodeValue);
2407 }
2408 }
2409 }
2410 }
2411 return strValue;
2412 }
2413
2414 /***
2415 * Method importValue reads values from desired XML tag and puts them into Vector.
2416 * @param doc Parsed import XML file.
2417 * @param tagName The name of XML tag.
2418 * @param strAttrName The name of tag attribute which reads input strValue.
2419 * @param iImportJobItem Number of ImportDefinition tag which is processed.
2420 * @param defaultValue The default value of strattrname attribute.
2421 * @return Vector of importing values.
2422 */
2423 private Vector importValue (Document doc, String tagName, String strAttrName,
2424 int iImportJobItem, String defaultValue) {
2425 Vector strValue = new Vector();
2426 NodeList tagBasic = doc.getElementsByTagName("importDefinition");
2427 if (tagBasic.getLength() != 0) {
2428 Element docFragment = (Element)tagBasic.item(iImportJobItem);
2429 NodeList tag = docFragment.getElementsByTagName(tagName);
2430 for (int i = 0; i < tag.getLength(); i++) {
2431 String nodeValue = "";
2432 if (strAttrName != null) {
2433 NamedNodeMap attrs = tag.item(i).getAttributes();
2434 Node nodeResult = attrs.getNamedItem(strAttrName);
2435 if (nodeResult != null)
2436 nodeValue = nodeResult.getNodeValue();
2437 else
2438 nodeValue = defaultValue;
2439 strValue.addElement(nodeValue);
2440 }
2441 else {
2442 NodeList nodeText = tag.item(i).getChildNodes();
2443 if (nodeText.item(0) != null) {
2444 nodeValue = nodeText.item(0).getNodeValue();
2445 strValue.addElement(nodeValue);
2446 }
2447 }
2448 }
2449 }
2450 return strValue;
2451 }
2452
2453 /***
2454 * Method importXMLFile is used for setting of global variables
2455 * during importing values from XML file.
2456 * This method validates the imported data from XML file.
2457 * If there is an error Exception "NullPointerException" or "Exception" is thrown.
2458 * @param doc Parsed imports XML file.
2459 * @param iJobNumber Number of ImportJob tag which is processed.
2460 * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
2461 * @throws Exception Constructs an Exception with the specified detail message.
2462 */
2463 private void importXMLFile (Document doc, int iJobNumber) throws NullPointerException,
2464 Exception {
2465 this.echo.writeToLog("full", "\timportXMLFile method is started.");
2466 Vector vecValueColumnSourceColumnName = new Vector();
2467 Vector vecValueColumnTargetTableName = new Vector();
2468 Vector vecValueColumnTargetColumnName = new Vector();
2469 Vector vecValueColumnTargetTableID = new Vector();
2470 Vector vecValueColumnValueMode = new Vector();
2471 Vector vecConstantColumnTargetColumnName = new Vector();
2472 Vector vecConstantColumnValueMode = new Vector();
2473 Vector vecConstantColumnConstantValue = new Vector();
2474 Vector vecRestartCounterVector = new Vector();
2475 Vector vecJDBCSourceName = new Vector();
2476 Vector vecJDBCSourceValue = new Vector();
2477 Vector vecJDBCTargetName = new Vector();
2478 Vector vecJDBCTargetValue = new Vector();
2479 int iNumberOfColumns = 0;
2480
2481 try {
2482 this.strImportDefinitionName = this.importAttributeValue(doc, "importDefinition",
2483 "name", iJobNumber);
2484 this.strImportDefinitionTableName = this.importAttributeValue(doc,
2485 "importDefinition", "tableName", iJobNumber);
2486 String strCommitCount = this.importAttributeValue(doc, "importDefinition",
2487 "commitCount", iJobNumber);
2488 if (!strCommitCount.equals(""))
2489 this.iImportDefinitionCommitCount = Integer.parseInt(this.importAttributeValue(doc,
2490 "importDefinition", "commitCount", iJobNumber));
2491 else {
2492 if (this.iCommitCount != 0)
2493 this.iImportDefinitionCommitCount = this.iCommitCount;
2494 else
2495 this.iImportDefinitionCommitCount = this.iDefaultCommitCount;
2496 }
2497 this.strImportDefinitionLogMode = this.importAttributeValue(doc,
2498 "importDefinition", "logMode", iJobNumber);
2499 if (this.strImportDefinitionLogMode.equals("")) {
2500 if (this.strLogMode.equals(""))
2501 this.strImportDefinitionLogMode = this.strDefaultLogMode;
2502 else
2503 this.strImportDefinitionLogMode = this.strLogMode;
2504 }
2505
2506 this.strImportDefinitionSelectStatement = this.importAttributeValue(doc,
2507 "importDefinition", "selectStatement", iJobNumber);
2508
2509 String strIncrement = this.importAttributeValue(doc, "importDefinition",
2510 "objectIDIncrement", iJobNumber);
2511 if (!strIncrement.equals(""))
2512 this.iObjectID = Integer.parseInt(strIncrement);
2513 else
2514 this.iObjectID = this.iDefaultObjectIDIncrement;
2515 this.strObjectIDTableName = this.importAttributeValue(doc, "importDefinition",
2516 "objectIDTableName", iJobNumber);
2517 if (this.strObjectIDTableName.equals(""))
2518 this.strObjectIDTableName = this.strDefaultObjectIDTableName;
2519 this.strObjectIDColumnName = this.importAttributeValue(doc, "importDefinition",
2520 "objectIDColumnName", iJobNumber);
2521
2522 //TOS
2523 this.strObjectIDNameColumnName= this.importAttributeValue(doc, "importDefinition",
2524 "objectIDNameColumnName", iJobNumber);
2525 this.strObjectIDNameColumnValue= this.importAttributeValue(doc, "importDefinition",
2526 "objectIDNameColumnValue", iJobNumber);
2527
2528 if(this.strObjectIDNameColumnName.equals("")) {
2529 this.strObjectIDNameColumnName = this.strDefaultObjectIDNameColumnName;
2530 }
2531 if(this.strObjectIDNameColumnValue.equals("")) {
2532 this.strObjectIDNameColumnValue = this.strDefaultObjectIDNameColumnValue;
2533 }
2534
2535 if (this.strObjectIDColumnName.equals(""))
2536 this.strObjectIDColumnName = this.strDefaultObjectIDColumnName;
2537 String strObjectIDAutoCreate = this.importAttributeValue(doc, "importDefinition",
2538 "objectIDAutoCreate", iJobNumber);
2539 if (strObjectIDAutoCreate.equals(""))
2540 this.bObjectIDAutoCreate = this.bDefaultObjectIDAutoCreate;
2541 else
2542 this.bObjectIDAutoCreate = (new Boolean(strObjectIDAutoCreate)).booleanValue();
2543 if (this.bObjectIDAutoCreate == true) {
2544 String strObjectIDStartValue = this.importAttributeValue(doc,
2545 "importDefinition", "objectIDStartValue", iJobNumber);
2546 if (strObjectIDStartValue.equals(""))
2547 this.iObjectIDStartValue = this.iDefaultObjectIDStartValue;
2548 else
2549 this.iObjectIDStartValue = Integer.parseInt(strObjectIDStartValue);
2550 }
2551 String strReturnCode = this.importAttributeValue(doc,
2552 "importDefinition", "returnCode", iJobNumber);
2553 if(!strReturnCode.equals(""))
2554 ReturnCode.setErrorReturnCode(Integer.parseInt(strReturnCode));
2555 else
2556 ReturnCode.setErrorReturnCode(ReturnCode.getDefaultErrorReturnCode());
2557 this.vecRestartCounterSortColumn = this.importValue(doc, "sortColumn",
2558 "entry", iJobNumber);
2559 this.strDbVendor = this.importAttribute(doc, "jdbcSourceParameters",
2560 "dbVendor", iJobNumber);
2561 this.strSourceDriverName=this.importAttribute(doc, "jdbcSourceParameters",
2562 "driverName", iJobNumber);
2563 if (this.strDbVendor.equals(""))
2564 this.strDbVendor = this.strDbVendorDefault;
2565 if (this.strDbVendor.equals(""))
2566 this.strDbVendor = "csv";
2567 if (this.strSourceDriverName.equals(""))
2568 this.strSourceDriverName = this.strDriverNameDefault;
2569 if (this.strSourceDriverName.equals("") && this.strDbVendor.equalsIgnoreCase("mssql"))
2570 this.strSourceDriverName = "jturbo";
2571
2572 this.strTargetDbVendor = this.importAttribute(doc, "jdbcTargetParameters",
2573 "dbVendor", iJobNumber);
2574 this.strTargetDriverName = this.importAttribute(doc, "jdbcTargetParameters",
2575 "driverName", iJobNumber);
2576 if (this.strTargetDbVendor.equals(""))
2577 this.strTargetDbVendor = this.strTargetDbVendorDefault;
2578 if (this.strTargetDbVendor.equals(""))
2579 this.strTargetDbVendor = "mssql";
2580 if (this.strTargetDriverName.equals(""))
2581 this.strTargetDriverName = this.strTargetDriverNameDefault;
2582 if (this.strTargetDriverName.equals("") && this.strTargetDbVendor.equalsIgnoreCase("mssql"))
2583 this.strTargetDriverName = "jturbo";
2584
2585 vecJDBCSourceValue = this.importValue(doc, "jdbcSourceParameter",
2586 "value", iJobNumber);
2587 vecJDBCSourceName = this.importValue(doc, "jdbcSourceParameter",
2588 "name", iJobNumber);
2589 if (vecJDBCSourceValue.size() != 0) {
2590 for (int i = 0; i < vecJDBCSourceValue.size(); i++) {
2591 if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
2592 this.strJDBCSourceParameterDriver = vecJDBCSourceValue.get(i).toString();
2593 else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("Connection.Url")) {
2594 //Testing SelectMethod parameter in microsoft MSSQL driver
2595 if(vecJDBCSourceValue.get(i).toString().indexOf("jdbc:microsoft:sqlserver")!=-1) {
2596 if(vecJDBCSourceValue.get(i).toString().indexOf("SelectMethod")==-1) {
2597 this.strJDBCSourceParameterConnection = vecJDBCSourceValue.get(i).toString() + ";SelectMethod=cursor";
2598 } else if(vecJDBCSourceValue.get(i).toString().indexOf("cursor")!=-1) {
2599 this.strJDBCSourceParameterConnection = vecJDBCSourceValue.get(i).toString();
2600 } else {
2601 this.echo.writeToLog("none", "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor" );
2602 LoaderException le = new LoaderException("Exception: value of Connection.Url perameter SelectMethod has to be cursor");
2603 throw le;
2604 }
2605 } else {
2606 this.strJDBCSourceParameterConnection = vecJDBCSourceValue.get(i).toString();
2607 }
2608 }
2609 else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("User"))
2610 this.strJDBCSourceParameterUser = vecJDBCSourceValue.get(i).toString();
2611 else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("Password"))
2612 this.strJDBCSourceParameterPassword = vecJDBCSourceValue.get(i).toString();
2613 }
2614 }
2615 else {
2616 this.strJDBCSourceParameterDriver = this.strJDBCDefaultSourceParameterDriver;
2617 // if(this.strJDBCSourceParameterDriver.equals("")||this.strJDBCSourceParameterDriver==null)
2618 // this.strJDBCSourceParameterDriver=this.strSourceDriverClassName;
2619 this.strJDBCSourceParameterConnection = this.strJDBCDefaultSourceParameterConnection;
2620 this.strJDBCSourceParameterUser = this.strJDBCDefaultSourceParameterUser;
2621 this.strJDBCSourceParameterPassword = this.strJDBCDefaultSourceParameterPassword;
2622 }
2623 vecJDBCTargetValue = this.importValue(doc, "jdbcTargetParameter",
2624 "value", iJobNumber);
2625 vecJDBCTargetName = this.importValue(doc, "jdbcTargetParameter",
2626 "name", iJobNumber);
2627
2628 if (vecJDBCTargetValue.size() != 0) {
2629 for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
2630 if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
2631 this.strJDBCTargetParameterDriver = vecJDBCTargetValue.get(i).toString();
2632 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Connection.Url")){
2633 //Testing SelectMethod parameter in microsoft MSSQL driver
2634 if(vecJDBCTargetValue.get(i).toString().indexOf("jdbc:microsoft:sqlserver")!=-1) {
2635 if(vecJDBCTargetValue.get(i).toString().indexOf("SelectMethod")==-1) {
2636 this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString()+";SelectMethod=cursor";
2637 } else if(vecJDBCTargetValue.get(i).toString().indexOf("cursor")!=-1) {
2638 this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
2639 } else {
2640 this.echo.writeToLog("none", "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor" );
2641 LoaderException le = new LoaderException("Exception: value of Connection.Url parameter SelectMethod has to be cursor");
2642 throw le;
2643 }
2644 }
2645 else {
2646 this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
2647 }
2648 }
2649 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("User"))
2650 this.strJDBCTargetParameterUser = vecJDBCTargetValue.get(i).toString();
2651 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Password"))
2652 this.strJDBCTargetParameterPassword = vecJDBCTargetValue.get(i).toString();
2653 }
2654 }
2655 else {
2656 this.strJDBCTargetParameterDriver = this.strJDBCDefaultTargetParameterDriver;
2657 // if(this.strJDBCTargetParameterDriver.equals("")||this.strJDBCTargetParameterDriver==null)
2658 // this.strJDBCTargetParameterDriver=this.strTargetDriverClassName;
2659 this.strJDBCTargetParameterConnection = this.strJDBCDefaultTargetParameterConnection;
2660 this.strJDBCTargetParameterUser = this.strJDBCDefaultTargetParameterUser;
2661 this.strJDBCTargetParameterPassword = this.strJDBCDefaultTargetParameterPassword;
2662 }
2663 vecValueColumnSourceColumnName = this.importValue(doc, "valueColumn",
2664 "sourceColumnName", iJobNumber);
2665 vecValueColumnTargetTableName = this.importValue(doc, "valueColumn",
2666 "targetTableName", iJobNumber);
2667 this.iValueColumns = vecValueColumnTargetTableName.size();
2668 vecValueColumnTargetColumnName = this.importValue(doc, "valueColumn",
2669 "targetColumnName", iJobNumber);
2670 vecValueColumnTargetTableID = this.importValue(doc, "valueColumn",
2671 "targetTableID", iJobNumber);
2672 vecValueColumnValueMode = this.importValue(doc, "valueColumn",
2673 "valueMode", iJobNumber);
2674 this.vecVariableColumnName = this.importValue(doc, "variableColumn",
2675 "name", iJobNumber);
2676 this.vecVariableColumnTargetTableName = this.importValue(doc, "variableColumn",
2677 "targetTableName", iJobNumber);
2678 this.vecVariableColumnTargetColumnName = this.importValue(doc,
2679 "variableColumn", "targetColumnName", iJobNumber);
2680 this.vecVariableColumnTargetTableID = this.importValue(doc, "variableColumn",
2681 "targetTableID", iJobNumber);
2682 this.vecVariableColumnValueMode = this.importValue(doc, "variableColumn",
2683 "valueMode", iJobNumber);
2684 this.vecVariableUseIDTableName = this.importValue(doc, "userIDColumn",
2685 "targetTableName", iJobNumber);
2686 this.vecVariableUseIDColumnName = this.importValue(doc, "userIDColumn",
2687 "targetColumnName", iJobNumber);
2688 this.vecVariableUseIDTableID = this.importValue(doc, "userIDColumn",
2689 "targetTableID", iJobNumber);
2690 this.vecVariableUseIDValueMode = this.importValue(doc, "userIDColumn",
2691 "valueMode", iJobNumber);
2692 this.vecVariableTimesTableName = this.importValue(doc, "timeStampColumn",
2693 "targetTableName", iJobNumber);
2694 this.vecVariableTimesColumnName = this.importValue(doc, "timeStampColumn",
2695 "targetColumnName", iJobNumber);
2696 this.vecVariableTimesTableID = this.importValue(doc, "timeStampColumn",
2697 "targetTableID", iJobNumber);
2698 this.vecVariableTimesValueMode = this.importValue(doc, "timeStampColumn",
2699 "valueMode", iJobNumber);
2700 this.vecConstantColumnTargetTableName = this.importValue(doc, "constantColumn",
2701 "targetTableName", iJobNumber);
2702 this.iConstantColumns = this.vecConstantColumnTargetTableName.size();
2703 vecConstantColumnTargetColumnName = this.importValue(doc, "constantColumn",
2704 "targetColumnName", iJobNumber);
2705 this.vecConstantColumnTargetTableID = this.importValue(doc, "constantColumn",
2706 "targetTableID", iJobNumber);
2707 vecConstantColumnValueMode = this.importValue(doc, "constantColumn",
2708 "valueMode", iJobNumber);
2709 vecConstantColumnConstantValue = this.importValue(doc, "constantColumn",
2710 "constantValue", iJobNumber, null);
2711 this.vecRelationColumnSourceTableName = this.importValue(doc, "relationColumn",
2712 "relationSourceTableName", iJobNumber);
2713 this.iRelationColumns = this.vecRelationColumnSourceTableName.size();
2714 this.vecRelationColumnSourceTableID = this.importValue(doc, "relationColumn",
2715 "relationSourceTableID", iJobNumber);
2716 this.vecRelationColumnSourceColumnName = this.importValue(doc,
2717 "relationColumn", "relationSourceColumnName", iJobNumber);
2718 this.vecRelationColumnTargetTableName = this.importValue(doc, "relationColumn",
2719 "relationTargetTableName", iJobNumber);
2720 this.vecRelationColumnTargetColumnName = this.importValue(doc,
2721 "relationColumn", "relationTargetColumnName", iJobNumber);
2722 this.vecRelationColumnTargetTableID = this.importValue(doc, "relationColumn",
2723 "relationTargetTableID", iJobNumber);
2724 this.vecRelationColumnRelationMode = this.importValue(doc, "relationColumn",
2725 "relationMode", iJobNumber);
2726
2727 //sinisa 02.03.2003. Add counterColumns
2728 this.counterColumns=new CounterColumns();
2729 this.counterColumns.readConstantColumnAttributes(doc,iJobNumber);
2730 this.counterColumns.readConstantColumnsParameters(doc,iJobNumber);
2731 //end sinisa
2732
2733 this.vecTableTableName = this.importValue(doc, "table", "tableName",
2734 iJobNumber);
2735 this.iTables = this.vecTableTableName.size();
2736 this.vecTableTableID = this.importValue(doc, "table", "tableID",
2737 iJobNumber);
2738 this.vecTableInsert = this.importValue(doc, "table", "insert",
2739 iJobNumber);
2740 this.vecTableTableMode = this.importValue(doc, "table", "tableMode",
2741 iJobNumber, this.strDefaultTableMode);
2742 this.vecTableOidLogic = this.importValue(doc, "table", "oidLogic",
2743 iJobNumber, (new Boolean(this.bDefaultOidLogic)).toString());
2744
2745 if (this.vecRelationColumnSourceTableName.size() != 0) {
2746 this.changeRelationsOrder();
2747 this.changeTableOrder();
2748 }
2749
2750 this.vecQueryWhere.setSize(this.iTables);
2751 this.vecRelationKeyColumns.setSize(this.iTables);
2752 this.vecRelationKeyTypes.setSize(this.iTables);
2753 this.vecConstantTargetColumnName.setSize(this.iTables);
2754 this.vecConstantValueMode.setSize(this.iTables);
2755 this.vecConstantConstantValue.setSize(this.iTables);
2756 this.vecConstantColumnType.setSize(this.iTables);
2757 for (int k = 0; k < vecValueColumnTargetTableName.size(); k++) {
2758 boolean isImportColumn = false;
2759 for (int l = 0; l < this.iTables; l++) {
2760 if (vecValueColumnTargetTableName.get(k).toString().equalsIgnoreCase(this.vecTableTableName.get(l).toString())
2761 && vecValueColumnTargetTableID.get(k).toString().equalsIgnoreCase(this.vecTableTableID.get(l).toString())) {
2762 isImportColumn = true;
2763 }
2764 }
2765 if (!isImportColumn) {
2766 this.echo.writeToLog("none", "Incorrect XML import variables - TABLE ID");
2767 LoaderException le = new LoaderException("Exception: ",
2768 (Throwable)(new Exception("Incorrect XML import variables - TABLE ID")));
2769 throw le;
2770 // System.exit(1);
2771 }
2772 }
2773 if (this.vecVariableUseIDTableName.size() != 0) {
2774 if (this.strUserID.equals("")) {
2775 this.echo.writeToLog("none", "Error : User parametar missing");
2776 LoaderException le = new LoaderException("Exception: ",
2777 (Throwable)(new Exception("Error : User parametar missing")));
2778 throw le;
2779 // System.exit(1);
2780 }
2781 }
2782 for (int k = 0; k < this.iTables; k++) {
2783 iNumberOfColumns = 0;
2784 Vector vecTargetTable1 = new Vector();
2785 Vector vecTargetTable2 = new Vector();
2786 Vector vecTargetTable3 = new Vector();
2787 Vector vecTargetTable4 = new Vector();
2788 Vector vecTargetTable5 = new Vector();
2789 Vector vecTargetTable6 = new Vector();
2790 Vector vecTargetTable7 = new Vector();
2791 Vector vecTargetTable8 = new Vector();
2792 for (int l = 0; l < this.iValueColumns; l++) {
2793 if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(vecValueColumnTargetTableName.get(l).toString())
2794 && vecValueColumnTargetTableID.get(l).toString().equalsIgnoreCase(this.vecTableTableID.get(k).toString())) {
2795 iNumberOfColumns++;
2796 vecTargetTable1.addElement(vecValueColumnSourceColumnName.get(l).toString());
2797 vecTargetTable2.addElement(vecValueColumnTargetColumnName.get(l).toString());
2798 vecTargetTable4.addElement(vecValueColumnValueMode.get(l).toString());
2799 if (vecValueColumnValueMode.get(l).toString().equalsIgnoreCase("Key"))
2800 vecTargetTable5.addElement(vecValueColumnTargetColumnName.get(l).toString());
2801 }
2802 }
2803 for (int l = 0; l < this.vecVariableUseIDTableName.size(); l++) {
2804 if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(this.vecVariableUseIDTableName.get(l).toString())
2805 && this.vecVariableUseIDTableID.get(l).toString().equalsIgnoreCase(this.vecTableTableID.get(k).toString())) {
2806 vecTargetTable2.addElement(this.vecVariableUseIDColumnName.get(l).toString());
2807 vecTargetTable4.addElement(this.vecVariableUseIDValueMode.get(l).toString());
2808 if (this.vecVariableUseIDValueMode.get(l).toString().equalsIgnoreCase("Key"))
2809 vecTargetTable5.addElement(this.vecVariableUseIDColumnName.get(l).toString());
2810 }
2811 }
2812 for (int l = 0; l < this.vecRelationColumnSourceColumnName.size(); l++) {
2813 if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(this.vecRelationColumnTargetTableName.get(l).toString())
2814 && this.vecRelationColumnTargetTableID.get(l).toString().equalsIgnoreCase(this.vecTableTableID.get(k).toString())
2815 && this.vecRelationColumnRelationMode.get(l).toString().equalsIgnoreCase("Key")) {
2816 vecTargetTable3.addElement(this.vecRelationColumnTargetColumnName.get(l).toString());
2817 }
2818 }
2819
2820 this.vecSourceColumnName.addElement(vecTargetTable1);
2821 this.vecTargetColumnName.addElement(vecTargetTable2);
2822 this.vecRelationKeyColumns.setElementAt(vecTargetTable3, k);
2823 this.vecValueMode.addElement(vecTargetTable4);
2824 this.vecTargetKeyColumnName.addElement(vecTargetTable5);
2825 this.vecValueColumnsTargetTables.addElement(new Integer(iNumberOfColumns));
2826 for (int p = 0; p < this.iConstantColumns; p++) {
2827 if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(this.vecConstantColumnTargetTableName.get(p).toString())
2828 && this.vecConstantColumnTargetTableID.get(p).toString().equalsIgnoreCase(this.vecTableTableID.get(k).toString())) {
2829 vecTargetTable6.addElement(vecConstantColumnTargetColumnName.get(p).toString());
2830 vecTargetTable7.addElement(vecConstantColumnValueMode.get(p).toString());
2831 if (vecConstantColumnConstantValue.get(p) == null)
2832 vecTargetTable8.addElement(null);
2833 else
2834 vecTargetTable8.addElement(vecConstantColumnConstantValue.get(p).toString());
2835 }
2836 }
2837 this.vecConstantTargetColumnName.setElementAt(vecTargetTable6,
2838 k);
2839 this.vecConstantValueMode.setElementAt(vecTargetTable7, k);
2840 this.vecConstantConstantValue.setElementAt(vecTargetTable8,
2841 k);
2842
2843 //sinisa 02.03.2003. Add counterColumns
2844
2845 this.counterColumns.setConstantColumnsParameters(this.vecTableTableName.get(k).toString(),this.vecTableTableID.get(k).toString());
2846 //end sinisa
2847 }
2848
2849
2850 for (int i = 0; i < this.vecRelationColumnSourceColumnName.size(); i++) {
2851 if (this.vecRelationColumnSourceColumnName.get(i).toString().equals("")) {
2852 for (int k = 0; k < this.vecTableTableName.size(); k++) {
2853 if (this.vecRelationColumnSourceTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(k).toString())
2854 && this.vecRelationColumnSourceTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(k).toString())) {
2855 if (this.vecTableOidLogic.get(k).toString().equalsIgnoreCase("true"))
2856 this.vecRelationColumnSourceColumnName.setElementAt("OID",
2857 i);
2858 }
2859 }
2860 }
2861 }
2862 this.vecRelationSourceValue.setSize(this.iRelationColumns);
2863 this.vecRelationSourceType.setSize(this.iRelationColumns);
2864 } catch (NullPointerException ex) {
2865 throw ex;
2866 } catch (Exception ex) {
2867 throw ex;
2868 }
2869 this.echo.writeToLog("full", "\timportXMLFile method is finished.");
2870 }
2871
2872 /***
2873 * Metod cache is used to load data from the source table and to put them into vector "vectorCache".
2874 * This method includes only target tables which tableMode is "Cache". If there
2875 * is an error, Exception "SQLException" is thrown.
2876 * @param c Connection to the source table.
2877 * @param bdecRowCount Number of current row.
2878 * @param strQuery SQL query for select all columns in to the source table.
2879 * @return Integer - number of rows in a block
2880 * @throws SQLException Constructs an SQLException object with a reason.
2881 */
2882 private int cache (Connection c, BigDecimal bdecRowCount, String strQuery) throws SQLException {
2883 int j = 0;
2884 int iRowCountCache = 0, blockCount = 0;
2885 this.echo.writeToLog("full", "\tcache method is started.");
2886 this.vecTargetColumnValue.setSize(this.iTables);
2887 BigDecimal bdecCountRows = new BigDecimal(0);
2888 try {
2889 Statement stmtCounter = null;
2890 if (this.bEnableJumpResult) {
2891 stmtCounter = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
2892 ResultSet.CONCUR_UPDATABLE);
2893 }
2894 else {
2895 stmtCounter = c.createStatement();
2896
2897 }
2898 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
2899 //SINISA 07.02.2003.
2900 // add select statement result into HashTable
2901 if(this.strImportDefinitionSelectStatement!=null && !this.strImportDefinitionSelectStatement.equals("") && !this.cacheValues.getCache().isEmpty()) {
2902 if(this.cacheValues.getCache().size() > bdecRowCount.intValue()+this.iImportDefinitionCommitCount)
2903 blockCount = this.iImportDefinitionCommitCount;
2904 else
2905 blockCount=this.cacheValues.getCache().size() - bdecRowCount.intValue();
2906 }
2907 else {
2908 ResultSet rsetCounter = stmtCounter.executeQuery(strQuery);
2909 if (this.bEnableJumpResult) {
2910 if (!this.bBeforeFirstRow)
2911 rsetCounter.absolute(bdecRowCount.intValue() + 1);
2912 else
2913 rsetCounter.absolute(bdecRowCount.intValue());
2914 }
2915 else {
2916 while (bdecCountRows.compareTo(bdecRowCount) == -1) {
2917 rsetCounter.next();
2918 bdecCountRows = bdecCountRows.add(new BigDecimal(1));
2919 }
2920 }
2921 out:
2922 while (blockCount < this.iImportDefinitionCommitCount && rsetCounter.next()) {
2923 if(this.strDbVendor.equalsIgnoreCase("csv")){
2924 if(checkRow(rsetCounter)){
2925 blockCount++;
2926 }
2927 else {
2928 while(true) {
2929 if(rsetCounter.next()){
2930 if(checkRow(rsetCounter)){
2931 SQLException ex2 = new SQLException("Problem with source table");
2932 throw ex2;
2933 }
2934 }
2935 else
2936 break out;
2937 }
2938 }
2939 }
2940 else
2941 blockCount++;
2942 }
2943 if (!this.bBeforeFirstRow && blockCount != this.iImportDefinitionCommitCount)
2944 blockCount++;
2945 rsetCounter.close();
2946 stmtCounter.close();
2947 }
2948 for (int i = 0; i < this.iTables; i++) {
2949 BigDecimal k = new BigDecimal(0);
2950 Statement stmtCsv = null;
2951 ResultSet rsetCsv = null;
2952 if (this.bEnableJumpResult)
2953 stmtCsv = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
2954 ResultSet.CONCUR_UPDATABLE);
2955 else
2956 stmtCsv = c.createStatement();
2957 //sinisa 09.03.2003. read data form cache - selectStatement
2958 if(!(this.vecTableTableMode.get(i).toString().equalsIgnoreCase("Cache") &&
2959 this.strImportDefinitionSelectStatement!=null && !this.strImportDefinitionSelectStatement.equals(""))) {
2960
2961 rsetCsv = stmtCsv.executeQuery(strQuery);
2962 int iNumColumnsCurrent = 0;
2963 if (this.bEnableJumpResult) {
2964 if (!this.bBeforeFirstRow)
2965 rsetCsv.absolute(bdecRowCount.intValue() + 1);
2966 else
2967 rsetCsv.absolute(bdecRowCount.intValue());
2968 }
2969 else {
2970 while (k.compareTo(bdecRowCount) == -1) {
2971 rsetCsv.next();
2972 k = k.add(new BigDecimal(1));
2973 }
2974 }
2975 }
2976 Vector vectorCache = new Vector();
2977 iRowCountCache = 0;
2978 //read data from Cache - hashtable
2979 if (this.vecTableTableMode.get(i).toString().equalsIgnoreCase("Cache")) {
2980 if(this.strImportDefinitionSelectStatement!=null && !this.strImportDefinitionSelectStatement.equals("")) {
2981 while (iRowCountCache < blockCount) {
2982 Vector srcNames = new Vector();
2983 srcNames = (Vector)this.vecSourceColumnName.get(i);
2984 Vector readValues = this.cacheValues.getCacheRow(bdecRowCount.add(new BigDecimal(iRowCountCache)));
2985 int iCounterCol = 0;
2986 for (int m = 0; m < i; m++) {
2987 if(this.vecTableTableMode.get(m).toString().equalsIgnoreCase("Cache"))
2988 iCounterCol = iCounterCol + Integer.parseInt(this.vecValueColumnsTargetTables.get(m).toString());
2989 }
2990 iCounterCol++;
2991 for (int l = iCounterCol; l < (iCounterCol + Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString())); l++) {
2992 // }
2993 // for(int s=0; s<srcNames.size(); s++) {
2994 if(readValues.get(l-1)!=null){
2995 if(!readValues.get(l-1).toString().equalsIgnoreCase("null")){
2996 vectorCache.add(readValues.get(l-1).toString());
2997 }
2998 else{
2999 vectorCache.add(null);
3000 }
3001 }
3002 else{
3003 vectorCache.add(null);
3004 }
3005 }
3006 iRowCountCache++;
3007 this.vecTargetColumnValue.setElementAt(vectorCache, i);
3008 }
3009 }
3010 else {
3011 while (iRowCountCache < blockCount) {
3012 if (!(!this.bBeforeFirstRow && this.bEnablePreviousRecord)) {
3013 rsetCsv.next();
3014 }
3015 int iCounterCol = 0;
3016 for (int m = 0; m < i; m++) {
3017 iCounterCol = iCounterCol + Integer.parseInt(this.vecValueColumnsTargetTables.get(m).toString());
3018 }
3019 iCounterCol++;
3020 for (int l = iCounterCol; l < (iCounterCol + Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString())); l++) {
3021 if (this.iFirstColumnResult == 0) {
3022 String readValue = rsetCsv.getString(l-1);
3023 if(readValue!=null){
3024 if(!readValue.equalsIgnoreCase("null")){
3025 if(readValue.indexOf("'")!=-1)
3026 readValue=replaceChar(readValue,'\'',"\'\'");
3027
3028 vectorCache.add(readValue);
3029 }
3030 else{
3031 vectorCache.add(null);
3032 }
3033 }
3034 else{
3035 vectorCache.add(null);
3036 }
3037 }
3038 else {
3039 String readValue = rsetCsv.getString(l);
3040 if(readValue!=null){
3041 if(!readValue.equalsIgnoreCase("null")){
3042 if(readValue.indexOf("'")!=-1)
3043 readValue=replaceChar(readValue,'\'',"\'\'");
3044 vectorCache.add(readValue);
3045
3046 }
3047 }
3048 else{
3049 vectorCache.add(null);
3050 }
3051 }
3052 }
3053 iRowCountCache++;
3054 if (!this.bBeforeFirstRow && this.bEnablePreviousRecord){
3055 rsetCsv.next();
3056 }
3057 }
3058 this.vecTargetColumnValue.setElementAt(vectorCache, i);
3059 }
3060 // this.vecTargetColumnValue.setElementAt(vectorCache, i);
3061 }
3062 if(rsetCsv!=null)
3063 rsetCsv.close();
3064 if(stmtCsv!=null)
3065 stmtCsv.close();
3066 }
3067 } catch (SQLException ex) {
3068 SQLException ex1 = new SQLException("Problem with source table: "+(bdecRowCount.intValue()+blockCount+1)+". row \n"+ex.toString());
3069 throw ex1;
3070 }
3071 this.echo.writeToLog("full", "\tcache method is finished.");
3072 return blockCount;
3073 }
3074
3075 /***
3076 * Metod addToCacheUsingSelect is used to load data from the source table
3077 * (using select statement parameter) and to put them into vector "vectorCache".
3078 * This method includes only target tables which tableMode is "Cache". If there
3079 * is an error, Exception "SQLException" is thrown.
3080 * @param c Connection to the source table.
3081 * @param bdecRowCount Number of current row.
3082 * @param strQuery SQL query for select all columns in to the source table.
3083 * @return Integer - number of rows in a block
3084 * @throws SQLException Constructs an SQLException object with a reason.
3085 */
3086 private int addToCacheUsingSelect (Connection c, String strQuery) throws SQLException {
3087 int j = 0;
3088 int iRowCountCache = 0;
3089 this.echo.writeToLog("full", "\taddToCacheUsingSelect method is started.");
3090 this.vecTargetColumnValue.setSize(this.iTables);
3091 this.cacheValues=new Cache();
3092 try {
3093 /* Statement stmtCounter = null;
3094 if (this.bEnableJumpResult) {
3095 stmtCounter = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
3096 ResultSet.CONCUR_UPDATABLE);
3097 }
3098 else {
3099 stmtCounter = c.createStatement();
3100 }
3101 */ boolean isEnd = false;
3102
3103 Statement stmtCsv = null;
3104 if (this.bEnableJumpResult)
3105 stmtCsv = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
3106 ResultSet.CONCUR_UPDATABLE);
3107 else
3108 stmtCsv = c.createStatement();
3109 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
3110 ResultSet rsetCsv = stmtCsv.executeQuery(strQuery);
3111 iRowCountCache = 0;
3112 out:
3113 while(!isEnd) {
3114 Vector vectorCache = new Vector();
3115
3116 if (!(!this.bBeforeFirstRow && this.bEnablePreviousRecord)) {
3117
3118 isEnd=!rsetCsv.next();
3119 }
3120 if(isEnd)
3121 break out;
3122
3123 for (int i = 0; i < this.iTables; i++) {
3124 BigDecimal k = new BigDecimal(0);
3125 int iNumColumnsCurrent = 0;
3126 if (this.vecTableTableMode.get(i).toString().equalsIgnoreCase("Cache")) {
3127
3128 //Sinisa - add reading data from source when Loader uses selectStatement
3129 if(this.strImportDefinitionSelectStatement!=null && !this.strImportDefinitionSelectStatement.equals("")) {
3130 Vector srcNames = new Vector();
3131 srcNames = (Vector)this.vecSourceColumnName.get(i);
3132
3133 int iCounterCol = 0;
3134 for (int m = 0; m < i; m++) {
3135 iCounterCol = iCounterCol + Integer.parseInt(this.vecValueColumnsTargetTables.get(m).toString());
3136 }
3137 iCounterCol++;
3138
3139 for(int s=0; s<srcNames.size(); s++) {
3140 if(srcNames.get(s)!=null) {
3141 //Sinisa 17.01.2003. d'Ambrosio problem
3142 String readValue = rsetCsv.getString(srcNames.get(s).toString());
3143 if(readValue!=null){
3144 if(!readValue.equalsIgnoreCase("null")){
3145 if(readValue.indexOf("'")!=-1)
3146 readValue=replaceChar(readValue,'\'',"\'\'");
3147 vectorCache.add(readValue);
3148 }
3149 else{
3150 vectorCache.add(null);
3151 }
3152 }
3153 else{
3154 vectorCache.add(null);
3155 }
3156 }
3157 // }
3158 }
3159 }
3160 }
3161 }
3162 cacheValues.setCacheRow(new BigDecimal(iRowCountCache), vectorCache);
3163 iRowCountCache++;
3164 if (!this.bBeforeFirstRow && this.bEnablePreviousRecord){
3165
3166 isEnd=!rsetCsv.next();
3167 }
3168 }
3169 rsetCsv.close();
3170 stmtCsv.close();
3171 } catch (SQLException ex) {
3172 SQLException ex1 = new SQLException("Error reading data from SQL query: "+ex.toString());
3173 throw ex1;
3174 }
3175 this.echo.writeToLog("full", "\tcache method is finished.");
3176 return iRowCountCache;
3177 }
3178
3179 private boolean checkRow(ResultSet rset) {
3180
3181 boolean isOK = true;
3182 try {
3183 if (this.iFirstColumnResult == 0){
3184 // rset.getString(this.iColumnsInSourceTable-1);
3185 rset.getObject(this.iColumnsInSourceTable-1);
3186 }
3187 else {
3188 // rset.getString(this.iColumnsInSourceTable);
3189 rset.getObject(this.iColumnsInSourceTable);
3190 }
3191 }
3192 catch (SQLException ex){
3193 isOK = false;
3194 }
3195 finally {
3196 return isOK;
3197 }
3198
3199 // return isOK;
3200 }
3201
3202 /***
3203 * Method updateCurrentTime write system time into timeStamp variable columns
3204 * @param c Connection to the target table.
3205 * @param iTable Number of target table.
3206 * @param strQueryWhereSQL Part of SQL query - where clause.
3207 * @param bWriteData if it is true, in current row some data in any column is changed,
3208 * if it is false, no data in current row in target table is not changed.
3209 * @throws SQLException
3210 * @throws NullPointerException
3211 */
3212 private void updateCurrentTime (Connection c, int iTable, String strQueryWhereSQL,
3213 boolean bWriteData) throws SQLException, NullPointerException {
3214 String strQueryInsertTime = "";
3215 this.echo.writeToLog("full", "\tupdateCurrentTime method is started.");
3216 try {
3217 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
3218 if (this.vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTable).toString())
3219 && this.vecVariableTimesTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTable).toString())) {
3220 Statement stmtRelations = c.createStatement();
3221 // strQueryInsertTime += "update " + this.vecVariableTimesTableName.get(i).toString()
3222 strQueryInsertTime = "update " + this.vecVariableTimesTableName.get(i).toString()
3223 + " set " + this.vecVariableTimesColumnName.get(i).toString()
3224 + " = ";
3225 if (this.vecVariableTimesValueMode.get(i).toString().equalsIgnoreCase("Overwrite")
3226 && bWriteData == true)
3227 strQueryInsertTime += " '" + this.createCurrentDate() +
3228 "' where " + strQueryWhereSQL;
3229 else
3230 strQueryInsertTime += " '" + this.createCurrentDate()
3231 + "' where " + this.vecVariableTimesColumnName.get(i).toString()
3232 + " is null and " + strQueryWhereSQL;
3233 this.echo.writeToLog("full", "\tQuery '" + strQueryInsertTime
3234 + "' will be executed");
3235 if (bReplaceInData) {
3236 strQueryInsertTime = this.replaceInData(strQueryInsertTime);
3237 }
3238 stmtRelations.executeUpdate(strQueryInsertTime);
3239 stmtRelations.close();
3240 // c.commit();
3241 }
3242 }
3243 } catch (SQLException ex) {
3244 throw ex;
3245 } catch (NullPointerException ex) {
3246 throw ex;
3247 }
3248 this.echo.writeToLog("full", "\tupdateCurrentTime method is finished.");
3249 }
3250
3251 /***
3252 * Method updateNameValue writes nameValue value (Loader's argument) into variable columns
3253 * @param c Connection to the target table.
3254 * @param iTable Number of target table.
3255 * @param strQueryWhereSQL Part of SQL query - where clause.
3256 * @throws SQLException
3257 * @throws NullPointerException
3258 */
3259 private void updateNameValue (Connection c, int iTable, String strQueryWhereSQL) throws SQLException,
3260 NullPointerException, LoaderException {
3261 String strQueryInsertName = "";
3262 this.echo.writeToLog("full", "\tupdateNameValue method is started.");
3263 try {
3264 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
3265 boolean bInsert = true;
3266 if (this.vecVariableColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTable).toString())
3267 && this.vecVariableColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTable).toString())) {
3268 int iPositionInVector = this.vecVariableName.indexOf(this.vecVariableColumnName.get(i).toString());
3269 if (iPositionInVector != -1) {
3270 Statement stmtRelations = c.createStatement();
3271 // strQueryInsertName += "update " + this.vecVariableColumnTargetTableName.get(i).toString()
3272 strQueryInsertName = "update " + this.vecVariableColumnTargetTableName.get(i).toString()
3273 + " set " + this.vecVariableColumnTargetColumnName.get(i).toString()
3274 + " = ";
3275 if (this.vecVariableColumnValueMode.get(i).toString().equalsIgnoreCase("Overwrite")) {
3276 if (this.vecVariableValue.get(iPositionInVector)
3277 == null)
3278 strQueryInsertName += " null where " + strQueryWhereSQL;
3279 else {
3280 if (!isNumber(this.vecVariableColumnTypes.get(i).toString()))
3281 strQueryInsertName += " '" + this.vecVariableValue.get(iPositionInVector).toString()
3282 + "' where " + strQueryWhereSQL;
3283 else
3284 strQueryInsertName += this.vecVariableValue.get(iPositionInVector).toString()
3285 + " where " + strQueryWhereSQL;
3286 }
3287 }
3288 else if (this.vecVariableColumnValueMode.get(i).toString().equalsIgnoreCase("SetNull")) {
3289 if (this.vecVariableValue.get(iPositionInVector)
3290 == null)
3291 strQueryInsertName += " null where " + strQueryWhereSQL;
3292 else
3293 bInsert = false;
3294 }
3295 else {
3296 if (this.vecVariableValue.get(iPositionInVector)
3297 == null)
3298 strQueryInsertName += " null where " + this.vecVariableColumnTargetColumnName.get(i).toString()
3299 + " is null and " + strQueryWhereSQL;
3300 else {
3301 if (!isNumber(this.vecVariableColumnTypes.get(i).toString()))
3302 strQueryInsertName += " '" + this.vecVariableValue.get(iPositionInVector).toString()
3303 + "' where " + this.vecVariableColumnTargetColumnName.get(i).toString()
3304 + " is null and " + strQueryWhereSQL;
3305 else
3306 strQueryInsertName += this.vecVariableValue.get(iPositionInVector).toString()
3307 + " where " + this.vecVariableColumnTargetColumnName.get(i).toString()
3308 + " is null and " + strQueryWhereSQL;
3309 }
3310 }
3311 if(bInsert)
3312 this.echo.writeToLog("full", "\tQuery '" + strQueryInsertName
3313 + "' will be executed");
3314
3315 if (bReplaceInData) {
3316 strQueryInsertName = this.replaceInData(strQueryInsertName);
3317 }
3318 if(bInsert) {
3319 stmtRelations.executeUpdate(strQueryInsertName);
3320 }
3321 stmtRelations.close();
3322 }
3323 else {
3324 this.echo.writeToLog("none", "\tError: Cannot find value for variable column :"
3325 + this.vecVariableColumnName.get(i).toString());
3326 LoaderException le = new LoaderException("Exception: ",
3327 (Throwable)(new Exception("Error: Cannot find value for variable column :")));
3328 throw le;
3329 // System.exit(1);
3330 }
3331 }
3332 }
3333 } catch (SQLException ex) {
3334 throw ex;
3335 } catch (NullPointerException ex) {
3336 throw ex;
3337 }
3338 this.echo.writeToLog("full", "\tupdateNameValue method is finished.");
3339 }
3340
3341 /***
3342 * Method queryRelations is used to make SQL query for reading source value for relations between target tables.
3343 * It puts the value from the source column in source relation
3344 * table to the target column in target relation table. If there
3345 * is an error, Exception "SQLException" or NullPointerException is thrown.
3346 * @param iTableInt Number of target table.
3347 * @param iNumberOfRelationColumn Number of relation tag.
3348 * @param strQueryWhere Part of SQL query - where clause.
3349 * @return String which will be executed for update or insert relation columns into target tables
3350 * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
3351 */
3352 private String queryRelations (int iTableInt, int iNumberOfRelationColumn,
3353 String strQueryWhere) throws NullPointerException {
3354 this.echo.writeToLog("full", "\tqueryRelations method is started.");
3355 String strQueryRelations = "";
3356
3357 try {
3358 strQueryRelations = "update " + this.vecRelationColumnTargetTableName.get(iNumberOfRelationColumn).toString()
3359 + " set " + this.vecRelationColumnTargetColumnName.get(iNumberOfRelationColumn).toString();
3360 if (this.vecRelationSourceValue.get(iNumberOfRelationColumn) ==
3361 null)
3362 strQueryRelations += " = null where ";
3363 else {
3364 if (isNumber(this.vecRelationSourceType.get(iNumberOfRelationColumn).toString()))
3365 strQueryRelations += " = " + this.vecRelationSourceValue.get(iNumberOfRelationColumn).toString()
3366 + " where ";
3367 else
3368 strQueryRelations += " = '" + this.vecRelationSourceValue.get(iNumberOfRelationColumn).toString()
3369 + "' where ";
3370 }
3371 strQueryRelations += strQueryWhere;
3372 if (strQueryRelations.trim().endsWith("where"))
3373 strQueryRelations = strQueryRelations.substring(0, strQueryRelations.length()
3374 - 6);
3375 else {
3376 if (!this.vecRelationColumnRelationMode.get(iNumberOfRelationColumn).toString().equalsIgnoreCase("overwrite")) {
3377 strQueryRelations += " and " + this.vecRelationColumnTargetColumnName.get(iNumberOfRelationColumn).toString()
3378 + " is null";
3379 }
3380 }
3381 } catch (NullPointerException ex) {
3382 throw ex;
3383 }
3384 this.echo.writeToLog("full", "\tqueryRelations method is finished.");
3385 return strQueryRelations;
3386 }
3387 /***
3388 * Method isNumber is used for checking column type.
3389 * @param s String that represents column type.
3390 * @return True if it is numeric and false if it is not.
3391 */
3392 private boolean isNumber (String s) {
3393 boolean type = false;
3394 if (s.equalsIgnoreCase("decimal") || s.equalsIgnoreCase("int") || s.equalsIgnoreCase("numeric")
3395 || s.equalsIgnoreCase("real")|| s.equalsIgnoreCase("bigdecimal")|| s.equalsIgnoreCase("short")
3396 || s.equalsIgnoreCase("long")|| s.equalsIgnoreCase("float")|| s.equalsIgnoreCase("double")
3397 || s.equalsIgnoreCase("bigint") || s.equalsIgnoreCase("money") || s.equalsIgnoreCase("smallmoney")
3398 || s.equalsIgnoreCase("smallint"))
3399 type = true;
3400 return type;
3401 }
3402
3403 /***
3404 * Method insertTargetTable is used to put one row of data from columns
3405 * of source tables into target table ordered by column modes.
3406 * If there is an error, Exception "SQLException, "NullPointerException"
3407 * or "Exception" is thrown.
3408 * @param iTableInt Number of the target table which is processed.
3409 * @param vecColumnValues One row of values from the source table.
3410 * @param vecColumnNames Vector of column names in a target table.
3411 * @param vecColumnMode Modes of columns in the target table.
3412 * @param vecColumnTypes Types of columns in the target table.
3413 * @param c Connection to the target database.
3414 * @throws SQLException Constructs an SQLException object with a reason.
3415 * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
3416 * @throws Exception Constructs an Exception with the specified detail message.
3417 */
3418 private void insertTargetTable (int iTableInt, Vector vecColumnValues,
3419 Vector vecColumnNames, Vector vecColumnMode, Vector vecColumnTypes,
3420 Connection c) throws SQLException, NullPointerException, Exception {
3421 this.echo.writeToLog("full", "\tinsertTargetTable method is started.");
3422 boolean bInsertTable = false;
3423 int iVersionValue = 0;
3424 int iVersionMax = 0;
3425 boolean bWriteData = false;
3426 String strQueryWhere = "";
3427 String strQuery = new String("select ");
3428 boolean bOidLogicCurrentTable = new Boolean(this.vecTableOidLogic.get(iTableInt).toString()).booleanValue();
3429 boolean isTOS = !(this.strObjectIDNameColumnName.equals("")||this.strObjectIDNameColumnValue.equals(""));
3430 if (bOidLogicCurrentTable) {
3431 if(isTOS)
3432 strQuery = strQuery + "OID, ";
3433 else
3434 strQuery = strQuery + "oid, version, ";
3435 }
3436
3437 Vector vecTempKeyColumns = (Vector)this.vecTargetKeyColumnName.get(iTableInt);
3438 strQueryWhere = "";
3439 for (int k = 0; k < vecTempKeyColumns.size(); k++) {
3440 if (vecColumnNames.size() != 0) {
3441 for (int l = 0; l < vecColumnNames.size(); l++) {
3442 if (vecTempKeyColumns.get(k).toString().equalsIgnoreCase(vecColumnNames.get(l).toString())) {
3443 strQueryWhere += vecColumnNames.get(l).toString();
3444 if (!this.isNumber(vecColumnTypes.get(l).toString())) {
3445 if (vecColumnValues.get(l) == null)
3446 strQueryWhere += " is null and ";
3447 else
3448 strQueryWhere += " = '" + vecColumnValues.get(l).toString()
3449 + "' and ";
3450 }
3451 else {
3452 if (vecColumnValues.get(l) == null)
3453 strQueryWhere += " is null and ";
3454 else
3455 strQueryWhere += " = " + vecColumnValues.get(l).toString()
3456 + " and ";
3457 }
3458 }
3459 }
3460 }
3461 }
3462 for (int k = 0; k < ((Vector)this.vecRelationKeyColumns.get(iTableInt)).size(); k++) {
3463 int iNumRelation = -1;
3464 for (int p = 0; p < this.iRelationColumns; p++) {
3465 if (this.vecRelationColumnTargetTableName.get(p).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
3466 && this.vecRelationColumnTargetTableID.get(p).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())
3467 && this.vecRelationColumnTargetColumnName.get(p).toString().equalsIgnoreCase(((Vector)this.vecRelationKeyColumns.get(iTableInt)).get(k).toString())) {
3468 iNumRelation = p;
3469 }
3470 }
3471 strQueryWhere += ((Vector)this.vecRelationKeyColumns.get(iTableInt)).get(k).toString();
3472 if (this.vecRelationSourceValue.get(iNumRelation) == null)
3473 strQueryWhere += " is null and ";
3474 else {
3475 if (this.isNumber(((Vector)this.vecRelationKeyTypes.get(iTableInt)).get(k).toString()))
3476 strQueryWhere += " = " + this.vecRelationSourceValue.get(iNumRelation).toString()
3477 + " and ";
3478 else
3479 strQueryWhere += " = '" + this.vecRelationSourceValue.get(iNumRelation).toString()
3480 + "' and ";
3481 }
3482 }
3483 //sinisa
3484 Vector vecTempConstantColumns = (Vector)this.vecConstantTargetColumnName.get(iTableInt);
3485 Vector vecTempConstantValues = (Vector)this.vecConstantConstantValue.get(iTableInt);
3486 Vector vecTempConstantMode = (Vector)this.vecConstantValueMode.get(iTableInt);
3487 Vector vecTempConstantType = (Vector)this.vecConstantColumnType.get(iTableInt);
3488
3489 for (int k = 0; k < vecTempConstantColumns.size(); k++) {
3490 if (vecTempConstantMode.get(k).toString().equalsIgnoreCase("Key")) {
3491 strQueryWhere += vecTempConstantColumns.get(k).toString();
3492 if (vecTempConstantValues.get(k) == null)
3493 strQueryWhere += " is null and ";
3494 else {
3495 if (this.isNumber(vecTempConstantType.get(k).toString()))
3496 strQueryWhere += " = " + vecTempConstantValues.get(k).toString()
3497 + " and ";
3498 else
3499 strQueryWhere += " = '" + vecTempConstantValues.get(k).toString()
3500 + "' and ";
3501
3502 }
3503 }
3504 }
3505
3506 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
3507 if (this.vecVariableColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
3508 && this.vecVariableColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())
3509 && this.vecVariableColumnValueMode.get(i).toString().equalsIgnoreCase("Key")) {
3510 int iPositionInVector = this.vecVariableName.indexOf(this.vecVariableColumnName.get(i).toString());
3511 if (iPositionInVector != -1) {
3512 strQueryWhere += this.vecVariableColumnTargetColumnName.get(i).toString();
3513 if (this.vecVariableValue.get(iPositionInVector)
3514 == null)
3515 strQueryWhere += " is null and ";
3516 else {
3517 if (!isNumber(this.vecVariableColumnTypes.get(i).toString()))
3518 strQueryWhere += "= '" + this.vecVariableValue.get(iPositionInVector).toString()
3519 + "' and ";
3520 else
3521 strQuery += " = "+this.vecVariableValue.get(iPositionInVector).toString()
3522 + " and ";
3523 }
3524 }
3525 else {
3526 this.echo.writeToLog("none", "\tError: Cannot find value for variable column :"
3527 + this.vecVariableColumnName.get(i).toString());
3528 LoaderException le = new LoaderException("Exception: ",
3529 (Throwable)(new Exception("Error: Cannot find value for variable column :")));
3530 throw le;
3531 // System.exit(1);
3532 }
3533 }
3534 }
3535
3536 //end
3537
3538 if (!(strQueryWhere.length() < 4))
3539 strQueryWhere = strQueryWhere.substring(0, strQueryWhere.length()
3540 - 4);
3541 this.vecQueryWhere.setElementAt(strQueryWhere, iTableInt);
3542 for (int i = 0; i < vecColumnMode.size(); i++) {
3543 strQuery = strQuery + vecColumnNames.get(i).toString() + ", ";
3544 }
3545 strQuery = strQuery.substring(0, strQuery.length() - 2);
3546 strQuery += " from " + this.vecTableTableName.get(iTableInt).toString()
3547 + " where " + strQueryWhere;
3548 try {
3549 if (strQueryWhere.equals("")) {
3550 this.insertRow(c, vecColumnValues, vecColumnTypes, vecColumnNames,
3551 vecColumnMode, bOidLogicCurrentTable, iTableInt);
3552 bInsertTable = true;
3553 }
3554 else {
3555 Statement stmtTarget;
3556 if (this.bEnableJumpResult)
3557 stmtTarget = c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
3558 else
3559 stmtTarget = c.createStatement();
3560
3561 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
3562 ResultSet rsetTarget = stmtTarget.executeQuery(strQuery);
3563 if (!rsetTarget.next()) {
3564 this.insertRow(c, vecColumnValues, vecColumnTypes, vecColumnNames,
3565 vecColumnMode, bOidLogicCurrentTable, iTableInt);
3566 bInsertTable = true;
3567 rsetTarget.close();
3568 }
3569 else {
3570 out: do {
3571 if (bOidLogicCurrentTable && !isTOS) {
3572 iVersionValue = rsetTarget.getInt(2);
3573 if (iVersionValue > iVersionMax)
3574 iVersionMax = iVersionValue;
3575 }
3576 } while (rsetTarget.next());
3577 rsetTarget.close();
3578 if (!bInsertTable) {
3579 for (int j = 0; j < vecColumnNames.size(); j++) {
3580 String strQueryUpdate = "update " + this.vecTableTableName.get(iTableInt).toString()
3581 + " set ";
3582 if (vecColumnMode.get(j).toString().equalsIgnoreCase("Overwrite")) {
3583 strQueryUpdate += vecColumnNames.get(j).toString()
3584 + "=";
3585 if (vecColumnValues.get(j) == null)
3586 strQueryUpdate += " null ";
3587 else {
3588 if (!this.isNumber(vecColumnTypes.get(j).toString()))
3589 strQueryUpdate += "'" + vecColumnValues.get(j).toString()
3590 + "' ";
3591 else
3592 strQueryUpdate += vecColumnValues.get(j).toString()
3593 + " ";
3594 }
3595 if (bOidLogicCurrentTable && !isTOS)
3596 strQueryUpdate += ", version = " + (iVersionMax
3597 + 1) + " where ";
3598 else
3599 strQueryUpdate += " where ";
3600 // if insert table is false and execute string has "insert" skip execute
3601 if (!(this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("false")&&
3602 ((strQueryUpdate+strQueryWhere).indexOf("insert")!=-1||
3603 (strQueryUpdate+strQueryWhere).indexOf("INSERT")!=-1))) {
3604 if (bReplaceInData) {
3605 strQueryUpdate = this.replaceInData(strQueryUpdate);
3606 strQueryWhere = this.replaceInData( strQueryWhere);
3607 }
3608 this.echo.writeToLog("full", "\tQuery '" +
3609 strQueryUpdate + strQueryWhere +
3610 "' will be executed");
3611
3612 stmtTarget.executeUpdate(strQueryUpdate
3613 + strQueryWhere);
3614 bWriteData = true;
3615 }
3616 }
3617 else if (vecColumnMode.get(j).toString().equalsIgnoreCase("Update")) {
3618 strQueryUpdate += vecColumnNames.get(j).toString()
3619 + "=";
3620 if (vecColumnValues.get(j) == null)
3621 strQueryUpdate += " null ";
3622 else {
3623 if (!this.isNumber(vecColumnTypes.get(j).toString()))
3624 strQueryUpdate += "'" + vecColumnValues.get(j).toString()
3625 + "' ";
3626 else
3627 strQueryUpdate += vecColumnValues.get(j).toString()
3628 + " ";
3629 }
3630 if (bOidLogicCurrentTable && !isTOS)
3631 strQueryUpdate += ", version = " + (iVersionMax
3632 + 1) + " where ";
3633 else
3634 strQueryUpdate += " where ";
3635 strQueryUpdate += vecColumnNames.get(j).toString()
3636 + " is null and ";
3637 //if insert table is false and execute string has "insert" skip execute
3638 if (!(this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("false")&&
3639 ((strQueryUpdate+strQueryWhere).indexOf("insert")!=-1||
3640 (strQueryUpdate+strQueryWhere).indexOf("INSERT")!=-1))) {
3641 if (bReplaceInData) {
3642 strQueryUpdate = this.replaceInData(strQueryUpdate);
3643 strQueryWhere = this.replaceInData(strQueryWhere);
3644 }
3645 this.echo.writeToLog("full", "\tQuery '" +
3646 strQueryUpdate + strQueryWhere +
3647 "' will be executed");
3648
3649 int iNumRow = stmtTarget.executeUpdate(
3650 strQueryUpdate + strQueryWhere);
3651 if (iNumRow != 0)
3652 bWriteData = true;
3653 }
3654 }
3655 else if (vecColumnMode.get(j).toString().equalsIgnoreCase("SetNull")) {
3656 strQueryUpdate += vecColumnNames.get(j).toString()
3657 + "=";
3658 if (vecColumnValues.get(j) == null) {
3659 strQueryUpdate += " null ";
3660 if (bOidLogicCurrentTable && !isTOS)
3661 strQueryUpdate += ", version = " +
3662 (iVersionMax + 1) + " where ";
3663 else
3664 strQueryUpdate += " where ";
3665 //if insert table is false and execute string has "insert" skip execute
3666 if (!(this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("false")&&
3667 ((strQueryUpdate+strQueryWhere).indexOf("insert")!=-1||
3668 (strQueryUpdate+strQueryWhere).indexOf("INSERT")!=-1))) {
3669 if (bReplaceInData) {
3670 strQueryUpdate = this.replaceInData(strQueryUpdate);
3671 strQueryWhere = this.replaceInData(strQueryWhere);
3672 }
3673 this.echo.writeToLog("full", "\tQuery '"
3674 + strQueryUpdate + strQueryWhere
3675 + "' will be executed");
3676 int iNumRow = stmtTarget.executeUpdate(
3677 strQueryUpdate + strQueryWhere);
3678 if (iNumRow != 0)
3679 bWriteData = true;
3680 }
3681 }
3682 }
3683 }
3684 for (int i = 0; i < this.iRelationColumns; i++) {
3685 outLoop: if (this.vecRelationColumnSourceTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
3686 && this.vecRelationColumnSourceTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
3687 for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) {
3688 if (this.vecRelationColumnSourceTableName.get(i).toString().equalsIgnoreCase(this.vecVariableUseIDTableName.get(m).toString())
3689 && this.vecRelationColumnSourceTableID.get(i).toString().equalsIgnoreCase(this.vecVariableUseIDTableID.get(m).toString())) {
3690 String strQueryRelations = "select "
3691 + this.vecRelationColumnSourceColumnName.get(i).toString()
3692 + " from " + this.vecRelationColumnSourceTableName.get(i).toString()
3693 + " where ";
3694 strQueryRelations += vecTempKeyColumns.get(0).toString()
3695 + " = ";
3696 if (!this.isNumber(vecColumnTypes.get(0).toString()))
3697 strQueryRelations += "'" + this.strUserID
3698 + "'";
3699 else
3700 strQueryRelations += this.strUserID;
3701 this.echo.writeToLog("full", "\tQuery '"
3702 + strQueryRelations + "' will be executed");
3703 rsetTarget.close();
3704 rsetTarget = stmtTarget.executeQuery(strQueryRelations);
3705 rsetTarget.next();
3706 if (this.iTargetFirstColumnResult ==
3707 1) {
3708 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(1),
3709 i);
3710 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().getColumnTypeName(1),
3711 i);
3712 }
3713 else {
3714 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(0),
3715 i);
3716 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().getColumnTypeName(0),
3717 i);
3718 }
3719 break outLoop;
3720 }
3721 }
3722 String strQueryRelations = "select " + this.vecRelationColumnSourceColumnName.get(i).toString()
3723 + " from " + this.vecRelationColumnSourceTableName.get(i).toString()
3724 + " where " + strQueryWhere;
3725 this.echo.writeToLog("full", "\tQuery '" + strQueryRelations
3726 + "' will be executed");
3727 rsetTarget.close();
3728 rsetTarget = stmtTarget.executeQuery(strQueryRelations);
3729 rsetTarget.next();
3730 if (this.iTargetFirstColumnResult == 1) {
3731 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(1),
3732 i);
3733 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().getColumnTypeName(1),
3734 i);
3735 }
3736 else {
3737 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(0),
3738 i);
3739 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().getColumnTypeName(0),
3740 i);
3741 }
3742 }
3743 }
3744 // if(!this.strTargetDbVendor.equalsIgnoreCase("Qed"))
3745 rsetTarget.close();
3746 for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) {
3747 if (this.vecRelationColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
3748 && this.vecRelationColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
3749 if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("SetNull")) {
3750 if (this.vecRelationSourceValue.get(i) ==
3751 null) {
3752 String strUpdateRelations = this.queryRelations(iTableInt,
3753 i, strQueryWhere);
3754 this.echo.writeToLog("full", "\tQuery '"
3755 + strUpdateRelations + "' will be executed");
3756 if (bReplaceInData) {
3757 strUpdateRelations = this.replaceInData(strUpdateRelations);
3758 }
3759 int iNumRow = stmtTarget.executeUpdate(strUpdateRelations);
3760 if (iNumRow != 0)
3761 bWriteData = true;
3762 }
3763 }
3764 else {
3765 String strUpdateRelations = this.queryRelations(iTableInt,
3766 i, strQueryWhere);
3767 this.echo.writeToLog("full", "\tQuery '" +
3768 strUpdateRelations + "' will be executed");
3769 if (bReplaceInData) {
3770 strUpdateRelations = this.replaceInData(strUpdateRelations);
3771 }
3772 int iNumRow = stmtTarget.executeUpdate(strUpdateRelations);
3773 if (iNumRow != 0)
3774 bWriteData = true;
3775 }
3776 }
3777 }
3778 // Vector vecTempConstantColumns = (Vector)this.vecConstantTargetColumnName.get(iTableInt);
3779 // Vector vecTempConstantValues = (Vector)this.vecConstantConstantValue.get(iTableInt);
3780 // Vector vecTempConstantMode = (Vector)this.vecConstantValueMode.get(iTableInt);
3781 // Vector vecTempConstantType = (Vector)this.vecConstantColumnType.get(iTableInt);
3782 for (int i = 0; i < vecTempConstantColumns.size(); i++) {
3783 String vecQueryConstant = "update " + this.vecTableTableName.get(iTableInt).toString()
3784 + " set ";
3785 if (vecTempConstantMode.get(i).toString().equalsIgnoreCase("Overwrite")) {
3786 if (vecTempConstantValues.get(i) == null)
3787 vecQueryConstant += vecTempConstantColumns.get(i).toString()
3788 + " = null where ";
3789 else {
3790 if (!this.isNumber(vecTempConstantType.get(i).toString()))
3791 vecQueryConstant += vecTempConstantColumns.get(i).toString()
3792 + " = '" + vecTempConstantValues.get(i).toString()
3793 + "' where ";
3794 else
3795 vecQueryConstant += vecTempConstantColumns.get(i).toString()
3796 + " = " + vecTempConstantValues.get(i).toString()
3797 + " where ";
3798 }
3799 //if insert table is false and execute string has "insert" skip execute
3800 if (!(this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("false")&&
3801 ((vecQueryConstant + strQueryWhere).indexOf("insert")!=-1||
3802 (vecQueryConstant + strQueryWhere).indexOf("INSERT")!=-1))) {
3803 if (bReplaceInData) {
3804 vecQueryConstant = this.replaceInData(vecQueryConstant);
3805 strQueryWhere = this.replaceInData(strQueryWhere);
3806 }
3807 this.echo.writeToLog("full", "\tQuery '" +
3808 vecQueryConstant + strQueryWhere
3809 + "' will be executed");
3810 int iNumRow = stmtTarget.executeUpdate(
3811 vecQueryConstant + strQueryWhere);
3812 if (iNumRow != 0)
3813 bWriteData = true;
3814 }
3815 }
3816 else {
3817 if (vecTempConstantValues.get(i) == null)
3818 vecQueryConstant += vecTempConstantColumns.get(i).toString()
3819 + " = null where ";
3820 else {
3821 if (!this.isNumber(vecTempConstantType.get(i).toString()))
3822 vecQueryConstant += vecTempConstantColumns.get(i).toString()
3823 + " = '" + vecTempConstantValues.get(i).toString()
3824 + "' where ";
3825 else
3826 vecQueryConstant += vecTempConstantColumns.get(i).toString()
3827 + " = " + vecTempConstantValues.get(i).toString()
3828 + " where ";
3829 }
3830 //if insert table is false and execute string has "insert" skip execute
3831 if (!(this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("false")&&
3832 ((vecQueryConstant + strQueryWhere
3833 + " and " + vecTempConstantColumns.get(i).toString()
3834 + " is null").indexOf("insert")!=-1||
3835 (vecQueryConstant + strQueryWhere
3836 + " and " + vecTempConstantColumns.get(i).toString()
3837 + " is null").indexOf("INSERT")!=-1))) {
3838 if (bReplaceInData) {
3839 vecQueryConstant = this.replaceInData(vecQueryConstant);
3840 strQueryWhere = this.replaceInData(strQueryWhere);
3841 }
3842 this.echo.writeToLog("full", "\tQuery '" +
3843 vecQueryConstant + strQueryWhere
3844 + " and " + vecTempConstantColumns.get(i).toString()
3845 + " is null" + "' will be executed");
3846 int iNumRow = stmtTarget.executeUpdate(
3847 vecQueryConstant + strQueryWhere
3848 + " and " + vecTempConstantColumns.get(i).toString()
3849 + " is null");
3850 if (iNumRow != 0)
3851 bWriteData = true;
3852 }
3853 /*end if*/
3854
3855 }
3856 /*end else*/
3857
3858 }
3859
3860 /*for*/
3861 if (this.vecVariableTimesTableName.size() != 0)
3862 this.updateCurrentTime(c, iTableInt, strQueryWhere,
3863 bWriteData);
3864 if (this.vecVariableColumnTargetTableName.size() !=
3865 0)
3866 this.updateNameValue(c, iTableInt, strQueryWhere);
3867 }
3868 }
3869 stmtTarget.close();
3870 }
3871 } catch (SQLException ex) {
3872 throw ex;
3873 } catch (NullPointerException ex) {
3874 throw ex;
3875 } catch (Exception ex) {
3876 throw ex;
3877 }
3878 this.echo.writeToLog("full", "\tinsertTargetTable method is finished.");
3879 }
3880
3881 /***
3882 * Method insertRow is used to insert new row in the target table.
3883 * Also includes inserting values into constant, variable and relation columns of the target table.
3884 * If there is an error, Exception "SQLException" or "NullPointerException" or
3885 * "Exception" is thrown.
3886 * @param c Connection to the target database.
3887 * @param vecColumnValues One row of values from source table.
3888 * @param vecColumnNamesTypes Types of columns in a target table.
3889 * @param vecColumnNames Vector of column names in a target table.
3890 * @param bOIDlogicValue true if oid column exists in the target table.
3891 * @param iTableInt Number of target table which is processed.
3892 * @throws SQLException Constructs an SQLException object with a reason.
3893 * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
3894 * @throws Exception Constructs an Exception with the specified detail message.
3895 */
3896 private void insertRow (Connection c, Vector vecColumnValues, Vector vecColumnNamesTypes,
3897 Vector vecColumnNames, Vector vecColumnMode, boolean bOIDlogicValue,
3898 int iTableInt) throws SQLException, NullPointerException, Exception {
3899 this.echo.writeToLog("full", "\tinsertRow method is started.");
3900 String strQuery = "insert into " + this.vecTableTableName.get(iTableInt).toString();
3901 boolean isTOS=!(this.strObjectIDNameColumnName.equals("")||this.strObjectIDNameColumnValue.equals(""));
3902 Statement stmt = c.createStatement();
3903 String strSourceValue = "";
3904 //sinisa 15.03.2003. Add subCouterColumns
3905 Vector subCounterKeyColumns = this.counterColumns.getSubCounterKeyColumns(
3906 this.vecTableTableName.get(iTableInt).toString(), this.vecTableTableID.get(iTableInt).toString());
3907 Hashtable subKeyValues = new Hashtable();
3908 try {
3909 Vector vecTempConstantColumns = (Vector)this.vecConstantTargetColumnName.get(iTableInt);
3910 Vector vecTempConstantValues = (Vector)this.vecConstantConstantValue.get(iTableInt);
3911 if (bOIDlogicValue) {
3912 if(isTOS)
3913 strQuery = strQuery + "(OID, ";
3914 else
3915 strQuery = strQuery + "(oid,version, ";
3916 for (int j = 0; j < vecColumnValues.size(); j++) {
3917 if (!this.isRelationColumn(vecColumnNames.get(j).toString(),
3918 iTableInt)) {
3919 if (vecColumnMode.get(j).toString().equalsIgnoreCase("SetNull")) {
3920 if (vecColumnValues.get(j) == null)
3921 strQuery = strQuery + vecColumnNames.get(j).toString()
3922 + ", ";
3923 }
3924 else
3925 strQuery = strQuery + vecColumnNames.get(j).toString()
3926 + ", ";
3927 }
3928 }
3929 for (int p = 0; p < vecTempConstantColumns.size(); p++)
3930 strQuery += vecTempConstantColumns.get(p).toString() +
3931 ", ";
3932 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
3933 if (this.vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
3934 && this.vecVariableTimesTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
3935 strQuery += this.vecVariableTimesColumnName.get(i).toString()
3936 + ", ";
3937 }
3938 }
3939 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
3940 if (this.vecVariableColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
3941 && this.vecVariableColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
3942 strQuery += this.vecVariableColumnTargetColumnName.get(i).toString()
3943 + ", ";
3944 }
3945 }
3946 for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) {
3947 if (this.vecRelationColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
3948 && this.vecRelationColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
3949 if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("SetNull")) {
3950 if (this.vecRelationSourceValue.get(i) == null)
3951 strQuery += this.vecRelationColumnTargetColumnName.get(i).toString()
3952 + ", ";
3953 }
3954 else
3955 strQuery += this.vecRelationColumnTargetColumnName.get(i).toString()
3956 + ", ";
3957 }
3958 }
3959
3960 //sinisa 02.03.2003. Add couterColumns
3961 Vector counterColNames = this.counterColumns.getTargetColumnName(this.vecTableTableName.get(iTableInt).toString(),
3962 this.vecTableTableID.get(iTableInt).toString());
3963 for (int i = 0; i < counterColNames.size(); i++) {
3964 if(counterColNames.get(i)!=null)
3965 strQuery += counterColNames.get(i).toString() + ", ";
3966 }
3967 //end sinisa
3968 //sinisa 15.03.2003. Add subCouterColumns
3969 Vector subCounterColNames = this.counterColumns.getSubTargetColumnName(this.vecTableTableName.get(iTableInt).toString(),
3970 this.vecTableTableID.get(iTableInt).toString());
3971 for (int i = 0; i < subCounterColNames.size(); i++) {
3972 if(subCounterColNames.get(i)!=null)
3973 strQuery += subCounterColNames.get(i).toString() + ", ";
3974 }
3975 //end sinisa
3976
3977 strQuery = strQuery.substring(0, strQuery.length() - 2);
3978 if(isTOS)
3979 strQuery = strQuery + ") VALUES('" + this.bdecOidNumber + "', ";
3980 else
3981 strQuery = strQuery + ") VALUES(" + this.bdecOidNumber + ", 0, ";
3982 for (int j = 0; j < vecColumnValues.size(); j++) {
3983 if (!this.isRelationColumn(vecColumnNames.get(j).toString(),
3984 iTableInt)) {
3985 if (vecColumnMode.get(j).toString().equalsIgnoreCase("SetNull")) {
3986 if (vecColumnValues.get(j) == null)
3987 strQuery += " null, ";
3988 }
3989 else {
3990 if (vecColumnValues.get(j) == null)
3991 strQuery += " null, ";
3992 else {
3993 if (!this.isNumber(vecColumnNamesTypes.get(j).toString())) {
3994 strQuery += "'" + vecColumnValues.get(j).toString()
3995 + "', ";
3996 }
3997 else {
3998 strQuery += vecColumnValues.get(j).toString()
3999 + ", ";
4000 }
4001 }
4002 }
4003 }
4004 // sinisa 15.03 Add subCounter columns
4005 for(int l=0; l<subCounterKeyColumns.size();l++) {
4006 if(subCounterKeyColumns.get(l)!=null && ((Vector)subCounterKeyColumns.get(l)).size()!=0 && ((Vector)subCounterKeyColumns.get(l)).contains(vecColumnNames.get(j).toString())) {
4007 if(vecColumnValues.get(j)!=null) {
4008 subKeyValues.put(vecColumnNames.get(j).toString(),vecColumnValues.get(j).toString());
4009 }
4010 }
4011 }
4012 }
4013 for (int p = 0; p < vecTempConstantValues.size(); p++) {
4014 if (vecTempConstantValues.get(p) == null)
4015 strQuery += null + ", ";
4016 else {
4017 if (!this.isNumber(((Vector)this.vecConstantColumnType.get(iTableInt)).get(p).toString())) {
4018 strQuery += "'" + vecTempConstantValues.get(p).toString()
4019 + "' , ";
4020 }
4021 else
4022 strQuery += vecTempConstantValues.get(p).toString()
4023 + ", ";
4024 }
4025 // sinisa 15.03 Add subCounter columns
4026 for(int l=0; l<subCounterKeyColumns.size();l++) {
4027 if(subCounterKeyColumns.get(l)!=null && ((Vector)subCounterKeyColumns.get(l)).size()!=0 && ((Vector)subCounterKeyColumns.get(l)).contains(vecTempConstantColumns.get(p))) {
4028 if(vecTempConstantValues.get(p)!=null)
4029 subKeyValues.put(vecTempConstantColumns.get(p).toString(),vecTempConstantValues.get(p).toString());
4030 }
4031 }
4032 }
4033 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
4034 if (this.vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4035 && this.vecVariableTimesTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4036 strQuery += "'" + createCurrentDate() + "', ";
4037 }
4038 }
4039 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
4040 if (this.vecVariableColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4041 && this.vecVariableColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4042 int iPositionInVector = this.vecVariableName.indexOf(this.vecVariableColumnName.get(i).toString());
4043 if (iPositionInVector != -1) {
4044 if (this.vecVariableValue.get(iPositionInVector)
4045 == null)
4046 strQuery += " null, ";
4047 else {
4048 if (!isNumber(this.vecVariableColumnTypes.get(i).toString()))
4049 strQuery += "'" + this.vecVariableValue.get(iPositionInVector).toString()
4050 + "', ";
4051 else
4052 strQuery += this.vecVariableValue.get(iPositionInVector).toString()
4053 + ", ";
4054 }
4055 }
4056 else {
4057 this.echo.writeToLog("none", "\tError: Cannot find value for variable column :"
4058 + this.vecVariableColumnName.get(i).toString());
4059 LoaderException le = new LoaderException("Exception: ",
4060 (Throwable)(new Exception("Error: Cannot find value for variable column :")));
4061 throw le;
4062 // System.exit(1);
4063 }
4064 // sinisa 15.03 Add subCounter columns
4065 for(int l=0; l<subCounterKeyColumns.size();l++) {
4066 if(subCounterKeyColumns.get(l)!=null && ((Vector)subCounterKeyColumns.get(l)).size()!=0 && ((Vector)subCounterKeyColumns.get(l)).contains(this.vecVariableColumnName.get(iPositionInVector))) {
4067 if(this.vecVariableValue.get(iPositionInVector)!=null)
4068 subKeyValues.put(this.vecVariableColumnName.get(iPositionInVector).toString(),this.vecVariableValue.get(iPositionInVector).toString());
4069 }
4070 }
4071 }
4072
4073 }
4074 //find value for relation column - userID
4075 for (int i = 0; i < this.iRelationColumns; i++) {
4076 outLoop1: if (this.vecRelationColumnSourceTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4077 && this.vecRelationColumnSourceTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4078 for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) {
4079 if (this.vecRelationColumnSourceTableName.get(i).toString().equalsIgnoreCase(this.vecVariableUseIDTableName.get(m).toString())
4080 && this.vecRelationColumnSourceTableID.get(i).toString().equalsIgnoreCase(this.vecVariableUseIDTableID.get(m).toString())) {
4081 String strQueryRelations = "select " + this.vecRelationColumnSourceColumnName.get(i).toString()
4082 + " from " + this.vecRelationColumnSourceTableName.get(i).toString()
4083 + " where ";
4084 strQueryRelations += ((Vector)this.vecTargetKeyColumnName.get(iTableInt)).get(0).toString()
4085 + " = ";
4086 if (!this.isNumber(vecColumnNamesTypes.get(0).toString()))
4087 strQueryRelations += "'" + this.strUserID
4088 + "'";
4089 else
4090 strQueryRelations += this.strUserID;
4091 this.echo.writeToLog("full", "\tQuery '" + strQueryRelations
4092 + "' will be executed");
4093 ResultSet rsetTarget = stmt.executeQuery(strQueryRelations);
4094 rsetTarget.next();
4095 if (this.iTargetFirstColumnResult == 1) {
4096 // this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(1),
4097 // i);
4098 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(1),
4099 i);
4100 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().getColumnTypeName(1),
4101 i);
4102 }
4103 else {
4104 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(0),
4105 i);
4106 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().getColumnTypeName(0),
4107 i);
4108 }
4109 strSourceValue = this.vecRelationSourceValue.get(i).toString();
4110 rsetTarget.close();
4111 break outLoop1;
4112 }
4113 }
4114 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
4115 //if (true) {
4116 this.vecRelationSourceValue.setElementAt(this.bdecOidNumber,
4117 i);
4118 this.vecRelationSourceType.setElementAt("decimal",
4119 i);
4120 strSourceValue = this.vecRelationSourceValue.get(i).toString();
4121 }
4122 else {
4123
4124 this.vecRelationSourceValue.setElementAt(null,
4125 i);
4126 this.vecRelationSourceType.setElementAt("decimal",
4127 i);
4128 strSourceValue = "null";
4129 }
4130 }
4131 }
4132 for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) {
4133 if (this.vecRelationColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4134 && this.vecRelationColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4135 if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("SetNull")) {
4136 if (this.vecRelationSourceValue.get(i) == null)
4137 strQuery += " null, ";
4138 }
4139 else {
4140 if (this.vecRelationSourceValue.get(i) == null)
4141 strQuery += " null, ";
4142 else {
4143 if (isNumber(this.vecRelationSourceType.get(i).toString()))
4144 strQuery += this.vecRelationSourceValue.get(i).toString()
4145 + ", ";
4146 else
4147 strQuery += "'" + this.vecRelationSourceValue.get(i).toString()
4148 + "', ";
4149 }
4150 }
4151 // sinisa 15.03 Add subCounter columns
4152 for(int l=0; l<subCounterKeyColumns.size();l++) {
4153 if(subCounterKeyColumns.get(l)!=null && ((Vector)subCounterKeyColumns.get(l)).size()!=0 && ((Vector)subCounterKeyColumns.get(l)).contains(this.vecRelationColumnTargetColumnName.get(i))) {
4154 if(this.vecRelationSourceValue.get(i)!=null)
4155 subKeyValues.put(this.vecRelationColumnTargetColumnName.get(i).toString(),this.vecRelationSourceValue.get(i).toString());
4156 }
4157 }
4158 }
4159
4160 }
4161 //sinisa 02.03.2003. Add couterColumns
4162 Vector counterColValues = this.counterColumns.getCounterValue(
4163 this.vecTableTableName.get(iTableInt).toString(), this.vecTableTableID.get(iTableInt).toString());
4164 for (int i = 0; i < counterColValues.size(); i++) {
4165 if(counterColValues.get(i)!=null)
4166 strQuery += new BigDecimal(counterColValues.get(i).toString()).intValue() + ", ";
4167 else
4168 strQuery += " null, ";
4169 }
4170 this.counterColumns.setCounterValue(this.vecTableTableName.get(iTableInt).toString(),
4171 this.vecTableTableID.get(iTableInt).toString());
4172 //end sinisa
4173
4174 //sinisa 15.03.2003. Add couterColumns
4175 this.counterColumns.setSubCounterKeyValues(
4176 this.vecTableTableName.get(iTableInt).toString(), this.vecTableTableID.get(iTableInt).toString(), subKeyValues);
4177 Vector subCounterColValues = this.counterColumns.readSubCounterValue(
4178 this.vecTableTableName.get(iTableInt).toString(), this.vecTableTableID.get(iTableInt).toString(), c,this.iTargetFirstColumnResult);
4179 for (int i = 0; i < subCounterColValues.size(); i++) {
4180 if(subCounterColValues.get(i)!=null)
4181 strQuery += new BigDecimal(subCounterColValues.get(i).toString()).intValue() + ", ";
4182 else
4183 strQuery += " null, ";
4184 }
4185 //end sinisa
4186
4187
4188 if (this.bdecOidNumber.compareTo(this.bdecOidNumber2000) ==
4189 0) {
4190 this.checkOidLogic(c);
4191 this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal(1));
4192 }
4193 else
4194 this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal(1));
4195 }
4196 // if oidLogic is false
4197 else {
4198 strQuery = strQuery + "(";
4199 for (int j = 0; j < vecColumnValues.size(); j++) {
4200 if (!this.isRelationColumn(vecColumnNames.get(j).toString(),
4201 iTableInt)) {
4202 if (vecColumnMode.get(j).toString().equalsIgnoreCase("SetNull")) {
4203 if (vecColumnValues.get(j) == null)
4204 strQuery = strQuery + vecColumnNames.get(j).toString()
4205 + ", ";
4206 }
4207 else
4208 strQuery = strQuery + vecColumnNames.get(j).toString()
4209 + ", ";
4210 }
4211 }
4212 for (int p = 0; p < vecTempConstantColumns.size(); p++)
4213 strQuery += vecTempConstantColumns.get(p).toString() +
4214 ", ";
4215 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
4216 if (this.vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4217 && this.vecVariableTimesTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4218 strQuery += this.vecVariableTimesColumnName.get(i).toString()
4219 + ", ";
4220 }
4221 }
4222 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
4223 if (this.vecVariableColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4224 && this.vecVariableColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4225 strQuery += this.vecVariableColumnTargetColumnName.get(i).toString()
4226 + ", ";
4227 }
4228 }
4229 for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) {
4230 if (this.vecRelationColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4231 && this.vecRelationColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4232 if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("SetNull")) {
4233 if (this.vecRelationSourceValue.get(i) == null)
4234 strQuery += this.vecRelationColumnTargetColumnName.get(i).toString()
4235 + ", ";
4236 }
4237 else
4238 strQuery += this.vecRelationColumnTargetColumnName.get(i).toString()
4239 + ", ";
4240 }
4241 }
4242 //sinisa 02.03.2003. Add couterColumns
4243 Vector counterColNames = this.counterColumns.getTargetColumnName(this.vecTableTableName.get(iTableInt).toString(),
4244 this.vecTableTableID.get(iTableInt).toString());
4245 for (int i = 0; i < counterColNames.size(); i++) {
4246 if(counterColNames.get(i)!=null)
4247 strQuery += counterColNames.get(i).toString() + ", ";
4248 }
4249 //end sinisa
4250 //sinisa 15.03.2003. Add subCouterColumns
4251 Vector subCounterColNames = this.counterColumns.getSubTargetColumnName(this.vecTableTableName.get(iTableInt).toString(),
4252 this.vecTableTableID.get(iTableInt).toString());
4253 for (int i = 0; i < subCounterColNames.size(); i++) {
4254 if(subCounterColNames.get(i)!=null)
4255 strQuery += subCounterColNames.get(i).toString() + ", ";
4256 }
4257 //end sinisa
4258
4259 strQuery = strQuery.substring(0, strQuery.length() - 2);
4260 strQuery = strQuery + ") VALUES(";
4261 for (int j = 0; j < vecColumnValues.size(); j++) {
4262 if (!this.isRelationColumn(vecColumnNames.get(j).toString(),
4263 iTableInt)) {
4264 if (vecColumnMode.get(j).toString().equalsIgnoreCase("SetNull")) {
4265 if (vecColumnValues.get(j) == null)
4266 strQuery += " null, ";
4267 }
4268 else {
4269 if (vecColumnValues.get(j) == null)
4270 strQuery += " null, ";
4271 else {
4272 if (!this.isNumber(vecColumnNamesTypes.get(j).toString()))
4273 strQuery = strQuery + "'" + vecColumnValues.get(j).toString()
4274 + "', ";
4275 else
4276 strQuery = strQuery + vecColumnValues.get(j).toString()
4277 + ", ";
4278 }
4279 }
4280 }
4281 // sinisa 15.03 Add subCounter columns
4282 for(int l=0; l<subCounterKeyColumns.size();l++) {
4283 if(subCounterKeyColumns.get(l)!=null && ((Vector)subCounterKeyColumns.get(l)).size()!=0 && ((Vector)subCounterKeyColumns.get(l)).contains(vecColumnNames.get(j).toString())) {
4284 if(vecColumnValues.get(j)!=null) {
4285 subKeyValues.put(vecColumnNames.get(j).toString(),vecColumnValues.get(j).toString());
4286 }
4287 }
4288 }
4289 }
4290 for (int p = 0; p < vecTempConstantValues.size(); p++) {
4291 if (vecTempConstantValues.get(p) == null)
4292 strQuery += null + ", ";
4293 else {
4294 if (!this.isNumber(((Vector)this.vecConstantColumnType.get(iTableInt)).get(p).toString()))
4295 strQuery += "'" + vecTempConstantValues.get(p).toString()
4296 + "' , ";
4297 else
4298 strQuery += vecTempConstantValues.get(p).toString()
4299 + ", ";
4300 }
4301 // sinisa 15.03 Add subCounter columns
4302 for(int l=0; l<subCounterKeyColumns.size();l++) {
4303 if(subCounterKeyColumns.get(l)!=null && ((Vector)subCounterKeyColumns.get(l)).size()!=0 && ((Vector)subCounterKeyColumns.get(l)).contains(vecTempConstantColumns.get(p))) {
4304 if(vecTempConstantValues.get(p)!=null)
4305 subKeyValues.put(vecTempConstantColumns.get(p).toString(),vecTempConstantValues.get(p).toString());
4306 }
4307 }
4308 }
4309 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
4310 if (this.vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4311 && this.vecVariableTimesTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4312 strQuery += "'" + createCurrentDate() + "', ";
4313 }
4314 }
4315 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
4316 if (this.vecVariableColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4317 && this.vecVariableColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4318 int iPositionInVector = this.vecVariableName.indexOf(this.vecVariableColumnName.get(i).toString());
4319 if (iPositionInVector != -1) {
4320 if (this.vecVariableValue.get(iPositionInVector)
4321 == null)
4322 strQuery += " null, ";
4323 else {
4324 if (!isNumber(this.vecVariableColumnTypes.get(i).toString()))
4325 strQuery += "'" + this.vecVariableValue.get(iPositionInVector).toString()
4326 + "', ";
4327 else
4328 strQuery += this.vecVariableValue.get(iPositionInVector).toString()
4329 + ", ";
4330 }
4331 }
4332 else {
4333 this.echo.writeToLog("none", "\tError: Cannot find value for variable column :"
4334 + this.vecVariableColumnName.get(i).toString());
4335 LoaderException le = new LoaderException("Exception: ",
4336 (Throwable)(new Exception("Error: Cannot find value for variable column :")));
4337 throw le;
4338 // System.exit(1);
4339 }
4340 // sinisa 15.03 Add subCounter columns
4341 for(int l=0; l<subCounterKeyColumns.size();l++) {
4342 if(subCounterKeyColumns.get(l)!=null && ((Vector)subCounterKeyColumns.get(l)).size()!=0 && ((Vector)subCounterKeyColumns.get(l)).contains(this.vecVariableColumnName.get(iPositionInVector))) {
4343 if(this.vecVariableValue.get(iPositionInVector)!=null)
4344 subKeyValues.put(this.vecVariableColumnName.get(iPositionInVector).toString(),this.vecVariableValue.get(iPositionInVector).toString());
4345 }
4346 }
4347 }
4348 }
4349 for (int i = 0; i < this.iRelationColumns; i++) {
4350 outLoop2: if (this.vecRelationColumnSourceTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4351 && this.vecRelationColumnSourceTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4352 for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) {
4353 if (this.vecRelationColumnSourceTableName.get(i).toString().equalsIgnoreCase(this.vecVariableUseIDTableName.get(m).toString())
4354 && this.vecRelationColumnSourceTableID.get(i).toString().equalsIgnoreCase(this.vecVariableUseIDTableID.get(m).toString())) {
4355 String strQueryRelations = "select " + this.vecRelationColumnSourceColumnName.get(i).toString()
4356 + " from " + this.vecRelationColumnSourceTableName.get(i).toString()
4357 + " where ";
4358 strQueryRelations += ((Vector)this.vecTargetKeyColumnName.get(iTableInt)).get(0).toString()
4359 + " = ";
4360 if (!this.isNumber(vecColumnNamesTypes.get(0).toString()))
4361 strQueryRelations += "'" + this.strUserID
4362 + "'";
4363 else
4364 strQueryRelations += this.strUserID;
4365 this.echo.writeToLog("full", "\tQuery '" + strQueryRelations
4366 + "' will be executed");
4367 ResultSet rsetTarget = stmt.executeQuery(strQueryRelations);
4368 rsetTarget.next();
4369 if (this.iTargetFirstColumnResult == 1) {
4370 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(1),
4371 i);
4372 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().getColumnTypeName(1),
4373 i);
4374 }
4375 else {
4376 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(0),
4377 i);
4378 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData().getColumnTypeName(0),
4379 i);
4380 }
4381 strSourceValue = this.vecRelationSourceValue.get(i).toString();
4382 rsetTarget.close();
4383 break outLoop2;
4384 }
4385 }
4386 for (int j = 0; j < this.iRelationColumns; j++) {
4387 if (this.vecRelationColumnSourceColumnName.get(i).toString().equalsIgnoreCase(vecColumnNames.get(j).toString())) {
4388 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) {
4389 //if (true) {
4390 this.vecRelationSourceValue.setElementAt(vecColumnValues.get(j).toString(),
4391 i);
4392 this.vecRelationSourceType.setElementAt(vecColumnNamesTypes.get(j).toString(),
4393 i);
4394 strSourceValue = this.vecRelationSourceValue.get(i).toString();
4395 }
4396 else {
4397 this.vecRelationSourceValue.setElementAt(null,
4398 i);
4399 this.vecRelationSourceType.setElementAt(vecColumnNamesTypes.get(j).toString(),
4400 i);
4401 strSourceValue = "null";
4402 }
4403 }
4404 }
4405 }
4406 }
4407 for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) {
4408 if (this.vecRelationColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString())
4409 && this.vecRelationColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) {
4410 if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("SetNull")) {
4411 if (this.vecRelationSourceValue.get(i) == null)
4412 strQuery += " null, ";
4413 }
4414 else {
4415 if (this.vecRelationSourceValue.get(i) == null)
4416 strQuery += " null, ";
4417 else {
4418 if (isNumber(this.vecRelationSourceType.get(i).toString()))
4419 strQuery += this.vecRelationSourceValue.get(i).toString()
4420 + ", ";
4421 else
4422 strQuery += "'" + this.vecRelationSourceValue.get(i).toString()
4423 + "', ";
4424 }
4425 }
4426 // sinisa 15.03 Add subCounter columns
4427 for(int l=0; l<subCounterKeyColumns.size();l++) {
4428 if(subCounterKeyColumns.get(l)!=null && ((Vector)subCounterKeyColumns.get(l)).size()!=0 && ((Vector)subCounterKeyColumns.get(l)).contains(this.vecRelationColumnTargetColumnName.get(i))) {
4429 if(this.vecRelationSourceValue.get(i)!=null)
4430 subKeyValues.put(this.vecRelationColumnTargetColumnName.get(i).toString(),this.vecRelationSourceValue.get(i).toString());
4431 }
4432 }
4433 }
4434 }
4435 //sinisa 02.03.2003. Add couterColumns
4436 Vector counterColValues = this.counterColumns.getCounterValue(
4437 this.vecTableTableName.get(iTableInt).toString(), this.vecTableTableID.get(iTableInt).toString());
4438 for (int i = 0; i < counterColValues.size(); i++) {
4439 if(counterColValues.get(i)!=null)
4440 strQuery += new BigDecimal(counterColValues.get(i).toString()).intValue() + ", ";
4441 else
4442 strQuery += " null, ";
4443 }
4444 this.counterColumns.setCounterValue(this.vecTableTableName.get(iTableInt).toString(),
4445 this.vecTableTableID.get(iTableInt).toString());
4446
4447 //end sinisa
4448
4449 //sinisa 15.03.2003. Add couterColumns
4450 this.counterColumns.setSubCounterKeyValues(
4451 this.vecTableTableName.get(iTableInt).toString(), this.vecTableTableID.get(iTableInt).toString(), subKeyValues);
4452 Vector subCounterColValues = this.counterColumns.readSubCounterValue(
4453 this.vecTableTableName.get(iTableInt).toString(), this.vecTableTableID.get(iTableInt).toString(), c,this.iTargetFirstColumnResult);
4454 for (int i = 0; i < subCounterColValues.size(); i++) {
4455 if(subCounterColValues.get(i)!=null)
4456 strQuery += new BigDecimal(subCounterColValues.get(i).toString()).intValue() + ", ";
4457 else
4458 strQuery += " null, ";
4459 }
4460 //end sinisa
4461
4462
4463 }
4464 strQuery = strQuery.substring(0, strQuery.length() - 2);
4465 strQuery += ")";
4466 //if insert table is false and execute string has "insert" skip execute
4467 if (!(this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("false")&&
4468 (strQuery.indexOf("insert")!=-1||
4469 strQuery.indexOf("INSERT")!=-1))) {
4470 if (bReplaceInData) {
4471 strQuery = this.replaceInData(strQuery);
4472 }
4473 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
4474 stmt.executeUpdate(strQuery);
4475 this.counterColumns.updateCounter(this.vecTableTableName.get(iTableInt).toString(),
4476 this.vecTableTableID.get(iTableInt).toString(),c);
4477
4478 }
4479 stmt.close();
4480 } catch (SQLException ex) {
4481 throw ex;
4482 } catch (NullPointerException ex) {
4483 throw ex;
4484 } catch (Exception ex) {
4485 throw ex;
4486 }
4487 this.echo.writeToLog("full", "\tinsertRow method is finished.");
4488 }
4489
4490 /***
4491 * Method isRelationColumn checkes if the column(strColumnName) in target table(iTable)
4492 * is mentioned in relation tags (target column name). If it is, return true, else return false.
4493 * @param strColumnName - Name of target column
4494 * @param iTable - Number of target table
4495 * @return boolean - true if strColumnName is relation target column, false if it is not.
4496 */
4497 private boolean isRelationColumn (String strColumnName, int iTable) {
4498 boolean bFind = false;
4499 endFor: for (int i = 0; i < this.vecRelationColumnTargetTableName.size(); i++) {
4500 if (this.vecRelationColumnTargetTableName.get(i).toString().equalsIgnoreCase(this.vecTableTableName.get(iTable).toString())
4501 && this.vecRelationColumnTargetTableID.get(i).toString().equalsIgnoreCase(this.vecTableTableID.get(iTable).toString())
4502 && this.vecRelationColumnTargetColumnName.get(i).toString().equalsIgnoreCase(strColumnName)) {
4503 bFind = true;
4504 break endFor;
4505 }
4506 }
4507 return bFind;
4508 }
4509
4510 /***
4511 * Method checkOidLogic is used to increase the ObjectID value with adding iObjectIDIncrement value.
4512 * Method puts new value in ObjectID table for current importDefinition.
4513 * If there is an error, Exception "SQLException" or NullPointerException is thrown.
4514 * @param c Connection to target database.
4515 * @throws SQLException Constructs an SQLException object with a reason.
4516 * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
4517 */
4518 private void checkOidLogic (Connection c) throws SQLException, NullPointerException {
4519 String strQuery = "";
4520 this.echo.writeToLog("full", "\tcheckOidLogic method is started.");
4521 Boolean bTemp = new Boolean("false");
4522 for (int i = 0; i < this.iTables; i++) {
4523 if (this.vecTableOidLogic.get(i).toString().equalsIgnoreCase("true")) {
4524 bTemp = new Boolean("true");
4525 }
4526 }
4527 if (bTemp.booleanValue()) {
4528 try {
4529 if(!(this.strObjectIDNameColumnName.equals("")||this.strObjectIDNameColumnValue.equals(""))) {
4530 strQuery = new String("SELECT " + this.strObjectIDColumnName
4531 + " FROM " + this.strObjectIDTableName + " WHERE "
4532 + this.strObjectIDNameColumnName +" = '" +this.strObjectIDNameColumnValue+"'");
4533 }
4534 else {
4535 strQuery = new String("SELECT " + this.strObjectIDColumnName
4536 + " FROM " + this.strObjectIDTableName);
4537 }
4538 Statement stmtOid = c.createStatement();
4539 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
4540 ResultSet rsetOid = stmtOid.executeQuery(strQuery);
4541 if(rsetOid.next()) {
4542 if (this.iTargetFirstColumnResult == 1)
4543 this.bdecOidNumber = new BigDecimal(Integer.parseInt(rsetOid.getString(1)));
4544 else
4545 this.bdecOidNumber = new BigDecimal(Integer.parseInt(rsetOid.getString(0)));
4546 }
4547 else {
4548 if(!(this.strObjectIDNameColumnName.equals("")||this.strObjectIDNameColumnValue.equals(""))) {
4549 String insert = "insert " + this.strObjectIDTableName + " (" +
4550 this.strObjectIDNameColumnName +","+ this.strObjectIDColumnName+") values ('" + this.strObjectIDNameColumnValue
4551 + "','"+ this.iObjectIDStartValue+"');";
4552 stmtOid.execute(insert);
4553 }
4554 }
4555 rsetOid.close();
4556 stmtOid.close();
4557 this.bdecOidNumber2000 = this.bdecOidNumber.add(new BigDecimal(this.iObjectID));
4558 stmtOid = c.createStatement();
4559 if(!(this.strObjectIDNameColumnName.equals("")||this.strObjectIDNameColumnValue.equals(""))) {
4560 this.echo.writeToLog("full", "\tQuery '" + "UPDATE " + this.strObjectIDTableName
4561 + " SET " + this.strObjectIDColumnName + " = " + this.bdecOidNumber2000
4562 + " where " + this.strObjectIDNameColumnName +" = '" +this.strObjectIDNameColumnValue+"'' will be executed");
4563 stmtOid.executeUpdate("UPDATE " + this.strObjectIDTableName
4564 + " SET " + this.strObjectIDColumnName + " = " + this.bdecOidNumber2000
4565 + " where " + this.strObjectIDNameColumnName +" = '" +this.strObjectIDNameColumnValue+"'");
4566
4567 }
4568 else {
4569 this.echo.writeToLog("full", "\tQuery '" + "UPDATE " + this.strObjectIDTableName
4570 + " SET " + this.strObjectIDColumnName + " = " + this.bdecOidNumber2000
4571 + " where " + this.strObjectIDColumnName + " = " +
4572 this.bdecOidNumber + "' will be executed");
4573 stmtOid.executeUpdate("UPDATE " + this.strObjectIDTableName
4574 + " SET " + this.strObjectIDColumnName + " = " + this.bdecOidNumber2000
4575 + " where " + this.strObjectIDColumnName + " = " +
4576 this.bdecOidNumber);
4577 }
4578 stmtOid.close();
4579 } catch (SQLException ex) {
4580 throw ex;
4581 } catch (NullPointerException ex) {
4582 throw ex;
4583 }
4584 }
4585 this.echo.writeToLog("full", "\tcheckOidLogic method is finished.");
4586 }
4587
4588
4589
4590
4591 /***
4592 * Method querySource is used to make SQL query to source table and to
4593 * sort columns from source table ordered by sortColumns.
4594 * @return SQL Query to source table.
4595 */
4596 private String querySource () {
4597 int i = 0;
4598 int j = 0;
4599 this.echo.writeToLog("full", "\tquerySource method is started.");
4600 Vector vecVektor = new Vector();
4601 String strQuery = "select ";
4602 while (i < this.iTables) {
4603 vecVektor = (Vector)this.vecSourceColumnName.get(i);
4604 while (j < Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString())) {
4605 strQuery = strQuery + vecVektor.get(j).toString() + ", ";
4606 j++;
4607 this.iColumnsInSourceTable++;
4608 }
4609 j = 0;
4610 i++;
4611 }
4612 strQuery = strQuery.substring(0, strQuery.length() - 2);
4613 strQuery += " from " + this.strImportDefinitionTableName;
4614 if (this.vecRestartCounterSortColumn.size() != 0) {
4615 if (this.bEnableOrderBy) {
4616 strQuery += " order by ";
4617 for (j = 0; j < this.vecRestartCounterSortColumn.size(); j++) {
4618 strQuery += this.vecRestartCounterSortColumn.get(j).toString()
4619 + ", ";
4620 }
4621 strQuery = strQuery.substring(0, strQuery.length() - 2);
4622 }
4623 }
4624 this.echo.writeToLog("full", "\tquerySource method is finished.");
4625 return strQuery;
4626 }
4627
4628
4629
4630
4631 /***
4632 * Method sourceColumnTypes is used to put source table column types
4633 * into Vector "vecSourceColumnType". This includes columns from the querySource
4634 * method. If there is an error, Exception "SQLException" or NullPointerException
4635 * is thrown.
4636 * @param connTarget Connection to the target table.
4637 * @throws SQLException Constructs an SQLException object with a reason.
4638 * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
4639 */
4640 private void sourceColumnTypes (Connection connTarget) throws SQLException,
4641 NullPointerException {
4642 int iColumn;
4643 String strQueryTypes = "";
4644 this.echo.writeToLog("full", "\tsourceColumnTypes method is started.");
4645 try {
4646 for (int i = 0; i < this.iTables; i++) {
4647 Vector vecKeyTypesRelations = new Vector();
4648 Vector vecVektor = new Vector();
4649 iColumn = 0;
4650 Statement stmtTypes = connTarget.createStatement();
4651 strQueryTypes = "select ";
4652 for (int j = 0; j < ((Vector)this.vecTargetColumnName.get(i)).size(); j++) {
4653 strQueryTypes += (((Vector)this.vecTargetColumnName.get(i)).get(j).toString())
4654 + ",";
4655 }
4656 for (int j = 0; j < ((Vector)this.vecRelationKeyColumns.get(i)).size(); j++) {
4657 strQueryTypes += (((Vector)this.vecRelationKeyColumns.get(i)).get(j).toString())
4658 + ",";
4659 }
4660 strQueryTypes = strQueryTypes.substring(0, strQueryTypes.length()
4661 - 1);
4662 strQueryTypes += " from ";
4663 strQueryTypes += " " + this.vecTableTableName.get(i).toString();
4664 ResultSet rsetTypes;
4665 if (((Vector)this.vecTargetColumnName.get(i)).size() != 0 ||
4666 ((Vector)this.vecRelationKeyColumns.get(i)).size() !=
4667 0) {
4668 this.echo.writeToLog("full", "\tQuery '" + strQueryTypes +
4669 "' will be executed");
4670 rsetTypes = stmtTypes.executeQuery(strQueryTypes);
4671 for (int j = 0; j < ((Vector)this.vecValueMode.get(i)).size(); j++) {
4672 iColumn++;
4673 if (this.iTargetFirstColumnResult == 1)
4674 vecVektor.add(rsetTypes.getMetaData().getColumnTypeName(iColumn));
4675 else
4676 vecVektor.add(rsetTypes.getMetaData().getColumnTypeName(
4677 iColumn - 1));
4678 }
4679 for (int j = 0; j < ((Vector)this.vecRelationKeyColumns.get(i)).size(); j++) {
4680 iColumn++;
4681 if (this.iTargetFirstColumnResult == 1)
4682 vecKeyTypesRelations.add(rsetTypes.getMetaData().getColumnTypeName(iColumn));
4683 else
4684 vecKeyTypesRelations.add(rsetTypes.getMetaData().getColumnTypeName(
4685 iColumn - 1));
4686 }
4687 rsetTypes.close();
4688 stmtTypes.close();
4689 }
4690 this.vecRelationKeyTypes.setElementAt(vecKeyTypesRelations,
4691 i);
4692 this.vecSourceColumnType.add(vecVektor);
4693 }
4694 Statement stmtVariableTypes = connTarget.createStatement();
4695 for (int j = 0; j < this.vecVariableColumnTargetTableName.size(); j++) {
4696 strQueryTypes = "select ";
4697 strQueryTypes += this.vecVariableColumnTargetColumnName.get(j).toString()
4698 + " from ";
4699 strQueryTypes += this.vecVariableColumnTargetTableName.get(j).toString();
4700 ResultSet rsetVariableTypes;
4701 this.echo.writeToLog("full", "\tQuery '" + strQueryTypes + "' will be executed");
4702 rsetVariableTypes = stmtVariableTypes.executeQuery(strQueryTypes);
4703 if (this.iTargetFirstColumnResult == 1)
4704 this.vecVariableColumnTypes.add(rsetVariableTypes.getMetaData().getColumnTypeName(1));
4705 else
4706 this.vecVariableColumnTypes.add(rsetVariableTypes.getMetaData().getColumnTypeName(0));
4707 rsetVariableTypes.close();
4708 }
4709 stmtVariableTypes.close();
4710 } catch (SQLException ex) {
4711 throw ex;
4712 } catch (NullPointerException ex) {
4713 throw ex;
4714 }
4715 this.echo.writeToLog("full", "\tsourceColumnTypes method is finished.");
4716 }
4717
4718 /***
4719 * Method checkDataTransmition is used to check input parameter "restart".
4720 * If loader started as a restart application,reads values from restart
4721 * counter table and sets this parameter.
4722 * If there is an error, Exception "SQLException" or NullPointerException is thrown.
4723 * @param bArg2 Boolean type which is true if "restart" mode and false if "new" mode.
4724 * @param c Connection to a Loader database.
4725 * @param rset Pointer to the source table.
4726 * @return Value of restart counter in the target table.
4727 * @throws SQLException Constructs an SQLException object with a reason.
4728 */
4729 private BigDecimal checkDataTransmition (boolean bArg2, Connection c, ResultSet rset) throws SQLException {
4730 String strQuery = "";
4731 String strQueryDelete = "";
4732 this.echo.writeToLog("full", "\tcheckDataTransmition method is started.");
4733 BigDecimal bdecRestartCounter = new BigDecimal(0);
4734 try {
4735 strQuery = "SELECT " + this.strRestartCounterValue + " FROM " +
4736 this.strRestartCounterTableName + " WHERE " + this.strRestartCounterImportDefinitionName
4737 + " = '" + this.strImportDefinitionName + "'";
4738 Statement stmtCountT = c.createStatement();
4739 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
4740 ResultSet rsetCountT = stmtCountT.executeQuery(strQuery);
4741 if (!rsetCountT.next()) {
4742 strQuery = "INSERT into " + this.strRestartCounterTableName
4743 + " (" + this.strRestartCounterImportDefinitionName
4744 + ", " + this.strRestartCounterValue + ") " + " VALUES ('"
4745 + this.strImportDefinitionName + "', null)";
4746 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
4747 if (bReplaceInData) {
4748 strQuery = this.replaceInData(strQuery);
4749 }
4750 stmtCountT.executeUpdate(strQuery);
4751 if (this.hasRestartCounter)
4752 c.commit();
4753 }
4754 if (bArg2) {
4755 strQuery = "SELECT " + this.strRestartCounterValue + " FROM "
4756 + this.strRestartCounterTableName + " WHERE " + this.strRestartCounterImportDefinitionName
4757 + " = '" + this.strImportDefinitionName + "'";
4758 stmtCountT = c.createStatement();
4759 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
4760 rsetCountT = stmtCountT.executeQuery(strQuery);
4761 rsetCountT.next();
4762 if (iTargetFirstColumnResult == 1)
4763 bdecRestartCounter = new BigDecimal(Integer.parseInt(rsetCountT.getString(1)));
4764 else
4765 bdecRestartCounter = new BigDecimal(Integer.parseInt(rsetCountT.getString(0)));
4766 if (rsetCountT.wasNull())
4767 bdecRestartCounter = new BigDecimal(0);
4768 if (this.bEnableJumpResult)
4769 rset.relative(bdecRestartCounter.intValue());
4770 else {
4771 BigDecimal kl = new BigDecimal(0);
4772 while (kl.compareTo(bdecRestartCounter) == -1) {
4773 rset.next();
4774 kl = kl.add(new BigDecimal(1));
4775 }
4776 }
4777 rsetCountT.close();
4778 stmtCountT.close();
4779 }
4780 else {
4781 strQueryDelete = "UPDATE " + this.strRestartCounterTableName
4782 + " SET " + this.strRestartCounterValue + " = null WHERE "
4783 + this.strRestartCounterImportDefinitionName + " = '"
4784 + this.strImportDefinitionName + "'";
4785 Statement stmtDelete = c.createStatement();
4786 this.echo.writeToLog("full", "\tQuery '" + strQueryDelete + "' will be executed");
4787 if (bReplaceInData) {
4788 strQueryDelete = this.replaceInData(strQueryDelete);
4789 }
4790 stmtDelete.executeUpdate(strQueryDelete);
4791 if (this.hasRestartCounter)
4792 c.commit();
4793 stmtDelete.close();
4794 rsetCountT.close();
4795 stmtCountT.close();
4796 }
4797 } catch (SQLException ex) {
4798 throw ex;
4799 }
4800 this.echo.writeToLog("full", "\tcheckDataTransmition method is finished.");
4801 return bdecRestartCounter;
4802 }
4803
4804 /***
4805 * Metod createCurrentDate is used to create current date and time in format that supported by SQL server.
4806 * Format of date : MM-DD-YYYY HH:MM:SS:mmm.
4807 * @return String representation of current date and time.
4808 */
4809 private String createCurrentDate () {
4810 int iYear, iMonth, iDate, iHour, iMinute, iSecond, iMillisecond;
4811 String strDateTime = "";
4812 Calendar calendar = Calendar.getInstance();
4813 Date currentDate = new Date();
4814 calendar.setTime(currentDate);
4815 iYear = calendar.get(Calendar.YEAR);
4816 iMonth = calendar.get(Calendar.MONTH) + 1;
4817 iDate = calendar.get(Calendar.DAY_OF_MONTH);
4818 iHour = calendar.get(Calendar.HOUR_OF_DAY);
4819 iMinute = calendar.get(Calendar.MINUTE);
4820 iSecond = calendar.get(Calendar.SECOND);
4821 iMillisecond = calendar.get(Calendar.MILLISECOND);
4822 strDateTime = iMonth + "-" + iDate + "-" + iYear + " " + iHour + ":"
4823 + iMinute + ":" + iSecond + ":" + iMillisecond;
4824 return strDateTime;
4825 }
4826
4827 /***
4828 * Method constantColumnTypes is used to put types of constant columns into
4829 * global vector sorted in target tables.If there is an error, Exception
4830 * "SQLException" or "NullPointerException" is thrown.
4831 * @param c Connection to target database.
4832 * @throws SQLException Constructs an SQLException object with a reason.
4833 * @throws NullPointerException Constructs a NullPointerException with the specified detail message.
4834 */
4835 private void constantColumnTypes (Connection c) throws SQLException, NullPointerException {
4836 int iCnt = 0;
4837 this.echo.writeToLog("full", "\tconstantColumnTypes method is started.");
4838 try {
4839 for (int i = 0; i < this.iTables; i++) {
4840 Vector vecTempConstantType = new Vector();
4841 Vector vecTempConstantName = new Vector();
4842 String strQuery = "select ";
4843 vecTempConstantName = (Vector)this.vecConstantTargetColumnName.get(i);
4844 if (vecTempConstantName.size() != 0) {
4845 Statement stmtConstant = c.createStatement();
4846 for (int j = 0; j < vecTempConstantName.size(); j++)
4847 strQuery += vecTempConstantName.get(j).toString() +
4848 ", ";
4849 strQuery = strQuery.substring(0, strQuery.length() - 2);
4850 strQuery += " from " + this.vecTableTableName.get(i).toString();
4851 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' will be executed");
4852 ResultSet rsetConstant = stmtConstant.executeQuery(strQuery);
4853 iCnt = vecTempConstantName.size();
4854 for (int k = 0; k < iCnt; k++) {
4855 if (this.iTargetFirstColumnResult == 1)
4856 vecTempConstantType.add(rsetConstant.getMetaData().getColumnTypeName(
4857 k + 1));
4858 else
4859 vecTempConstantType.add(rsetConstant.getMetaData().getColumnTypeName(k));
4860 }
4861 rsetConstant.close();
4862 stmtConstant.close();
4863 }
4864 this.vecConstantColumnType.setElementAt(vecTempConstantType,
4865 i);
4866 }
4867 } catch (SQLException ex) {
4868 throw ex;
4869 } catch (NullPointerException ex) {
4870 throw ex;
4871 }
4872 this.echo.writeToLog("full", "\tconstantColumnTypes method is finished.");
4873 }
4874
4875 /***
4876 * Method insertCounter is used to update Restart Counter table with the
4877 * number of commited rows.
4878 * If there is an error, Exception "SQLException" is thrown.
4879 * @param conn Connection to target database.
4880 * @param iRowNumber Number of commited rows to add to the restart counter.
4881 * @param bdecCount Number of rows, updates the restart counter.
4882 * @return Number of rows which is commited in the target tables.
4883 * @throws SQLException Constructs an SQLException object with a reason.
4884 */
4885 private BigDecimal insertCounter (Connection conn, int iRowNumber, BigDecimal bdecCount) throws SQLException {
4886 this.echo.writeToLog("full", "\tinsertCounter method is started.");
4887 bdecCount = bdecCount.add(new BigDecimal(iRowNumber));
4888 String strQueryChange = "update " + this.strRestartCounterTableName
4889 + " set " + this.strRestartCounterValue + " = " + bdecCount
4890 + " where " + this.strRestartCounterImportDefinitionName +
4891 " = '" + this.strImportDefinitionName + "'";
4892 try {
4893 Statement stmtChange = conn.createStatement();
4894 this.echo.writeToLog("full", "\tQuery '" + strQueryChange + "' will be executed");
4895 if (bReplaceInData) {
4896 strQueryChange = this.replaceInData(strQueryChange);
4897 }
4898 stmtChange.executeUpdate(strQueryChange);
4899 stmtChange.close();
4900 if (this.hasRestartCounter)
4901 conn.commit();
4902 } catch (SQLException ex) {
4903 throw ex;
4904 }
4905 this.echo.writeToLog("full", "\tinsertCounter method is finished.");
4906 return bdecCount;
4907 }
4908
4909 /***
4910 * Method resetRestartCounter is used to reset value in the Restart Counter table.
4911 * After successful importDefinition this method sets value of restart counter on 0.
4912 * If there is an error, Exception "SQLException" is thrown.
4913 * @param conn Connection to target database.
4914 * @param strColumnName Name of importDefinition.
4915 * @throws SQLException Constructs an SQLException object with a reason.
4916 */
4917 private void resetRestartCounter (Connection conn, String strColumnName) throws SQLException {
4918 this.echo.writeToLog("full", "\tresetRestartCounter method is started.");
4919 String strQueryReset = "update " + this.strRestartCounterTableName +
4920 " set " + this.strRestartCounterValue + " = 0 where " + this.strRestartCounterImportDefinitionName
4921 + " = '" + this.strImportDefinitionName + "'";
4922 try {
4923 Statement stmtChange = conn.createStatement();
4924 this.echo.writeToLog("full", "\tQuery '" + strQueryReset + "' will be executed");
4925 if (bReplaceInData) {
4926 strQueryReset = this.replaceInData(strQueryReset);
4927 }
4928 stmtChange.executeUpdate(strQueryReset);
4929 stmtChange.close();
4930 if (this.hasRestartCounter)
4931 conn.commit();
4932 } catch (SQLException ex) {
4933 throw ex;
4934 }
4935 this.echo.writeToLog("full", "\tresetRestartCounter method is finished.");
4936 }
4937
4938 /***
4939 * Method inputUser is used to give a user the possibility to connect to
4940 * Source and Target database using user name and password.
4941 * If missing, user and password parameters for database in XML file,
4942 * Loader asks user for these parameters.
4943 * If there is an error, Exception "IOException" is thrown.
4944 * @param b Boolean type. If b is true- source database, false- target database
4945 * @throws IOException Constructs an IOException with the specified detail message.
4946 */
4947 private void inputUser (boolean b) throws java.io.IOException {
4948 if (b) {
4949 this.echo.writeToLog("none", "Missing user name and password for the Source DB.");
4950 }
4951 else {
4952 this.echo.writeToLog("none", "Missing user name and password for the Target DB.");
4953 }
4954 String strUserName;
4955 String strPassword;
4956 char cu;
4957 char cp;
4958 StringBuffer bufu = new StringBuffer();
4959 StringBuffer bufp = new StringBuffer();
4960 System.out.println("User name: ");
4961 try {
4962 while ((cu = (char)System.in.read()) != '\n')
4963 bufu.append(cu);
4964 strUserName = bufu.toString();
4965 strUserName = strUserName.substring(0, strUserName.length() - 1);
4966 System.out.println("Password: ");
4967 while ((cp = (char)System.in.read()) != '\n')
4968 bufp.append(cp);
4969 strPassword = bufp.toString();
4970 strPassword = strPassword.substring(0, strPassword.length() - 1);
4971 if (b) {
4972 this.strJDBCSourceParameterUser = strUserName;
4973 this.strJDBCSourceParameterPassword = strPassword;
4974 }
4975 else {
4976 this.strJDBCTargetParameterUser = strUserName;
4977 this.strJDBCTargetParameterPassword = strPassword;
4978 }
4979 } catch (IOException ex) {
4980 throw ex;
4981 }
4982 }
4983
4984 /***
4985 * Method changeTableOrder change order of Tables into public Vector vecTableTableName
4986 * Relation source tables puts before the others target tables.
4987 */
4988 private void changeTableOrder () {
4989 Vector vecTempTableTableName = new Vector();
4990 Vector vecTempTableTableID = new Vector();
4991 Vector vecTempTableInsert = new Vector();
4992 Vector vecTempTableTableMode = new Vector();
4993 Vector vecTempTableOidLogic = new Vector();
4994 Vector vecNumberOfTable = new Vector();
4995 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
4996 int iNumberOfTable = 0;
4997 for (int j = 0; j < this.vecTableTableName.size(); j++) {
4998 if (this.vecTableTableName.get(j).toString().equalsIgnoreCase(this.vecRelationColumnSourceTableName.get(i).toString())
4999 && this.vecTableTableID.get(j).toString().equalsIgnoreCase(this.vecRelationColumnSourceTableID.get(i).toString())) {
5000 iNumberOfTable = j;
5001 boolean bEqualsRelationSource = false;
5002 for (int k = 0; k < vecNumberOfTable.size(); k++) {
5003 if (j == (new Integer(vecNumberOfTable.get(k).toString())).intValue())
5004 bEqualsRelationSource = true;
5005 }
5006 if (!bEqualsRelationSource) {
5007 vecTempTableTableName.addElement(this.vecTableTableName.get(j).toString());
5008 vecTempTableTableID.addElement(this.vecTableTableID.get(j).toString());
5009 vecTempTableInsert.addElement(this.vecTableInsert.get(j).toString());
5010 vecTempTableTableMode.addElement(this.vecTableTableMode.get(j).toString());
5011 vecTempTableOidLogic.addElement(this.vecTableOidLogic.get(j).toString());
5012 vecNumberOfTable.addElement(new Integer(iNumberOfTable));
5013 }
5014 }
5015 }
5016 }
5017 if (this.vecRelationColumnSourceTableName.size() != 0) {
5018 for (int i = 0; i < this.vecTableTableName.size(); i++) {
5019 boolean bEquals = false;
5020 for (int j = 0; j < vecNumberOfTable.size(); j++) {
5021 if (i == (new Integer(vecNumberOfTable.get(j).toString())).intValue()) {
5022 bEquals = true;
5023 }
5024 }
5025 if (!bEquals) {
5026 vecTempTableTableName.addElement(this.vecTableTableName.get(i).toString());
5027 vecTempTableTableID.addElement(this.vecTableTableID.get(i).toString());
5028 vecTempTableInsert.addElement(this.vecTableInsert.get(i).toString());
5029 vecTempTableTableMode.addElement(this.vecTableTableMode.get(i).toString());
5030 vecTempTableOidLogic.addElement(this.vecTableOidLogic.get(i).toString());
5031 }
5032 }
5033 this.vecTableTableName = new Vector();
5034 this.vecTableTableID = new Vector();
5035 this.vecTableInsert = new Vector();
5036 this.vecTableTableMode = new Vector();
5037 this.vecTableOidLogic = new Vector();
5038 for (int i = 0; i < vecTempTableTableName.size(); i++) {
5039 this.vecTableTableName.addElement(vecTempTableTableName.get(i).toString());
5040 this.vecTableTableID.addElement(vecTempTableTableID.get(i).toString());
5041 this.vecTableInsert.addElement(vecTempTableInsert.get(i).toString());
5042 this.vecTableTableMode.addElement(vecTempTableTableMode.get(i).toString());
5043 this.vecTableOidLogic.addElement(vecTempTableOidLogic.get(i).toString());
5044 }
5045 }
5046 }
5047
5048 /***
5049 * Method changeRelationsOrder change order of relation tags.
5050 * Order of relation tags depends of 'complex relations'. Method puts at the begining of relation global Vectors
5051 * relations which is used only to read source values for another relation.
5052 *
5053 */
5054 private void changeRelationsOrder () {
5055 Vector vecTempSourceTableName = new Vector();
5056 Vector vecTempSourceTableID = new Vector();
5057 Vector vecTempSourceColumnName = new Vector();
5058 Vector vecTempTargetTableName = new Vector();
5059 Vector vecTempTargetTableID = new Vector();
5060 Vector vecTempTargetColumnName = new Vector();
5061 Vector vecTempRelationMode = new Vector();
5062 Vector vecRelationsOrder = new Vector();
5063 vecRelationsOrder.setSize(this.vecRelationColumnSourceTableName.size());
5064 for (int i = 0; i < vecRelationsOrder.size(); i++)
5065 vecRelationsOrder.setElementAt(new Integer(i), i);
5066 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
5067 if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("Key")) {
5068 for (int j = 0; j < this.vecRelationColumnSourceTableName.size(); j++) {
5069 if (this.vecRelationColumnSourceTableName.get(i).toString().equalsIgnoreCase(this.vecRelationColumnTargetTableName.get(j).toString())
5070 && this.vecRelationColumnSourceTableID.get(i).toString().equalsIgnoreCase(this.vecRelationColumnTargetTableID.get(j).toString()))
5071 vecRelationsOrder = this.setAfter(vecRelationsOrder,
5072 i, j);
5073 }
5074 }
5075 else {
5076 vecRelationsOrder = this.setLast(vecRelationsOrder, i);
5077 }
5078 }
5079 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
5080 vecTempSourceTableName.add(this.vecRelationColumnSourceTableName.get(i));
5081 vecTempSourceTableID.add(this.vecRelationColumnSourceTableID.get(i));
5082 vecTempSourceColumnName.add(this.vecRelationColumnSourceColumnName.get(i));
5083 vecTempTargetTableName.add(this.vecRelationColumnTargetTableName.get(i));
5084 vecTempTargetTableID.add(this.vecRelationColumnTargetTableID.get(i));
5085 vecTempTargetColumnName.add(this.vecRelationColumnTargetColumnName.get(i));
5086 vecTempRelationMode.add(this.vecRelationColumnRelationMode.get(i));
5087 }
5088 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
5089 this.vecRelationColumnSourceTableName.setElementAt(vecTempSourceTableName.get(Integer.parseInt(vecRelationsOrder.get(i).toString())),
5090 i);
5091 this.vecRelationColumnSourceTableID.setElementAt(vecTempSourceTableID.get(Integer.parseInt(vecRelationsOrder.get(i).toString())),
5092 i);
5093 this.vecRelationColumnSourceColumnName.setElementAt(vecTempSourceColumnName.get(Integer.parseInt(vecRelationsOrder.get(i).toString())),
5094 i);
5095 this.vecRelationColumnTargetTableName.setElementAt(vecTempTargetTableName.get(Integer.parseInt(vecRelationsOrder.get(i).toString())),
5096 i);
5097 this.vecRelationColumnTargetTableID.setElementAt(vecTempTargetTableID.get(Integer.parseInt(vecRelationsOrder.get(i).toString())),
5098 i);
5099 this.vecRelationColumnTargetColumnName.setElementAt(vecTempTargetColumnName.get(Integer.parseInt(vecRelationsOrder.get(i).toString())),
5100 i);
5101 this.vecRelationColumnRelationMode.setElementAt(vecTempRelationMode.get(Integer.parseInt(vecRelationsOrder.get(i).toString())),
5102 i);
5103 }
5104 }
5105
5106 /***
5107 * Method setLast changes order of vecOrder's elements. Element at iRelationTag position will be removed
5108 * and inserted at the end of Vector.
5109 * @param vecOrder Vector - order of relation tags
5110 * @param iRelationTag integer - position of element in Vector which changes its position.
5111 * @return Vector - order of relation tags after changing positions of elements.
5112 */
5113 private Vector setLast (Vector vecOrder, int iRelationTag) {
5114 int iLast = vecOrder.indexOf(new Integer(iRelationTag));
5115 vecOrder.remove(iLast);
5116 vecOrder.add(new Integer(iRelationTag));
5117 return vecOrder;
5118 }
5119
5120 /***
5121 * Method setAfter changes order of vecOrder's elements. Element at iIndexCurrent position will be removed
5122 * and inserted after element at iIndexTarget position.
5123 * @param vecOrder Vector - order of relation tags
5124 * @param iIndexCurrent integer - position of element in Vector which changes its position.
5125 * @param iIndexTarget integer - position of 'target' element in Vector .
5126 * @return Vector - order of relation tags after changing element's positions.
5127 */
5128 Vector setAfter (Vector vecOrder, int iIndexCurrent, int iIndexTarget) {
5129 if (iIndexCurrent < iIndexTarget) {
5130 int iCurrent = vecOrder.indexOf(new Integer(iIndexCurrent));
5131 vecOrder.remove(iCurrent);
5132 int iTarget = vecOrder.indexOf(new Integer(iIndexTarget));
5133 vecOrder.insertElementAt(new Integer(iIndexCurrent), iTarget +
5134 1);
5135 }
5136 return vecOrder;
5137 }
5138
5139 /***
5140 * Method executeSQLStatement is used to execute SQL statement. This method
5141 * executes and commit changes immediately. JDBC parameters, Continue on Error parameters
5142 * and SQL statements are set in XML file.
5143 * * If there is an error Exception "Exception" is thrown.
5144 * @throws Exception.
5145 */
5146 private void executeSQLStatement () throws Exception {
5147 Connection conn = null;
5148 try {
5149 this.echo.writeToLog("full", "\tmethod executeSQLStatement is started");
5150 // this.echo.writeToLog("normal", "SQL statement " + this.strSqlName +
5151 // " is started");
5152 Class.forName(this.strJDBCTargetParameterDriver);
5153 conn = DriverManager.getConnection(this.strJDBCTargetParameterConnection,
5154 strJDBCTargetParameterUser, strJDBCTargetParameterPassword);
5155 Statement stmtSeparate;
5156 if (this.bEnableJumpResult)
5157 stmtSeparate = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
5158 ResultSet.CONCUR_UPDATABLE);
5159 else
5160 stmtSeparate = conn.createStatement();
5161 for (int i = 0; i < this.vecSqlStmt.size(); i++) {
5162 this.echo.writeToLog("full", "\tSQL_stmt : '" + this.vecSqlStmt.get(i).toString()
5163 + "' will be executed");
5164 Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt.get(i).toString());
5165 for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
5166 executeSql(stmtSeparate, vecSingleSqlStmt.get(j).toString(),
5167 0);
5168 }
5169 }
5170 stmtSeparate.close();
5171 conn.close();
5172 // this.echo.writeToLog("normal", "SQL statement " + this.strSqlName +
5173 // " is finished");
5174 } catch (SQLException e) {
5175 throw e;
5176 }
5177 finally {
5178 if (conn != null)
5179 conn.close();
5180 }
5181 }
5182
5183 /***
5184 * Method executeSQLStatement is used to execute SQL statement. This method
5185 * commit changes immediately only if is commit paremeter true. If it is false commit changes after all aql stetements.
5186 * JDBC parameters, Continue on Error parameters
5187 * and SQL statements are set in XML file.
5188 * * If there is an error Exception "Exception" is thrown.
5189 * @param conn The Connection of target table.
5190 * @throws Exception.
5191 */
5192 private void executeSQLStatement (Connection conn) throws Exception {
5193 try {
5194 this.timeCounter.setStartJobTime();
5195 this.echo.writeToLog("full", "\tmethod executeSQLStatement is started");
5196 this.echo.writeToLog("normal", "SQL statement " + this.strSqlName +
5197 " is started");
5198 boolean isCreateDatabaseStatement=false;
5199 out:
5200 for (int i = 0; i < this.vecSqlStmt.size(); i++) {
5201 if(this.vecSqlStmt.get(i).toString().toUpperCase().trim().startsWith("CREATE DATABASE") ||
5202 this.vecSqlStmt.get(i).toString().toUpperCase().trim().startsWith("DROP DATABASE")) {
5203 isCreateDatabaseStatement=true;
5204 break out;
5205 }
5206 }
5207 if(isCreateDatabaseStatement)
5208 {
5209 executeSQLStatement();
5210 }
5211 else {
5212
5213 Statement stmtSeparate;
5214 if (this.bEnableJumpResult)
5215 stmtSeparate = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
5216 ResultSet.CONCUR_UPDATABLE);
5217 else
5218 stmtSeparate = conn.createStatement();
5219 for (int i = 0; i < this.vecSqlStmt.size(); i++) {
5220 this.echo.writeToLog("full", "\tSQL_stmt : '" + this.vecSqlStmt.get(i).toString()
5221 + "' will be executed");
5222 Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt.get(i).toString());
5223 for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
5224 executeSql(stmtSeparate, vecSingleSqlStmt.get(j).toString(),
5225 j + 1);
5226 }
5227 }
5228 if (this.strSqlCommit.equalsIgnoreCase("true")) {
5229 if(!conn.getAutoCommit())
5230 conn.commit();
5231 }
5232 stmtSeparate.close();
5233 }
5234
5235 this.echo.writeToLog("normal", "SQL statement " + this.strSqlName +
5236 " is finished");
5237 this.echo.writeToLog("normal"," Duration :"+ this.timeCounter.getJobTime());
5238
5239 } catch (SQLException e) {
5240 throw e;
5241 }
5242 }
5243
5244 /***
5245 * Method sqlStringToVector is used to cut Sql string with number of statements
5246 * into vector whose elements are single Sql statemnets.
5247 * @param sql Sql string with number of statements.
5248 */
5249 private Vector sqlStringToVector (String sql) {
5250 Vector vecSqlString = new Vector();
5251 int i = sql.indexOf(";");
5252 if (i != -1) {
5253 while (i != -1) {
5254 vecSqlString.add(sql.substring(0, i + 1));
5255 sql = sql.substring(i + 1);
5256 i = sql.indexOf(";");
5257 }
5258 }
5259 else
5260 vecSqlString.add(sql.trim() + ";");
5261 return vecSqlString;
5262 }
5263
5264 /***
5265 * Method executeSql is used to execute singl Sql statement. If there is an error
5266 * depends on OnErrorContinue parameter throws exception or not. Error message is
5267 * always shown. If there is an error, message with the error message,
5268 * statement and number of statement is shown.
5269 * @param stmtSql Statement.
5270 * @param sqlStmt Sql statement to execute.
5271 * @param i Number of the Sql statement.
5272 * @throws SQLException
5273 */
5274 private void executeSql (Statement stmtSql, String sqlStmt, int i) throws SQLException {
5275 try {
5276 if (bReplaceInData) {
5277 sqlStmt = this.replaceInData(sqlStmt);
5278 }
5279 stmtSql.execute(sqlStmt);
5280 } catch (SQLException e) {
5281 if (this.strSqlOnErrorContinue.equalsIgnoreCase("true")) {
5282 if (this.strSqlCommit.equalsIgnoreCase("true"))
5283 this.echo.writeToLog("none", "\t Error in SQL statement: " +
5284 sqlStmt + " executing SQL statements continue...");
5285 else
5286 this.echo.writeToLog("none", "\t Error in SQL statement: " +
5287 sqlStmt + " \n\tStatement is number: " + i + " all statements before it is not commited, executing SQL statements continue...");
5288 LoaderException le = new LoaderException("SQLException: ",
5289 (Throwable)e);
5290 this.echo.writeToLog("none", "\t " + le.getCause().toString());
5291 }
5292 else {
5293 this.echo.writeToLog("none", "\t Error in SQL statement: " + sqlStmt);
5294 throw e;
5295 }
5296 }
5297 }
5298
5299 /***
5300 * Method checkSortColumns checks if sort columns in source table have unique values.
5301 * If source table have more rows with equal values in sort columns return true, if not return false.
5302 * @param conn - Connection to the source table.
5303 * @return boolean - true - source table has more rows with equal values in sort columns,
5304 * false - if source table has unique values in sort columns.
5305 * @throws LoaderException with the specified detail message.
5306 */
5307 private boolean checkSortColumns (Connection connSource) throws LoaderException {
5308 boolean isEqualValues = false;
5309 String strQuery = "select ";
5310 try {
5311 this.echo.writeToLog("full", "\tmethod checkSortColumns is started");
5312 for (int i = 0; i < this.vecRestartCounterSortColumn.size(); i++)
5313 strQuery += this.vecRestartCounterSortColumn.get(i).toString()
5314 + ",";
5315 strQuery = strQuery.substring(0, strQuery.length() - 1);
5316 strQuery += " from " + this.strImportDefinitionTableName;
5317 strQuery += " order by ";
5318 for (int j = 0; j < this.vecRestartCounterSortColumn.size(); j++)
5319 strQuery += this.vecRestartCounterSortColumn.get(j).toString()
5320 + ", ";
5321 strQuery = strQuery.substring(0, strQuery.length() - 2);
5322 Statement stmtSort;
5323 if (this.bEnableJumpResult)
5324 stmtSort = connSource.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
5325 ResultSet.CONCUR_UPDATABLE);
5326 else
5327 stmtSort = connSource.createStatement();
5328
5329 this.echo.writeToLog("full", "\tQuery '" + strQuery + "' executes");
5330 ResultSet rsetSort = stmtSort.executeQuery(strQuery);
5331 endWhile: while (rsetSort.next()) {
5332 Vector vecSortNewValues = new Vector();
5333 for (int i = 0; i < this.vecRestartCounterSortColumn.size(); i++)
5334 vecSortNewValues.add(rsetSort.getString(i + 1));
5335 if (vecSortNewValues.equals(this.vecSortValues)) {
5336 isEqualValues = true;
5337 break endWhile;
5338 }
5339 else {
5340 this.vecSortValues = new Vector();
5341 for (int i = 0; i < this.vecRestartCounterSortColumn.size(); i++)
5342 this.vecSortValues.add(vecSortNewValues.get(i));
5343 }
5344 }
5345 rsetSort.close();
5346 stmtSort.close();
5347 } catch (SQLException e) {
5348 LoaderException le = new LoaderException("SQLException: ", (Throwable)e);
5349 this.echo.writeToLog("none", le.getCause().toString());
5350 throw le;
5351 }
5352 this.echo.writeToLog("full", "\tmethod checkSortColumns is finished");
5353 return isEqualValues;
5354 }
5355
5356 /***Method readConfigValues read specific values for desired database(dbVendor) and
5357 * puts them into global variables. Second parameter in this method describes which database is analysed (target or source)
5358 * Method reads values from Loader.conf configuration file (XML format).
5359 * @param dbVendor - String - type of source database (table);
5360 * @param strType - String - type of Loader database (source or target);
5361 */
5362 private void readConfigValues (String dbVendor, String driverName, String strType) throws LoaderException{
5363 Document doc = null;
5364 this.echo.writeToLog("full", "\treadConfigValues method is started.");
5365 try {
5366 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
5367 DocumentBuilder db = null;
5368 db = dbf.newDocumentBuilder();
5369 File configFile = new File(this.strVendorFileName);
5370 if (configFile.exists())
5371 doc = db.parse(this.strVendorFileName);
5372 else {
5373 if (strType.equalsIgnoreCase("source")) {
5374 // this.strSourceDriverName = "csvjdbc";
5375 this.strSourceDriverClassName = "org.relique.jdbc.csv.CsvDriver";
5376 this.iFirstColumnResult = 1;
5377 this.bRequiredUser = false;
5378 this.bEnableJumpResult = false;
5379 this.bEnablePreviousRecord = false;
5380 this.bBeforeFirstRow = true;
5381 this.bAfterLastRow = true;
5382 this.bEnableOrderBy = false;
5383 }
5384 else {
5385 // this.strTargetDriverName = "freetds_jdbc";
5386 this.strTargetDriverClassName = "com.ashna.jturbo.driver.Driver";
5387 this.iTargetFirstColumnResult = 1;
5388 this.bTargetRequiredUser = true;
5389 }
5390 }
5391 } catch (Exception e) {
5392 this.echo.writeToLog("none", "Sorry, an error occurred: " + e);
5393 LoaderException le = new LoaderException("Exception: ", (Throwable)e);
5394 throw le;
5395 // System.exit(1);
5396 }
5397 String strDbVendor = "";
5398 String strDriverName = "";
5399 if (doc != null) {
5400 NodeList tagDbVendor = doc.getElementsByTagName("dbVendor");
5401 out: for (int i = 0; i < tagDbVendor.getLength(); i++) {
5402 Node nodeMain = tagDbVendor.item(i);
5403 NamedNodeMap attrs = nodeMain.getAttributes();
5404 Node nodeResult = attrs.getNamedItem("name");
5405 Node nodeDriver = attrs.getNamedItem("driverName");
5406 if (nodeResult != null) {
5407 strDbVendor = nodeResult.getNodeValue();
5408 if (strDbVendor.equalsIgnoreCase(dbVendor)) {
5409 if (nodeDriver != null) {
5410 strDriverName=nodeDriver.getNodeValue();
5411 if(!(driverName==null || driverName.equalsIgnoreCase(""))) {
5412 if (strDriverName.equalsIgnoreCase(driverName)) {
5413 NodeList configNodes = nodeMain.getChildNodes();
5414 for (int j = 0; j < configNodes.getLength(); j++) {
5415 if (configNodes.item(j).getNodeName().equalsIgnoreCase("FirstColumnResult")) {
5416 NamedNodeMap configAttributes = null;
5417 Node nodeValue = null;
5418 configAttributes = configNodes.item(j).getAttributes();
5419 if (configAttributes != null) {
5420 if ((nodeValue = configAttributes.getNamedItem("value"))
5421 != null) {
5422 if (strType.equalsIgnoreCase("source"))
5423 this.iFirstColumnResult = Integer.parseInt(nodeValue.getNodeValue());
5424 else
5425 this.iTargetFirstColumnResult = Integer.parseInt(nodeValue.getNodeValue());
5426 }
5427 }
5428 }
5429 else if (configNodes.item(j).getNodeName().equalsIgnoreCase("RequiredUser")) {
5430 NamedNodeMap configAttributes = null;
5431 Node nodeValue = null;
5432 configAttributes = configNodes.item(j).getAttributes();
5433 if (configAttributes != null) {
5434 if ((nodeValue = configAttributes.getNamedItem("value"))
5435 != null) {
5436 if (strType.equalsIgnoreCase("source")){
5437
5438 this.bRequiredUser = (new Boolean(nodeValue.getNodeValue())).booleanValue();
5439 }
5440 else {
5441 this.bTargetRequiredUser = (new Boolean(nodeValue.getNodeValue())).booleanValue();
5442 }
5443 }
5444 }
5445 }
5446 else if (configNodes.item(j).getNodeName().equalsIgnoreCase("EnableJumpInResult")) {
5447 NamedNodeMap configAttributes = null;
5448 Node nodeValue = null;
5449 configAttributes = configNodes.item(j).getAttributes();
5450 if (configAttributes != null) {
5451 if ((nodeValue = configAttributes.getNamedItem("value"))
5452 != null) {
5453 if (strType.equalsIgnoreCase("source"))
5454 this.bEnableJumpResult = (new Boolean(nodeValue.getNodeValue())).booleanValue();
5455 }
5456 }
5457 }
5458 else if (configNodes.item(j).getNodeName().equalsIgnoreCase("EnablePreviousRecord")) {
5459 NamedNodeMap configAttributes = null;
5460 Node nodeValue = null;
5461 configAttributes = configNodes.item(j).getAttributes();
5462 if (configAttributes != null) {
5463 if ((nodeValue = configAttributes.getNamedItem("value"))
5464 != null) {
5465 if (strType.equalsIgnoreCase("source"))
5466 this.bEnablePreviousRecord = (new Boolean(nodeValue.getNodeValue())).booleanValue();
5467 }
5468 }
5469 }
5470 else if (configNodes.item(j).getNodeName().equalsIgnoreCase("BeforeFirstRow")) {
5471 NamedNodeMap configAttributes = null;
5472 Node nodeValue = null;
5473 configAttributes = configNodes.item(j).getAttributes();
5474 if (configAttributes != null) {
5475 if ((nodeValue = configAttributes.getNamedItem("value"))
5476 != null) {
5477 if (strType.equalsIgnoreCase("source"))
5478 this.bBeforeFirstRow = (new Boolean(nodeValue.getNodeValue())).booleanValue();
5479 }
5480 }
5481 }
5482 else if (configNodes.item(j).getNodeName().equalsIgnoreCase("AfterLastRow")) {
5483 NamedNodeMap configAttributes = null;
5484 Node nodeValue = null;
5485 configAttributes = configNodes.item(j).getAttributes();
5486 if (configAttributes != null) {
5487 if ((nodeValue = configAttributes.getNamedItem("value"))
5488 != null) {
5489 if (strType.equalsIgnoreCase("source"))
5490 this.bAfterLastRow = (new Boolean(nodeValue.getNodeValue())).booleanValue();
5491 }
5492 }
5493 }
5494 else if (configNodes.item(j).getNodeName().equalsIgnoreCase("EnableOrderBy")) {
5495 NamedNodeMap configAttributes = null;
5496 Node nodeValue = null;
5497 configAttributes = configNodes.item(j).getAttributes();
5498 if (configAttributes != null) {
5499 if ((nodeValue = configAttributes.getNamedItem("value"))
5500 != null) {
5501 if (strType.equalsIgnoreCase("source"))
5502 this.bEnableOrderBy = (new Boolean(nodeValue.getNodeValue())).booleanValue();
5503 }
5504 }
5505 }
5506 /* else if (configNodes.item(j).getNodeName().equalsIgnoreCase("DriverName")) {
5507 NamedNodeMap configAttributes = null;
5508 Node nodeValue = null;
5509 configAttributes = configNodes.item(j).getAttributes();
5510 if (configAttributes != null) {
5511 if ((nodeValue = configAttributes.getNamedItem("value"))
5512 != null) {
5513 if (strType.equalsIgnoreCase("source"))
5514 this.strSourceDriverName = (nodeValue.getNodeValue()).toString();
5515 else
5516 this.strTargetDriverName = (nodeValue.getNodeValue()).toString();
5517 }
5518 }
5519 }
5520 */ else if (configNodes.item(j).getNodeName().equalsIgnoreCase("ClassName")) {
5521 NamedNodeMap configAttributes = null;
5522 Node nodeValue = null;
5523 configAttributes = configNodes.item(j).getAttributes();
5524 if (configAttributes != null) {
5525 if ((nodeValue = configAttributes.getNamedItem("value"))
5526 != null) {
5527 if (strType.equalsIgnoreCase("source"))
5528 this.strSourceDriverClassName = (nodeValue.getNodeValue()).toString();
5529 else
5530 this.strTargetDriverClassName = (nodeValue.getNodeValue()).toString();
5531 }
5532 }
5533 }
5534
5535 }
5536 /* if(strType.equalsIgnoreCase("source")) {
5537 if(this.strJDBCSourceParameterConnection.toLowerCase().indexOf(this.strSourceDriverName.toLowerCase())!=-1)
5538 break out;
5539 }
5540 else {
5541 if(this.strJDBCTargetParameterConnection.toLowerCase().indexOf(this.strTargetDriverName.toLowerCase())!=-1)
5542 break out;
5543 }
5544 */ }
5545 }
5546 }
5547 }
5548 }
5549 }
5550 }
5551 this.echo.writeToLog("full", "\treadConfigValues method is finished.");
5552 }
5553
5554 /***
5555 * put your documentation comment here
5556 * @param conn
5557 * @exception LoaderException
5558 */
5559 private void createObjectIDTable (Connection conn) throws LoaderException {
5560 try {
5561 Statement stmt;
5562 if (this.bEnableJumpResult)
5563 stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
5564 ResultSet.CONCUR_UPDATABLE);
5565 else
5566 stmt = conn.createStatement();
5567 String sqlStmt = "";
5568 if(!(this.strObjectIDNameColumnName.equals("")||this.strObjectIDNameColumnValue.equals(""))) {
5569 sqlStmt = "create table " + this.strObjectIDTableName +
5570 " (" + this.strObjectIDColumnName + " VARCHAR(30) ,"
5571 +this.strObjectIDNameColumnName + " VARCHAR(30)) NOT NULL;";
5572
5573 }
5574 else
5575 {
5576 sqlStmt = "create table " + this.strObjectIDTableName +
5577 " (" + this.strObjectIDColumnName + " DECIMAL(19,0) NOT NULL);";
5578 }
5579
5580 stmt.execute(sqlStmt);
5581 String insert="";
5582 if(!(this.strObjectIDNameColumnName.equals("")||this.strObjectIDNameColumnValue.equals(""))) {
5583 insert = "insert " + this.strObjectIDTableName + " (" +
5584 this.strObjectIDNameColumnName +","+ this.strObjectIDColumnName+") values ('" + this.strObjectIDNameColumnValue
5585 + "','"+ this.iObjectIDStartValue+"');";
5586 }
5587 else {
5588 insert = "insert " + this.strObjectIDTableName + " (" +
5589 this.strObjectIDColumnName + ") values (" + this.iObjectIDStartValue
5590 + ");";
5591 }
5592 if (bReplaceInData) {
5593 insert = this.replaceInData(insert);
5594 }
5595 stmt.execute(insert);
5596 conn.commit();
5597 stmt.close();
5598 } catch (SQLException e) {
5599 LoaderException le = new LoaderException("SQLException: ", (Throwable)e);
5600 this.echo.writeToLog("none", le.getCause().toString());
5601 throw le;
5602 }
5603 }
5604
5605 /***
5606 * put your documentation comment here
5607 * @param conn
5608 * @exception LoaderException
5609 */
5610 private void createRestartCounterTable (Connection conn) throws LoaderException {
5611 try {
5612 Statement stmt;
5613 if (this.bEnableJumpResult)
5614 stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
5615 ResultSet.CONCUR_UPDATABLE);
5616 else
5617 stmt = conn.createStatement();
5618
5619 String sqlStmt = "create table " + this.strRestartCounterTableName
5620 + " (" + strRestartCounterImportDefinitionName + " VARCHAR(50) NOT NULL, "
5621 + strRestartCounterValue + " DECIMAL(19,0));";
5622 if (bReplaceInData) {
5623 sqlStmt = this.replaceInData(sqlStmt);
5624 }
5625 stmt.execute(sqlStmt);
5626 conn.commit();
5627 stmt.close();
5628 } catch (SQLException e) {
5629 LoaderException le = new LoaderException("SQLException: ", (Throwable)e);
5630 this.echo.writeToLog("none", le.getCause().toString());
5631 throw le;
5632 }
5633 }
5634
5635 /***
5636 * put your documentation comment here
5637 * @param values
5638 * @return
5639 */
5640 private static Map convertToMap (String values) {
5641 Map mapValues = new HashMap();
5642 int i = values.indexOf(";");
5643 int k = 0;
5644 String part = new String(values);
5645 if (i != -1) {
5646 while (i != -1) {
5647 part = new String(values.substring(k, k + i));
5648 int j = part.indexOf("=");
5649 String strObject = part.substring(0, j);
5650 String strValue = part.substring(j + 1);
5651 if (strValue.equals(""))
5652 strValue = null;
5653 mapValues.put(strObject, strValue);
5654 k += i + 1;
5655 i = values.substring(k).indexOf(";");
5656 }
5657 if (!(values.substring(k).trim().equals("") || values.substring(k).trim().equals(";"))) {
5658 part = new String(values.substring(k));
5659 int j = part.indexOf("=");
5660 String strObject = part.substring(0, j);
5661 String strValue = part.substring(j + 1);
5662 if (strValue.equals(""))
5663 strValue = null;
5664 mapValues.put(strObject, strValue);
5665 }
5666 }
5667 else {
5668 int j = values.indexOf("=");
5669 String strObject = values.substring(k, j);
5670 String strValue = values.substring(j + 1);
5671 if (strValue.equals(""))
5672 strValue = null;
5673 mapValues.put(strObject, strValue);
5674 }
5675 return mapValues;
5676 }
5677
5678 /***
5679 * Method replaceInData replace data in string if there is the same variable as
5680 * in attribut prefix+name+suffix in variable tag.
5681 * @param s - String to replace.
5682 */
5683 private String replaceInData (String s) {
5684 // going throw vector
5685 for (int k = 0; k < this.vecReplaceInData.size(); k++) {
5686 // if this is to change...
5687 if (this.vecReplaceInData.get(k).toString().equalsIgnoreCase("true")) {
5688 String sPreNameSu = this.vecVariablePrefix.get(k).toString()
5689 + this.vecVariableName.get(k).toString() + this.vecVariableSufix.get(k).toString();
5690 int j = s.indexOf(sPreNameSu);
5691 // if costant is variable
5692 while (j != -1) {
5693 s = s.substring(0, j) + this.vecVariableValue.get(k).toString()
5694 + s.substring(j + sPreNameSu.length(), s.length());
5695 j = s.indexOf(sPreNameSu);
5696 }
5697 }
5698 }
5699 return s;
5700 }
5701
5702 /***
5703 * @param s - String to replace.
5704 * @param oldChar - Char
5705 * @param newValue - String
5706 */
5707 private String replaceChar (String s, char oldChar, String newValue) {
5708
5709 int j = s.indexOf(oldChar);
5710 String replacedString = "";
5711 while (j != -1) {
5712 replacedString = replacedString+ s.substring(0, j)+ newValue;
5713 s= s.substring(j+1);
5714 j = s.indexOf(oldChar);
5715 }
5716 replacedString = replacedString + s;
5717 return replacedString;
5718 }
5719
5720
5721 /***
5722 * Method resetGlobalVariables reset all global variables to the start values
5723 * after each importDefinition job.
5724 */
5725 private void resetGlobalVariables () {
5726 this.strImportDefinitionName = "";
5727 this.strImportDefinitionTableName = "";
5728 this.iImportDefinitionCommitCount = 0;
5729 this.strImportDefinitionLogMode = "normal";
5730 this.strImportDefinitionSelectStatement = "";
5731 this.bObjectIDAutoCreate = this.bDefaultObjectIDAutoCreate;
5732 this.iObjectIDStartValue = this.iDefaultObjectIDStartValue;
5733
5734 this.vecRestartCounterSortColumn = new Vector();
5735 this.strDbVendor = "";
5736 this.strTargetDbVendor = "";
5737 this.strJDBCSourceParameterDriver = "";
5738 this.strJDBCTargetParameterDriver = "";
5739 this.strJDBCSourceParameterConnection = "";
5740 this.strJDBCTargetParameterConnection = "";
5741 this.strJDBCSourceParameterUser = "";
5742 this.strJDBCTargetParameterUser = "";
5743 this.strJDBCSourceParameterPassword = "";
5744 this.strJDBCTargetParameterPassword = "";
5745 this.iValueColumns = 0;
5746 this.vecValueColumnsTargetTables = new Vector();
5747 this.vecSourceColumnName = new Vector();
5748 this.vecTargetColumnName = new Vector();
5749 this.vecValueMode = new Vector();
5750 this.vecTargetColumnValue = new Vector();
5751 this.vecTargetKeyColumnName = new Vector();
5752 this.iConstantColumns = 0;
5753 this.vecConstantTargetColumnName = new Vector();
5754 this.vecConstantValueMode = new Vector();
5755 this.vecConstantConstantValue = new Vector();
5756 this.vecConstantColumnTargetTableName = new Vector();
5757 this.vecConstantColumnTargetTableID = new Vector();
5758 this.iRelationColumns = 0;
5759 this.vecRelationColumnSourceTableName = new Vector();
5760 this.vecRelationColumnSourceTableID = new Vector();
5761 this.vecRelationColumnSourceColumnName = new Vector();
5762 this.vecRelationColumnTargetTableName = new Vector();
5763 this.vecRelationColumnTargetColumnName = new Vector();
5764 this.vecRelationColumnTargetTableID = new Vector();
5765 this.vecRelationColumnRelationMode = new Vector();
5766 this.iTables = 0;
5767 this.vecTableTableName = new Vector();
5768 this.vecTableTableID = new Vector();
5769 this.vecTableInsert = new Vector();
5770 this.vecTableTableMode = new Vector();
5771 this.vecTableOidLogic = new Vector();
5772 this.vecRelationSourceValue = new Vector();
5773 this.vecRelationSourceType = new Vector();
5774 this.vecSourceColumnType = new Vector();
5775 this.vecConstantColumnType = new Vector();
5776 this.bdecOidNumber = new BigDecimal(0);
5777 this.bdecOidNumber2000 = new BigDecimal(0);
5778 this.iObjectID = 0;
5779 this.strObjectIDTableName = "";
5780 this.strObjectIDColumnName = "";
5781 // TOS
5782 this.strObjectIDNameColumnName = "";
5783 this.strObjectIDNameColumnValue = "";
5784
5785 this.vecVariableUseIDTableName = new Vector();
5786 this.vecVariableUseIDTableID = new Vector();
5787 this.vecVariableUseIDColumnName = new Vector();
5788 this.vecVariableUseIDValueMode = new Vector();
5789 this.vecVariableColumnName = new Vector();
5790 this.vecVariableColumnTargetTableName = new Vector();
5791 this.vecVariableColumnTargetTableID = new Vector();
5792 this.vecVariableColumnTargetColumnName = new Vector();
5793 this.vecVariableColumnValueMode = new Vector();
5794 this.vecVariableColumnTypes = new Vector();
5795 this.vecVariableTimesTableName = new Vector();
5796 this.vecVariableTimesTableID = new Vector();
5797 this.vecVariableTimesColumnName = new Vector();
5798 this.vecVariableTimesValueMode = new Vector();
5799 this.vecRelationKeyColumns = new Vector();
5800 this.vecRelationKeyTypes = new Vector();
5801 this.vecQueryWhere = new Vector();
5802 this.vecSortValues = new Vector();
5803 this.strSqlName = "";
5804 this.strSqlLogMode = "";
5805 this.strSqlOnErrorContinue = "";
5806 this.strSqlCommit = "";
5807 this.vecSqlStmt = new Vector();
5808 this.strSourceDriverName = "";
5809 this.strTargetDriverName = "";
5810 this.strSourceDriverClassName = "";
5811 this.strTargetDriverClassName = "";
5812 this.bRequiredUser = false;
5813 this.bTargetRequiredUser = false;
5814 this.bEnableJumpResult = false;
5815 this.bEnablePreviousRecord = false;
5816 this.bBeforeFirstRow = true;
5817 this.bAfterLastRow = true;
5818 this.bEnableOrderBy = false;
5819 this.iFirstColumnResult = 1;
5820 this.iTargetFirstColumnResult = 1;
5821 this.iColumnsInSourceTable = 0;
5822 }
5823 }
This page automatically generated by Maven