1 /*
2 Loader - tool for transfering data from one JDBC source to another and
3 doing transformations during copy.
4 Copyright (C) 2002-2003 Together
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13 You should have received a copy of the GNU Lesser General Public
14 License along with this library; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 Loader.java
17 Date: 03.03.2003.
18 @version 2.1 alpha
19 @authors:
20 Milosevic Sinisa sinisa@prozone.yu
21 Radoslav Dutina rale@prozone.co.yu
22 */
23
24 package org.webdocwf.util.loader;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.ByteArrayOutputStream;
28 import java.io.File;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.math.BigDecimal;
32 import java.net.URL;
33 import java.sql.Connection;
34 import java.sql.DriverManager;
35 import java.sql.PreparedStatement;
36 import java.sql.ResultSet;
37 import java.sql.ResultSetMetaData;
38 import java.sql.SQLException;
39 import java.sql.Statement;
40 import java.sql.Time;
41 import java.sql.Timestamp;
42 import java.text.DateFormat;
43 import java.text.ParseException;
44 import java.text.SimpleDateFormat;
45 import java.util.ArrayList;
46 import java.util.Date;
47 import java.util.HashMap;
48 import java.util.Hashtable;
49 import java.util.Iterator;
50 import java.util.List;
51 import java.util.Map;
52 import java.util.StringTokenizer;
53 import java.util.Vector;
54
55 import javax.xml.parsers.DocumentBuilder;
56 import javax.xml.parsers.DocumentBuilderFactory;
57
58 import org.w3c.dom.Document;
59 import org.w3c.dom.Element;
60 import org.w3c.dom.NamedNodeMap;
61 import org.w3c.dom.Node;
62 import org.w3c.dom.NodeList;
63 import org.webdocwf.util.loader.logging.Logger;
64 import org.webdocwf.util.loader.logging.StandardLogger;
65 import org.webdocwf.util.loader.transformation.QueryTransformationSet;
66 import org.webdocwf.util.loader.transformation.Transformation;
67 import org.webdocwf.util.loader.transformation.Transformations;
68 import org.xml.sax.SAXException;
69
70 /***
71 * <p>
72 * Loader class loads data from source database into target database using
73 * criteria set in XML file which is used as parameter. Also Loader can execute
74 * SQL statements which import from XML file. <br>
75 * All loading rolls are set in XML file. Some capabilities of this loader are:
76 * there could be more then one importDefinition and number of them is not
77 * limited, source and target database could be different, source database could
78 * be ASCII,Excel or Access file too, operator (the person or application which
79 * starts Loader) have to define. Restart mode with second parameter (optional).
80 * </p>
81 * <p>
82 * There are two possible ways to start Loader. The first is as stand alone
83 * application, the sintaxs is: <br>
84 * <code><B>java org.webdocwf.util.loader.Loader [-options] urlOfTheXmlFile.xml</B></code>
85 * <br>
86 * urlOfTheXmlFile.xml is URL of the XML file with loading criteria,<br>
87 * </p>
88 * <p>
89 * The second way is to start Loader as package, the sintax is:<br>
90 * <code><B>public Loader(String loadJobFileName, String mode, String userID, String logDirName,
91 * String logFileName, boolean restartIndicator, Map variableValues, String vendorFileName,
92 * boolean onErrorContinue, String additionalPaths, int commitCount, int returnCode);
93 * </code><br>
94 * ldr.load();</B> <br>
95 * If we want to execute Loader class without last for parameters, we must put
96 * null as these arguments
97 * </p>
98 * <p>
99 * When the Loader is started the log file is generated. Log file is txt file
100 * and its name defines date and time when the Loader is started. There are
101 * three Log modes: none - report only begining and finishing the application,
102 * and exceptions if there are any, normal - add to log importing blocks and
103 * full - with detailed report to operator.
104 * </p>
105 * <p>
106 * Another big adventage of Loader is its possibility to execute any SQL
107 * statements in target database. (creating database; creating, modifying and
108 * deleting tables...)
109 * </p>
110 * <p>
111 * XML file is the key part for loading criteria. XML tags define how the
112 * loading job will be done.
113 * </p>
114 *
115 * @author Milosevic Sinisa
116 * @author Radoslav Dutina
117 * @author Zoran Milakovic
118 */
119 public class Loader {
120 int iValueColumns;
121
122 Vector vecValueColumnsTargetTables = new Vector();
123
124 // Vector vecTransformColumnsTargetTables = new Vector();
125 Vector vecSourceColumnName = new Vector();
126
127 Vector vecTargetColumnName = new Vector();
128
129 Vector vecValueMode = new Vector();
130
131 Vector vecTargetColumnValue = new Vector();
132
133 Vector vecTargetKeyColumnName = new Vector();
134
135 Vector vecVariableUseIDTableName = new Vector();
136
137 Vector vecVariableUseIDTableID = new Vector();
138
139 Vector vecVariableUseIDColumnName = new Vector();
140
141 Vector vecVariableUseIDValueMode = new Vector();
142
143 Vector vecVariableColumnName = new Vector();
144
145 Vector vecVariableColumnTargetTableName = new Vector();
146
147 Vector vecVariableColumnTargetTableID = new Vector();
148
149 Vector vecVariableColumnTargetColumnName = new Vector();
150
151 Vector vecVariableColumnValueMode = new Vector();
152
153 Vector vecVariableColumnTypes = new Vector();
154
155 Vector vecVariableTimesTableName = new Vector();
156
157 Vector vecVariableTimesTableID = new Vector();
158
159 Vector vecVariableTimesColumnName = new Vector();
160
161 Vector vecVariableTimesValueMode = new Vector();
162
163 int iConstantColumns;
164
165 Vector vecConstantTargetColumnName = new Vector();
166
167 Vector vecConstantValueMode = new Vector();
168
169 Vector vecConstantConstantValue = new Vector();
170
171 Vector vecConstantColumnTargetTableName = new Vector();
172
173 Vector vecConstantColumnTargetTableID = new Vector();
174
175 int iRelationColumns;
176
177 Vector vecRelationColumnSourceTableName = new Vector();
178
179 Vector vecRelationColumnSourceTableID = new Vector();
180
181 Vector vecRelationColumnSourceColumnName = new Vector();
182
183 Vector vecRelationColumnTargetTableName = new Vector();
184
185 Vector vecRelationColumnTargetColumnName = new Vector();
186
187 Vector vecRelationColumnTargetTableID = new Vector();
188
189 Vector vecRelationColumnRelationMode = new Vector();
190
191 int iTables;
192
193 Vector vecTableTableName = new Vector();
194
195 Vector vecTableTableID = new Vector();
196
197 Vector vecTableInsert = new Vector();
198
199 Vector vecTableTableMode = new Vector();
200
201 Vector vecTableOidLogic = new Vector();
202
203 Vector vecRelationSourceValue = new Vector();
204
205 Vector vecRelationSourceType = new Vector();
206
207 Vector vecTargetColumnType = new Vector();
208
209 Vector vecConstantColumnType = new Vector();
210
211 BigDecimal bdecOidNumber = new BigDecimal(0);
212
213 BigDecimal bdecOidNumber2000 = new BigDecimal(0);
214
215 String strLoaderJobFileName = "";
216
217 boolean bRestartIndicator;
218
219 Map mapVariableValues = new HashMap();
220
221 boolean bOnErrorContinue;
222
223 String strUserID = "";
224
225 String strLogDirName = "";
226
227 String strLogFileName = "";
228
229 String strVendorFileName = "";
230
231 String strAdditionalPaths = "";
232
233 String confJarStructure = "";
234
235 // interne Sinisa
236 boolean hasRestartCounter;
237
238 boolean hasUserID;
239
240 Vector vecRelationKeyColumns = new Vector();
241
242 Vector vecRelationKeyTypes = new Vector();
243
244 Vector vecSortValues = new Vector();
245
246 Vector vecSqlStmt = new Vector();
247
248 String strSourceDriverName = "";
249
250 String strTargetDriverName = "";
251
252 // conf file default
253 int iFirstColumnResult = 1;
254
255 int iTargetFirstColumnResult = 1;
256
257 //
258 Vector vecVariableName = new Vector();
259
260 Vector vecVariableValue = new Vector();
261
262 Vector vecVariablePrefix = new Vector();
263
264 Vector vecVariableSufix = new Vector();
265
266 Vector vecVariableOverride = new Vector();
267
268 Vector vecReplaceInConstants = new Vector();
269
270 Vector vecReplaceInSQL = new Vector();
271
272 Vector vecReplaceInData = new Vector();
273
274 Vector vecReplaceInJDBC = new Vector();
275
276 public static final String LOGMODE_NONE = "none";
277
278 public static final String LOGMODE_NORMAL = "normal";
279
280 public static final String LOGMODE_FULL = "full";
281
282 ByteArrayOutputStream foStreamTmp = new ByteArrayOutputStream();
283
284 boolean bReplaceInData = false;
285
286 int iColumnsInSourceTable = 0;
287
288 boolean isDefaultJdbc = false;
289
290 private String defaultLogMode = LOGMODE_NORMAL;
291
292 ArrayList logModes = new ArrayList();
293
294 // private Cache cacheValues;
295 // private EchoElement echo;
296 private Logger logger;
297
298 private CounterColumns counterColumns;
299
300 private TimeWatch timeCounter;
301
302 private Transformations transformations;
303
304 // NEW CLASSES
305 private JdbcParametersElement jdbcParametersElement = new JdbcParametersElement();
306
307 private SqlElement sqlElement = new SqlElement();
308
309 private ConfigReader configReaderSource = new ConfigReader();
310
311 private ConfigReader configReaderTarget = new ConfigReader();
312
313 private LoaderJobAttrReader loaderJobReader = new LoaderJobAttrReader();
314
315 private ImportDefinitionElement importDefinitionElement = new ImportDefinitionElement();
316
317 private DataCleaning dataCleaning = new DataCleaning(configReaderTarget);
318
319 // rale
320 private String strQuerySet = "";
321
322 QueryWhereSet queryWhereSet = null;
323
324 QueryConstantSet queryConstantSet = null;
325
326 QueryTransformationSet queryTransformationSet = null;
327
328 Hashtable queryStatement = new Hashtable();
329
330 Hashtable indexDValue = new Hashtable();
331
332 Hashtable indexDRelationValue = new Hashtable();
333
334 Hashtable indexConstantDValue = new Hashtable();
335
336 Hashtable indexDVariableValue = new Hashtable();
337
338 Hashtable indexDTransformationValue = new Hashtable();
339
340 Hashtable updateStatement = new Hashtable();
341
342 Hashtable indexDOverwrite = new Hashtable();
343
344 Hashtable indexDSetNull = new Hashtable();
345
346 Hashtable updateConstantStatement = new Hashtable();
347
348 Hashtable indexDConstantOver = new Hashtable();
349
350 Hashtable indexDConstantNull = new Hashtable();
351
352 // zk added this
353 Hashtable resultVector = new Hashtable();
354
355 Hashtable updateTransformationStatement = new Hashtable();
356
357 Hashtable indexDTransformationOver = new Hashtable();
358
359 Hashtable indexDTransformationNull = new Hashtable();
360
361 Hashtable indexDTransformationUpdate = new Hashtable();
362
363 // insert row
364 Hashtable queryInsertRow = new Hashtable();
365
366 Hashtable indexIsNotRelationsColumns = new Hashtable();
367
368 Hashtable pstmtForInsert = new Hashtable();
369
370 Hashtable pstmtColumnNames = new Hashtable();
371
372 // Hashtable pstmtColumnTypes = new Hashtable();
373
374 Vector pstmtKeys = new Vector();
375
376 // default value
377 Vector vecDefaultValue = new Vector();
378
379 Vector vecDefaultVariableValue = new Vector();
380
381 Vector vecDefaultVariableName = new Vector();
382
383 Vector vecDefaultRelationValue = new Vector();
384
385 Vector vecTempUserID = new Vector();
386
387 boolean userIDExists = false;
388
389 private int currentRow = 0;
390
391 // coy table
392 // source data which are not maped in to target data
393 Hashtable allSourceColumnNameNoMap = new Hashtable();
394
395 Hashtable allSourceColumnValueNoMap = new Hashtable();
396
397 Hashtable allSourceColumnTypeNoMap = new Hashtable();
398
399 Vector ImportDefinitionSourceColumnName = new Vector();
400
401 Vector ImportDefinitionTargetColumnName = new Vector();
402
403 private String currentJobName = "";
404
405 Vector vecCTAutoMapp = new Vector();
406
407 Vector vecCTDefaultMode = new Vector();
408
409 Vector vecBlobVector = new Vector();
410
411 Vector vecToHex = new Vector();
412
413 Vector vecFromHex = new Vector();
414
415 // caching the relations
416 RelationsCache relationsCache = new RelationsCache();
417
418 private Vector includeTables = new Vector();
419
420 // caching the 'row check' query
421 CheckRowCache checkRowCache = new CheckRowCache();
422
423 // restart counter
424 DataTransmition dataTransmition = new DataTransmition(
425 importDefinitionElement);
426
427 // oid and version column name
428 private String currentOidColumnName = "oid";
429
430 private String currentVersionColumnName = "version";
431
432 // private PreparedStatementMethods pstmtMethods=new
433 // PreparedStatementMethods();
434 private Vector transformationsColumnNames = new Vector();
435
436 private Vector transformationsValueModes = new Vector();
437
438 private Vector transformationsColumnValueMode = new Vector();
439
440 private Vector transformationsColumnTypes = new Vector();
441
442 private Vector transformationsResultVectorTypes = new Vector();
443
444 private Vector resultVectorTypes = new Vector();
445
446 // ValidateSelectStmt validStmt = new ValidateSelectStmt();
447
448 // number of columns before transformation values from source query
449 // private int iOffsetForTransColumns = 0;
450
451 // values for transformations, used from source ResultSet for all
452 // transformation
453 // source coulmns
454 Vector transformationValues = new Vector();
455
456 /***
457 * Construct object Loader with an associated parameters.
458 *
459 * @param loadJobFileName
460 * defines xml input file.
461 * @param mode
462 * defines the default logmode. Possible values are "none",
463 * "normal" (is the default) and "full". Is "normal" otherwise -m
464 * none
465 * @param userID
466 * String which is name of user. This argument is used for
467 * writing userID into variable columns. If it is 'null' there is
468 * no define userID columns.
469 * @param logDirName
470 * defines the logfile directory. The default is the current
471 * working directory.
472 * @param logFileName
473 * defines the logfile name. The default is
474 * "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
475 * @param restartIndicator
476 * which is true if "restart" mode and false if "new" mode.
477 * @param variableValues
478 * Map defines variables used in variable columns.
479 * @param vendorFileName
480 * the filename of the XML DB-vendor configuration file. The
481 * default is "OctopusDBVendors.xml".
482 * @param onErrorContinue
483 * defines to set the default of "onErrorContinue" to "true". Is
484 * false otherwise.
485 * @param additionalPaths
486 * Extend the classpath with additional paths.
487 * @param commitCount
488 * Sets the default commit count. System default is "100".
489 * @param returnCode
490 * Sets the default error return code. System default is "1".
491 * @param includeTables
492 * defines tables which will be processed
493 */
494 public Loader(String loadJobFileName, String mode, String userID,
495 String logDirName, String logFileName, boolean restartIndicator,
496 Map variableValues, String vendorFileName, boolean onErrorContinue,
497 String additionalPaths, int commitCount, int returnCode,
498 String[] includeTables, String confJarStructure) {
499 this.strLoaderJobFileName = loadJobFileName;
500 // defines the log mode,
501 if (mode != null) {
502 if (mode.equalsIgnoreCase("none")
503 || mode.equalsIgnoreCase("normal")
504 || mode.equalsIgnoreCase("full")) {
505 // importDefinitionElement.strLogMode = mode;
506 this.defaultLogMode = mode;
507 // sqlElement.strLogMode = mode;
508 } // else {
509 // importDefinitionElement.strLogMode = "";
510 // sqlElement.strLogMode = "";
511 }
512
513 if (userID != null) {
514 this.strUserID = userID;
515 this.hasUserID = true;
516 } else
517 this.hasUserID = false;
518 if (logDirName != null)
519 this.strLogDirName = logDirName;
520 else {
521 File fCurrent = new File("");
522 this.strLogDirName = fCurrent.getAbsolutePath();
523 }
524 if (logFileName != null) {
525 this.strLogFileName = logFileName;
526 } else
527 this.strLogFileName = "default";
528 this.bRestartIndicator = restartIndicator;
529 if (this.bRestartIndicator == true)
530 this.hasRestartCounter = true;
531 else
532 this.hasRestartCounter = false;
533 this.mapVariableValues = variableValues;
534 if (vendorFileName != null) {
535 this.strVendorFileName = vendorFileName;
536 }
537 this.bOnErrorContinue = onErrorContinue;
538 if (additionalPaths != null) {
539 try {
540 this.strAdditionalPaths = additionalPaths;
541 StringTokenizer st = new StringTokenizer(
542 this.strAdditionalPaths, ";");
543 URL[] urls = new URL[st.countTokens()];
544 int count = 0;
545 while (st.hasMoreTokens()) {
546 urls[count] = new File(st.nextElement().toString()).toURL();
547 count++;
548 }
549 for (int i = 0; i < urls.length; i++) {
550 OctopusClassLoader.addURL(urls[i]);
551 }
552 } catch (Exception ne) {
553 ne.printStackTrace();
554 }
555 }
556 if (includeTables != null) {
557 for (int i = 0; i < includeTables.length; i++) {
558 this.includeTables.add(includeTables[i]);
559 }
560 }
561 importDefinitionElement.iCommitCount = commitCount;
562 ReturnCode.setDefaultErrorReturnCode(returnCode);
563 this.confJarStructure = confJarStructure;
564 }
565
566 /***
567 * Construct object Loader with an associated parameters.
568 *
569 * @param loadJobFileName
570 * defines xml input file.
571 * @param mode
572 * defines the default logmode. Possible values are "none",
573 * "normal" (is the default) and "full". Is "normal" otherwise -m
574 * none
575 * @param userID
576 * String which is name of user. This argument is used for
577 * writing userID into variable columns. If it is 'null' there is
578 * no define userID columns.
579 * @param logDirName
580 * defines the logfile directory. The default is the current
581 * working directory.
582 * @param logFileName
583 * defines the logfile name. The default is
584 * "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
585 * @param restartIndicator
586 * which is true if "restart" mode and false if "new" mode.
587 * @param variableValues
588 * Map defines variables used in variable columns.
589 * @param vendorFileName
590 * the filename of the XML DB-vendor configuration file. The
591 * default is "OctopusDBVendors.xml".
592 * @param onErrorContinue
593 * defines to set the default of "onErrorContinue" to "true". Is
594 * false otherwise.
595 * @param additionalPaths
596 * Extend the classpath with additional paths.
597 * @param commitCount
598 * Sets the default commit count. System default is "100".
599 * @param returnCode
600 * Sets the default error return code. System default is "1".
601 */
602 public Loader(String loadJobFileName, String mode, String userID,
603 String logDirName, String logFileName, boolean restartIndicator,
604 Map variableValues, String vendorFileName, boolean onErrorContinue,
605 String additionalPaths, int commitCount, int returnCode) {
606
607 this(loadJobFileName, mode, userID, logDirName, logFileName,
608 restartIndicator, variableValues, vendorFileName,
609 onErrorContinue, additionalPaths, commitCount, returnCode,
610 null, null);
611
612 }
613
614 /***
615 * Construct object Loader with an associated parameters.
616 *
617 * @param loadJobFileName
618 * defines xml input file.
619 * @param mode
620 * defines the default logmode. Possible values are "none",
621 * "normal" (is the default) and "full". Is "normal" otherwise -m
622 * none
623 * @param userID
624 * String which is name of user. This argument is used for
625 * writing userID into variable columns. If it is 'null' there is
626 * no define userID columns.
627 * @param logDirName
628 * defines the logfile directory. The default is the current
629 * working directory.
630 * @param logFileName
631 * defines the logfile name. The default is
632 * "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
633 * @param restartIndicator
634 * which is true if "restart" mode and false if "new" mode.
635 * @param variableValues
636 * Map defines variables used in variable columns.
637 * @param vendorFileName
638 * the filename of the XML DB-vendor configuration file. The
639 * default is "OctopusDBVendors.xml".
640 * @param onErrorContinue
641 * defines to set the default of "onErrorContinue" to "true". Is
642 * false otherwise.
643 * @param additionalPaths
644 * Extend the classpath with additional paths.
645 * @param commitCount
646 * Sets the default commit count. System default is "100".
647 * @param returnCode
648 * Sets the default error return code. System default is "1".
649 */
650 public Loader(String loadJobFileName, String mode, String userID,
651 String logDirName, String logFileName, boolean restartIndicator,
652 Map variableValues, String vendorFileName, boolean onErrorContinue,
653 String additionalPaths, int commitCount, int returnCode,
654 String[] includeTables) {
655
656 this(loadJobFileName, mode, userID, logDirName, logFileName,
657 restartIndicator, variableValues, vendorFileName,
658 onErrorContinue, additionalPaths, commitCount, returnCode,
659 includeTables, null);
660
661 }
662
663 /***
664 * Construct object Loader with an associated parameters.
665 *
666 * @param loadJobFileName
667 * defines xml input file.
668 * @param mode
669 * defines the default logmode. Possible values are "none",
670 * "normal" (is the default) and "full". Is "normal" otherwise -m
671 * none
672 * @param userID
673 * String which is name of user. This argument is used for
674 * writing userID into variable columns. If it is 'null' there is
675 * no define userID columns.
676 * @param logDirName
677 * defines the logfile directory. The default is the current
678 * working directory.
679 * @param logFileName
680 * defines the logfile name. The default is
681 * "LoaderLog-YYYY-MM-DD-HH-mm-SS.txt".
682 * @param restartIndicator
683 * which is true if "restart" mode and false if "new" mode.
684 * @param variableValues
685 * Map defines variables used in variable columns.
686 * @param vendorFileName
687 * the filename of the XML DB-vendor configuration file. The
688 * default is "OctopusDBVendors.xml".
689 * @param onErrorContinue
690 * defines to set the default of "onErrorContinue" to "true". Is
691 * false otherwise.
692 * @param additionalPaths
693 * Extend the classpath with additional paths.
694 * @param commitCount
695 * Sets the default commit count. System default is "100".
696 * @param returnCode
697 * Sets the default error return code. System default is "1".
698 */
699 public Loader(String loadJobFileName, String mode, String userID,
700 String logDirName, String logFileName, boolean restartIndicator,
701 Map variableValues, String vendorFileName, boolean onErrorContinue,
702 String additionalPaths, int commitCount, int returnCode,
703 String confJarStructure) {
704
705 this(loadJobFileName, mode, userID, logDirName, logFileName,
706 restartIndicator, variableValues, vendorFileName,
707 onErrorContinue, additionalPaths, commitCount, returnCode,
708 null, confJarStructure);
709
710 }
711
712 /***
713 * Method addClassPath adds additional class paths into system classpath
714 * property
715 *
716 * @param oldClassPath -
717 * System classpath;
718 * @param add -
719 * additional class paths.
720 * @return value of parameter classPath
721 */
722 private String addClassPath(String oldClassPath, String add) {
723
724 String classPath = oldClassPath;
725 if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
726 if (!classPath.trim().endsWith(";"))
727 classPath += ";";
728 add = add.replace('\n', '//');
729 add = add.replace('\t', '//');
730 add = add.replace('\b', '//');
731 add = add.replace('\r', '//');
732 add = add.replace('\f', '//');
733 classPath = classPath.concat(add);
734 } else {
735 if (!classPath.trim().endsWith(":"))
736 classPath += ":";
737 add = add.replace('\n', '/');
738 add = add.replace('\t', '/');
739 add = add.replace('\b', '/');
740 add = add.replace('\r', '/');
741 add = add.replace('\f', '/');
742 classPath = classPath.concat(add);
743
744 }
745 return classPath;
746 }
747
748 /***
749 * Public constructor of Loader class. Constructor set value for
750 * loadJobFileName attribute. Class set all other attributes to the default
751 * values.
752 *
753 * @param loadJobFileName
754 * Name of loadJob import XML file.
755 *
756 */
757 public Loader(String loadJobFileName) {
758 this(loadJobFileName, null);
759 }
760
761 /***
762 * Public constructor of Loader class. Constructor set value for
763 * loadJobFileName attribute. Class set all other attributes to the default
764 * values.
765 *
766 * @param loadJobFileName
767 * Name of loadJob import XML file.
768 *
769 */
770 public Loader(String loadJobFileName, String confJarStructure) {
771 this.strLoaderJobFileName = loadJobFileName;
772 // importDefinitionElement.strLogMode = "";
773 this.hasUserID = false;
774 File fCurrent = new File("");
775 this.strLogDirName = fCurrent.getAbsolutePath();
776 this.strLogFileName = "default";
777 this.bRestartIndicator = false;
778 this.hasRestartCounter = false;
779 this.bOnErrorContinue = false;
780 importDefinitionElement.iCommitCount = 100;
781 ReturnCode.setDefaultErrorReturnCode(1);
782 this.confJarStructure = confJarStructure;
783 }
784
785 /***
786 * Read value of loadJobFileName attribute.
787 *
788 * @return String value of loadFileName attribute
789 */
790 public String getLoadJobFileName() {
791 return this.strLoaderJobFileName;
792 }
793
794 /***
795 * This method sets value of loadJobFileName attribute.
796 *
797 * @param loadJobFileName
798 * loadJob XML file name
799 */
800 public void setLoadJobFileName(String loadJobFileName) {
801 this.strLoaderJobFileName = loadJobFileName;
802 }
803
804 /***
805 * Read value of Mode(LogMode) attribute.
806 *
807 * @return value of attribute.
808 */
809 // public String getMode() {
810 // return importDefinitionElement.strLogMode;
811 // }
812 /***
813 * This method sets value of Mode attribute.
814 *
815 * @param mode
816 * define Log mode. Possible values are: Loader.LOGMODE_NONE,
817 * Loader.LOGMODE_NORMAL, Loader.LOGMODE_FULL.
818 */
819 // public void setMode(String mode) {
820 // importDefinitionElement.strLogMode = mode;
821 // }
822 /***
823 * Read value of userID attribute.
824 *
825 * @return value of attribute.
826 */
827 public String getUserID() {
828 return this.strUserID;
829 }
830
831 /***
832 * This method sets value of userID attribute.
833 *
834 * @param userID
835 * attribute.
836 */
837 public void setUserID(String userID) {
838 this.strUserID = userID;
839 }
840
841 /***
842 * Read value of logDirName attribute
843 *
844 * @return value of attribute
845 */
846 public String getLogDirName() {
847 return this.strLogDirName;
848 }
849
850 /***
851 * This method sets value of logDirName attribute.
852 *
853 * @param logDirName
854 * value of attribute.
855 */
856 public void setLogDirName(String logDirName) {
857 this.strLogDirName = logDirName;
858 }
859
860 /***
861 * Read value of logFileName attribute.
862 *
863 * @return value of attribute.
864 */
865 public String getLogFileName() {
866 return this.strLogFileName;
867 }
868
869 /***
870 * This method sets value of logFileName attribute.
871 *
872 * @param logFileName
873 * value of attribute.
874 */
875 public void setLogFileName(String logFileName) {
876 this.strLogFileName = logFileName;
877 }
878
879 /***
880 * Read value of restartIndicator attribute.
881 *
882 * @return value of attribute.
883 */
884 public boolean getRestartIndicator() {
885 return this.bRestartIndicator;
886 }
887
888 /***
889 * This method sets value of restartIndicator attribute.
890 *
891 * @param restartIndicator
892 * value of attribute.
893 */
894 public void setRestartIndicator(boolean restartIndicator) {
895 this.bRestartIndicator = restartIndicator;
896 }
897
898 /***
899 * Read value of variableValues attribute.
900 *
901 * @return value of attribute.
902 */
903 public Map getVariableValues() {
904 return this.mapVariableValues;
905 }
906
907 /***
908 * This method sets value of variableValues attribute.
909 *
910 * @param variableValue
911 * value of attribute.
912 */
913 public void setVariableValues(Map variableValue) {
914 this.mapVariableValues = variableValue;
915 }
916
917 /***
918 * Read value of vendorFileName.
919 *
920 * @return value of attribute.
921 */
922 public String getVendorFileName() {
923 return this.strVendorFileName;
924 }
925
926 /***
927 * This method sets value of vendorFileName attribute.
928 *
929 * @param vendorFileName
930 * value of attribute.
931 */
932 public void setVendorFileName(String vendorFileName) {
933 this.strVendorFileName = vendorFileName;
934 }
935
936 /***
937 * read value of onErrorContinue attribute.
938 *
939 * @return value of attribute.
940 */
941 public boolean getOnErrorContinue() {
942 return this.bOnErrorContinue;
943 }
944
945 /***
946 * This method sets value of onErrorContinue attribute.
947 *
948 * @param onErrorContinue
949 * value of attribute.
950 */
951 public void setOnErrorContinue(boolean onErrorContinue) {
952 this.bOnErrorContinue = onErrorContinue;
953 }
954
955 /***
956 * Read value of additionalPaths attribute.
957 *
958 * @return value of attribute.
959 */
960 public String getAdditionalPaths() {
961 return this.strAdditionalPaths;
962 }
963
964 /***
965 * This method sets value of additionalPaths attribute.
966 *
967 * @param additionalPaths
968 * value of attribute.
969 */
970 public void setAdditionalPaths(String additionalPaths) {
971 this.strAdditionalPaths = additionalPaths;
972 String strClassPath = System.getProperty("java.class.path");
973 strClassPath = this.addClassPath(strClassPath, this.strAdditionalPaths);
974 try {
975 this.getClass().getClassLoader().loadClass(strClassPath);
976 } catch (ClassNotFoundException ne) {
977 ne.printStackTrace();
978 }
979 // System.setProperty("java.class.path", strClassPath);
980 }
981
982 /***
983 * Read value of commitCount attribute.
984 *
985 * @return value of attribute.
986 */
987 public int getCommitCount() {
988 return importDefinitionElement.iCommitCount;
989 }
990
991 /***
992 * This method sets value of commitCount attribute.
993 *
994 * @param commitCount
995 * value of attribute.
996 */
997 public void setCommitCount(int commitCount) {
998 importDefinitionElement.iCommitCount = commitCount;
999 }
1000
1001 /***
1002 * Read value of default error return code attribute.
1003 *
1004 * @return value of attribute.
1005 */
1006 public int getDefaultReturnCode() {
1007 return ReturnCode.getDefaultErrorReturnCode();
1008 }
1009
1010 /***
1011 * This method sets value of default error return code attribute.
1012 *
1013 * @param code
1014 * is value of attribute.
1015 */
1016 public void setDefaultReturnCode(int code) {
1017 ReturnCode.setDefaultErrorReturnCode(code);
1018 }
1019
1020 /***
1021 * This method set value of includeJobs parameter
1022 *
1023 * @param include_Tables
1024 * is value of parameter
1025 */
1026 public void setIncludedJobs(String include_Tables[]) {
1027 for (int i = 0; i < include_Tables.length; i++) {
1028 includeTables.add(include_Tables[i]);
1029 }
1030 }
1031
1032 /***
1033 * This method read value of includeJobs parameter
1034 *
1035 * @return value of parameter
1036 */
1037 public String[] getIncludedJobs() {
1038 String ret[] = new String[this.includeTables.size()];
1039 for (int i = 0; i < includeTables.size(); i++) {
1040 ret[i] = includeTables.get(i).toString();
1041 }
1042 return ret;
1043 }
1044
1045 /***
1046 * This method read value of confJarStructure parameter
1047 *
1048 * @return value of parameter
1049 */
1050 public String getConfJarStructure() {
1051
1052 return this.confJarStructure;
1053 }
1054
1055 /***
1056 * This method read value of defaultLogMode parameter
1057 *
1058 * @return value of parameter
1059 */
1060 public String getDefaultLogMode() {
1061
1062 return this.defaultLogMode;
1063 }
1064
1065 /***
1066 * Main method Loader with an associated XML, restart mode (optional) i user
1067 * (optional). Main method controls parameters, it they are OK starts load
1068 * method, but if they aren't makes alert. Usage: java
1069 * org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
1070 * Options: -m defines the default logmode. Possible values are 'none',
1071 * 'normal' (is the default) and 'full'. -r starts the Loader in restart
1072 * mode after abnormal termination in a prior execution. -u defines the
1073 * current UserID used in UserID value columns. -v defines variables used in
1074 * variable columns. -l defines the logfile directory. The default is the
1075 * current working directory. -f defines the logfile name. The default is
1076 * 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. -d the filename of the XML DB-vendor
1077 * configuration file. The default is 'OctopusDBVendors.xml'. -e defines to
1078 * set the default of 'onErrorContinue' to 'true'. Is false otherwise. -p
1079 * Extend the classpath with additional paths. -c Sets the default commit
1080 * count. System default is '100'. -rc Sets the default error return code.
1081 * System default is '1'. -it Sets the table names which will be proccesed
1082 *
1083 * @param argv
1084 * represents input parmeters
1085 */
1086 public static void main(String argv[]) {
1087 String loadJobFileName = null;
1088 String mode = null;
1089 String userID = null;
1090 String logDirName = null;
1091 String logFileName = null;
1092 boolean restartIndicator = false;
1093 Map variableValues = null;
1094 String strVariableValues = null;
1095 String vendorFileName = null;
1096 boolean onErrorContinue = false;
1097 String additionalPaths = null;
1098 int defaultReturnCode = 1;
1099 int commitCount = 0;
1100 String[] includeTables = null;
1101 String confJarStructure = null;
1102
1103 if (argv.length > 0 && argv.length < 26) {
1104 loadJobFileName = argv[argv.length - 1];
1105 for (int i = 0; i < argv.length - 1; i = i + 1) {
1106 if (argv[i].equalsIgnoreCase("-m"))
1107 mode = argv[++i];
1108 else if (argv[i].equalsIgnoreCase("-r"))
1109 restartIndicator = true;
1110 else if (argv[i].equalsIgnoreCase("-u"))
1111 userID = argv[++i];
1112 else if (argv[i].equalsIgnoreCase("-l"))
1113 logDirName = argv[++i];
1114 else if (argv[i].equalsIgnoreCase("-f"))
1115 logFileName = argv[++i];
1116 else if (argv[i].equalsIgnoreCase("-d"))
1117 vendorFileName = argv[++i];
1118 else if (argv[i].equalsIgnoreCase("-e"))
1119 onErrorContinue = true;
1120 else if (argv[i].equalsIgnoreCase("-p"))
1121 additionalPaths = argv[++i];
1122 else if (argv[i].equalsIgnoreCase("-c"))
1123 commitCount = (new Integer(argv[++i])).intValue();
1124 else if (argv[i].equalsIgnoreCase("-v")) {
1125 strVariableValues = argv[++i];
1126 variableValues = new HashMap(
1127 convertToMap(strVariableValues));
1128 } else if (argv[i].equalsIgnoreCase("-rc")) {
1129 defaultReturnCode = (new Integer(argv[++i])).intValue();
1130 ReturnCode.isParameter = true;
1131 } else if (argv[i].equalsIgnoreCase("-it")) {
1132 String array = argv[++i];
1133 StringTokenizer st = new StringTokenizer(array, ";");
1134 includeTables = new String[st.countTokens()];
1135 int pos = 0;
1136 while (st.hasMoreTokens()) {
1137 includeTables[pos] = st.nextToken();
1138 pos++;
1139 }
1140 } else if (argv[i].equalsIgnoreCase("-cjs")) {
1141 confJarStructure = argv[++i];
1142 }
1143 }
1144 } else
1145 printUsage();
1146 Loader l = new Loader(loadJobFileName, mode, userID, logDirName,
1147 logFileName, restartIndicator, variableValues, vendorFileName,
1148 onErrorContinue, additionalPaths, commitCount,
1149 defaultReturnCode, includeTables, confJarStructure);
1150 try {
1151 l.load();
1152 BufferOctopusClass.getInstance().writeToBuffer(
1153 String.valueOf(ReturnCode.getOKReturnCode()));
1154 } catch (LoaderException le) {
1155 BufferOctopusClass.getInstance()
1156 .writeToBuffer(le.getCause() + "\n");
1157 BufferOctopusClass.getInstance().writeToBuffer(
1158 String.valueOf(ReturnCode.getErrorReturnCode()));
1159 System.exit(ReturnCode.getErrorReturnCode());
1160 }
1161 }
1162
1163 /***
1164 * put your documentation comment here
1165 */
1166 static void printUsage() {
1167 System.out
1168 .println("Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename");
1169 System.out.println(" Options:");
1170 System.out
1171 .println(" -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.");
1172 System.out
1173 .println(" -r starts the Loader in restart mode after abnormal termination in a prior execution. \n");
1174 System.out
1175 .println(" -u defines the current UserID used in UserID value columns. \n");
1176 System.out
1177 .println(" -v defines variables used in variable columns. \n");
1178 System.out
1179 .println(" -l defines the logfile directory. The default is the current working directory. \n");
1180 System.out
1181 .println(" -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n");
1182 System.out
1183 .println(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n");
1184 System.out
1185 .println(" -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n");
1186 System.out.println(" -p Extend the classpath with additional paths \n");
1187 System.out
1188 .println(" -c Sets the default commit count. System default is '100'. \n");
1189 System.out
1190 .println(" -rc Sets the default error return code. System default is '1'. \n");
1191 System.out
1192 .println(" -it Sets the table names which will be proccesed ");
1193 System.exit(ReturnCode.getErrorReturnCode());
1194 }
1195
1196 /***
1197 * Method load is main method in class Loader. It is used to load data from
1198 * the source table into target tables and(or) execute SQL statements.
1199 * Loading parameters are set in XML file. During loading, load status is
1200 * printed on the screen and also put into log file. If there is an error
1201 * Exception "LoaderException" is thrown.
1202 *
1203 * @throws LoaderException
1204 */
1205 public void load() throws LoaderException {
1206 int iImportJobs = 0;
1207 int iCopyTable = 0;
1208 int iConnection = 0;
1209 int iSqlTags = 0;
1210 int iEchoElements = 0;
1211 int iLastImportDefinition = 0;
1212 Vector vecXmlElements = new Vector();
1213 Vector vecJDBCTargetConnections = new Vector();
1214
1215 // initializing logger
1216 // videti jos oko ulaznih parametara, iz main methode ili is xml fajla
1217 ParseLoggerParam loggerParam = new ParseLoggerParam(
1218 this.strLoaderJobFileName);
1219 String logClassName = loggerParam.getLogClassName();
1220
1221 String pathToLoggerConf = loggerParam.getPathToLoggerConf();
1222 String strLoggerParam = "";
1223 boolean standardLogger = false;
1224 try {
1225 this.logger = (org.webdocwf.util.loader.logging.Logger) Class
1226 .forName(logClassName).newInstance();
1227 if (pathToLoggerConf != null && pathToLoggerConf.length() != 0)
1228 strLoggerParam = pathToLoggerConf;
1229 else
1230 strLoggerParam = this.strLogDirName + ";" + this.strLogFileName;
1231 } catch (Exception e) {
1232 this.logger = new StandardLogger();
1233 strLoggerParam = this.strLogDirName + ";" + this.strLogFileName;
1234 standardLogger = true;
1235 }
1236
1237 try {
1238 logger.configure(strLoggerParam);
1239 logger.setEnabledLogLevels(this.defaultLogMode);
1240 if (standardLogger == true) {
1241 // if
1242 // (!importDefinitionElement.strLogMode.equalsIgnoreCase("none"))
1243 // {
1244 this.logger.write("normal",
1245 "Default (Standard) Logger is load.");
1246 // }
1247 }
1248
1249 } catch (Exception ex) {
1250 String msg = "Error while configuring logger.";
1251 LoaderException le = new LoaderException(msg + "\n"
1252 + ex.getMessage(), (Throwable) ex);
1253 BufferOctopusClass.getInstance().writeToBuffer(
1254 msg + "\n" + ex.getMessage() + "\n");
1255 // this.logger.write("normal", msg + "\n" + ex.getMessage() + "\n");
1256 this.logger.write("full", le.getStackTraceAsString());
1257 throw le;
1258 }
1259
1260 this.timeCounter = new TimeWatch();
1261
1262 // if (!this.echo.createLog(this.strLogDirName, this.strLogFileName))
1263 // this.echo.setLogFile(new File(this.strLogDirName,
1264 // this.strLogFileName));
1265 // this.createLog(this.strLogFileName);
1266
1267 jdbcParametersElement.setLogger(this.logger);
1268 jdbcParametersElement.setConfigReaderSource(this.configReaderSource);
1269 jdbcParametersElement.setLoaderJobPath(this.strLoaderJobFileName);
1270
1271 configReaderSource.setLogger(this.logger);
1272 configReaderTarget.setLogger(this.logger);
1273 configReaderSource.setConfJarStructure(this.confJarStructure);
1274 configReaderTarget.setConfJarStructure(this.confJarStructure);
1275
1276 loaderJobReader.setLogger(this.logger);
1277 loaderJobReader.setDefaultOnErrorContinue(this.bOnErrorContinue);
1278 sqlElement.setLogger(this.logger);
1279 sqlElement.setLoaderJob(this.loaderJobReader);
1280 sqlElement.setConfigReader(this.configReaderTarget);
1281 sqlElement.setJdbcParametersElement(this.jdbcParametersElement);
1282 checkRowCache.setLogger(this.logger);
1283 dataTransmition.setLogger(this.logger);
1284
1285 // if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
1286 this.logger.write("normal", "\nApplication is started.");
1287 // }
1288
1289 this.timeCounter.setStartTime();
1290 ByteArrayInputStream inStream = null;
1291 ByteArrayOutputStream foStream = new ByteArrayOutputStream();
1292 // Loading XML file and replacing include tags
1293 LoaderXIncluder loaderInclude = new LoaderXIncluder(foStream);
1294 LocationOfException locationOfException = new LocationOfException(
1295 this.strLoaderJobFileName);
1296 loaderInclude.parseURI(this.strLoaderJobFileName);
1297 inStream = new ByteArrayInputStream(foStream.toByteArray());
1298
1299 // for test only
1300 // try {
1301 // File file=new
1302 // File("c:/Users/Rale/Octopus/ObjectLoader/InputStream.txt");
1303 // FileOutputStream fileLogr=new FileOutputStream(file);
1304 // if(file.exists())
1305 // file.delete();
1306 // fileLogr.write(foStream.toByteArray());
1307 // fileLogr.close();
1308 // } catch(Exception e) { System.out.println("File error"); }
1309
1310 // part for validating input xml file
1311 try {
1312 OctopusValidator validator = new OctopusValidator();
1313 validator
1314 .validate(new ByteArrayInputStream(foStream.toByteArray()));
1315 } catch (Exception e) {
1316 this.logger.write("normal",
1317 "Sorry, validation error occurred . Message was: "
1318 + e.getMessage());
1319
1320 BufferOctopusClass.getInstance().writeToBuffer(
1321 "Sorry, validation error occurred . Message was: "
1322 + e.getMessage());
1323 LoaderException le = new LoaderException("Exception:"
1324 + e.getMessage(), (Throwable) e);
1325 this.logger.write("full", le.getStackTraceAsString());
1326 throw le;
1327
1328 }
1329 // if (!importDefinitionElement.strLogMode.equalsIgnoreCase("none")) {
1330 this.logger.write("normal", "\nXML document is valid.");
1331
1332 // }
1333
1334 // Import attribute values from variable tags from XML
1335 this.importVariable(inStream);
1336 // Setting bReplaceInData if there is even one ReplaceInData attribut
1337 // in variable tags
1338 for (int i = 0; i < this.vecReplaceInData.size(); i++) {
1339 if (this.vecReplaceInData.get(i).toString()
1340 .equalsIgnoreCase("true"))
1341 bReplaceInData = true;
1342 }
1343 // Change variable values in SQL, JDBC and Constants Tags in XML
1344 this.foStreamTmp = foStream;
1345 foStream = new ByteArrayOutputStream();
1346 LoadVariable loadVariable = new LoadVariable(foStream, this);
1347 loadVariable.parseURI();
1348 // refresh inStream with replaced variables
1349 inStream = new ByteArrayInputStream(foStream.toByteArray());
1350 loaderJobReader.setDefaultLogMode(this.defaultLogMode);
1351 loaderJobReader.importLoaderJobAttributes(inStream);
1352 iImportJobs = this.parseImportJob(inStream);
1353 iCopyTable = this.parseCopyTable(inStream);
1354 iSqlTags = sqlElement.parseSql(inStream);
1355 iEchoElements = this.parseEcho(inStream);
1356 this.importRestartCounter(inStream);
1357 vecXmlElements = this.parseMainElements(inStream);
1358
1359 // setting the last number of importDefinition tag
1360 iLastImportDefinition = 0;
1361 for (int i = 0; i < vecXmlElements.size(); i++) {
1362 if (vecXmlElements.get(i).toString().equalsIgnoreCase(
1363 "importDefinition"))
1364 iLastImportDefinition = i;
1365 }
1366 jdbcParametersElement.parseTargetJDBCParameters(inStream);
1367 DBConnectionManager connManager = new DBConnectionManager(
1368 jdbcParametersElement.getTargetConnections());
1369 Connection connToPools = null;
1370
1371 try {
1372 this.isDefaultJdbc = jdbcParametersElement
1373 .parseImportJDBCDefaultParameters(inStream);
1374
1375 if (this.strVendorFileName != null
1376 && !this.strVendorFileName.equals(""))
1377 configReaderTarget.setVendorFileName(this.strVendorFileName);
1378 // this can be erased!!!?
1379 configReaderTarget.readConfigValues(jdbcParametersElement
1380 .getTargetDBVendor(), jdbcParametersElement
1381 .getTargetDriverName(), "target");
1382 this.currentOidColumnName = configReaderTarget.getOidColumnName();
1383 this.currentVersionColumnName = configReaderTarget
1384 .getVersionColumnName();
1385
1386 if (jdbcParametersElement.getJDBCTargetParameterDriver().equals("")
1387 || jdbcParametersElement.getJDBCTargetParameterDriver() == null)
1388 jdbcParametersElement
1389 .setJDBCTargetParameterDriver(configReaderTarget
1390 .getDriverClassName());
1391 Class.forName(jdbcParametersElement.getJDBCTargetParameterDriver());
1392
1393 int iImport = 0;
1394 int iCopy = 0;
1395 int iSql = 0;
1396 int iEcho = 0;
1397 // main loop
1398 for (int l = 0; l < (iImportJobs + iCopyTable + iSqlTags + iEchoElements); l++) {
1399 Object tempLogMode = this.logModes.get(l);
1400 if (tempLogMode != null && !tempLogMode.equals(""))
1401 this.logger.setEnabledLogLevels(tempLogMode.toString());
1402 else
1403 this.logger.setEnabledLogLevels(loaderJobReader
1404 .getDefaultLogMode());
1405 // reset global variables
1406 this.resetGlobalVariables();
1407 relationsCache.resetRelationsCache();
1408 checkRowCache.resetCheckRowCache();
1409 // if
1410 // (!importDefinitionElement.strLogMode.equalsIgnoreCase("none"))
1411 // {
1412 this.logger.write("normal", "\nImport job No. "
1413 + (iImport + iCopy + iSql + 1) + " is started.");
1414 // }
1415
1416 if (vecXmlElements.get(l).toString().equalsIgnoreCase(
1417 "importDefinition")) {
1418 this.logger.write("full",
1419 "Importing and parsing XML file is started.");
1420 // importing specific jdbc parameters if any exist
1421 this.parseAndImport(inStream, iImport, true);
1422 jdbcParametersElement.parseImportJDBCParameters(inStream,
1423 iImport + 1, "importDefinition");
1424
1425 configReaderSource.readConfigValues(jdbcParametersElement
1426 .getDbVendor(), jdbcParametersElement
1427 .getDriverName(), "source");
1428 configReaderTarget.readConfigValues(jdbcParametersElement
1429 .getTargetDBVendor(), jdbcParametersElement
1430 .getTargetDriverName(), "target");
1431 // validStmt.setConfigReader(configReaderSource);
1432 this.currentOidColumnName = configReaderTarget
1433 .getOidColumnName();
1434 this.currentVersionColumnName = configReaderTarget
1435 .getVersionColumnName();
1436
1437 }
1438 // rale 24.10.2003
1439 else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
1440 "copyTable")) {
1441 this.logger.write("full",
1442 "Importing and parsing XML file is started.");
1443 this.parseAndImport(inStream, iCopy, false);
1444 // this.logger.setEnabledLogLevels(importDefinitionElement.strCopyTableLogMode);
1445 jdbcParametersElement.parseImportJDBCParameters(inStream,
1446 iCopy + 1, "copyTable");
1447
1448 configReaderSource.readConfigValues(jdbcParametersElement
1449 .getDbVendor(), jdbcParametersElement
1450 .getDriverName(), "source");
1451 configReaderTarget.readConfigValues(jdbcParametersElement
1452 .getTargetDBVendor(), jdbcParametersElement
1453 .getTargetDriverName(), "target");
1454 this.currentOidColumnName = configReaderTarget
1455 .getOidColumnName();
1456 this.currentVersionColumnName = configReaderTarget
1457 .getVersionColumnName();
1458 } else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
1459 "sql")) {
1460 configReaderTarget.readConfigValues(jdbcParametersElement
1461 .getTargetDBVendor(), jdbcParametersElement
1462 .getTargetDriverName(), "target");
1463
1464 this.currentOidColumnName = configReaderTarget
1465 .getOidColumnName();
1466 this.currentVersionColumnName = configReaderTarget
1467 .getVersionColumnName();
1468
1469 // this don't send enything to logger (importSQLStatement)
1470 this.logger.write("full",
1471 "Importing and parsing XML file is started.");
1472 this.vecSqlStmt = sqlElement.importSQLStatement(inStream,
1473 iSql);
1474 // defining the log mode
1475 // if (!sqlElement.getSqlLogMode().equals("") &&
1476 // sqlElement.getSqlLogMode() != null)
1477 // this.logger.setEnabledLogLevels(sqlElement.getSqlLogMode());
1478 // else
1479 // this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
1480
1481 // importing specific jdbc parameters if any exist
1482 this.logger.write("full",
1483 "Importing and parsing XML file is started.");
1484 jdbcParametersElement.parseImportJDBCParameters(inStream,
1485 iSql + 1, "sql");
1486 }
1487 if (vecXmlElements.get(l).toString().equalsIgnoreCase(
1488 "importDefinition")
1489 || vecXmlElements.get(l).toString().equalsIgnoreCase(
1490 "sql")
1491 || vecXmlElements.get(l).toString().equalsIgnoreCase(
1492 "copyTable")) {
1493
1494 if (jdbcParametersElement.getJDBCSourceParameterDriver()
1495 .equals("")
1496 || jdbcParametersElement
1497 .getJDBCSourceParameterDriver() == null)
1498 jdbcParametersElement
1499 .setJDBCSourceParameterDriver(configReaderSource
1500 .getDriverClassName());
1501
1502 if (jdbcParametersElement.getJDBCTargetParameterDriver()
1503 .equals("")
1504 || jdbcParametersElement
1505 .getJDBCTargetParameterDriver() == null)
1506 jdbcParametersElement
1507 .setJDBCTargetParameterDriver(configReaderTarget
1508 .getDriverClassName());
1509 }
1510 this.logger.write("full",
1511 "Importing and parsing XML file is finished.");
1512
1513 connManager.setLoaderJobPath(this.strLoaderJobFileName);
1514 connManager.setConnectionPrefix(configReaderTarget
1515 .getConnectionPrefix());
1516 connManager.setParsePermission(configReaderTarget
1517 .getFileSystemDatabase());
1518
1519 try {
1520 connToPools = connManager
1521 .getConnection(jdbcParametersElement
1522 .getJDBCTargetParameterConnection());
1523 // TODO ZK 17.6 2004. This make problem with Excel
1524 // jdbc-odbc.
1525 connToPools.setAutoCommit(false);
1526 } catch (Exception ex) {
1527 String message = "Can't get connection to Target Database."
1528 + "\n"
1529 + "Maybe connection "
1530 + jdbcParametersElement
1531 .getJDBCTargetParameterConnection()
1532 + " is wrong. ";
1533 LoaderException le = new LoaderException("SQLException: "
1534 + message + "\n" + ex.getMessage() + "\n",
1535 (Throwable) ex);
1536 this.logger.write("full", le.getStackTraceAsString());
1537 throw le;
1538 }
1539 if (vecXmlElements.get(l).toString().equalsIgnoreCase(
1540 "importDefinition")) {
1541 if (importDefinitionElement.bRestartAutoCreate == true) {
1542 dataTransmition.createRestartCounterTable(connToPools);
1543 }
1544 this.currentJobName = "importDefinition";
1545 String importName = importDefinitionElement.strImportDefinitionName;
1546 boolean doJob = true;
1547 for (int i = 0; i < this.includeTables.size(); i++) {
1548 if (importName.equalsIgnoreCase(this.includeTables.get(
1549 i).toString())) {
1550 doJob = true;
1551 break;
1552 } else {
1553 doJob = false;
1554 }
1555 }
1556 if (doJob) {
1557 try {
1558 this.loadSource(connToPools);
1559
1560 } catch (Exception ex) {
1561 // this.logger.write("normal", "\t" +
1562 // ex.getMessage().toString());
1563 LoaderException le = new LoaderException(
1564 "SQLException: ", (Throwable) ex);
1565 this.logger.write("full", le
1566 .getStackTraceAsString());
1567 if (importDefinitionElement.strOnErrorContinueXml
1568 .equalsIgnoreCase("true")) {
1569 this.logger
1570 .write(
1571 "normal",
1572 "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'");
1573 } else {
1574 this.logger
1575 .write(
1576 "normal",
1577 "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'");
1578 connManager.release("true");
1579 throw le;
1580 }
1581 }
1582 // release resources
1583 finally {
1584 for (int i = 0; i < pstmtForInsert.size(); i++) {
1585 String key = pstmtKeys.get(i).toString();
1586 PreparedStatement pstmt = (PreparedStatement) pstmtForInsert
1587 .get(key);
1588 pstmt.close();
1589 }
1590 pstmtKeys.clear();
1591 pstmtForInsert.clear();
1592 // release transformations
1593 List transformations = this.transformations
1594 .getTransformations();
1595 for (int iCount = 0; iCount < transformations
1596 .size(); iCount++) {
1597 ((Transformation) transformations.get(iCount))
1598 .release();
1599 }
1600 }
1601 } else
1602 this.logger.write("normal", "\tImportDefinition "
1603 + importName + " is excluded from process");
1604 // this.logger.setEnabledLogLevels("none");
1605 iImport++;
1606 }
1607 // rale 24.10.2003
1608 else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
1609 "copyTable")) {
1610 if (importDefinitionElement.bRestartAutoCreate == true) {
1611 dataTransmition.createRestartCounterTable(connToPools);
1612 }
1613 this.currentJobName = "copyTable";
1614 String importName = importDefinitionElement.strCopyTableName;
1615 boolean doJob = true;
1616 for (int i = 0; i < this.includeTables.size(); i++) {
1617 if (importName.equalsIgnoreCase(this.includeTables.get(
1618 i).toString())) {
1619 doJob = true;
1620 break;
1621 } else {
1622 doJob = false;
1623 }
1624 }
1625 if (doJob) {
1626 try {
1627 this.loadSourceCT(connToPools);
1628 } catch (Exception e) {
1629 // this.logger.write("normal", "\t" +
1630 // e.getMessage());
1631 LoaderException le = new LoaderException(
1632 "SQLException: ", (Throwable) e);
1633 this.logger.write("full", le
1634 .getStackTraceAsString());
1635 if (importDefinitionElement.strCopyTableOnErrorContinue
1636 .equalsIgnoreCase("true")) {
1637 this.logger
1638 .write(
1639 "normal",
1640 "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'");
1641 } else {
1642 this.logger
1643 .write(
1644 "normal",
1645 "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'");
1646 connManager.release("true");
1647 throw le;
1648 }
1649 }
1650 } else {
1651 this.logger.write("normal", "\tCopyTable " + importName
1652 + " is excluded from process");
1653 }
1654 // this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
1655 iCopy++;
1656 } else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
1657 "echo")) {
1658 this.currentJobName = "echo";
1659 logger.writeEcho(this.logger.getMessage(new Integer(iEcho)
1660 .toString()));
1661 iEcho++;
1662 } else if (vecXmlElements.get(l).toString().equalsIgnoreCase(
1663 "sql")) {
1664 this.currentJobName = "sql";
1665 String sqlName = sqlElement.getSqlName();
1666 boolean doJob = true;
1667 for (int i = 0; i < this.includeTables.size(); i++) {
1668 if (sqlName.equalsIgnoreCase(this.includeTables.get(i)
1669 .toString())) {
1670 doJob = true;
1671 break;
1672 } else {
1673 doJob = false;
1674 }
1675 }
1676 if (doJob) {
1677 try {
1678 if (sqlElement.getSqlCommit().equalsIgnoreCase(
1679 "true")) {
1680 connToPools.setAutoCommit(true);
1681 // ZK change this because of problems with
1682 // onErrorContinue="true" and commit="true" in
1683 // <sql ...> tag
1684 try {
1685 this.executeSQLStatement(connToPools);
1686 } catch (Exception e) {
1687 throw e;
1688 } finally {
1689 connToPools.setAutoCommit(false);
1690 }
1691 } else
1692 this.executeSQLStatement(connToPools);
1693 } catch (Exception e) {
1694 LoaderException le = new LoaderException(
1695 "SQLException: ", (Throwable) e);
1696 // this.logger.write("normal", "\t" +
1697 // e.getMessage());
1698 this.logger.write("full", le
1699 .getStackTraceAsString());
1700 if (sqlElement.getSqlOnErrorContinue()
1701 .equalsIgnoreCase("true")) {
1702 this.logger
1703 .write(
1704 "normal",
1705 "\tError : Because OnErrorContinue Attribute is true application is not terminated");
1706 } else if (sqlElement.getSqlOnErrorContinue()
1707 .equalsIgnoreCase("")
1708 && loaderJobReader
1709 .getDefaultOnErrorContinue() == true) {
1710
1711 this.logger
1712 .write(
1713 "normal",
1714 "\tError : Because OnErrorContinue Attribute is true application is not terminated");
1715 } else {
1716 this.logger
1717 .write(
1718 "normal",
1719 "\tError : Because OnErrorContinue Attribute is false application is terminated");
1720 connManager.release("true");
1721 throw le;
1722 }
1723 }
1724 } else {
1725 this.logger.write("normal", "\tSql statement "
1726 + sqlName + " is excluded from process");
1727 }
1728 iSql++;
1729 // this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode());
1730 } else {
1731 // this.logger.write("normal",
1732 // "Error : Loader supports loading data up to maximum 3 SQL
1733 // database");
1734 LoaderException le = new LoaderException(
1735 "SQLException: ",
1736 (Throwable) (new SQLException(
1737 "Error : Loader supports loading data up to maximum 3 SQL database")));
1738 this.logger.write("full", le.getStackTraceAsString());
1739 if (connToPools != null)
1740 connManager.release("true");
1741 throw le;
1742 }
1743
1744 if (!this.hasRestartCounter && iLastImportDefinition == l) {
1745 if (connToPools != null && !connToPools.isClosed())
1746
1747 connToPools.commit();
1748 }
1749
1750 }
1751 this.logger.setEnabledLogLevels(this.defaultLogMode);
1752 connManager.release("false");
1753 this.logger.write("normal", "All rows are commited.");
1754 this.logger.write("normal", "Application is finished.");
1755 this.logger.write("normal", "All jobs duration: "
1756 + this.timeCounter.getTotalTime());
1757 } catch (Exception e) {
1758 LoaderException le = new LoaderException("Exception: ",
1759 (Throwable) e);
1760 // this.logger.write("normal", le.getCause().toString());
1761 this.logger.write("full", le.getStackTraceAsString());
1762 throw le;
1763 } finally {
1764 try {
1765 if (connToPools != null && !connToPools.isClosed())
1766 connToPools.close();
1767 this.logger.close();
1768 } catch (SQLException e) {
1769 LoaderException le = new LoaderException("SQLException: ",
1770 (Throwable) e);
1771 // this.logger.write("normal", le.getCause().toString());
1772 this.logger.write("full", le.getStackTraceAsString());
1773 throw le;
1774 }
1775 }
1776 }
1777
1778 /***
1779 * Method loadSourceCT is used to load data from the source table (Csv,
1780 * MySql, MsSql, Exel...) into target tables.
1781 *
1782 * @param connTarget
1783 * is connection object to target database
1784 * @throws java.lang.Exception
1785 */
1786 private void loadSourceCT(Connection connTarget) throws Exception {
1787
1788 this.timeCounter.setStartJobTime();
1789 DateFormat dfNow = DateFormat.getDateTimeInstance();
1790 Date currentDate = new Date();
1791
1792 this.logger.write("full", "\tloadSourceCT method is started.");
1793 this.logger.write("normal", "Copy Table "
1794 + importDefinitionElement.strCopyTableName + " is started at "
1795 + dfNow.format(currentDate) + ".");
1796
1797 Connection connSource = null;
1798 ResultSet rsetSource = null;
1799 ResultSet rsetTarget = null;
1800 Statement stmtSource = null;
1801 Statement stmtTarget = null;
1802 String logStatement = "";
1803 String strQuery = "";
1804 Vector vecNewColumnNames = new Vector();
1805 Vector vecNewColumnTypes = new Vector();
1806 Hashtable tmpColumnReader = new Hashtable();
1807
1808 boolean bOidLogicCurrentTable = new Boolean(
1809 importDefinitionElement.strCopyTableOidLogic).booleanValue();
1810 boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
1811 .equals("") || importDefinitionElement.strObjectIDNameColumnValue
1812 .equals(""));
1813 try {
1814 this.checkOidLogic(connTarget);
1815 if (configReaderSource.getRequiredUser()) {
1816 if (jdbcParametersElement.getJDBCSourceParameterUser().equals(
1817 ""))
1818 this.inputUser(true);
1819 Class.forName(jdbcParametersElement
1820 .getJDBCSourceParameterDriver());
1821 connSource = DriverManager.getConnection(jdbcParametersElement
1822 .getJDBCSourceParameterConnection(),
1823 jdbcParametersElement.getJDBCSourceParameterUser(),
1824 jdbcParametersElement.getJDBCSourceParameterPassword());
1825 } else {
1826 Class.forName(jdbcParametersElement
1827 .getJDBCSourceParameterDriver());
1828 connSource = DriverManager.getConnection(jdbcParametersElement
1829 .getJDBCSourceParameterConnection());
1830 }
1831
1832 int iRowNumber = 0;
1833 boolean isEndFlag = false;
1834 stmtSource = connSource.createStatement();
1835 stmtTarget = connTarget.createStatement();
1836
1837 // setCursorName
1838 boolean setCursorName = false;
1839 if (!importDefinitionElement.setCursorNameCT.equalsIgnoreCase(""))
1840 setCursorName = new Boolean(
1841 importDefinitionElement.setCursorNameCT).booleanValue();
1842 else
1843 setCursorName = configReaderSource.getSetCursorNameEnabled();
1844
1845 if (setCursorName) {
1846 long cursorName = System.currentTimeMillis();
1847 stmtSource.setCursorName(String.valueOf(cursorName));
1848 }
1849 // setFetchSize
1850 boolean setFetchSize = false;
1851 if (!importDefinitionElement.setFetchSizeCT.equalsIgnoreCase(""))
1852 setFetchSize = new Boolean(
1853 importDefinitionElement.setFetchSizeCT).booleanValue();
1854 else
1855 setFetchSize = configReaderSource.getSetFetchSizeEnabled();
1856
1857 if (setFetchSize)
1858 stmtSource
1859 .setFetchSize(importDefinitionElement.iCopyTableCommitCount);
1860 // ZK added this 5.4 2004
1861 // begin
1862 // next line will give me parameter getColumnsSupported from
1863 // *conf.xml. It describe is getColumns() method is suported
1864 // by used driver
1865
1866 boolean columnsSuportedTarget = configReaderTarget
1867 .getColumnsSupported();
1868 boolean columnsSuportedSource = configReaderSource
1869 .getColumnsSupported();
1870
1871 strQuery = "select * from ";
1872
1873 // sourceColumnCount is used out of try block also
1874 rsetSource = stmtSource.executeQuery(strQuery
1875 + importDefinitionElement.strCopyTableSourceTableName);
1876 int sourceColumnCount = rsetSource.getMetaData().getColumnCount();
1877 try {
1878 if (columnsSuportedSource) {
1879 ResultSet rsetSourceTemp = connSource
1880 .getMetaData()
1881 .getColumns(
1882 connSource.getCatalog(),
1883 null,
1884 importDefinitionElement.strCopyTableSourceTableName,
1885 "%");
1886 while (rsetSourceTemp.next()) {
1887 vecNewColumnNames.add(rsetSourceTemp.getString(4));
1888 }
1889 rsetSourceTemp.close();
1890
1891 } else {
1892 // rsetSource and source column count are already maked
1893 // above try block
1894 for (int i = 1; i < sourceColumnCount + 1; i++) {
1895 vecNewColumnNames.add(rsetSource.getMetaData()
1896 .getColumnName(i));
1897 }
1898 }
1899
1900 if (columnsSuportedTarget) {
1901 ResultSet rsetTargetTemp = connTarget
1902 .getMetaData()
1903 .getColumns(
1904 connTarget.getCatalog(),
1905 null,
1906 importDefinitionElement.strCopyTableTargetTableName,
1907 "%");
1908
1909 while (rsetTargetTemp.next()) {
1910 String targetColumnName = rsetTargetTemp.getString(4);
1911 String targetColumnType = rsetTargetTemp.getString(6);
1912 tmpColumnReader.put(targetColumnName.toUpperCase(),
1913 targetColumnType);
1914 }
1915 rsetTargetTemp.close();
1916
1917 } else {
1918 if (configReaderTarget.getMaxRowsSupported()) {
1919 stmtTarget.setMaxRows(1);
1920 }
1921
1922 rsetTarget = stmtTarget
1923 .executeQuery(strQuery
1924 + importDefinitionElement.strCopyTableTargetTableName);
1925 int targetColumnCount = 0;
1926 targetColumnCount = rsetTarget.getMetaData()
1927 .getColumnCount();
1928 for (int i = 1; i < targetColumnCount + 1; i++) {
1929 String targetColumnName = rsetTarget.getMetaData()
1930 .getColumnName(i);
1931 String targetColumnType = rsetTarget.getMetaData()
1932 .getColumnTypeName(i);
1933 tmpColumnReader.put(targetColumnName.toUpperCase(),
1934 targetColumnType);
1935 }
1936 rsetTarget.close();
1937 }
1938
1939 // same for both cases
1940 for (int i = 0; i < vecNewColumnNames.size(); i++) {
1941 String columnName = vecNewColumnNames.get(i).toString()
1942 .toUpperCase();
1943 String tmpTargetColumnType = tmpColumnReader
1944 .get(columnName).toString();
1945 vecNewColumnTypes.add(tmpTargetColumnType);
1946 }
1947
1948 }
1949
1950 catch (Exception ex) {
1951
1952 String msg = "In copy table job '"
1953 + importDefinitionElement.strCopyTableName + "',"
1954 + " Source and Target table are not compatibile.";
1955 Exception e = new Exception(msg + "\n" + ex.getMessage());
1956 throw e;
1957 }
1958
1959 int currentBlock = 0;
1960 int blockNumber = 0;
1961 int bdecRowCount = 0;
1962 int currentVersion = 0;
1963 BigDecimal bdecCounter = new BigDecimal(0);
1964
1965 if (configReaderSource.getRowCountEnabled()) {
1966 String countSQL = "";
1967 try {
1968 // countSQL = " select count(*) as \"counter\" from "
1969 // + importDefinitionElement.strCopyTableName;
1970 countSQL = " select count(*) from "
1971 + importDefinitionElement.strCopyTableName;
1972 Statement stmtSourceCount = connSource.createStatement();
1973 ResultSet rsetSourceCount = stmtSourceCount
1974 .executeQuery(countSQL);
1975 rsetSourceCount.next();
1976 // iRowNumber = rsetSourceCount.getInt("counter");
1977 iRowNumber = rsetSourceCount.getInt(configReaderSource
1978 .getFirstColumnResult());
1979 blockNumber = iRowNumber
1980 / importDefinitionElement.iCopyTableCommitCount + 1;
1981 rsetSourceCount.close();
1982 stmtSourceCount.close();
1983 } catch (Exception e) {
1984 this.logger.write(Logger.LOGMODE_NORMAL,
1985 "Error while execute count sql: " + countSQL);
1986 }
1987 }
1988
1989 boolean main = true;
1990 if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
1991 if (this.hasRestartCounter) {
1992 bdecCounter = dataTransmition.checkDataTransmition(
1993 connTarget, rsetSource, this.currentJobName,
1994 configReaderTarget.getFirstColumnResult());
1995
1996 if (bdecCounter != null) {
1997 if (bdecCounter.toString().equalsIgnoreCase("0")) {
1998 // if is mycounter=0 in myrestart table escape this
1999 // importdefinition
2000 main = false;
2001 }
2002 } else {
2003 bdecCounter = new BigDecimal(0);
2004 }
2005 }
2006 }
2007
2008 while (main) {
2009 // iCopyTableCommitCount (ImportDefinition or default (100))
2010 this.logger.write("normal", "Import block is started.");
2011 currentBlock++;
2012 if (configReaderSource.getRowCountEnabled()) {
2013 this.logger.write("normal", "Working... " + currentBlock
2014 + ". block of " + blockNumber);
2015 } else {
2016 this.logger.write("normal", "Working... " + currentBlock
2017 + ". block");
2018 }
2019 this.logger.write("full", "\tStarted from the "
2020 + bdecCounter.add(new BigDecimal(1)).toString()
2021 + ". row.");
2022 iRowNumber = 0;
2023
2024 QueryInsertRowCt queryInsertRowCt = new QueryInsertRowCt(
2025 bOidLogicCurrentTable, isTOS, vecNewColumnNames,
2026 vecNewColumnTypes,
2027 importDefinitionElement.strCopyTableTargetTableName,
2028 this.bdecOidNumber, this.currentOidColumnName,
2029 this.currentVersionColumnName, configReaderTarget
2030 .getOidDbType(), configReaderTarget
2031 .getVersionDbType(), configReaderTarget
2032 .getJavaTypeMapings());
2033
2034 String pstmtInsert = queryInsertRowCt
2035 .getPreperedStatementForInsert();
2036 PreparedStatement pstmt = connTarget
2037 .prepareStatement(pstmtInsert);
2038
2039 while (iRowNumber < importDefinitionElement.iCopyTableCommitCount) {
2040 if (!rsetSource.next()) {
2041 isEndFlag = true;
2042 break;
2043 }
2044 currentRow = iRowNumber;
2045 if (bOidLogicCurrentTable) {
2046 if (this.bdecOidNumber
2047 .compareTo(this.bdecOidNumber2000) == 0) {
2048 this.checkOidLogic(connTarget);
2049 this.bdecOidNumber = this.bdecOidNumber
2050 .add(new BigDecimal(1));
2051 } else {
2052 this.bdecOidNumber = this.bdecOidNumber
2053 .add(new BigDecimal(1));
2054 }
2055 }
2056 try {
2057 int mnemonic = -1;
2058 String insertForOut = pstmtInsert;
2059 for (int i = 1; i < sourceColumnCount + 1; i++) {
2060 String columnType = vecNewColumnTypes.get(i - 1)
2061 .toString();
2062 String javaType = (String) configReaderTarget
2063 .getJavaTypeMapings().get(
2064 columnType.toUpperCase());
2065
2066 if (javaType == null) {
2067 this.logger.write("normal",
2068 "There is no java type defined for sql type "
2069 + columnType.toUpperCase());
2070 LoaderException le = new LoaderException(
2071 "Exception:", new Exception(
2072 "There is no java type defined for sql type "
2073 + columnType
2074 .toUpperCase()));
2075 this.logger.write("full", le
2076 .getStackTraceAsString());
2077 throw le;
2078 }
2079
2080 int javaTypeInt = Integer.parseInt(javaType);
2081 if (javaTypeInt == 1) {
2082 byte[] isBlob = rsetSource.getBytes(i);
2083 if (isBlob == null || isBlob.length == 0) {
2084 pstmt.setBytes(i, null);
2085 mnemonic = insertForOut.indexOf("?");
2086 insertForOut = insertForOut.substring(0,
2087 mnemonic)
2088 + "BinaryObject(null)"
2089 + insertForOut
2090 .substring(mnemonic + 1);
2091 } else {
2092 ByteArrayInputStream bais = new ByteArrayInputStream(
2093 isBlob);
2094 // TODO see how to solve this on general
2095 // way,best to make configurable which
2096 // method will be called
2097 pstmt.setBytes(i, isBlob);
2098 // pstmt.setBinaryStream(i,bais,isBlob.length);
2099
2100 mnemonic = insertForOut.indexOf("?");
2101 insertForOut = insertForOut.substring(0,
2102 mnemonic)
2103 + "BinaryObject"
2104 + insertForOut
2105 .substring(mnemonic + 1);
2106 }
2107 } else {
2108 String value = rsetSource.getString(i);
2109 if (value == null)
2110 value = "null";
2111 if (bReplaceInData)
2112 value = this.replaceInData(value);
2113
2114 this.setValueOnStatement(value, javaTypeInt, i,
2115 pstmt);
2116
2117 mnemonic = insertForOut.indexOf("?");
2118 insertForOut = insertForOut.substring(0,
2119 mnemonic)
2120 + value
2121 + insertForOut.substring(mnemonic + 1);
2122
2123 } // end of main else
2124 } // end of for loop
2125 logStatement = insertForOut;
2126 this.logger.write("full", "\tQuery '" + insertForOut
2127 + "' will be executed");
2128 pstmt.executeUpdate();
2129 pstmt.clearParameters();
2130 } catch (Exception ex) {
2131 if (importDefinitionElement.strCopyTableOnErrorContinue
2132 .equalsIgnoreCase("true")) {
2133 dataCleaning
2134 .cleaningInsert(
2135 importDefinitionElement.strCopyTableTargetTableName,
2136 connTarget, currentRow, "INSERT",
2137 ex.getMessage(), "COPY TABLE",
2138 logStatement);
2139 } else {
2140 throw ex;
2141 }
2142 }
2143 this.logger
2144 .write("full", "\tinsertRow method is finished.");
2145 iRowNumber++;
2146 } // iRowNumber <
2147 // importDefinitionElement.iCopyTableCommitCount
2148
2149 // restart counter table
2150 if (!importDefinitionElement.strRestartCounterTableName
2151 .equals("")) {
2152 if (this.hasRestartCounter) {
2153 bdecCounter = bdecCounter
2154 .add(new BigDecimal(iRowNumber));
2155 dataTransmition.insertCounter(this.currentJobName,
2156 bdecCounter, connTarget);
2157 }
2158 }
2159 if (this.hasRestartCounter) {
2160
2161 connTarget.commit();
2162 this.logger.write("normal", "Imported block is commited.");
2163 this.logger.write("full", Integer.toString(iRowNumber)
2164 + " rows are commited.");
2165 }
2166
2167 iRowNumber = 0;
2168 if (isEndFlag) {
2169 break;
2170 }
2171 pstmt.close();
2172 } // while(true)
2173
2174 strQuery = "";
2175 rsetSource.close();
2176 // rsetTarget.close();
2177 stmtSource.close();
2178 stmtTarget.close();
2179 if (!connSource.isClosed())
2180 connSource.close();
2181
2182 // seting mycounter=0 in myrestart table (success)
2183 if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
2184 if (this.hasRestartCounter) {
2185 dataTransmition.resetRestartCounter(connTarget,
2186 this.currentJobName);
2187 }
2188 }
2189 currentDate = new Date();
2190 dfNow = DateFormat.getDateTimeInstance();
2191 this.logger.write("normal", "Copy table "
2192 + importDefinitionElement.strCopyTableName
2193 + " is finished at " + dfNow.format(currentDate) + ".");
2194 this.logger.write("normal", " Duration of copyTable:"
2195 + this.timeCounter.getJobTime());
2196 } catch (Exception e) {
2197 throw e;
2198 }
2199 }
2200
2201 /***
2202 * Method loadSource is used to load data from the source table (Csv, MySql,
2203 * MsSql, Exel...) into target tables. This method uses configuration file
2204 * OctopusDbVendors.xml. Loading parameters are set in XML file. During
2205 * loading, load status is printed on the screen and also put into log file.
2206 * This method is used for loading data by rules which is defined in a
2207 * single importDefinition. If there is an error Exception "LoaderException"
2208 * is thrown.
2209 *
2210 * @param connTarget
2211 * represents connection of target table.
2212 * @throws LoaderException
2213 */
2214 private void loadSource(Connection connTarget) throws LoaderException {
2215 int iRowNumber = 0;
2216 BigDecimal bdecCounter = new BigDecimal(0);
2217 BigDecimal k = new BigDecimal(0);
2218 Date currentDate = new Date();
2219 DateFormat dfNow = DateFormat.getDateTimeInstance();
2220 boolean columnsSuportedTarget = configReaderTarget
2221 .getColumnsSupported();
2222 this.timeCounter.setStartJobTime();
2223 this.logger.write("full", "\tloadSource method is started.");
2224 this.logger.write("normal", "Import definition "
2225 + importDefinitionElement.strImportDefinitionName
2226 + " is started at " + dfNow.format(currentDate) + ".");
2227 Connection connSource = null;
2228
2229 try {
2230
2231 for (int i = 0; i < this.iTables; i++) {
2232 this.counterColumns.setTargetColumnStartValues(
2233 this.vecTableTableName.get(i).toString(),
2234 this.vecTableTableID.get(i).toString(), connTarget,
2235 this.iTargetFirstColumnResult);
2236 this.counterColumns.counterColumnTypes(this.vecTableTableName
2237 .get(i).toString(), this.vecTableTableID.get(i)
2238 .toString(), connTarget, this.iTargetFirstColumnResult,
2239 columnsSuportedTarget, configReaderTarget);
2240
2241 }
2242
2243 // source
2244 if (configReaderSource.getRequiredUser()) {
2245 if (jdbcParametersElement.getJDBCSourceParameterUser().equals(
2246 ""))
2247 this.inputUser(true);
2248 Class.forName(jdbcParametersElement
2249 .getJDBCSourceParameterDriver());
2250 connSource = DriverManager.getConnection(jdbcParametersElement
2251 .getJDBCSourceParameterConnection(),
2252 jdbcParametersElement.getJDBCSourceParameterUser(),
2253 jdbcParametersElement.getJDBCSourceParameterPassword());
2254
2255 } else {
2256 Class.forName(jdbcParametersElement
2257 .getJDBCSourceParameterDriver());
2258 connSource = DriverManager.getConnection(jdbcParametersElement
2259 .getJDBCSourceParameterConnection());
2260 }
2261
2262 Statement stmtSource = null;
2263 stmtSource = connSource.createStatement();
2264
2265 // target
2266 if (importDefinitionElement.bObjectIDAutoCreate == true) {
2267 createObjectIDTable(connTarget);
2268 connTarget.commit();
2269 }
2270 // Statement stmtTarget = connTarget.createStatement();
2271
2272 this.constantColumnTypes(connTarget);
2273 this.targetColumnTypes(connTarget);
2274 this.checkOidLogic(connTarget);
2275
2276 int currentBlock = 0;
2277 String strQueryWhere = "";
2278
2279 for (int i = 0; i < this.iTables; i++) {
2280 // ZK added 18.5.2004
2281 // QueryTransformationSet queryTransformationSet = null;
2282 // this.indexDTransformationOver = new Hashtable();
2283 // this.indexDTransformationOver = new Hashtable();
2284 // this.updateTransformationStatement = new Hashtable();
2285 // // end
2286 // ZK added this for transformations - 27.04.2004.
2287 ArrayList trans = this.transformations.getTransformations();
2288 Iterator iTrans = trans.iterator();
2289
2290 while (iTrans.hasNext()) {
2291 Transformation temp = (Transformation) iTrans.next();
2292
2293 // temp.setTargetParameters(this.vecTableTableName.get(i).toString(),this.vecTableTableID.get(i).toString());
2294 temp.transformationColumnTypes(connTarget,
2295 this.iTargetFirstColumnResult,
2296 columnsSuportedTarget, configReaderTarget);
2297
2298 }
2299 // end
2300 // ZK added this for transormations
2301 Vector pomTypes;
2302 Vector pomNames;
2303 Vector pomValueModes;
2304 Vector targetKeyColumnNames;
2305 Vector targetColumnNames;
2306 Vector targetColumnTypes;
2307 targetColumnNames = new Vector();
2308 targetKeyColumnNames = new Vector();
2309 Vector targetValueModes = new Vector();
2310 targetColumnTypes = new Vector();
2311 pomNames = new Vector();
2312 pomTypes = new Vector();
2313 pomValueModes = new Vector();
2314
2315 String tableId = this.vecTableTableID.get(i).toString();
2316 ArrayList transTableIDs = this.transformations
2317 .getTransformationsTableIDs();
2318 if (transTableIDs.contains(tableId)) {
2319
2320 for (int j = 0; j < trans.size(); j++) {
2321 Transformation pom = (Transformation) trans.get(j);
2322 targetColumnNames = pom.getTargetColumnNames(i);
2323 targetColumnTypes = pom.getTargetColumnTypes(i);
2324 targetKeyColumnNames = pom.getTargetKeyColumnNames(i);
2325 targetValueModes = pom.getTargetValueModes(i);
2326
2327 for (int o = 0; o < targetColumnTypes.size(); o++) {
2328 pomTypes.add(targetColumnTypes.get(o).toString());
2329 }
2330 for (int o = 0; o < targetColumnNames.size(); o++) {
2331 pomNames.add(targetColumnNames.get(o).toString());
2332 }
2333 for (int o = 0; o < targetValueModes.size(); o++) {
2334 pomValueModes.add(targetValueModes.get(o)
2335 .toString());
2336 }
2337 }
2338
2339 }
2340
2341 this.transformationsColumnTypes.add(pomTypes);
2342 this.transformationsColumnNames.add(pomNames);
2343 this.transformationsValueModes.add(pomValueModes);
2344 // end
2345 boolean bOidLogicCurrentTable = new Boolean(
2346 this.vecTableOidLogic.get(i).toString()).booleanValue();
2347 boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
2348 .equals("") || importDefinitionElement.strObjectIDNameColumnValue
2349 .equals(""));
2350 boolean oid = false;
2351 if (bOidLogicCurrentTable && !isTOS)
2352 oid = true;
2353
2354 // source column data which are not maped to targetdatabase
2355 LoadAllSourceData allSourceData = null;
2356 Vector vecRelationColumns = this.vecRelationColumnTargetColumnName;
2357 Vector vecVariableColumns = this.vecVariableColumnTargetColumnName;
2358 Vector vecConstantColumns = (Vector) this.vecConstantTargetColumnName
2359 .get(i);
2360
2361 Vector vecUseIDColumns = this.vecVariableUseIDColumnName;
2362 Vector vecTimesColumns = this.vecVariableTimesColumnName;
2363
2364 String ctAutoMapColumns = this.vecCTAutoMapp.get(i).toString();
2365 String ctDefaultMode = this.vecCTDefaultMode.get(i).toString();
2366 String sourceTableName = importDefinitionElement.strImportDefinitionTableName;
2367 // ZK change this. Added new parameter columnsSuportedTarget.
2368
2369 if (ctAutoMapColumns.equalsIgnoreCase("true")) {
2370 allSourceData = new LoadAllSourceData(connSource,
2371 sourceTableName, ImportDefinitionSourceColumnName,
2372 vecTableTableName.get(i).toString(), connTarget,
2373 logger, vecRelationColumns, vecVariableColumns,
2374 vecConstantColumns, vecUseIDColumns,
2375 vecTimesColumns, columnsSuportedTarget,
2376 configReaderTarget);
2377 } else {
2378 // stmtTarget.close();
2379 }
2380
2381 // source column data which are not maped to targetdatabase
2382 if (allSourceData != null) {
2383 String keySource = String.valueOf(i);
2384 allSourceColumnNameNoMap.put(keySource, allSourceData
2385 .getNoMapSourceColumnName());
2386 allSourceColumnTypeNoMap.put(keySource, allSourceData
2387 .getNoMapSourceColumnType());
2388 allSourceColumnValueNoMap.put(keySource, allSourceData
2389 .getNoMapSourceColumnValue());
2390 }
2391
2392 // set new column names, column types and value modes for column
2393 // which are not maped in to
2394 // target columns
2395 if (allSourceData != null) {
2396 if (allSourceData.getNoMapSourceColumnName().size() > 0) {
2397 for (int o = 0; o < allSourceData
2398 .getNoMapSourceColumnName().size(); o++) {
2399 ((Vector) this.vecTargetColumnName.get(i))
2400 .add(allSourceData
2401 .getNoMapSourceColumnName().get(o)
2402 .toString());
2403 ((Vector) this.vecSourceColumnName.get(i))
2404 .add(allSourceData
2405 .getNoMapSourceColumnName().get(o)
2406 .toString());
2407 ((Vector) this.vecToHex.get(i)).add("");
2408 ((Vector) this.vecFromHex.get(i)).add("");
2409 ((Vector) this.vecDefaultValue.get(i)).add("");
2410 }
2411 int map = Integer
2412 .parseInt(this.vecValueColumnsTargetTables.get(
2413 i).toString());
2414 int noMap = allSourceData.getNoMapSourceColumnName()
2415 .size();
2416 int all = map + noMap;
2417 this.vecValueColumnsTargetTables.set(i,
2418 new Integer(all));
2419 }
2420 }
2421 if (allSourceData != null) {
2422 if (allSourceData.getNoMapSourceColumnName().size() > 0) {
2423 for (int o = 0; o < allSourceData
2424 .getNoMapSourceColumnName().size(); o++) {
2425 ((Vector) this.vecValueMode.get(i))
2426 .add(ctDefaultMode);
2427 }
2428 }
2429 }
2430 if (allSourceData != null) {
2431 if (allSourceData.getNoMapSourceColumnType().size() > 0) {
2432 for (int o = 0; o < allSourceData
2433 .getNoMapSourceColumnType().size(); o++) {
2434 ((Vector) this.vecTargetColumnType.get(i))
2435 .add(allSourceData
2436 .getNoMapSourceColumnType().get(o)
2437 .toString());
2438 }
2439 }
2440 }
2441
2442 Vector vecColumnNames = (Vector) this.vecTargetColumnName
2443 .get(i);
2444 Vector vecColumnTypes = (Vector) this.vecTargetColumnType
2445 .get(i);
2446 Vector vecValueModes = (Vector) this.vecValueMode.get(i);
2447
2448 // set query statement
2449 QuerySet querySet = new QuerySet(i, bOidLogicCurrentTable,
2450 isTOS, vecColumnNames, vecTableTableName,
2451 this.currentOidColumnName,
2452 this.currentVersionColumnName);
2453
2454 // set query where statement
2455 queryWhereSet = new QueryWhereSet(vecColumnNames,
2456 vecColumnTypes, vecTableTableName.get(i).toString(),
2457 vecTableTableID.get(i).toString());
2458
2459 // set query update statement
2460 QueryUpdateSet queryUpdateSet = new QueryUpdateSet(
2461 vecColumnNames, vecColumnTypes, vecValueModes,
2462 vecTableTableName.get(i).toString(), oid,
2463 this.currentVersionColumnName, configReaderTarget);
2464
2465 if (((Vector) this.vecTargetKeyColumnName.get(i)).size() > 0)
2466 // ZK change this 7.5.2004. Because of new parameter in
2467 // getKeyColumns
2468 queryWhereSet.getKeyColumns(
2469 (Vector) this.vecTargetKeyColumnName.get(i),
2470 configReaderTarget);
2471
2472 // //ZK added this for transformations
2473 if (targetKeyColumnNames.size() > 0)
2474 queryWhereSet.getTransformationKeyColumns(
2475 targetColumnNames, targetKeyColumnNames,
2476 targetColumnTypes, configReaderTarget);
2477 // //ZK end
2478
2479 if (((Vector) this.vecRelationKeyColumns.get(i)).size() > 0)
2480 queryWhereSet.getRelationKeyColumns(
2481 (Vector) vecRelationKeyColumns.get(i),
2482 iRelationColumns, vecRelationColumnTargetTableName,
2483 vecRelationColumnTargetTableID,
2484 vecRelationColumnTargetColumnName,
2485 // TODO zoran, try this change, vecRelationKeyTypes
2486 // to (Vector)vecRelationKeyTypes.get(i)
2487 (Vector) vecRelationKeyTypes.get(i),
2488 configReaderTarget);
2489 if (((Vector) this.vecConstantTargetColumnName.get(i)).size() > 0)
2490 queryWhereSet.getConstantKeyColumns(
2491 (Vector) this.vecConstantTargetColumnName.get(i),
2492 (Vector) this.vecConstantValueMode.get(i),
2493 (Vector) this.vecConstantColumnType.get(i),
2494 configReaderTarget);
2495
2496 if (vecVariableColumnTargetTableName.size() > 0)
2497 queryWhereSet.getVariableKeyColumns(
2498 vecVariableColumnTargetTableName,
2499 vecVariableColumnTargetTableID,
2500 vecVariableColumnValueMode, vecVariableName,
2501 vecVariableColumnName,
2502 vecVariableColumnTargetColumnName,
2503 vecVariableColumnTypes, logger, configReaderTarget);
2504 // set insert row
2505
2506 InsertRowQuerySet insertRowQuerySet = new InsertRowQuerySet(
2507 connTarget, (Vector) this.vecTargetColumnName.get(i),
2508 (Vector) this.vecValueMode.get(i), vecTableTableName
2509 .get(i).toString(), vecTableTableID.get(i)
2510 .toString(), i,
2511 (Vector) this.vecConstantTargetColumnName.get(i),
2512 vecVariableTimesTableName, vecVariableTimesTableID,
2513 vecVariableTimesColumnName,
2514 vecVariableColumnTargetTableName,
2515 vecVariableColumnTargetTableID,
2516 vecVariableColumnTargetColumnName,
2517 vecRelationColumnTargetColumnName,
2518 vecRelationColumnTargetTableName,
2519 vecRelationColumnTargetTableID,
2520 vecRelationColumnRelationMode, counterColumns,
2521 transformations, bOidLogicCurrentTable, isTOS,
2522 this.currentOidColumnName,
2523 this.currentVersionColumnName);
2524
2525 // set query constant statement
2526 if (((Vector) this.vecConstantTargetColumnName.get(i)).size() > 0)
2527 queryConstantSet = new QueryConstantSet(vecTableTableName
2528 .get(i).toString(),
2529 (Vector) this.vecConstantTargetColumnName.get(i),
2530 (Vector) this.vecConstantValueMode.get(i),
2531 (Vector) this.vecConstantColumnType.get(i),
2532 configReaderTarget);
2533 strQuerySet = querySet.getQuerySet();
2534 strQueryWhere = queryWhereSet.getQueryWhere();
2535
2536 if (!(strQueryWhere.length() < 8)) {
2537 strQueryWhere = strQueryWhere.substring(0, strQueryWhere
2538 .length() - 4);
2539 } else {
2540 strQueryWhere = "";
2541 }
2542
2543 if ((((Vector) this.transformationsColumnNames).size() > 0))
2544 queryTransformationSet = new QueryTransformationSet(
2545 vecTableTableName.get(i).toString(),
2546 (Vector) this.transformationsColumnNames.get(i),
2547 (Vector) this.transformationsValueModes.get(i),
2548 (Vector) this.transformationsColumnTypes.get(i),
2549 configReaderTarget);
2550
2551 // } //querySet+queryWhere
2552 String strQueryTarget = strQuerySet + strQueryWhere;
2553 String key = String.valueOf(i);
2554 Vector indexDommyValue = queryWhereSet.getIndexDummyValue();
2555 Vector indexDommyRelationValue = queryWhereSet
2556 .getIndexDummyRelationValue();
2557 Vector indexDommyConstantValue = queryWhereSet
2558 .getIndexDummyConstantValue();
2559 Vector indexDommyVariableValue = queryWhereSet
2560 .getIndexDummyVariableValue();
2561
2562 // ZK added this 28.4.2004 for transformations
2563 Vector indexDummyTransformationValue = queryWhereSet
2564 .getTransformationKeyColumns();
2565 // ZK end
2566 queryStatement.put(key, strQueryTarget);
2567 indexDValue.put(key, indexDommyValue);
2568 indexDRelationValue.put(key, indexDommyRelationValue);
2569 indexConstantDValue.put(key, indexDommyConstantValue);
2570 indexDVariableValue.put(key, indexDommyVariableValue);
2571 // ZK added this 28.4.2004 for transformations
2572 indexDTransformationValue.put(key,
2573 indexDummyTransformationValue);
2574 // end
2575 // query update
2576 String strUpdateTarget = queryUpdateSet.getQueryUpdate();
2577 Vector indexDommyOverwrite = queryUpdateSet
2578 .getIndexDummyOverwrite();
2579 Vector indexDommySetNull = queryUpdateSet
2580 .getIndexDummySetNull();
2581
2582 updateStatement.put(key, strUpdateTarget);
2583 indexDOverwrite.put(key, indexDommyOverwrite);
2584 indexDSetNull.put(key, indexDommySetNull);
2585
2586 // query update constant columns
2587 if (queryConstantSet != null) {
2588 String strUpdateConstant = queryConstantSet
2589 .getQueryConstant();
2590 Vector indexConstantOver = queryConstantSet
2591 .getIndexDummyOverwrite();
2592 Vector indexConstantNull = queryConstantSet
2593 .getIndexDummyNull();
2594
2595 updateConstantStatement.put(key, strUpdateConstant);
2596 indexDConstantOver.put(key, indexConstantOver);
2597 indexDConstantNull.put(key, indexConstantNull);
2598 }
2599
2600 if (queryTransformationSet != null) {
2601
2602 String strUpdateTransformation = queryTransformationSet
2603 .getQueryTransformation();
2604 Vector indexTransformationOver = queryTransformationSet
2605 .getIndexDummyOverwrite();
2606 Vector indexTransformationNull = queryTransformationSet
2607 .getIndexDummyNull();
2608 Vector indexTransformationUpdate = queryTransformationSet
2609 .getIndexDummyUpdate();
2610
2611 updateTransformationStatement.put(key,
2612 strUpdateTransformation);
2613 indexDTransformationOver.put(key, indexTransformationOver);
2614 indexDTransformationNull.put(key, indexTransformationNull);
2615 indexDTransformationUpdate.put(key,
2616 indexTransformationUpdate);
2617 }
2618 // query insert row
2619 String strInsertRow = insertRowQuerySet.getStrQuery();
2620 Vector indexRelations = insertRowQuerySet
2621 .getIndexDummyIsNotRelationsColumn();
2622 // prepare statement
2623 PreparedStatement pstmt = insertRowQuerySet
2624 .getPreparedStatementForInsert();
2625 Vector pstmtCNames = insertRowQuerySet.getColumnNames();
2626 // Hashtable
2627 // pstmtCTypes=insertRowQuerySet.getPreparedStatemetTypes();
2628
2629 // this vector keep tracking about key for prepareStmt...
2630 pstmtKeys.add(key);
2631 queryInsertRow.put(key, strInsertRow);
2632 indexIsNotRelationsColumns.put(key, indexRelations);
2633 pstmtForInsert.put(key, pstmt);
2634 pstmtColumnNames.put(key, pstmtCNames);
2635 // pstmtColumnTypes.put(key,pstmtCTypes);
2636 }
2637
2638 String strQuery = "";
2639 // if we have select statement insted of table name
2640 if (importDefinitionElement.strImportDefinitionSelectStatement != null
2641 && !importDefinitionElement.strImportDefinitionSelectStatement
2642 .equals("")) {
2643 strQuery = importDefinitionElement.strImportDefinitionSelectStatement;
2644 // strQuery = this.replaceInSelectStatement(strQuery);
2645 // TODO Allow different order of columns which should be
2646 // transformed
2647 // this part is for determine where columns for transformation
2648 // are started in
2649 // source result set
2650 // In selectStatement, columns for transformation should be on
2651 // the end, and they must
2652 // be in order same as in sourceColumn tags in all
2653 // transformations.
2654 // if (this.transformations.getTransformations().size() > 0) {
2655 // SqlParser parser = new SqlParser();
2656 // try {
2657 // parser.parse(strQuery);
2658 // } catch (Throwable e) {
2659 // this.logger
2660 // .write(
2661 // "full",
2662 // "Unable to parse sql query from 'selectStatement' attribute. This is needed by transformations if they exists.");
2663 // }
2664 // String[] columnNames = parser.getColumnNames();
2665 // List allSourceColNames = this.transformations
2666 // .getAllTransformationSourceColNames();
2667 // for (int br1 = 0; br1 < columnNames.length; br1++) {
2668 // for (int br2 = 0; br2 < allSourceColNames.size(); br2++) {
2669 // if (allSourceColNames.get(br2).toString()
2670 // .toUpperCase().equals(columnNames[br1]))
2671 // this.iOffsetForTransColumns = br1;
2672 // break;
2673 // }
2674 // }
2675 // }
2676
2677 if (!configReaderSource.getReadingOrderRelevant()) {
2678 int in = 0;
2679 int jn = 0;
2680 Vector vecVector = new Vector();
2681 while (in < this.iTables) {
2682 vecVector = (Vector) this.vecSourceColumnName.get(in);
2683 while (jn < Integer
2684 .parseInt(this.vecValueColumnsTargetTables.get(
2685 in).toString())) {
2686 jn++;
2687 this.iColumnsInSourceTable++;
2688 }
2689 jn = 0;
2690 in++;
2691 }
2692 }
2693 } else {
2694 // when table name is defined
2695 strQuery = this.querySource();
2696 }
2697
2698 if (strQuery.indexOf("order by") != -1) {
2699 if (checkSortColumns(connSource)) {
2700 this.logger
2701 .write("normal",
2702 "Error : Sort columns have more rows with equals values.");
2703 LoaderException le = new LoaderException(
2704 "SQLException: ",
2705 (Throwable) (new SQLException(
2706 "Error : Sort columns have more rows with equals values.")));
2707 this.logger.write("full", le.getStackTraceAsString());
2708 throw le;
2709 }
2710 }
2711
2712 ResultSet rsetSource = null;
2713 int blockNumber = 0;
2714 boolean usingSelectStmt = false;
2715 if (importDefinitionElement.strImportDefinitionSelectStatement != null
2716 && !importDefinitionElement.strImportDefinitionSelectStatement
2717 .equals("")) {
2718 usingSelectStmt = true;
2719 } else {
2720 if (configReaderSource.getRowCountEnabled()) {
2721 String countSQL = " select count(*) as \"counter\" from "
2722 + importDefinitionElement.strImportDefinitionTableName;
2723 Statement stmtSourceCount = connSource.createStatement();
2724 ResultSet rsetSourceCount = stmtSourceCount
2725 .executeQuery(countSQL);
2726 rsetSourceCount.next();
2727 iRowNumber = rsetSourceCount.getInt("counter");
2728 blockNumber = iRowNumber
2729 / importDefinitionElement.iImportDefinitionCommitCount
2730 + 1;
2731 rsetSourceCount.close();
2732 stmtSourceCount.close();
2733 }
2734 }
2735 iRowNumber = 0;
2736
2737 // set the number of rows in result set
2738 // setCursorName
2739 boolean setCursorName = false;
2740 if (!importDefinitionElement.setCursorNameID.equalsIgnoreCase(""))
2741 setCursorName = new Boolean(
2742 importDefinitionElement.setCursorNameID).booleanValue();
2743 else
2744 setCursorName = configReaderSource.getSetCursorNameEnabled();
2745
2746 if (setCursorName) {
2747 long cursorName = System.currentTimeMillis();
2748 stmtSource.setCursorName(String.valueOf(cursorName));
2749 }
2750 // setFetchSize
2751 boolean setFetchSize = false;
2752 if (!importDefinitionElement.setFetchSizeID.equalsIgnoreCase(""))
2753 setFetchSize = new Boolean(
2754 importDefinitionElement.setFetchSizeID).booleanValue();
2755 else
2756 setFetchSize = configReaderSource.getSetFetchSizeEnabled();
2757
2758 if (setFetchSize)
2759 stmtSource
2760 .setFetchSize(importDefinitionElement.iImportDefinitionCommitCount);
2761
2762 this.logger.write("full", "\tQuery '" + strQuery
2763 + "' will be executed");
2764 rsetSource = stmtSource.executeQuery(strQuery);
2765
2766 // this parameter defines if restartCounter has seccessfuly ended
2767 boolean main = true;
2768 if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
2769 if (this.hasRestartCounter) {
2770 bdecCounter = dataTransmition.checkDataTransmition(
2771 connTarget, rsetSource, this.currentJobName,
2772 configReaderTarget.getFirstColumnResult());
2773
2774 if (bdecCounter != null) {
2775 if (bdecCounter.toString().equalsIgnoreCase("0")) {
2776 // if is mycounter=0 in myrestart table escape this
2777 // importdefinition
2778 main = false;
2779 }
2780 } else {
2781 bdecCounter = new BigDecimal(0);
2782 }
2783 }
2784 if (!bdecCounter.toString().equalsIgnoreCase("0")) {
2785 // int num1 = Integer.parseInt(bdecCounter.toString());
2786 // int num2 = Integer.parseInt(this.bdecOidNumber.toString());
2787 // this.bdecOidNumber = new BigDecimal(num1 + num2);
2788 this.bdecOidNumber = bdecCounter.add(this.bdecOidNumber);
2789 }
2790 }
2791
2792 while (main) {
2793 boolean isEndFlag = false;
2794 this.logger.write("normal", "Import block is started.");
2795 currentBlock++;
2796 if (configReaderSource.getRowCountEnabled()) {
2797 if (!usingSelectStmt)
2798 this.logger.write("normal", "Working... "
2799 + currentBlock + ". block of " + blockNumber);
2800 else
2801 this.logger.write("normal", "Working... "
2802 + currentBlock + ". block");
2803 } else
2804 this.logger.write("normal", "Working... " + currentBlock
2805 + ". block");
2806 this.logger.write("full", "\tStarted from the "
2807 + bdecCounter.add(new BigDecimal(1)).toString()
2808 + ". row.");
2809 int bdecRowCount = 0;
2810 while (iRowNumber < importDefinitionElement.iImportDefinitionCommitCount) {
2811 if (!rsetSource.next()) {
2812 isEndFlag = true;
2813 break;
2814 }
2815 currentRow = iRowNumber;
2816 boolean readingOrderRelevant = false;
2817 if (configReaderSource.getReadingOrderRelevant())
2818 readingOrderRelevant = true;
2819
2820 for (int i = 0; i < this.iTables; i++) {
2821 Vector vecVektor = new Vector();
2822 this.vecBlobVector.clear();
2823
2824 // only for microsoft driver
2825 Hashtable orderRelevantColumnValues = new Hashtable();
2826 Hashtable sourceColumnTypes = new Hashtable();
2827 if (readingOrderRelevant) {
2828 int orderRelevantColumnCount = rsetSource
2829 .getMetaData().getColumnCount();
2830 for (int j = 1; j < orderRelevantColumnCount + 1; j++) {
2831 String orderRelevantColumnName = rsetSource
2832 .getMetaData().getColumnName(j);
2833 orderRelevantColumnName = orderRelevantColumnName
2834 .toUpperCase();
2835 Object orderRelevantColumnValue;
2836 if (configReaderSource.isDate(rsetSource
2837 .getMetaData().getColumnTypeName(j))) {
2838 // senka 27.12.2006 changed getData to getTimestamp
2839 orderRelevantColumnValue = rsetSource
2840 .getTimestamp(j);
2841 } else if (configReaderSource
2842 .isBinaryObject(rsetSource
2843 .getMetaData()
2844 .getColumnTypeName(j))) {
2845 orderRelevantColumnValue = rsetSource
2846 .getBytes(j);
2847 } else {
2848 orderRelevantColumnValue = rsetSource
2849 .getString(j);
2850 }
2851 if (orderRelevantColumnValue == null) {
2852 orderRelevantColumnValues.put(
2853 orderRelevantColumnName, "null");
2854 } else {
2855 orderRelevantColumnValues.put(
2856 orderRelevantColumnName,
2857 orderRelevantColumnValue);
2858 }
2859 // senka 27.12.2006 added to resolve problem with sourceColumnTypes for microsoft driver
2860 // put type of column
2861 sourceColumnTypes.put(orderRelevantColumnName,rsetSource.getMetaData().getColumnTypeName(j));
2862 this.logger
2863 .write(
2864 "normal",
2865 "\torderRelevantColumnTypes.put(orderRelevantColumnName, rsetSource.getMetaData().getColumnTypeName(j));");
2866 // orderRelevantColumnTypes.put(orderRelevantColumnName,
2867 // rsetSource.getMetaData().getColumnTypeName(j));
2868 }
2869 }
2870 // Read data from source
2871 // selectStatement=XXX
2872 if (importDefinitionElement.strImportDefinitionSelectStatement != null
2873 && !importDefinitionElement.strImportDefinitionSelectStatement
2874 .equals("")) {
2875 // for value columns
2876 Vector srcNames = new Vector();
2877 srcNames = (Vector) this.vecSourceColumnName.get(i);
2878 Object readValue = "";
2879 for (int s = 0; s < srcNames.size(); s++) {
2880 if (srcNames.get(s) != null) {
2881 String columnName = srcNames.get(s)
2882 .toString();
2883 if (!readingOrderRelevant) {
2884 readValue = rsetSource
2885 .getString(columnName);
2886 // since types are not filled, fill it
2887 // now
2888 int colIndex = rsetSource
2889 .findColumn(columnName);
2890 sourceColumnTypes.put(
2891 columnName, rsetSource
2892 .getMetaData()
2893 .getColumnTypeName(
2894 colIndex));
2895 } else {
2896 columnName = columnName.toUpperCase();
2897 // TODO Should readValue be String or
2898 // Object
2899 readValue = orderRelevantColumnValues
2900 .get(columnName);
2901 // .toString()
2902 ;
2903 }
2904 parseInputData(readValue, vecVektor,
2905 rsetSource, i, columnName, s + 1,
2906 readingOrderRelevant,
2907 orderRelevantColumnValues,
2908 sourceColumnTypes);
2909 }
2910 }
2911 // orderRelevantColumnValues.clear();
2912 // for transformations
2913 this.transformationValues.clear();
2914 List allSrcCls = this.transformations.getAllTransformationSourceColNames();
2915 for (int j = 0; j < allSrcCls.size(); j++) {
2916 Object value = "";
2917 String columnName = (String)allSrcCls.get(j);
2918 if (!readingOrderRelevant) {
2919 sourceColumnTypes.put(
2920 columnName, rsetSource
2921 .getMetaData()
2922 .getColumnTypeName(rsetSource.findColumn(columnName)));
2923 value = rsetSource.getString(columnName);
2924 } else {
2925 columnName = columnName.toUpperCase();
2926 value = orderRelevantColumnValues
2927 .get(columnName);
2928 }
2929 this.transformationValues.add(value);
2930 }
2931 orderRelevantColumnValues.clear();
2932 } else {
2933 // When tableName is defined, tableName=XXX
2934 // skip previous tables
2935 int iCounterCol = 0;
2936 for (int m = 0; m < i; m++) {
2937 iCounterCol = iCounterCol
2938 + Integer
2939 .parseInt(this.vecValueColumnsTargetTables
2940 .get(m).toString())
2941 // +
2942 // Integer.parseInt(this.vecTransformColumnsTargetTables.get(m).toString())
2943 ;
2944 }
2945 iCounterCol++;
2946 // for value columns
2947 for (int j = iCounterCol; j < (iCounterCol + Integer
2948 .parseInt(this.vecValueColumnsTargetTables
2949 .get(i).toString())
2950 // +
2951 // Integer.parseInt(this.vecTransformColumnsTargetTables.get(i).toString())
2952 ); j++) {
2953 String readValue = "";
2954 String columnName = rsetSource.getMetaData()
2955 .getColumnName(j);
2956 if (!readingOrderRelevant) {
2957 if (this.iFirstColumnResult == 0) {
2958 readValue = rsetSource.getString(j - 1);
2959 sourceColumnTypes.put(
2960 columnName, rsetSource
2961 .getMetaData()
2962 .getColumnTypeName(
2963 j - 1));
2964 } else {
2965 readValue = rsetSource.getString(j);
2966 sourceColumnTypes.put(
2967 columnName, rsetSource
2968 .getMetaData()
2969 .getColumnTypeName(
2970 j));
2971 }
2972 } else {
2973 columnName = columnName.toUpperCase();
2974 readValue = orderRelevantColumnValues.get(
2975 columnName).toString();
2976 }
2977 parseInputData(readValue, vecVektor,
2978 rsetSource, i, columnName, j
2979 - iCounterCol + 1,
2980 readingOrderRelevant,
2981 orderRelevantColumnValues,
2982 sourceColumnTypes);
2983 }
2984 // for transformations
2985 this.transformationValues.clear();
2986 List allSrcCls = this.transformations.getAllTransformationSourceColNames();
2987 for (int j = 0; j < allSrcCls.size(); j++) {
2988 Object value = "";
2989 String columnName = (String)allSrcCls.get(j);
2990 if (!readingOrderRelevant) {
2991 value = rsetSource.getString(columnName);
2992 } else {
2993 value = orderRelevantColumnValues
2994 .get(columnName.toUpperCase());
2995 }
2996 this.transformationValues.add(value);
2997 }
2998 }
2999 for (int l = 0; l < this.vecVariableUseIDTableName
3000 .size(); l++) {
3001 if (this.vecTableTableName.get(i).toString()
3002 .equalsIgnoreCase(
3003 this.vecVariableUseIDTableName.get(
3004 l).toString())
3005 && this.vecVariableUseIDTableID.get(l)
3006 .toString().equalsIgnoreCase(
3007 this.vecTableTableID.get(i)
3008 .toString()))
3009 vecVektor.add(this.strUserID);
3010 }
3011 Vector transformedValues = new Vector();
3012 Vector resultVectorTypes = new Vector();
3013 List trans = this.transformations.getTransformations();
3014 Vector vecTransformedValues = new Vector();
3015 Vector pomResultVectorTypes = new Vector();
3016 String tableId = this.vecTableTableID.get(i).toString();
3017 List transTableIDs = this.transformations
3018 .getTransformationsTableIDs();
3019 if (transTableIDs.contains(tableId)) {
3020 this.logger.write("full",
3021 "\ttransformation of values is started");
3022 int offset = 0;
3023 for (int j = 0; j < trans.size(); j++) {
3024 Transformation transformation = (Transformation) trans
3025 .get(j);
3026 Vector sourceColumnNames = transformation
3027 .getSourceColumnNames();
3028 Vector valuesForTrans = new Vector();
3029 for (int n = offset; n < offset
3030 + sourceColumnNames.size(); n++) {
3031 valuesForTrans
3032 .add(this.transformationValues
3033 .elementAt(n));
3034 }
3035 offset += sourceColumnNames.size();
3036 vecTransformedValues = transformation
3037 .transformValues(valuesForTrans);
3038 // senka 22.08.2007 changed i-->Integer.parseInt(tableId)
3039 //pomResultVectorTypes = transformation
3040 // .getOrderedTargetColumnTypes(i);
3041 pomResultVectorTypes = transformation
3042 .getOrderedTargetColumnTypes(Integer.parseInt(tableId));
3043 if (vecTransformedValues != null) {
3044 for (int m = 0; m < vecTransformedValues
3045 .size(); m++) {
3046 // use only values and types for
3047 // specified logic table
3048 if (pomResultVectorTypes.get(m) == null)
3049 continue;
3050 transformedValues
3051 .add(vecTransformedValues
3052 .get(m));
3053 resultVectorTypes
3054 .add(pomResultVectorTypes
3055 .get(m).toString());
3056 }
3057 }
3058 }
3059 this.logger.write("full",
3060 "\ttransformation of values is finished");
3061 }
3062
3063 // insert row into target logic table
3064 this.insertTargetTable(i, vecVektor,
3065 (Vector) this.vecTargetColumnName.get(i),
3066 (Vector) this.vecValueMode.get(i),
3067 (Vector) this.vecTargetColumnType.get(i),
3068 connTarget, transformedValues,
3069 resultVectorTypes);
3070
3071 }
3072 iRowNumber++;
3073 }
3074 // restart counter table
3075 if (!importDefinitionElement.strRestartCounterTableName
3076 .equals("")) {
3077 if (this.hasRestartCounter) {
3078 bdecCounter = bdecCounter
3079 .add(new BigDecimal(iRowNumber));
3080 dataTransmition.insertCounter(this.currentJobName,
3081 bdecCounter, connTarget);
3082 }
3083 }
3084
3085 if (this.hasRestartCounter) {
3086 // TODO THIS IS WRITE PLACE:ZK added this for update of
3087 // counterColumns. This will update values in CounterTable
3088 // for this import job.
3089 // this.counterColumns.updateCounter(this.htValuesForCounterColumns,
3090 // connTarget);
3091 this.counterColumns.updateCounter(connTarget);
3092 connTarget.commit();
3093 this.logger.write("normal", "Imported block is commited.");
3094 this.logger.write("full", Integer.toString(iRowNumber)
3095 + " rows are commited.");
3096 }
3097 iRowNumber = 0;
3098 if (isEndFlag == true)
3099 break;
3100 }// End of while(main)
3101
3102 rsetSource.close();
3103 stmtSource.close();
3104 connSource.close();
3105
3106 if (!importDefinitionElement.strRestartCounterTableName.equals("")) {
3107 if (this.hasRestartCounter) {
3108 dataTransmition.resetRestartCounter(connTarget,
3109 this.currentJobName);
3110 }
3111 }
3112 // TODO ZK added this for update of counterColumns. This will update
3113 // values in CounterTable for every importDefinition.
3114 if (!this.hasRestartCounter) {
3115 this.counterColumns.updateCounter(connTarget);
3116 }
3117 // end
3118 currentDate = new Date();
3119 dfNow = DateFormat.getDateTimeInstance();
3120 this.logger.write("normal", "Import definition "
3121 + importDefinitionElement.strImportDefinitionName
3122 + " is finished at " + dfNow.format(currentDate) + ".");
3123 this.logger.write("normal", " Duration of importDefinition:"
3124 + this.timeCounter.getJobTime());
3125 }
3126
3127 catch (Exception e) {
3128 try {
3129 if (connSource != null)
3130 connSource.close();
3131 } catch (Exception ex) {
3132 this.logger.write("normal", "\t" + ex.getMessage());
3133 }
3134 String msq = "Error: In import job '"
3135 + importDefinitionElement.strImportDefinitionName + "', "
3136 + "some error has occured:";
3137 this.logger.write("normal", "\t" + msq);
3138 LoaderException le = new LoaderException("Exception:"
3139 + e.getMessage(), (Throwable) e);
3140 this.logger.write("full", "\t" + le.getStackTraceAsString());
3141
3142 throw le;
3143 } finally {
3144 try {
3145
3146 this.logger.write("full", "loadSource method is finished.");
3147 if (connSource != null && !connSource.isClosed())
3148 connSource.close();
3149 } catch (SQLException e) {
3150 LoaderException le = new LoaderException("SQLException: ",
3151 (Throwable) e);
3152 // this.logger.write("normal", le.getCause().toString());
3153 this.logger.write("full", le.getStackTraceAsString());
3154 throw le;
3155 }
3156 }
3157 }
3158
3159 /***
3160 * This method read data from source table
3161 *
3162 * @param readValue
3163 * is data value which is reed
3164 * @param vecVektor
3165 * defines vector
3166 * @param rsetSource
3167 * defines ResultSet object
3168 * @param i
3169 * is interger
3170 * @param columnName
3171 * defines source column name
3172 * @param blobCount
3173 * defines counter for blob object
3174 * @param isMicrosoftDriver
3175 * defines if we use microsoft driver
3176 * @param columnValuesMicrosoft
3177 * defines column values which is read with microsoft driver
3178 */
3179 public void parseInputData(Object readValueObject, Vector vecVektor,
3180 ResultSet rsetSource, int i, String columnName, int blobCount,
3181 boolean isMicrosoftDriver, Hashtable columnValuesMicrosoft,
3182 Hashtable sourceColumnTypes) throws LoaderException {
3183 try {
3184 String readValue = "";
3185 if (readValueObject instanceof String)
3186 readValue = (String) readValueObject;
3187 else
3188 readValue = readValueObject != null ? readValueObject
3189 .toString() : "null";
3190
3191 if (readValue == null
3192 || readValue.toString().equalsIgnoreCase("null")) {
3193 vecVektor.add(null);
3194 } else if (readValue.toString().equalsIgnoreCase("")) {
3195 if (configReaderTarget.getSetEmptyStringAsNull())
3196 vecVektor.add(null);
3197 else
3198 vecVektor.add("");
3199 } else {
3200 // int indexOld = (
3201 // (Vector)this.vecTargetColumnName.get(i)).indexOf(columnName);
3202 int index = blobCount - 1;
3203 // if (index == -1) {
3204 // if (readValue.indexOf("'") != -1)
3205 // readValue = replaceChar(readValue, '\'', "\'\'");
3206 // vecVektor.add(readValue);
3207 // } else {
3208 byte[] blob;
3209
3210 String columnTypeTarget = ((Vector) this.vecTargetColumnType
3211 .get(i)).get(index).toString();
3212
3213 String columnTypeSource = sourceColumnTypes.get(columnName)
3214 .toString();
3215
3216 String mode = ((Vector) this.vecValueMode.get(i)).get(index)
3217 .toString();
3218 String toHex = ((Vector) this.vecToHex.get(i)).get(index)
3219 .toString();
3220 String fromHex = ((Vector) this.vecFromHex.get(i)).get(index)
3221 .toString();
3222 String blobObjectName = "binaryObject" + blobCount;
3223
3224 if (toHex.equalsIgnoreCase("true")
3225 && !fromHex.equalsIgnoreCase("true")) {
3226 if (isMicrosoftDriver)
3227 blob = (byte[]) columnValuesMicrosoft.get(columnName);
3228 else
3229 blob = rsetSource.getBytes(columnName);
3230
3231 String toHexString = ToAndFromHex.getStringFromBlob(blob);
3232 vecVektor.add(toHexString);
3233 } else if (fromHex.equalsIgnoreCase("true")
3234 && !toHex.equalsIgnoreCase("true")) {
3235 // ZK change this 7.5.2004 from CheckType to
3236 // configReaderTarget
3237 if (configReaderTarget.isBinaryObject(columnTypeTarget)) {
3238 // if (javaTypeInt==1) {
3239 byte[] newBlob = ToAndFromHex
3240 .getByteArrayFromString(readValue.toString());
3241 if (mode.equalsIgnoreCase("Update")) {
3242 this.vecBlobVector.add(columnName);
3243 this.vecBlobVector.add(newBlob);
3244 this.vecBlobVector.add(" where " + columnName
3245 + " is null and ");
3246 this.vecBlobVector.add(mode);
3247 this.vecBlobVector.add(blobObjectName);
3248 vecVektor.add(blobObjectName);
3249 } else {
3250 this.vecBlobVector.add(columnName);
3251 this.vecBlobVector.add(newBlob);
3252 this.vecBlobVector.add(null);
3253 this.vecBlobVector.add(mode);
3254 this.vecBlobVector.add(blobObjectName);
3255 vecVektor.add(blobObjectName);
3256 }
3257 } else {
3258 if (readValue.toString().indexOf("'") != -1)
3259 readValue = replaceChar(readValue, '\'', "\'\'");
3260 vecVektor.add(readValue);
3261 }
3262 } else {
3263 // ZK change this 7.5.2004 from CheckType to
3264 // configReaderSource
3265 if (configReaderTarget.isBinaryObject(columnTypeTarget)) {
3266 // if (javaTypeInt==1) {
3267 if (isMicrosoftDriver)
3268 blob = (byte[]) columnValuesMicrosoft
3269 .get(columnName);
3270 else
3271 blob = rsetSource.getBytes(columnName);
3272 if (mode.equalsIgnoreCase("Update")) {
3273 this.vecBlobVector.add(columnName);
3274 this.vecBlobVector.add(blob);
3275 this.vecBlobVector.add(" where " + columnName
3276 + " is null and ");
3277 this.vecBlobVector.add(mode);
3278 this.vecBlobVector.add(blobObjectName);
3279 vecVektor.add(blobObjectName);
3280 } else {
3281 this.vecBlobVector.add(columnName);
3282 this.vecBlobVector.add(blob);
3283 this.vecBlobVector.add(null);
3284 this.vecBlobVector.add(mode);
3285 this.vecBlobVector.add(blobObjectName);
3286 vecVektor.add(blobObjectName);
3287 }
3288 }
3289 else if (configReaderSource.isDate(columnTypeSource)) {
3290
3291 Date tmpDate = null;
3292 // Senka 27.12.2006 , separated Date and Timestamp columns
3293 if (isMicrosoftDriver){
3294 if (columnValuesMicrosoft.get(columnName).toString().length()>10)
3295 tmpDate = (java.sql.Timestamp) columnValuesMicrosoft
3296 .get(columnName);
3297 else
3298 tmpDate = (java.sql.Date) columnValuesMicrosoft
3299 .get(columnName);
3300
3301 }else{
3302 if (rsetSource.getObject(columnName).toString().length()>10)
3303 tmpDate = rsetSource.getTimestamp(columnName);
3304 else
3305 tmpDate= rsetSource.getDate(columnName);
3306 }
3307 if (!configReaderTarget.isDate(columnTypeTarget)) {
3308 String format = this.configReaderTarget.getDateFormat();
3309 SimpleDateFormat formatDate = new SimpleDateFormat(format);
3310 vecVektor.add(formatDate.format(tmpDate));
3311 } else {
3312 vecVektor.add(tmpDate);
3313 }
3314 }
3315 else {
3316 if (readValue.indexOf("'") != -1)
3317 readValue = replaceChar(readValue, '\'', "\'\'");
3318 vecVektor.add(readValue);
3319 }
3320 }
3321 }
3322 // }
3323 } catch (Exception ex) {
3324 LoaderException le = new LoaderException(
3325 "Error in parseInputData.", ex);
3326 this.logger.write("full", le.getStackTraceAsString());
3327 throw le;
3328 }
3329 }
3330
3331 /***
3332 * Method parseImportJOB is used to analyse import XML file about
3333 * ImportDefinitions tags. Return number of importDefinition elements in
3334 * whole xml file.
3335 *
3336 * @param inStream
3337 * Data from inputXML file which is converted into InputStream.
3338 * @return Number of ImportDefinitions tags in an input XML file.
3339 * @throws LoaderException
3340 */
3341 private int parseImportJob(InputStream inStream) throws LoaderException {
3342 int iNumTagsImportJob = 0;
3343 Document doc = null;
3344 this.logger.write("full", "\tparseImportJob method is started.");
3345 try {
3346
3347 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
3348 DocumentBuilder db = null;
3349 db = dbf.newDocumentBuilder();
3350 doc = db.parse(inStream);
3351 } catch (Exception e) {
3352 this.logger.write("normal", "Sorry, an error occurred: " + e);
3353 LoaderException le = new LoaderException("Exception: ",
3354 (Throwable) e);
3355 this.logger.write("full", le.getStackTraceAsString());
3356 throw le;
3357 }
3358 if (doc != null) {
3359 NodeList tagBasic = doc.getElementsByTagName("importDefinition");
3360 iNumTagsImportJob = tagBasic.getLength();
3361 Vector vecNames = new Vector();
3362 String strName = "";
3363 for (int i = 0; i < iNumTagsImportJob; i++) {
3364 strName = new String("");
3365 strName = OctopusXMLUtil.importAttributeValue(doc,
3366 "importDefinition", "name", i);
3367 for (int j = 0; j < vecNames.size(); j++) {
3368 if (strName.equals("")) {
3369 this.logger
3370 .write("normal",
3371 "Sorry, an error occurred: No importDefinition name .");
3372 LoaderException le = new LoaderException(
3373 "Exception: ",
3374 (Throwable) (new Exception(
3375 "Sorry, an error occurred: No importDefinition name .")));
3376 this.logger.write("full", le.getStackTraceAsString());
3377 throw le;
3378 }
3379 if (strName.equalsIgnoreCase(vecNames.get(j).toString())) {
3380 this.logger.write("normal",
3381 "Sorry, an error occurred: More importDefinition with same name :"
3382 + strName);
3383 LoaderException le = new LoaderException(
3384 "Exception: ",
3385 (Throwable) (new Exception(
3386 "Sorry, an error occurred: More importDefinition with same name :")));
3387 this.logger.write("full", le.getStackTraceAsString());
3388 throw le;
3389 }
3390 }
3391 vecNames.addElement(strName);
3392 }
3393 }
3394 try {
3395 inStream.reset();
3396 } catch (IOException e) {
3397 // this.logger.write("normal", "Sorry, an error occurred: " + e);
3398 LoaderException le = new LoaderException("IOException: ",
3399 (Throwable) e);
3400 this.logger.write("full", le.getStackTraceAsString());
3401 throw le;
3402 }
3403 this.logger.write("full", "\tparseImportJob method is finished.");
3404 return iNumTagsImportJob;
3405 }
3406
3407 /***
3408 * Method parseCopyTable is used to analyse import XML file about copyTable
3409 * tags. Return number of copyTable elements in whole xml file.
3410 *
3411 * @param inStream
3412 * Data from inputXML file which is converted into InputStream.
3413 * @return Number of iNumTagsCopyTable tags in an input XML file.
3414 * @throws LoaderException
3415 */
3416
3417 private int parseCopyTable(InputStream inStream) throws LoaderException {
3418 int iNumTagsCopyTable = 0;
3419 Document doc = null;
3420 this.logger.write("full", "\tparseCopyTable method is started.");
3421 try {
3422
3423 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
3424 DocumentBuilder db = null;
3425 db = dbf.newDocumentBuilder();
3426 doc = db.parse(inStream);
3427 } catch (Exception e) {
3428 this.logger.write("normal", "Sorry, an error occurred: " + e);
3429 LoaderException le = new LoaderException("Exception: ",
3430 (Throwable) e);
3431 this.logger.write("full", le.getStackTraceAsString());
3432 throw le;
3433 }
3434 if (doc != null) {
3435 NodeList tagCopyTable = doc.getElementsByTagName("copyTable");
3436 iNumTagsCopyTable = tagCopyTable.getLength();
3437 Vector vecNames = new Vector();
3438 String strName = "";
3439 for (int i = 0; i < iNumTagsCopyTable; i++) {
3440 strName = new String("");
3441 strName = OctopusXMLUtil.importAttributeValue(doc, "copyTable",
3442 "name", i);
3443 for (int j = 0; j < vecNames.size(); j++) {
3444 if (strName.equals("")) {
3445 this.logger
3446 .write("normal",
3447 "Sorry, an error occurred: No copyTable name .");
3448 LoaderException le = new LoaderException(
3449 "Exception: ",
3450 (Throwable) (new Exception(
3451 "Sorry, an error occurred: No copyTable name .")));
3452 this.logger.write("full", le.getStackTraceAsString());
3453 throw le;
3454 }
3455 if (strName.equalsIgnoreCase(vecNames.get(j).toString())) {
3456 this.logger.write("normal",
3457 "Sorry, an error occurred: More copyTable with same name :"
3458 + strName);
3459 LoaderException le = new LoaderException(
3460 "Exception: ",
3461 (Throwable) (new Exception(
3462 "Sorry, an error occurred: More copyTable with same name :")));
3463 this.logger.write("full", le.getStackTraceAsString());
3464 throw le;
3465 }
3466 }
3467 vecNames.addElement(strName);
3468 }
3469 }
3470 try {
3471 inStream.reset();
3472 } catch (IOException e) {
3473 this.logger.write("normal", "Sorry, an error occurred: " + e);
3474 LoaderException le = new LoaderException("IOException: ",
3475 (Throwable) e);
3476 this.logger.write("full", le.getStackTraceAsString());
3477 throw le;
3478 }
3479 this.logger.write("full", "\tparseImportJob method is finished.");
3480 return iNumTagsCopyTable;
3481 }
3482
3483 /***
3484 * Method parseEchoElement is used to analyse import XML file about echo
3485 * tags. Return number of echo elements in a whole xml input file.
3486 *
3487 * @param inStream
3488 * Data from inputXML file which is converted into InputStream.
3489 * @return Number of echo tags in an input XML file.
3490 * @throws LoaderException
3491 */
3492 private int parseEcho(InputStream inStream) throws LoaderException {
3493 int iNumTagsEcho = 0;
3494 Document doc = null;
3495 this.logger.write("full", "\tparseEcho method is started.");
3496 try {
3497 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
3498 DocumentBuilder db = null;
3499 db = dbf.newDocumentBuilder();
3500 doc = db.parse(inStream);
3501 } catch (Exception e) {
3502 this.logger.write("normal", "Sorry, an error occurred: " + e);
3503 LoaderException le = new LoaderException("Exception: ",
3504 (Throwable) e);
3505 this.logger.write("full", le.getStackTraceAsString());
3506 throw le;
3507 }
3508 if (doc != null) {
3509 NodeList tagBasic = doc.getElementsByTagName("echo");
3510 iNumTagsEcho = tagBasic.getLength();
3511 String strMessage = "";
3512 for (int i = 0; i < iNumTagsEcho; i++) {
3513 strMessage = new String("");
3514 strMessage = OctopusXMLUtil.importAttributeValue(doc, "echo",
3515 "message", i);
3516 if (strMessage != null)
3517 logger.setMessage((new Integer(i)).toString(), strMessage);
3518 }
3519 }
3520 try {
3521 inStream.reset();
3522 } catch (IOException e) {
3523 this.logger.write("normal", "Sorry, an error occurred: " + e);
3524 LoaderException le = new LoaderException("IOxception: ",
3525 (Throwable) e);
3526 this.logger.write("full", le.getStackTraceAsString());
3527 throw le;
3528 // System.exit(1);
3529 }
3530 this.logger.write("full", "\tparseSql method is finished.");
3531 return iNumTagsEcho;
3532 }
3533
3534 /***
3535 * Method parseMainElements is used to analyse import XML file about main
3536 * elements (sql and importDefinition). Puts names of elements (sql or
3537 * importDefinition) in Vector.
3538 *
3539 * @param inStream
3540 * Data from inputXML file which is converted into InputStream.
3541 * @return Vector which elements are names of main elements in the same
3542 * order as in XML import file .
3543 * @throws LoaderException
3544 */
3545 private Vector parseMainElements(InputStream inStream)
3546 throws LoaderException {
3547
3548 Vector vecLoaderElements = new Vector();
3549 Vector vecLoaderNamesOfElements = new Vector();
3550
3551 Document doc = null;
3552 this.logger.write("full", "\tparseMainElements method is started.");
3553 try {
3554 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
3555 DocumentBuilder db = null;
3556 db = dbf.newDocumentBuilder();
3557 doc = db.parse(inStream);
3558 } catch (Exception e) {
3559 this.logger.write("normal", "Sorry, an error occurred: " + e);
3560 LoaderException le = new LoaderException("Exception: ",
3561 (Throwable) e);
3562 this.logger.write("full", le.getStackTraceAsString());
3563 throw le;
3564 }
3565 if (doc != null) {
3566 NodeList tagBasic = doc.getElementsByTagName("loaderJob");
3567 NodeList nlMainElements = tagBasic.item(0).getChildNodes();
3568 for (int i = 0; i < nlMainElements.getLength(); i++) {
3569 String strTagName = nlMainElements.item(i).getNodeName();
3570 if (strTagName.equalsIgnoreCase("sql")
3571 || strTagName.equalsIgnoreCase("importDefinition")
3572 || strTagName.equalsIgnoreCase("echo")
3573 || strTagName.equalsIgnoreCase("copyTable"))
3574 if (nlMainElements.item(i).getNodeType() == Node.ELEMENT_NODE) {
3575 String strTagJobName = (((Element) nlMainElements
3576 .item(i)).getAttribute("name"));
3577 String strLogMode = (((Element) nlMainElements.item(i))
3578 .getAttribute("logMode"));
3579 vecLoaderElements.addElement(strTagName);
3580 this.logModes.add(strLogMode);
3581 boolean addJobName = true;
3582 if (!strTagJobName.equalsIgnoreCase("")) {
3583 for (int j = 0; j < vecLoaderNamesOfElements.size(); j++) {
3584 if (strTagJobName
3585 .equalsIgnoreCase(vecLoaderNamesOfElements
3586 .get(j).toString())) {
3587 addJobName = false;
3588 break;
3589 }
3590 }
3591 if (addJobName) {
3592 vecLoaderNamesOfElements.add(strTagJobName);
3593 } else {
3594 String msg = "Sorry, an error occurred: More import jobs with same name :"
3595 + strTagJobName;
3596 LoaderException le = new LoaderException(
3597 "Exception:", new Exception(msg));
3598
3599 throw le;
3600 }
3601 }
3602 }
3603 }
3604 }
3605 try {
3606 inStream.reset();
3607 } catch (IOException e) {
3608 this.logger.write("normal", "Sorry, an error occurred: "
3609 + e.getMessage());
3610 LoaderException le = new LoaderException("IOException: ",
3611 (Throwable) e);
3612 this.logger.write("full", le.getStackTraceAsString());
3613 throw le;
3614 }
3615 this.logger.write("full", "\tparseMainElements method is finished.");
3616 return vecLoaderElements;
3617 }
3618
3619 /***
3620 * Method importRestartCounter is used to analyse import XML file and read
3621 * restart counter attributes. Values of these attributes puts in Vectors
3622 *
3623 * @param inStream
3624 * Data from inputXML file which is converted into InputStream.
3625 * @throws LoaderException
3626 */
3627 private void importRestartCounter(InputStream inStream)
3628 throws LoaderException {
3629 Document doc = null;
3630 this.logger.write("full", "\timportRestartCounter method is started.");
3631 try {
3632 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
3633 DocumentBuilder db = null;
3634 db = dbf.newDocumentBuilder();
3635 doc = db.parse(inStream);
3636 } catch (Exception e) {
3637 this.logger.write("normal", "Sorry, an error occurred: " + e);
3638 LoaderException le = new LoaderException("Exception: ",
3639 (Throwable) e);
3640 this.logger.write("full", le.getStackTraceAsString());
3641 throw le;
3642 // System.exit(1);
3643 }
3644 if (doc != null) {
3645 NodeList tagRestartCounter = doc
3646 .getElementsByTagName("restartCounter");
3647 if (tagRestartCounter.getLength() != 0) {
3648 this.hasRestartCounter = true;
3649 NamedNodeMap attrs = tagRestartCounter.item(0).getAttributes();
3650 Node nodeResult = attrs.getNamedItem("tableName");
3651 if (nodeResult != null)
3652 importDefinitionElement.strRestartCounterTableName = nodeResult
3653 .getNodeValue();
3654 else
3655 importDefinitionElement.strRestartCounterTableName = "LOADERRESTART";
3656 nodeResult = attrs.getNamedItem("importDefinitionColumnName");
3657 if (nodeResult != null)
3658 importDefinitionElement.strRestartCounterImportDefinitionName = nodeResult
3659 .getNodeValue();
3660 else
3661 importDefinitionElement.strRestartCounterImportDefinitionName = "IMPORTDEFINITION";
3662 nodeResult = attrs.getNamedItem("restartCounterColumnName");
3663 if (nodeResult != null)
3664 importDefinitionElement.strRestartCounterValue = nodeResult
3665 .getNodeValue();
3666 else
3667 importDefinitionElement.strRestartCounterValue = "RESTARTCOUNTER";
3668 nodeResult = attrs.getNamedItem("restartAutoCreate");
3669 if (nodeResult != null)
3670 importDefinitionElement.bRestartAutoCreate = (new Boolean(
3671 nodeResult.getNodeValue())).booleanValue();
3672 else
3673 importDefinitionElement.bRestartAutoCreate = false;
3674 }
3675 }
3676 try {
3677 inStream.reset();
3678 } catch (IOException e) {
3679 this.logger.write("normal", "Sorry, an error occurred: " + e);
3680 LoaderException le = new LoaderException("IOException: ",
3681 (Throwable) e);
3682 this.logger.write("full", le.getStackTraceAsString());
3683 throw le;
3684 // System.exit(1);
3685 }
3686 this.logger.write("full", "\timportRestartCounter method is finished.");
3687 }
3688
3689 /***
3690 * Method importVariable imports sql attributes from xml file and puts them
3691 * in the global variables. Return Vector. It's elements are strings which
3692 * represents sql statements.
3693 *
3694 * @param inStream
3695 * Data from inputXML file which is converted into InputStream.
3696 * @throws LoaderException
3697 */
3698 private void importVariable(InputStream inStream) throws LoaderException {
3699 Document doc = null;
3700 String strNodeValue = "";
3701 String strDefaultVariableOverride = "";
3702 String strDefaultReplaceInConstants = "";
3703 String strDefaultReplaceInSQL = "";
3704 String strDefaultReplaceInData = "";
3705 String strDefaultReplaceInJDBC = "";
3706 String strDefaultVariablePrefix = "";
3707 String strDefaultVariableSufix = "";
3708 this.logger.write("full", "\timportVariable method is started.");
3709 try {
3710 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
3711 DocumentBuilder db = null;
3712 db = dbf.newDocumentBuilder();
3713 doc = db.parse(inStream);
3714 if (doc != null) {
3715 NodeList tagBasic = doc.getElementsByTagName("variables");
3716 if (tagBasic.getLength() != 0) {
3717 Element docFragment = (Element) tagBasic.item(0);
3718 strDefaultVariablePrefix = docFragment
3719 .getAttribute("prefix");
3720 if (strDefaultVariablePrefix.equals(""))
3721 strDefaultVariablePrefix = "%";
3722 strDefaultVariableSufix = docFragment
3723 .getAttribute("suffix");
3724 if (strDefaultVariableSufix.equals(""))
3725 strDefaultVariableSufix = "%";
3726 strDefaultVariableOverride = docFragment
3727 .getAttribute("override");
3728 if (strDefaultVariableOverride.equals(""))
3729 strDefaultVariableOverride = "true";
3730 strDefaultReplaceInConstants = docFragment
3731 .getAttribute("replaceInConstants");
3732 if (strDefaultReplaceInConstants.equals(""))
3733 strDefaultReplaceInConstants = "false";
3734 strDefaultReplaceInSQL = docFragment
3735 .getAttribute("replaceInSQL");
3736 if (strDefaultReplaceInSQL.equals(""))
3737 strDefaultReplaceInSQL = "false";
3738 strDefaultReplaceInData = docFragment
3739 .getAttribute("replaceInData");
3740 if (strDefaultReplaceInData.equals(""))
3741 strDefaultReplaceInData = "false";
3742 strDefaultReplaceInJDBC = docFragment
3743 .getAttribute("replaceInJDBC");
3744 if (strDefaultReplaceInJDBC.equals(""))
3745 strDefaultReplaceInJDBC = "false";
3746 NodeList tag = docFragment.getElementsByTagName("variable");
3747 this.vecVariableName = OctopusXMLUtil.getAttributeValues(
3748 tag, "name", null);
3749 this.vecVariableValue = OctopusXMLUtil.getAttributeValues(
3750 tag, "value", null);
3751 this.vecVariablePrefix = OctopusXMLUtil.getAttributeValues(
3752 tag, "prefix", strDefaultVariablePrefix);
3753 this.vecVariableSufix = OctopusXMLUtil.getAttributeValues(
3754 tag, "suffix", strDefaultVariableSufix);
3755 this.vecVariableOverride = OctopusXMLUtil
3756 .getAttributeValues(tag, "override",
3757 strDefaultVariableOverride);
3758 this.vecReplaceInConstants = OctopusXMLUtil
3759 .getAttributeValues(tag, "replaceInConstants",
3760 strDefaultReplaceInConstants);
3761 this.vecReplaceInSQL = OctopusXMLUtil.getAttributeValues(
3762 tag, "replaceInSQL", strDefaultReplaceInSQL);
3763 this.vecReplaceInData = OctopusXMLUtil.getAttributeValues(
3764 tag, "replaceInData", strDefaultReplaceInData);
3765 this.vecReplaceInJDBC = OctopusXMLUtil.getAttributeValues(
3766 tag, "replaceInJDBC", strDefaultReplaceInJDBC);
3767 for (int i = 0; i < this.vecVariableOverride.size(); i++) {
3768 if (this.vecVariableOverride.get(i).toString()
3769 .equalsIgnoreCase("true")) {
3770 if (this.mapVariableValues.get(this.vecVariableName
3771 .get(i)) == null)
3772 this.vecVariableValue.setElementAt(null, i);
3773 else
3774 this.vecVariableValue
3775 .setElementAt(this.mapVariableValues
3776 .get(
3777 this.vecVariableName
3778 .get(i)
3779 .toString())
3780 .toString(), i);
3781 }
3782 }
3783 }
3784 }
3785 } catch (Exception e) {
3786 this.logger.write("normal",
3787 "Sorry, an error with the variables occurred: " + e);
3788 LoaderException le = new LoaderException("Exception: ",
3789 (Throwable) e);
3790 this.logger.write("full", le.getStackTraceAsString());
3791 throw le;
3792 }
3793 try {
3794 inStream.reset();
3795 } catch (IOException e) {
3796 this.logger.write("normal", "Sorry, an error occurred: " + e);
3797 LoaderException le = new LoaderException("IOException: ",
3798 (Throwable) e);
3799 this.logger.write("full", le.getStackTraceAsString());
3800 throw le;
3801 }
3802 this.logger.write("full", "\timportVariable method is finished.");
3803 }
3804
3805 /***
3806 * Method parseAndImport is used to analyse the importDefinition no. l in
3807 * xml file and input all values and puts them into global variables. If
3808 * there is an error, Exception "SAXException" is thrown.
3809 *
3810 * @param inStream
3811 * Data from inputXML file which is converted into InputStream.
3812 * @param l
3813 * Number of ImportDefinition tag which is processed.
3814 * @param isImportDefinition
3815 * true if ImportJob tag is "importDefinition".
3816 * @throws SAXException
3817 * Constructs an JAXP 1.1 Exception with the specified detail
3818 * message.
3819 * @throws Exception
3820 * Constructs an Exception with the specified detail message.
3821 * @throws LoaderException
3822 */
3823 // 26.07.2007 senka added parameter isImportDefinition
3824 private void parseAndImport(InputStream inStream, int l, boolean isImportDefinition)
3825 throws SAXException, LoaderException, Exception {
3826 this.logger.write("full", "\tparseAndImport method is started.");
3827 Document doc = null;
3828 try {
3829 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
3830 DocumentBuilder db = null;
3831 db = dbf.newDocumentBuilder();
3832 doc = db.parse(inStream);
3833 } catch (SAXException e) {
3834 throw e;
3835 } catch (Exception e) {
3836 throw e;
3837 }
3838 if (doc != null)
3839 this.importXMLFile(doc, l, isImportDefinition);
3840 try {
3841 inStream.reset();
3842 } catch (IOException e) {
3843 this.logger.write("normal", "Sorry, an error occurred: " + e);
3844 LoaderException le = new LoaderException("IOException: ",
3845 (Throwable) e);
3846 this.logger.write("full", le.getStackTraceAsString());
3847 throw le;
3848 }
3849 this.logger.write("full", "\tparseAndImport method is finished.");
3850 }
3851
3852 /***
3853 * Method importXMLFile is used for setting of global variables during
3854 * importing values from XML file. This method validates the imported data
3855 * from XML file. If there is an error Exception "NullPointerException" or
3856 * "Exception" is thrown.
3857 *
3858 * @param doc
3859 * Parsed imports XML file.
3860 * @param iJobNumber
3861 * Number of ImportJob tag which is processed.
3862 * @param isImportDefinition
3863 * true if ImportJob tag is "importDefinition".
3864 * @throws NullPointerException
3865 * Constructs a NullPointerException with the specified detail
3866 * message.
3867 * @throws Exception
3868 * Constructs an Exception with the specified detail message.
3869 */
3870 // 26.07.2007 senka added parameter isImportDefinition
3871 private void importXMLFile(Document doc, int iJobNumber, boolean isImportDefinition)
3872 throws NullPointerException, Exception {
3873 this.logger.write("full", "\timportXMLFile method is started.");
3874 Vector vecValueColumnSourceColumnName = new Vector();
3875 Vector vecValueColumnTargetTableName = new Vector();
3876 Vector vecValueColumnTargetColumnName = new Vector();
3877 Vector vecValueColumnTargetTableID = new Vector();
3878 Vector vecValueColumnValueMode = new Vector();
3879 Vector vecConstantColumnTargetColumnName = new Vector();
3880 Vector vecConstantColumnValueMode = new Vector();
3881 Vector vecConstantColumnConstantValue = new Vector();
3882 Vector vecRestartCounterVector = new Vector();
3883 Vector vecJDBCSourceName = new Vector();
3884 Vector vecJDBCSourceValue = new Vector();
3885 Vector vecJDBCTargetName = new Vector();
3886 Vector vecJDBCTargetValue = new Vector();
3887 // vector for default values of columns
3888 Vector vecDefaultValueTemp = new Vector();
3889 this.vecDefaultValue = new Vector();
3890 this.vecDefaultRelationValue = null;
3891 this.vecDefaultVariableValue = null;
3892 this.vecDefaultVariableName = null;
3893 this.vecTempUserID = null;
3894 int iNumberOfColumns = 0;
3895 // to and form hex
3896 Vector vecToHexTemp = new Vector();
3897 Vector vecFromHexTemp = new Vector();
3898 this.vecToHex = new Vector();
3899 this.vecFromHex = new Vector();
3900
3901 try {
3902
3903 importDefinitionElement.setLogger(this.logger);
3904 dataCleaning.setLogger(this.logger);
3905
3906 if (!this.loaderJobReader.getLogTableName().equalsIgnoreCase(""))
3907 dataCleaning.setLogTableName(this.loaderJobReader
3908 .getLogTableName());
3909
3910 if (!this.loaderJobReader.getLogTable().equalsIgnoreCase(""))
3911 dataCleaning.setLogTable(this.loaderJobReader.getLogTable());
3912
3913 if (!this.loaderJobReader.getLogColumnName().equalsIgnoreCase(""))
3914 dataCleaning.setLogColumnName(this.loaderJobReader
3915 .getLogColumnName());
3916
3917 if (!this.loaderJobReader.getLogRowNumber().equalsIgnoreCase(""))
3918 dataCleaning.setLogRowNumber(this.loaderJobReader
3919 .getLogRowNumber());
3920
3921 if (!this.loaderJobReader.getLogOriginalValue()
3922 .equalsIgnoreCase(""))
3923 dataCleaning.setLogOriginalValue(this.loaderJobReader
3924 .getLogOriginalValue());
3925
3926 if (!this.loaderJobReader.getLogNewValue().equalsIgnoreCase(""))
3927 dataCleaning.setLogNewValue(this.loaderJobReader
3928 .getLogNewValue());
3929
3930 if (!this.loaderJobReader.getLogImportDefinitionName()
3931 .equalsIgnoreCase(""))
3932 dataCleaning.setLogImportDefinitionName(this.loaderJobReader
3933 .getLogImportDefinitionName());
3934
3935 if (!this.loaderJobReader.getLogOperationName()
3936 .equalsIgnoreCase(""))
3937 dataCleaning.setLogOperationName(this.loaderJobReader
3938 .getLogOperationName());
3939 if (!this.loaderJobReader.getLogTime().equalsIgnoreCase(""))
3940 dataCleaning.setLogTime(this.loaderJobReader.getLogTime());
3941
3942 if (!this.loaderJobReader.getLogFailedStatement().equalsIgnoreCase(
3943 ""))
3944 dataCleaning.setLogPrimaryKeyValue(this.loaderJobReader
3945 .getLogFailedStatement());
3946
3947 if (!this.loaderJobReader.getLogTypeName().equalsIgnoreCase(""))
3948 dataCleaning.setLogTypeName(this.loaderJobReader
3949 .getLogTypeName());
3950
3951 importDefinitionElement.setLoaderJob(this.loaderJobReader);
3952 // sqlElement.setLoaderJob(this.loaderJobReader);
3953 importDefinitionElement.importXMLFile(doc, iJobNumber);
3954
3955 // set data cut off parameter based on priority
3956 if (importDefinitionElement.strDefaultCutOffData
3957 .equalsIgnoreCase(""))
3958 importDefinitionElement.strDefaultCutOffData = loaderJobReader
3959 .getDefaultDataCutOff();
3960
3961 // set onErrorContinue parameter based on priority for xml
3962 if (importDefinitionElement.strOnErrorContinueXml
3963 .equalsIgnoreCase(""))
3964 importDefinitionElement.strOnErrorContinueXml = ""
3965 + loaderJobReader.getDefaultOnErrorContinue();
3966
3967 if (importDefinitionElement.strCopyTableOnErrorContinue
3968 .equalsIgnoreCase(""))
3969 importDefinitionElement.strCopyTableOnErrorContinue = ""
3970 + loaderJobReader.getDefaultOnErrorContinue();
3971 if (isImportDefinition){ // 26.07.2007 senka added this check
3972 vecJDBCSourceValue = OctopusXMLUtil.importValue(doc,
3973 "jdbcSourceParameter", "value", iJobNumber);
3974 vecJDBCSourceName = OctopusXMLUtil.importValue(doc,
3975 "jdbcSourceParameter", "name", iJobNumber);
3976
3977 if (vecJDBCSourceValue.size() != 0) {
3978 for (int i = 0; i < vecJDBCSourceValue.size(); i++) {
3979 if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase(
3980 "JdbcDriver"))
3981 jdbcParametersElement
3982 .setJDBCSourceParameterDriver(vecJDBCSourceValue
3983 .get(i).toString());
3984 else if (vecJDBCSourceName.get(i).toString()
3985 .equalsIgnoreCase("Connection.Url")) {
3986 // Testing SelectMethod parameter in microsoft MSSQL
3987 // driver
3988 if (vecJDBCSourceValue.get(i).toString().indexOf(
3989 "jdbc:microsoft:sqlserver") != -1) {
3990 if (vecJDBCSourceValue.get(i).toString().indexOf(
3991 "SelectMethod") == -1) {
3992 jdbcParametersElement
3993 .setJDBCSourceParameterConnection(vecJDBCSourceValue
3994 .get(i).toString()
3995 + ";SelectMethod=cursor");
3996 } else if (vecJDBCSourceValue.get(i).toString()
3997 .indexOf("cursor") != -1) {
3998 jdbcParametersElement
3999 .setJDBCSourceParameterConnection(vecJDBCSourceValue
4000 .get(i).toString());
4001 } else {
4002 this.logger
4003 .write(
4004 "normal",
4005 "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor");
4006 LoaderException le = new LoaderException(
4007 "Exception:",
4008 new Exception(
4009 "Value of Connection.Url perameter SelectMethod has to be cursor"));
4010 this.logger.write("full", le
4011 .getStackTraceAsString());
4012 throw le;
4013 }
4014 } else {
4015 jdbcParametersElement
4016 .setJDBCSourceParameterConnection(vecJDBCSourceValue
4017 .get(i).toString());
4018 }
4019 } else if (vecJDBCSourceName.get(i).toString()
4020 .equalsIgnoreCase("User"))
4021 jdbcParametersElement
4022 .setJDBCSourceParameterUser(vecJDBCSourceValue
4023 .get(i).toString());
4024 else if (vecJDBCSourceName.get(i).toString()
4025 .equalsIgnoreCase("Password"))
4026 jdbcParametersElement
4027 .setJDBCSourceParameterPassword(vecJDBCSourceValue
4028 .get(i).toString());
4029 }
4030 }
4031
4032 vecJDBCTargetValue = OctopusXMLUtil.importValue(doc,
4033 "jdbcTargetParameter", "value", iJobNumber);
4034 vecJDBCTargetName = OctopusXMLUtil.importValue(doc,
4035 "jdbcTargetParameter", "name", iJobNumber);
4036
4037 if (vecJDBCTargetValue.size() != 0) {
4038 for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
4039 if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase(
4040 "JdbcDriver"))
4041 jdbcParametersElement
4042 .setJDBCTargetParameterDriver(vecJDBCTargetValue
4043 .get(i).toString());
4044 else if (vecJDBCTargetName.get(i).toString()
4045 .equalsIgnoreCase("Connection.Url")) {
4046 // Testing SelectMethod parameter in microsoft MSSQL
4047 // driver
4048 if (vecJDBCTargetValue.get(i).toString().indexOf(
4049 "jdbc:microsoft:sqlserver") != -1) {
4050 if (vecJDBCTargetValue.get(i).toString().indexOf(
4051 "SelectMethod") == -1) {
4052 jdbcParametersElement
4053 .setJDBCTargetParameterConnection(vecJDBCTargetValue
4054 .get(i).toString()
4055 + ";SelectMethod=cursor");
4056 } else if (vecJDBCTargetValue.get(i).toString()
4057 .indexOf("cursor") != -1) {
4058 jdbcParametersElement
4059 .setJDBCTargetParameterConnection(vecJDBCTargetValue
4060 .get(i).toString());
4061 } else {
4062 this.logger
4063 .write(
4064 "normal",
4065 "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor");
4066 LoaderException le = new LoaderException(
4067 "Exception:",
4068 new Exception(
4069 "value of Connection.Url parameter SelectMethod has to be cursor"));
4070 this.logger.write("full", le
4071 .getStackTraceAsString());
4072 throw le;
4073 }
4074 } else {
4075 jdbcParametersElement
4076 .setJDBCTargetParameterConnection(vecJDBCTargetValue
4077 .get(i).toString());
4078 }
4079 } else if (vecJDBCTargetName.get(i).toString()
4080 .equalsIgnoreCase("User"))
4081 jdbcParametersElement
4082 .setJDBCTargetParameterUser(vecJDBCTargetValue
4083 .get(i).toString());
4084 else if (vecJDBCTargetName.get(i).toString()
4085 .equalsIgnoreCase("Password"))
4086 jdbcParametersElement
4087 .setJDBCTargetParameterPassword(vecJDBCTargetValue
4088 .get(i).toString());
4089 }
4090 }
4091 // to and form hex
4092
4093 vecToHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn",
4094 "toHex", iJobNumber);
4095 vecFromHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn",
4096 "fromHex", iJobNumber);
4097 // defalut values
4098 vecDefaultValueTemp = OctopusXMLUtil.importValue(doc,
4099 "valueColumn", "defaultValue", iJobNumber);
4100 this.vecDefaultVariableValue = OctopusXMLUtil.importValue(doc,
4101 "variableColumn", "defaultValue", iJobNumber);
4102 this.vecDefaultVariableName = OctopusXMLUtil.importValue(doc,
4103 "variableColumn", "name", iJobNumber);
4104 this.vecDefaultRelationValue = OctopusXMLUtil.importValue(doc,
4105 "relationColumn", "defaultValue", iJobNumber);
4106 this.vecTempUserID = OctopusXMLUtil.importValue(doc,
4107 "userIDColumn", "defaultValue", iJobNumber);
4108 vecValueColumnSourceColumnName = OctopusXMLUtil.importValue(doc,
4109 "valueColumn", "sourceColumnName", iJobNumber);
4110 vecValueColumnTargetTableName = OctopusXMLUtil.importValue(doc,
4111 "valueColumn", "targetTableName", iJobNumber);
4112 this.iValueColumns = vecValueColumnTargetTableName.size();
4113 vecValueColumnTargetColumnName = OctopusXMLUtil.importValue(doc,
4114 "valueColumn", "targetColumnName", iJobNumber);
4115 vecValueColumnTargetTableID = OctopusXMLUtil.importValue(doc,
4116 "valueColumn", "targetTableID", iJobNumber);
4117 vecValueColumnValueMode = OctopusXMLUtil.importValue(doc,
4118 "valueColumn", "valueMode", iJobNumber);
4119 this.vecVariableColumnName = OctopusXMLUtil.importValue(doc,
4120 "variableColumn", "name", iJobNumber);
4121 this.vecVariableColumnTargetTableName = OctopusXMLUtil.importValue(
4122 doc, "variableColumn", "targetTableName", iJobNumber);
4123 this.vecVariableColumnTargetColumnName = OctopusXMLUtil
4124 .importValue(doc, "variableColumn", "targetColumnName",
4125 iJobNumber);
4126 this.vecVariableColumnTargetTableID = OctopusXMLUtil.importValue(
4127 doc, "variableColumn", "targetTableID", iJobNumber);
4128 this.vecVariableColumnValueMode = OctopusXMLUtil.importValue(doc,
4129 "variableColumn", "valueMode", iJobNumber);
4130 this.vecVariableUseIDTableName = OctopusXMLUtil.importValue(doc,
4131 "userIDColumn", "targetTableName", iJobNumber);
4132 this.vecVariableUseIDColumnName = OctopusXMLUtil.importValue(doc,
4133 "userIDColumn", "targetColumnName", iJobNumber);
4134 this.vecVariableUseIDTableID = OctopusXMLUtil.importValue(doc,
4135 "userIDColumn", "targetTableID", iJobNumber);
4136 this.vecVariableUseIDValueMode = OctopusXMLUtil.importValue(doc,
4137 "userIDColumn", "valueMode", iJobNumber);
4138 this.vecVariableTimesTableName = OctopusXMLUtil.importValue(doc,
4139 "timeStampColumn", "targetTableName", iJobNumber);
4140 this.vecVariableTimesColumnName = OctopusXMLUtil.importValue(doc,
4141 "timeStampColumn", "targetColumnName", iJobNumber);
4142 this.vecVariableTimesTableID = OctopusXMLUtil.importValue(doc,
4143 "timeStampColumn", "targetTableID", iJobNumber);
4144 this.vecVariableTimesValueMode = OctopusXMLUtil.importValue(doc,
4145 "timeStampColumn", "valueMode", iJobNumber);
4146 this.vecConstantColumnTargetTableName = OctopusXMLUtil.importValue(
4147 doc, "constantColumn", "targetTableName", iJobNumber);
4148 this.iConstantColumns = this.vecConstantColumnTargetTableName
4149 .size();
4150 vecConstantColumnTargetColumnName = OctopusXMLUtil.importValue(doc,
4151 "constantColumn", "targetColumnName", iJobNumber);
4152 this.vecConstantColumnTargetTableID = OctopusXMLUtil.importValue(
4153 doc, "constantColumn", "targetTableID", iJobNumber);
4154 vecConstantColumnValueMode = OctopusXMLUtil.importValue(doc,
4155 "constantColumn", "valueMode", iJobNumber);
4156
4157 vecConstantColumnConstantValue = OctopusXMLUtil.importValue(doc,
4158 "constantColumn", "constantValue", iJobNumber, null);
4159 this.vecRelationColumnSourceTableName = OctopusXMLUtil.importValue(
4160 doc, "relationColumn", "relationSourceTableName",
4161 iJobNumber);
4162 this.iRelationColumns = this.vecRelationColumnSourceTableName
4163 .size();
4164 this.vecRelationColumnSourceTableID = OctopusXMLUtil.importValue(
4165 doc, "relationColumn", "relationSourceTableID", iJobNumber);
4166 this.vecRelationColumnSourceColumnName = OctopusXMLUtil
4167 .importValue(doc, "relationColumn",
4168 "relationSourceColumnName", iJobNumber);
4169 this.vecRelationColumnTargetTableName = OctopusXMLUtil.importValue(
4170 doc, "relationColumn", "relationTargetTableName",
4171 iJobNumber);
4172 this.vecRelationColumnTargetColumnName = OctopusXMLUtil
4173 .importValue(doc, "relationColumn",
4174 "relationTargetColumnName", iJobNumber);
4175 this.vecRelationColumnTargetTableID = OctopusXMLUtil.importValue(
4176 doc, "relationColumn", "relationTargetTableID", iJobNumber);
4177 this.vecRelationColumnRelationMode = OctopusXMLUtil.importValue(
4178 doc, "relationColumn", "relationMode", iJobNumber);
4179 // rale
4180
4181 ImportDefinitionSourceColumnName = vecValueColumnSourceColumnName;
4182 ImportDefinitionTargetColumnName = vecValueColumnTargetColumnName;
4183
4184 // sinisa 02.03.2003. Add counterColumns
4185 this.counterColumns = new CounterColumns();
4186 this.counterColumns.setLogger(this.logger);
4187 this.counterColumns.resetSubCounterCache();
4188 this.counterColumns.readConstantColumnAttributes(doc, iJobNumber);
4189 this.counterColumns.readConstantColumnsParameters(doc, iJobNumber);
4190 // end sinisa
4191
4192 // sinisa 02.03.2003. Add transformations
4193 this.transformations = new Transformations(this.logger);
4194 // ArrayList transTableNamesIDs =
4195 // this.transformations.getTransformationsTableNamesAndIDs();
4196 this.transformations.createTransformationElements(doc, iJobNumber);
4197 ArrayList trans = this.transformations.getTransformations();
4198 Iterator iTrans = trans.iterator();
4199
4200 while (iTrans.hasNext()) {
4201 Transformation temp = (Transformation) iTrans.next();
4202 temp.setLogger(this.logger);
4203
4204 // temp.readSourceColumns(doc, iJobNumber);
4205 // temp.readTargetColumns(doc, iJobNumber);
4206 // temp.readSourceColumns();
4207 // temp.readTargetColumns();
4208
4209 }
4210
4211 // end sinisa
4212
4213 this.vecTableTableName = OctopusXMLUtil.importValue(doc, "table",
4214 "tableName", iJobNumber);
4215 this.iTables = this.vecTableTableName.size();
4216 this.vecTableTableID = OctopusXMLUtil.importValue(doc, "table",
4217 "tableID", iJobNumber);
4218 this.vecTableInsert = OctopusXMLUtil.importValue(doc, "table",
4219 "insert", iJobNumber);
4220 this.vecTableTableMode = OctopusXMLUtil.importValue(doc, "table",
4221 "tableMode", iJobNumber, loaderJobReader
4222 .getDefaultTableMode());
4223 this.vecTableOidLogic = OctopusXMLUtil.importValue(doc, "table",
4224 "oidLogic", iJobNumber, (new Boolean(loaderJobReader
4225 .getDefaultOidLogic())).toString());
4226
4227 this.vecCTAutoMapp = OctopusXMLUtil.importValue(doc, "table",
4228 "autoMapColumns", iJobNumber);
4229 this.vecCTDefaultMode = OctopusXMLUtil.importValue(doc, "table",
4230 "defaultMode", iJobNumber);
4231 } // senka added : end of if (isImportDefinition)
4232 if (this.vecRelationColumnSourceTableName.size() != 0) {
4233 this.changeRelationsOrder();
4234 this.changeTableOrder();
4235 }
4236 this.vecRelationKeyColumns.setSize(this.iTables);
4237 this.vecRelationKeyTypes.setSize(this.iTables);
4238 this.vecConstantTargetColumnName.setSize(this.iTables);
4239 // ZK added this
4240 // this.transformationsColumnNames.setSize(this.iTables);
4241
4242 this.vecConstantValueMode.setSize(this.iTables);
4243 this.vecConstantConstantValue.setSize(this.iTables);
4244 this.vecConstantColumnType.setSize(this.iTables);
4245 for (int k = 0; k < vecValueColumnTargetTableName.size(); k++) {
4246 boolean isImportColumn = false;
4247 for (int l = 0; l < this.iTables; l++) {
4248 if (vecValueColumnTargetTableName.get(k).toString()
4249 .equalsIgnoreCase(
4250 this.vecTableTableName.get(l).toString())
4251 && vecValueColumnTargetTableID.get(k).toString()
4252 .equalsIgnoreCase(
4253 this.vecTableTableID.get(l)
4254 .toString())) {
4255 isImportColumn = true;
4256 }
4257 }
4258 if (!isImportColumn) {
4259 this.logger.write("normal",
4260 "Incorrect XML import variables - TABLE ID");
4261 LoaderException le = new LoaderException(
4262 "Exception: ",
4263 (Throwable) (new Exception(
4264 "Incorrect XML import variables - TABLE ID")));
4265 this.logger.write("full", le.getStackTraceAsString());
4266 throw le;
4267 }
4268 }
4269
4270 if (this.vecVariableUseIDTableName.size() != 0) {
4271 String tempUserID = this.vecTempUserID.get(0).toString();
4272 if (userIDExists)
4273 this.strUserID = "";
4274 if (this.strUserID.equals("")) {
4275 if (!tempUserID.equalsIgnoreCase("")) {
4276 this.strUserID = tempUserID;
4277 this.userIDExists = true;
4278 } else {
4279 this.logger.write("normal",
4280 "Error : User parametar missing");
4281 LoaderException le = new LoaderException("Exception: ",
4282 (Throwable) (new Exception(
4283 "Error : User parametar missing")));
4284 this.logger.write("full", le.getStackTraceAsString());
4285 throw le;
4286 }
4287 }
4288 }
4289 for (int k = 0; k < this.iTables; k++) {
4290 iNumberOfColumns = 0;
4291 Vector vecTargetTable1 = new Vector();
4292 Vector vecTargetTable2 = new Vector();
4293 Vector vecTargetTable3 = new Vector();
4294 Vector vecTargetTable4 = new Vector();
4295 Vector vecTargetTable5 = new Vector();
4296 Vector vecTargetTable6 = new Vector();
4297 Vector vecTargetTable7 = new Vector();
4298 Vector vecTargetTable8 = new Vector();
4299 Vector vecTargetTable9 = new Vector();
4300 Vector vecTargetTable10 = new Vector();
4301 Vector vecTargetTable11 = new Vector();
4302
4303 for (int l = 0; l < this.iValueColumns; l++) {
4304 if (this.vecTableTableName.get(k).toString()
4305 .equalsIgnoreCase(
4306 vecValueColumnTargetTableName.get(l)
4307 .toString())
4308 && vecValueColumnTargetTableID.get(l).toString()
4309 .equalsIgnoreCase(
4310 this.vecTableTableID.get(k)
4311 .toString())) {
4312 iNumberOfColumns++;
4313 vecTargetTable1
4314 .addElement(vecValueColumnSourceColumnName.get(
4315 l).toString());
4316 vecTargetTable2
4317 .addElement(vecValueColumnTargetColumnName.get(
4318 l).toString());
4319 vecTargetTable4.addElement(vecValueColumnValueMode.get(
4320 l).toString());
4321 // rale
4322 vecTargetTable9.addElement(vecDefaultValueTemp.get(l)
4323 .toString());
4324 vecTargetTable10.addElement(vecToHexTemp.get(l)
4325 .toString());
4326 vecTargetTable11.addElement(vecFromHexTemp.get(l)
4327 .toString());
4328 if (vecValueColumnValueMode.get(l).toString()
4329 .equalsIgnoreCase("Key"))
4330 vecTargetTable5
4331 .addElement(vecValueColumnTargetColumnName
4332 .get(l).toString());
4333 }
4334 }
4335 for (int l = 0; l < this.vecVariableUseIDTableName.size(); l++) {
4336 if (this.vecTableTableName.get(k).toString()
4337 .equalsIgnoreCase(
4338 this.vecVariableUseIDTableName.get(l)
4339 .toString())
4340 && this.vecVariableUseIDTableID.get(l).toString()
4341 .equalsIgnoreCase(
4342 this.vecTableTableID.get(k)
4343 .toString())) {
4344 vecTargetTable2
4345 .addElement(this.vecVariableUseIDColumnName
4346 .get(l).toString());
4347 vecTargetTable4
4348 .addElement(this.vecVariableUseIDValueMode.get(
4349 l).toString());
4350 // rale
4351 // vecTargetTable9.addElement(vecDefaultValueTemp.get(l).toString());
4352 // vecTargetTable10.addElement(vecToHexTemp.get(l).toString());
4353 // vecTargetTable11.addElement(vecFromHexTemp.get(l).toString());
4354
4355 if (this.vecVariableUseIDValueMode.get(l).toString()
4356 .equalsIgnoreCase("Key"))
4357 vecTargetTable5
4358 .addElement(this.vecVariableUseIDColumnName
4359 .get(l).toString());
4360 }
4361 }
4362 for (int l = 0; l < this.vecRelationColumnSourceColumnName
4363 .size(); l++) {
4364 if (this.vecTableTableName.get(k).toString()
4365 .equalsIgnoreCase(
4366 this.vecRelationColumnTargetTableName
4367 .get(l).toString())
4368 && this.vecRelationColumnTargetTableID.get(l)
4369 .toString().equalsIgnoreCase(
4370 this.vecTableTableID.get(k)
4371 .toString())
4372 && this.vecRelationColumnRelationMode.get(l)
4373 .toString().equalsIgnoreCase("Key")) {
4374 vecTargetTable3
4375 .addElement(this.vecRelationColumnTargetColumnName
4376 .get(l).toString());
4377 }
4378 }
4379
4380 // rale
4381 this.vecToHex.addElement(vecToHexTemp);
4382 this.vecFromHex.addElement(vecFromHexTemp);
4383 this.vecDefaultValue.addElement(vecTargetTable9);
4384 this.vecSourceColumnName.addElement(vecTargetTable1);
4385 this.vecTargetColumnName.addElement(vecTargetTable2);
4386 this.vecRelationKeyColumns.setElementAt(vecTargetTable3, k);
4387 this.vecValueMode.addElement(vecTargetTable4);
4388 this.vecTargetKeyColumnName.addElement(vecTargetTable5);
4389 this.vecValueColumnsTargetTables.addElement(new Integer(
4390 iNumberOfColumns));
4391 for (int p = 0; p < this.iConstantColumns; p++) {
4392 if (this.vecTableTableName.get(k).toString()
4393 .equalsIgnoreCase(
4394 this.vecConstantColumnTargetTableName
4395 .get(p).toString())
4396 && this.vecConstantColumnTargetTableID.get(p)
4397 .toString().equalsIgnoreCase(
4398 this.vecTableTableID.get(k)
4399 .toString())) {
4400 vecTargetTable6
4401 .addElement(vecConstantColumnTargetColumnName
4402 .get(p).toString());
4403 vecTargetTable7.addElement(vecConstantColumnValueMode
4404 .get(p).toString());
4405 if (vecConstantColumnConstantValue.get(p) == null)
4406 vecTargetTable8.addElement(null);
4407 else
4408 vecTargetTable8
4409 .addElement(vecConstantColumnConstantValue
4410 .get(p).toString());
4411 }
4412 }
4413 this.vecConstantTargetColumnName.setElementAt(vecTargetTable6,
4414 k);
4415 this.vecConstantValueMode.setElementAt(vecTargetTable7, k);
4416 this.vecConstantConstantValue.setElementAt(vecTargetTable8, k);
4417
4418 // sinisa 02.03.2003. Add counterColumns
4419
4420 this.counterColumns.setConstantColumnsParameters(
4421 this.vecTableTableName.get(k).toString(),
4422 this.vecTableTableID.get(k).toString());
4423 // end sinisa
4424 }
4425
4426 for (int i = 0; i < this.vecRelationColumnSourceColumnName.size(); i++) {
4427 if (this.vecRelationColumnSourceColumnName.get(i).toString()
4428 .equals("")) {
4429 for (int k = 0; k < this.vecTableTableName.size(); k++) {
4430 if (this.vecRelationColumnSourceTableName.get(i)
4431 .toString().equalsIgnoreCase(
4432 this.vecTableTableName.get(k)
4433 .toString())
4434 && this.vecRelationColumnSourceTableID.get(i)
4435 .toString().equalsIgnoreCase(
4436 this.vecTableTableID.get(k)
4437 .toString())) {
4438 if (this.vecTableOidLogic.get(k).toString()
4439 .equalsIgnoreCase("true"))
4440 this.vecRelationColumnSourceColumnName
4441 .setElementAt(
4442 this.currentOidColumnName, i);
4443 // this.vecRelationColumnSourceColumnName.setElementAt("oid",i);
4444 }
4445 }
4446 }
4447 }
4448 this.vecRelationSourceValue.setSize(this.iRelationColumns);
4449 this.vecRelationSourceType.setSize(this.iRelationColumns);
4450 } catch (NullPointerException ex) {
4451 throw ex;
4452 } catch (Exception ex) {
4453 throw ex;
4454 }
4455 this.logger.write("full", "\timportXMLFile method is finished.");
4456 }
4457
4458 /***
4459 * Method updateCurrentTime write system time into timeStamp variable
4460 * columns
4461 *
4462 * @param c
4463 * Connection to the target table.
4464 * @param iTable
4465 * Number of target table.
4466 * @param strQueryWhereSQL
4467 * Part of SQL query - where clause.
4468 * @param currentVersion
4469 * represents current version of insert/update
4470 * @param oid
4471 * repersents if the oid logic is present
4472 * @throws SQLException
4473 * @throws NullPointerException
4474 * @return true if something is written to database
4475 */
4476 private boolean updateCurrentTime(Connection c, int iTable,
4477 String strQueryWhereSQL, int currentVersion, boolean oid)
4478 throws SQLException, NullPointerException {
4479 String strQueryInsertTime = "";
4480 boolean bWriteData = false;
4481 String oidVersion = "";
4482 // if (oid)
4483 // oidVersion = ", version=" + currentVersion;
4484 if (oid)
4485 oidVersion = ", " + this.currentVersionColumnName + "="
4486 + currentVersion;
4487 this.logger.write("full", "\t updateCurrentTime method is started.");
4488 try {
4489 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
4490 if (this.vecVariableTimesTableName.get(i).toString()
4491 .equalsIgnoreCase(
4492 this.vecTableTableName.get(iTable).toString())
4493 && this.vecVariableTimesTableID.get(i).toString()
4494 .equalsIgnoreCase(
4495 this.vecTableTableID.get(iTable)
4496 .toString())) {
4497 Statement stmtRelations = c.createStatement();
4498 strQueryInsertTime = "update "
4499 + this.vecVariableTimesTableName.get(i).toString()
4500 + " set "
4501 + this.vecVariableTimesColumnName.get(i).toString()
4502 + " = ";
4503 if (this.vecVariableTimesValueMode.get(i).toString()
4504 .equalsIgnoreCase("Overwrite"))
4505
4506 // && bWriteData == true)
4507 strQueryInsertTime += " '" + this.createCurrentDate()
4508 + "'" + oidVersion + " where "
4509 + strQueryWhereSQL;
4510 else
4511 strQueryInsertTime += " '"
4512 + this.createCurrentDate()
4513 + "'"
4514 + oidVersion
4515 + " where "
4516 + this.vecVariableTimesColumnName.get(i)
4517 .toString() + " is null and "
4518 + strQueryWhereSQL;
4519 this.logger.write("full", "\tQuery '" + strQueryInsertTime
4520 + "' will be executed");
4521 if (bReplaceInData) {
4522 strQueryInsertTime = this
4523 .replaceInData(strQueryInsertTime);
4524 }
4525 int num = stmtRelations.executeUpdate(strQueryInsertTime);
4526 if (num != 0) {
4527 bWriteData = true;
4528 }
4529 stmtRelations.close();
4530 }
4531 }
4532 } catch (SQLException ex) {
4533 throw ex;
4534 } catch (NullPointerException ex) {
4535 throw ex;
4536 }
4537 this.logger.write("full", "\tupdateCurrentTime method is finished.");
4538 return bWriteData;
4539 }
4540
4541 /***
4542 * Method updateNameValue writes nameValue value (Loader's argument) into
4543 * variable columns
4544 *
4545 * @param c
4546 * Connection to the target table.
4547 * @param iTable
4548 * Number of target table.
4549 * @param strQueryWhereSQL
4550 * Part of SQL query - where clause.
4551 * @param currentVersion
4552 * represents current version of insert/update
4553 * @param oid
4554 * define if oid logic is present
4555 * @throws SQLException
4556 * @throws NullPointerException
4557 * @throws LoaderException
4558 * @return true if something is written to database
4559 */
4560 private boolean updateNameValue(Connection c, int iTable,
4561 String strQueryWhereSQL, int currentVersion, boolean oid)
4562 throws SQLException, NullPointerException, LoaderException {
4563
4564 String strQueryInsertName = "";
4565 boolean bWriteData = false;
4566 String oidVersion = "";
4567 // if (oid)
4568 // oidVersion = ", version=" + currentVersion;
4569 if (oid)
4570 oidVersion = ", " + this.currentVersionColumnName + "="
4571 + currentVersion;
4572
4573 this.logger.write("full", "\t updateNameValue method is started.");
4574 try {
4575 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) {
4576 boolean bInsert = true;
4577 if (this.vecVariableColumnTargetTableName.get(i).toString()
4578 .equalsIgnoreCase(
4579 this.vecTableTableName.get(iTable).toString())
4580 && this.vecVariableColumnTargetTableID.get(i)
4581 .toString().equalsIgnoreCase(
4582 this.vecTableTableID.get(iTable)
4583 .toString())) {
4584 int iPositionInVector = this.vecVariableName
4585 .indexOf(this.vecVariableColumnName.get(i)
4586 .toString());
4587 if (iPositionInVector != -1) {
4588 Statement stmtRelations = c.createStatement();
4589 strQueryInsertName = "update "
4590 + this.vecVariableColumnTargetTableName.get(i)
4591 .toString()
4592 + " set "
4593 + this.vecVariableColumnTargetColumnName.get(i)
4594 .toString() + " = ";
4595 if (this.vecVariableColumnValueMode.get(i).toString()
4596 .equalsIgnoreCase("Overwrite")) {
4597 if (this.vecVariableValue.get(iPositionInVector) == null) {
4598 String variableName = this.vecVariableColumnName
4599 .get(i).toString();
4600 for (int k = 0; k < this.vecDefaultVariableName
4601 .size(); k++) {
4602 if (this.vecDefaultVariableName.get(k)
4603 .toString().equalsIgnoreCase(
4604 variableName)) {
4605 if (!this.vecDefaultVariableValue
4606 .get(k).toString()
4607 .equalsIgnoreCase("")) {
4608 // if
4609 // (!CheckType.isNumber(this.vecVariableColumnTypes.get(i).
4610 // toString()))
4611 // ZK change this from CheckType to
4612 // configReaderTarget this 7.5.2004
4613
4614 if (!configReaderTarget
4615 .isNumber(this.vecVariableColumnTypes
4616 .get(i).toString()))
4617
4618 strQueryInsertName += " '"
4619 + this.vecDefaultVariableValue
4620 .get(k)
4621 .toString()
4622 + "' " + oidVersion
4623 + " where "
4624 + strQueryWhereSQL;
4625 else
4626 strQueryInsertName += " "
4627 + this.vecDefaultVariableValue
4628 .get(k) + " "
4629 + oidVersion
4630 + " where "
4631 + strQueryWhereSQL;
4632
4633 } else {
4634 strQueryInsertName += " null"
4635 + oidVersion + " where "
4636 + strQueryWhereSQL;
4637 }
4638 break;
4639 }
4640 }
4641 } else {
4642 // ZK change this from CheckType to
4643 // configReaderTarget this 7.5.2004
4644 if (!configReaderTarget
4645 .isNumber(this.vecVariableColumnTypes
4646 .get(i).toString()))
4647 strQueryInsertName += " '"
4648 + this.vecVariableValue.get(
4649 iPositionInVector)
4650 .toString() + "'"
4651 + oidVersion + " where "
4652 + strQueryWhereSQL;
4653 else
4654 strQueryInsertName += this.vecVariableValue
4655 .get(iPositionInVector).toString()
4656 + oidVersion
4657 + " where "
4658 + strQueryWhereSQL;
4659 }
4660 } else if (this.vecVariableColumnValueMode.get(i)
4661 .toString().equalsIgnoreCase("SetNull")) {
4662 if (this.vecVariableValue.get(iPositionInVector) == null)
4663 strQueryInsertName += " null" + oidVersion
4664 + " where " + strQueryWhereSQL;
4665 else
4666 bInsert = false;
4667 } else {
4668 if (this.vecVariableValue.get(iPositionInVector) == null) {
4669 String variableName = this.vecVariableColumnName
4670 .get(i).toString();
4671 for (int k = 0; k < this.vecDefaultVariableName
4672 .size(); k++) {
4673 if (this.vecDefaultVariableName.get(k)
4674 .toString().equalsIgnoreCase(
4675 variableName)) {
4676 if (!this.vecDefaultVariableValue
4677 .get(k).toString()
4678 .equalsIgnoreCase("")) {
4679 // ZK change this from CheckType to
4680 // configReaderTarget this 7.5.2004
4681 if (!configReaderTarget
4682 .isNumber(this.vecVariableColumnTypes
4683 .get(i).toString()))
4684 strQueryInsertName += " '"
4685 + this.vecDefaultVariableValue
4686 .get(k)
4687 .toString()
4688 + "' "
4689 + oidVersion
4690 + " where "
4691 + this.vecVariableColumnTargetColumnName
4692 .get(i)
4693 .toString()
4694 + " is null and "
4695 + strQueryWhereSQL;
4696 else
4697 strQueryInsertName += " "
4698 + this.vecDefaultVariableValue
4699 .get(k)
4700 + " "
4701 + oidVersion
4702 + " where "
4703 + this.vecVariableColumnTargetColumnName
4704 .get(i)
4705 .toString()
4706 + " is null and "
4707 + strQueryWhereSQL;
4708 } else {
4709 strQueryInsertName += " null"
4710 + oidVersion
4711 + " where "
4712 + this.vecVariableColumnTargetColumnName
4713 .get(i).toString()
4714 + " is null and "
4715 + strQueryWhereSQL;
4716 }
4717 break;
4718 }
4719 }
4720 } else {
4721 // ZK change this from CheckType to
4722 // configReaderTarget this 7.5.2004
4723 if (!configReaderTarget
4724 .isNumber(this.vecVariableColumnTypes
4725 .get(i).toString()))
4726 strQueryInsertName += " '"
4727 + this.vecVariableValue.get(
4728 iPositionInVector)
4729 .toString()
4730 + "'"
4731 + oidVersion
4732 + " where "
4733 + this.vecVariableColumnTargetColumnName
4734 .get(i).toString()
4735 + " is null and "
4736 + strQueryWhereSQL;
4737 else
4738 strQueryInsertName += this.vecVariableValue
4739 .get(iPositionInVector).toString()
4740 + oidVersion
4741 + " where "
4742 + this.vecVariableColumnTargetColumnName
4743 .get(i).toString()
4744 + " is null and "
4745 + strQueryWhereSQL;
4746 }
4747 }
4748 if (bInsert)
4749 this.logger
4750 .write("full", "\tQuery '"
4751 + strQueryInsertName
4752 + "' will be executed");
4753
4754 if (bReplaceInData) {
4755 strQueryInsertName = this
4756 .replaceInData(strQueryInsertName);
4757 }
4758 if (bInsert) {
4759 int num = 0;
4760 try {
4761 num = stmtRelations
4762 .executeUpdate(strQueryInsertName);
4763 } catch (SQLException ex) {
4764 stmtRelations.close();
4765 stmtRelations = c.createStatement();
4766 if ((importDefinitionElement.strDefaultCutOffData
4767 .equalsIgnoreCase("true"))) {
4768 dataCleaning
4769 .cutingDataLenghtUpdate(
4770 this.vecTableTableName.get(
4771 iTable).toString(),
4772 c,
4773 "",
4774 currentRow,
4775 strQueryInsertName,
4776 importDefinitionElement.strOnErrorContinueXml,
4777 importDefinitionElement.strImportDefinitionName,
4778 strQueryInsertName);
4779 } else
4780 throw ex;
4781 }
4782 }
4783 // stmtRelations.close();
4784 } else {
4785 this.logger.write("normal",
4786 "\tError: Cannot find value for variable column :"
4787 + this.vecVariableColumnName.get(i)
4788 .toString());
4789 LoaderException le = new LoaderException(
4790 "Exception: ",
4791 (Throwable) (new Exception(
4792 "Error: Cannot find value for variable column :")));
4793 this.logger.write("full", le.getStackTraceAsString());
4794 throw le;
4795 }
4796 }
4797 }
4798 } catch (SQLException ex) {
4799 throw ex;
4800 } catch (NullPointerException ex) {
4801 throw ex;
4802 }
4803 this.logger.write("full", "\tupdateNameValue method is finished.");
4804 return bWriteData;
4805 }
4806
4807 /***
4808 * Method queryRelations is used to make SQL query for reading source value
4809 * for relations between target tables. It puts the value from the source
4810 * column in source relation table to the target column in target relation
4811 * table. If there is an error, Exception "SQLException" or
4812 * NullPointerException is thrown.
4813 *
4814 * @param iTableInt
4815 * Number of target table.
4816 * @param iNumberOfRelationColumn
4817 * Number of relation tag.
4818 * @param strQueryWhere
4819 * Part of SQL query - where clause.
4820 * @param conn
4821 * represents connection to target database
4822 * @param currentVersion
4823 * represents currnet version of insert/update
4824 * @param oid
4825 * define if oid logic is present
4826 * @return String which will be executed for update or insert relation
4827 * columns into target tables
4828 * @throws NullPointerException
4829 * Constructs a NullPointerException with the specified detail
4830 * message.
4831 * @throws LoaderException
4832 */
4833 private String queryRelations(int iTableInt, int iNumberOfRelationColumn,
4834 String strQueryWhere, Connection conn, int currentVersion,
4835 boolean oid) throws NullPointerException, LoaderException {
4836 this.logger.write("full", "\tqueryRelations method is started.");
4837 String strQueryRelations = "";
4838 String oidVersion = "";
4839 String selectValueInRel = "";
4840 String currentValueInRel = "";
4841 // if (oid)
4842 // oidVersion = ", version=" + currentVersion;
4843 if (oid)
4844 oidVersion = ", " + this.currentVersionColumnName + "="
4845 + currentVersion;
4846
4847 try {
4848 strQueryRelations = "update "
4849 + this.vecRelationColumnTargetTableName.get(
4850 iNumberOfRelationColumn).toString()
4851 + " set "
4852 + this.vecRelationColumnTargetColumnName.get(
4853 iNumberOfRelationColumn).toString();
4854 if (this.vecRelationSourceValue.get(iNumberOfRelationColumn) == null) {
4855 String replacementValueInRel = vecDefaultRelationValue.get(
4856 iNumberOfRelationColumn).toString();
4857 if (!replacementValueInRel.equalsIgnoreCase("")) {
4858 try {
4859 Statement stmt = conn.createStatement();
4860 ResultSet newRelationValue;
4861 String relationValue;
4862 boolean isFull = false;
4863 if (!replacementValueInRel
4864 .equalsIgnoreCase(selectValueInRel)) {
4865 selectValueInRel = replacementValueInRel;
4866 newRelationValue = stmt
4867 .executeQuery(replacementValueInRel);
4868 isFull = newRelationValue.next();
4869 if (isFull) {
4870 relationValue = newRelationValue.getString(1);
4871 currentValueInRel = relationValue;
4872 } else {
4873 relationValue = "";
4874 currentValueInRel = "";
4875 }
4876 newRelationValue.close();
4877 } else {
4878 if (!currentValueInRel.equalsIgnoreCase("")
4879 && currentValueInRel != null) {
4880 relationValue = currentValueInRel;
4881 isFull = true;
4882 } else {
4883 relationValue = "";
4884 }
4885 }
4886 if (isFull) {
4887 strQueryRelations += dataCleaning
4888 .cleaningRelationValues(
4889 this.vecTableTableName.get(
4890 iTableInt).toString(),
4891 this.vecRelationColumnTargetColumnName
4892 .get(
4893 iNumberOfRelationColumn)
4894 .toString(),
4895 relationValue,
4896 this.vecRelationSourceType.get(
4897 iNumberOfRelationColumn)
4898 .toString(),
4899 currentRow,
4900 conn,
4901 "UPDATE",
4902 currentVersion,
4903 oid,
4904 importDefinitionElement.strImportDefinitionName,
4905 this.currentVersionColumnName,
4906 replacementValueInRel);
4907
4908 } else {
4909 dataCleaning
4910 .cleaningInsert(
4911 this.vecTableTableName.get(
4912 iTableInt).toString(),
4913 conn,
4914 currentRow,
4915 "UPDATE",
4916 "Default value '"
4917 + replacementValueInRel
4918 + "' for relations is not valid.",
4919 importDefinitionElement.strImportDefinitionName,
4920 replacementValueInRel);
4921 strQueryRelations += " = null " + oidVersion
4922 + " where ";
4923 }
4924 } catch (SQLException ex) {
4925 String msg = "Default value for foreign key("
4926 + replacementValueInRel
4927 + ") is not valid. Import definition name: "
4928 + importDefinitionElement.strImportDefinitionName;
4929 LoaderException le = new LoaderException(
4930 "SQLException: " + msg, (Throwable) ex);
4931 this.logger.write("full", le.getStackTraceAsString());
4932 throw le;
4933 }
4934
4935 } else
4936 strQueryRelations += " = null " + oidVersion + " where ";
4937 } else {
4938 // TODO Check this part of code. ZK change from
4939 // configReaderSource to configReaderTarget because of problems
4940 // with relation columns.
4941 if (configReaderTarget.isNumber(this.vecRelationSourceType.get(
4942 iNumberOfRelationColumn).toString())) {
4943 strQueryRelations += " = "
4944 + this.vecRelationSourceValue.get(
4945 iNumberOfRelationColumn).toString()
4946 + oidVersion + " where ";
4947 } else {
4948 strQueryRelations += " = ";
4949 if (configReaderTarget.isWithN(this.vecRelationSourceType
4950 .get(iNumberOfRelationColumn).toString())) {
4951 strQueryRelations += "N";
4952 }
4953 strQueryRelations += "'"
4954 + this.vecRelationSourceValue.get(
4955 iNumberOfRelationColumn).toString() + "'"
4956 + oidVersion + " where ";
4957 }
4958
4959 }
4960 strQueryRelations += strQueryWhere;
4961 if (strQueryRelations.trim().endsWith("where"))
4962 strQueryRelations = strQueryRelations.substring(0,
4963 strQueryRelations.length() - 6);
4964 else {
4965 if (!this.vecRelationColumnRelationMode.get(
4966 iNumberOfRelationColumn).toString().equalsIgnoreCase(
4967 "overwrite")) {
4968 // ||
4969 // !this.vecRelationColumnRelationMode.get(iNumberOfRelationColumn).toString().
4970 // equalsIgnoreCase("SetIfCreated")) {
4971
4972 strQueryRelations += " and "
4973 + this.vecRelationColumnTargetColumnName.get(
4974 iNumberOfRelationColumn).toString()
4975 + " is null";
4976 }
4977 }
4978 } catch (NullPointerException ex) {
4979 throw ex;
4980 }
4981 this.logger.write("full", "\tqueryRelations method is finished.");
4982 return strQueryRelations;
4983 }
4984
4985 /***
4986 * Method insertTargetTable is used to put one row of data from columns of
4987 * source tables into target table ordered by column modes. If there is an
4988 * error, Exception "SQLException, "NullPointerException" or "Exception" is
4989 * thrown.
4990 *
4991 * @param iTableInt
4992 * Number of the target table which is processed.
4993 * @param vecColumnValues
4994 * One row of values from the source table.
4995 * @param vecColumnNames
4996 * Vector of column names in a target table.
4997 * @param vecColumnMode
4998 * Modes of columns in the target table.
4999 * @param vecColumnTypes
5000 * Types of columns in the target table.
5001 * @param c
5002 * Connection to the target database.
5003 * @throws SQLException
5004 * Constructs an SQLException object with a reason.
5005 * @throws NullPointerException
5006 * Constructs a NullPointerException with the specified detail
5007 * message.
5008 * @throws Exception
5009 * Constructs an Exception with the specified detail message.
5010 */
5011 private void insertTargetTable(int iTableInt, Vector vecColumnValues,
5012 Vector vecColumnNames, Vector vecColumnMode, Vector vecColumnTypes,
5013 Connection c, Vector vecTransformationValue,
5014 Vector transTargetColumnTypes) throws SQLException,
5015 NullPointerException, Exception {
5016
5017 this.logger.write("full", "\tinsertTargetTable method is started.");
5018 boolean bInsertTable = false;
5019 int iVersionValue = 0;
5020 int iVersionMax = 0;
5021 boolean bWriteData = false;
5022 String strQueryWhere = "";
5023 String strQuery = new String("select ");
5024 // for handling exception in FK (data cleanining)
5025 String exceptionInRelations = "";
5026 String replacementValueInRel = "";
5027 String replacementTable = "";
5028 String replacementColumn = "";
5029 // String replacementColumnType = "";
5030 boolean relationIsOk = false;
5031 boolean updateQueryIsOk = false;
5032 boolean updateConstantIsOk = false;
5033 String strQueryConstantApendix = "";
5034
5035 boolean bOidLogicCurrentTable = new Boolean(this.vecTableOidLogic.get(
5036 iTableInt).toString()).booleanValue();
5037 boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
5038 .equals("") || importDefinitionElement.strObjectIDNameColumnValue
5039 .equals(""));
5040 boolean oid = false;
5041 if (bOidLogicCurrentTable && !isTOS)
5042 oid = true;
5043
5044 Vector vecTempKeyColumns = (Vector) this.vecTargetKeyColumnName
5045 .get(iTableInt);
5046
5047 String key = String.valueOf(iTableInt);
5048 String query = (String) queryStatement.get(key);
5049 // System.out.println("query="+query);
5050 String update = (String) updateStatement.get(key);
5051 String updateConstant = (String) updateConstantStatement.get(key);
5052
5053 String updateTransformation = (String) updateTransformationStatement
5054 .get(key);
5055
5056 // updateTransformation =
5057 // (String)this.updateTransformationStatement.get(key);
5058 Statement stmtTarget = null;
5059 // ZK added this. If (select something from ... )is valid (contains oid,
5060 // version and more) then do insert
5061 // String query1 = (String)queryStatement.get(key);
5062 // System.out.println("query="+query);
5063 // boolean isValidStmt = validStmt.checkStatement(query);
5064 // System.out.println("isValidStmt="+isValidStmt);
5065 String logStatement = "";
5066 try {
5067 // if (isValidStmt){
5068 if (query.indexOf(" where ") == -1) {
5069 this.insertRow(c, vecColumnValues, vecColumnTypes,
5070 vecColumnNames, vecColumnMode, bOidLogicCurrentTable,
5071 iTableInt, vecTransformationValue,
5072 transTargetColumnTypes);
5073 bInsertTable = true;
5074 } else {
5075 Vector dv = (Vector) indexDValue.get(key);
5076 Vector drv = (Vector) indexDRelationValue.get(key);
5077 Vector dcv = (Vector) indexConstantDValue.get(key);
5078 Vector dvv = (Vector) indexDVariableValue.get(key);
5079 Vector dtv = (Vector) indexDTransformationValue.get(key);
5080
5081 if (dv.size() > 0) {
5082 for (int i = 0; i < dv.size(); i++) {
5083 int index = Integer.parseInt(dv.get(i).toString());
5084 if (vecColumnValues.get(index) == null) {
5085 int str = query.indexOf("'dummyValue'");
5086 int num = query.indexOf("dummyValue");
5087 if (str != -1 && (num == -1 || str < num))
5088 query = replaceFirst(query, "= 'dummyValue'",
5089 " is null ");
5090 else
5091 query = replaceFirst(query, "= dummyValue",
5092 " is null ");
5093 } else {
5094 query = replaceFirst(query, "dummyValue",
5095 vecColumnValues.get(index).toString());
5096 }
5097 }
5098 }
5099 if (drv.size() > 0) {
5100 for (int i = 0; i < drv.size(); i++) {
5101 int index = Integer.parseInt(drv.get(i).toString());
5102 int str = query.indexOf("'dummyRelationValue'");
5103 int num = query.indexOf("dummyRelationValue");
5104 if ((this.vecRelationSourceValue.get(index) == null) ||
5105 (this.vecRelationSourceValue.get(index).toString() == "null")) {
5106 // int str = query.indexOf("'dummyRelationValue'");
5107 // int num = query.indexOf("dummyRelationValue");
5108 if (str != -1 && (num == -1 || str < num))
5109 query = replaceFirst(query,
5110 "= 'dummyRelationValue'", " is null ");
5111 else
5112 query = replaceFirst(query,
5113 "= dummyRelationValue", " is null ");
5114 } else {
5115 //query = replaceFirst(query, "dummyRelationValue",
5116 // this.vecRelationSourceValue.get(index)
5117 // .toString());
5118 // senka change
5119 String relValues=this.vecRelationSourceValue.get(index).toString();
5120 if (relValues.startsWith(" IN")) {
5121 if (str != -1 && (num == -1 || str < num))
5122 query = replaceFirst(query, "= 'dummyRelationValue'",relValues);
5123 else
5124 query = replaceFirst(query, "= dummyRelationValue",relValues);
5125 }else{
5126 query = replaceFirst(query, "dummyRelationValue",relValues);
5127 }
5128 }
5129 }
5130 }
5131
5132 Vector vecTempConstantColumns = (Vector) this.vecConstantTargetColumnName
5133 .get(iTableInt);
5134 Vector vecTempConstantValues = (Vector) this.vecConstantConstantValue
5135 .get(iTableInt);
5136 Vector vecTempConstantMode = (Vector) this.vecConstantValueMode
5137 .get(iTableInt);
5138 Vector vecTempConstantType = (Vector) this.vecConstantColumnType
5139 .get(iTableInt);
5140 // ZK added 19.4.2004
5141
5142 // Vector vecTempTransformationValues = (Vector)
5143 // vecTransformationValue.get(iTableInt);
5144
5145 if (dcv.size() > 0) {
5146 for (int i = 0; i < dcv.size(); i++) {
5147 int index = Integer.parseInt(dcv.get(i).toString());
5148 if (vecTempConstantValues.get(index) == null) {
5149 int str = query.indexOf("'dummyConstantValue'");
5150 int num = query.indexOf("dummyConstantValue");
5151 if (str != -1 && (num == -1 || str < num))
5152 query = replaceFirst(query,
5153 "= 'dummyConstantValue'", " is null ");
5154 else
5155 query = replaceFirst(query,
5156 "= dummyConstantValue", " is null ");
5157 } else {
5158 query = replaceFirst(query, "dummyConstantValue",
5159 vecTempConstantValues.get(index).toString());
5160 }
5161 }
5162 }
5163
5164 if (dvv.size() > 0) {
5165 for (int i = 0; i < dvv.size(); i++) {
5166 int index = Integer.parseInt(dvv.get(i).toString());
5167 if (vecVariableValue.get(index) == null) {
5168 int str = query.indexOf("'dummyVariableValue'");
5169 int num = query.indexOf("dummyVariableValue");
5170 if (str != -1 && (num == -1 || str < num))
5171 query = replaceFirst(query,
5172 "= 'dummyVariableValue'", " is null ");
5173 else
5174 query = replaceFirst(query,
5175 "= dummyVariableValue", " is null ");
5176 } else {
5177 query = replaceFirst(query, "dummyVariableValue",
5178 vecVariableValue.get(index).toString());
5179 }
5180 }
5181 }
5182 // ZK added this for transformation. Key colona.
5183 if (dtv.size() > 0) {
5184 for (int i = 0; i < dtv.size(); i++) {
5185 int index = Integer.parseInt(dtv.get(i).toString());
5186 if (vecTransformationValue.get(index) == null) {
5187 int str = query
5188 .indexOf("'dummyTransformationValue'");
5189 int num = query.indexOf("dummyTransformationValue");
5190 if (str != -1 && (num == -1 || str < num))
5191 query = replaceFirst(query,
5192 "= 'dummyTransformationValue'",
5193 " is null ");
5194 else
5195 query = replaceFirst(query,
5196 "= dummyTransformationValue",
5197 " is null ");
5198 } else {
5199 query = replaceFirst(query,
5200 "dummyTransformationValue",
5201 vecTransformationValue.get(index)
5202 .toString());
5203 }
5204 }
5205 }
5206 // ZK end
5207 if (query.indexOf("where") != -1)
5208 strQueryWhere = query.substring(query.indexOf("where") + 5);
5209
5210 stmtTarget = c.createStatement();
5211 boolean rowExist;
5212 if (bOidLogicCurrentTable && !isTOS)
5213 rowExist = this.checkRowCache.getCheckRowValue(query, c,
5214 this.iTargetFirstColumnResult,
5215 this.currentVersionColumnName);
5216 else
5217 rowExist = this.checkRowCache.getCheckRowValue(query, c,
5218 this.iTargetFirstColumnResult, null);
5219
5220 if (!rowExist) {
5221 this.insertRow(c, vecColumnValues, vecColumnTypes,
5222 vecColumnNames, vecColumnMode,
5223 bOidLogicCurrentTable, iTableInt,
5224 vecTransformationValue, transTargetColumnTypes);
5225 bInsertTable = true;
5226 } else { // row exist = true
5227 if (bOidLogicCurrentTable && !isTOS) {
5228 iVersionValue = this.checkRowCache
5229 .getCheckRowVersionValue();
5230 if (iVersionValue > iVersionMax)
5231 iVersionMax = iVersionValue;
5232 }
5233 if (!bInsertTable) {
5234 Vector dOverwrite = (Vector) indexDOverwrite.get(key);
5235 Vector dSetNull = (Vector) indexDSetNull.get(key);
5236
5237 if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere)
5238 .indexOf("UPDATE") != -1)) {
5239 if (dOverwrite.size() > 0) {
5240 int start = 0;
5241 for (int i = 0; i < dOverwrite.size(); i++) {
5242 Vector replacedValue = (Vector) vecDefaultValue
5243 .get(iTableInt);
5244 int index = Integer.parseInt(dOverwrite
5245 .get(i).toString());
5246 if (vecColumnValues.get(index) == null) {
5247 int str = update
5248 .indexOf("'dummyOverwrite'");
5249 int num = update
5250 .indexOf("dummyOverwrite");
5251 if (replacedValue.get(index) != "") {
5252 if (str != -1
5253 && (num == -1 || str < num))
5254 update = replaceFirst(
5255 update,
5256 "'dummyOverwrite'",
5257 " '"
5258 + replacedValue
5259 .get(
5260 index)
5261 .toString()
5262 + "' ");
5263 else
5264 update = replaceFirst(
5265 update,
5266 "dummyOverwrite",
5267 " "
5268 + replacedValue
5269 .get(
5270 index)
5271 .toString()
5272 + " ");
5273
5274 dataCleaning
5275 .cleaningColumnValues(
5276 this.vecTableTableName
5277 .get(
5278 iTableInt)
5279 .toString(),
5280 vecColumnNames.get(
5281 index)
5282 .toString(),
5283 replacedValue.get(
5284 index)
5285 .toString(),
5286 currentRow,
5287 c,
5288 "UPDATE",
5289 importDefinitionElement.strImportDefinitionName);
5290 } else {
5291 if (str != -1
5292 && (num == -1 || str < num)) {
5293 String forReplace = "'dummyOverwrite'";
5294 // patch from mail list
5295 // int thisIndex =
5296 // update.indexOf("N'dummyOverwrite'");
5297 // if (thisIndex != -1 &&
5298 // thisIndex < str)
5299 if (update
5300 .indexOf("N'dummyOverwrite'") != -1)
5301 forReplace = "N'dummyOverwrite'";
5302 update = replaceFirst(update,
5303 forReplace, " null ");
5304 } else {
5305 update = replaceFirst(update,
5306 "dummyOverwrite",
5307 " null ");
5308 }
5309 }
5310 } else {
5311 String replacement = vecColumnValues
5312 .get(index).toString();
5313 start = update.indexOf(
5314 "dummyOverwrite", start);
5315 update = update.substring(0, start)
5316 + replacement
5317 + update.substring(start + 14);
5318 start = replacement.length();
5319 }
5320 }
5321 }
5322 if (dSetNull.size() > 0) {
5323 for (int j = 0; j < dSetNull.size(); j++) {
5324 int index = Integer.parseInt(dSetNull
5325 .get(j).toString());
5326 if (vecColumnValues.get(index) == null) {
5327 update = replaceFirst(update,
5328 "dummySetNull", vecColumnNames
5329 .get(index).toString()
5330 + "=" + " null ");
5331 } else {
5332 update = replaceFirst(update,
5333 "dummySetNull,", "");
5334 }
5335 }
5336 }
5337 if (dOverwrite.size() > 0 || dSetNull.size() > 0) {
5338 if (bWriteData)
5339 update = replaceFirst(update,
5340 "dummyVersionOverwrite", String
5341 .valueOf(iVersionMax));
5342 else
5343 update = replaceFirst(update,
5344 "dummyVersionOverwrite", String
5345 .valueOf(iVersionMax + 1));
5346 if (bReplaceInData) {
5347 update = this.replaceInData(update);
5348 strQueryWhere = this
5349 .replaceInData(strQueryWhere);
5350 }
5351 relationIsOk = true;
5352 updateConstantIsOk = true;
5353 updateQueryIsOk = false;
5354 int iNumRowUp = 0;
5355 // int ver = update.indexOf("version");
5356 int ver = update
5357 .indexOf(this.currentVersionColumnName);
5358 int equals = update.indexOf("=");
5359 try {
5360 if (equals != ver + 8) { // update set
5361 // version=1
5362 // where x=x
5363 this.logger.write("full", "\tQuery '"
5364 + update + strQueryWhere
5365 + "' will be executed");
5366 logStatement = update + strQueryWhere;
5367 iNumRowUp = stmtTarget
5368 .executeUpdate(update
5369 + strQueryWhere);
5370 }
5371 if (iNumRowUp != 0) {
5372 if (!bWriteData)
5373 iVersionMax = iVersionMax + 1;
5374 bWriteData = true;
5375 }
5376 String tableName = this.vecTableTableName
5377 .get(iTableInt).toString();
5378 for (int i = 0; i < this.vecBlobVector
5379 .size(); i = i + 5) {
5380 if (!this.vecBlobVector.get(i + 3)
5381 .toString().equalsIgnoreCase(
5382 "update")) {
5383 String version = "";
5384 if (oid) {
5385 if (bWriteData) {
5386 // version += ", version = "
5387 // + iVersionMax;
5388 version += ", "
5389 + this.currentVersionColumnName
5390 + " = "
5391 + iVersionMax;
5392 } else {
5393 // version += ", version = "
5394 // + (iVersionMax + 1);
5395 version += ", "
5396 + this.currentVersionColumnName
5397 + "= "
5398 + (iVersionMax + 1);
5399 }
5400 }
5401 String columnName = this.vecBlobVector
5402 .get(i).toString();
5403 byte[] isBlob = (byte[]) this.vecBlobVector
5404 .get(i + 1);
5405 if (isBlob != null) {
5406 ByteArrayInputStream bais = new ByteArrayInputStream(
5407 isBlob);
5408 logStatement = "update "
5409 + tableName + " set "
5410 + columnName + "=(?)"
5411 + version + " where "
5412 + columnName
5413 + " is null";
5414 PreparedStatement pstmt = c
5415 .prepareStatement("update "
5416 + tableName
5417 + " set "
5418 + columnName
5419 + "=(?)"
5420 + version
5421 + " where "
5422 + columnName
5423 + " is null");
5424 pstmt.setBytes(1, isBlob);
5425 int intRowStmt = pstmt
5426 .executeUpdate();
5427 pstmt.close();
5428 if (intRowStmt != 0) {
5429 if (!bWriteData)
5430 iVersionMax = iVersionMax + 1;
5431 bWriteData = true;
5432 }
5433 }
5434 }
5435 }
5436 } catch (SQLException ex) {
5437 stmtTarget.close();
5438 stmtTarget = c.createStatement();
5439
5440 if ((importDefinitionElement.strDefaultCutOffData
5441 .equalsIgnoreCase("true"))) {
5442 dataCleaning
5443 .cutingDataLenghtUpdate(
5444 this.vecTableTableName
5445 .get(iTableInt)
5446 .toString(),
5447 c,
5448 strQueryWhere,
5449 currentRow,
5450 update,
5451 importDefinitionElement.strOnErrorContinueXml,
5452 importDefinitionElement.strImportDefinitionName,
5453 update + strQueryWhere);
5454 } else
5455
5456 throw ex;
5457 }
5458 }
5459 for (int j = 0; j < vecColumnNames.size(); j++) {
5460 if (vecColumnMode.get(j).toString()
5461 .equalsIgnoreCase("Update")) {
5462 // String javaType =
5463 // configReaderTarget.getJavaTypeMapings()
5464 // .get(vecColumnTypes.get(j).toString().toUpperCase()).toString();
5465 // ZK change this 7.5.2004 from CheckType to
5466 // configReaderSource
5467 if (configReaderTarget
5468 .isBinaryObject(vecColumnTypes.get(
5469 j).toString())) {
5470 // int
5471 // javaTypeInt=Integer.parseInt(javaType);
5472 // if (javaTypeInt==1) {
5473 for (int i = 0; i < vecBlobVector
5474 .size(); i = i + 5) {
5475 if (vecBlobVector.get(i + 3)
5476 .toString()
5477 .equalsIgnoreCase("update")) {
5478 if (vecBlobVector
5479 .get(i)
5480 .toString()
5481 .equalsIgnoreCase(
5482 vecColumnNames
5483 .get(j)
5484 .toString())) {
5485 String version = "";
5486 if (oid) {
5487 if (bWriteData) {
5488 // version += ",
5489 // version = " +
5490 // (iVersionMax);
5491 version += ", "
5492 + this.currentVersionColumnName
5493 + " = "
5494 + (iVersionMax);
5495 } else {
5496 // version += ",
5497 // version = " +
5498 // (iVersionMax +
5499 // 1);
5500 version += ", "
5501 + this.currentVersionColumnName
5502 + " = "
5503 + (iVersionMax + 1);
5504 }
5505 }
5506 String tableName = this.vecTableTableName
5507 .get(iTableInt)
5508 .toString();
5509 String columnName = this.vecBlobVector
5510 .get(i).toString();
5511 byte[] isBlob = (byte[]) this.vecBlobVector
5512 .get(i + 1);
5513 String condition = this.vecBlobVector
5514 .get(i + 2)
5515 .toString();
5516 if (isBlob != null) {
5517 ByteArrayInputStream bais = new ByteArrayInputStream(
5518 isBlob);
5519 PreparedStatement pstmt = c
5520 .prepareStatement("update "
5521 + tableName
5522 + " set "
5523 + columnName
5524 + "=(?)"
5525 + version
5526 + condition
5527 + strQueryWhere);
5528 pstmt.setBytes(1,
5529 isBlob);
5530 this.logger
5531 .write(
5532 "full",
5533 "\tQuery '"
5534 + "update "
5535 + tableName
5536 + " set "
5537 + columnName
5538 + "=BlobObject"
5539 + version
5540 + condition
5541 + " where "
5542 + strQueryWhere
5543 + "' will be executed");
5544 int intRowStmt = 0;
5545 logStatement = "update "
5546 + tableName
5547 + " set "
5548 + columnName
5549 + "=BlobObject"
5550 + version
5551 + condition
5552 + " where "
5553 + strQueryWhere;
5554 intRowStmt = pstmt
5555 .executeUpdate();
5556 pstmt.close();
5557 if (intRowStmt != 0) {
5558 if (!bWriteData)
5559 iVersionMax = iVersionMax + 1;
5560 bWriteData = true;
5561 }
5562 }
5563 }
5564 }
5565 } // for petlja za blob
5566 } else {
5567 String strQueryUpdate = "update "
5568 + this.vecTableTableName.get(
5569 iTableInt).toString()
5570 + " set ";
5571 strQueryUpdate += vecColumnNames.get(j)
5572 .toString()
5573 + "=";
5574 if (vecColumnValues.get(j) == null)
5575 strQueryUpdate += " null ";
5576 else {
5577 // ZK change this from CheckType to
5578 // configReaderTarget this 7.5.2004
5579 if (!configReaderTarget
5580 .isNumber(vecColumnTypes
5581 .get(j).toString()))
5582 strQueryUpdate += "'"
5583 + vecColumnValues
5584 .get(j)
5585 .toString()
5586 + "' ";
5587 else
5588 strQueryUpdate += vecColumnValues
5589 .get(j).toString()
5590 + " ";
5591 }
5592 if (oid) {
5593 if (bWriteData) {
5594 // strQueryUpdate += ", version
5595 // = " + (iVersionMax) + " where
5596 // ";
5597 strQueryUpdate += ", "
5598 + this.currentVersionColumnName
5599 + " = " + (iVersionMax)
5600 + " where ";
5601 } else {
5602 // strQueryUpdate += ", version
5603 // = " + (iVersionMax + 1) + "
5604 // where ";
5605 strQueryUpdate += ", "
5606 + this.currentVersionColumnName
5607 + " = "
5608 + (iVersionMax + 1)
5609 + " where ";
5610 }
5611 } else
5612 strQueryUpdate += " where ";
5613 strQueryUpdate += vecColumnNames.get(j)
5614 .toString()
5615 + " is null and ";
5616 if (bReplaceInData) {
5617 strQueryUpdate = this
5618 .replaceInData(strQueryUpdate);
5619 strQueryWhere = this
5620 .replaceInData(strQueryWhere);
5621 }
5622 this.logger.write("full", "\tQuery '"
5623 + strQueryUpdate
5624 + strQueryWhere
5625 + "' will be executed");
5626 int iNumRow = 0;
5627 try {
5628 iNumRow = stmtTarget
5629 .executeUpdate(strQueryUpdate
5630 + strQueryWhere);
5631 } catch (SQLException ex) {
5632 stmtTarget.close();
5633 stmtTarget = c.createStatement();
5634 if ((importDefinitionElement.strDefaultCutOffData
5635 .equalsIgnoreCase("true"))) {
5636 dataCleaning
5637 .cutingDataLenghtUpdate(
5638 this.vecTableTableName
5639 .get(
5640 iTableInt)
5641 .toString(),
5642 c,
5643 strQueryWhere,
5644 currentRow,
5645 update,
5646 importDefinitionElement.strOnErrorContinueXml,
5647 importDefinitionElement.strImportDefinitionName,
5648 strQueryUpdate
5649 + strQueryWhere);
5650 } else
5651 throw ex;
5652 }
5653 if (iNumRow != 0) {
5654 if (!bWriteData)
5655 iVersionMax = iVersionMax + 1;
5656 bWriteData = true;
5657 }
5658 }
5659 } // end of main if loop
5660 }
5661 }
5662 for (int i = 0; i < this.iRelationColumns; i++) {
5663 outLoop: if (this.vecRelationColumnSourceTableName
5664 .get(i).toString().equalsIgnoreCase(
5665 this.vecTableTableName.get(
5666 iTableInt).toString())
5667 && this.vecRelationColumnSourceTableID.get(
5668 i).toString().equalsIgnoreCase(
5669 this.vecTableTableID.get(iTableInt)
5670 .toString())) {
5671 for (int m = 0; m < this.vecVariableUseIDTableName
5672 .size(); m++) {
5673 if (this.vecRelationColumnSourceTableName
5674 .get(i)
5675 .toString()
5676 .equalsIgnoreCase(
5677 this.vecVariableUseIDTableName
5678 .get(m).toString())
5679 && this.vecRelationColumnSourceTableID
5680 .get(i)
5681 .toString()
5682 .equalsIgnoreCase(
5683 this.vecVariableUseIDTableID
5684 .get(m)
5685 .toString())) {
5686 String strQueryRelations = "select "
5687 + this.vecRelationColumnSourceColumnName
5688 .get(i).toString()
5689 + " from "
5690 + this.vecRelationColumnSourceTableName
5691 .get(i).toString()
5692 + " where ";
5693 strQueryRelations += vecTempKeyColumns
5694 .get(0).toString()
5695 + " = ";
5696 // ZK change this from CheckType to
5697 // configReaderTarget this 7.5.2004
5698 if (!configReaderTarget
5699 .isNumber(vecColumnTypes.get(0)
5700 .toString()))
5701 strQueryRelations += "'"
5702 + this.strUserID + "'";
5703 else
5704 strQueryRelations += this.strUserID;
5705
5706 if (this.vecTableTableMode.get(
5707 iTableInt).toString()
5708 .equalsIgnoreCase("cache")) {
5709 Object obj = relationsCache
5710 .getRelationsCacheValue(strQueryRelations);
5711 if (obj != null) {
5712 if (!obj.toString()
5713 .equalsIgnoreCase(
5714 "#$Together#$")) {
5715 this.vecRelationSourceValue
5716 .setElementAt(obj,
5717 i);
5718 String type = relationsCache
5719 .getRelationsCachType(strQueryRelations);
5720 this.vecRelationSourceType
5721 .setElementAt(type,
5722 i);
5723 }
5724 } else {
5725 Statement stmtForUserID1 = c
5726 .createStatement();
5727 ResultSet rsForUserID1 = null;
5728 try {
5729 this.logger
5730 .write(
5731 "full",
5732 "\tQuery '"
5733 + strQueryRelations
5734 + "' will be executed");
5735 rsForUserID1 = stmtForUserID1
5736 .executeQuery(strQueryRelations);
5737 } catch (SQLException ex) {
5738 rsForUserID1.close();
5739 stmtForUserID1.close();
5740 dataCleaning
5741 .cutingDataLenghtUpdate(
5742 this.vecTableTableName
5743 .get(
5744 iTableInt)
5745 .toString(),
5746 c,
5747 strQueryWhere,
5748 currentRow,
5749 update,
5750 importDefinitionElement.strOnErrorContinueXml,
5751 importDefinitionElement.strImportDefinitionName,
5752 strQueryRelations);
5753 }
5754 if (rsForUserID1.next()) {
5755 if (this.iTargetFirstColumnResult == 1) {
5756 this.vecRelationSourceValue
5757 .setElementAt(
5758 rsForUserID1
5759 .getObject(1),
5760 i);
5761 this.vecRelationSourceType
5762 .setElementAt(
5763 rsForUserID1
5764 .getMetaData()
5765 .getColumnTypeName(
5766 1),
5767 i);
5768 relationsCache
5769 .setRelationsCacheValue(
5770 strQueryRelations,
5771 rsForUserID1
5772 .getObject(1));
5773 relationsCache
5774 .setRelationsCacheType(
5775 strQueryRelations,
5776 rsForUserID1
5777 .getMetaData()
5778 .getColumnTypeName(
5779 1));
5780 }
5781 } else {
5782 relationsCache
5783 .setRelationsCacheValue(
5784 strQueryRelations,
5785 "#$Together#$");
5786 relationsCache
5787 .setRelationsCacheType(
5788 strQueryRelations,
5789 "#$Together#$");
5790 }
5791 rsForUserID1.close();
5792 stmtForUserID1.close();
5793 break outLoop;
5794 }
5795 } else { // tableMode=Query
5796 this.logger
5797 .write(
5798 "full",
5799 "\tQuery '"
5800 + strQueryRelations
5801 + "' will be executed");
5802 Statement stmtForUserID2 = c
5803 .createStatement();
5804 ResultSet rsForUserID2 = null;
5805 try {
5806 rsForUserID2 = stmtForUserID2
5807 .executeQuery(strQueryRelations);
5808 } catch (SQLException ex) {
5809 rsForUserID2.close();
5810 stmtForUserID2.close();
5811 dataCleaning
5812 .cutingDataLenghtUpdate(
5813 this.vecTableTableName
5814 .get(
5815 iTableInt)
5816 .toString(),
5817 c,
5818 strQueryWhere,
5819 currentRow,
5820 update,
5821 importDefinitionElement.strOnErrorContinueXml,
5822 importDefinitionElement.strImportDefinitionName,
5823 strQueryRelations);
5824
5825 }
5826 if (rsForUserID2.next()) {
5827
5828 if (this.iTargetFirstColumnResult == 1) {
5829 this.vecRelationSourceValue
5830 .setElementAt(
5831 rsForUserID2
5832 .getObject(1),
5833 i);
5834 this.vecRelationSourceType
5835 .setElementAt(
5836 rsForUserID2
5837 .getMetaData()
5838 .getColumnTypeName(
5839 1),
5840 i);
5841
5842 } else {
5843 this.vecRelationSourceValue
5844 .setElementAt(
5845 rsForUserID2
5846 .getObject(0),
5847 i);
5848 this.vecRelationSourceType
5849 .setElementAt(
5850 rsForUserID2
5851 .getMetaData()
5852 .getColumnTypeName(
5853 0),
5854 i);
5855 }
5856 }
5857 rsForUserID2.close();
5858 stmtForUserID2.close();
5859 break outLoop;
5860 }
5861 }
5862 } // end of vecVariableUseIDTableName loop
5863 String strQueryRelations = "select "
5864 + this.vecRelationColumnSourceColumnName
5865 .get(i).toString()
5866 + " from "
5867 + this.vecRelationColumnSourceTableName
5868 .get(i).toString() + " where "
5869 + strQueryWhere;
5870 if (this.vecTableTableMode.get(iTableInt)
5871 .toString().equalsIgnoreCase("cache")) {
5872 Object obj = relationsCache
5873 .getRelationsCacheValue(strQueryRelations);
5874 if (obj != null) {
5875 if (!obj.toString().equalsIgnoreCase(
5876 "#$Together#$")) {
5877 this.vecRelationSourceValue
5878 .setElementAt(obj, i);
5879 String type = relationsCache
5880 .getRelationsCachType(strQueryRelations);
5881 this.vecRelationSourceType
5882 .setElementAt(type, i);
5883 }
5884 } else {
5885 Statement stmtForRel1 = c
5886 .createStatement();
5887 ResultSet rsForRel1 = null;
5888 try {
5889 this.logger
5890 .write(
5891 "full",
5892 "\tQuery '"
5893 + strQueryRelations
5894 + "' will be executed");
5895 rsForRel1 = stmtForRel1
5896 .executeQuery(strQueryRelations);
5897 } catch (SQLException ex) {
5898 rsForRel1.close();
5899 stmtForRel1.close();
5900 dataCleaning
5901 .cutingDataLenghtUpdate(
5902 this.vecTableTableName
5903 .get(
5904 iTableInt)
5905 .toString(),
5906 c,
5907 strQueryWhere,
5908 currentRow,
5909 update,
5910 importDefinitionElement.strOnErrorContinueXml,
5911 importDefinitionElement.strImportDefinitionName,
5912 strQueryRelations);
5913 }
5914
5915 if (rsForRel1.next()) {
5916 String relVal=getSQLRelationString(rsForRel1); //senka added
5917 if (this.iTargetFirstColumnResult == 1) {
5918 // this.vecRelationSourceValue
5919 // .setElementAt(rsForRel1
5920 // .getObject(1),
5921 // i);
5922 // senka change
5923 this.vecRelationSourceValue
5924 .setElementAt(relVal,
5925 i);
5926
5927 this.vecRelationSourceType
5928 .setElementAt(
5929 rsForRel1
5930 .getMetaData()
5931 .getColumnTypeName(
5932 1),
5933 i);
5934 // relationsCache
5935 // .setRelationsCacheValue(
5936 // strQueryRelations,
5937 // rsForRel1
5938 // .getObject(1));
5939 // senka change
5940 relationsCache
5941 .setRelationsCacheValue(
5942 strQueryRelations,
5943 relVal
5944 );
5945 relationsCache
5946 .setRelationsCacheType(
5947 strQueryRelations,
5948 rsForRel1
5949 .getMetaData()
5950 .getColumnTypeName(
5951 1));
5952 } else {
5953 // this.vecRelationSourceValue
5954 // .setElementAt(rsForRel1
5955 // .getObject(0),
5956 // i);
5957 // senka change
5958 this.vecRelationSourceValue
5959 .setElementAt(relVal,
5960 i);
5961 this.vecRelationSourceType
5962 .setElementAt(
5963 rsForRel1
5964 .getMetaData()
5965 .getColumnTypeName(
5966 0),
5967 i);
5968 // relationsCache
5969 // .setRelationsCacheValue(
5970 // strQueryRelations,
5971 // rsForRel1
5972 // .getObject(0));
5973 // senka change
5974 relationsCache
5975 .setRelationsCacheValue(
5976 strQueryRelations,
5977 relVal
5978 );
5979 relationsCache
5980 .setRelationsCacheType(
5981 strQueryRelations,
5982 rsForRel1
5983 .getMetaData()
5984 .getColumnTypeName(
5985 0));
5986 }
5987 } else {
5988 relationsCache
5989 .setRelationsCacheValue(
5990 strQueryRelations,
5991 "#$Together#$");
5992 relationsCache
5993 .setRelationsCacheType(
5994 strQueryRelations,
5995 "#$Together#$");
5996 }
5997 rsForRel1.close();
5998 stmtForRel1.close();
5999 }
6000 } else { // tableMode=Query
6001
6002 Statement stmtForRel2 = c.createStatement();
6003 ResultSet rsForRel2 = null;
6004 try {
6005 this.logger.write("full", "\tQuery '"
6006 + strQueryRelations
6007 + "' will be executed");
6008 rsForRel2 = stmtForRel2
6009 .executeQuery(strQueryRelations);
6010 } catch (SQLException ex) {
6011 rsForRel2.close();
6012 stmtForRel2.close();
6013 dataCleaning
6014 .cutingDataLenghtUpdate(
6015 this.vecTableTableName
6016 .get(iTableInt)
6017 .toString(),
6018 c,
6019 strQueryWhere,
6020 currentRow,
6021 update,
6022 importDefinitionElement.strOnErrorContinueXml,
6023 importDefinitionElement.strImportDefinitionName,
6024 strQueryRelations);
6025 }
6026 if (rsForRel2.next()) {
6027 String relVal2=getSQLRelationString(rsForRel2); //senka added
6028 if (this.iTargetFirstColumnResult == 1) {
6029 // this.vecRelationSourceValue
6030 // .setElementAt(rsForRel2
6031 // .getObject(1), i);
6032 // senka
6033 this.vecRelationSourceValue
6034 .setElementAt(relVal2, i);
6035 this.vecRelationSourceType
6036 .setElementAt(rsForRel2
6037 .getMetaData()
6038 .getColumnTypeName(
6039 1), i);
6040 } else {
6041 //this.vecRelationSourceValue
6042 // .setElementAt(rsForRel2
6043 // .getObject(0), i);
6044 // senka
6045 this.vecRelationSourceValue
6046 .setElementAt(relVal2, i);
6047 this.vecRelationSourceType
6048 .setElementAt(rsForRel2
6049 .getMetaData()
6050 .getColumnTypeName(
6051 0), i);
6052 }
6053 }
6054 rsForRel2.close();
6055 stmtForRel2.close();
6056 }
6057 }
6058 }
6059
6060 for (int i = 0; i < this.vecRelationColumnTargetColumnName
6061 .size(); i++) {
6062 if (this.vecRelationColumnTargetTableName.get(i)
6063 .toString().equalsIgnoreCase(
6064 this.vecTableTableName.get(
6065 iTableInt).toString())
6066 && this.vecRelationColumnTargetTableID.get(
6067 i).toString().equalsIgnoreCase(
6068 this.vecTableTableID.get(iTableInt)
6069 .toString())) {
6070 int currentVersion = 0;
6071 if (bWriteData)
6072 currentVersion = iVersionMax;
6073 else
6074 currentVersion = iVersionMax + 1;
6075
6076 if (this.vecRelationColumnRelationMode.get(i)
6077 .toString().equalsIgnoreCase("SetNull")) {
6078 if (this.vecRelationSourceValue.get(i) == null) {
6079 String strUpdateRelations = this
6080 .queryRelations(iTableInt, i,
6081 strQueryWhere, c,
6082 currentVersion, oid);
6083 this.logger.write("full", "\tQuery '"
6084 + strUpdateRelations
6085 + "' will be executed");
6086 if (bReplaceInData) {
6087 strUpdateRelations = this
6088 .replaceInData(strUpdateRelations);
6089 }
6090 int iNumRow = 0;
6091 logStatement = strUpdateRelations;
6092 iNumRow = stmtTarget
6093 .executeUpdate(strUpdateRelations);
6094 this.vecRelationSourceValue
6095 .setElementAt(null, i);
6096 // this.vecRelationSourceType.setElementAt(null,i);
6097 if (iNumRow != 0) {
6098 if (!bWriteData)
6099 iVersionMax = iVersionMax + 1;
6100 bWriteData = true;
6101 }
6102 }
6103 } else if (this.vecRelationColumnRelationMode
6104 .get(i).toString().equalsIgnoreCase(
6105 "Overwrite")
6106 || (this.vecRelationColumnRelationMode
6107 .get(i).toString()
6108 .equalsIgnoreCase("Update"))) {
6109
6110 // for handling exception in FK
6111 replacementValueInRel = vecDefaultRelationValue
6112 .get(i).toString();
6113 replacementTable = vecRelationColumnTargetTableName
6114 .get(i).toString();
6115 replacementColumn = vecRelationColumnTargetColumnName
6116 .get(i).toString();
6117 // replacementColumnType =
6118 // this.vecRelationSourceType.get(i).toString();
6119 String strUpdateRelations = this
6120 .queryRelations(iTableInt, i,
6121 strQueryWhere, c,
6122 currentVersion, oid);
6123 this.logger.write("full", "\tQuery '"
6124 + strUpdateRelations
6125 + "' will be executed");
6126 if (bReplaceInData) {
6127 strUpdateRelations = this
6128 .replaceInData(strUpdateRelations);
6129 }
6130 // only for catch exceptions in foreign keys
6131 // statement
6132 exceptionInRelations = strUpdateRelations;
6133 updateQueryIsOk = true;
6134 updateConstantIsOk = true;
6135 relationIsOk = false;
6136 int iNumRow = 0;
6137 try {
6138 logStatement = strUpdateRelations;
6139 iNumRow = stmtTarget
6140 .executeUpdate(strUpdateRelations);
6141 this.vecRelationSourceValue
6142 .setElementAt(null, i);
6143 // this.vecRelationSourceType.setElementAt(null,i);
6144 } catch (SQLException ex) {
6145 stmtTarget.close();
6146
6147 stmtTarget = c.createStatement();
6148 if ((importDefinitionElement.strDefaultCutOffData
6149 .equalsIgnoreCase("true"))) {
6150 dataCleaning
6151 .cutingDataLenghtUpdate(
6152 this.vecTableTableName
6153 .get(
6154 iTableInt)
6155 .toString(),
6156 c,
6157 strQueryWhere,
6158 currentRow,
6159 update,
6160 importDefinitionElement.strOnErrorContinueXml,
6161 importDefinitionElement.strImportDefinitionName,
6162 strUpdateRelations);
6163 } else
6164 throw ex;
6165 }
6166 if (iNumRow != 0) {
6167 if (!bWriteData)
6168 iVersionMax = iVersionMax + 1;
6169 bWriteData = true;
6170 }
6171 }
6172 }
6173 }
6174
6175 if (this.vecTableInsert.get(iTableInt).toString()
6176 .equalsIgnoreCase("true")) {
6177 if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere)
6178 .indexOf("UPDATE") != -1)) {
6179 if (vecTempConstantColumns.size() > 0) {
6180 if (updateConstant.indexOf(",") != -1)
6181 updateConstant = updateConstant
6182 .substring(0, updateConstant
6183 .lastIndexOf(","));
6184
6185 Vector cOverwrite = (Vector) indexDConstantOver
6186 .get(key);
6187 Vector cNull = (Vector) indexDConstantNull
6188 .get(key);
6189 strQueryConstantApendix = "";
6190 if (cOverwrite.size() > 0) {
6191 int startOver = 0;
6192 for (int i = 0; i < cOverwrite.size(); i++) {
6193 int index = Integer
6194 .parseInt(cOverwrite.get(i)
6195 .toString());
6196 if (vecTempConstantValues
6197 .get(index) == null) {
6198 int str = updateConstant
6199 .indexOf("'dummyConstantOver'");
6200 int num = updateConstant
6201 .indexOf("dummyConstantOver");
6202 if (str != -1
6203 && (num == -1 || str < num))
6204 updateConstant = replaceFirst(
6205 updateConstant,
6206 "'dummyConstantOver'",
6207 " null ");
6208 else
6209 updateConstant = replaceFirst(
6210 updateConstant,
6211 "dummyConstantOver",
6212 " null ");
6213 } else {
6214 String replacement = vecTempConstantValues
6215 .get(index).toString();
6216 startOver = updateConstant
6217 .indexOf(
6218 "dummyConstantOver",
6219 startOver);
6220 updateConstant = updateConstant
6221 .substring(0, startOver)
6222 + replacement
6223 + updateConstant
6224 .substring(startOver + 17);
6225 startOver = replacement
6226 .length();
6227 }
6228 }
6229 }
6230 if (cNull.size() > 0) {
6231 int startNull = 0;
6232 for (int i = 0; i < cNull.size(); i++) {
6233 int index = Integer.parseInt(cNull
6234 .get(i).toString());
6235 if (vecTempConstantValues
6236 .get(index) == null) {
6237 int str = updateConstant
6238 .indexOf("'dummyConstantNull'");
6239 int num = updateConstant
6240 .indexOf("dummyConstantNull");
6241 if (str != -1
6242 && (num == -1 || str < num))
6243 updateConstant = replaceFirst(
6244 updateConstant,
6245 "'dummyConstantNull'",
6246 " null ");
6247 else
6248 updateConstant = replaceFirst(
6249 updateConstant,
6250 "dummyConstantNull",
6251 " null ");
6252
6253 strQueryConstantApendix += " and "
6254 + vecTempConstantColumns
6255 .get(index)
6256 .toString()
6257 + " is null ";
6258 } else {
6259 String replacement = vecTempConstantValues
6260 .get(index).toString();
6261 startNull = updateConstant
6262 .indexOf(
6263 "dummyConstantNull",
6264 startNull);
6265 updateConstant = updateConstant
6266 .substring(0, startNull)
6267 + replacement
6268 + updateConstant
6269 .substring(startNull + 17);
6270 startNull = replacement
6271 .length();
6272 }
6273 }
6274 }
6275
6276 if (bReplaceInData) {
6277 // System.out.println("bReplaceInData: "
6278 // + bReplaceInData);
6279 updateConstant = this
6280 .replaceInData(updateConstant);
6281 strQueryWhere = this
6282 .replaceInData(strQueryWhere);
6283 }
6284
6285 if (oid) {
6286 if (bWriteData) {
6287 // updateConstant += ", version = "
6288 // + (iVersionMax);
6289 updateConstant += ", "
6290 + this.currentVersionColumnName
6291 + " = " + (iVersionMax);
6292 } else {
6293 // updateConstant += ", version = "
6294 // + (iVersionMax + 1);
6295 updateConstant += ", "
6296 + this.currentVersionColumnName
6297 + " = " + (iVersionMax + 1);
6298 }
6299 }
6300 updateQueryIsOk = true;
6301 relationIsOk = true;
6302 updateConstantIsOk = false;
6303 int iNumRow = 0;
6304 try {
6305 if (!updateConstant.endsWith(" set ")) {
6306 this.logger
6307 .write(
6308 "full",
6309 "\tQuery '"
6310 + updateConstant
6311 + " where "
6312 + strQueryWhere
6313 + strQueryConstantApendix
6314 + "' will be executed");
6315 logStatement = updateConstant
6316 + " where " + strQueryWhere;
6317 iNumRow = stmtTarget
6318 .executeUpdate(updateConstant
6319 + " where "
6320 + strQueryWhere
6321 + strQueryConstantApendix);
6322 }
6323 } catch (SQLException ex) {
6324 stmtTarget.close();
6325
6326 stmtTarget = c.createStatement();
6327 if ((importDefinitionElement.strDefaultCutOffData
6328 .equalsIgnoreCase("true"))) {
6329 dataCleaning
6330 .cutingDataLenghtUpdate(
6331 this.vecTableTableName
6332 .get(
6333 iTableInt)
6334 .toString(),
6335 c,
6336 " where "
6337 + strQueryWhere
6338 + strQueryConstantApendix,
6339 currentRow,
6340 updateConstant,
6341 importDefinitionElement.strOnErrorContinueXml,
6342 importDefinitionElement.strImportDefinitionName,
6343 updateConstant
6344 + " where "
6345 + strQueryWhere
6346 + strQueryConstantApendix);
6347 } else
6348 throw ex;
6349 }
6350 if (iNumRow != 0) {
6351 if (!bWriteData)
6352 iVersionMax = iVersionMax + 1;
6353 bWriteData = true;
6354 }
6355 }
6356 if (this.vecVariableTimesTableName.size() != 0) {
6357 int currentVersion = 0;
6358 boolean bool = false;
6359 if (!bWriteData)
6360 currentVersion = iVersionMax + 1;
6361 else
6362 currentVersion = iVersionMax;
6363 bool = this.updateCurrentTime(c, iTableInt,
6364 strQueryWhere, currentVersion, oid);
6365 if (bool) {
6366 if (!bWriteData)
6367 iVersionMax = iVersionMax + 1;
6368 bWriteData = true;
6369 }
6370 }
6371 if (this.vecVariableColumnTargetTableName
6372 .size() != 0) {
6373 int currentVersion = 0;
6374 boolean bool = false;
6375 if (!bWriteData)
6376 currentVersion = iVersionMax + 1;
6377 else
6378 currentVersion = iVersionMax;
6379 try {
6380 bool = this.updateNameValue(c,
6381 iTableInt, strQueryWhere,
6382 currentVersion, oid);
6383 } catch (SQLException ex) {
6384 throw ex;
6385 }
6386 if (bool) {
6387 if (!bWriteData)
6388 iVersionMax = iVersionMax + 1;
6389 bWriteData = true;
6390 }
6391 }
6392 }
6393 } // insertTable=true
6394 // ZK added this 17.5.2004
6395 // System.out.println("iTableInt="+iTableInt);
6396 // System.out.println("update + strQueryWhere="+update +
6397 // strQueryWhere);
6398
6399 if (this.vecTableInsert.get(iTableInt).toString()
6400 .equalsIgnoreCase("true")) {
6401 if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere)
6402 .indexOf("UPDATE") != -1)) {
6403
6404 // if(((Vector)transformationsColumnNames.get(iTableInt)).size()
6405 // > 0){
6406
6407 // System.out.println("updateTransformation =
6408 // "+updateTransformation);
6409 // System.out.println("transformedValues="+transformedValues);
6410
6411 Vector tOverwrite = (Vector) indexDTransformationOver
6412 .get(key);
6413 Vector tNull = (Vector) indexDTransformationNull
6414 .get(key);
6415
6416 if ((updateTransformation.indexOf(",") != -1))
6417 updateTransformation = updateTransformation
6418 .substring(0, updateTransformation
6419 .lastIndexOf(","));
6420
6421 if (tOverwrite.size() > 0) {
6422 int startOver = 0;
6423 for (int i = 0; i < tOverwrite.size(); i++) {
6424 int index = Integer.parseInt(tOverwrite
6425 .get(i).toString());
6426 if (vecTransformationValue.get(index) == null) {
6427
6428 int str = updateTransformation
6429 .indexOf("'dummyTransformationOver'");
6430 int num = updateTransformation
6431 .indexOf("dummyTransformationOver");
6432 if (str != -1
6433 && (num == -1 || str < num))
6434 updateTransformation = replaceFirst(
6435 updateTransformation,
6436 "'dummyTransformationOver'",
6437 " null ");
6438 else
6439 updateTransformation = replaceFirst(
6440 updateTransformation,
6441 "dummyTransformationOver",
6442 " null ");
6443 } else {
6444 String replacement = vecTransformationValue
6445 .get(index).toString();
6446 startOver = updateTransformation
6447 .indexOf(
6448 "dummyTransformationOver",
6449 startOver);
6450 updateTransformation = updateTransformation
6451 .substring(0, startOver)
6452 + replacement
6453 + updateTransformation
6454 .substring(startOver + 23);
6455 startOver = replacement.length();
6456
6457 }
6458
6459 }
6460 }
6461
6462 if (tNull.size() > 0) {
6463 int startNull = 0;
6464 for (int i = 0; i < tNull.size(); i++) {
6465 int index = Integer.parseInt(tNull.get(
6466 i).toString());
6467 String colName = ((Vector) transformationsColumnNames
6468 .get(iTableInt)).get(index)
6469 .toString();
6470 if (vecTransformationValue.get(index) == null) {
6471 updateTransformation = replaceFirst(
6472 updateTransformation,
6473 "dummyTransformationNull",
6474 colName + " = null ");
6475 } else {
6476 updateTransformation = replaceFirst(
6477 updateTransformation,
6478 "dummyTransformationNull,",
6479 " ");
6480 }
6481 }
6482 }
6483
6484 if ((tOverwrite.size() > 0)
6485 || (tNull.size() > 0)) {
6486
6487 if (bReplaceInData) {
6488 updateTransformation = this
6489 .replaceInData(updateTransformation);
6490 strQueryWhere = this
6491 .replaceInData(strQueryWhere);
6492 }
6493
6494 if (oid) {
6495 if (bWriteData) {
6496 updateTransformation += ", "
6497 + this.currentVersionColumnName
6498 + " = " + (iVersionMax);
6499 } else {
6500 updateTransformation += ", "
6501 + this.currentVersionColumnName
6502 + " = " + (iVersionMax + 1);
6503 }
6504 }
6505
6506 int iNumRow = 0;
6507 try {
6508 if (!updateTransformation
6509 .endsWith(" set ")) {
6510 this.logger
6511 .write(
6512 "full",
6513 "\tQuery '"
6514 + updateTransformation
6515 + " where "
6516 + strQueryWhere
6517 + "' will be executed");
6518 logStatement = updateTransformation
6519 + " where " + strQueryWhere;
6520 iNumRow = stmtTarget
6521 .executeUpdate(updateTransformation
6522 + " where "
6523 + strQueryWhere);
6524 }
6525 } catch (SQLException ex) {
6526 stmtTarget.close();
6527 throw ex;
6528 }
6529
6530 if (iNumRow != 0) {
6531 if (!bWriteData)
6532 iVersionMax = iVersionMax + 1;
6533 bWriteData = true;
6534 }
6535
6536 }
6537
6538 }// this is my
6539 }// END IF
6540 // ZK added 20.5 2004 for "Update" mode
6541 if (this.vecTableInsert.get(iTableInt).toString()
6542 .equalsIgnoreCase("true")) {
6543 if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere)
6544 .indexOf("UPDATE") != -1)) {
6545
6546 // if(((Vector)transformationsColumnNames.get(iTableInt)).size()
6547 // > 0){
6548 Vector tUpdate = (Vector) indexDTransformationUpdate
6549 .get(key);
6550 if (tUpdate.size() > 0) {
6551 // int startUpdate = 0;
6552 for (int j = 0; j < tUpdate.size(); j++) {
6553 int index = Integer.parseInt(tUpdate
6554 .get(j).toString());
6555 Vector tempTransValueModes = (Vector) transformationsValueModes
6556 .get(iTableInt);
6557 Vector tempTransColumnNames = (Vector) transformationsColumnNames
6558 .get(iTableInt);
6559 Vector tempTransColumnTypes = (Vector) transformationsColumnTypes
6560 .get(iTableInt);
6561 if (tempTransValueModes.get(index)
6562 .toString().equalsIgnoreCase(
6563 "Update")) {
6564
6565 String strQueryUpdate = "update "
6566 + this.vecTableTableName
6567 .get(iTableInt)
6568 .toString()
6569 + " set ";
6570 strQueryUpdate += tempTransColumnNames
6571 .get(index).toString()
6572 + "=";
6573 if (vecTransformationValue
6574 .get(index) == null)
6575 strQueryUpdate += " null ";
6576 else {
6577
6578 if (!configReaderTarget
6579 .isNumber(tempTransColumnTypes
6580 .get(index)
6581 .toString()))
6582 strQueryUpdate += "'"
6583 + vecTransformationValue
6584 .get(index)
6585 .toString()
6586 + "' ";
6587 else
6588 strQueryUpdate += vecTransformationValue
6589 .get(index)
6590 .toString()
6591 + " ";
6592 }
6593 if (oid) {
6594 if (bWriteData) {
6595
6596 strQueryUpdate += ", "
6597 + this.currentVersionColumnName
6598 + " = "
6599 + (iVersionMax)
6600 + " where ";
6601 } else {
6602
6603 strQueryUpdate += ", "
6604 + this.currentVersionColumnName
6605 + " = "
6606 + (iVersionMax + 1)
6607 + " where ";
6608 }
6609 }
6610 // strQueryUpdate += " where ";
6611 strQueryUpdate += tempTransColumnNames
6612 .get(j).toString()
6613 + " is null and ";
6614
6615 if (bReplaceInData) {
6616 strQueryUpdate = this
6617 .replaceInData(strQueryUpdate);
6618 strQueryWhere = this
6619 .replaceInData(strQueryWhere);
6620 }
6621 this.logger
6622 .write(
6623 "full",
6624 "\tQuery '"
6625 + strQueryUpdate
6626 + strQueryWhere
6627 + "' will be executed");
6628 int iNumRow = 0;
6629 try {
6630 logStatement = strQueryUpdate
6631 + strQueryWhere;
6632 iNumRow = stmtTarget
6633 .executeUpdate(strQueryUpdate
6634 + strQueryWhere);
6635 } catch (SQLException ex) {
6636 stmtTarget.close();
6637 stmtTarget = c
6638 .createStatement();
6639 if ((importDefinitionElement.strDefaultCutOffData
6640 .equalsIgnoreCase("true"))) {
6641 dataCleaning
6642 .cutingDataLenghtUpdate(
6643 this.vecTableTableName
6644 .get(
6645 iTableInt)
6646 .toString(),
6647 c,
6648 strQueryWhere,
6649 currentRow,
6650 update,
6651 importDefinitionElement.strOnErrorContinueXml,
6652 importDefinitionElement.strImportDefinitionName,
6653 strQueryUpdate
6654 + strQueryWhere);
6655 } else
6656 throw ex;
6657 }
6658 if (iNumRow != 0) {
6659 if (!bWriteData)
6660 iVersionMax = iVersionMax + 1;
6661 bWriteData = true;
6662 }
6663
6664 }
6665 // }
6666 }
6667 }
6668 }
6669 }
6670
6671 // ZK END
6672 }
6673
6674 // checkRowCache.setCheckRowVersionValue(String
6675 // .valueOf(iVersionMax - 1));
6676 }
6677 stmtTarget.close();
6678
6679 }
6680 }
6681 // }
6682 catch (SQLException ex) {
6683
6684 if (stmtTarget != null)
6685 stmtTarget.close();
6686 if ((importDefinitionElement.strDefaultCutOffData
6687 .equalsIgnoreCase("true"))) {
6688 dataCleaning.cleaningInsert(this.vecTableTableName.get(
6689 iTableInt).toString(), c, currentRow, "UPDATE", ex
6690 .getMessage(),
6691 importDefinitionElement.strImportDefinitionName,
6692 logStatement);
6693 // } else if (
6694 // (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("false")
6695 // ||
6696 // importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase(""))
6697 // &&
6698 // importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("true"))
6699 // {
6700 // dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).toString(),
6701 // c, currentRow, "UPDATE", ex.getMessage(),
6702 // importDefinitionElement.strImportDefinitionName);
6703 } else {
6704 this.logger.write("normal",
6705 "\tDataCleaning features is not turn on.");
6706 throw ex;
6707 }
6708 } catch (NullPointerException ex) {
6709 throw ex;
6710 } catch (Exception ex) {
6711
6712 throw ex;
6713 }
6714 this.logger.write("full", "\tinsertTargetTable method is finished.");
6715 }
6716
6717 /***
6718 * Method insertRow is used to insert new row in the target table. Also
6719 * includes inserting values into constant, variable and relation columns of
6720 * the target table. If there is an error, Exception "SQLException" or
6721 * "NullPointerException" or "Exception" is thrown.
6722 *
6723 * @param c
6724 * Connection to the target database.
6725 * @param vecColumnValues
6726 * One row of values from source table.
6727 * @param vecColumnNamesTypes
6728 * Types of columns in a target table.
6729 * @param vecColumnNames
6730 * Vector of column names in a target table.
6731 * @param bOIDlogicValue
6732 * true if oid column exists in the target table.
6733 * @param iTableInt
6734 * Number of target table which is processed.
6735 * @param vecColumnMode
6736 * represents vector of table modes for currnet table
6737 * @throws SQLException
6738 * Constructs an SQLException object with a reason.
6739 * @throws NullPointerException
6740 * Constructs a NullPointerException with the specified detail
6741 * message.
6742 * @throws Exception
6743 * Constructs an Exception with the specified detail message.
6744 */
6745 private void insertRow(Connection c, Vector vecColumnValues,
6746 Vector vecColumnNamesTypes, Vector vecColumnNames,
6747 Vector vecColumnMode, boolean bOIDlogicValue, int iTableInt,
6748 Vector vecTransformationValue,
6749 Vector transformationTargetColumnTypes) throws SQLException,
6750 NullPointerException, Exception {
6751
6752 String key = String.valueOf(iTableInt);
6753 String strInsertRow = (String) queryInsertRow.get(key);
6754 Vector indexOfNotRelationColumns = (Vector) indexIsNotRelationsColumns
6755 .get(key);
6756
6757 PreparedStatement pstmt = (PreparedStatement) pstmtForInsert.get(key);
6758
6759 Vector pstmtColNames = (Vector) pstmtColumnNames.get(key);
6760 Vector pstmtValues = new Vector();
6761 Vector pstmtTypes = new Vector();
6762 // hendling select statement in relation tag!
6763 String selectValueInRel = "";
6764 String currentValueInRel = "";
6765
6766 this.logger.write("full", "\tinsertRow method is started.");
6767 String strQuery = "";
6768 boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName
6769 .equals("") || importDefinitionElement.strObjectIDNameColumnValue
6770 .equals(""));
6771 // sinisa 15.03.2003. Add subCouterColumns
6772 Vector subCounterKeyColumns = this.counterColumns
6773 .getSubCounterKeyColumns(this.vecTableTableName.get(iTableInt)
6774 .toString(), this.vecTableTableID.get(iTableInt)
6775 .toString());
6776
6777 Hashtable subKeyValues = new Hashtable();
6778 try {
6779 Vector vecTempConstantColumns = (Vector) this.vecConstantTargetColumnName
6780 .get(iTableInt);
6781 Vector vecTempConstantValues = (Vector) this.vecConstantConstantValue
6782 .get(iTableInt);
6783 strInsertRow = strInsertRow.trim();
6784 int comma = strInsertRow.lastIndexOf(",");
6785 if (comma == (strInsertRow.length() - 1))
6786 strQuery = strInsertRow.substring(0, strInsertRow.length() - 1);
6787 else
6788 strQuery = strInsertRow;
6789 if (bOIDlogicValue) {
6790 if (isTOS) {
6791 pstmtValues.add(this.bdecOidNumber);
6792 pstmtTypes.add("java.math.BigDecimal");
6793 } else {
6794 pstmtValues.add(this.bdecOidNumber);
6795 pstmtValues.add(String.valueOf(0));
6796 pstmtTypes.add("java.math.BigDecimal");
6797 pstmtTypes.add("java.lang.Integer");
6798 }
6799 }
6800
6801 strQuery = strQuery + ") VALUES (";
6802
6803 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase(
6804 "true")) {
6805 if (indexOfNotRelationColumns.size() > 0) {
6806 for (int k = 0; k < indexOfNotRelationColumns.size(); k++) {
6807 int index = Integer.parseInt(indexOfNotRelationColumns
6808 .get(k).toString());
6809 Vector replacedValue = (Vector) vecDefaultValue
6810 .get(iTableInt);
6811 if (vecColumnValues.get(index) == null) {
6812 if (replacedValue.get(index) != "") {
6813 pstmtValues.add(replacedValue.get(index)
6814 // .toString()
6815 );
6816 pstmtTypes.add(vecColumnNamesTypes.get(index)
6817 .toString());
6818 dataCleaning
6819 .cleaningColumnValues(
6820 this.vecTableTableName.get(
6821 iTableInt).toString(),
6822 vecColumnNames.get(index)
6823 .toString(),
6824 replacedValue.get(index)
6825 .toString(),
6826 currentRow,
6827 c,
6828 "INSERT",
6829 importDefinitionElement.strImportDefinitionName);
6830 } else {
6831 pstmtValues.add("null");
6832 pstmtTypes.add(vecColumnNamesTypes.get(index)
6833 .toString());
6834 }
6835 } else {
6836 pstmtValues.add(vecColumnValues.get(index)
6837 // .toString()
6838 );
6839 pstmtTypes.add(vecColumnNamesTypes.get(index)
6840 .toString());
6841 }
6842
6843 // sinisa 15.03 Add subCounter columns
6844 for (int l = 0; l < subCounterKeyColumns.size(); l++) {
6845 if (subCounterKeyColumns.get(l) != null
6846 && ((Vector) subCounterKeyColumns.get(l))
6847 .size() != 0
6848 && ((Vector) subCounterKeyColumns.get(l))
6849 .contains(vecColumnNames.get(index)
6850 .toString())) {
6851 if (vecColumnValues.get(index) != null) {
6852 subKeyValues.put(vecColumnNames.get(index)
6853 .toString(), vecColumnValues.get(
6854 index).toString());
6855 }
6856 }
6857 }
6858 }
6859 }
6860 }
6861 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase(
6862 "true")) {
6863 for (int p = 0; p < vecTempConstantValues.size(); p++) {
6864 if (vecTempConstantValues.get(p) == null) {
6865 pstmtValues.add("null");
6866 pstmtTypes.add(((Vector) this.vecConstantColumnType
6867 .get(iTableInt)).get(p).toString());
6868 } else {
6869 pstmtValues.add(vecTempConstantValues.get(p)
6870 // .toString()
6871 );
6872 pstmtTypes.add(((Vector) this.vecConstantColumnType
6873 .get(iTableInt)).get(p).toString());
6874
6875 }
6876 // sinisa 15.03 Add subCounter columns
6877 for (int l = 0; l < subCounterKeyColumns.size(); l++) {
6878 if (subCounterKeyColumns.get(l) != null
6879 && ((Vector) subCounterKeyColumns.get(l))
6880 .size() != 0
6881 && ((Vector) subCounterKeyColumns.get(l))
6882 .contains(vecTempConstantColumns.get(p))) {
6883 if (vecTempConstantValues.get(p) != null)
6884 subKeyValues.put(vecTempConstantColumns.get(p)
6885 .toString(), vecTempConstantValues.get(
6886 p).toString());
6887 }
6888 }
6889 }
6890 }
6891 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase(
6892 "true")) {
6893 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) {
6894 if (this.vecVariableTimesTableName.get(i).toString()
6895 .equalsIgnoreCase(
6896 this.vecTableTableName.get(iTableInt)
6897 .toString())
6898 && this.vecVariableTimesTableID.get(i).toString()
6899 .equalsIgnoreCase(
6900 this.vecTableTableID.get(iTableInt)
6901 .toString())) {
6902 pstmtValues.add(createCurrentDate());
6903 pstmtTypes.add("java.sql.Date");
6904 }
6905 }
6906 for (int i = 0; i < this.vecVariableColumnTargetTableName
6907 .size(); i++) {
6908 if (this.vecVariableColumnTargetTableName.get(i).toString()
6909 .equalsIgnoreCase(
6910 this.vecTableTableName.get(iTableInt)
6911 .toString())
6912 && this.vecVariableColumnTargetTableID.get(i)
6913 .toString().equalsIgnoreCase(
6914 this.vecTableTableID.get(iTableInt)
6915 .toString())) {
6916 int iPositionInVector = this.vecVariableName
6917 .indexOf(this.vecVariableColumnName.get(i)
6918 .toString());
6919 if (iPositionInVector != -1) {
6920 if (this.vecVariableValue.get(iPositionInVector) == null) {
6921 String variableName = this.vecVariableColumnName
6922 .get(i).toString();
6923 for (int k = 0; k < this.vecDefaultVariableName
6924 .size(); k++) {
6925 if (this.vecDefaultVariableName.get(k)
6926 .toString().equalsIgnoreCase(
6927 variableName)) {
6928 if (!this.vecDefaultVariableValue
6929 .get(k).toString()
6930 .equalsIgnoreCase("")) {
6931 pstmtValues
6932 .add(this.vecDefaultVariableValue
6933 .get(k)
6934 // .toString()
6935 );
6936 pstmtTypes
6937 .add(this.vecVariableColumnTypes
6938 .get(i).toString());
6939 } else {
6940 pstmtValues.add("null");
6941 pstmtTypes
6942 .add(this.vecVariableColumnTypes
6943 .get(i).toString());
6944 }
6945 break;
6946 }
6947 }
6948 } else {
6949 pstmtValues.add(this.vecVariableValue
6950 .get(iPositionInVector)
6951 // .toString()
6952 );
6953 pstmtTypes.add(this.vecVariableColumnTypes.get(
6954 i).toString());
6955 }
6956 } else {
6957 this.logger.write("normal",
6958 "\tError: Cannot find value for variable column :"
6959 + this.vecVariableColumnName.get(i)
6960 .toString());
6961 LoaderException le = new LoaderException(
6962 "Exception: ",
6963 (Throwable) (new Exception(
6964 "Error: Cannot find value for variable column :")));
6965 this.logger.write("full", le
6966 .getStackTraceAsString());
6967 throw le;
6968 }
6969 // sinisa 15.03 Add subCounter columns
6970 for (int l = 0; l < subCounterKeyColumns.size(); l++) {
6971 if (subCounterKeyColumns.get(l) != null
6972 && ((Vector) subCounterKeyColumns.get(l))
6973 .size() != 0
6974 && ((Vector) subCounterKeyColumns.get(l))
6975 .contains(this.vecVariableColumnName
6976 .get(iPositionInVector))) {
6977 if (this.vecVariableValue
6978 .get(iPositionInVector) != null)
6979 subKeyValues.put(this.vecVariableColumnName
6980 .get(iPositionInVector).toString(),
6981 this.vecVariableValue.get(
6982 iPositionInVector)
6983 .toString());
6984 }
6985 }
6986 }
6987 }
6988 }
6989 // find value for relation column - userID
6990 for (int i = 0; i < this.iRelationColumns; i++) {
6991 outLoop1: if (this.vecRelationColumnSourceTableName.get(i)
6992 .toString().equalsIgnoreCase(
6993 this.vecTableTableName.get(iTableInt)
6994 .toString())
6995 && this.vecRelationColumnSourceTableID.get(i)
6996 .toString().equalsIgnoreCase(
6997 this.vecTableTableID.get(iTableInt)
6998 .toString())) {
6999 for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) {
7000 if (this.vecRelationColumnSourceTableName.get(i)
7001 .toString().equalsIgnoreCase(
7002 this.vecVariableUseIDTableName.get(m)
7003 .toString())
7004 && this.vecRelationColumnSourceTableID.get(i)
7005 .toString().equalsIgnoreCase(
7006 this.vecVariableUseIDTableID
7007 .get(m).toString())) {
7008 String strQueryRelations = "select "
7009 + this.vecRelationColumnSourceColumnName
7010 .get(i).toString()
7011 + " from "
7012 + this.vecRelationColumnSourceTableName
7013 .get(i).toString() + " where ";
7014 strQueryRelations += ((Vector) this.vecTargetKeyColumnName
7015 .get(iTableInt)).get(0).toString()
7016 + " = ";
7017 // ZK change this from CheckType to
7018 // configReaderTarget this 7.5.2004
7019 if (!configReaderTarget
7020 .isNumber(vecColumnNamesTypes.get(0)
7021 .toString()))
7022 strQueryRelations += "'" + this.strUserID + "'";
7023 else
7024 strQueryRelations += this.strUserID;
7025 this.logger.write("full", "\tQuery '"
7026 + strQueryRelations + "' will be executed");
7027 Statement stmt = c.createStatement();
7028 ResultSet rsetTarget = stmt
7029 .executeQuery(strQueryRelations);
7030 if (rsetTarget.next()) {
7031 if (this.iTargetFirstColumnResult == 1) {
7032 this.vecRelationSourceValue.setElementAt(
7033 rsetTarget.getObject(1), i);
7034 this.vecRelationSourceType.setElementAt(
7035 rsetTarget.getMetaData()
7036 .getColumnTypeName(1), i);
7037 } else {
7038 this.vecRelationSourceValue.setElementAt(
7039 rsetTarget.getObject(0), i);
7040 this.vecRelationSourceType.setElementAt(
7041 rsetTarget.getMetaData()
7042 .getColumnTypeName(0), i);
7043 }
7044 }
7045 rsetTarget.close();
7046 stmt.close();
7047 break outLoop1;
7048 }
7049 }
7050 if (bOIDlogicValue) {
7051 String oidType = configReaderTarget.getOidDbType();
7052 int end = oidType.indexOf("(");
7053 if (end != -1)
7054 oidType = (oidType.substring(0, end)).trim();
7055 else
7056 oidType = oidType.trim();
7057 if (this.vecTableInsert.get(iTableInt).toString()
7058 .equalsIgnoreCase("true")) {
7059 // insertTable=true
7060 this.vecRelationSourceValue.setElementAt(
7061 this.bdecOidNumber, i);
7062 this.vecRelationSourceType.setElementAt(oidType
7063 .toLowerCase(), i);
7064
7065 } else {
7066 // insertTable=false
7067 this.vecRelationSourceValue.setElementAt(null, i);
7068 this.vecRelationSourceType.setElementAt(oidType
7069 .toLowerCase(), i);
7070
7071 }
7072 } else { // bOIDlogicValue=false
7073 if (this.iRelationColumns > 0) {
7074 for (int j = 0; j < vecColumnNames.size(); j++) {
7075 if (this.vecRelationColumnSourceColumnName.get(
7076 i).toString().equalsIgnoreCase(
7077 vecColumnNames.get(j).toString())) {
7078 if (this.vecTableInsert.get(iTableInt)
7079 .toString()
7080 .equalsIgnoreCase("true")) {
7081 // insertTable=true
7082 this.vecRelationSourceValue
7083 .setElementAt(vecColumnValues
7084 .get(j).toString(), i);
7085 this.vecRelationSourceType
7086 .setElementAt(
7087 vecColumnNamesTypes
7088 .get(j)
7089 .toString(), i);
7090 } else {
7091 // insertTable=false;
7092 this.vecRelationSourceValue
7093 .setElementAt(null, i);
7094 this.vecRelationSourceType
7095 .setElementAt(
7096 vecColumnNamesTypes
7097 .get(j)
7098 .toString(), i);
7099 }
7100 }
7101 } // end vecColumnNames.size()
7102 }
7103 }
7104 }
7105 }
7106
7107 for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) {
7108 String tmpRelationForCount = "";
7109 if (this.vecRelationColumnTargetTableName.get(i).toString()
7110 .equalsIgnoreCase(
7111 this.vecTableTableName.get(iTableInt)
7112 .toString())
7113 && this.vecRelationColumnTargetTableID.get(i)
7114 .toString().equalsIgnoreCase(
7115 this.vecTableTableID.get(iTableInt)
7116 .toString())) {
7117 if (this.vecRelationSourceValue.get(i) == null) {
7118 String replacementValueInRel = vecDefaultRelationValue
7119 .get(i).toString();
7120 if (!replacementValueInRel.equalsIgnoreCase("")) {
7121 // default value for relation exists
7122 try {
7123 Object obj = relationsCache
7124 .getRelationsCacheValue(replacementValueInRel);
7125 String relationValue;
7126 String relationType;
7127 if (obj != null) {
7128 // relation (default value) is cached
7129 relationValue = obj.toString();
7130 relationType = relationsCache
7131 .getRelationsCachType(replacementValueInRel);
7132 pstmtValues.add(relationValue);
7133 pstmtTypes.add(relationType);
7134 } else {
7135 // relation (default value) isn't cached
7136 ResultSet newRelationValue = null;
7137 Statement newRelationsStmt = c
7138 .createStatement();
7139 try {
7140 this.logger.write("full", "\tQuery '"
7141 + replacementValueInRel
7142 + "' will be executed");
7143 newRelationValue = newRelationsStmt
7144 .executeQuery(replacementValueInRel);
7145 if (newRelationValue.next()) {
7146 relationValue = newRelationValue
7147 .getString(1);
7148 relationsCache
7149 .setRelationsCacheValue(
7150 replacementValueInRel,
7151 relationValue);
7152 relationType = newRelationValue
7153 .getMetaData()
7154 .getColumnTypeName(1);
7155 relationsCache
7156 .setRelationsCacheType(
7157 replacementValueInRel,
7158 relationType);
7159
7160 newRelationValue.close();
7161 newRelationsStmt.close();
7162
7163 String strDataCleaning = dataCleaning
7164 .cleaningRelationValues(
7165 this.vecTableTableName
7166 .get(
7167 iTableInt)
7168 .toString(),
7169 this.vecRelationColumnTargetColumnName
7170 .get(i)
7171 .toString(),
7172 relationValue,
7173 relationType,
7174 currentRow,
7175 c,
7176 "INSERT",
7177 0,
7178 false,
7179 importDefinitionElement.strImportDefinitionName,
7180 this.currentVersionColumnName,
7181 replacementValueInRel);
7182 pstmtValues.add(strDataCleaning);
7183 pstmtTypes.add(relationType);
7184 } else { // newRelationValue.next()=false
7185 newRelationValue.close();
7186 newRelationsStmt.close();
7187 relationValue = "null";
7188 dataCleaning
7189 .cleaningInsert(
7190 this.vecTableTableName
7191 .get(
7192 iTableInt)
7193 .toString(),
7194 c,
7195 currentRow,
7196 "INSERT",
7197 "Default value '"
7198 + replacementValueInRel
7199 + "' for relations is not valid.",
7200 importDefinitionElement.strImportDefinitionName,
7201 replacementValueInRel);
7202
7203 pstmtValues.add("null");
7204 pstmtTypes
7205 .add(this.vecRelationSourceType
7206 .get(i).toString());
7207 }
7208 } catch (SQLException ex) {
7209 newRelationValue.close();
7210 newRelationsStmt.close();
7211 LoaderException le = new LoaderException(
7212 "\n" + "SQLException: "
7213 + ex.getMessage(),
7214 (Throwable) ex);
7215 this.logger.write("full", le
7216 .getStackTraceAsString());
7217 throw le;
7218 }
7219 }
7220
7221 } catch (SQLException ex) {
7222 String msg = "Default value for foreign key("
7223 + replacementValueInRel
7224 + ") is not valid. Import definition name: "
7225 + importDefinitionElement.strImportDefinitionName;
7226 LoaderException le = new LoaderException(
7227 "SQLException: " + msg, (Throwable) ex);
7228 this.logger.write("full", le
7229 .getStackTraceAsString());
7230 throw le;
7231 }
7232
7233 } else { // default value for relations doesn't
7234 // exsist
7235 pstmtValues.add("null");
7236 if (this.vecRelationSourceType.get(i) != null)
7237 pstmtTypes.add(this.vecRelationSourceType
7238 .get(i).toString());
7239 else
7240 pstmtTypes.add("java.lang.Object");
7241 }
7242 } else { // this.vecRelationSourceType.get(i)!=null
7243 pstmtValues.add(this.vecRelationSourceValue.get(i)
7244 .toString());
7245 pstmtTypes.add(this.vecRelationSourceType.get(i)
7246 .toString());
7247
7248 tmpRelationForCount = this.vecRelationSourceValue
7249 .get(i).toString();//
7250 this.vecRelationSourceValue.setElementAt(null, i);
7251
7252 }
7253
7254 // sinisa 15.03 Add subCounter columns
7255 for (int l = 0; l < subCounterKeyColumns.size(); l++) {
7256 if (subCounterKeyColumns.get(l) != null
7257 && ((Vector) subCounterKeyColumns.get(l))
7258 .size() != 0
7259 && ((Vector) subCounterKeyColumns.get(l))
7260 .contains(this.vecRelationColumnTargetColumnName
7261 .get(i))) {
7262 if (tmpRelationForCount != null) {
7263 subKeyValues.put(
7264 this.vecRelationColumnTargetColumnName
7265 .get(i).toString(),
7266 tmpRelationForCount);
7267 }
7268 }
7269 }
7270 }
7271 }
7272
7273 // sinisa 02.03.2003. Add couterColumns
7274 Vector counterColValues = this.counterColumns.getCounterValue(
7275 this.vecTableTableName.get(iTableInt).toString(),
7276 this.vecTableTableID.get(iTableInt).toString());
7277 for (int i = 0; i < counterColValues.size(); i++) {
7278 if (counterColValues.get(i) != null) {
7279 int strInt = new BigDecimal(counterColValues.get(i)
7280 .toString()).intValue();
7281 pstmtValues.add(String.valueOf(strInt));
7282 pstmtTypes.add("java.lang.Integer");
7283 } else {
7284 pstmtValues.add("null");
7285 pstmtTypes.add("java.lang.Integer");
7286 }
7287 }
7288 this.counterColumns.setCounterValue(this.vecTableTableName.get(
7289 iTableInt).toString(), this.vecTableTableID.get(iTableInt)
7290 .toString());
7291 // end sinisa
7292
7293 // sinisa 15.03.2003. Add counterColumns
7294 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase(
7295 "true")) {
7296 this.counterColumns.setSubCounterKeyValues(
7297 this.vecTableTableName.get(iTableInt).toString(),
7298 this.vecTableTableID.get(iTableInt).toString(),
7299 subKeyValues);
7300 Vector subCounterColValues = this.counterColumns
7301 .readSubCounterValue(this.vecTableTableName.get(
7302 iTableInt).toString(), this.vecTableTableID
7303 .get(iTableInt).toString(), c,
7304 this.iTargetFirstColumnResult,
7305 this.vecTableTableMode.get(iTableInt)
7306 .toString(), configReaderTarget);
7307 for (int i = 0; i < subCounterColValues.size(); i++) {
7308 if (subCounterColValues.get(i) != null) {
7309 pstmtValues.add(new BigDecimal(subCounterColValues.get(
7310 i).toString()));
7311 pstmtTypes.add("java.math.BigDecimal");
7312 } else {
7313 pstmtValues.add("null");
7314 pstmtTypes.add("java.math.BigDecimal");
7315 }
7316 }
7317 if (bOIDlogicValue) {
7318 if (this.bdecOidNumber.compareTo(this.bdecOidNumber2000) == 0) {
7319 this.checkOidLogic(c);
7320 this.bdecOidNumber = this.bdecOidNumber
7321 .add(new BigDecimal(1));
7322 } else
7323 this.bdecOidNumber = this.bdecOidNumber
7324 .add(new BigDecimal(1));
7325 }
7326
7327 // ZK added this for transormations
7328 for (int i = 0; i < vecTransformationValue.size(); i++) {
7329 if ((vecTransformationValue.get(i)) == null) {
7330 String valueForPstmt = "null";
7331 pstmtValues.add(valueForPstmt);
7332 } else {
7333 pstmtValues.add(vecTransformationValue.get(i)
7334 // .toString()
7335 );
7336 }
7337
7338 pstmtTypes.add(transformationTargetColumnTypes.get(i)
7339 .toString());
7340
7341 }
7342
7343 // String tableNameId=
7344 // this.vecTableTableName.get(iTableInt).toString()+this.vecTableTableID.get(iTableInt).toString();
7345 // if (transTableNamesIDs.contains(tableNameId)){
7346 // for (int i=0; i < trans.size();i++){
7347 // Transformation pom = (Transformation)trans.get(i);
7348 // Vector sourceColumnNames = pom.getSourceColumnNames();
7349 // Vector targetColumnNames =
7350 // pom.getTargetColumnNames(this.vecTableTableName.get(iTableInt).toString(),
7351 // this.vecTableTableID.get(iTableInt).toString());
7352 //
7353 // Vector resultVector =
7354 // pom.readTransformationValues(sourceColumnNames,
7355 // this.vecTableTableName.get(iTableInt).toString(),
7356 // this.vecTableTableID.get(iTableInt).toString());
7357 // Vector resultVectorTypes =
7358 // pom.getTargetColumnTypes(this.vecTableTableName.get(iTableInt).toString(),
7359 // this.vecTableTableID.get(iTableInt).toString());
7360 // for(int j=0;j < resultVector.size();j++) {
7361 // pstmtValues.add(resultVector.get(j));
7362 // pstmtTypes.add(resultVectorTypes.get(j));
7363 // }
7364 // }
7365 // }
7366 // end
7367
7368 // handling blob object
7369 // strQuery = strQuery + ") VALUES (";
7370 String pstmtColumnValue;
7371 for (int i = 0; i < pstmtValues.size(); i++) {
7372
7373 String javaType = pstmtTypes.get(i).toString()
7374 .toUpperCase();
7375 if (javaType.indexOf("JAVA") == -1) {
7376 // //ZK Added next line because of DB2 type LONG VARCHAR
7377 // javaType = Utils.replaceAll(javaType," ","_");
7378 javaType = (String) configReaderTarget
7379 .getJavaTypeMapings().get(
7380 javaType.toUpperCase());
7381 if (javaType == null) {
7382 LoaderException le = new LoaderException(
7383 "Exception:",
7384 new Exception(
7385 "This type of data "
7386 + pstmtTypes.get(i)
7387 .toString()
7388 .toUpperCase()
7389 + " doesn't exists in the target table conf file!"));
7390 this.logger.write("full", le
7391 .getStackTraceAsString());
7392 throw le;
7393 }
7394 } else {
7395 if (javaType.equalsIgnoreCase("java.math.BigDecimal"))
7396 javaType = "2";
7397 else if (javaType.equalsIgnoreCase("java.lang.Integer"))
7398 javaType = "5";
7399 else if (javaType.equalsIgnoreCase("java.sql.Date"))
7400 javaType = "9";
7401 else if (javaType.equalsIgnoreCase("java.lang.Object"))
7402 javaType = "14";
7403
7404 }
7405
7406 int javaTypeInt = Integer.parseInt(javaType);
7407 pstmtColumnValue = pstmtValues.get(i).toString();
7408 Object pstmtColumnValueAsObject = pstmtValues.get(i);
7409 // ZK changed this 17.6 2004 because of problems with null
7410 // binary object.
7411 // if (pstmtColumnValue.startsWith("binaryObject")) {
7412 if (javaTypeInt == 1) {
7413 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7414 String binaryName = pstmtValues.get(i).toString();
7415 for (int j = 0; j < vecBlobVector.size(); j = j + 5) {
7416 if (binaryName.equalsIgnoreCase(vecBlobVector
7417 .get(j + 4).toString())) {
7418 byte[] isBlob = (byte[]) this.vecBlobVector
7419 .get(j + 1);
7420 strQuery = strQuery + binaryName + ",";
7421 pstmt.setBytes(i + 1, isBlob);
7422 strQuery = strQuery + "BlobObject" + i
7423 + ",";
7424 break;
7425 }
7426 }
7427 } else {
7428 pstmt.setNull(i + 1, java.sql.Types.BINARY);
7429 strQuery = strQuery + "null" + ",";
7430 }
7431 } else {
7432 if (javaTypeInt == 2) { // java.math.BigDecimal
7433 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7434 BigDecimal number = new BigDecimal(0);
7435 if (!pstmtColumnValue.equalsIgnoreCase(""))
7436 number = new BigDecimal(pstmtColumnValue);
7437 strQuery = strQuery + pstmtColumnValue + ",";
7438 pstmt.setBigDecimal(i + 1, number);
7439 } else {
7440 pstmt.setNull(i + 1, java.sql.Types.DECIMAL);
7441 strQuery = strQuery + "null" + ",";
7442 }
7443 } else if (javaTypeInt == 3) { // java.lang.Double
7444 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7445 double number = 0;
7446 if (!pstmtColumnValue.equalsIgnoreCase(""))
7447 number = Double
7448 .parseDouble(pstmtColumnValue);
7449 strQuery = strQuery + pstmtColumnValue + ",";
7450 pstmt.setDouble(i + 1, number);
7451 } else {
7452 strQuery = strQuery + "null" + ",";
7453 pstmt.setNull(i + 1, java.sql.Types.DOUBLE);
7454 }
7455 } else if (javaTypeInt == 4) { // java.lang.Float
7456 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7457 float number = 0;
7458 if (!pstmtColumnValue.equalsIgnoreCase(""))
7459 number = Float.parseFloat(pstmtColumnValue);
7460 pstmt.setFloat(i + 1, number);
7461 strQuery = strQuery + pstmtColumnValue + ",";
7462 } else {
7463 pstmt.setNull(i + 1, java.sql.Types.FLOAT);
7464 strQuery = strQuery + "null" + ",";
7465 }
7466 } else if (javaTypeInt == 5) { // java.lang.Integer
7467 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7468 int number = 0;
7469 if (!pstmtColumnValue.equalsIgnoreCase(""))
7470 number = Integer.parseInt(pstmtColumnValue);
7471 pstmt.setInt(i + 1, number);
7472 strQuery = strQuery + pstmtColumnValue + ",";
7473 } else {
7474 pstmt.setNull(i + 1, java.sql.Types.INTEGER);
7475 strQuery = strQuery + "null" + ",";
7476 }
7477
7478 } else if (javaTypeInt == 6) { // java.lang.Long
7479 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7480 long number = 0;
7481 if (!pstmtColumnValue.equalsIgnoreCase(""))
7482 number = Long.parseLong(pstmtColumnValue);
7483 pstmt.setLong(i + 1, number);
7484 strQuery = strQuery + pstmtColumnValue + ",";
7485 } else {
7486 pstmt.setNull(i + 1, java.sql.Types.DOUBLE);
7487 strQuery = strQuery + "null" + ",";
7488 }
7489 } else if (javaTypeInt == 7) { // java.lang.Short
7490 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7491 short number = 0;
7492 if (!pstmtColumnValue.equalsIgnoreCase(""))
7493 number = Short.parseShort(pstmtColumnValue);
7494 pstmt.setShort(i + 1, number);
7495 strQuery = strQuery + pstmtColumnValue + ",";
7496 } else {
7497 pstmt.setNull(i + 1, java.sql.Types.SMALLINT);
7498 strQuery = strQuery + "null" + ",";
7499 }
7500 } else if (javaTypeInt == 8) { // java.lang.String
7501 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7502 // all '' back to ' (original value)
7503 if (pstmtColumnValue.indexOf("''") != -1) {
7504 pstmtColumnValue = Utils.replaceAll(
7505 pstmtColumnValue, "''", "'");
7506 }
7507 pstmt.setString(i + 1, pstmtColumnValue);
7508 strQuery = strQuery + "'" + pstmtColumnValue
7509 + "'" + ",";
7510 } else {
7511 pstmt.setNull(i + 1, java.sql.Types.VARCHAR);
7512 strQuery = strQuery + "null" + ",";
7513
7514 }
7515 } else if (javaTypeInt == 9) { // java.sql.Date
7516 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7517 if (pstmtColumnValueAsObject instanceof java.sql.Date)
7518 pstmt
7519 .setDate(
7520 i + 1,
7521 (java.sql.Date) pstmtColumnValueAsObject);
7522 else {
7523 //try {
7524 // pstmt.setDate(i + 1, new java.sql.Date(getDateFromString(pstmtColumnValue).getTime()));
7525 //} catch (Exception e) {
7526 this.logger.write("full","call setString on date: "+ pstmtColumnValue);
7527 pstmt.setString(i + 1,pstmtColumnValue);
7528 //}
7529 }
7530 strQuery = strQuery + "'" + pstmtColumnValue
7531 + "'" + ",";
7532 } else {
7533 pstmt.setNull(i + 1, java.sql.Types.DATE);
7534 strQuery = strQuery + "null" + ",";
7535 }
7536 } else if (javaTypeInt == 10) { // java.sql.Time
7537 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7538 if (pstmtColumnValueAsObject instanceof Time)
7539 pstmt
7540 .setTime(
7541 i + 1,
7542 (java.sql.Time) pstmtColumnValueAsObject);
7543 else {
7544 // String format =
7545 // this.configReaderSource.getDateFormat();
7546 // SimpleDateFormat formatDate = new
7547 // SimpleDateFormat(format);
7548 // Date tmpDate =
7549 // formatDate.parse(pstmtColumnValue);
7550 try {
7551 pstmt.setTime(i + 1, new java.sql.Time(
7552 getDateFromString(
7553 pstmtColumnValue)
7554 .getTime()));
7555 } catch (Exception e) {
7556 pstmt
7557 .setString(i + 1,
7558 pstmtColumnValue);
7559 }
7560 }
7561 strQuery = strQuery + "'" + pstmtColumnValue
7562 + "'" + ",";
7563 } else {
7564 pstmt.setNull(i + 1, java.sql.Types.TIME);
7565 strQuery = strQuery + "null" + ",";
7566 }
7567
7568 } else if (javaTypeInt == 11) { // java.sql.Timestamp
7569 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7570 if (pstmtColumnValueAsObject instanceof java.sql.Timestamp)
7571 pstmt
7572 .setTimestamp(
7573 i + 1,
7574 (java.sql.Timestamp) pstmtColumnValueAsObject);
7575 else {
7576 // String format =
7577 // this.configReaderSource.getDateFormat();
7578 // SimpleDateFormat formatDate = new
7579 // SimpleDateFormat(format);
7580 // Date tmpDate =
7581 // formatDate.parse(pstmtColumnValue);
7582 try {
7583 pstmt
7584 .setTimestamp(
7585 i + 1,
7586 new Timestamp(
7587 getDateFromString(
7588 pstmtColumnValue)
7589 .getTime()));
7590 } catch (Exception e) {
7591 pstmt
7592 .setString(i + 1,
7593 pstmtColumnValue);
7594 }
7595 }
7596 strQuery = strQuery + "'" + pstmtColumnValue
7597 + "'" + ",";
7598 } else {
7599 pstmt.setNull(i + 1, java.sql.Types.TIMESTAMP);
7600 strQuery = strQuery + "null" + ",";
7601 }
7602
7603 } else if (javaTypeInt == 12) { // java.lang.Boolean
7604 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7605 boolean bool = new Boolean(pstmtColumnValue)
7606 .booleanValue();
7607 pstmt.setBoolean(i + 1, bool);
7608 strQuery = strQuery + pstmtColumnValue + ",";
7609 } else {
7610 pstmt.setNull(i + 1, java.sql.Types.BIT);
7611 strQuery = strQuery + "null" + ",";
7612 }
7613 } else if (javaTypeInt == 13) { // java.lang.Byte
7614 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7615 pstmt.setString(i + 1, pstmtColumnValue);
7616 strQuery = strQuery + "'" + pstmtColumnValue
7617 + "'" + ",";
7618 } else {
7619 pstmt.setNull(i + 1, java.sql.Types.BIT);
7620 strQuery = strQuery + "null" + ",";
7621 }
7622 } else if (javaTypeInt == 14) { // java.lang.Object
7623 if (!pstmtColumnValue.equalsIgnoreCase("null")) {
7624 pstmt.setString(i + 1, pstmtColumnValue);
7625 strQuery = strQuery + "'" + pstmtColumnValue
7626 + "'" + ",";
7627 } else {
7628 // TODO zoran pogledati ovo
7629 try {
7630 pstmt.setNull(i + 1, java.sql.Types.NULL);
7631 } catch (Exception e) {
7632 pstmt.setString(i + 1, null);
7633 }
7634 strQuery = strQuery + "null" + ",";
7635 }
7636 } else {
7637 LoaderException le = new LoaderException(
7638 "Exception:", new Exception(
7639 "This java type is not supported!"));
7640 this.logger.write("full", le
7641 .getStackTraceAsString());
7642 throw le;
7643 }
7644 }// end of else (not blob)
7645 pstmtColumnValue = null;
7646 }
7647 strQuery = strQuery.substring(0, strQuery.length() - 1) + ")";
7648 this.logger.write("full", "\tQuery '" + strQuery
7649 + "' will be executed");
7650
7651 int pstmtInsert = 0;
7652 pstmtInsert = pstmt.executeUpdate();
7653 // setting the cache value for inseted row
7654 // if (pstmtInsert != 0)
7655 // this.checkRowCache.setCheckRowValue();
7656 pstmt.clearParameters();
7657 pstmtValues.clear();
7658 pstmtTypes.clear();
7659
7660 // TODO 14.6.2004 ZK Comented this because of problems with
7661 // update on counters table which are not needed.
7662 // this.counterColumns.updateCounter(this.vecTableTableName.get(iTableInt).toString(),
7663 // this.vecTableTableID.get(iTableInt).toString(), c);
7664
7665 } else {
7666 // this.checkRowCache.setCheckRowValue();
7667 }
7668 } catch (SQLException ex) {
7669 pstmt.clearParameters();
7670 pstmtValues.clear();
7671 pstmtTypes.clear();
7672 LoaderException le = new LoaderException("SQLException: ",
7673 (Throwable) ex);
7674 if (importDefinitionElement.strDefaultCutOffData
7675 .equalsIgnoreCase("true")) {
7676 dataCleaning.cutingDataLenght(this.vecTableTableName.get(
7677 iTableInt).toString(), c, strQuery, currentRow,
7678 importDefinitionElement.strOnErrorContinueXml, ex
7679 .getMessage(),
7680 importDefinitionElement.strImportDefinitionName,
7681 strQuery);
7682 } else if (importDefinitionElement.strOnErrorContinueXml
7683 .equalsIgnoreCase("true")) {
7684 pstmt.clearParameters();
7685 pstmtValues.clear();
7686 pstmtTypes.clear();
7687 // this.logger.write("full", "\tError in SQL statement: " +
7688 // le.getStackCause());
7689 this.logger.write("full", "\tError in SQL statement: "
7690 + le.getStackTraceAsString());
7691 dataCleaning.cleaningInsert(this.vecTableTableName.get(
7692 iTableInt).toString(), c, currentRow, "INSERT", ex
7693 .getMessage(),
7694 importDefinitionElement.strImportDefinitionName,
7695 strQuery);
7696 } else {
7697 pstmt.clearParameters();
7698 pstmtValues.clear();
7699 pstmtTypes.clear();
7700 this.logger.write("normal", "\tError in SQL statement: "
7701 + le.getCause());
7702 this.logger.write("full", le.getStackTraceAsString());
7703 // throw ex;
7704 throw le;
7705 }
7706 } catch (NullPointerException ex) {
7707 throw ex;
7708 } catch (Exception ex) {
7709 throw ex;
7710 }
7711 this.logger.write("full", "\tinsertRow method is finished.");
7712 }
7713
7714 /***
7715 * Method isRelationColumn checkes if the column(strColumnName) in target
7716 * table(iTable) is mentioned in relation tags (target column name). If it
7717 * is, return true, else return false.
7718 *
7719 * @param strColumnName -
7720 * Name of target column
7721 * @param iTable -
7722 * Number of target table
7723 * @return boolean - true if strColumnName is relation target column, false
7724 * if it is not.
7725 */
7726 private boolean isRelationColumn(String strColumnName, int iTable) {
7727 boolean bFind = false;
7728 endFor: for (int i = 0; i < this.vecRelationColumnTargetTableName
7729 .size(); i++) {
7730 if (this.vecRelationColumnTargetTableName.get(i).toString()
7731 .equalsIgnoreCase(
7732 this.vecTableTableName.get(iTable).toString())
7733 && this.vecRelationColumnTargetTableID
7734 .get(i)
7735 .toString()
7736 .equalsIgnoreCase(
7737 this.vecTableTableID.get(iTable).toString())
7738 && this.vecRelationColumnTargetColumnName.get(i).toString()
7739 .equalsIgnoreCase(strColumnName)) {
7740 bFind = true;
7741 break endFor;
7742 }
7743 }
7744 return bFind;
7745 }
7746
7747 /***
7748 * Method checkOidLogic is used to increase the ObjectID value with adding
7749 * iObjectIDIncrement value. Method puts new value in ObjectID table for
7750 * current importDefinition. If there is an error, Exception "SQLException"
7751 * or NullPointerException is thrown.
7752 *
7753 * @param c
7754 * Connection to target database.
7755 * @throws SQLException
7756 * Constructs an SQLException object with a reason.
7757 * @throws NullPointerException
7758 * Constructs a NullPointerException with the specified detail
7759 * message.
7760 */
7761 private void checkOidLogic(Connection c) throws SQLException,
7762 NullPointerException {
7763 String strQuery = "";
7764 this.logger.write("full", "\tcheckOidLogic method is started.");
7765 Boolean bTemp = new Boolean("false");
7766
7767 if (currentJobName.equalsIgnoreCase("importDefinition")) {
7768 for (int i = 0; i < this.iTables; i++) {
7769 if (this.vecTableOidLogic.get(i).toString().equalsIgnoreCase(
7770 "true")) {
7771 bTemp = new Boolean("true");
7772 }
7773 }
7774 } else if (currentJobName.equalsIgnoreCase("copyTable")) {
7775 if (importDefinitionElement.strCopyTableOidLogic
7776 .equalsIgnoreCase("true")) {
7777 bTemp = new Boolean("true");
7778 }
7779 }
7780
7781 if (bTemp.booleanValue()) {
7782 try {
7783 if (!(importDefinitionElement.strObjectIDNameColumnName
7784 .equals("") || importDefinitionElement.strObjectIDNameColumnValue
7785 .equals(""))) {
7786 strQuery = new String(
7787 "SELECT "
7788 + importDefinitionElement.strObjectIDColumnName
7789 + " FROM "
7790 + importDefinitionElement.strObjectIDTableName
7791 + " WHERE "
7792 + importDefinitionElement.strObjectIDNameColumnName
7793 + " = '"
7794 + importDefinitionElement.strObjectIDNameColumnValue
7795 + "'");
7796 } else {
7797 strQuery = new String("SELECT "
7798 + importDefinitionElement.strObjectIDColumnName
7799 + " FROM "
7800 + importDefinitionElement.strObjectIDTableName);
7801 }
7802 this.logger.write("full", "\tQuery '" + strQuery
7803 + "' will be executed");
7804 Statement stmtOid = c.createStatement();
7805 ResultSet rsetOid = stmtOid.executeQuery(strQuery);
7806 if (rsetOid.next()) {
7807 if (this.iTargetFirstColumnResult == 1)
7808 this.bdecOidNumber = new BigDecimal(rsetOid.getString(1));
7809 else
7810 this.bdecOidNumber = new BigDecimal(rsetOid.getString(0));
7811 } else {
7812 if (!(importDefinitionElement.strObjectIDNameColumnName
7813 .equals("") || importDefinitionElement.strObjectIDNameColumnValue
7814 .equals(""))) {
7815 String insert = "insert into "
7816 + importDefinitionElement.strObjectIDTableName
7817 + " ("
7818 + importDefinitionElement.strObjectIDNameColumnName
7819 + ","
7820 + importDefinitionElement.strObjectIDColumnName
7821 + ") values ('"
7822 + importDefinitionElement.strObjectIDNameColumnValue
7823 + "','"
7824 + importDefinitionElement.iObjectIDStartValue
7825 + "');";
7826 stmtOid.execute(insert);
7827 }
7828 }
7829 rsetOid.close();
7830 stmtOid.close();
7831
7832 if (currentJobName.equalsIgnoreCase("copyTable")) {
7833 this.bdecOidNumber2000 = this.bdecOidNumber
7834 .add(new BigDecimal(
7835 importDefinitionElement.iObjectIDCT));
7836 } else {
7837 this.bdecOidNumber2000 = this.bdecOidNumber
7838 .add(new BigDecimal(
7839 importDefinitionElement.iObjectID));
7840 }
7841 Statement stmtOid2 = c.createStatement();
7842 if (!(importDefinitionElement.strObjectIDNameColumnName
7843 .equals("") || importDefinitionElement.strObjectIDNameColumnValue
7844 .equals(""))) {
7845 this.logger
7846 .write(
7847 "full",
7848 "\tQuery '"
7849 + "UPDATE "
7850 + importDefinitionElement.strObjectIDTableName
7851 + " SET "
7852 + importDefinitionElement.strObjectIDColumnName
7853 + " = "
7854 + this.bdecOidNumber2000
7855 + " where "
7856 + importDefinitionElement.strObjectIDNameColumnName
7857 + " = '"
7858 + importDefinitionElement.strObjectIDNameColumnValue
7859 + "'' will be executed");
7860 stmtOid2
7861 .executeUpdate("UPDATE "
7862 + importDefinitionElement.strObjectIDTableName
7863 + " SET "
7864 + importDefinitionElement.strObjectIDColumnName
7865 + " = "
7866 + this.bdecOidNumber2000
7867 + " where "
7868 + importDefinitionElement.strObjectIDNameColumnName
7869 + " = '"
7870 + importDefinitionElement.strObjectIDNameColumnValue
7871 + "'");
7872 } else {
7873 this.logger
7874 .write(
7875 "full",
7876 "\tQuery '"
7877 + "UPDATE "
7878 + importDefinitionElement.strObjectIDTableName
7879 + " SET "
7880 + importDefinitionElement.strObjectIDColumnName
7881 + " = "
7882 + this.bdecOidNumber2000
7883 + " where "
7884 + importDefinitionElement.strObjectIDColumnName
7885 + " = " + this.bdecOidNumber
7886 + "' will be executed");
7887 stmtOid2.executeUpdate("UPDATE "
7888 + importDefinitionElement.strObjectIDTableName
7889 + " SET "
7890 + importDefinitionElement.strObjectIDColumnName
7891 + " = " + this.bdecOidNumber2000 + " where "
7892 + importDefinitionElement.strObjectIDColumnName
7893 + " = " + this.bdecOidNumber);
7894 }
7895 stmtOid2.close();
7896 } catch (SQLException ex) {
7897 throw ex;
7898 } catch (NullPointerException ex) {
7899 throw ex;
7900 }
7901 }
7902 this.logger.write("full", "\tcheckOidLogic method is finished.");
7903 }
7904
7905 /***
7906 * Method querySource is used to make SQL query to source table and to sort
7907 * columns from source table ordered by sortColumns.
7908 *
7909 * @return SQL Query to source table.
7910 * @throws LoaderException
7911 */
7912 private String querySource() throws LoaderException {
7913 int i = 0;
7914 int j = 0;
7915 this.logger.write("full", "\tquerySource method is started.");
7916 Vector vecVektor = new Vector();
7917 String strQuery = "select ";
7918 // this is pointer where transformations columns starts within result
7919 // set
7920 // this.iOffsetForTransColumns = 0;
7921 while (i < this.iTables) {
7922 vecVektor = (Vector) this.vecSourceColumnName.get(i);
7923 // this.iOffsetForTransColumns += vecVektor.size();
7924 while (j < Integer.parseInt(this.vecValueColumnsTargetTables.get(i)
7925 .toString())) {
7926 strQuery = strQuery + vecVektor.get(j).toString() + ", ";
7927 j++;
7928 this.iColumnsInSourceTable++;
7929 }
7930 j = 0;
7931 i++;
7932 }
7933 ArrayList trans = this.transformations.getTransformations();
7934 // int numTransSourceColumns = 0;
7935 // read all source columns for all transformations
7936 // i = 0;
7937 // while (i < this.iTables) {
7938 for (int k = 0; k < trans.size(); k++) {
7939 Transformation transformation = (Transformation) trans.get(k);
7940 // if( i != Integer.parseInt( transformation.getTargetTableID() ) )
7941 // continue;
7942 Vector sourceColumnNames = transformation.getSourceColumnNames();
7943 for (int kk = 0; kk < sourceColumnNames.size(); kk++) {
7944 strQuery = strQuery + sourceColumnNames.get(kk).toString()
7945 + ", ";
7946 // numTransSourceColumns++;
7947 }
7948 }
7949 // this.vecTransformColumnsTargetTables.add(
7950 // String.valueOf(numTransSourceColumns) );
7951 // numTransSourceColumns=0;
7952 // i++;
7953 // }
7954 strQuery = strQuery.substring(0, strQuery.length() - 2);
7955 strQuery += " from "
7956 + importDefinitionElement.strImportDefinitionTableName;
7957 if (importDefinitionElement.vecRestartCounterSortColumn.size() != 0) {
7958 if (configReaderSource.getEnableOrderBy()) {
7959 strQuery += " order by ";
7960 for (j = 0; j < importDefinitionElement.vecRestartCounterSortColumn
7961 .size(); j++) {
7962 strQuery += importDefinitionElement.vecRestartCounterSortColumn
7963 .get(j).toString()
7964 + ", ";
7965 }
7966 strQuery = strQuery.substring(0, strQuery.length() - 2);
7967 }
7968 }
7969
7970 this.logger.write("full", "\tquerySource method is finished.");
7971 return strQuery;
7972 }
7973
7974 /***
7975 * Method targetColumnTypes is used to put source table column types into
7976 * Vector "vecSourceColumnType". This includes columns from the querySource
7977 * method. If there is an error, Exception "SQLException" or
7978 * NullPointerException is thrown.
7979 *
7980 * @param connTarget
7981 * Connection to the target table.
7982 * @throws SQLException
7983 * Constructs an SQLException object with a reason.
7984 * @throws NullPointerException
7985 * Constructs a NullPointerException with the specified detail
7986 * message.
7987 */
7988 private void targetColumnTypes(Connection connTarget) throws SQLException,
7989 NullPointerException {
7990 int iColumn;
7991 String strQueryTypes = "";
7992 this.logger.write("full", "\ttargetColumnTypes method is started.");
7993 try {
7994 for (int i = 0; i < this.iTables; i++) {
7995 Vector vecKeyTypesRelations = new Vector();
7996 Vector vecVektor = new Vector();
7997 iColumn = 0;
7998 Statement stmtTypes = connTarget.createStatement();
7999 // ZK added 11.6.2004 because of new parameter
8000 // GetMaxRowsSupported
8001 if (this.configReaderTarget.getMaxRowsSupported()) {
8002 stmtTypes.setMaxRows(1);
8003 }
8004
8005 strQueryTypes = "select ";
8006 for (int j = 0; j < ((Vector) this.vecTargetColumnName.get(i))
8007 .size(); j++) {
8008 strQueryTypes += (((Vector) this.vecTargetColumnName.get(i))
8009 .get(j).toString())
8010 + ",";
8011 }
8012 for (int j = 0; j < ((Vector) this.vecRelationKeyColumns.get(i))
8013 .size(); j++) {
8014 strQueryTypes += (((Vector) this.vecRelationKeyColumns
8015 .get(i)).get(j).toString())
8016 + ",";
8017 }
8018 strQueryTypes = strQueryTypes.substring(0, strQueryTypes
8019 .length() - 1);
8020 strQueryTypes += " from ";
8021 strQueryTypes += " " + this.vecTableTableName.get(i).toString();
8022
8023 if (((Vector) this.vecTargetColumnName.get(i)).size() != 0
8024 || ((Vector) this.vecRelationKeyColumns.get(i)).size() != 0) {
8025
8026 this.logger.write("full", "\tQuery '" + strQueryTypes
8027 + "' will be executed");
8028 ResultSet rsetTypes = stmtTypes.executeQuery(strQueryTypes);
8029 for (int j = 0; j < ((Vector) this.vecValueMode.get(i))
8030 .size(); j++) {
8031 iColumn++;
8032 if (this.iTargetFirstColumnResult == 1)
8033 vecVektor.add(rsetTypes.getMetaData()
8034 .getColumnTypeName(iColumn));
8035 else
8036 vecVektor.add(rsetTypes.getMetaData()
8037 .getColumnTypeName(iColumn - 1));
8038 }
8039 for (int j = 0; j < ((Vector) this.vecRelationKeyColumns
8040 .get(i)).size(); j++) {
8041 iColumn++;
8042 if (this.iTargetFirstColumnResult == 1)
8043 vecKeyTypesRelations.add(rsetTypes.getMetaData()
8044 .getColumnTypeName(iColumn));
8045 else
8046 vecKeyTypesRelations.add(rsetTypes.getMetaData()
8047 .getColumnTypeName(iColumn - 1));
8048 }
8049 rsetTypes.close();
8050 }
8051 stmtTypes.close();
8052 this.vecRelationKeyTypes.setElementAt(vecKeyTypesRelations, i);
8053 this.vecTargetColumnType.add(vecVektor);
8054 }
8055 Statement stmtVariableTypes = connTarget.createStatement();
8056 if (this.configReaderTarget.getMaxRowsSupported()) {
8057 stmtVariableTypes.setMaxRows(1);
8058 }
8059 for (int j = 0; j < this.vecVariableColumnTargetTableName.size(); j++) {
8060 strQueryTypes = "select ";
8061 strQueryTypes += this.vecVariableColumnTargetColumnName.get(j)
8062 .toString()
8063 + " from ";
8064 strQueryTypes += this.vecVariableColumnTargetTableName.get(j)
8065 .toString();
8066 ResultSet rsetVariableTypes;
8067 this.logger.write("full", "\tQuery '" + strQueryTypes
8068 + "' will be executed");
8069 rsetVariableTypes = stmtVariableTypes
8070 .executeQuery(strQueryTypes);
8071 if (this.iTargetFirstColumnResult == 1)
8072 this.vecVariableColumnTypes.add(rsetVariableTypes
8073 .getMetaData().getColumnTypeName(1));
8074 else
8075 this.vecVariableColumnTypes.add(rsetVariableTypes
8076 .getMetaData().getColumnTypeName(0));
8077 rsetVariableTypes.close();
8078 }
8079 stmtVariableTypes.close();
8080 } catch (SQLException ex) {
8081 throw ex;
8082 } catch (NullPointerException ex) {
8083 throw ex;
8084 }
8085 this.logger.write("full", "\ttargetColumnTypes method is finished.");
8086 }
8087
8088 /***
8089 * Metod createCurrentDate is used to create current date and time in format
8090 * that supported by SQL server.
8091 *
8092 * @return String representation of current date and time.
8093 */
8094 private String createCurrentDate() {
8095
8096 // it is read from configReaderSource because before call to setDate on
8097 // target database, it will be parsed using date format
8098 // from source config and transformed into java.sql.Date
8099 String strDateTimeFormat = this.configReaderSource.getDateFormat();
8100 SimpleDateFormat tmpDate = new SimpleDateFormat(strDateTimeFormat);
8101 String strDate = tmpDate.format(new Date(System.currentTimeMillis()));
8102 return strDate;
8103
8104 }
8105
8106 /***
8107 * Method constantColumnTypes is used to put types of constant columns into
8108 * global vector sorted in target tables.If there is an error, Exception
8109 * "SQLException" or "NullPointerException" is thrown.
8110 *
8111 * @param c
8112 * Connection to target database.
8113 * @throws SQLException
8114 * Constructs an SQLException object with a reason.
8115 * @throws NullPointerException
8116 * Constructs a NullPointerException with the specified detail
8117 * message.
8118 */
8119 private void constantColumnTypes(Connection c) throws SQLException,
8120 NullPointerException {
8121 int iCnt = 0;
8122 this.logger.write("full", "\tconstantColumnTypes method is started.");
8123 try {
8124 for (int i = 0; i < this.iTables; i++) {
8125 Vector vecTempConstantType = new Vector();
8126 Vector vecTempConstantName = new Vector();
8127 String strQuery = "select ";
8128 vecTempConstantName = (Vector) this.vecConstantTargetColumnName
8129 .get(i);
8130 if (vecTempConstantName.size() != 0) {
8131 Statement stmtConstant = c.createStatement();
8132 for (int j = 0; j < vecTempConstantName.size(); j++)
8133 strQuery += vecTempConstantName.get(j).toString()
8134 + ", ";
8135 strQuery = strQuery.substring(0, strQuery.length() - 2);
8136 strQuery += " from "
8137 + this.vecTableTableName.get(i).toString();
8138 this.logger.write("full", "\tQuery '" + strQuery
8139 + "' will be executed");
8140 ResultSet rsetConstant = stmtConstant
8141 .executeQuery(strQuery);
8142 iCnt = vecTempConstantName.size();
8143 for (int k = 0; k < iCnt; k++) {
8144 if (this.iTargetFirstColumnResult == 1)
8145 vecTempConstantType.add(rsetConstant.getMetaData()
8146 .getColumnTypeName(k + 1));
8147 else
8148 vecTempConstantType.add(rsetConstant.getMetaData()
8149 .getColumnTypeName(k));
8150 }
8151 rsetConstant.close();
8152 stmtConstant.close();
8153 }
8154 this.vecConstantColumnType.setElementAt(vecTempConstantType, i);
8155 }
8156 } catch (SQLException ex) {
8157 throw ex;
8158 } catch (NullPointerException ex) {
8159 throw ex;
8160 }
8161 this.logger.write("full", "\tconstantColumnTypes method is finished.");
8162 }
8163
8164 /***
8165 * Method inputUser is used to give a user the possibility to connect to
8166 * Source and Target database using user name and password. If missing, user
8167 * and password parameters for database in XML file, Loader asks user for
8168 * these parameters. If there is an error, Exception "IOException" is
8169 * thrown.
8170 *
8171 * @param b
8172 * Boolean type. If b is true- source database, false- target
8173 * database
8174 * @throws IOException
8175 * Constructs an IOException with the specified detail message.
8176 */
8177 private void inputUser(boolean b) throws java.io.IOException {
8178 if (b) {
8179 if (BufferOctopusClass.getInstance().IsUsed())
8180 throw new IOException(
8181 "Missing user name and password for the Source DB. Check LoaderJob.olj file!");
8182 else
8183 this.logger.write("normal",
8184 "Missing user name and password for the Source DB.");
8185 } else {
8186 if (BufferOctopusClass.getInstance().IsUsed())
8187 throw new IOException(
8188 "Missing user name and password for the Target DB. Check LoaderJob.olj file!");
8189 else
8190 this.logger.write("normal",
8191 "Missing user name and password for the Target DB.");
8192 }
8193 String strUserName;
8194 String strPassword;
8195 char cu;
8196 char cp;
8197 StringBuffer bufu = new StringBuffer();
8198 StringBuffer bufp = new StringBuffer();
8199 System.out.println("User name: ");
8200 try {
8201 while ((cu = (char) System.in.read()) != '\n')
8202 bufu.append(cu);
8203 strUserName = bufu.toString();
8204 strUserName = strUserName.substring(0, strUserName.length() - 1);
8205 System.out.println("Password: ");
8206 while ((cp = (char) System.in.read()) != '\n')
8207 bufp.append(cp);
8208 strPassword = bufp.toString();
8209 if (strPassword.length() != 0)
8210 strPassword = strPassword
8211 .substring(0, strPassword.length() - 1);
8212 if (b) {
8213 jdbcParametersElement.setJDBCSourceParameterUser(strUserName);
8214 jdbcParametersElement
8215 .setJDBCSourceParameterPassword(strPassword);
8216 } else {
8217 jdbcParametersElement.setJDBCTargetParameterUser(strUserName);
8218 jdbcParametersElement
8219 .setJDBCTargetParameterPassword(strPassword);
8220 }
8221 } catch (IOException ex) {
8222 throw ex;
8223 }
8224 }
8225
8226 /***
8227 * Method changeTableOrder change order of Tables into public Vector
8228 * vecTableTableName Relation source tables puts before the others target
8229 * tables.
8230 */
8231 private void changeTableOrder() {
8232 Vector vecTempTableTableName = new Vector();
8233 Vector vecTempTableTableID = new Vector();
8234 Vector vecTempTableInsert = new Vector();
8235 Vector vecTempTableTableMode = new Vector();
8236 Vector vecTempTableOidLogic = new Vector();
8237 Vector vecNumberOfTable = new Vector();
8238 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
8239 int iNumberOfTable = 0;
8240 for (int j = 0; j < this.vecTableTableName.size(); j++) {
8241 if (this.vecTableTableName.get(j).toString()
8242 .equalsIgnoreCase(
8243 this.vecRelationColumnSourceTableName.get(i)
8244 .toString())
8245 && this.vecTableTableID.get(j).toString()
8246 .equalsIgnoreCase(
8247 this.vecRelationColumnSourceTableID
8248 .get(i).toString())) {
8249 iNumberOfTable = j;
8250 boolean bEqualsRelationSource = false;
8251 for (int k = 0; k < vecNumberOfTable.size(); k++) {
8252 if (j == (new Integer(vecNumberOfTable.get(k)
8253 .toString())).intValue())
8254 bEqualsRelationSource = true;
8255 }
8256 if (!bEqualsRelationSource) {
8257 vecTempTableTableName.addElement(this.vecTableTableName
8258 .get(j).toString());
8259 vecTempTableTableID.addElement(this.vecTableTableID
8260 .get(j).toString());
8261 vecTempTableInsert.addElement(this.vecTableInsert
8262 .get(j).toString());
8263 vecTempTableTableMode.addElement(this.vecTableTableMode
8264 .get(j).toString());
8265 vecTempTableOidLogic.addElement(this.vecTableOidLogic
8266 .get(j).toString());
8267 vecNumberOfTable
8268 .addElement(new Integer(iNumberOfTable));
8269 }
8270 }
8271 }
8272 }
8273 if (this.vecRelationColumnSourceTableName.size() != 0) {
8274 for (int i = 0; i < this.vecTableTableName.size(); i++) {
8275 boolean bEquals = false;
8276 for (int j = 0; j < vecNumberOfTable.size(); j++) {
8277 if (i == (new Integer(vecNumberOfTable.get(j).toString()))
8278 .intValue()) {
8279 bEquals = true;
8280 }
8281 }
8282 if (!bEquals) {
8283 vecTempTableTableName.addElement(this.vecTableTableName
8284 .get(i).toString());
8285 vecTempTableTableID.addElement(this.vecTableTableID.get(i)
8286 .toString());
8287 vecTempTableInsert.addElement(this.vecTableInsert.get(i)
8288 .toString());
8289 vecTempTableTableMode.addElement(this.vecTableTableMode
8290 .get(i).toString());
8291 vecTempTableOidLogic.addElement(this.vecTableOidLogic
8292 .get(i).toString());
8293 }
8294 }
8295 this.vecTableTableName = new Vector();
8296 this.vecTableTableID = new Vector();
8297 this.vecTableInsert = new Vector();
8298 this.vecTableTableMode = new Vector();
8299 this.vecTableOidLogic = new Vector();
8300 for (int i = 0; i < vecTempTableTableName.size(); i++) {
8301 this.vecTableTableName.addElement(vecTempTableTableName.get(i)
8302 .toString());
8303 this.vecTableTableID.addElement(vecTempTableTableID.get(i)
8304 .toString());
8305 this.vecTableInsert.addElement(vecTempTableInsert.get(i)
8306 .toString());
8307 this.vecTableTableMode.addElement(vecTempTableTableMode.get(i)
8308 .toString());
8309 this.vecTableOidLogic.addElement(vecTempTableOidLogic.get(i)
8310 .toString());
8311 }
8312 }
8313 }
8314
8315 /***
8316 * Method changeRelationsOrder change order of relation tags. Order of
8317 * relation tags depends of 'complex relations'. Method puts at the begining
8318 * of relation global Vectors relations which is used only to read source
8319 * values for another relation.
8320 *
8321 */
8322 private void changeRelationsOrder() {
8323 Vector vecTempSourceTableName = new Vector();
8324 Vector vecTempSourceTableID = new Vector();
8325 Vector vecTempSourceColumnName = new Vector();
8326 Vector vecTempTargetTableName = new Vector();
8327 Vector vecTempTargetTableID = new Vector();
8328 Vector vecTempTargetColumnName = new Vector();
8329 Vector vecTempRelationMode = new Vector();
8330 Vector vecRelationsOrder = new Vector();
8331 vecRelationsOrder.setSize(this.vecRelationColumnSourceTableName.size());
8332 for (int i = 0; i < vecRelationsOrder.size(); i++)
8333 vecRelationsOrder.setElementAt(new Integer(i), i);
8334 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
8335 if (this.vecRelationColumnRelationMode.get(i).toString()
8336 .equalsIgnoreCase("Key")) {
8337 for (int j = 0; j < this.vecRelationColumnSourceTableName
8338 .size(); j++) {
8339 if (this.vecRelationColumnSourceTableName.get(i).toString()
8340 .equalsIgnoreCase(
8341 this.vecRelationColumnTargetTableName
8342 .get(j).toString())
8343 && this.vecRelationColumnSourceTableID.get(i)
8344 .toString().equalsIgnoreCase(
8345 this.vecRelationColumnTargetTableID
8346 .get(j).toString()))
8347 vecRelationsOrder = this.setAfter(vecRelationsOrder, i,
8348 j);
8349 }
8350 } else {
8351 vecRelationsOrder = this.setLast(vecRelationsOrder, i);
8352 }
8353 }
8354 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
8355 vecTempSourceTableName.add(this.vecRelationColumnSourceTableName
8356 .get(i));
8357 vecTempSourceTableID
8358 .add(this.vecRelationColumnSourceTableID.get(i));
8359 vecTempSourceColumnName.add(this.vecRelationColumnSourceColumnName
8360 .get(i));
8361 vecTempTargetTableName.add(this.vecRelationColumnTargetTableName
8362 .get(i));
8363 vecTempTargetTableID
8364 .add(this.vecRelationColumnTargetTableID.get(i));
8365 vecTempTargetColumnName.add(this.vecRelationColumnTargetColumnName
8366 .get(i));
8367 vecTempRelationMode.add(this.vecRelationColumnRelationMode.get(i));
8368 }
8369 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) {
8370 this.vecRelationColumnSourceTableName.setElementAt(
8371 vecTempSourceTableName.get(Integer
8372 .parseInt(vecRelationsOrder.get(i).toString())), i);
8373 this.vecRelationColumnSourceTableID.setElementAt(
8374 vecTempSourceTableID.get(Integer.parseInt(vecRelationsOrder
8375 .get(i).toString())), i);
8376 this.vecRelationColumnSourceColumnName.setElementAt(
8377 vecTempSourceColumnName.get(Integer
8378 .parseInt(vecRelationsOrder.get(i).toString())), i);
8379 this.vecRelationColumnTargetTableName.setElementAt(
8380 vecTempTargetTableName.get(Integer
8381 .parseInt(vecRelationsOrder.get(i).toString())), i);
8382 this.vecRelationColumnTargetTableID.setElementAt(
8383 vecTempTargetTableID.get(Integer.parseInt(vecRelationsOrder
8384 .get(i).toString())), i);
8385 this.vecRelationColumnTargetColumnName.setElementAt(
8386 vecTempTargetColumnName.get(Integer
8387 .parseInt(vecRelationsOrder.get(i).toString())), i);
8388 this.vecRelationColumnRelationMode.setElementAt(
8389 vecTempRelationMode.get(Integer.parseInt(vecRelationsOrder
8390 .get(i).toString())), i);
8391 }
8392 }
8393
8394 /***
8395 * Method setLast changes order of vecOrder's elements. Element at
8396 * iRelationTag position will be removed and inserted at the end of Vector.
8397 *
8398 * @param vecOrder
8399 * Vector - order of relation tags
8400 * @param iRelationTag
8401 * integer - position of element in Vector which changes its
8402 * position.
8403 * @return Vector - order of relation tags after changing positions of
8404 * elements.
8405 */
8406 private Vector setLast(Vector vecOrder, int iRelationTag) {
8407 int iLast = vecOrder.indexOf(new Integer(iRelationTag));
8408 vecOrder.remove(iLast);
8409 vecOrder.add(new Integer(iRelationTag));
8410 return vecOrder;
8411 }
8412
8413 /***
8414 * Method setAfter changes order of vecOrder's elements. Element at
8415 * iIndexCurrent position will be removed and inserted after element at
8416 * iIndexTarget position.
8417 *
8418 * @param vecOrder
8419 * Vector - order of relation tags
8420 * @param iIndexCurrent
8421 * integer - position of element in Vector which changes its
8422 * position.
8423 * @param iIndexTarget
8424 * integer - position of 'target' element in Vector .
8425 * @return Vector - order of relation tags after changing element's
8426 * positions.
8427 */
8428 Vector setAfter(Vector vecOrder, int iIndexCurrent, int iIndexTarget) {
8429 if (iIndexCurrent < iIndexTarget) {
8430 int iCurrent = vecOrder.indexOf(new Integer(iIndexCurrent));
8431 vecOrder.remove(iCurrent);
8432 int iTarget = vecOrder.indexOf(new Integer(iIndexTarget));
8433 vecOrder.insertElementAt(new Integer(iIndexCurrent), iTarget + 1);
8434 }
8435 return vecOrder;
8436 }
8437
8438 /***
8439 * Method executeSQLStatement is used to execute SQL statement. This method
8440 * executes and commit changes immediately. JDBC parameters, Continue on
8441 * Error parameters and SQL statements are set in XML file. If there is an
8442 * error Exception "Exception" is thrown.
8443 *
8444 * @throws Exception
8445 */
8446 private void executeSQLStatement() throws Exception {
8447 Connection conn = null;
8448 try {
8449 this.logger
8450 .write("full", "\tmethod executeSQLStatement is started");
8451 // this.logger.write("normal", "SQL statement " + this.strSqlName +
8452 // " is started");
8453 Class.forName(jdbcParametersElement.getJDBCTargetParameterDriver());
8454 conn = DriverManager.getConnection(jdbcParametersElement
8455 .getJDBCTargetParameterConnection(), jdbcParametersElement
8456 .getJDBCTargetParameterUser(), jdbcParametersElement
8457 .getJDBCTargetParameterPassword());
8458 Statement stmtSeparate = conn.createStatement();
8459 for (int i = 0; i < this.vecSqlStmt.size(); i++) {
8460 this.logger.write("full", "\tSQL_stmt : '"
8461 + this.vecSqlStmt.get(i).toString()
8462 + "' will be executed");
8463 Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt
8464 .get(i).toString());
8465 for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
8466 executeSql(stmtSeparate,
8467 vecSingleSqlStmt.get(j).toString(), 0);
8468 }
8469 }
8470 stmtSeparate.close();
8471 conn.close();
8472 } catch (SQLException e) {
8473 throw e;
8474 } finally {
8475 if (conn != null && !conn.isClosed())
8476 conn.close();
8477 }
8478 }
8479
8480 /***
8481 * Method executeSQLStatement is used to execute SQL statement. This method
8482 * commit changes immediately only if is commit paremeter true. If it is
8483 * false commit changes after all aql stetements. JDBC parameters, Continue
8484 * on Error parameters and SQL statements are set in XML file. If there is
8485 * an error Exception "Exception" is thrown.
8486 *
8487 * @param conn
8488 * represents connection to target table
8489 * @throws Exception
8490 */
8491 private void executeSQLStatement(Connection conn) throws Exception {
8492 try {
8493 this.timeCounter.setStartJobTime();
8494 this.logger
8495 .write("full", "\tmethod executeSQLStatement is started");
8496 this.logger.write("normal", "SQL statement "
8497 + sqlElement.getSqlName() + " is started");
8498 boolean isCreateDatabaseStatement = false;
8499 out: for (int i = 0; i < this.vecSqlStmt.size(); i++) {
8500 if (this.vecSqlStmt.get(i).toString().toUpperCase().trim()
8501 .startsWith("CREATE DATABASE")
8502 || this.vecSqlStmt.get(i).toString().toUpperCase()
8503 .trim().startsWith("DROP DATABASE")) {
8504 isCreateDatabaseStatement = true;
8505 break out;
8506 }
8507 }
8508 if (isCreateDatabaseStatement) {
8509 executeSQLStatement();
8510 } else {
8511
8512 Statement stmtSeparate = conn.createStatement();
8513 for (int i = 0; i < this.vecSqlStmt.size(); i++) {
8514 this.logger.write("full", "\tSQL_stmt : '"
8515 + this.vecSqlStmt.get(i).toString()
8516 + "' will be executed");
8517 Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt
8518 .get(i).toString());
8519 for (int j = 0; j < vecSingleSqlStmt.size(); j++) {
8520 executeSql(stmtSeparate, vecSingleSqlStmt.get(j)
8521 .toString(), j + 1);
8522 }
8523 }
8524 if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) {
8525 if (!conn.getAutoCommit())
8526 conn.commit();
8527 }
8528 stmtSeparate.close();
8529 }
8530
8531 this.logger.write("normal", "SQL statement "
8532 + sqlElement.getSqlName() + " is finished");
8533 this.logger.write("full",
8534 "\tmethod executeSQLStatement is finished");
8535 this.logger.write("normal", " Duration :"
8536 + this.timeCounter.getJobTime());
8537 } catch (SQLException e) {
8538 throw e;
8539 }
8540 }
8541
8542 /***
8543 * Method sqlStringToVector is used to cut Sql string with number of
8544 * statements into vector whose elements are single Sql statemnets.
8545 *
8546 * @param sql
8547 * Sql string with number of statements.
8548 * @return vector of sql statemetns
8549 */
8550 private Vector sqlStringToVector(String sql) {
8551 Vector vecSqlString = new Vector();
8552 int i = sql.indexOf(";");
8553 if (i != -1) {
8554 while (i != -1) {
8555 // vecSqlString.add(sql.substring(0, i + 1));
8556 vecSqlString.add(sql.substring(0, i));
8557 sql = sql.substring(i + 1);
8558 i = sql.indexOf(";");
8559 }
8560 } else
8561
8562 // vecSqlString.add(sql.trim() + ";");
8563 vecSqlString.add(sql.trim());
8564 return vecSqlString;
8565 }
8566
8567 /***
8568 * Method executeSql is used to execute singl Sql statement. If there is an
8569 * error depends on OnErrorContinue parameter throws exception or not. Error
8570 * message is always shown. If there is an error, message with the error
8571 * message, statement and number of statement is shown.
8572 *
8573 * @param stmtSql
8574 * Statement.
8575 * @param sqlStmt
8576 * Sql statement to execute.
8577 * @param i
8578 * Number of the Sql statement.
8579 * @throws SQLException
8580 */
8581 private void executeSql(Statement stmtSql, String sqlStmt, int i)
8582 throws SQLException {
8583 try {
8584 if (bReplaceInData) {
8585 sqlStmt = this.replaceInData(sqlStmt);
8586 }
8587 sqlStmt.trim();
8588 if (sqlStmt.length() != 0)
8589 stmtSql.execute(sqlStmt);
8590 } catch (SQLException e) {
8591 if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase("true")) {
8592 if (sqlElement.getSqlCommit().equalsIgnoreCase("true"))
8593 this.logger.write("normal", "\t Error in SQL statement: "
8594 + sqlStmt
8595 + " executing SQL statements continue...");
8596 else
8597 this.logger
8598 .write(
8599 "normal",
8600 "\t Error in SQL statement: "
8601 + sqlStmt
8602 + " \n\tStatement is number: "
8603 + i
8604 + " all statements before it is not commited, executing SQL statements continue...");
8605 LoaderException le = new LoaderException("SQLException: ",
8606 (Throwable) e);
8607 this.logger.write("full", le.getStackTraceAsString());
8608 // this.logger.write("normal", "\t " + e.getMessage());
8609 } else {
8610 this.logger.write("normal", "\t Error in SQL statement: "
8611 + sqlStmt);
8612 throw e;
8613 }
8614 }
8615 }
8616
8617 /***
8618 * Method checkSortColumns checks if sort columns in source table have
8619 * unique values. If source table have more rows with equal values in sort
8620 * columns return true, if not return false.
8621 *
8622 * @param connSource -
8623 * Connection to the source table.
8624 * @return boolean - true - source table has more rows with equal values in
8625 * sort columns, false - if source table has unique values in sort
8626 * columns.
8627 * @throws LoaderException
8628 * with the specified detail message.
8629 */
8630 private boolean checkSortColumns(Connection connSource)
8631 throws LoaderException {
8632 boolean isEqualValues = false;
8633 String strQuery = "select ";
8634 try {
8635 this.logger.write("full", "\tmethod checkSortColumns is started");
8636 for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn
8637 .size(); i++)
8638 strQuery += importDefinitionElement.vecRestartCounterSortColumn
8639 .get(i).toString()
8640 + ",";
8641 strQuery = strQuery.substring(0, strQuery.length() - 1);
8642 strQuery += " from "
8643 + importDefinitionElement.strImportDefinitionTableName;
8644 strQuery += " order by ";
8645 for (int j = 0; j < importDefinitionElement.vecRestartCounterSortColumn
8646 .size(); j++)
8647 strQuery += importDefinitionElement.vecRestartCounterSortColumn
8648 .get(j).toString()
8649 + ", ";
8650 strQuery = strQuery.substring(0, strQuery.length() - 2);
8651 this.logger.write("full", "\tQuery '" + strQuery + "' executes");
8652 Statement stmtSort = connSource.createStatement();
8653 ResultSet rsetSort = stmtSort.executeQuery(strQuery);
8654 endWhile: while (rsetSort.next()) {
8655 Vector vecSortNewValues = new Vector();
8656 for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn
8657 .size(); i++)
8658 vecSortNewValues.add(rsetSort.getString(i + 1));
8659 if (vecSortNewValues.equals(this.vecSortValues)) {
8660 isEqualValues = true;
8661 break endWhile;
8662 } else {
8663 this.vecSortValues = new Vector();
8664 for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn
8665 .size(); i++)
8666 this.vecSortValues.add(vecSortNewValues.get(i));
8667 }
8668 }
8669 rsetSort.close();
8670 stmtSort.close();
8671 } catch (SQLException e) {
8672 LoaderException le = new LoaderException("SQLException: ",
8673 (Throwable) e);
8674 // this.logger.write("normal", le.getCause().toString());
8675 this.logger.write("full", le.getStackTraceAsString());
8676 throw le;
8677 }
8678 this.logger.write("full", "\tmethod checkSortColumns is finished");
8679 return isEqualValues;
8680 }
8681
8682 /***
8683 * put your documentation comment here
8684 *
8685 * @param conn
8686 * represents connection
8687 * @exception LoaderException
8688 */
8689 private void createObjectIDTable(Connection conn) throws LoaderException {
8690 try {
8691 Statement stmt = conn.createStatement();
8692 String sqlStmt = "";
8693 if (!(importDefinitionElement.strObjectIDNameColumnName.equals("") || importDefinitionElement.strObjectIDNameColumnValue
8694 .equals(""))) {
8695 sqlStmt = "create table "
8696 + importDefinitionElement.strObjectIDTableName + " ("
8697 + importDefinitionElement.strObjectIDColumnName
8698 + " VARCHAR(30) ,"
8699 + importDefinitionElement.strObjectIDNameColumnName
8700 + " VARCHAR(30)) NOT NULL;";
8701
8702 } else {
8703 sqlStmt = "create table "
8704 + importDefinitionElement.strObjectIDTableName + " ("
8705 + importDefinitionElement.strObjectIDColumnName
8706 + " DECIMAL(19,0) NOT NULL);";
8707 }
8708 stmt.execute(sqlStmt);
8709 String insert = "";
8710 if (!(importDefinitionElement.strObjectIDNameColumnName.equals("") || importDefinitionElement.strObjectIDNameColumnValue
8711 .equals(""))) {
8712 insert = "insert "
8713 + importDefinitionElement.strObjectIDTableName + " ("
8714 + importDefinitionElement.strObjectIDNameColumnName
8715 + "," + importDefinitionElement.strObjectIDColumnName
8716 + ") values ('"
8717 + importDefinitionElement.strObjectIDNameColumnValue
8718 + "','" + importDefinitionElement.iObjectIDStartValue
8719 + "');";
8720 } else {
8721 insert = "insert "
8722 + importDefinitionElement.strObjectIDTableName + " ("
8723 + importDefinitionElement.strObjectIDColumnName
8724 + ") values ("
8725 + importDefinitionElement.iObjectIDStartValue + ");";
8726 }
8727 if (bReplaceInData) {
8728 insert = this.replaceInData(insert);
8729 }
8730 stmt.execute(insert);
8731 conn.commit();
8732 stmt.close();
8733 } catch (SQLException e) {
8734 LoaderException le = new LoaderException("SQLException: ",
8735 (Throwable) e);
8736 // this.logger.write("normal", le.getCause().toString());
8737 this.logger.write("full", le.getStackTraceAsString());
8738 throw le;
8739 }
8740 }
8741
8742 /***
8743 * put your documentation comment here
8744 *
8745 * @param values
8746 * represents map values
8747 * @return those values
8748 */
8749 private static Map convertToMap(String values) {
8750 Map mapValues = new HashMap();
8751 int i = values.indexOf(";");
8752 int k = 0;
8753 String part = new String(values);
8754 if (i != -1) {
8755 while (i != -1) {
8756 part = new String(values.substring(k, k + i));
8757 int j = part.indexOf("=");
8758 String strObject = part.substring(0, j);
8759 String strValue = part.substring(j + 1);
8760 if (strValue.equals(""))
8761 strValue = null;
8762 mapValues.put(strObject, strValue);
8763 k += i + 1;
8764 i = values.substring(k).indexOf(";");
8765 }
8766 if (!(values.substring(k).trim().equals("") || values.substring(k)
8767 .trim().equals(";"))) {
8768 part = new String(values.substring(k));
8769 int j = part.indexOf("=");
8770 String strObject = part.substring(0, j);
8771 String strValue = part.substring(j + 1);
8772 if (strValue.equals(""))
8773 strValue = null;
8774 mapValues.put(strObject, strValue);
8775 }
8776 } else {
8777 int j = values.indexOf("=");
8778 String strObject = values.substring(k, j);
8779 String strValue = values.substring(j + 1);
8780 if (strValue.equals(""))
8781 strValue = null;
8782 mapValues.put(strObject, strValue);
8783 }
8784 return mapValues;
8785 }
8786
8787 /***
8788 * Method replaceInData replace data in string if there is the same variable
8789 * as in attribut prefix+name+suffix in variable tag.
8790 *
8791 * @param s -
8792 * String to replace.
8793 * @return s
8794 */
8795 private String replaceInData(String s) {
8796 // going throw vector
8797 for (int k = 0; k < this.vecReplaceInData.size(); k++) {
8798 // if this is to change...
8799 if (this.vecReplaceInData.get(k).toString()
8800 .equalsIgnoreCase("true")) {
8801 String sPreNameSu = this.vecVariablePrefix.get(k).toString()
8802 + this.vecVariableName.get(k).toString()
8803 + this.vecVariableSufix.get(k).toString();
8804 int j = s.indexOf(sPreNameSu);
8805 // if costant is variable
8806 while (j != -1) {
8807 s = s.substring(0, j)
8808 + this.vecVariableValue.get(k).toString()
8809 + s.substring(j + sPreNameSu.length(), s.length());
8810 j = s.indexOf(sPreNameSu);
8811 }
8812 }
8813 }
8814 return s;
8815 }
8816
8817 /***
8818 * Method replaceInSelectStatement replace data in string if there is the
8819 * same variable as in attribut prefix+name+suffix in variable tag.
8820 *
8821 * @param s -
8822 * String to replace.
8823 * @return s
8824 */
8825 // private String replaceInSelectStatement(String s) {
8826 // // going throw vector
8827 // for (int k = 0; k < this.vecVariableValue.size(); k++) {
8828 // if( this.vecReplaceInSQL.get(k).toString().equalsIgnoreCase("false"))
8829 // continue;
8830 // String sPreNameSu = this.vecVariablePrefix.get(k).toString()
8831 // + this.vecVariableName.get(k).toString() +
8832 // this.vecVariableSufix.get(k).toString();
8833 // int j = s.indexOf(sPreNameSu);
8834 //
8835 // while (j != -1) {
8836 // s = s.substring(0, j) + this.vecVariableValue.get(k).toString()
8837 // + s.substring(j + sPreNameSu.length(), s.length());
8838 // j = s.indexOf(sPreNameSu);
8839 // }
8840 // }
8841 // return s;
8842 // }
8843 /***
8844 * @param s -
8845 * String to replace.
8846 * @param oldChar -
8847 * Char
8848 * @param newValue -
8849 * String
8850 * @return s
8851 */
8852 private String replaceChar(String s, char oldChar, String newValue) {
8853
8854 int j = s.indexOf(oldChar);
8855 String replacedString = "";
8856 while (j != -1) {
8857 replacedString = replacedString + s.substring(0, j) + newValue;
8858 s = s.substring(j + 1);
8859 j = s.indexOf(oldChar);
8860 }
8861 replacedString = replacedString + s;
8862 return replacedString;
8863 }
8864
8865 /***
8866 * Method resetGlobalVariables reset all global variables to the start
8867 * values after each importDefinition job.
8868 */
8869 private void resetGlobalVariables() {
8870 importDefinitionElement.strImportDefinitionName = "";
8871 importDefinitionElement.strImportDefinitionTableName = "";
8872 importDefinitionElement.iImportDefinitionCommitCount = 0;
8873 // importDefinitionElement.strImportDefinitionLogMode = "normal";
8874 importDefinitionElement.strImportDefinitionSelectStatement = "";
8875 importDefinitionElement.bObjectIDAutoCreate = loaderJobReader
8876 .getDefaultObjectIDAutoCreate();
8877 importDefinitionElement.iObjectIDStartValue = loaderJobReader
8878 .getDefaultObjectIDStartValue();
8879
8880 importDefinitionElement.vecRestartCounterSortColumn = new Vector();
8881 this.iValueColumns = 0;
8882 this.vecValueColumnsTargetTables = new Vector();
8883 // this.vecTransformColumnsTargetTables = new Vector();
8884 this.vecSourceColumnName = new Vector();
8885 this.vecTargetColumnName = new Vector();
8886 this.vecValueMode = new Vector();
8887 this.vecTargetColumnValue = new Vector();
8888 this.vecTargetKeyColumnName = new Vector();
8889 this.iConstantColumns = 0;
8890 this.vecConstantTargetColumnName = new Vector();
8891 this.vecConstantValueMode = new Vector();
8892 this.vecConstantConstantValue = new Vector();
8893 this.vecConstantColumnTargetTableName = new Vector();
8894 this.vecConstantColumnTargetTableID = new Vector();
8895 this.iRelationColumns = 0;
8896 this.vecRelationColumnSourceTableName = new Vector();
8897 this.vecRelationColumnSourceTableID = new Vector();
8898 this.vecRelationColumnSourceColumnName = new Vector();
8899 this.vecRelationColumnTargetTableName = new Vector();
8900 this.vecRelationColumnTargetColumnName = new Vector();
8901 this.vecRelationColumnTargetTableID = new Vector();
8902 this.vecRelationColumnRelationMode = new Vector();
8903 this.iTables = 0;
8904 this.vecTableTableName = new Vector();
8905 this.vecTableTableID = new Vector();
8906 this.vecTableInsert = new Vector();
8907 this.vecTableTableMode = new Vector();
8908 this.vecTableOidLogic = new Vector();
8909 this.vecRelationSourceValue = new Vector();
8910 this.vecRelationSourceType = new Vector();
8911 this.vecTargetColumnType = new Vector();
8912 this.vecConstantColumnType = new Vector();
8913 this.bdecOidNumber = new BigDecimal(0);
8914 this.bdecOidNumber2000 = new BigDecimal(0);
8915 importDefinitionElement.iObjectID = 0;
8916 importDefinitionElement.iObjectIDCT = 0;
8917 importDefinitionElement.strObjectIDTableName = "";
8918 importDefinitionElement.strObjectIDColumnName = "";
8919 // TOS
8920 importDefinitionElement.strObjectIDNameColumnName = "";
8921 importDefinitionElement.strObjectIDNameColumnValue = "";
8922
8923 this.vecVariableUseIDTableName = new Vector();
8924 this.vecVariableUseIDTableID = new Vector();
8925 this.vecVariableUseIDColumnName = new Vector();
8926 this.vecVariableUseIDValueMode = new Vector();
8927 this.vecVariableColumnName = new Vector();
8928 this.vecVariableColumnTargetTableName = new Vector();
8929 this.vecVariableColumnTargetTableID = new Vector();
8930 this.vecVariableColumnTargetColumnName = new Vector();
8931 this.vecVariableColumnValueMode = new Vector();
8932 this.vecVariableColumnTypes = new Vector();
8933 this.vecVariableTimesTableName = new Vector();
8934 this.vecVariableTimesTableID = new Vector();
8935 this.vecVariableTimesColumnName = new Vector();
8936 this.vecVariableTimesValueMode = new Vector();
8937 this.vecRelationKeyColumns = new Vector();
8938 this.vecRelationKeyTypes = new Vector();
8939 this.vecSortValues = new Vector();
8940 this.vecSqlStmt = new Vector();
8941 this.strSourceDriverName = "";
8942 this.strTargetDriverName = "";
8943 this.iFirstColumnResult = 1;
8944 this.iTargetFirstColumnResult = 1;
8945 this.iColumnsInSourceTable = 0;
8946 // copy table
8947 this.vecCTAutoMapp = new Vector();
8948 this.vecCTDefaultMode = new Vector();
8949 this.vecBlobVector = new Vector();
8950 // added for transformations
8951 this.transformationsColumnNames = new Vector();
8952 this.indexDTransformationOver = new Hashtable();
8953 this.indexDTransformationNull = new Hashtable();
8954 this.transformationsValueModes = new Vector();
8955 this.transformationsColumnTypes = new Vector();
8956 this.transformationValues = new Vector();
8957
8958 }
8959
8960 private String replaceFirst(String input, String forReplace,
8961 String replaceWith) {
8962 String retVal = input;
8963 int start = input.indexOf(forReplace);
8964 int end = start + forReplace.length();
8965 if (start != -1) {
8966 retVal = input.substring(0, start) + replaceWith
8967 + input.substring(end);
8968 }
8969 return retVal;
8970 }
8971
8972 /***
8973 * This method write values for all input parameters to log file when log
8974 * level is full
8975 *
8976 * @throws LoaderException
8977 */
8978 public String inputToString() throws LoaderException {
8979 String resString = "";
8980 try {
8981 logger.write("full", "Log mode =" + getDefaultLogMode());
8982 logger.write("full", "Restart indicator =" + getRestartIndicator());
8983 logger.write("full", "UserID =" + getUserID());
8984 Hashtable resHashtable = new Hashtable();
8985 resHashtable = (Hashtable) getVariableValues();
8986 String pom2 = "";
8987
8988 if (resHashtable != null) {
8989 logger.write("full", "Variables =" + resHashtable.toString());
8990 pom2 = "Variables =" + resHashtable.toString();
8991 } else {
8992 logger.write("full", "Variables = null");
8993 pom2 = "Variables = null";
8994 }
8995 logger.write("full", "Log directory =" + getLogDirName());
8996 logger.write("full", "Log file name =" + getLogFileName());
8997 logger.write("full", "LoadJob file name =" + getLoadJobFileName());
8998 logger.write("full", "On error continue =" + getOnErrorContinue());
8999 logger.write("full", "Commit count =" + getCommitCount());
9000 logger.write("full", "Return code =" + getDefaultReturnCode());
9001 logger.write("full", "Vendor conf file =" + getVendorFileName());
9002
9003 logger.write("full", "Include list =");
9004 String pom1 = "";
9005 pom1 = "Include list =";
9006 String[] listOfJobs = getIncludedJobs();
9007 for (int j = 0; j < listOfJobs.length; j++) {
9008 logger.write("full", listOfJobs[j].toString());
9009 pom1 += listOfJobs[j].toString() + "\n";
9010 }
9011 logger.write("full", "Path to conf files in jar ="
9012 + getConfJarStructure());
9013 logger.write("full", "Additional paths =" + getAdditionalPaths());
9014 resString = "Log mode =" + getDefaultLogMode() + "\n"
9015 + "Restart indicator =" + getRestartIndicator() + "\n"
9016 + "UserID =" + getUserID() + "\n" + pom2 + "\n"
9017 + "Log directory =" + getLogDirName() + "\n"
9018 + "Log file name =" + getLogFileName() + "\n"
9019 + "LoadJob file name =" + getLoadJobFileName() + "\n"
9020 + "On error continue =" + getOnErrorContinue() + "\n"
9021 + "Commit count =" + getCommitCount() + "\n"
9022 + "Return code =" + getDefaultReturnCode() + "\n"
9023 + "Vendor conf file =" + getVendorFileName() + "\n" + pom1
9024 + "\n" + "Path to conf files in jar ="
9025 + getConfJarStructure() + "\n" + "Additional paths ="
9026 + getAdditionalPaths() + "\n";
9027
9028 return resString;
9029 } catch (Exception e) {
9030
9031 LoaderException le = new LoaderException("Exception:"
9032 + e.getMessage(), e);
9033 this.logger.write("full", le.getStackTraceAsString());
9034 throw le;
9035 }
9036
9037 }
9038
9039 protected java.util.Date getDateFromString(String date) throws Exception {
9040 Date tmpDate = null;
9041 try {
9042 this.logger.write("full", "Try to parse date with src config: "
9043 + date);
9044 String format = this.configReaderSource.getDateFormat();
9045 SimpleDateFormat formatDate = new SimpleDateFormat(format);
9046 tmpDate = formatDate.parse(date);
9047 } catch (ParseException e) {
9048 try {
9049 this.logger.write("full",
9050 "Try to parse date with target config: " + date);
9051 String format = this.configReaderTarget.getDateFormat();
9052 SimpleDateFormat formatDate = new SimpleDateFormat(format);
9053 tmpDate = formatDate.parse(date);
9054 } catch (ParseException e1) {
9055 }
9056 }
9057 if (tmpDate != null) {
9058 return tmpDate;
9059 } else {
9060 throw new LoaderException("Unable to parse date: " + date);
9061 }
9062 }
9063
9064 protected void setValueOnStatement(String value, int javaTypeInt, int i,
9065 PreparedStatement pstmt) throws Exception {
9066 if (javaTypeInt == 2) { // java.math.BigDecimal
9067 if (!value.equalsIgnoreCase("null")) {
9068 BigDecimal number = new BigDecimal(0);
9069 if (!value.equalsIgnoreCase(""))
9070 number = new BigDecimal(value);
9071 pstmt.setBigDecimal(i, number);
9072 } else {
9073 pstmt.setNull(i, java.sql.Types.DECIMAL);
9074 }
9075 } else if (javaTypeInt == 3) { // java.lang.Double
9076 if (!value.equalsIgnoreCase("null")) {
9077 double number = 0;
9078 if (!value.equalsIgnoreCase(""))
9079 number = Double.parseDouble(value);
9080 pstmt.setDouble(i, number);
9081 } else {
9082 pstmt.setNull(i, java.sql.Types.DOUBLE);
9083 }
9084 } else if (javaTypeInt == 4) { // java.lang.Float
9085 if (!value.equalsIgnoreCase("null")) {
9086 float number = 0;
9087 if (!value.equalsIgnoreCase(""))
9088 number = Float.parseFloat(value);
9089 pstmt.setFloat(i, number);
9090 } else {
9091 pstmt.setNull(i, java.sql.Types.FLOAT);
9092 }
9093 } else if (javaTypeInt == 5) { // java.lang.Integer
9094 if (!value.equalsIgnoreCase("null")) {
9095 int number = 0;
9096 if (!value.equalsIgnoreCase(""))
9097 number = Integer.parseInt(value);
9098 pstmt.setInt(i, number);
9099 } else {
9100 pstmt.setNull(i, java.sql.Types.INTEGER);
9101 }
9102
9103 } else if (javaTypeInt == 6) { // java.lang.Long
9104 if (!value.equalsIgnoreCase("null")) {
9105 long number = 0;
9106 if (!value.equalsIgnoreCase(""))
9107 number = Long.parseLong(value);
9108 pstmt.setLong(i, number);
9109 } else {
9110 pstmt.setNull(i, java.sql.Types.DOUBLE);
9111 }
9112 } else if (javaTypeInt == 7) { // java.lang.Short
9113 if (!value.equalsIgnoreCase("null")) {
9114 short number = 0;
9115 if (!value.equalsIgnoreCase(""))
9116 number = Short.parseShort(value);
9117 pstmt.setShort(i, number);
9118 } else {
9119 pstmt.setNull(i, java.sql.Types.SMALLINT);
9120 }
9121 } else if (javaTypeInt == 8) { // java.lang.String
9122 if (!value.equalsIgnoreCase("null")) {
9123 // all '' back to ' (original value)
9124 if (value.indexOf("''") != -1) {
9125 value = Utils.replaceAll(value, "''", "'");
9126 }
9127 pstmt.setString(i, value);
9128 } else {
9129 pstmt.setNull(i, java.sql.Types.VARCHAR);
9130 }
9131 } else if (javaTypeInt == 9) { // java.sql.Date
9132 if (!value.equalsIgnoreCase("null")) {
9133 // String format = this.configReaderSource.getDateFormat();
9134 // SimpleDateFormat formatDate = new SimpleDateFormat(format);
9135 // Date tmpDate = formatDate.parse(value);
9136 try {
9137 pstmt.setDate(i, new java.sql.Date(getDateFromString(value)
9138 .getTime()));
9139 } catch (Exception e) {
9140 this.logger.write("normal", "call setString on date: "
9141 + value);
9142 pstmt.setString(i, value);
9143 }
9144 // }
9145
9146 } else {
9147 pstmt.setNull(i, java.sql.Types.DATE);
9148 }
9149 } else if (javaTypeInt == 10) { // java.sql.Time
9150 if (!value.equalsIgnoreCase("null")) {
9151 // String format = this.configReaderSource.getDateFormat();
9152 // SimpleDateFormat formatDate = new SimpleDateFormat(format);
9153 // Date tmpDate = formatDate.parse(value);
9154 try {
9155 pstmt.setTime(i, new java.sql.Time(getDateFromString(value)
9156 .getTime()));
9157 } catch (Exception e) {
9158 pstmt.setString(i, value);
9159 }
9160 } else {
9161 pstmt.setNull(i, java.sql.Types.TIME);
9162 }
9163
9164 } else if (javaTypeInt == 11) { // java.sql.Timestamp
9165 if (!value.equalsIgnoreCase("null")) {
9166 // String format = this.configReaderSource.getDateFormat();
9167 // SimpleDateFormat formatDate = new SimpleDateFormat(format);
9168 // Date tmpDate = formatDate.parse(value);
9169 try {
9170 pstmt.setTimestamp(i, new Timestamp(
9171 getDateFromString(value).getTime()));
9172 } catch (Exception e) {
9173 pstmt.setString(i, value);
9174 }
9175 } else {
9176 pstmt.setNull(i, java.sql.Types.TIMESTAMP);
9177 }
9178
9179 } else if (javaTypeInt == 12) { // java.lang.Boolean
9180 if (!value.equalsIgnoreCase("null")) {
9181 boolean bool = new Boolean(value).booleanValue();
9182 pstmt.setBoolean(i, bool);
9183 } else {
9184 // TODO test this peace of code
9185 pstmt.setNull(i, java.sql.Types.BIT);
9186 }
9187 } else if (javaTypeInt == 13) { // java.lang.Byte
9188 if (!value.equalsIgnoreCase("null")) {
9189 pstmt.setString(i, value);
9190 } else {
9191 pstmt.setNull(i, java.sql.Types.BIT);
9192 }
9193 } else if (javaTypeInt == 14) { // java.lang.Object
9194 if (!value.equalsIgnoreCase("null")) {
9195 pstmt.setString(i, value);
9196 } else {
9197 // TODO zoran pogledati ovo
9198 try {
9199 pstmt.setNull(i, java.sql.Types.NULL);
9200 } catch (Exception e) {
9201 pstmt.setString(i, null);
9202 }
9203 }
9204 }
9205 }
9206
9207 //senka added
9208 protected String getSQLRelationString(ResultSet rs){
9209 String res="";
9210 String r="";
9211 String temp="";
9212 int col=0;
9213 int counter=1;
9214
9215 if (this.iTargetFirstColumnResult == 1) col=1;
9216 try {
9217 try {
9218 if (!configReaderTarget.isNumber(rs.getMetaData().getColumnTypeName(col))) temp="'";
9219 } catch (LoaderException e) {
9220 e.printStackTrace();
9221 }
9222 Object obj=rs.getObject(col);
9223 if (obj!=null){
9224 res=res+temp+obj.toString()+temp+",";
9225 while (rs.next()){
9226 obj=rs.getObject(col);
9227 if (obj!=null){
9228 res=res+temp+obj.toString()+temp;
9229 res=res+",";
9230 counter++;
9231 }
9232 }
9233 } else{
9234 res=res+temp+"null"+temp+",";
9235 }
9236
9237
9238 } catch (SQLException e) {
9239 e.printStackTrace();
9240 }
9241
9242 if (counter==1) {
9243 r=res.substring(temp.length(),res.length()-1-temp.length());
9244 }
9245 else{
9246 r=" IN ("+res.substring(0,res.length()-1)+")";
9247 }
9248 return r;
9249 }
9250
9251 }
This page was automatically generated by Maven