View Javadoc
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); 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); 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 pomResultVectorTypes = transformation 3039 .getOrderedTargetColumnTypes(i); 3040 if (vecTransformedValues != null) { 3041 for (int m = 0; m < vecTransformedValues 3042 .size(); m++) { 3043 // use only values and types for 3044 // specified logic table 3045 if (pomResultVectorTypes.get(m) == null) 3046 continue; 3047 transformedValues 3048 .add(vecTransformedValues 3049 .get(m)); 3050 resultVectorTypes 3051 .add(pomResultVectorTypes 3052 .get(m).toString()); 3053 } 3054 } 3055 } 3056 this.logger.write("full", 3057 "\ttransformation of values is finished"); 3058 } 3059 3060 // insert row into target logic table 3061 this.insertTargetTable(i, vecVektor, 3062 (Vector) this.vecTargetColumnName.get(i), 3063 (Vector) this.vecValueMode.get(i), 3064 (Vector) this.vecTargetColumnType.get(i), 3065 connTarget, transformedValues, 3066 resultVectorTypes); 3067 3068 } 3069 iRowNumber++; 3070 } 3071 // restart counter table 3072 if (!importDefinitionElement.strRestartCounterTableName 3073 .equals("")) { 3074 if (this.hasRestartCounter) { 3075 bdecCounter = bdecCounter 3076 .add(new BigDecimal(iRowNumber)); 3077 dataTransmition.insertCounter(this.currentJobName, 3078 bdecCounter, connTarget); 3079 } 3080 } 3081 3082 if (this.hasRestartCounter) { 3083 // TODO THIS IS WRITE PLACE:ZK added this for update of 3084 // counterColumns. This will update values in CounterTable 3085 // for this import job. 3086 // this.counterColumns.updateCounter(this.htValuesForCounterColumns, 3087 // connTarget); 3088 this.counterColumns.updateCounter(connTarget); 3089 connTarget.commit(); 3090 this.logger.write("normal", "Imported block is commited."); 3091 this.logger.write("full", Integer.toString(iRowNumber) 3092 + " rows are commited."); 3093 } 3094 iRowNumber = 0; 3095 if (isEndFlag == true) 3096 break; 3097 }// End of while(main) 3098 3099 rsetSource.close(); 3100 stmtSource.close(); 3101 connSource.close(); 3102 3103 if (!importDefinitionElement.strRestartCounterTableName.equals("")) { 3104 if (this.hasRestartCounter) { 3105 dataTransmition.resetRestartCounter(connTarget, 3106 this.currentJobName); 3107 } 3108 } 3109 // TODO ZK added this for update of counterColumns. This will update 3110 // values in CounterTable for every importDefinition. 3111 if (!this.hasRestartCounter) { 3112 this.counterColumns.updateCounter(connTarget); 3113 } 3114 // end 3115 currentDate = new Date(); 3116 dfNow = DateFormat.getDateTimeInstance(); 3117 this.logger.write("normal", "Import definition " 3118 + importDefinitionElement.strImportDefinitionName 3119 + " is finished at " + dfNow.format(currentDate) + "."); 3120 this.logger.write("normal", " Duration of importDefinition:" 3121 + this.timeCounter.getJobTime()); 3122 } 3123 3124 catch (Exception e) { 3125 try { 3126 if (connSource != null) 3127 connSource.close(); 3128 } catch (Exception ex) { 3129 this.logger.write("normal", "\t" + ex.getMessage()); 3130 } 3131 String msq = "Error: In import job '" 3132 + importDefinitionElement.strImportDefinitionName + "', " 3133 + "some error has occured:"; 3134 this.logger.write("normal", "\t" + msq); 3135 LoaderException le = new LoaderException("Exception:" 3136 + e.getMessage(), (Throwable) e); 3137 this.logger.write("full", "\t" + le.getStackTraceAsString()); 3138 3139 throw le; 3140 } finally { 3141 try { 3142 3143 this.logger.write("full", "loadSource method is finished."); 3144 if (connSource != null && !connSource.isClosed()) 3145 connSource.close(); 3146 } catch (SQLException e) { 3147 LoaderException le = new LoaderException("SQLException: ", 3148 (Throwable) e); 3149 // this.logger.write("normal", le.getCause().toString()); 3150 this.logger.write("full", le.getStackTraceAsString()); 3151 throw le; 3152 } 3153 } 3154 } 3155 3156 /*** 3157 * This method read data from source table 3158 * 3159 * @param readValue 3160 * is data value which is reed 3161 * @param vecVektor 3162 * defines vector 3163 * @param rsetSource 3164 * defines ResultSet object 3165 * @param i 3166 * is interger 3167 * @param columnName 3168 * defines source column name 3169 * @param blobCount 3170 * defines counter for blob object 3171 * @param isMicrosoftDriver 3172 * defines if we use microsoft driver 3173 * @param columnValuesMicrosoft 3174 * defines column values which is read with microsoft driver 3175 */ 3176 public void parseInputData(Object readValueObject, Vector vecVektor, 3177 ResultSet rsetSource, int i, String columnName, int blobCount, 3178 boolean isMicrosoftDriver, Hashtable columnValuesMicrosoft, 3179 Hashtable sourceColumnTypes) throws LoaderException { 3180 try { 3181 String readValue = ""; 3182 if (readValueObject instanceof String) 3183 readValue = (String) readValueObject; 3184 else 3185 readValue = readValueObject != null ? readValueObject 3186 .toString() : "null"; 3187 3188 if (readValue == null 3189 || readValue.toString().equalsIgnoreCase("null")) { 3190 vecVektor.add(null); 3191 } else if (readValue.toString().equalsIgnoreCase("")) { 3192 if (configReaderTarget.getSetEmptyStringAsNull()) 3193 vecVektor.add(null); 3194 else 3195 vecVektor.add(""); 3196 } else { 3197 // int indexOld = ( 3198 // (Vector)this.vecTargetColumnName.get(i)).indexOf(columnName); 3199 int index = blobCount - 1; 3200 // if (index == -1) { 3201 // if (readValue.indexOf("'") != -1) 3202 // readValue = replaceChar(readValue, '\'', "\'\'"); 3203 // vecVektor.add(readValue); 3204 // } else { 3205 byte[] blob; 3206 3207 String columnTypeTarget = ((Vector) this.vecTargetColumnType 3208 .get(i)).get(index).toString(); 3209 3210 String columnTypeSource = sourceColumnTypes.get(columnName) 3211 .toString(); 3212 3213 String mode = ((Vector) this.vecValueMode.get(i)).get(index) 3214 .toString(); 3215 String toHex = ((Vector) this.vecToHex.get(i)).get(index) 3216 .toString(); 3217 String fromHex = ((Vector) this.vecFromHex.get(i)).get(index) 3218 .toString(); 3219 String blobObjectName = "binaryObject" + blobCount; 3220 3221 if (toHex.equalsIgnoreCase("true") 3222 && !fromHex.equalsIgnoreCase("true")) { 3223 if (isMicrosoftDriver) 3224 blob = (byte[]) columnValuesMicrosoft.get(columnName); 3225 else 3226 blob = rsetSource.getBytes(columnName); 3227 3228 String toHexString = ToAndFromHex.getStringFromBlob(blob); 3229 vecVektor.add(toHexString); 3230 } else if (fromHex.equalsIgnoreCase("true") 3231 && !toHex.equalsIgnoreCase("true")) { 3232 // ZK change this 7.5.2004 from CheckType to 3233 // configReaderTarget 3234 if (configReaderTarget.isBinaryObject(columnTypeTarget)) { 3235 // if (javaTypeInt==1) { 3236 byte[] newBlob = ToAndFromHex 3237 .getByteArrayFromString(readValue.toString()); 3238 if (mode.equalsIgnoreCase("Update")) { 3239 this.vecBlobVector.add(columnName); 3240 this.vecBlobVector.add(newBlob); 3241 this.vecBlobVector.add(" where " + columnName 3242 + " is null and "); 3243 this.vecBlobVector.add(mode); 3244 this.vecBlobVector.add(blobObjectName); 3245 vecVektor.add(blobObjectName); 3246 } else { 3247 this.vecBlobVector.add(columnName); 3248 this.vecBlobVector.add(newBlob); 3249 this.vecBlobVector.add(null); 3250 this.vecBlobVector.add(mode); 3251 this.vecBlobVector.add(blobObjectName); 3252 vecVektor.add(blobObjectName); 3253 } 3254 } else { 3255 if (readValue.toString().indexOf("'") != -1) 3256 readValue = replaceChar(readValue, '\'', "\'\'"); 3257 vecVektor.add(readValue); 3258 } 3259 } else { 3260 // ZK change this 7.5.2004 from CheckType to 3261 // configReaderSource 3262 if (configReaderTarget.isBinaryObject(columnTypeTarget)) { 3263 // if (javaTypeInt==1) { 3264 if (isMicrosoftDriver) 3265 blob = (byte[]) columnValuesMicrosoft 3266 .get(columnName); 3267 else 3268 blob = rsetSource.getBytes(columnName); 3269 if (mode.equalsIgnoreCase("Update")) { 3270 this.vecBlobVector.add(columnName); 3271 this.vecBlobVector.add(blob); 3272 this.vecBlobVector.add(" where " + columnName 3273 + " is null and "); 3274 this.vecBlobVector.add(mode); 3275 this.vecBlobVector.add(blobObjectName); 3276 vecVektor.add(blobObjectName); 3277 } else { 3278 this.vecBlobVector.add(columnName); 3279 this.vecBlobVector.add(blob); 3280 this.vecBlobVector.add(null); 3281 this.vecBlobVector.add(mode); 3282 this.vecBlobVector.add(blobObjectName); 3283 vecVektor.add(blobObjectName); 3284 } 3285 } 3286 else if (configReaderSource.isDate(columnTypeSource)) { 3287 3288 Date tmpDate = null; 3289 // Senka 27.12.2006 , separated Date and Timestamp columns 3290 if (isMicrosoftDriver){ 3291 if (columnValuesMicrosoft.get(columnName).toString().length()>10) 3292 tmpDate = (java.sql.Timestamp) columnValuesMicrosoft 3293 .get(columnName); 3294 else 3295 tmpDate = (java.sql.Date) columnValuesMicrosoft 3296 .get(columnName); 3297 3298 }else{ 3299 if (rsetSource.getObject(columnName).toString().length()>10) 3300 tmpDate = rsetSource.getTimestamp(columnName); 3301 else 3302 tmpDate= rsetSource.getDate(columnName); 3303 } 3304 if (!configReaderTarget.isDate(columnTypeTarget)) { 3305 String format = this.configReaderTarget.getDateFormat(); 3306 SimpleDateFormat formatDate = new SimpleDateFormat(format); 3307 vecVektor.add(formatDate.format(tmpDate)); 3308 } else { 3309 vecVektor.add(tmpDate); 3310 } 3311 } 3312 else { 3313 if (readValue.indexOf("'") != -1) 3314 readValue = replaceChar(readValue, '\'', "\'\'"); 3315 vecVektor.add(readValue); 3316 } 3317 } 3318 } 3319 // } 3320 } catch (Exception ex) { 3321 LoaderException le = new LoaderException( 3322 "Error in parseInputData.", ex); 3323 this.logger.write("full", le.getStackTraceAsString()); 3324 throw le; 3325 } 3326 } 3327 3328 /*** 3329 * Method parseImportJOB is used to analyse import XML file about 3330 * ImportDefinitions tags. Return number of importDefinition elements in 3331 * whole xml file. 3332 * 3333 * @param inStream 3334 * Data from inputXML file which is converted into InputStream. 3335 * @return Number of ImportDefinitions tags in an input XML file. 3336 * @throws LoaderException 3337 */ 3338 private int parseImportJob(InputStream inStream) throws LoaderException { 3339 int iNumTagsImportJob = 0; 3340 Document doc = null; 3341 this.logger.write("full", "\tparseImportJob method is started."); 3342 try { 3343 3344 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3345 DocumentBuilder db = null; 3346 db = dbf.newDocumentBuilder(); 3347 doc = db.parse(inStream); 3348 } catch (Exception e) { 3349 this.logger.write("normal", "Sorry, an error occurred: " + e); 3350 LoaderException le = new LoaderException("Exception: ", 3351 (Throwable) e); 3352 this.logger.write("full", le.getStackTraceAsString()); 3353 throw le; 3354 } 3355 if (doc != null) { 3356 NodeList tagBasic = doc.getElementsByTagName("importDefinition"); 3357 iNumTagsImportJob = tagBasic.getLength(); 3358 Vector vecNames = new Vector(); 3359 String strName = ""; 3360 for (int i = 0; i < iNumTagsImportJob; i++) { 3361 strName = new String(""); 3362 strName = OctopusXMLUtil.importAttributeValue(doc, 3363 "importDefinition", "name", i); 3364 for (int j = 0; j < vecNames.size(); j++) { 3365 if (strName.equals("")) { 3366 this.logger 3367 .write("normal", 3368 "Sorry, an error occurred: No importDefinition name ."); 3369 LoaderException le = new LoaderException( 3370 "Exception: ", 3371 (Throwable) (new Exception( 3372 "Sorry, an error occurred: No importDefinition name ."))); 3373 this.logger.write("full", le.getStackTraceAsString()); 3374 throw le; 3375 } 3376 if (strName.equalsIgnoreCase(vecNames.get(j).toString())) { 3377 this.logger.write("normal", 3378 "Sorry, an error occurred: More importDefinition with same name :" 3379 + strName); 3380 LoaderException le = new LoaderException( 3381 "Exception: ", 3382 (Throwable) (new Exception( 3383 "Sorry, an error occurred: More importDefinition with same name :"))); 3384 this.logger.write("full", le.getStackTraceAsString()); 3385 throw le; 3386 } 3387 } 3388 vecNames.addElement(strName); 3389 } 3390 } 3391 try { 3392 inStream.reset(); 3393 } catch (IOException e) { 3394 // this.logger.write("normal", "Sorry, an error occurred: " + e); 3395 LoaderException le = new LoaderException("IOException: ", 3396 (Throwable) e); 3397 this.logger.write("full", le.getStackTraceAsString()); 3398 throw le; 3399 } 3400 this.logger.write("full", "\tparseImportJob method is finished."); 3401 return iNumTagsImportJob; 3402 } 3403 3404 /*** 3405 * Method parseCopyTable is used to analyse import XML file about copyTable 3406 * tags. Return number of copyTable elements in whole xml file. 3407 * 3408 * @param inStream 3409 * Data from inputXML file which is converted into InputStream. 3410 * @return Number of iNumTagsCopyTable tags in an input XML file. 3411 * @throws LoaderException 3412 */ 3413 3414 private int parseCopyTable(InputStream inStream) throws LoaderException { 3415 int iNumTagsCopyTable = 0; 3416 Document doc = null; 3417 this.logger.write("full", "\tparseCopyTable method is started."); 3418 try { 3419 3420 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3421 DocumentBuilder db = null; 3422 db = dbf.newDocumentBuilder(); 3423 doc = db.parse(inStream); 3424 } catch (Exception e) { 3425 this.logger.write("normal", "Sorry, an error occurred: " + e); 3426 LoaderException le = new LoaderException("Exception: ", 3427 (Throwable) e); 3428 this.logger.write("full", le.getStackTraceAsString()); 3429 throw le; 3430 } 3431 if (doc != null) { 3432 NodeList tagCopyTable = doc.getElementsByTagName("copyTable"); 3433 iNumTagsCopyTable = tagCopyTable.getLength(); 3434 Vector vecNames = new Vector(); 3435 String strName = ""; 3436 for (int i = 0; i < iNumTagsCopyTable; i++) { 3437 strName = new String(""); 3438 strName = OctopusXMLUtil.importAttributeValue(doc, "copyTable", 3439 "name", i); 3440 for (int j = 0; j < vecNames.size(); j++) { 3441 if (strName.equals("")) { 3442 this.logger 3443 .write("normal", 3444 "Sorry, an error occurred: No copyTable name ."); 3445 LoaderException le = new LoaderException( 3446 "Exception: ", 3447 (Throwable) (new Exception( 3448 "Sorry, an error occurred: No copyTable name ."))); 3449 this.logger.write("full", le.getStackTraceAsString()); 3450 throw le; 3451 } 3452 if (strName.equalsIgnoreCase(vecNames.get(j).toString())) { 3453 this.logger.write("normal", 3454 "Sorry, an error occurred: More copyTable with same name :" 3455 + strName); 3456 LoaderException le = new LoaderException( 3457 "Exception: ", 3458 (Throwable) (new Exception( 3459 "Sorry, an error occurred: More copyTable with same name :"))); 3460 this.logger.write("full", le.getStackTraceAsString()); 3461 throw le; 3462 } 3463 } 3464 vecNames.addElement(strName); 3465 } 3466 } 3467 try { 3468 inStream.reset(); 3469 } catch (IOException e) { 3470 this.logger.write("normal", "Sorry, an error occurred: " + e); 3471 LoaderException le = new LoaderException("IOException: ", 3472 (Throwable) e); 3473 this.logger.write("full", le.getStackTraceAsString()); 3474 throw le; 3475 } 3476 this.logger.write("full", "\tparseImportJob method is finished."); 3477 return iNumTagsCopyTable; 3478 } 3479 3480 /*** 3481 * Method parseEchoElement is used to analyse import XML file about echo 3482 * tags. Return number of echo elements in a whole xml input file. 3483 * 3484 * @param inStream 3485 * Data from inputXML file which is converted into InputStream. 3486 * @return Number of echo tags in an input XML file. 3487 * @throws LoaderException 3488 */ 3489 private int parseEcho(InputStream inStream) throws LoaderException { 3490 int iNumTagsEcho = 0; 3491 Document doc = null; 3492 this.logger.write("full", "\tparseEcho method is started."); 3493 try { 3494 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3495 DocumentBuilder db = null; 3496 db = dbf.newDocumentBuilder(); 3497 doc = db.parse(inStream); 3498 } catch (Exception e) { 3499 this.logger.write("normal", "Sorry, an error occurred: " + e); 3500 LoaderException le = new LoaderException("Exception: ", 3501 (Throwable) e); 3502 this.logger.write("full", le.getStackTraceAsString()); 3503 throw le; 3504 } 3505 if (doc != null) { 3506 NodeList tagBasic = doc.getElementsByTagName("echo"); 3507 iNumTagsEcho = tagBasic.getLength(); 3508 String strMessage = ""; 3509 for (int i = 0; i < iNumTagsEcho; i++) { 3510 strMessage = new String(""); 3511 strMessage = OctopusXMLUtil.importAttributeValue(doc, "echo", 3512 "message", i); 3513 if (strMessage != null) 3514 logger.setMessage((new Integer(i)).toString(), strMessage); 3515 } 3516 } 3517 try { 3518 inStream.reset(); 3519 } catch (IOException e) { 3520 this.logger.write("normal", "Sorry, an error occurred: " + e); 3521 LoaderException le = new LoaderException("IOxception: ", 3522 (Throwable) e); 3523 this.logger.write("full", le.getStackTraceAsString()); 3524 throw le; 3525 // System.exit(1); 3526 } 3527 this.logger.write("full", "\tparseSql method is finished."); 3528 return iNumTagsEcho; 3529 } 3530 3531 /*** 3532 * Method parseMainElements is used to analyse import XML file about main 3533 * elements (sql and importDefinition). Puts names of elements (sql or 3534 * importDefinition) in Vector. 3535 * 3536 * @param inStream 3537 * Data from inputXML file which is converted into InputStream. 3538 * @return Vector which elements are names of main elements in the same 3539 * order as in XML import file . 3540 * @throws LoaderException 3541 */ 3542 private Vector parseMainElements(InputStream inStream) 3543 throws LoaderException { 3544 3545 Vector vecLoaderElements = new Vector(); 3546 Vector vecLoaderNamesOfElements = new Vector(); 3547 3548 Document doc = null; 3549 this.logger.write("full", "\tparseMainElements method is started."); 3550 try { 3551 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3552 DocumentBuilder db = null; 3553 db = dbf.newDocumentBuilder(); 3554 doc = db.parse(inStream); 3555 } catch (Exception e) { 3556 this.logger.write("normal", "Sorry, an error occurred: " + e); 3557 LoaderException le = new LoaderException("Exception: ", 3558 (Throwable) e); 3559 this.logger.write("full", le.getStackTraceAsString()); 3560 throw le; 3561 } 3562 if (doc != null) { 3563 NodeList tagBasic = doc.getElementsByTagName("loaderJob"); 3564 NodeList nlMainElements = tagBasic.item(0).getChildNodes(); 3565 for (int i = 0; i < nlMainElements.getLength(); i++) { 3566 String strTagName = nlMainElements.item(i).getNodeName(); 3567 if (strTagName.equalsIgnoreCase("sql") 3568 || strTagName.equalsIgnoreCase("importDefinition") 3569 || strTagName.equalsIgnoreCase("echo") 3570 || strTagName.equalsIgnoreCase("copyTable")) 3571 if (nlMainElements.item(i).getNodeType() == Node.ELEMENT_NODE) { 3572 String strTagJobName = (((Element) nlMainElements 3573 .item(i)).getAttribute("name")); 3574 String strLogMode = (((Element) nlMainElements.item(i)) 3575 .getAttribute("logMode")); 3576 vecLoaderElements.addElement(strTagName); 3577 this.logModes.add(strLogMode); 3578 boolean addJobName = true; 3579 if (!strTagJobName.equalsIgnoreCase("")) { 3580 for (int j = 0; j < vecLoaderNamesOfElements.size(); j++) { 3581 if (strTagJobName 3582 .equalsIgnoreCase(vecLoaderNamesOfElements 3583 .get(j).toString())) { 3584 addJobName = false; 3585 break; 3586 } 3587 } 3588 if (addJobName) { 3589 vecLoaderNamesOfElements.add(strTagJobName); 3590 } else { 3591 String msg = "Sorry, an error occurred: More import jobs with same name :" 3592 + strTagJobName; 3593 LoaderException le = new LoaderException( 3594 "Exception:", new Exception(msg)); 3595 3596 throw le; 3597 } 3598 } 3599 } 3600 } 3601 } 3602 try { 3603 inStream.reset(); 3604 } catch (IOException e) { 3605 this.logger.write("normal", "Sorry, an error occurred: " 3606 + e.getMessage()); 3607 LoaderException le = new LoaderException("IOException: ", 3608 (Throwable) e); 3609 this.logger.write("full", le.getStackTraceAsString()); 3610 throw le; 3611 } 3612 this.logger.write("full", "\tparseMainElements method is finished."); 3613 return vecLoaderElements; 3614 } 3615 3616 /*** 3617 * Method importRestartCounter is used to analyse import XML file and read 3618 * restart counter attributes. Values of these attributes puts in Vectors 3619 * 3620 * @param inStream 3621 * Data from inputXML file which is converted into InputStream. 3622 * @throws LoaderException 3623 */ 3624 private void importRestartCounter(InputStream inStream) 3625 throws LoaderException { 3626 Document doc = null; 3627 this.logger.write("full", "\timportRestartCounter method is started."); 3628 try { 3629 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3630 DocumentBuilder db = null; 3631 db = dbf.newDocumentBuilder(); 3632 doc = db.parse(inStream); 3633 } catch (Exception e) { 3634 this.logger.write("normal", "Sorry, an error occurred: " + e); 3635 LoaderException le = new LoaderException("Exception: ", 3636 (Throwable) e); 3637 this.logger.write("full", le.getStackTraceAsString()); 3638 throw le; 3639 // System.exit(1); 3640 } 3641 if (doc != null) { 3642 NodeList tagRestartCounter = doc 3643 .getElementsByTagName("restartCounter"); 3644 if (tagRestartCounter.getLength() != 0) { 3645 this.hasRestartCounter = true; 3646 NamedNodeMap attrs = tagRestartCounter.item(0).getAttributes(); 3647 Node nodeResult = attrs.getNamedItem("tableName"); 3648 if (nodeResult != null) 3649 importDefinitionElement.strRestartCounterTableName = nodeResult 3650 .getNodeValue(); 3651 else 3652 importDefinitionElement.strRestartCounterTableName = "LOADERRESTART"; 3653 nodeResult = attrs.getNamedItem("importDefinitionColumnName"); 3654 if (nodeResult != null) 3655 importDefinitionElement.strRestartCounterImportDefinitionName = nodeResult 3656 .getNodeValue(); 3657 else 3658 importDefinitionElement.strRestartCounterImportDefinitionName = "IMPORTDEFINITION"; 3659 nodeResult = attrs.getNamedItem("restartCounterColumnName"); 3660 if (nodeResult != null) 3661 importDefinitionElement.strRestartCounterValue = nodeResult 3662 .getNodeValue(); 3663 else 3664 importDefinitionElement.strRestartCounterValue = "RESTARTCOUNTER"; 3665 nodeResult = attrs.getNamedItem("restartAutoCreate"); 3666 if (nodeResult != null) 3667 importDefinitionElement.bRestartAutoCreate = (new Boolean( 3668 nodeResult.getNodeValue())).booleanValue(); 3669 else 3670 importDefinitionElement.bRestartAutoCreate = false; 3671 } 3672 } 3673 try { 3674 inStream.reset(); 3675 } catch (IOException e) { 3676 this.logger.write("normal", "Sorry, an error occurred: " + e); 3677 LoaderException le = new LoaderException("IOException: ", 3678 (Throwable) e); 3679 this.logger.write("full", le.getStackTraceAsString()); 3680 throw le; 3681 // System.exit(1); 3682 } 3683 this.logger.write("full", "\timportRestartCounter method is finished."); 3684 } 3685 3686 /*** 3687 * Method importVariable imports sql attributes from xml file and puts them 3688 * in the global variables. Return Vector. It's elements are strings which 3689 * represents sql statements. 3690 * 3691 * @param inStream 3692 * Data from inputXML file which is converted into InputStream. 3693 * @throws LoaderException 3694 */ 3695 private void importVariable(InputStream inStream) throws LoaderException { 3696 Document doc = null; 3697 String strNodeValue = ""; 3698 String strDefaultVariableOverride = ""; 3699 String strDefaultReplaceInConstants = ""; 3700 String strDefaultReplaceInSQL = ""; 3701 String strDefaultReplaceInData = ""; 3702 String strDefaultReplaceInJDBC = ""; 3703 String strDefaultVariablePrefix = ""; 3704 String strDefaultVariableSufix = ""; 3705 this.logger.write("full", "\timportVariable method is started."); 3706 try { 3707 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3708 DocumentBuilder db = null; 3709 db = dbf.newDocumentBuilder(); 3710 doc = db.parse(inStream); 3711 if (doc != null) { 3712 NodeList tagBasic = doc.getElementsByTagName("variables"); 3713 if (tagBasic.getLength() != 0) { 3714 Element docFragment = (Element) tagBasic.item(0); 3715 strDefaultVariablePrefix = docFragment 3716 .getAttribute("prefix"); 3717 if (strDefaultVariablePrefix.equals("")) 3718 strDefaultVariablePrefix = "%"; 3719 strDefaultVariableSufix = docFragment 3720 .getAttribute("suffix"); 3721 if (strDefaultVariableSufix.equals("")) 3722 strDefaultVariableSufix = "%"; 3723 strDefaultVariableOverride = docFragment 3724 .getAttribute("override"); 3725 if (strDefaultVariableOverride.equals("")) 3726 strDefaultVariableOverride = "true"; 3727 strDefaultReplaceInConstants = docFragment 3728 .getAttribute("replaceInConstants"); 3729 if (strDefaultReplaceInConstants.equals("")) 3730 strDefaultReplaceInConstants = "false"; 3731 strDefaultReplaceInSQL = docFragment 3732 .getAttribute("replaceInSQL"); 3733 if (strDefaultReplaceInSQL.equals("")) 3734 strDefaultReplaceInSQL = "false"; 3735 strDefaultReplaceInData = docFragment 3736 .getAttribute("replaceInData"); 3737 if (strDefaultReplaceInData.equals("")) 3738 strDefaultReplaceInData = "false"; 3739 strDefaultReplaceInJDBC = docFragment 3740 .getAttribute("replaceInJDBC"); 3741 if (strDefaultReplaceInJDBC.equals("")) 3742 strDefaultReplaceInJDBC = "false"; 3743 NodeList tag = docFragment.getElementsByTagName("variable"); 3744 this.vecVariableName = OctopusXMLUtil.getAttributeValues( 3745 tag, "name", null); 3746 this.vecVariableValue = OctopusXMLUtil.getAttributeValues( 3747 tag, "value", null); 3748 this.vecVariablePrefix = OctopusXMLUtil.getAttributeValues( 3749 tag, "prefix", strDefaultVariablePrefix); 3750 this.vecVariableSufix = OctopusXMLUtil.getAttributeValues( 3751 tag, "suffix", strDefaultVariableSufix); 3752 this.vecVariableOverride = OctopusXMLUtil 3753 .getAttributeValues(tag, "override", 3754 strDefaultVariableOverride); 3755 this.vecReplaceInConstants = OctopusXMLUtil 3756 .getAttributeValues(tag, "replaceInConstants", 3757 strDefaultReplaceInConstants); 3758 this.vecReplaceInSQL = OctopusXMLUtil.getAttributeValues( 3759 tag, "replaceInSQL", strDefaultReplaceInSQL); 3760 this.vecReplaceInData = OctopusXMLUtil.getAttributeValues( 3761 tag, "replaceInData", strDefaultReplaceInData); 3762 this.vecReplaceInJDBC = OctopusXMLUtil.getAttributeValues( 3763 tag, "replaceInJDBC", strDefaultReplaceInJDBC); 3764 for (int i = 0; i < this.vecVariableOverride.size(); i++) { 3765 if (this.vecVariableOverride.get(i).toString() 3766 .equalsIgnoreCase("true")) { 3767 if (this.mapVariableValues.get(this.vecVariableName 3768 .get(i)) == null) 3769 this.vecVariableValue.setElementAt(null, i); 3770 else 3771 this.vecVariableValue 3772 .setElementAt(this.mapVariableValues 3773 .get( 3774 this.vecVariableName 3775 .get(i) 3776 .toString()) 3777 .toString(), i); 3778 } 3779 } 3780 } 3781 } 3782 } catch (Exception e) { 3783 this.logger.write("normal", 3784 "Sorry, an error with the variables occurred: " + e); 3785 LoaderException le = new LoaderException("Exception: ", 3786 (Throwable) e); 3787 this.logger.write("full", le.getStackTraceAsString()); 3788 throw le; 3789 } 3790 try { 3791 inStream.reset(); 3792 } catch (IOException e) { 3793 this.logger.write("normal", "Sorry, an error occurred: " + e); 3794 LoaderException le = new LoaderException("IOException: ", 3795 (Throwable) e); 3796 this.logger.write("full", le.getStackTraceAsString()); 3797 throw le; 3798 } 3799 this.logger.write("full", "\timportVariable method is finished."); 3800 } 3801 3802 /*** 3803 * Method parseAndImport is used to analyse the importDefinition no. l in 3804 * xml file and input all values and puts them into global variables. If 3805 * there is an error, Exception "SAXException" is thrown. 3806 * 3807 * @param inStream 3808 * Data from inputXML file which is converted into InputStream. 3809 * @param l 3810 * Number of ImportDefinition tag which is processed. 3811 * @throws SAXException 3812 * Constructs an JAXP 1.1 Exception with the specified detail 3813 * message. 3814 * @throws Exception 3815 * Constructs an Exception with the specified detail message. 3816 * @throws LoaderException 3817 */ 3818 private void parseAndImport(InputStream inStream, int l) 3819 throws SAXException, LoaderException, Exception { 3820 this.logger.write("full", "\tparseAndImport method is started."); 3821 Document doc = null; 3822 try { 3823 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3824 DocumentBuilder db = null; 3825 db = dbf.newDocumentBuilder(); 3826 doc = db.parse(inStream); 3827 } catch (SAXException e) { 3828 throw e; 3829 } catch (Exception e) { 3830 throw e; 3831 } 3832 if (doc != null) 3833 this.importXMLFile(doc, l); 3834 try { 3835 inStream.reset(); 3836 } catch (IOException e) { 3837 this.logger.write("normal", "Sorry, an error occurred: " + e); 3838 LoaderException le = new LoaderException("IOException: ", 3839 (Throwable) e); 3840 this.logger.write("full", le.getStackTraceAsString()); 3841 throw le; 3842 } 3843 this.logger.write("full", "\tparseAndImport method is finished."); 3844 } 3845 3846 /*** 3847 * Method importXMLFile is used for setting of global variables during 3848 * importing values from XML file. This method validates the imported data 3849 * from XML file. If there is an error Exception "NullPointerException" or 3850 * "Exception" is thrown. 3851 * 3852 * @param doc 3853 * Parsed imports XML file. 3854 * @param iJobNumber 3855 * Number of ImportJob tag which is processed. 3856 * @throws NullPointerException 3857 * Constructs a NullPointerException with the specified detail 3858 * message. 3859 * @throws Exception 3860 * Constructs an Exception with the specified detail message. 3861 */ 3862 private void importXMLFile(Document doc, int iJobNumber) 3863 throws NullPointerException, Exception { 3864 this.logger.write("full", "\timportXMLFile method is started."); 3865 Vector vecValueColumnSourceColumnName = new Vector(); 3866 Vector vecValueColumnTargetTableName = new Vector(); 3867 Vector vecValueColumnTargetColumnName = new Vector(); 3868 Vector vecValueColumnTargetTableID = new Vector(); 3869 Vector vecValueColumnValueMode = new Vector(); 3870 Vector vecConstantColumnTargetColumnName = new Vector(); 3871 Vector vecConstantColumnValueMode = new Vector(); 3872 Vector vecConstantColumnConstantValue = new Vector(); 3873 Vector vecRestartCounterVector = new Vector(); 3874 Vector vecJDBCSourceName = new Vector(); 3875 Vector vecJDBCSourceValue = new Vector(); 3876 Vector vecJDBCTargetName = new Vector(); 3877 Vector vecJDBCTargetValue = new Vector(); 3878 // vector for default values of columns 3879 Vector vecDefaultValueTemp = new Vector(); 3880 this.vecDefaultValue = new Vector(); 3881 this.vecDefaultRelationValue = null; 3882 this.vecDefaultVariableValue = null; 3883 this.vecDefaultVariableName = null; 3884 this.vecTempUserID = null; 3885 int iNumberOfColumns = 0; 3886 // to and form hex 3887 Vector vecToHexTemp = new Vector(); 3888 Vector vecFromHexTemp = new Vector(); 3889 this.vecToHex = new Vector(); 3890 this.vecFromHex = new Vector(); 3891 3892 try { 3893 3894 importDefinitionElement.setLogger(this.logger); 3895 dataCleaning.setLogger(this.logger); 3896 3897 if (!this.loaderJobReader.getLogTableName().equalsIgnoreCase("")) 3898 dataCleaning.setLogTableName(this.loaderJobReader 3899 .getLogTableName()); 3900 3901 if (!this.loaderJobReader.getLogTable().equalsIgnoreCase("")) 3902 dataCleaning.setLogTable(this.loaderJobReader.getLogTable()); 3903 3904 if (!this.loaderJobReader.getLogColumnName().equalsIgnoreCase("")) 3905 dataCleaning.setLogColumnName(this.loaderJobReader 3906 .getLogColumnName()); 3907 3908 if (!this.loaderJobReader.getLogRowNumber().equalsIgnoreCase("")) 3909 dataCleaning.setLogRowNumber(this.loaderJobReader 3910 .getLogRowNumber()); 3911 3912 if (!this.loaderJobReader.getLogOriginalValue() 3913 .equalsIgnoreCase("")) 3914 dataCleaning.setLogOriginalValue(this.loaderJobReader 3915 .getLogOriginalValue()); 3916 3917 if (!this.loaderJobReader.getLogNewValue().equalsIgnoreCase("")) 3918 dataCleaning.setLogNewValue(this.loaderJobReader 3919 .getLogNewValue()); 3920 3921 if (!this.loaderJobReader.getLogImportDefinitionName() 3922 .equalsIgnoreCase("")) 3923 dataCleaning.setLogImportDefinitionName(this.loaderJobReader 3924 .getLogImportDefinitionName()); 3925 3926 if (!this.loaderJobReader.getLogOperationName() 3927 .equalsIgnoreCase("")) 3928 dataCleaning.setLogOperationName(this.loaderJobReader 3929 .getLogOperationName()); 3930 if (!this.loaderJobReader.getLogTime().equalsIgnoreCase("")) 3931 dataCleaning.setLogTime(this.loaderJobReader.getLogTime()); 3932 3933 if (!this.loaderJobReader.getLogFailedStatement().equalsIgnoreCase( 3934 "")) 3935 dataCleaning.setLogPrimaryKeyValue(this.loaderJobReader 3936 .getLogFailedStatement()); 3937 3938 if (!this.loaderJobReader.getLogTypeName().equalsIgnoreCase("")) 3939 dataCleaning.setLogTypeName(this.loaderJobReader 3940 .getLogTypeName()); 3941 3942 importDefinitionElement.setLoaderJob(this.loaderJobReader); 3943 // sqlElement.setLoaderJob(this.loaderJobReader); 3944 importDefinitionElement.importXMLFile(doc, iJobNumber); 3945 3946 // set data cut off parameter based on priority 3947 if (importDefinitionElement.strDefaultCutOffData 3948 .equalsIgnoreCase("")) 3949 importDefinitionElement.strDefaultCutOffData = loaderJobReader 3950 .getDefaultDataCutOff(); 3951 3952 // set onErrorContinue parameter based on priority for xml 3953 if (importDefinitionElement.strOnErrorContinueXml 3954 .equalsIgnoreCase("")) 3955 importDefinitionElement.strOnErrorContinueXml = "" 3956 + loaderJobReader.getDefaultOnErrorContinue(); 3957 3958 if (importDefinitionElement.strCopyTableOnErrorContinue 3959 .equalsIgnoreCase("")) 3960 importDefinitionElement.strCopyTableOnErrorContinue = "" 3961 + loaderJobReader.getDefaultOnErrorContinue(); 3962 3963 vecJDBCSourceValue = OctopusXMLUtil.importValue(doc, 3964 "jdbcSourceParameter", "value", iJobNumber); 3965 vecJDBCSourceName = OctopusXMLUtil.importValue(doc, 3966 "jdbcSourceParameter", "name", iJobNumber); 3967 if (vecJDBCSourceValue.size() != 0) { 3968 for (int i = 0; i < vecJDBCSourceValue.size(); i++) { 3969 if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase( 3970 "JdbcDriver")) 3971 jdbcParametersElement 3972 .setJDBCSourceParameterDriver(vecJDBCSourceValue 3973 .get(i).toString()); 3974 else if (vecJDBCSourceName.get(i).toString() 3975 .equalsIgnoreCase("Connection.Url")) { 3976 // Testing SelectMethod parameter in microsoft MSSQL 3977 // driver 3978 if (vecJDBCSourceValue.get(i).toString().indexOf( 3979 "jdbc:microsoft:sqlserver") != -1) { 3980 if (vecJDBCSourceValue.get(i).toString().indexOf( 3981 "SelectMethod") == -1) { 3982 jdbcParametersElement 3983 .setJDBCSourceParameterConnection(vecJDBCSourceValue 3984 .get(i).toString() 3985 + ";SelectMethod=cursor"); 3986 } else if (vecJDBCSourceValue.get(i).toString() 3987 .indexOf("cursor") != -1) { 3988 jdbcParametersElement 3989 .setJDBCSourceParameterConnection(vecJDBCSourceValue 3990 .get(i).toString()); 3991 } else { 3992 this.logger 3993 .write( 3994 "normal", 3995 "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor"); 3996 LoaderException le = new LoaderException( 3997 "Exception:", 3998 new Exception( 3999 "Value of Connection.Url perameter SelectMethod has to be cursor")); 4000 this.logger.write("full", le 4001 .getStackTraceAsString()); 4002 throw le; 4003 } 4004 } else { 4005 jdbcParametersElement 4006 .setJDBCSourceParameterConnection(vecJDBCSourceValue 4007 .get(i).toString()); 4008 } 4009 } else if (vecJDBCSourceName.get(i).toString() 4010 .equalsIgnoreCase("User")) 4011 jdbcParametersElement 4012 .setJDBCSourceParameterUser(vecJDBCSourceValue 4013 .get(i).toString()); 4014 else if (vecJDBCSourceName.get(i).toString() 4015 .equalsIgnoreCase("Password")) 4016 jdbcParametersElement 4017 .setJDBCSourceParameterPassword(vecJDBCSourceValue 4018 .get(i).toString()); 4019 } 4020 } 4021 vecJDBCTargetValue = OctopusXMLUtil.importValue(doc, 4022 "jdbcTargetParameter", "value", iJobNumber); 4023 vecJDBCTargetName = OctopusXMLUtil.importValue(doc, 4024 "jdbcTargetParameter", "name", iJobNumber); 4025 4026 if (vecJDBCTargetValue.size() != 0) { 4027 for (int i = 0; i < vecJDBCTargetValue.size(); i++) { 4028 if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase( 4029 "JdbcDriver")) 4030 jdbcParametersElement 4031 .setJDBCTargetParameterDriver(vecJDBCTargetValue 4032 .get(i).toString()); 4033 else if (vecJDBCTargetName.get(i).toString() 4034 .equalsIgnoreCase("Connection.Url")) { 4035 // Testing SelectMethod parameter in microsoft MSSQL 4036 // driver 4037 if (vecJDBCTargetValue.get(i).toString().indexOf( 4038 "jdbc:microsoft:sqlserver") != -1) { 4039 if (vecJDBCTargetValue.get(i).toString().indexOf( 4040 "SelectMethod") == -1) { 4041 jdbcParametersElement 4042 .setJDBCTargetParameterConnection(vecJDBCTargetValue 4043 .get(i).toString() 4044 + ";SelectMethod=cursor"); 4045 } else if (vecJDBCTargetValue.get(i).toString() 4046 .indexOf("cursor") != -1) { 4047 jdbcParametersElement 4048 .setJDBCTargetParameterConnection(vecJDBCTargetValue 4049 .get(i).toString()); 4050 } else { 4051 this.logger 4052 .write( 4053 "normal", 4054 "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor"); 4055 LoaderException le = new LoaderException( 4056 "Exception:", 4057 new Exception( 4058 "value of Connection.Url parameter SelectMethod has to be cursor")); 4059 this.logger.write("full", le 4060 .getStackTraceAsString()); 4061 throw le; 4062 } 4063 } else { 4064 jdbcParametersElement 4065 .setJDBCTargetParameterConnection(vecJDBCTargetValue 4066 .get(i).toString()); 4067 } 4068 } else if (vecJDBCTargetName.get(i).toString() 4069 .equalsIgnoreCase("User")) 4070 jdbcParametersElement 4071 .setJDBCTargetParameterUser(vecJDBCTargetValue 4072 .get(i).toString()); 4073 else if (vecJDBCTargetName.get(i).toString() 4074 .equalsIgnoreCase("Password")) 4075 jdbcParametersElement 4076 .setJDBCTargetParameterPassword(vecJDBCTargetValue 4077 .get(i).toString()); 4078 } 4079 } 4080 // to and form hex 4081 vecToHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn", 4082 "toHex", iJobNumber); 4083 vecFromHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn", 4084 "fromHex", iJobNumber); 4085 // defalut values 4086 vecDefaultValueTemp = OctopusXMLUtil.importValue(doc, 4087 "valueColumn", "defaultValue", iJobNumber); 4088 this.vecDefaultVariableValue = OctopusXMLUtil.importValue(doc, 4089 "variableColumn", "defaultValue", iJobNumber); 4090 this.vecDefaultVariableName = OctopusXMLUtil.importValue(doc, 4091 "variableColumn", "name", iJobNumber); 4092 this.vecDefaultRelationValue = OctopusXMLUtil.importValue(doc, 4093 "relationColumn", "defaultValue", iJobNumber); 4094 this.vecTempUserID = OctopusXMLUtil.importValue(doc, 4095 "userIDColumn", "defaultValue", iJobNumber); 4096 vecValueColumnSourceColumnName = OctopusXMLUtil.importValue(doc, 4097 "valueColumn", "sourceColumnName", iJobNumber); 4098 vecValueColumnTargetTableName = OctopusXMLUtil.importValue(doc, 4099 "valueColumn", "targetTableName", iJobNumber); 4100 this.iValueColumns = vecValueColumnTargetTableName.size(); 4101 vecValueColumnTargetColumnName = OctopusXMLUtil.importValue(doc, 4102 "valueColumn", "targetColumnName", iJobNumber); 4103 vecValueColumnTargetTableID = OctopusXMLUtil.importValue(doc, 4104 "valueColumn", "targetTableID", iJobNumber); 4105 vecValueColumnValueMode = OctopusXMLUtil.importValue(doc, 4106 "valueColumn", "valueMode", iJobNumber); 4107 this.vecVariableColumnName = OctopusXMLUtil.importValue(doc, 4108 "variableColumn", "name", iJobNumber); 4109 this.vecVariableColumnTargetTableName = OctopusXMLUtil.importValue( 4110 doc, "variableColumn", "targetTableName", iJobNumber); 4111 this.vecVariableColumnTargetColumnName = OctopusXMLUtil 4112 .importValue(doc, "variableColumn", "targetColumnName", 4113 iJobNumber); 4114 this.vecVariableColumnTargetTableID = OctopusXMLUtil.importValue( 4115 doc, "variableColumn", "targetTableID", iJobNumber); 4116 this.vecVariableColumnValueMode = OctopusXMLUtil.importValue(doc, 4117 "variableColumn", "valueMode", iJobNumber); 4118 this.vecVariableUseIDTableName = OctopusXMLUtil.importValue(doc, 4119 "userIDColumn", "targetTableName", iJobNumber); 4120 this.vecVariableUseIDColumnName = OctopusXMLUtil.importValue(doc, 4121 "userIDColumn", "targetColumnName", iJobNumber); 4122 this.vecVariableUseIDTableID = OctopusXMLUtil.importValue(doc, 4123 "userIDColumn", "targetTableID", iJobNumber); 4124 this.vecVariableUseIDValueMode = OctopusXMLUtil.importValue(doc, 4125 "userIDColumn", "valueMode", iJobNumber); 4126 this.vecVariableTimesTableName = OctopusXMLUtil.importValue(doc, 4127 "timeStampColumn", "targetTableName", iJobNumber); 4128 this.vecVariableTimesColumnName = OctopusXMLUtil.importValue(doc, 4129 "timeStampColumn", "targetColumnName", iJobNumber); 4130 this.vecVariableTimesTableID = OctopusXMLUtil.importValue(doc, 4131 "timeStampColumn", "targetTableID", iJobNumber); 4132 this.vecVariableTimesValueMode = OctopusXMLUtil.importValue(doc, 4133 "timeStampColumn", "valueMode", iJobNumber); 4134 this.vecConstantColumnTargetTableName = OctopusXMLUtil.importValue( 4135 doc, "constantColumn", "targetTableName", iJobNumber); 4136 this.iConstantColumns = this.vecConstantColumnTargetTableName 4137 .size(); 4138 vecConstantColumnTargetColumnName = OctopusXMLUtil.importValue(doc, 4139 "constantColumn", "targetColumnName", iJobNumber); 4140 this.vecConstantColumnTargetTableID = OctopusXMLUtil.importValue( 4141 doc, "constantColumn", "targetTableID", iJobNumber); 4142 vecConstantColumnValueMode = OctopusXMLUtil.importValue(doc, 4143 "constantColumn", "valueMode", iJobNumber); 4144 4145 vecConstantColumnConstantValue = OctopusXMLUtil.importValue(doc, 4146 "constantColumn", "constantValue", iJobNumber, null); 4147 this.vecRelationColumnSourceTableName = OctopusXMLUtil.importValue( 4148 doc, "relationColumn", "relationSourceTableName", 4149 iJobNumber); 4150 this.iRelationColumns = this.vecRelationColumnSourceTableName 4151 .size(); 4152 this.vecRelationColumnSourceTableID = OctopusXMLUtil.importValue( 4153 doc, "relationColumn", "relationSourceTableID", iJobNumber); 4154 this.vecRelationColumnSourceColumnName = OctopusXMLUtil 4155 .importValue(doc, "relationColumn", 4156 "relationSourceColumnName", iJobNumber); 4157 this.vecRelationColumnTargetTableName = OctopusXMLUtil.importValue( 4158 doc, "relationColumn", "relationTargetTableName", 4159 iJobNumber); 4160 this.vecRelationColumnTargetColumnName = OctopusXMLUtil 4161 .importValue(doc, "relationColumn", 4162 "relationTargetColumnName", iJobNumber); 4163 this.vecRelationColumnTargetTableID = OctopusXMLUtil.importValue( 4164 doc, "relationColumn", "relationTargetTableID", iJobNumber); 4165 this.vecRelationColumnRelationMode = OctopusXMLUtil.importValue( 4166 doc, "relationColumn", "relationMode", iJobNumber); 4167 // rale 4168 4169 ImportDefinitionSourceColumnName = vecValueColumnSourceColumnName; 4170 ImportDefinitionTargetColumnName = vecValueColumnTargetColumnName; 4171 4172 // sinisa 02.03.2003. Add counterColumns 4173 this.counterColumns = new CounterColumns(); 4174 this.counterColumns.setLogger(this.logger); 4175 this.counterColumns.resetSubCounterCache(); 4176 this.counterColumns.readConstantColumnAttributes(doc, iJobNumber); 4177 this.counterColumns.readConstantColumnsParameters(doc, iJobNumber); 4178 // end sinisa 4179 4180 // sinisa 02.03.2003. Add transformations 4181 this.transformations = new Transformations(this.logger); 4182 // ArrayList transTableNamesIDs = 4183 // this.transformations.getTransformationsTableNamesAndIDs(); 4184 this.transformations.createTransformationElements(doc, iJobNumber); 4185 ArrayList trans = this.transformations.getTransformations(); 4186 Iterator iTrans = trans.iterator(); 4187 4188 while (iTrans.hasNext()) { 4189 Transformation temp = (Transformation) iTrans.next(); 4190 temp.setLogger(this.logger); 4191 4192 // temp.readSourceColumns(doc, iJobNumber); 4193 // temp.readTargetColumns(doc, iJobNumber); 4194 // temp.readSourceColumns(); 4195 // temp.readTargetColumns(); 4196 4197 } 4198 4199 // end sinisa 4200 4201 this.vecTableTableName = OctopusXMLUtil.importValue(doc, "table", 4202 "tableName", iJobNumber); 4203 this.iTables = this.vecTableTableName.size(); 4204 this.vecTableTableID = OctopusXMLUtil.importValue(doc, "table", 4205 "tableID", iJobNumber); 4206 this.vecTableInsert = OctopusXMLUtil.importValue(doc, "table", 4207 "insert", iJobNumber); 4208 this.vecTableTableMode = OctopusXMLUtil.importValue(doc, "table", 4209 "tableMode", iJobNumber, loaderJobReader 4210 .getDefaultTableMode()); 4211 this.vecTableOidLogic = OctopusXMLUtil.importValue(doc, "table", 4212 "oidLogic", iJobNumber, (new Boolean(loaderJobReader 4213 .getDefaultOidLogic())).toString()); 4214 4215 this.vecCTAutoMapp = OctopusXMLUtil.importValue(doc, "table", 4216 "autoMapColumns", iJobNumber); 4217 this.vecCTDefaultMode = OctopusXMLUtil.importValue(doc, "table", 4218 "defaultMode", iJobNumber); 4219 4220 if (this.vecRelationColumnSourceTableName.size() != 0) { 4221 this.changeRelationsOrder(); 4222 this.changeTableOrder(); 4223 } 4224 this.vecRelationKeyColumns.setSize(this.iTables); 4225 this.vecRelationKeyTypes.setSize(this.iTables); 4226 this.vecConstantTargetColumnName.setSize(this.iTables); 4227 // ZK added this 4228 // this.transformationsColumnNames.setSize(this.iTables); 4229 4230 this.vecConstantValueMode.setSize(this.iTables); 4231 this.vecConstantConstantValue.setSize(this.iTables); 4232 this.vecConstantColumnType.setSize(this.iTables); 4233 for (int k = 0; k < vecValueColumnTargetTableName.size(); k++) { 4234 boolean isImportColumn = false; 4235 for (int l = 0; l < this.iTables; l++) { 4236 if (vecValueColumnTargetTableName.get(k).toString() 4237 .equalsIgnoreCase( 4238 this.vecTableTableName.get(l).toString()) 4239 && vecValueColumnTargetTableID.get(k).toString() 4240 .equalsIgnoreCase( 4241 this.vecTableTableID.get(l) 4242 .toString())) { 4243 isImportColumn = true; 4244 } 4245 } 4246 if (!isImportColumn) { 4247 this.logger.write("normal", 4248 "Incorrect XML import variables - TABLE ID"); 4249 LoaderException le = new LoaderException( 4250 "Exception: ", 4251 (Throwable) (new Exception( 4252 "Incorrect XML import variables - TABLE ID"))); 4253 this.logger.write("full", le.getStackTraceAsString()); 4254 throw le; 4255 } 4256 } 4257 4258 if (this.vecVariableUseIDTableName.size() != 0) { 4259 String tempUserID = this.vecTempUserID.get(0).toString(); 4260 if (userIDExists) 4261 this.strUserID = ""; 4262 if (this.strUserID.equals("")) { 4263 if (!tempUserID.equalsIgnoreCase("")) { 4264 this.strUserID = tempUserID; 4265 this.userIDExists = true; 4266 } else { 4267 this.logger.write("normal", 4268 "Error : User parametar missing"); 4269 LoaderException le = new LoaderException("Exception: ", 4270 (Throwable) (new Exception( 4271 "Error : User parametar missing"))); 4272 this.logger.write("full", le.getStackTraceAsString()); 4273 throw le; 4274 } 4275 } 4276 } 4277 for (int k = 0; k < this.iTables; k++) { 4278 iNumberOfColumns = 0; 4279 Vector vecTargetTable1 = new Vector(); 4280 Vector vecTargetTable2 = new Vector(); 4281 Vector vecTargetTable3 = new Vector(); 4282 Vector vecTargetTable4 = new Vector(); 4283 Vector vecTargetTable5 = new Vector(); 4284 Vector vecTargetTable6 = new Vector(); 4285 Vector vecTargetTable7 = new Vector(); 4286 Vector vecTargetTable8 = new Vector(); 4287 Vector vecTargetTable9 = new Vector(); 4288 Vector vecTargetTable10 = new Vector(); 4289 Vector vecTargetTable11 = new Vector(); 4290 4291 for (int l = 0; l < this.iValueColumns; l++) { 4292 if (this.vecTableTableName.get(k).toString() 4293 .equalsIgnoreCase( 4294 vecValueColumnTargetTableName.get(l) 4295 .toString()) 4296 && vecValueColumnTargetTableID.get(l).toString() 4297 .equalsIgnoreCase( 4298 this.vecTableTableID.get(k) 4299 .toString())) { 4300 iNumberOfColumns++; 4301 vecTargetTable1 4302 .addElement(vecValueColumnSourceColumnName.get( 4303 l).toString()); 4304 vecTargetTable2 4305 .addElement(vecValueColumnTargetColumnName.get( 4306 l).toString()); 4307 vecTargetTable4.addElement(vecValueColumnValueMode.get( 4308 l).toString()); 4309 // rale 4310 vecTargetTable9.addElement(vecDefaultValueTemp.get(l) 4311 .toString()); 4312 vecTargetTable10.addElement(vecToHexTemp.get(l) 4313 .toString()); 4314 vecTargetTable11.addElement(vecFromHexTemp.get(l) 4315 .toString()); 4316 if (vecValueColumnValueMode.get(l).toString() 4317 .equalsIgnoreCase("Key")) 4318 vecTargetTable5 4319 .addElement(vecValueColumnTargetColumnName 4320 .get(l).toString()); 4321 } 4322 } 4323 for (int l = 0; l < this.vecVariableUseIDTableName.size(); l++) { 4324 if (this.vecTableTableName.get(k).toString() 4325 .equalsIgnoreCase( 4326 this.vecVariableUseIDTableName.get(l) 4327 .toString()) 4328 && this.vecVariableUseIDTableID.get(l).toString() 4329 .equalsIgnoreCase( 4330 this.vecTableTableID.get(k) 4331 .toString())) { 4332 vecTargetTable2 4333 .addElement(this.vecVariableUseIDColumnName 4334 .get(l).toString()); 4335 vecTargetTable4 4336 .addElement(this.vecVariableUseIDValueMode.get( 4337 l).toString()); 4338 // rale 4339 // vecTargetTable9.addElement(vecDefaultValueTemp.get(l).toString()); 4340 // vecTargetTable10.addElement(vecToHexTemp.get(l).toString()); 4341 // vecTargetTable11.addElement(vecFromHexTemp.get(l).toString()); 4342 4343 if (this.vecVariableUseIDValueMode.get(l).toString() 4344 .equalsIgnoreCase("Key")) 4345 vecTargetTable5 4346 .addElement(this.vecVariableUseIDColumnName 4347 .get(l).toString()); 4348 } 4349 } 4350 for (int l = 0; l < this.vecRelationColumnSourceColumnName 4351 .size(); l++) { 4352 if (this.vecTableTableName.get(k).toString() 4353 .equalsIgnoreCase( 4354 this.vecRelationColumnTargetTableName 4355 .get(l).toString()) 4356 && this.vecRelationColumnTargetTableID.get(l) 4357 .toString().equalsIgnoreCase( 4358 this.vecTableTableID.get(k) 4359 .toString()) 4360 && this.vecRelationColumnRelationMode.get(l) 4361 .toString().equalsIgnoreCase("Key")) { 4362 vecTargetTable3 4363 .addElement(this.vecRelationColumnTargetColumnName 4364 .get(l).toString()); 4365 } 4366 } 4367 4368 // rale 4369 this.vecToHex.addElement(vecToHexTemp); 4370 this.vecFromHex.addElement(vecFromHexTemp); 4371 this.vecDefaultValue.addElement(vecTargetTable9); 4372 this.vecSourceColumnName.addElement(vecTargetTable1); 4373 this.vecTargetColumnName.addElement(vecTargetTable2); 4374 this.vecRelationKeyColumns.setElementAt(vecTargetTable3, k); 4375 this.vecValueMode.addElement(vecTargetTable4); 4376 this.vecTargetKeyColumnName.addElement(vecTargetTable5); 4377 this.vecValueColumnsTargetTables.addElement(new Integer( 4378 iNumberOfColumns)); 4379 for (int p = 0; p < this.iConstantColumns; p++) { 4380 if (this.vecTableTableName.get(k).toString() 4381 .equalsIgnoreCase( 4382 this.vecConstantColumnTargetTableName 4383 .get(p).toString()) 4384 && this.vecConstantColumnTargetTableID.get(p) 4385 .toString().equalsIgnoreCase( 4386 this.vecTableTableID.get(k) 4387 .toString())) { 4388 vecTargetTable6 4389 .addElement(vecConstantColumnTargetColumnName 4390 .get(p).toString()); 4391 vecTargetTable7.addElement(vecConstantColumnValueMode 4392 .get(p).toString()); 4393 if (vecConstantColumnConstantValue.get(p) == null) 4394 vecTargetTable8.addElement(null); 4395 else 4396 vecTargetTable8 4397 .addElement(vecConstantColumnConstantValue 4398 .get(p).toString()); 4399 } 4400 } 4401 this.vecConstantTargetColumnName.setElementAt(vecTargetTable6, 4402 k); 4403 this.vecConstantValueMode.setElementAt(vecTargetTable7, k); 4404 this.vecConstantConstantValue.setElementAt(vecTargetTable8, k); 4405 4406 // sinisa 02.03.2003. Add counterColumns 4407 4408 this.counterColumns.setConstantColumnsParameters( 4409 this.vecTableTableName.get(k).toString(), 4410 this.vecTableTableID.get(k).toString()); 4411 // end sinisa 4412 } 4413 4414 for (int i = 0; i < this.vecRelationColumnSourceColumnName.size(); i++) { 4415 if (this.vecRelationColumnSourceColumnName.get(i).toString() 4416 .equals("")) { 4417 for (int k = 0; k < this.vecTableTableName.size(); k++) { 4418 if (this.vecRelationColumnSourceTableName.get(i) 4419 .toString().equalsIgnoreCase( 4420 this.vecTableTableName.get(k) 4421 .toString()) 4422 && this.vecRelationColumnSourceTableID.get(i) 4423 .toString().equalsIgnoreCase( 4424 this.vecTableTableID.get(k) 4425 .toString())) { 4426 if (this.vecTableOidLogic.get(k).toString() 4427 .equalsIgnoreCase("true")) 4428 this.vecRelationColumnSourceColumnName 4429 .setElementAt( 4430 this.currentOidColumnName, i); 4431 // this.vecRelationColumnSourceColumnName.setElementAt("oid",i); 4432 } 4433 } 4434 } 4435 } 4436 this.vecRelationSourceValue.setSize(this.iRelationColumns); 4437 this.vecRelationSourceType.setSize(this.iRelationColumns); 4438 } catch (NullPointerException ex) { 4439 throw ex; 4440 } catch (Exception ex) { 4441 throw ex; 4442 } 4443 this.logger.write("full", "\timportXMLFile method is finished."); 4444 } 4445 4446 /*** 4447 * Method updateCurrentTime write system time into timeStamp variable 4448 * columns 4449 * 4450 * @param c 4451 * Connection to the target table. 4452 * @param iTable 4453 * Number of target table. 4454 * @param strQueryWhereSQL 4455 * Part of SQL query - where clause. 4456 * @param currentVersion 4457 * represents current version of insert/update 4458 * @param oid 4459 * repersents if the oid logic is present 4460 * @throws SQLException 4461 * @throws NullPointerException 4462 * @return true if something is written to database 4463 */ 4464 private boolean updateCurrentTime(Connection c, int iTable, 4465 String strQueryWhereSQL, int currentVersion, boolean oid) 4466 throws SQLException, NullPointerException { 4467 String strQueryInsertTime = ""; 4468 boolean bWriteData = false; 4469 String oidVersion = ""; 4470 // if (oid) 4471 // oidVersion = ", version=" + currentVersion; 4472 if (oid) 4473 oidVersion = ", " + this.currentVersionColumnName + "=" 4474 + currentVersion; 4475 this.logger.write("full", "\t updateCurrentTime method is started."); 4476 try { 4477 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) { 4478 if (this.vecVariableTimesTableName.get(i).toString() 4479 .equalsIgnoreCase( 4480 this.vecTableTableName.get(iTable).toString()) 4481 && this.vecVariableTimesTableID.get(i).toString() 4482 .equalsIgnoreCase( 4483 this.vecTableTableID.get(iTable) 4484 .toString())) { 4485 Statement stmtRelations = c.createStatement(); 4486 strQueryInsertTime = "update " 4487 + this.vecVariableTimesTableName.get(i).toString() 4488 + " set " 4489 + this.vecVariableTimesColumnName.get(i).toString() 4490 + " = "; 4491 if (this.vecVariableTimesValueMode.get(i).toString() 4492 .equalsIgnoreCase("Overwrite")) 4493 4494 // && bWriteData == true) 4495 strQueryInsertTime += " '" + this.createCurrentDate() 4496 + "'" + oidVersion + " where " 4497 + strQueryWhereSQL; 4498 else 4499 strQueryInsertTime += " '" 4500 + this.createCurrentDate() 4501 + "'" 4502 + oidVersion 4503 + " where " 4504 + this.vecVariableTimesColumnName.get(i) 4505 .toString() + " is null and " 4506 + strQueryWhereSQL; 4507 this.logger.write("full", "\tQuery '" + strQueryInsertTime 4508 + "' will be executed"); 4509 if (bReplaceInData) { 4510 strQueryInsertTime = this 4511 .replaceInData(strQueryInsertTime); 4512 } 4513 int num = stmtRelations.executeUpdate(strQueryInsertTime); 4514 if (num != 0) { 4515 bWriteData = true; 4516 } 4517 stmtRelations.close(); 4518 } 4519 } 4520 } catch (SQLException ex) { 4521 throw ex; 4522 } catch (NullPointerException ex) { 4523 throw ex; 4524 } 4525 this.logger.write("full", "\tupdateCurrentTime method is finished."); 4526 return bWriteData; 4527 } 4528 4529 /*** 4530 * Method updateNameValue writes nameValue value (Loader's argument) into 4531 * variable columns 4532 * 4533 * @param c 4534 * Connection to the target table. 4535 * @param iTable 4536 * Number of target table. 4537 * @param strQueryWhereSQL 4538 * Part of SQL query - where clause. 4539 * @param currentVersion 4540 * represents current version of insert/update 4541 * @param oid 4542 * define if oid logic is present 4543 * @throws SQLException 4544 * @throws NullPointerException 4545 * @throws LoaderException 4546 * @return true if something is written to database 4547 */ 4548 private boolean updateNameValue(Connection c, int iTable, 4549 String strQueryWhereSQL, int currentVersion, boolean oid) 4550 throws SQLException, NullPointerException, LoaderException { 4551 4552 String strQueryInsertName = ""; 4553 boolean bWriteData = false; 4554 String oidVersion = ""; 4555 // if (oid) 4556 // oidVersion = ", version=" + currentVersion; 4557 if (oid) 4558 oidVersion = ", " + this.currentVersionColumnName + "=" 4559 + currentVersion; 4560 4561 this.logger.write("full", "\t updateNameValue method is started."); 4562 try { 4563 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) { 4564 boolean bInsert = true; 4565 if (this.vecVariableColumnTargetTableName.get(i).toString() 4566 .equalsIgnoreCase( 4567 this.vecTableTableName.get(iTable).toString()) 4568 && this.vecVariableColumnTargetTableID.get(i) 4569 .toString().equalsIgnoreCase( 4570 this.vecTableTableID.get(iTable) 4571 .toString())) { 4572 int iPositionInVector = this.vecVariableName 4573 .indexOf(this.vecVariableColumnName.get(i) 4574 .toString()); 4575 if (iPositionInVector != -1) { 4576 Statement stmtRelations = c.createStatement(); 4577 strQueryInsertName = "update " 4578 + this.vecVariableColumnTargetTableName.get(i) 4579 .toString() 4580 + " set " 4581 + this.vecVariableColumnTargetColumnName.get(i) 4582 .toString() + " = "; 4583 if (this.vecVariableColumnValueMode.get(i).toString() 4584 .equalsIgnoreCase("Overwrite")) { 4585 if (this.vecVariableValue.get(iPositionInVector) == null) { 4586 String variableName = this.vecVariableColumnName 4587 .get(i).toString(); 4588 for (int k = 0; k < this.vecDefaultVariableName 4589 .size(); k++) { 4590 if (this.vecDefaultVariableName.get(k) 4591 .toString().equalsIgnoreCase( 4592 variableName)) { 4593 if (!this.vecDefaultVariableValue 4594 .get(k).toString() 4595 .equalsIgnoreCase("")) { 4596 // if 4597 // (!CheckType.isNumber(this.vecVariableColumnTypes.get(i). 4598 // toString())) 4599 // ZK change this from CheckType to 4600 // configReaderTarget this 7.5.2004 4601 4602 if (!configReaderTarget 4603 .isNumber(this.vecVariableColumnTypes 4604 .get(i).toString())) 4605 4606 strQueryInsertName += " '" 4607 + this.vecDefaultVariableValue 4608 .get(k) 4609 .toString() 4610 + "' " + oidVersion 4611 + " where " 4612 + strQueryWhereSQL; 4613 else 4614 strQueryInsertName += " " 4615 + this.vecDefaultVariableValue 4616 .get(k) + " " 4617 + oidVersion 4618 + " where " 4619 + strQueryWhereSQL; 4620 4621 } else { 4622 strQueryInsertName += " null" 4623 + oidVersion + " where " 4624 + strQueryWhereSQL; 4625 } 4626 break; 4627 } 4628 } 4629 } else { 4630 // ZK change this from CheckType to 4631 // configReaderTarget this 7.5.2004 4632 if (!configReaderTarget 4633 .isNumber(this.vecVariableColumnTypes 4634 .get(i).toString())) 4635 strQueryInsertName += " '" 4636 + this.vecVariableValue.get( 4637 iPositionInVector) 4638 .toString() + "'" 4639 + oidVersion + " where " 4640 + strQueryWhereSQL; 4641 else 4642 strQueryInsertName += this.vecVariableValue 4643 .get(iPositionInVector).toString() 4644 + oidVersion 4645 + " where " 4646 + strQueryWhereSQL; 4647 } 4648 } else if (this.vecVariableColumnValueMode.get(i) 4649 .toString().equalsIgnoreCase("SetNull")) { 4650 if (this.vecVariableValue.get(iPositionInVector) == null) 4651 strQueryInsertName += " null" + oidVersion 4652 + " where " + strQueryWhereSQL; 4653 else 4654 bInsert = false; 4655 } else { 4656 if (this.vecVariableValue.get(iPositionInVector) == null) { 4657 String variableName = this.vecVariableColumnName 4658 .get(i).toString(); 4659 for (int k = 0; k < this.vecDefaultVariableName 4660 .size(); k++) { 4661 if (this.vecDefaultVariableName.get(k) 4662 .toString().equalsIgnoreCase( 4663 variableName)) { 4664 if (!this.vecDefaultVariableValue 4665 .get(k).toString() 4666 .equalsIgnoreCase("")) { 4667 // ZK change this from CheckType to 4668 // configReaderTarget this 7.5.2004 4669 if (!configReaderTarget 4670 .isNumber(this.vecVariableColumnTypes 4671 .get(i).toString())) 4672 strQueryInsertName += " '" 4673 + this.vecDefaultVariableValue 4674 .get(k) 4675 .toString() 4676 + "' " 4677 + oidVersion 4678 + " where " 4679 + this.vecVariableColumnTargetColumnName 4680 .get(i) 4681 .toString() 4682 + " is null and " 4683 + strQueryWhereSQL; 4684 else 4685 strQueryInsertName += " " 4686 + this.vecDefaultVariableValue 4687 .get(k) 4688 + " " 4689 + oidVersion 4690 + " where " 4691 + this.vecVariableColumnTargetColumnName 4692 .get(i) 4693 .toString() 4694 + " is null and " 4695 + strQueryWhereSQL; 4696 } else { 4697 strQueryInsertName += " null" 4698 + oidVersion 4699 + " where " 4700 + this.vecVariableColumnTargetColumnName 4701 .get(i).toString() 4702 + " is null and " 4703 + strQueryWhereSQL; 4704 } 4705 break; 4706 } 4707 } 4708 } else { 4709 // ZK change this from CheckType to 4710 // configReaderTarget this 7.5.2004 4711 if (!configReaderTarget 4712 .isNumber(this.vecVariableColumnTypes 4713 .get(i).toString())) 4714 strQueryInsertName += " '" 4715 + this.vecVariableValue.get( 4716 iPositionInVector) 4717 .toString() 4718 + "'" 4719 + oidVersion 4720 + " where " 4721 + this.vecVariableColumnTargetColumnName 4722 .get(i).toString() 4723 + " is null and " 4724 + strQueryWhereSQL; 4725 else 4726 strQueryInsertName += this.vecVariableValue 4727 .get(iPositionInVector).toString() 4728 + oidVersion 4729 + " where " 4730 + this.vecVariableColumnTargetColumnName 4731 .get(i).toString() 4732 + " is null and " 4733 + strQueryWhereSQL; 4734 } 4735 } 4736 if (bInsert) 4737 this.logger 4738 .write("full", "\tQuery '" 4739 + strQueryInsertName 4740 + "' will be executed"); 4741 4742 if (bReplaceInData) { 4743 strQueryInsertName = this 4744 .replaceInData(strQueryInsertName); 4745 } 4746 if (bInsert) { 4747 int num = 0; 4748 try { 4749 num = stmtRelations 4750 .executeUpdate(strQueryInsertName); 4751 } catch (SQLException ex) { 4752 stmtRelations.close(); 4753 stmtRelations = c.createStatement(); 4754 if ((importDefinitionElement.strDefaultCutOffData 4755 .equalsIgnoreCase("true"))) { 4756 dataCleaning 4757 .cutingDataLenghtUpdate( 4758 this.vecTableTableName.get( 4759 iTable).toString(), 4760 c, 4761 "", 4762 currentRow, 4763 strQueryInsertName, 4764 importDefinitionElement.strOnErrorContinueXml, 4765 importDefinitionElement.strImportDefinitionName, 4766 strQueryInsertName); 4767 } else 4768 throw ex; 4769 } 4770 } 4771 // stmtRelations.close(); 4772 } else { 4773 this.logger.write("normal", 4774 "\tError: Cannot find value for variable column :" 4775 + this.vecVariableColumnName.get(i) 4776 .toString()); 4777 LoaderException le = new LoaderException( 4778 "Exception: ", 4779 (Throwable) (new Exception( 4780 "Error: Cannot find value for variable column :"))); 4781 this.logger.write("full", le.getStackTraceAsString()); 4782 throw le; 4783 } 4784 } 4785 } 4786 } catch (SQLException ex) { 4787 throw ex; 4788 } catch (NullPointerException ex) { 4789 throw ex; 4790 } 4791 this.logger.write("full", "\tupdateNameValue method is finished."); 4792 return bWriteData; 4793 } 4794 4795 /*** 4796 * Method queryRelations is used to make SQL query for reading source value 4797 * for relations between target tables. It puts the value from the source 4798 * column in source relation table to the target column in target relation 4799 * table. If there is an error, Exception "SQLException" or 4800 * NullPointerException is thrown. 4801 * 4802 * @param iTableInt 4803 * Number of target table. 4804 * @param iNumberOfRelationColumn 4805 * Number of relation tag. 4806 * @param strQueryWhere 4807 * Part of SQL query - where clause. 4808 * @param conn 4809 * represents connection to target database 4810 * @param currentVersion 4811 * represents currnet version of insert/update 4812 * @param oid 4813 * define if oid logic is present 4814 * @return String which will be executed for update or insert relation 4815 * columns into target tables 4816 * @throws NullPointerException 4817 * Constructs a NullPointerException with the specified detail 4818 * message. 4819 * @throws LoaderException 4820 */ 4821 private String queryRelations(int iTableInt, int iNumberOfRelationColumn, 4822 String strQueryWhere, Connection conn, int currentVersion, 4823 boolean oid) throws NullPointerException, LoaderException { 4824 this.logger.write("full", "\tqueryRelations method is started."); 4825 String strQueryRelations = ""; 4826 String oidVersion = ""; 4827 String selectValueInRel = ""; 4828 String currentValueInRel = ""; 4829 // if (oid) 4830 // oidVersion = ", version=" + currentVersion; 4831 if (oid) 4832 oidVersion = ", " + this.currentVersionColumnName + "=" 4833 + currentVersion; 4834 4835 try { 4836 strQueryRelations = "update " 4837 + this.vecRelationColumnTargetTableName.get( 4838 iNumberOfRelationColumn).toString() 4839 + " set " 4840 + this.vecRelationColumnTargetColumnName.get( 4841 iNumberOfRelationColumn).toString(); 4842 if (this.vecRelationSourceValue.get(iNumberOfRelationColumn) == null) { 4843 String replacementValueInRel = vecDefaultRelationValue.get( 4844 iNumberOfRelationColumn).toString(); 4845 if (!replacementValueInRel.equalsIgnoreCase("")) { 4846 try { 4847 Statement stmt = conn.createStatement(); 4848 ResultSet newRelationValue; 4849 String relationValue; 4850 boolean isFull = false; 4851 if (!replacementValueInRel 4852 .equalsIgnoreCase(selectValueInRel)) { 4853 selectValueInRel = replacementValueInRel; 4854 newRelationValue = stmt 4855 .executeQuery(replacementValueInRel); 4856 isFull = newRelationValue.next(); 4857 if (isFull) { 4858 relationValue = newRelationValue.getString(1); 4859 currentValueInRel = relationValue; 4860 } else { 4861 relationValue = ""; 4862 currentValueInRel = ""; 4863 } 4864 newRelationValue.close(); 4865 } else { 4866 if (!currentValueInRel.equalsIgnoreCase("") 4867 && currentValueInRel != null) { 4868 relationValue = currentValueInRel; 4869 isFull = true; 4870 } else { 4871 relationValue = ""; 4872 } 4873 } 4874 if (isFull) { 4875 strQueryRelations += dataCleaning 4876 .cleaningRelationValues( 4877 this.vecTableTableName.get( 4878 iTableInt).toString(), 4879 this.vecRelationColumnTargetColumnName 4880 .get( 4881 iNumberOfRelationColumn) 4882 .toString(), 4883 relationValue, 4884 this.vecRelationSourceType.get( 4885 iNumberOfRelationColumn) 4886 .toString(), 4887 currentRow, 4888 conn, 4889 "UPDATE", 4890 currentVersion, 4891 oid, 4892 importDefinitionElement.strImportDefinitionName, 4893 this.currentVersionColumnName, 4894 replacementValueInRel); 4895 4896 } else { 4897 dataCleaning 4898 .cleaningInsert( 4899 this.vecTableTableName.get( 4900 iTableInt).toString(), 4901 conn, 4902 currentRow, 4903 "UPDATE", 4904 "Default value '" 4905 + replacementValueInRel 4906 + "' for relations is not valid.", 4907 importDefinitionElement.strImportDefinitionName, 4908 replacementValueInRel); 4909 strQueryRelations += " = null " + oidVersion 4910 + " where "; 4911 } 4912 } catch (SQLException ex) { 4913 String msg = "Default value for foreign key(" 4914 + replacementValueInRel 4915 + ") is not valid. Import definition name: " 4916 + importDefinitionElement.strImportDefinitionName; 4917 LoaderException le = new LoaderException( 4918 "SQLException: " + msg, (Throwable) ex); 4919 this.logger.write("full", le.getStackTraceAsString()); 4920 throw le; 4921 } 4922 4923 } else 4924 strQueryRelations += " = null " + oidVersion + " where "; 4925 } else { 4926 // TODO Check this part of code. ZK change from 4927 // configReaderSource to configReaderTarget because of problems 4928 // with relation columns. 4929 if (configReaderTarget.isNumber(this.vecRelationSourceType.get( 4930 iNumberOfRelationColumn).toString())) { 4931 strQueryRelations += " = " 4932 + this.vecRelationSourceValue.get( 4933 iNumberOfRelationColumn).toString() 4934 + oidVersion + " where "; 4935 } else { 4936 strQueryRelations += " = "; 4937 if (configReaderTarget.isWithN(this.vecRelationSourceType 4938 .get(iNumberOfRelationColumn).toString())) { 4939 strQueryRelations += "N"; 4940 } 4941 strQueryRelations += "'" 4942 + this.vecRelationSourceValue.get( 4943 iNumberOfRelationColumn).toString() + "'" 4944 + oidVersion + " where "; 4945 } 4946 4947 } 4948 strQueryRelations += strQueryWhere; 4949 if (strQueryRelations.trim().endsWith("where")) 4950 strQueryRelations = strQueryRelations.substring(0, 4951 strQueryRelations.length() - 6); 4952 else { 4953 if (!this.vecRelationColumnRelationMode.get( 4954 iNumberOfRelationColumn).toString().equalsIgnoreCase( 4955 "overwrite")) { 4956 // || 4957 // !this.vecRelationColumnRelationMode.get(iNumberOfRelationColumn).toString(). 4958 // equalsIgnoreCase("SetIfCreated")) { 4959 4960 strQueryRelations += " and " 4961 + this.vecRelationColumnTargetColumnName.get( 4962 iNumberOfRelationColumn).toString() 4963 + " is null"; 4964 } 4965 } 4966 } catch (NullPointerException ex) { 4967 throw ex; 4968 } 4969 this.logger.write("full", "\tqueryRelations method is finished."); 4970 return strQueryRelations; 4971 } 4972 4973 /*** 4974 * Method insertTargetTable is used to put one row of data from columns of 4975 * source tables into target table ordered by column modes. If there is an 4976 * error, Exception "SQLException, "NullPointerException" or "Exception" is 4977 * thrown. 4978 * 4979 * @param iTableInt 4980 * Number of the target table which is processed. 4981 * @param vecColumnValues 4982 * One row of values from the source table. 4983 * @param vecColumnNames 4984 * Vector of column names in a target table. 4985 * @param vecColumnMode 4986 * Modes of columns in the target table. 4987 * @param vecColumnTypes 4988 * Types of columns in the target table. 4989 * @param c 4990 * Connection to the target database. 4991 * @throws SQLException 4992 * Constructs an SQLException object with a reason. 4993 * @throws NullPointerException 4994 * Constructs a NullPointerException with the specified detail 4995 * message. 4996 * @throws Exception 4997 * Constructs an Exception with the specified detail message. 4998 */ 4999 private void insertTargetTable(int iTableInt, Vector vecColumnValues, 5000 Vector vecColumnNames, Vector vecColumnMode, Vector vecColumnTypes, 5001 Connection c, Vector vecTransformationValue, 5002 Vector transTargetColumnTypes) throws SQLException, 5003 NullPointerException, Exception { 5004 5005 this.logger.write("full", "\tinsertTargetTable method is started."); 5006 boolean bInsertTable = false; 5007 int iVersionValue = 0; 5008 int iVersionMax = 0; 5009 boolean bWriteData = false; 5010 String strQueryWhere = ""; 5011 String strQuery = new String("select "); 5012 // for handling exception in FK (data cleanining) 5013 String exceptionInRelations = ""; 5014 String replacementValueInRel = ""; 5015 String replacementTable = ""; 5016 String replacementColumn = ""; 5017 // String replacementColumnType = ""; 5018 boolean relationIsOk = false; 5019 boolean updateQueryIsOk = false; 5020 boolean updateConstantIsOk = false; 5021 String strQueryConstantApendix = ""; 5022 5023 boolean bOidLogicCurrentTable = new Boolean(this.vecTableOidLogic.get( 5024 iTableInt).toString()).booleanValue(); 5025 boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName 5026 .equals("") || importDefinitionElement.strObjectIDNameColumnValue 5027 .equals("")); 5028 boolean oid = false; 5029 if (bOidLogicCurrentTable && !isTOS) 5030 oid = true; 5031 5032 Vector vecTempKeyColumns = (Vector) this.vecTargetKeyColumnName 5033 .get(iTableInt); 5034 5035 String key = String.valueOf(iTableInt); 5036 String query = (String) queryStatement.get(key); 5037 // System.out.println("query="+query); 5038 String update = (String) updateStatement.get(key); 5039 String updateConstant = (String) updateConstantStatement.get(key); 5040 5041 String updateTransformation = (String) updateTransformationStatement 5042 .get(key); 5043 5044 // updateTransformation = 5045 // (String)this.updateTransformationStatement.get(key); 5046 Statement stmtTarget = null; 5047 // ZK added this. If (select something from ... )is valid (contains oid, 5048 // version and more) then do insert 5049 // String query1 = (String)queryStatement.get(key); 5050 // System.out.println("query="+query); 5051 // boolean isValidStmt = validStmt.checkStatement(query); 5052 // System.out.println("isValidStmt="+isValidStmt); 5053 String logStatement = ""; 5054 try { 5055 // if (isValidStmt){ 5056 if (query.indexOf(" where ") == -1) { 5057 this.insertRow(c, vecColumnValues, vecColumnTypes, 5058 vecColumnNames, vecColumnMode, bOidLogicCurrentTable, 5059 iTableInt, vecTransformationValue, 5060 transTargetColumnTypes); 5061 bInsertTable = true; 5062 } else { 5063 Vector dv = (Vector) indexDValue.get(key); 5064 Vector drv = (Vector) indexDRelationValue.get(key); 5065 Vector dcv = (Vector) indexConstantDValue.get(key); 5066 Vector dvv = (Vector) indexDVariableValue.get(key); 5067 Vector dtv = (Vector) indexDTransformationValue.get(key); 5068 5069 if (dv.size() > 0) { 5070 for (int i = 0; i < dv.size(); i++) { 5071 int index = Integer.parseInt(dv.get(i).toString()); 5072 if (vecColumnValues.get(index) == null) { 5073 int str = query.indexOf("'dummyValue'"); 5074 int num = query.indexOf("dummyValue"); 5075 if (str != -1 && (num == -1 || str < num)) 5076 query = replaceFirst(query, "= 'dummyValue'", 5077 " is null "); 5078 else 5079 query = replaceFirst(query, "= dummyValue", 5080 " is null "); 5081 } else { 5082 query = replaceFirst(query, "dummyValue", 5083 vecColumnValues.get(index).toString()); 5084 } 5085 } 5086 } 5087 if (drv.size() > 0) { 5088 for (int i = 0; i < drv.size(); i++) { 5089 int index = Integer.parseInt(drv.get(i).toString()); 5090 int str = query.indexOf("'dummyRelationValue'"); 5091 int num = query.indexOf("dummyRelationValue"); 5092 if ((this.vecRelationSourceValue.get(index) == null) || 5093 (this.vecRelationSourceValue.get(index).toString() == "null")) { 5094 // int str = query.indexOf("'dummyRelationValue'"); 5095 // int num = query.indexOf("dummyRelationValue"); 5096 if (str != -1 && (num == -1 || str < num)) 5097 query = replaceFirst(query, 5098 "= 'dummyRelationValue'", " is null "); 5099 else 5100 query = replaceFirst(query, 5101 "= dummyRelationValue", " is null "); 5102 } else { 5103 //query = replaceFirst(query, "dummyRelationValue", 5104 // this.vecRelationSourceValue.get(index) 5105 // .toString()); 5106 // senka change 5107 String relValues=this.vecRelationSourceValue.get(index).toString(); 5108 if (relValues.startsWith(" IN")) { 5109 if (str != -1 && (num == -1 || str < num)) 5110 query = replaceFirst(query, "= 'dummyRelationValue'",relValues); 5111 else 5112 query = replaceFirst(query, "= dummyRelationValue",relValues); 5113 }else{ 5114 query = replaceFirst(query, "dummyRelationValue",relValues); 5115 } 5116 } 5117 } 5118 } 5119 5120 Vector vecTempConstantColumns = (Vector) this.vecConstantTargetColumnName 5121 .get(iTableInt); 5122 Vector vecTempConstantValues = (Vector) this.vecConstantConstantValue 5123 .get(iTableInt); 5124 Vector vecTempConstantMode = (Vector) this.vecConstantValueMode 5125 .get(iTableInt); 5126 Vector vecTempConstantType = (Vector) this.vecConstantColumnType 5127 .get(iTableInt); 5128 // ZK added 19.4.2004 5129 5130 // Vector vecTempTransformationValues = (Vector) 5131 // vecTransformationValue.get(iTableInt); 5132 5133 if (dcv.size() > 0) { 5134 for (int i = 0; i < dcv.size(); i++) { 5135 int index = Integer.parseInt(dcv.get(i).toString()); 5136 if (vecTempConstantValues.get(index) == null) { 5137 int str = query.indexOf("'dummyConstantValue'"); 5138 int num = query.indexOf("dummyConstantValue"); 5139 if (str != -1 && (num == -1 || str < num)) 5140 query = replaceFirst(query, 5141 "= 'dummyConstantValue'", " is null "); 5142 else 5143 query = replaceFirst(query, 5144 "= dummyConstantValue", " is null "); 5145 } else { 5146 query = replaceFirst(query, "dummyConstantValue", 5147 vecTempConstantValues.get(index).toString()); 5148 } 5149 } 5150 } 5151 5152 if (dvv.size() > 0) { 5153 for (int i = 0; i < dvv.size(); i++) { 5154 int index = Integer.parseInt(dvv.get(i).toString()); 5155 if (vecVariableValue.get(index) == null) { 5156 int str = query.indexOf("'dummyVariableValue'"); 5157 int num = query.indexOf("dummyVariableValue"); 5158 if (str != -1 && (num == -1 || str < num)) 5159 query = replaceFirst(query, 5160 "= 'dummyVariableValue'", " is null "); 5161 else 5162 query = replaceFirst(query, 5163 "= dummyVariableValue", " is null "); 5164 } else { 5165 query = replaceFirst(query, "dummyVariableValue", 5166 vecVariableValue.get(index).toString()); 5167 } 5168 } 5169 } 5170 // ZK added this for transformation. Key colona. 5171 if (dtv.size() > 0) { 5172 for (int i = 0; i < dtv.size(); i++) { 5173 int index = Integer.parseInt(dtv.get(i).toString()); 5174 if (vecTransformationValue.get(index) == null) { 5175 int str = query 5176 .indexOf("'dummyTransformationValue'"); 5177 int num = query.indexOf("dummyTransformationValue"); 5178 if (str != -1 && (num == -1 || str < num)) 5179 query = replaceFirst(query, 5180 "= 'dummyTransformationValue'", 5181 " is null "); 5182 else 5183 query = replaceFirst(query, 5184 "= dummyTransformationValue", 5185 " is null "); 5186 } else { 5187 query = replaceFirst(query, 5188 "dummyTransformationValue", 5189 vecTransformationValue.get(index) 5190 .toString()); 5191 } 5192 } 5193 } 5194 // ZK end 5195 if (query.indexOf("where") != -1) 5196 strQueryWhere = query.substring(query.indexOf("where") + 5); 5197 5198 stmtTarget = c.createStatement(); 5199 boolean rowExist; 5200 if (bOidLogicCurrentTable && !isTOS) 5201 rowExist = this.checkRowCache.getCheckRowValue(query, c, 5202 this.iTargetFirstColumnResult, 5203 this.currentVersionColumnName); 5204 else 5205 rowExist = this.checkRowCache.getCheckRowValue(query, c, 5206 this.iTargetFirstColumnResult, null); 5207 5208 if (!rowExist) { 5209 this.insertRow(c, vecColumnValues, vecColumnTypes, 5210 vecColumnNames, vecColumnMode, 5211 bOidLogicCurrentTable, iTableInt, 5212 vecTransformationValue, transTargetColumnTypes); 5213 bInsertTable = true; 5214 } else { // row exist = true 5215 if (bOidLogicCurrentTable && !isTOS) { 5216 iVersionValue = this.checkRowCache 5217 .getCheckRowVersionValue(); 5218 if (iVersionValue > iVersionMax) 5219 iVersionMax = iVersionValue; 5220 } 5221 if (!bInsertTable) { 5222 Vector dOverwrite = (Vector) indexDOverwrite.get(key); 5223 Vector dSetNull = (Vector) indexDSetNull.get(key); 5224 5225 if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere) 5226 .indexOf("UPDATE") != -1)) { 5227 if (dOverwrite.size() > 0) { 5228 int start = 0; 5229 for (int i = 0; i < dOverwrite.size(); i++) { 5230 Vector replacedValue = (Vector) vecDefaultValue 5231 .get(iTableInt); 5232 int index = Integer.parseInt(dOverwrite 5233 .get(i).toString()); 5234 if (vecColumnValues.get(index) == null) { 5235 int str = update 5236 .indexOf("'dummyOverwrite'"); 5237 int num = update 5238 .indexOf("dummyOverwrite"); 5239 if (replacedValue.get(index) != "") { 5240 if (str != -1 5241 && (num == -1 || str < num)) 5242 update = replaceFirst( 5243 update, 5244 "'dummyOverwrite'", 5245 " '" 5246 + replacedValue 5247 .get( 5248 index) 5249 .toString() 5250 + "' "); 5251 else 5252 update = replaceFirst( 5253 update, 5254 "dummyOverwrite", 5255 " " 5256 + replacedValue 5257 .get( 5258 index) 5259 .toString() 5260 + " "); 5261 5262 dataCleaning 5263 .cleaningColumnValues( 5264 this.vecTableTableName 5265 .get( 5266 iTableInt) 5267 .toString(), 5268 vecColumnNames.get( 5269 index) 5270 .toString(), 5271 replacedValue.get( 5272 index) 5273 .toString(), 5274 currentRow, 5275 c, 5276 "UPDATE", 5277 importDefinitionElement.strImportDefinitionName); 5278 } else { 5279 if (str != -1 5280 && (num == -1 || str < num)) { 5281 String forReplace = "'dummyOverwrite'"; 5282 // patch from mail list 5283 // int thisIndex = 5284 // update.indexOf("N'dummyOverwrite'"); 5285 // if (thisIndex != -1 && 5286 // thisIndex < str) 5287 if (update 5288 .indexOf("N'dummyOverwrite'") != -1) 5289 forReplace = "N'dummyOverwrite'"; 5290 update = replaceFirst(update, 5291 forReplace, " null "); 5292 } else { 5293 update = replaceFirst(update, 5294 "dummyOverwrite", 5295 " null "); 5296 } 5297 } 5298 } else { 5299 String replacement = vecColumnValues 5300 .get(index).toString(); 5301 start = update.indexOf( 5302 "dummyOverwrite", start); 5303 update = update.substring(0, start) 5304 + replacement 5305 + update.substring(start + 14); 5306 start = replacement.length(); 5307 } 5308 } 5309 } 5310 if (dSetNull.size() > 0) { 5311 for (int j = 0; j < dSetNull.size(); j++) { 5312 int index = Integer.parseInt(dSetNull 5313 .get(j).toString()); 5314 if (vecColumnValues.get(index) == null) { 5315 update = replaceFirst(update, 5316 "dummySetNull", vecColumnNames 5317 .get(index).toString() 5318 + "=" + " null "); 5319 } else { 5320 update = replaceFirst(update, 5321 "dummySetNull,", ""); 5322 } 5323 } 5324 } 5325 if (dOverwrite.size() > 0 || dSetNull.size() > 0) { 5326 if (bWriteData) 5327 update = replaceFirst(update, 5328 "dummyVersionOverwrite", String 5329 .valueOf(iVersionMax)); 5330 else 5331 update = replaceFirst(update, 5332 "dummyVersionOverwrite", String 5333 .valueOf(iVersionMax + 1)); 5334 if (bReplaceInData) { 5335 update = this.replaceInData(update); 5336 strQueryWhere = this 5337 .replaceInData(strQueryWhere); 5338 } 5339 relationIsOk = true; 5340 updateConstantIsOk = true; 5341 updateQueryIsOk = false; 5342 int iNumRowUp = 0; 5343 // int ver = update.indexOf("version"); 5344 int ver = update 5345 .indexOf(this.currentVersionColumnName); 5346 int equals = update.indexOf("="); 5347 try { 5348 if (equals != ver + 8) { // update set 5349 // version=1 5350 // where x=x 5351 this.logger.write("full", "\tQuery '" 5352 + update + strQueryWhere 5353 + "' will be executed"); 5354 logStatement = update + strQueryWhere; 5355 iNumRowUp = stmtTarget 5356 .executeUpdate(update 5357 + strQueryWhere); 5358 } 5359 if (iNumRowUp != 0) { 5360 if (!bWriteData) 5361 iVersionMax = iVersionMax + 1; 5362 bWriteData = true; 5363 } 5364 String tableName = this.vecTableTableName 5365 .get(iTableInt).toString(); 5366 for (int i = 0; i < this.vecBlobVector 5367 .size(); i = i + 5) { 5368 if (!this.vecBlobVector.get(i + 3) 5369 .toString().equalsIgnoreCase( 5370 "update")) { 5371 String version = ""; 5372 if (oid) { 5373 if (bWriteData) { 5374 // version += ", version = " 5375 // + iVersionMax; 5376 version += ", " 5377 + this.currentVersionColumnName 5378 + " = " 5379 + iVersionMax; 5380 } else { 5381 // version += ", version = " 5382 // + (iVersionMax + 1); 5383 version += ", " 5384 + this.currentVersionColumnName 5385 + "= " 5386 + (iVersionMax + 1); 5387 } 5388 } 5389 String columnName = this.vecBlobVector 5390 .get(i).toString(); 5391 byte[] isBlob = (byte[]) this.vecBlobVector 5392 .get(i + 1); 5393 if (isBlob != null) { 5394 ByteArrayInputStream bais = new ByteArrayInputStream( 5395 isBlob); 5396 logStatement = "update " 5397 + tableName + " set " 5398 + columnName + "=(?)" 5399 + version + " where " 5400 + columnName 5401 + " is null"; 5402 PreparedStatement pstmt = c 5403 .prepareStatement("update " 5404 + tableName 5405 + " set " 5406 + columnName 5407 + "=(?)" 5408 + version 5409 + " where " 5410 + columnName 5411 + " is null"); 5412 pstmt.setBytes(1, isBlob); 5413 int intRowStmt = pstmt 5414 .executeUpdate(); 5415 pstmt.close(); 5416 if (intRowStmt != 0) { 5417 if (!bWriteData) 5418 iVersionMax = iVersionMax + 1; 5419 bWriteData = true; 5420 } 5421 } 5422 } 5423 } 5424 } catch (SQLException ex) { 5425 stmtTarget.close(); 5426 stmtTarget = c.createStatement(); 5427 5428 if ((importDefinitionElement.strDefaultCutOffData 5429 .equalsIgnoreCase("true"))) { 5430 dataCleaning 5431 .cutingDataLenghtUpdate( 5432 this.vecTableTableName 5433 .get(iTableInt) 5434 .toString(), 5435 c, 5436 strQueryWhere, 5437 currentRow, 5438 update, 5439 importDefinitionElement.strOnErrorContinueXml, 5440 importDefinitionElement.strImportDefinitionName, 5441 update + strQueryWhere); 5442 } else 5443 5444 throw ex; 5445 } 5446 } 5447 for (int j = 0; j < vecColumnNames.size(); j++) { 5448 if (vecColumnMode.get(j).toString() 5449 .equalsIgnoreCase("Update")) { 5450 // String javaType = 5451 // configReaderTarget.getJavaTypeMapings() 5452 // .get(vecColumnTypes.get(j).toString().toUpperCase()).toString(); 5453 // ZK change this 7.5.2004 from CheckType to 5454 // configReaderSource 5455 if (configReaderTarget 5456 .isBinaryObject(vecColumnTypes.get( 5457 j).toString())) { 5458 // int 5459 // javaTypeInt=Integer.parseInt(javaType); 5460 // if (javaTypeInt==1) { 5461 for (int i = 0; i < vecBlobVector 5462 .size(); i = i + 5) { 5463 if (vecBlobVector.get(i + 3) 5464 .toString() 5465 .equalsIgnoreCase("update")) { 5466 if (vecBlobVector 5467 .get(i) 5468 .toString() 5469 .equalsIgnoreCase( 5470 vecColumnNames 5471 .get(j) 5472 .toString())) { 5473 String version = ""; 5474 if (oid) { 5475 if (bWriteData) { 5476 // version += ", 5477 // version = " + 5478 // (iVersionMax); 5479 version += ", " 5480 + this.currentVersionColumnName 5481 + " = " 5482 + (iVersionMax); 5483 } else { 5484 // version += ", 5485 // version = " + 5486 // (iVersionMax + 5487 // 1); 5488 version += ", " 5489 + this.currentVersionColumnName 5490 + " = " 5491 + (iVersionMax + 1); 5492 } 5493 } 5494 String tableName = this.vecTableTableName 5495 .get(iTableInt) 5496 .toString(); 5497 String columnName = this.vecBlobVector 5498 .get(i).toString(); 5499 byte[] isBlob = (byte[]) this.vecBlobVector 5500 .get(i + 1); 5501 String condition = this.vecBlobVector 5502 .get(i + 2) 5503 .toString(); 5504 if (isBlob != null) { 5505 ByteArrayInputStream bais = new ByteArrayInputStream( 5506 isBlob); 5507 PreparedStatement pstmt = c 5508 .prepareStatement("update " 5509 + tableName 5510 + " set " 5511 + columnName 5512 + "=(?)" 5513 + version 5514 + condition 5515 + strQueryWhere); 5516 pstmt.setBytes(1, 5517 isBlob); 5518 this.logger 5519 .write( 5520 "full", 5521 "\tQuery '" 5522 + "update " 5523 + tableName 5524 + " set " 5525 + columnName 5526 + "=BlobObject" 5527 + version 5528 + condition 5529 + " where " 5530 + strQueryWhere 5531 + "' will be executed"); 5532 int intRowStmt = 0; 5533 logStatement = "update " 5534 + tableName 5535 + " set " 5536 + columnName 5537 + "=BlobObject" 5538 + version 5539 + condition 5540 + " where " 5541 + strQueryWhere; 5542 intRowStmt = pstmt 5543 .executeUpdate(); 5544 pstmt.close(); 5545 if (intRowStmt != 0) { 5546 if (!bWriteData) 5547 iVersionMax = iVersionMax + 1; 5548 bWriteData = true; 5549 } 5550 } 5551 } 5552 } 5553 } // for petlja za blob 5554 } else { 5555 String strQueryUpdate = "update " 5556 + this.vecTableTableName.get( 5557 iTableInt).toString() 5558 + " set "; 5559 strQueryUpdate += vecColumnNames.get(j) 5560 .toString() 5561 + "="; 5562 if (vecColumnValues.get(j) == null) 5563 strQueryUpdate += " null "; 5564 else { 5565 // ZK change this from CheckType to 5566 // configReaderTarget this 7.5.2004 5567 if (!configReaderTarget 5568 .isNumber(vecColumnTypes 5569 .get(j).toString())) 5570 strQueryUpdate += "'" 5571 + vecColumnValues 5572 .get(j) 5573 .toString() 5574 + "' "; 5575 else 5576 strQueryUpdate += vecColumnValues 5577 .get(j).toString() 5578 + " "; 5579 } 5580 if (oid) { 5581 if (bWriteData) { 5582 // strQueryUpdate += ", version 5583 // = " + (iVersionMax) + " where 5584 // "; 5585 strQueryUpdate += ", " 5586 + this.currentVersionColumnName 5587 + " = " + (iVersionMax) 5588 + " where "; 5589 } else { 5590 // strQueryUpdate += ", version 5591 // = " + (iVersionMax + 1) + " 5592 // where "; 5593 strQueryUpdate += ", " 5594 + this.currentVersionColumnName 5595 + " = " 5596 + (iVersionMax + 1) 5597 + " where "; 5598 } 5599 } else 5600 strQueryUpdate += " where "; 5601 strQueryUpdate += vecColumnNames.get(j) 5602 .toString() 5603 + " is null and "; 5604 if (bReplaceInData) { 5605 strQueryUpdate = this 5606 .replaceInData(strQueryUpdate); 5607 strQueryWhere = this 5608 .replaceInData(strQueryWhere); 5609 } 5610 this.logger.write("full", "\tQuery '" 5611 + strQueryUpdate 5612 + strQueryWhere 5613 + "' will be executed"); 5614 int iNumRow = 0; 5615 try { 5616 iNumRow = stmtTarget 5617 .executeUpdate(strQueryUpdate 5618 + strQueryWhere); 5619 } catch (SQLException ex) { 5620 stmtTarget.close(); 5621 stmtTarget = c.createStatement(); 5622 if ((importDefinitionElement.strDefaultCutOffData 5623 .equalsIgnoreCase("true"))) { 5624 dataCleaning 5625 .cutingDataLenghtUpdate( 5626 this.vecTableTableName 5627 .get( 5628 iTableInt) 5629 .toString(), 5630 c, 5631 strQueryWhere, 5632 currentRow, 5633 update, 5634 importDefinitionElement.strOnErrorContinueXml, 5635 importDefinitionElement.strImportDefinitionName, 5636 strQueryUpdate 5637 + strQueryWhere); 5638 } else 5639 throw ex; 5640 } 5641 if (iNumRow != 0) { 5642 if (!bWriteData) 5643 iVersionMax = iVersionMax + 1; 5644 bWriteData = true; 5645 } 5646 } 5647 } // end of main if loop 5648 } 5649 } 5650 for (int i = 0; i < this.iRelationColumns; i++) { 5651 outLoop: if (this.vecRelationColumnSourceTableName 5652 .get(i).toString().equalsIgnoreCase( 5653 this.vecTableTableName.get( 5654 iTableInt).toString()) 5655 && this.vecRelationColumnSourceTableID.get( 5656 i).toString().equalsIgnoreCase( 5657 this.vecTableTableID.get(iTableInt) 5658 .toString())) { 5659 for (int m = 0; m < this.vecVariableUseIDTableName 5660 .size(); m++) { 5661 if (this.vecRelationColumnSourceTableName 5662 .get(i) 5663 .toString() 5664 .equalsIgnoreCase( 5665 this.vecVariableUseIDTableName 5666 .get(m).toString()) 5667 && this.vecRelationColumnSourceTableID 5668 .get(i) 5669 .toString() 5670 .equalsIgnoreCase( 5671 this.vecVariableUseIDTableID 5672 .get(m) 5673 .toString())) { 5674 String strQueryRelations = "select " 5675 + this.vecRelationColumnSourceColumnName 5676 .get(i).toString() 5677 + " from " 5678 + this.vecRelationColumnSourceTableName 5679 .get(i).toString() 5680 + " where "; 5681 strQueryRelations += vecTempKeyColumns 5682 .get(0).toString() 5683 + " = "; 5684 // ZK change this from CheckType to 5685 // configReaderTarget this 7.5.2004 5686 if (!configReaderTarget 5687 .isNumber(vecColumnTypes.get(0) 5688 .toString())) 5689 strQueryRelations += "'" 5690 + this.strUserID + "'"; 5691 else 5692 strQueryRelations += this.strUserID; 5693 5694 if (this.vecTableTableMode.get( 5695 iTableInt).toString() 5696 .equalsIgnoreCase("cache")) { 5697 Object obj = relationsCache 5698 .getRelationsCacheValue(strQueryRelations); 5699 if (obj != null) { 5700 if (!obj.toString() 5701 .equalsIgnoreCase( 5702 "#$Together#$")) { 5703 this.vecRelationSourceValue 5704 .setElementAt(obj, 5705 i); 5706 String type = relationsCache 5707 .getRelationsCachType(strQueryRelations); 5708 this.vecRelationSourceType 5709 .setElementAt(type, 5710 i); 5711 } 5712 } else { 5713 Statement stmtForUserID1 = c 5714 .createStatement(); 5715 ResultSet rsForUserID1 = null; 5716 try { 5717 this.logger 5718 .write( 5719 "full", 5720 "\tQuery '" 5721 + strQueryRelations 5722 + "' will be executed"); 5723 rsForUserID1 = stmtForUserID1 5724 .executeQuery(strQueryRelations); 5725 } catch (SQLException ex) { 5726 rsForUserID1.close(); 5727 stmtForUserID1.close(); 5728 dataCleaning 5729 .cutingDataLenghtUpdate( 5730 this.vecTableTableName 5731 .get( 5732 iTableInt) 5733 .toString(), 5734 c, 5735 strQueryWhere, 5736 currentRow, 5737 update, 5738 importDefinitionElement.strOnErrorContinueXml, 5739 importDefinitionElement.strImportDefinitionName, 5740 strQueryRelations); 5741 } 5742 if (rsForUserID1.next()) { 5743 if (this.iTargetFirstColumnResult == 1) { 5744 this.vecRelationSourceValue 5745 .setElementAt( 5746 rsForUserID1 5747 .getObject(1), 5748 i); 5749 this.vecRelationSourceType 5750 .setElementAt( 5751 rsForUserID1 5752 .getMetaData() 5753 .getColumnTypeName( 5754 1), 5755 i); 5756 relationsCache 5757 .setRelationsCacheValue( 5758 strQueryRelations, 5759 rsForUserID1 5760 .getObject(1)); 5761 relationsCache 5762 .setRelationsCacheType( 5763 strQueryRelations, 5764 rsForUserID1 5765 .getMetaData() 5766 .getColumnTypeName( 5767 1)); 5768 } 5769 } else { 5770 relationsCache 5771 .setRelationsCacheValue( 5772 strQueryRelations, 5773 "#$Together#$"); 5774 relationsCache 5775 .setRelationsCacheType( 5776 strQueryRelations, 5777 "#$Together#$"); 5778 } 5779 rsForUserID1.close(); 5780 stmtForUserID1.close(); 5781 break outLoop; 5782 } 5783 } else { // tableMode=Query 5784 this.logger 5785 .write( 5786 "full", 5787 "\tQuery '" 5788 + strQueryRelations 5789 + "' will be executed"); 5790 Statement stmtForUserID2 = c 5791 .createStatement(); 5792 ResultSet rsForUserID2 = null; 5793 try { 5794 rsForUserID2 = stmtForUserID2 5795 .executeQuery(strQueryRelations); 5796 } catch (SQLException ex) { 5797 rsForUserID2.close(); 5798 stmtForUserID2.close(); 5799 dataCleaning 5800 .cutingDataLenghtUpdate( 5801 this.vecTableTableName 5802 .get( 5803 iTableInt) 5804 .toString(), 5805 c, 5806 strQueryWhere, 5807 currentRow, 5808 update, 5809 importDefinitionElement.strOnErrorContinueXml, 5810 importDefinitionElement.strImportDefinitionName, 5811 strQueryRelations); 5812 5813 } 5814 if (rsForUserID2.next()) { 5815 5816 if (this.iTargetFirstColumnResult == 1) { 5817 this.vecRelationSourceValue 5818 .setElementAt( 5819 rsForUserID2 5820 .getObject(1), 5821 i); 5822 this.vecRelationSourceType 5823 .setElementAt( 5824 rsForUserID2 5825 .getMetaData() 5826 .getColumnTypeName( 5827 1), 5828 i); 5829 5830 } else { 5831 this.vecRelationSourceValue 5832 .setElementAt( 5833 rsForUserID2 5834 .getObject(0), 5835 i); 5836 this.vecRelationSourceType 5837 .setElementAt( 5838 rsForUserID2 5839 .getMetaData() 5840 .getColumnTypeName( 5841 0), 5842 i); 5843 } 5844 } 5845 rsForUserID2.close(); 5846 stmtForUserID2.close(); 5847 break outLoop; 5848 } 5849 } 5850 } // end of vecVariableUseIDTableName loop 5851 String strQueryRelations = "select " 5852 + this.vecRelationColumnSourceColumnName 5853 .get(i).toString() 5854 + " from " 5855 + this.vecRelationColumnSourceTableName 5856 .get(i).toString() + " where " 5857 + strQueryWhere; 5858 if (this.vecTableTableMode.get(iTableInt) 5859 .toString().equalsIgnoreCase("cache")) { 5860 Object obj = relationsCache 5861 .getRelationsCacheValue(strQueryRelations); 5862 if (obj != null) { 5863 if (!obj.toString().equalsIgnoreCase( 5864 "#$Together#$")) { 5865 this.vecRelationSourceValue 5866 .setElementAt(obj, i); 5867 String type = relationsCache 5868 .getRelationsCachType(strQueryRelations); 5869 this.vecRelationSourceType 5870 .setElementAt(type, i); 5871 } 5872 } else { 5873 Statement stmtForRel1 = c 5874 .createStatement(); 5875 ResultSet rsForRel1 = null; 5876 try { 5877 this.logger 5878 .write( 5879 "full", 5880 "\tQuery '" 5881 + strQueryRelations 5882 + "' will be executed"); 5883 rsForRel1 = stmtForRel1 5884 .executeQuery(strQueryRelations); 5885 } catch (SQLException ex) { 5886 rsForRel1.close(); 5887 stmtForRel1.close(); 5888 dataCleaning 5889 .cutingDataLenghtUpdate( 5890 this.vecTableTableName 5891 .get( 5892 iTableInt) 5893 .toString(), 5894 c, 5895 strQueryWhere, 5896 currentRow, 5897 update, 5898 importDefinitionElement.strOnErrorContinueXml, 5899 importDefinitionElement.strImportDefinitionName, 5900 strQueryRelations); 5901 } 5902 5903 if (rsForRel1.next()) { 5904 String relVal=getSQLRelationString(rsForRel1); //senka added 5905 if (this.iTargetFirstColumnResult == 1) { 5906 // this.vecRelationSourceValue 5907 // .setElementAt(rsForRel1 5908 // .getObject(1), 5909 // i); 5910 // senka change 5911 this.vecRelationSourceValue 5912 .setElementAt(relVal, 5913 i); 5914 5915 this.vecRelationSourceType 5916 .setElementAt( 5917 rsForRel1 5918 .getMetaData() 5919 .getColumnTypeName( 5920 1), 5921 i); 5922 // relationsCache 5923 // .setRelationsCacheValue( 5924 // strQueryRelations, 5925 // rsForRel1 5926 // .getObject(1)); 5927 // senka change 5928 relationsCache 5929 .setRelationsCacheValue( 5930 strQueryRelations, 5931 relVal 5932 ); 5933 relationsCache 5934 .setRelationsCacheType( 5935 strQueryRelations, 5936 rsForRel1 5937 .getMetaData() 5938 .getColumnTypeName( 5939 1)); 5940 } else { 5941 // this.vecRelationSourceValue 5942 // .setElementAt(rsForRel1 5943 // .getObject(0), 5944 // i); 5945 // senka change 5946 this.vecRelationSourceValue 5947 .setElementAt(relVal, 5948 i); 5949 this.vecRelationSourceType 5950 .setElementAt( 5951 rsForRel1 5952 .getMetaData() 5953 .getColumnTypeName( 5954 0), 5955 i); 5956 // relationsCache 5957 // .setRelationsCacheValue( 5958 // strQueryRelations, 5959 // rsForRel1 5960 // .getObject(0)); 5961 // senka change 5962 relationsCache 5963 .setRelationsCacheValue( 5964 strQueryRelations, 5965 relVal 5966 ); 5967 relationsCache 5968 .setRelationsCacheType( 5969 strQueryRelations, 5970 rsForRel1 5971 .getMetaData() 5972 .getColumnTypeName( 5973 0)); 5974 } 5975 } else { 5976 relationsCache 5977 .setRelationsCacheValue( 5978 strQueryRelations, 5979 "#$Together#$"); 5980 relationsCache 5981 .setRelationsCacheType( 5982 strQueryRelations, 5983 "#$Together#$"); 5984 } 5985 rsForRel1.close(); 5986 stmtForRel1.close(); 5987 } 5988 } else { // tableMode=Query 5989 5990 Statement stmtForRel2 = c.createStatement(); 5991 ResultSet rsForRel2 = null; 5992 try { 5993 this.logger.write("full", "\tQuery '" 5994 + strQueryRelations 5995 + "' will be executed"); 5996 rsForRel2 = stmtForRel2 5997 .executeQuery(strQueryRelations); 5998 } catch (SQLException ex) { 5999 rsForRel2.close(); 6000 stmtForRel2.close(); 6001 dataCleaning 6002 .cutingDataLenghtUpdate( 6003 this.vecTableTableName 6004 .get(iTableInt) 6005 .toString(), 6006 c, 6007 strQueryWhere, 6008 currentRow, 6009 update, 6010 importDefinitionElement.strOnErrorContinueXml, 6011 importDefinitionElement.strImportDefinitionName, 6012 strQueryRelations); 6013 } 6014 if (rsForRel2.next()) { 6015 String relVal2=getSQLRelationString(rsForRel2); //senka added 6016 if (this.iTargetFirstColumnResult == 1) { 6017 // this.vecRelationSourceValue 6018 // .setElementAt(rsForRel2 6019 // .getObject(1), i); 6020 // senka 6021 this.vecRelationSourceValue 6022 .setElementAt(relVal2, i); 6023 this.vecRelationSourceType 6024 .setElementAt(rsForRel2 6025 .getMetaData() 6026 .getColumnTypeName( 6027 1), i); 6028 } else { 6029 //this.vecRelationSourceValue 6030 // .setElementAt(rsForRel2 6031 // .getObject(0), i); 6032 // senka 6033 this.vecRelationSourceValue 6034 .setElementAt(relVal2, i); 6035 this.vecRelationSourceType 6036 .setElementAt(rsForRel2 6037 .getMetaData() 6038 .getColumnTypeName( 6039 0), i); 6040 } 6041 } 6042 rsForRel2.close(); 6043 stmtForRel2.close(); 6044 } 6045 } 6046 } 6047 6048 for (int i = 0; i < this.vecRelationColumnTargetColumnName 6049 .size(); i++) { 6050 if (this.vecRelationColumnTargetTableName.get(i) 6051 .toString().equalsIgnoreCase( 6052 this.vecTableTableName.get( 6053 iTableInt).toString()) 6054 && this.vecRelationColumnTargetTableID.get( 6055 i).toString().equalsIgnoreCase( 6056 this.vecTableTableID.get(iTableInt) 6057 .toString())) { 6058 int currentVersion = 0; 6059 if (bWriteData) 6060 currentVersion = iVersionMax; 6061 else 6062 currentVersion = iVersionMax + 1; 6063 6064 if (this.vecRelationColumnRelationMode.get(i) 6065 .toString().equalsIgnoreCase("SetNull")) { 6066 if (this.vecRelationSourceValue.get(i) == null) { 6067 String strUpdateRelations = this 6068 .queryRelations(iTableInt, i, 6069 strQueryWhere, c, 6070 currentVersion, oid); 6071 this.logger.write("full", "\tQuery '" 6072 + strUpdateRelations 6073 + "' will be executed"); 6074 if (bReplaceInData) { 6075 strUpdateRelations = this 6076 .replaceInData(strUpdateRelations); 6077 } 6078 int iNumRow = 0; 6079 logStatement = strUpdateRelations; 6080 iNumRow = stmtTarget 6081 .executeUpdate(strUpdateRelations); 6082 this.vecRelationSourceValue 6083 .setElementAt(null, i); 6084 // this.vecRelationSourceType.setElementAt(null,i); 6085 if (iNumRow != 0) { 6086 if (!bWriteData) 6087 iVersionMax = iVersionMax + 1; 6088 bWriteData = true; 6089 } 6090 } 6091 } else if (this.vecRelationColumnRelationMode 6092 .get(i).toString().equalsIgnoreCase( 6093 "Overwrite") 6094 || (this.vecRelationColumnRelationMode 6095 .get(i).toString() 6096 .equalsIgnoreCase("Update"))) { 6097 6098 // for handling exception in FK 6099 replacementValueInRel = vecDefaultRelationValue 6100 .get(i).toString(); 6101 replacementTable = vecRelationColumnTargetTableName 6102 .get(i).toString(); 6103 replacementColumn = vecRelationColumnTargetColumnName 6104 .get(i).toString(); 6105 // replacementColumnType = 6106 // this.vecRelationSourceType.get(i).toString(); 6107 String strUpdateRelations = this 6108 .queryRelations(iTableInt, i, 6109 strQueryWhere, c, 6110 currentVersion, oid); 6111 this.logger.write("full", "\tQuery '" 6112 + strUpdateRelations 6113 + "' will be executed"); 6114 if (bReplaceInData) { 6115 strUpdateRelations = this 6116 .replaceInData(strUpdateRelations); 6117 } 6118 // only for catch exceptions in foreign keys 6119 // statement 6120 exceptionInRelations = strUpdateRelations; 6121 updateQueryIsOk = true; 6122 updateConstantIsOk = true; 6123 relationIsOk = false; 6124 int iNumRow = 0; 6125 try { 6126 logStatement = strUpdateRelations; 6127 iNumRow = stmtTarget 6128 .executeUpdate(strUpdateRelations); 6129 this.vecRelationSourceValue 6130 .setElementAt(null, i); 6131 // this.vecRelationSourceType.setElementAt(null,i); 6132 } catch (SQLException ex) { 6133 stmtTarget.close(); 6134 6135 stmtTarget = c.createStatement(); 6136 if ((importDefinitionElement.strDefaultCutOffData 6137 .equalsIgnoreCase("true"))) { 6138 dataCleaning 6139 .cutingDataLenghtUpdate( 6140 this.vecTableTableName 6141 .get( 6142 iTableInt) 6143 .toString(), 6144 c, 6145 strQueryWhere, 6146 currentRow, 6147 update, 6148 importDefinitionElement.strOnErrorContinueXml, 6149 importDefinitionElement.strImportDefinitionName, 6150 strUpdateRelations); 6151 } else 6152 throw ex; 6153 } 6154 if (iNumRow != 0) { 6155 if (!bWriteData) 6156 iVersionMax = iVersionMax + 1; 6157 bWriteData = true; 6158 } 6159 } 6160 } 6161 } 6162 6163 if (this.vecTableInsert.get(iTableInt).toString() 6164 .equalsIgnoreCase("true")) { 6165 if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere) 6166 .indexOf("UPDATE") != -1)) { 6167 if (vecTempConstantColumns.size() > 0) { 6168 if (updateConstant.indexOf(",") != -1) 6169 updateConstant = updateConstant 6170 .substring(0, updateConstant 6171 .lastIndexOf(",")); 6172 6173 Vector cOverwrite = (Vector) indexDConstantOver 6174 .get(key); 6175 Vector cNull = (Vector) indexDConstantNull 6176 .get(key); 6177 strQueryConstantApendix = ""; 6178 if (cOverwrite.size() > 0) { 6179 int startOver = 0; 6180 for (int i = 0; i < cOverwrite.size(); i++) { 6181 int index = Integer 6182 .parseInt(cOverwrite.get(i) 6183 .toString()); 6184 if (vecTempConstantValues 6185 .get(index) == null) { 6186 int str = updateConstant 6187 .indexOf("'dummyConstantOver'"); 6188 int num = updateConstant 6189 .indexOf("dummyConstantOver"); 6190 if (str != -1 6191 && (num == -1 || str < num)) 6192 updateConstant = replaceFirst( 6193 updateConstant, 6194 "'dummyConstantOver'", 6195 " null "); 6196 else 6197 updateConstant = replaceFirst( 6198 updateConstant, 6199 "dummyConstantOver", 6200 " null "); 6201 } else { 6202 String replacement = vecTempConstantValues 6203 .get(index).toString(); 6204 startOver = updateConstant 6205 .indexOf( 6206 "dummyConstantOver", 6207 startOver); 6208 updateConstant = updateConstant 6209 .substring(0, startOver) 6210 + replacement 6211 + updateConstant 6212 .substring(startOver + 17); 6213 startOver = replacement 6214 .length(); 6215 } 6216 } 6217 } 6218 if (cNull.size() > 0) { 6219 int startNull = 0; 6220 for (int i = 0; i < cNull.size(); i++) { 6221 int index = Integer.parseInt(cNull 6222 .get(i).toString()); 6223 if (vecTempConstantValues 6224 .get(index) == null) { 6225 int str = updateConstant 6226 .indexOf("'dummyConstantNull'"); 6227 int num = updateConstant 6228 .indexOf("dummyConstantNull"); 6229 if (str != -1 6230 && (num == -1 || str < num)) 6231 updateConstant = replaceFirst( 6232 updateConstant, 6233 "'dummyConstantNull'", 6234 " null "); 6235 else 6236 updateConstant = replaceFirst( 6237 updateConstant, 6238 "dummyConstantNull", 6239 " null "); 6240 6241 strQueryConstantApendix += " and " 6242 + vecTempConstantColumns 6243 .get(index) 6244 .toString() 6245 + " is null "; 6246 } else { 6247 String replacement = vecTempConstantValues 6248 .get(index).toString(); 6249 startNull = updateConstant 6250 .indexOf( 6251 "dummyConstantNull", 6252 startNull); 6253 updateConstant = updateConstant 6254 .substring(0, startNull) 6255 + replacement 6256 + updateConstant 6257 .substring(startNull + 17); 6258 startNull = replacement 6259 .length(); 6260 } 6261 } 6262 } 6263 6264 if (bReplaceInData) { 6265 // System.out.println("bReplaceInData: " 6266 // + bReplaceInData); 6267 updateConstant = this 6268 .replaceInData(updateConstant); 6269 strQueryWhere = this 6270 .replaceInData(strQueryWhere); 6271 } 6272 6273 if (oid) { 6274 if (bWriteData) { 6275 // updateConstant += ", version = " 6276 // + (iVersionMax); 6277 updateConstant += ", " 6278 + this.currentVersionColumnName 6279 + " = " + (iVersionMax); 6280 } else { 6281 // updateConstant += ", version = " 6282 // + (iVersionMax + 1); 6283 updateConstant += ", " 6284 + this.currentVersionColumnName 6285 + " = " + (iVersionMax + 1); 6286 } 6287 } 6288 updateQueryIsOk = true; 6289 relationIsOk = true; 6290 updateConstantIsOk = false; 6291 int iNumRow = 0; 6292 try { 6293 if (!updateConstant.endsWith(" set ")) { 6294 this.logger 6295 .write( 6296 "full", 6297 "\tQuery '" 6298 + updateConstant 6299 + " where " 6300 + strQueryWhere 6301 + strQueryConstantApendix 6302 + "' will be executed"); 6303 logStatement = updateConstant 6304 + " where " + strQueryWhere; 6305 iNumRow = stmtTarget 6306 .executeUpdate(updateConstant 6307 + " where " 6308 + strQueryWhere 6309 + strQueryConstantApendix); 6310 } 6311 } catch (SQLException ex) { 6312 stmtTarget.close(); 6313 6314 stmtTarget = c.createStatement(); 6315 if ((importDefinitionElement.strDefaultCutOffData 6316 .equalsIgnoreCase("true"))) { 6317 dataCleaning 6318 .cutingDataLenghtUpdate( 6319 this.vecTableTableName 6320 .get( 6321 iTableInt) 6322 .toString(), 6323 c, 6324 " where " 6325 + strQueryWhere 6326 + strQueryConstantApendix, 6327 currentRow, 6328 updateConstant, 6329 importDefinitionElement.strOnErrorContinueXml, 6330 importDefinitionElement.strImportDefinitionName, 6331 updateConstant 6332 + " where " 6333 + strQueryWhere 6334 + strQueryConstantApendix); 6335 } else 6336 throw ex; 6337 } 6338 if (iNumRow != 0) { 6339 if (!bWriteData) 6340 iVersionMax = iVersionMax + 1; 6341 bWriteData = true; 6342 } 6343 } 6344 if (this.vecVariableTimesTableName.size() != 0) { 6345 int currentVersion = 0; 6346 boolean bool = false; 6347 if (!bWriteData) 6348 currentVersion = iVersionMax + 1; 6349 else 6350 currentVersion = iVersionMax; 6351 bool = this.updateCurrentTime(c, iTableInt, 6352 strQueryWhere, currentVersion, oid); 6353 if (bool) { 6354 if (!bWriteData) 6355 iVersionMax = iVersionMax + 1; 6356 bWriteData = true; 6357 } 6358 } 6359 if (this.vecVariableColumnTargetTableName 6360 .size() != 0) { 6361 int currentVersion = 0; 6362 boolean bool = false; 6363 if (!bWriteData) 6364 currentVersion = iVersionMax + 1; 6365 else 6366 currentVersion = iVersionMax; 6367 try { 6368 bool = this.updateNameValue(c, 6369 iTableInt, strQueryWhere, 6370 currentVersion, oid); 6371 } catch (SQLException ex) { 6372 throw ex; 6373 } 6374 if (bool) { 6375 if (!bWriteData) 6376 iVersionMax = iVersionMax + 1; 6377 bWriteData = true; 6378 } 6379 } 6380 } 6381 } // insertTable=true 6382 // ZK added this 17.5.2004 6383 // System.out.println("iTableInt="+iTableInt); 6384 // System.out.println("update + strQueryWhere="+update + 6385 // strQueryWhere); 6386 6387 if (this.vecTableInsert.get(iTableInt).toString() 6388 .equalsIgnoreCase("true")) { 6389 if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere) 6390 .indexOf("UPDATE") != -1)) { 6391 6392 // if(((Vector)transformationsColumnNames.get(iTableInt)).size() 6393 // > 0){ 6394 6395 // System.out.println("updateTransformation = 6396 // "+updateTransformation); 6397 // System.out.println("transformedValues="+transformedValues); 6398 6399 Vector tOverwrite = (Vector) indexDTransformationOver 6400 .get(key); 6401 Vector tNull = (Vector) indexDTransformationNull 6402 .get(key); 6403 6404 if ((updateTransformation.indexOf(",") != -1)) 6405 updateTransformation = updateTransformation 6406 .substring(0, updateTransformation 6407 .lastIndexOf(",")); 6408 6409 if (tOverwrite.size() > 0) { 6410 int startOver = 0; 6411 for (int i = 0; i < tOverwrite.size(); i++) { 6412 int index = Integer.parseInt(tOverwrite 6413 .get(i).toString()); 6414 if (vecTransformationValue.get(index) == null) { 6415 6416 int str = updateTransformation 6417 .indexOf("'dummyTransformationOver'"); 6418 int num = updateTransformation 6419 .indexOf("dummyTransformationOver"); 6420 if (str != -1 6421 && (num == -1 || str < num)) 6422 updateTransformation = replaceFirst( 6423 updateTransformation, 6424 "'dummyTransformationOver'", 6425 " null "); 6426 else 6427 updateTransformation = replaceFirst( 6428 updateTransformation, 6429 "dummyTransformationOver", 6430 " null "); 6431 } else { 6432 String replacement = vecTransformationValue 6433 .get(index).toString(); 6434 startOver = updateTransformation 6435 .indexOf( 6436 "dummyTransformationOver", 6437 startOver); 6438 updateTransformation = updateTransformation 6439 .substring(0, startOver) 6440 + replacement 6441 + updateTransformation 6442 .substring(startOver + 23); 6443 startOver = replacement.length(); 6444 6445 } 6446 6447 } 6448 } 6449 6450 if (tNull.size() > 0) { 6451 int startNull = 0; 6452 for (int i = 0; i < tNull.size(); i++) { 6453 int index = Integer.parseInt(tNull.get( 6454 i).toString()); 6455 String colName = ((Vector) transformationsColumnNames 6456 .get(iTableInt)).get(index) 6457 .toString(); 6458 if (vecTransformationValue.get(index) == null) { 6459 updateTransformation = replaceFirst( 6460 updateTransformation, 6461 "dummyTransformationNull", 6462 colName + " = null "); 6463 } else { 6464 updateTransformation = replaceFirst( 6465 updateTransformation, 6466 "dummyTransformationNull,", 6467 " "); 6468 } 6469 } 6470 } 6471 6472 if ((tOverwrite.size() > 0) 6473 || (tNull.size() > 0)) { 6474 6475 if (bReplaceInData) { 6476 updateTransformation = this 6477 .replaceInData(updateTransformation); 6478 strQueryWhere = this 6479 .replaceInData(strQueryWhere); 6480 } 6481 6482 if (oid) { 6483 if (bWriteData) { 6484 updateTransformation += ", " 6485 + this.currentVersionColumnName 6486 + " = " + (iVersionMax); 6487 } else { 6488 updateTransformation += ", " 6489 + this.currentVersionColumnName 6490 + " = " + (iVersionMax + 1); 6491 } 6492 } 6493 6494 int iNumRow = 0; 6495 try { 6496 if (!updateTransformation 6497 .endsWith(" set ")) { 6498 this.logger 6499 .write( 6500 "full", 6501 "\tQuery '" 6502 + updateTransformation 6503 + " where " 6504 + strQueryWhere 6505 + "' will be executed"); 6506 logStatement = updateTransformation 6507 + " where " + strQueryWhere; 6508 iNumRow = stmtTarget 6509 .executeUpdate(updateTransformation 6510 + " where " 6511 + strQueryWhere); 6512 } 6513 } catch (SQLException ex) { 6514 stmtTarget.close(); 6515 throw ex; 6516 } 6517 6518 if (iNumRow != 0) { 6519 if (!bWriteData) 6520 iVersionMax = iVersionMax + 1; 6521 bWriteData = true; 6522 } 6523 6524 } 6525 6526 }// this is my 6527 }// END IF 6528 // ZK added 20.5 2004 for "Update" mode 6529 if (this.vecTableInsert.get(iTableInt).toString() 6530 .equalsIgnoreCase("true")) { 6531 if (((update + strQueryWhere).indexOf("update") != -1 || (update + strQueryWhere) 6532 .indexOf("UPDATE") != -1)) { 6533 6534 // if(((Vector)transformationsColumnNames.get(iTableInt)).size() 6535 // > 0){ 6536 Vector tUpdate = (Vector) indexDTransformationUpdate 6537 .get(key); 6538 if (tUpdate.size() > 0) { 6539 // int startUpdate = 0; 6540 for (int j = 0; j < tUpdate.size(); j++) { 6541 int index = Integer.parseInt(tUpdate 6542 .get(j).toString()); 6543 Vector tempTransValueModes = (Vector) transformationsValueModes 6544 .get(iTableInt); 6545 Vector tempTransColumnNames = (Vector) transformationsColumnNames 6546 .get(iTableInt); 6547 Vector tempTransColumnTypes = (Vector) transformationsColumnTypes 6548 .get(iTableInt); 6549 if (tempTransValueModes.get(index) 6550 .toString().equalsIgnoreCase( 6551 "Update")) { 6552 6553 String strQueryUpdate = "update " 6554 + this.vecTableTableName 6555 .get(iTableInt) 6556 .toString() 6557 + " set "; 6558 strQueryUpdate += tempTransColumnNames 6559 .get(index).toString() 6560 + "="; 6561 if (vecTransformationValue 6562 .get(index) == null) 6563 strQueryUpdate += " null "; 6564 else { 6565 6566 if (!configReaderTarget 6567 .isNumber(tempTransColumnTypes 6568 .get(index) 6569 .toString())) 6570 strQueryUpdate += "'" 6571 + vecTransformationValue 6572 .get(index) 6573 .toString() 6574 + "' "; 6575 else 6576 strQueryUpdate += vecTransformationValue 6577 .get(index) 6578 .toString() 6579 + " "; 6580 } 6581 if (oid) { 6582 if (bWriteData) { 6583 6584 strQueryUpdate += ", " 6585 + this.currentVersionColumnName 6586 + " = " 6587 + (iVersionMax) 6588 + " where "; 6589 } else { 6590 6591 strQueryUpdate += ", " 6592 + this.currentVersionColumnName 6593 + " = " 6594 + (iVersionMax + 1) 6595 + " where "; 6596 } 6597 } 6598 // strQueryUpdate += " where "; 6599 strQueryUpdate += tempTransColumnNames 6600 .get(j).toString() 6601 + " is null and "; 6602 6603 if (bReplaceInData) { 6604 strQueryUpdate = this 6605 .replaceInData(strQueryUpdate); 6606 strQueryWhere = this 6607 .replaceInData(strQueryWhere); 6608 } 6609 this.logger 6610 .write( 6611 "full", 6612 "\tQuery '" 6613 + strQueryUpdate 6614 + strQueryWhere 6615 + "' will be executed"); 6616 int iNumRow = 0; 6617 try { 6618 logStatement = strQueryUpdate 6619 + strQueryWhere; 6620 iNumRow = stmtTarget 6621 .executeUpdate(strQueryUpdate 6622 + strQueryWhere); 6623 } catch (SQLException ex) { 6624 stmtTarget.close(); 6625 stmtTarget = c 6626 .createStatement(); 6627 if ((importDefinitionElement.strDefaultCutOffData 6628 .equalsIgnoreCase("true"))) { 6629 dataCleaning 6630 .cutingDataLenghtUpdate( 6631 this.vecTableTableName 6632 .get( 6633 iTableInt) 6634 .toString(), 6635 c, 6636 strQueryWhere, 6637 currentRow, 6638 update, 6639 importDefinitionElement.strOnErrorContinueXml, 6640 importDefinitionElement.strImportDefinitionName, 6641 strQueryUpdate 6642 + strQueryWhere); 6643 } else 6644 throw ex; 6645 } 6646 if (iNumRow != 0) { 6647 if (!bWriteData) 6648 iVersionMax = iVersionMax + 1; 6649 bWriteData = true; 6650 } 6651 6652 } 6653 // } 6654 } 6655 } 6656 } 6657 } 6658 6659 // ZK END 6660 } 6661 6662 // checkRowCache.setCheckRowVersionValue(String 6663 // .valueOf(iVersionMax - 1)); 6664 } 6665 stmtTarget.close(); 6666 6667 } 6668 } 6669 // } 6670 catch (SQLException ex) { 6671 6672 if (stmtTarget != null) 6673 stmtTarget.close(); 6674 if ((importDefinitionElement.strDefaultCutOffData 6675 .equalsIgnoreCase("true"))) { 6676 dataCleaning.cleaningInsert(this.vecTableTableName.get( 6677 iTableInt).toString(), c, currentRow, "UPDATE", ex 6678 .getMessage(), 6679 importDefinitionElement.strImportDefinitionName, 6680 logStatement); 6681 // } else if ( 6682 // (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("false") 6683 // || 6684 // importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("")) 6685 // && 6686 // importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("true")) 6687 // { 6688 // dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).toString(), 6689 // c, currentRow, "UPDATE", ex.getMessage(), 6690 // importDefinitionElement.strImportDefinitionName); 6691 } else { 6692 this.logger.write("normal", 6693 "\tDataCleaning features is not turn on."); 6694 throw ex; 6695 } 6696 } catch (NullPointerException ex) { 6697 throw ex; 6698 } catch (Exception ex) { 6699 6700 throw ex; 6701 } 6702 this.logger.write("full", "\tinsertTargetTable method is finished."); 6703 } 6704 6705 /*** 6706 * Method insertRow is used to insert new row in the target table. Also 6707 * includes inserting values into constant, variable and relation columns of 6708 * the target table. If there is an error, Exception "SQLException" or 6709 * "NullPointerException" or "Exception" is thrown. 6710 * 6711 * @param c 6712 * Connection to the target database. 6713 * @param vecColumnValues 6714 * One row of values from source table. 6715 * @param vecColumnNamesTypes 6716 * Types of columns in a target table. 6717 * @param vecColumnNames 6718 * Vector of column names in a target table. 6719 * @param bOIDlogicValue 6720 * true if oid column exists in the target table. 6721 * @param iTableInt 6722 * Number of target table which is processed. 6723 * @param vecColumnMode 6724 * represents vector of table modes for currnet table 6725 * @throws SQLException 6726 * Constructs an SQLException object with a reason. 6727 * @throws NullPointerException 6728 * Constructs a NullPointerException with the specified detail 6729 * message. 6730 * @throws Exception 6731 * Constructs an Exception with the specified detail message. 6732 */ 6733 private void insertRow(Connection c, Vector vecColumnValues, 6734 Vector vecColumnNamesTypes, Vector vecColumnNames, 6735 Vector vecColumnMode, boolean bOIDlogicValue, int iTableInt, 6736 Vector vecTransformationValue, 6737 Vector transformationTargetColumnTypes) throws SQLException, 6738 NullPointerException, Exception { 6739 6740 String key = String.valueOf(iTableInt); 6741 String strInsertRow = (String) queryInsertRow.get(key); 6742 Vector indexOfNotRelationColumns = (Vector) indexIsNotRelationsColumns 6743 .get(key); 6744 6745 PreparedStatement pstmt = (PreparedStatement) pstmtForInsert.get(key); 6746 6747 Vector pstmtColNames = (Vector) pstmtColumnNames.get(key); 6748 Vector pstmtValues = new Vector(); 6749 Vector pstmtTypes = new Vector(); 6750 // hendling select statement in relation tag! 6751 String selectValueInRel = ""; 6752 String currentValueInRel = ""; 6753 6754 this.logger.write("full", "\tinsertRow method is started."); 6755 String strQuery = ""; 6756 boolean isTOS = !(importDefinitionElement.strObjectIDNameColumnName 6757 .equals("") || importDefinitionElement.strObjectIDNameColumnValue 6758 .equals("")); 6759 // sinisa 15.03.2003. Add subCouterColumns 6760 Vector subCounterKeyColumns = this.counterColumns 6761 .getSubCounterKeyColumns(this.vecTableTableName.get(iTableInt) 6762 .toString(), this.vecTableTableID.get(iTableInt) 6763 .toString()); 6764 6765 Hashtable subKeyValues = new Hashtable(); 6766 try { 6767 Vector vecTempConstantColumns = (Vector) this.vecConstantTargetColumnName 6768 .get(iTableInt); 6769 Vector vecTempConstantValues = (Vector) this.vecConstantConstantValue 6770 .get(iTableInt); 6771 strInsertRow = strInsertRow.trim(); 6772 int comma = strInsertRow.lastIndexOf(","); 6773 if (comma == (strInsertRow.length() - 1)) 6774 strQuery = strInsertRow.substring(0, strInsertRow.length() - 1); 6775 else 6776 strQuery = strInsertRow; 6777 if (bOIDlogicValue) { 6778 if (isTOS) { 6779 pstmtValues.add(this.bdecOidNumber); 6780 pstmtTypes.add("java.math.BigDecimal"); 6781 } else { 6782 pstmtValues.add(this.bdecOidNumber); 6783 pstmtValues.add(String.valueOf(0)); 6784 pstmtTypes.add("java.math.BigDecimal"); 6785 pstmtTypes.add("java.lang.Integer"); 6786 } 6787 } 6788 6789 strQuery = strQuery + ") VALUES ("; 6790 6791 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase( 6792 "true")) { 6793 if (indexOfNotRelationColumns.size() > 0) { 6794 for (int k = 0; k < indexOfNotRelationColumns.size(); k++) { 6795 int index = Integer.parseInt(indexOfNotRelationColumns 6796 .get(k).toString()); 6797 Vector replacedValue = (Vector) vecDefaultValue 6798 .get(iTableInt); 6799 if (vecColumnValues.get(index) == null) { 6800 if (replacedValue.get(index) != "") { 6801 pstmtValues.add(replacedValue.get(index) 6802 // .toString() 6803 ); 6804 pstmtTypes.add(vecColumnNamesTypes.get(index) 6805 .toString()); 6806 dataCleaning 6807 .cleaningColumnValues( 6808 this.vecTableTableName.get( 6809 iTableInt).toString(), 6810 vecColumnNames.get(index) 6811 .toString(), 6812 replacedValue.get(index) 6813 .toString(), 6814 currentRow, 6815 c, 6816 "INSERT", 6817 importDefinitionElement.strImportDefinitionName); 6818 } else { 6819 pstmtValues.add("null"); 6820 pstmtTypes.add(vecColumnNamesTypes.get(index) 6821 .toString()); 6822 } 6823 } else { 6824 pstmtValues.add(vecColumnValues.get(index) 6825 // .toString() 6826 ); 6827 pstmtTypes.add(vecColumnNamesTypes.get(index) 6828 .toString()); 6829 } 6830 6831 // sinisa 15.03 Add subCounter columns 6832 for (int l = 0; l < subCounterKeyColumns.size(); l++) { 6833 if (subCounterKeyColumns.get(l) != null 6834 && ((Vector) subCounterKeyColumns.get(l)) 6835 .size() != 0 6836 && ((Vector) subCounterKeyColumns.get(l)) 6837 .contains(vecColumnNames.get(index) 6838 .toString())) { 6839 if (vecColumnValues.get(index) != null) { 6840 subKeyValues.put(vecColumnNames.get(index) 6841 .toString(), vecColumnValues.get( 6842 index).toString()); 6843 } 6844 } 6845 } 6846 } 6847 } 6848 } 6849 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase( 6850 "true")) { 6851 for (int p = 0; p < vecTempConstantValues.size(); p++) { 6852 if (vecTempConstantValues.get(p) == null) { 6853 pstmtValues.add("null"); 6854 pstmtTypes.add(((Vector) this.vecConstantColumnType 6855 .get(iTableInt)).get(p).toString()); 6856 } else { 6857 pstmtValues.add(vecTempConstantValues.get(p) 6858 // .toString() 6859 ); 6860 pstmtTypes.add(((Vector) this.vecConstantColumnType 6861 .get(iTableInt)).get(p).toString()); 6862 6863 } 6864 // sinisa 15.03 Add subCounter columns 6865 for (int l = 0; l < subCounterKeyColumns.size(); l++) { 6866 if (subCounterKeyColumns.get(l) != null 6867 && ((Vector) subCounterKeyColumns.get(l)) 6868 .size() != 0 6869 && ((Vector) subCounterKeyColumns.get(l)) 6870 .contains(vecTempConstantColumns.get(p))) { 6871 if (vecTempConstantValues.get(p) != null) 6872 subKeyValues.put(vecTempConstantColumns.get(p) 6873 .toString(), vecTempConstantValues.get( 6874 p).toString()); 6875 } 6876 } 6877 } 6878 } 6879 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase( 6880 "true")) { 6881 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) { 6882 if (this.vecVariableTimesTableName.get(i).toString() 6883 .equalsIgnoreCase( 6884 this.vecTableTableName.get(iTableInt) 6885 .toString()) 6886 && this.vecVariableTimesTableID.get(i).toString() 6887 .equalsIgnoreCase( 6888 this.vecTableTableID.get(iTableInt) 6889 .toString())) { 6890 pstmtValues.add(createCurrentDate()); 6891 pstmtTypes.add("java.sql.Date"); 6892 } 6893 } 6894 for (int i = 0; i < this.vecVariableColumnTargetTableName 6895 .size(); i++) { 6896 if (this.vecVariableColumnTargetTableName.get(i).toString() 6897 .equalsIgnoreCase( 6898 this.vecTableTableName.get(iTableInt) 6899 .toString()) 6900 && this.vecVariableColumnTargetTableID.get(i) 6901 .toString().equalsIgnoreCase( 6902 this.vecTableTableID.get(iTableInt) 6903 .toString())) { 6904 int iPositionInVector = this.vecVariableName 6905 .indexOf(this.vecVariableColumnName.get(i) 6906 .toString()); 6907 if (iPositionInVector != -1) { 6908 if (this.vecVariableValue.get(iPositionInVector) == null) { 6909 String variableName = this.vecVariableColumnName 6910 .get(i).toString(); 6911 for (int k = 0; k < this.vecDefaultVariableName 6912 .size(); k++) { 6913 if (this.vecDefaultVariableName.get(k) 6914 .toString().equalsIgnoreCase( 6915 variableName)) { 6916 if (!this.vecDefaultVariableValue 6917 .get(k).toString() 6918 .equalsIgnoreCase("")) { 6919 pstmtValues 6920 .add(this.vecDefaultVariableValue 6921 .get(k) 6922 // .toString() 6923 ); 6924 pstmtTypes 6925 .add(this.vecVariableColumnTypes 6926 .get(i).toString()); 6927 } else { 6928 pstmtValues.add("null"); 6929 pstmtTypes 6930 .add(this.vecVariableColumnTypes 6931 .get(i).toString()); 6932 } 6933 break; 6934 } 6935 } 6936 } else { 6937 pstmtValues.add(this.vecVariableValue 6938 .get(iPositionInVector) 6939 // .toString() 6940 ); 6941 pstmtTypes.add(this.vecVariableColumnTypes.get( 6942 i).toString()); 6943 } 6944 } else { 6945 this.logger.write("normal", 6946 "\tError: Cannot find value for variable column :" 6947 + this.vecVariableColumnName.get(i) 6948 .toString()); 6949 LoaderException le = new LoaderException( 6950 "Exception: ", 6951 (Throwable) (new Exception( 6952 "Error: Cannot find value for variable column :"))); 6953 this.logger.write("full", le 6954 .getStackTraceAsString()); 6955 throw le; 6956 } 6957 // sinisa 15.03 Add subCounter columns 6958 for (int l = 0; l < subCounterKeyColumns.size(); l++) { 6959 if (subCounterKeyColumns.get(l) != null 6960 && ((Vector) subCounterKeyColumns.get(l)) 6961 .size() != 0 6962 && ((Vector) subCounterKeyColumns.get(l)) 6963 .contains(this.vecVariableColumnName 6964 .get(iPositionInVector))) { 6965 if (this.vecVariableValue 6966 .get(iPositionInVector) != null) 6967 subKeyValues.put(this.vecVariableColumnName 6968 .get(iPositionInVector).toString(), 6969 this.vecVariableValue.get( 6970 iPositionInVector) 6971 .toString()); 6972 } 6973 } 6974 } 6975 } 6976 } 6977 // find value for relation column - userID 6978 for (int i = 0; i < this.iRelationColumns; i++) { 6979 outLoop1: if (this.vecRelationColumnSourceTableName.get(i) 6980 .toString().equalsIgnoreCase( 6981 this.vecTableTableName.get(iTableInt) 6982 .toString()) 6983 && this.vecRelationColumnSourceTableID.get(i) 6984 .toString().equalsIgnoreCase( 6985 this.vecTableTableID.get(iTableInt) 6986 .toString())) { 6987 for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) { 6988 if (this.vecRelationColumnSourceTableName.get(i) 6989 .toString().equalsIgnoreCase( 6990 this.vecVariableUseIDTableName.get(m) 6991 .toString()) 6992 && this.vecRelationColumnSourceTableID.get(i) 6993 .toString().equalsIgnoreCase( 6994 this.vecVariableUseIDTableID 6995 .get(m).toString())) { 6996 String strQueryRelations = "select " 6997 + this.vecRelationColumnSourceColumnName 6998 .get(i).toString() 6999 + " from " 7000 + this.vecRelationColumnSourceTableName 7001 .get(i).toString() + " where "; 7002 strQueryRelations += ((Vector) this.vecTargetKeyColumnName 7003 .get(iTableInt)).get(0).toString() 7004 + " = "; 7005 // ZK change this from CheckType to 7006 // configReaderTarget this 7.5.2004 7007 if (!configReaderTarget 7008 .isNumber(vecColumnNamesTypes.get(0) 7009 .toString())) 7010 strQueryRelations += "'" + this.strUserID + "'"; 7011 else 7012 strQueryRelations += this.strUserID; 7013 this.logger.write("full", "\tQuery '" 7014 + strQueryRelations + "' will be executed"); 7015 Statement stmt = c.createStatement(); 7016 ResultSet rsetTarget = stmt 7017 .executeQuery(strQueryRelations); 7018 if (rsetTarget.next()) { 7019 if (this.iTargetFirstColumnResult == 1) { 7020 this.vecRelationSourceValue.setElementAt( 7021 rsetTarget.getObject(1), i); 7022 this.vecRelationSourceType.setElementAt( 7023 rsetTarget.getMetaData() 7024 .getColumnTypeName(1), i); 7025 } else { 7026 this.vecRelationSourceValue.setElementAt( 7027 rsetTarget.getObject(0), i); 7028 this.vecRelationSourceType.setElementAt( 7029 rsetTarget.getMetaData() 7030 .getColumnTypeName(0), i); 7031 } 7032 } 7033 rsetTarget.close(); 7034 stmt.close(); 7035 break outLoop1; 7036 } 7037 } 7038 if (bOIDlogicValue) { 7039 String oidType = configReaderTarget.getOidDbType(); 7040 int end = oidType.indexOf("("); 7041 if (end != -1) 7042 oidType = (oidType.substring(0, end)).trim(); 7043 else 7044 oidType = oidType.trim(); 7045 if (this.vecTableInsert.get(iTableInt).toString() 7046 .equalsIgnoreCase("true")) { 7047 // insertTable=true 7048 this.vecRelationSourceValue.setElementAt( 7049 this.bdecOidNumber, i); 7050 this.vecRelationSourceType.setElementAt(oidType 7051 .toLowerCase(), i); 7052 7053 } else { 7054 // insertTable=false 7055 this.vecRelationSourceValue.setElementAt(null, i); 7056 this.vecRelationSourceType.setElementAt(oidType 7057 .toLowerCase(), i); 7058 7059 } 7060 } else { // bOIDlogicValue=false 7061 if (this.iRelationColumns > 0) { 7062 for (int j = 0; j < vecColumnNames.size(); j++) { 7063 if (this.vecRelationColumnSourceColumnName.get( 7064 i).toString().equalsIgnoreCase( 7065 vecColumnNames.get(j).toString())) { 7066 if (this.vecTableInsert.get(iTableInt) 7067 .toString() 7068 .equalsIgnoreCase("true")) { 7069 // insertTable=true 7070 this.vecRelationSourceValue 7071 .setElementAt(vecColumnValues 7072 .get(j).toString(), i); 7073 this.vecRelationSourceType 7074 .setElementAt( 7075 vecColumnNamesTypes 7076 .get(j) 7077 .toString(), i); 7078 } else { 7079 // insertTable=false; 7080 this.vecRelationSourceValue 7081 .setElementAt(null, i); 7082 this.vecRelationSourceType 7083 .setElementAt( 7084 vecColumnNamesTypes 7085 .get(j) 7086 .toString(), i); 7087 } 7088 } 7089 } // end vecColumnNames.size() 7090 } 7091 } 7092 } 7093 } 7094 7095 for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) { 7096 String tmpRelationForCount = ""; 7097 if (this.vecRelationColumnTargetTableName.get(i).toString() 7098 .equalsIgnoreCase( 7099 this.vecTableTableName.get(iTableInt) 7100 .toString()) 7101 && this.vecRelationColumnTargetTableID.get(i) 7102 .toString().equalsIgnoreCase( 7103 this.vecTableTableID.get(iTableInt) 7104 .toString())) { 7105 if (this.vecRelationSourceValue.get(i) == null) { 7106 String replacementValueInRel = vecDefaultRelationValue 7107 .get(i).toString(); 7108 if (!replacementValueInRel.equalsIgnoreCase("")) { 7109 // default value for relation exists 7110 try { 7111 Object obj = relationsCache 7112 .getRelationsCacheValue(replacementValueInRel); 7113 String relationValue; 7114 String relationType; 7115 if (obj != null) { 7116 // relation (default value) is cached 7117 relationValue = obj.toString(); 7118 relationType = relationsCache 7119 .getRelationsCachType(replacementValueInRel); 7120 pstmtValues.add(relationValue); 7121 pstmtTypes.add(relationType); 7122 } else { 7123 // relation (default value) isn't cached 7124 ResultSet newRelationValue = null; 7125 Statement newRelationsStmt = c 7126 .createStatement(); 7127 try { 7128 this.logger.write("full", "\tQuery '" 7129 + replacementValueInRel 7130 + "' will be executed"); 7131 newRelationValue = newRelationsStmt 7132 .executeQuery(replacementValueInRel); 7133 if (newRelationValue.next()) { 7134 relationValue = newRelationValue 7135 .getString(1); 7136 relationsCache 7137 .setRelationsCacheValue( 7138 replacementValueInRel, 7139 relationValue); 7140 relationType = newRelationValue 7141 .getMetaData() 7142 .getColumnTypeName(1); 7143 relationsCache 7144 .setRelationsCacheType( 7145 replacementValueInRel, 7146 relationType); 7147 7148 newRelationValue.close(); 7149 newRelationsStmt.close(); 7150 7151 String strDataCleaning = dataCleaning 7152 .cleaningRelationValues( 7153 this.vecTableTableName 7154 .get( 7155 iTableInt) 7156 .toString(), 7157 this.vecRelationColumnTargetColumnName 7158 .get(i) 7159 .toString(), 7160 relationValue, 7161 relationType, 7162 currentRow, 7163 c, 7164 "INSERT", 7165 0, 7166 false, 7167 importDefinitionElement.strImportDefinitionName, 7168 this.currentVersionColumnName, 7169 replacementValueInRel); 7170 pstmtValues.add(strDataCleaning); 7171 pstmtTypes.add(relationType); 7172 } else { // newRelationValue.next()=false 7173 newRelationValue.close(); 7174 newRelationsStmt.close(); 7175 relationValue = "null"; 7176 dataCleaning 7177 .cleaningInsert( 7178 this.vecTableTableName 7179 .get( 7180 iTableInt) 7181 .toString(), 7182 c, 7183 currentRow, 7184 "INSERT", 7185 "Default value '" 7186 + replacementValueInRel 7187 + "' for relations is not valid.", 7188 importDefinitionElement.strImportDefinitionName, 7189 replacementValueInRel); 7190 7191 pstmtValues.add("null"); 7192 pstmtTypes 7193 .add(this.vecRelationSourceType 7194 .get(i).toString()); 7195 } 7196 } catch (SQLException ex) { 7197 newRelationValue.close(); 7198 newRelationsStmt.close(); 7199 LoaderException le = new LoaderException( 7200 "\n" + "SQLException: " 7201 + ex.getMessage(), 7202 (Throwable) ex); 7203 this.logger.write("full", le 7204 .getStackTraceAsString()); 7205 throw le; 7206 } 7207 } 7208 7209 } catch (SQLException ex) { 7210 String msg = "Default value for foreign key(" 7211 + replacementValueInRel 7212 + ") is not valid. Import definition name: " 7213 + importDefinitionElement.strImportDefinitionName; 7214 LoaderException le = new LoaderException( 7215 "SQLException: " + msg, (Throwable) ex); 7216 this.logger.write("full", le 7217 .getStackTraceAsString()); 7218 throw le; 7219 } 7220 7221 } else { // default value for relations doesn't 7222 // exsist 7223 pstmtValues.add("null"); 7224 if (this.vecRelationSourceType.get(i) != null) 7225 pstmtTypes.add(this.vecRelationSourceType 7226 .get(i).toString()); 7227 else 7228 pstmtTypes.add("java.lang.Object"); 7229 } 7230 } else { // this.vecRelationSourceType.get(i)!=null 7231 pstmtValues.add(this.vecRelationSourceValue.get(i) 7232 .toString()); 7233 pstmtTypes.add(this.vecRelationSourceType.get(i) 7234 .toString()); 7235 7236 tmpRelationForCount = this.vecRelationSourceValue 7237 .get(i).toString();// 7238 this.vecRelationSourceValue.setElementAt(null, i); 7239 7240 } 7241 7242 // sinisa 15.03 Add subCounter columns 7243 for (int l = 0; l < subCounterKeyColumns.size(); l++) { 7244 if (subCounterKeyColumns.get(l) != null 7245 && ((Vector) subCounterKeyColumns.get(l)) 7246 .size() != 0 7247 && ((Vector) subCounterKeyColumns.get(l)) 7248 .contains(this.vecRelationColumnTargetColumnName 7249 .get(i))) { 7250 if (tmpRelationForCount != null) { 7251 subKeyValues.put( 7252 this.vecRelationColumnTargetColumnName 7253 .get(i).toString(), 7254 tmpRelationForCount); 7255 } 7256 } 7257 } 7258 } 7259 } 7260 7261 // sinisa 02.03.2003. Add couterColumns 7262 Vector counterColValues = this.counterColumns.getCounterValue( 7263 this.vecTableTableName.get(iTableInt).toString(), 7264 this.vecTableTableID.get(iTableInt).toString()); 7265 for (int i = 0; i < counterColValues.size(); i++) { 7266 if (counterColValues.get(i) != null) { 7267 int strInt = new BigDecimal(counterColValues.get(i) 7268 .toString()).intValue(); 7269 pstmtValues.add(String.valueOf(strInt)); 7270 pstmtTypes.add("java.lang.Integer"); 7271 } else { 7272 pstmtValues.add("null"); 7273 pstmtTypes.add("java.lang.Integer"); 7274 } 7275 } 7276 this.counterColumns.setCounterValue(this.vecTableTableName.get( 7277 iTableInt).toString(), this.vecTableTableID.get(iTableInt) 7278 .toString()); 7279 // end sinisa 7280 7281 // sinisa 15.03.2003. Add counterColumns 7282 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase( 7283 "true")) { 7284 this.counterColumns.setSubCounterKeyValues( 7285 this.vecTableTableName.get(iTableInt).toString(), 7286 this.vecTableTableID.get(iTableInt).toString(), 7287 subKeyValues); 7288 Vector subCounterColValues = this.counterColumns 7289 .readSubCounterValue(this.vecTableTableName.get( 7290 iTableInt).toString(), this.vecTableTableID 7291 .get(iTableInt).toString(), c, 7292 this.iTargetFirstColumnResult, 7293 this.vecTableTableMode.get(iTableInt) 7294 .toString(), configReaderTarget); 7295 for (int i = 0; i < subCounterColValues.size(); i++) { 7296 if (subCounterColValues.get(i) != null) { 7297 pstmtValues.add(new BigDecimal(subCounterColValues.get( 7298 i).toString())); 7299 pstmtTypes.add("java.math.BigDecimal"); 7300 } else { 7301 pstmtValues.add("null"); 7302 pstmtTypes.add("java.math.BigDecimal"); 7303 } 7304 } 7305 if (bOIDlogicValue) { 7306 if (this.bdecOidNumber.compareTo(this.bdecOidNumber2000) == 0) { 7307 this.checkOidLogic(c); 7308 this.bdecOidNumber = this.bdecOidNumber 7309 .add(new BigDecimal(1)); 7310 } else 7311 this.bdecOidNumber = this.bdecOidNumber 7312 .add(new BigDecimal(1)); 7313 } 7314 7315 // ZK added this for transormations 7316 for (int i = 0; i < vecTransformationValue.size(); i++) { 7317 if ((vecTransformationValue.get(i)) == null) { 7318 String valueForPstmt = "null"; 7319 pstmtValues.add(valueForPstmt); 7320 } else { 7321 pstmtValues.add(vecTransformationValue.get(i) 7322 // .toString() 7323 ); 7324 } 7325 7326 pstmtTypes.add(transformationTargetColumnTypes.get(i) 7327 .toString()); 7328 7329 } 7330 7331 // String tableNameId= 7332 // this.vecTableTableName.get(iTableInt).toString()+this.vecTableTableID.get(iTableInt).toString(); 7333 // if (transTableNamesIDs.contains(tableNameId)){ 7334 // for (int i=0; i < trans.size();i++){ 7335 // Transformation pom = (Transformation)trans.get(i); 7336 // Vector sourceColumnNames = pom.getSourceColumnNames(); 7337 // Vector targetColumnNames = 7338 // pom.getTargetColumnNames(this.vecTableTableName.get(iTableInt).toString(), 7339 // this.vecTableTableID.get(iTableInt).toString()); 7340 // 7341 // Vector resultVector = 7342 // pom.readTransformationValues(sourceColumnNames, 7343 // this.vecTableTableName.get(iTableInt).toString(), 7344 // this.vecTableTableID.get(iTableInt).toString()); 7345 // Vector resultVectorTypes = 7346 // pom.getTargetColumnTypes(this.vecTableTableName.get(iTableInt).toString(), 7347 // this.vecTableTableID.get(iTableInt).toString()); 7348 // for(int j=0;j < resultVector.size();j++) { 7349 // pstmtValues.add(resultVector.get(j)); 7350 // pstmtTypes.add(resultVectorTypes.get(j)); 7351 // } 7352 // } 7353 // } 7354 // end 7355 7356 // handling blob object 7357 // strQuery = strQuery + ") VALUES ("; 7358 String pstmtColumnValue; 7359 for (int i = 0; i < pstmtValues.size(); i++) { 7360 7361 String javaType = pstmtTypes.get(i).toString() 7362 .toUpperCase(); 7363 if (javaType.indexOf("JAVA") == -1) { 7364 // //ZK Added next line because of DB2 type LONG VARCHAR 7365 // javaType = Utils.replaceAll(javaType," ","_"); 7366 javaType = (String) configReaderTarget 7367 .getJavaTypeMapings().get( 7368 javaType.toUpperCase()); 7369 if (javaType == null) { 7370 LoaderException le = new LoaderException( 7371 "Exception:", 7372 new Exception( 7373 "This type of data " 7374 + pstmtTypes.get(i) 7375 .toString() 7376 .toUpperCase() 7377 + " doesn't exists in the target table conf file!")); 7378 this.logger.write("full", le 7379 .getStackTraceAsString()); 7380 throw le; 7381 } 7382 } else { 7383 if (javaType.equalsIgnoreCase("java.math.BigDecimal")) 7384 javaType = "2"; 7385 else if (javaType.equalsIgnoreCase("java.lang.Integer")) 7386 javaType = "5"; 7387 else if (javaType.equalsIgnoreCase("java.sql.Date")) 7388 javaType = "9"; 7389 else if (javaType.equalsIgnoreCase("java.lang.Object")) 7390 javaType = "14"; 7391 7392 } 7393 7394 int javaTypeInt = Integer.parseInt(javaType); 7395 pstmtColumnValue = pstmtValues.get(i).toString(); 7396 Object pstmtColumnValueAsObject = pstmtValues.get(i); 7397 // ZK changed this 17.6 2004 because of problems with null 7398 // binary object. 7399 // if (pstmtColumnValue.startsWith("binaryObject")) { 7400 if (javaTypeInt == 1) { 7401 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7402 String binaryName = pstmtValues.get(i).toString(); 7403 for (int j = 0; j < vecBlobVector.size(); j = j + 5) { 7404 if (binaryName.equalsIgnoreCase(vecBlobVector 7405 .get(j + 4).toString())) { 7406 byte[] isBlob = (byte[]) this.vecBlobVector 7407 .get(j + 1); 7408 strQuery = strQuery + binaryName + ","; 7409 pstmt.setBytes(i + 1, isBlob); 7410 strQuery = strQuery + "BlobObject" + i 7411 + ","; 7412 break; 7413 } 7414 } 7415 } else { 7416 pstmt.setNull(i + 1, java.sql.Types.BINARY); 7417 strQuery = strQuery + "null" + ","; 7418 } 7419 } else { 7420 if (javaTypeInt == 2) { // java.math.BigDecimal 7421 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7422 BigDecimal number = new BigDecimal(0); 7423 if (!pstmtColumnValue.equalsIgnoreCase("")) 7424 number = new BigDecimal(pstmtColumnValue); 7425 strQuery = strQuery + pstmtColumnValue + ","; 7426 pstmt.setBigDecimal(i + 1, number); 7427 } else { 7428 pstmt.setNull(i + 1, java.sql.Types.DECIMAL); 7429 strQuery = strQuery + "null" + ","; 7430 } 7431 } else if (javaTypeInt == 3) { // java.lang.Double 7432 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7433 double number = 0; 7434 if (!pstmtColumnValue.equalsIgnoreCase("")) 7435 number = Double 7436 .parseDouble(pstmtColumnValue); 7437 strQuery = strQuery + pstmtColumnValue + ","; 7438 pstmt.setDouble(i + 1, number); 7439 } else { 7440 strQuery = strQuery + "null" + ","; 7441 pstmt.setNull(i + 1, java.sql.Types.DOUBLE); 7442 } 7443 } else if (javaTypeInt == 4) { // java.lang.Float 7444 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7445 float number = 0; 7446 if (!pstmtColumnValue.equalsIgnoreCase("")) 7447 number = Float.parseFloat(pstmtColumnValue); 7448 pstmt.setFloat(i + 1, number); 7449 strQuery = strQuery + pstmtColumnValue + ","; 7450 } else { 7451 pstmt.setNull(i + 1, java.sql.Types.FLOAT); 7452 strQuery = strQuery + "null" + ","; 7453 } 7454 } else if (javaTypeInt == 5) { // java.lang.Integer 7455 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7456 int number = 0; 7457 if (!pstmtColumnValue.equalsIgnoreCase("")) 7458 number = Integer.parseInt(pstmtColumnValue); 7459 pstmt.setInt(i + 1, number); 7460 strQuery = strQuery + pstmtColumnValue + ","; 7461 } else { 7462 pstmt.setNull(i + 1, java.sql.Types.INTEGER); 7463 strQuery = strQuery + "null" + ","; 7464 } 7465 7466 } else if (javaTypeInt == 6) { // java.lang.Long 7467 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7468 long number = 0; 7469 if (!pstmtColumnValue.equalsIgnoreCase("")) 7470 number = Long.parseLong(pstmtColumnValue); 7471 pstmt.setLong(i + 1, number); 7472 strQuery = strQuery + pstmtColumnValue + ","; 7473 } else { 7474 pstmt.setNull(i + 1, java.sql.Types.DOUBLE); 7475 strQuery = strQuery + "null" + ","; 7476 } 7477 } else if (javaTypeInt == 7) { // java.lang.Short 7478 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7479 short number = 0; 7480 if (!pstmtColumnValue.equalsIgnoreCase("")) 7481 number = Short.parseShort(pstmtColumnValue); 7482 pstmt.setShort(i + 1, number); 7483 strQuery = strQuery + pstmtColumnValue + ","; 7484 } else { 7485 pstmt.setNull(i + 1, java.sql.Types.SMALLINT); 7486 strQuery = strQuery + "null" + ","; 7487 } 7488 } else if (javaTypeInt == 8) { // java.lang.String 7489 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7490 // all '' back to ' (original value) 7491 if (pstmtColumnValue.indexOf("''") != -1) { 7492 pstmtColumnValue = Utils.replaceAll( 7493 pstmtColumnValue, "''", "'"); 7494 } 7495 pstmt.setString(i + 1, pstmtColumnValue); 7496 strQuery = strQuery + "'" + pstmtColumnValue 7497 + "'" + ","; 7498 } else { 7499 pstmt.setNull(i + 1, java.sql.Types.VARCHAR); 7500 strQuery = strQuery + "null" + ","; 7501 7502 } 7503 } else if (javaTypeInt == 9) { // java.sql.Date 7504 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7505 if (pstmtColumnValueAsObject instanceof java.sql.Date) 7506 pstmt 7507 .setDate( 7508 i + 1, 7509 (java.sql.Date) pstmtColumnValueAsObject); 7510 else { 7511 //try { 7512 // pstmt.setDate(i + 1, new java.sql.Date(getDateFromString(pstmtColumnValue).getTime())); 7513 //} catch (Exception e) { 7514 this.logger.write("full","call setString on date: "+ pstmtColumnValue); 7515 pstmt.setString(i + 1,pstmtColumnValue); 7516 //} 7517 } 7518 strQuery = strQuery + "'" + pstmtColumnValue 7519 + "'" + ","; 7520 } else { 7521 pstmt.setNull(i + 1, java.sql.Types.DATE); 7522 strQuery = strQuery + "null" + ","; 7523 } 7524 } else if (javaTypeInt == 10) { // java.sql.Time 7525 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7526 if (pstmtColumnValueAsObject instanceof Time) 7527 pstmt 7528 .setTime( 7529 i + 1, 7530 (java.sql.Time) pstmtColumnValueAsObject); 7531 else { 7532 // String format = 7533 // this.configReaderSource.getDateFormat(); 7534 // SimpleDateFormat formatDate = new 7535 // SimpleDateFormat(format); 7536 // Date tmpDate = 7537 // formatDate.parse(pstmtColumnValue); 7538 try { 7539 pstmt.setTime(i + 1, new java.sql.Time( 7540 getDateFromString( 7541 pstmtColumnValue) 7542 .getTime())); 7543 } catch (Exception e) { 7544 pstmt 7545 .setString(i + 1, 7546 pstmtColumnValue); 7547 } 7548 } 7549 strQuery = strQuery + "'" + pstmtColumnValue 7550 + "'" + ","; 7551 } else { 7552 pstmt.setNull(i + 1, java.sql.Types.TIME); 7553 strQuery = strQuery + "null" + ","; 7554 } 7555 7556 } else if (javaTypeInt == 11) { // java.sql.Timestamp 7557 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7558 if (pstmtColumnValueAsObject instanceof java.sql.Timestamp) 7559 pstmt 7560 .setTimestamp( 7561 i + 1, 7562 (java.sql.Timestamp) pstmtColumnValueAsObject); 7563 else { 7564 // String format = 7565 // this.configReaderSource.getDateFormat(); 7566 // SimpleDateFormat formatDate = new 7567 // SimpleDateFormat(format); 7568 // Date tmpDate = 7569 // formatDate.parse(pstmtColumnValue); 7570 try { 7571 pstmt 7572 .setTimestamp( 7573 i + 1, 7574 new Timestamp( 7575 getDateFromString( 7576 pstmtColumnValue) 7577 .getTime())); 7578 } catch (Exception e) { 7579 pstmt 7580 .setString(i + 1, 7581 pstmtColumnValue); 7582 } 7583 } 7584 strQuery = strQuery + "'" + pstmtColumnValue 7585 + "'" + ","; 7586 } else { 7587 pstmt.setNull(i + 1, java.sql.Types.TIMESTAMP); 7588 strQuery = strQuery + "null" + ","; 7589 } 7590 7591 } else if (javaTypeInt == 12) { // java.lang.Boolean 7592 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7593 boolean bool = new Boolean(pstmtColumnValue) 7594 .booleanValue(); 7595 pstmt.setBoolean(i + 1, bool); 7596 strQuery = strQuery + pstmtColumnValue + ","; 7597 } else { 7598 pstmt.setNull(i + 1, java.sql.Types.BIT); 7599 strQuery = strQuery + "null" + ","; 7600 } 7601 } else if (javaTypeInt == 13) { // java.lang.Byte 7602 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7603 pstmt.setString(i + 1, pstmtColumnValue); 7604 strQuery = strQuery + "'" + pstmtColumnValue 7605 + "'" + ","; 7606 } else { 7607 pstmt.setNull(i + 1, java.sql.Types.BIT); 7608 strQuery = strQuery + "null" + ","; 7609 } 7610 } else if (javaTypeInt == 14) { // java.lang.Object 7611 if (!pstmtColumnValue.equalsIgnoreCase("null")) { 7612 pstmt.setString(i + 1, pstmtColumnValue); 7613 strQuery = strQuery + "'" + pstmtColumnValue 7614 + "'" + ","; 7615 } else { 7616 // TODO zoran pogledati ovo 7617 try { 7618 pstmt.setNull(i + 1, java.sql.Types.NULL); 7619 } catch (Exception e) { 7620 pstmt.setString(i + 1, null); 7621 } 7622 strQuery = strQuery + "null" + ","; 7623 } 7624 } else { 7625 LoaderException le = new LoaderException( 7626 "Exception:", new Exception( 7627 "This java type is not supported!")); 7628 this.logger.write("full", le 7629 .getStackTraceAsString()); 7630 throw le; 7631 } 7632 }// end of else (not blob) 7633 pstmtColumnValue = null; 7634 } 7635 strQuery = strQuery.substring(0, strQuery.length() - 1) + ")"; 7636 this.logger.write("full", "\tQuery '" + strQuery 7637 + "' will be executed"); 7638 7639 int pstmtInsert = 0; 7640 pstmtInsert = pstmt.executeUpdate(); 7641 // setting the cache value for inseted row 7642 // if (pstmtInsert != 0) 7643 // this.checkRowCache.setCheckRowValue(); 7644 pstmt.clearParameters(); 7645 pstmtValues.clear(); 7646 pstmtTypes.clear(); 7647 7648 // TODO 14.6.2004 ZK Comented this because of problems with 7649 // update on counters table which are not needed. 7650 // this.counterColumns.updateCounter(this.vecTableTableName.get(iTableInt).toString(), 7651 // this.vecTableTableID.get(iTableInt).toString(), c); 7652 7653 } else { 7654 // this.checkRowCache.setCheckRowValue(); 7655 } 7656 } catch (SQLException ex) { 7657 pstmt.clearParameters(); 7658 pstmtValues.clear(); 7659 pstmtTypes.clear(); 7660 LoaderException le = new LoaderException("SQLException: ", 7661 (Throwable) ex); 7662 if (importDefinitionElement.strDefaultCutOffData 7663 .equalsIgnoreCase("true")) { 7664 dataCleaning.cutingDataLenght(this.vecTableTableName.get( 7665 iTableInt).toString(), c, strQuery, currentRow, 7666 importDefinitionElement.strOnErrorContinueXml, ex 7667 .getMessage(), 7668 importDefinitionElement.strImportDefinitionName, 7669 strQuery); 7670 } else if (importDefinitionElement.strOnErrorContinueXml 7671 .equalsIgnoreCase("true")) { 7672 pstmt.clearParameters(); 7673 pstmtValues.clear(); 7674 pstmtTypes.clear(); 7675 // this.logger.write("full", "\tError in SQL statement: " + 7676 // le.getStackCause()); 7677 this.logger.write("full", "\tError in SQL statement: " 7678 + le.getStackTraceAsString()); 7679 dataCleaning.cleaningInsert(this.vecTableTableName.get( 7680 iTableInt).toString(), c, currentRow, "INSERT", ex 7681 .getMessage(), 7682 importDefinitionElement.strImportDefinitionName, 7683 strQuery); 7684 } else { 7685 pstmt.clearParameters(); 7686 pstmtValues.clear(); 7687 pstmtTypes.clear(); 7688 this.logger.write("normal", "\tError in SQL statement: " 7689 + le.getCause()); 7690 this.logger.write("full", le.getStackTraceAsString()); 7691 // throw ex; 7692 throw le; 7693 } 7694 } catch (NullPointerException ex) { 7695 throw ex; 7696 } catch (Exception ex) { 7697 throw ex; 7698 } 7699 this.logger.write("full", "\tinsertRow method is finished."); 7700 } 7701 7702 /*** 7703 * Method isRelationColumn checkes if the column(strColumnName) in target 7704 * table(iTable) is mentioned in relation tags (target column name). If it 7705 * is, return true, else return false. 7706 * 7707 * @param strColumnName - 7708 * Name of target column 7709 * @param iTable - 7710 * Number of target table 7711 * @return boolean - true if strColumnName is relation target column, false 7712 * if it is not. 7713 */ 7714 private boolean isRelationColumn(String strColumnName, int iTable) { 7715 boolean bFind = false; 7716 endFor: for (int i = 0; i < this.vecRelationColumnTargetTableName 7717 .size(); i++) { 7718 if (this.vecRelationColumnTargetTableName.get(i).toString() 7719 .equalsIgnoreCase( 7720 this.vecTableTableName.get(iTable).toString()) 7721 && this.vecRelationColumnTargetTableID 7722 .get(i) 7723 .toString() 7724 .equalsIgnoreCase( 7725 this.vecTableTableID.get(iTable).toString()) 7726 && this.vecRelationColumnTargetColumnName.get(i).toString() 7727 .equalsIgnoreCase(strColumnName)) { 7728 bFind = true; 7729 break endFor; 7730 } 7731 } 7732 return bFind; 7733 } 7734 7735 /*** 7736 * Method checkOidLogic is used to increase the ObjectID value with adding 7737 * iObjectIDIncrement value. Method puts new value in ObjectID table for 7738 * current importDefinition. If there is an error, Exception "SQLException" 7739 * or NullPointerException is thrown. 7740 * 7741 * @param c 7742 * Connection to target database. 7743 * @throws SQLException 7744 * Constructs an SQLException object with a reason. 7745 * @throws NullPointerException 7746 * Constructs a NullPointerException with the specified detail 7747 * message. 7748 */ 7749 private void checkOidLogic(Connection c) throws SQLException, 7750 NullPointerException { 7751 String strQuery = ""; 7752 this.logger.write("full", "\tcheckOidLogic method is started."); 7753 Boolean bTemp = new Boolean("false"); 7754 7755 if (currentJobName.equalsIgnoreCase("importDefinition")) { 7756 for (int i = 0; i < this.iTables; i++) { 7757 if (this.vecTableOidLogic.get(i).toString().equalsIgnoreCase( 7758 "true")) { 7759 bTemp = new Boolean("true"); 7760 } 7761 } 7762 } else if (currentJobName.equalsIgnoreCase("copyTable")) { 7763 if (importDefinitionElement.strCopyTableOidLogic 7764 .equalsIgnoreCase("true")) { 7765 bTemp = new Boolean("true"); 7766 } 7767 } 7768 7769 if (bTemp.booleanValue()) { 7770 try { 7771 if (!(importDefinitionElement.strObjectIDNameColumnName 7772 .equals("") || importDefinitionElement.strObjectIDNameColumnValue 7773 .equals(""))) { 7774 strQuery = new String( 7775 "SELECT " 7776 + importDefinitionElement.strObjectIDColumnName 7777 + " FROM " 7778 + importDefinitionElement.strObjectIDTableName 7779 + " WHERE " 7780 + importDefinitionElement.strObjectIDNameColumnName 7781 + " = '" 7782 + importDefinitionElement.strObjectIDNameColumnValue 7783 + "'"); 7784 } else { 7785 strQuery = new String("SELECT " 7786 + importDefinitionElement.strObjectIDColumnName 7787 + " FROM " 7788 + importDefinitionElement.strObjectIDTableName); 7789 } 7790 this.logger.write("full", "\tQuery '" + strQuery 7791 + "' will be executed"); 7792 Statement stmtOid = c.createStatement(); 7793 ResultSet rsetOid = stmtOid.executeQuery(strQuery); 7794 if (rsetOid.next()) { 7795 if (this.iTargetFirstColumnResult == 1) 7796 this.bdecOidNumber = new BigDecimal(rsetOid.getString(1)); 7797 else 7798 this.bdecOidNumber = new BigDecimal(rsetOid.getString(0)); 7799 } else { 7800 if (!(importDefinitionElement.strObjectIDNameColumnName 7801 .equals("") || importDefinitionElement.strObjectIDNameColumnValue 7802 .equals(""))) { 7803 String insert = "insert into " 7804 + importDefinitionElement.strObjectIDTableName 7805 + " (" 7806 + importDefinitionElement.strObjectIDNameColumnName 7807 + "," 7808 + importDefinitionElement.strObjectIDColumnName 7809 + ") values ('" 7810 + importDefinitionElement.strObjectIDNameColumnValue 7811 + "','" 7812 + importDefinitionElement.iObjectIDStartValue 7813 + "');"; 7814 stmtOid.execute(insert); 7815 } 7816 } 7817 rsetOid.close(); 7818 stmtOid.close(); 7819 7820 if (currentJobName.equalsIgnoreCase("copyTable")) { 7821 this.bdecOidNumber2000 = this.bdecOidNumber 7822 .add(new BigDecimal( 7823 importDefinitionElement.iObjectIDCT)); 7824 } else { 7825 this.bdecOidNumber2000 = this.bdecOidNumber 7826 .add(new BigDecimal( 7827 importDefinitionElement.iObjectID)); 7828 } 7829 Statement stmtOid2 = c.createStatement(); 7830 if (!(importDefinitionElement.strObjectIDNameColumnName 7831 .equals("") || importDefinitionElement.strObjectIDNameColumnValue 7832 .equals(""))) { 7833 this.logger 7834 .write( 7835 "full", 7836 "\tQuery '" 7837 + "UPDATE " 7838 + importDefinitionElement.strObjectIDTableName 7839 + " SET " 7840 + importDefinitionElement.strObjectIDColumnName 7841 + " = " 7842 + this.bdecOidNumber2000 7843 + " where " 7844 + importDefinitionElement.strObjectIDNameColumnName 7845 + " = '" 7846 + importDefinitionElement.strObjectIDNameColumnValue 7847 + "'' will be executed"); 7848 stmtOid2 7849 .executeUpdate("UPDATE " 7850 + importDefinitionElement.strObjectIDTableName 7851 + " SET " 7852 + importDefinitionElement.strObjectIDColumnName 7853 + " = " 7854 + this.bdecOidNumber2000 7855 + " where " 7856 + importDefinitionElement.strObjectIDNameColumnName 7857 + " = '" 7858 + importDefinitionElement.strObjectIDNameColumnValue 7859 + "'"); 7860 } else { 7861 this.logger 7862 .write( 7863 "full", 7864 "\tQuery '" 7865 + "UPDATE " 7866 + importDefinitionElement.strObjectIDTableName 7867 + " SET " 7868 + importDefinitionElement.strObjectIDColumnName 7869 + " = " 7870 + this.bdecOidNumber2000 7871 + " where " 7872 + importDefinitionElement.strObjectIDColumnName 7873 + " = " + this.bdecOidNumber 7874 + "' will be executed"); 7875 stmtOid2.executeUpdate("UPDATE " 7876 + importDefinitionElement.strObjectIDTableName 7877 + " SET " 7878 + importDefinitionElement.strObjectIDColumnName 7879 + " = " + this.bdecOidNumber2000 + " where " 7880 + importDefinitionElement.strObjectIDColumnName 7881 + " = " + this.bdecOidNumber); 7882 } 7883 stmtOid2.close(); 7884 } catch (SQLException ex) { 7885 throw ex; 7886 } catch (NullPointerException ex) { 7887 throw ex; 7888 } 7889 } 7890 this.logger.write("full", "\tcheckOidLogic method is finished."); 7891 } 7892 7893 /*** 7894 * Method querySource is used to make SQL query to source table and to sort 7895 * columns from source table ordered by sortColumns. 7896 * 7897 * @return SQL Query to source table. 7898 * @throws LoaderException 7899 */ 7900 private String querySource() throws LoaderException { 7901 int i = 0; 7902 int j = 0; 7903 this.logger.write("full", "\tquerySource method is started."); 7904 Vector vecVektor = new Vector(); 7905 String strQuery = "select "; 7906 // this is pointer where transformations columns starts within result 7907 // set 7908 // this.iOffsetForTransColumns = 0; 7909 while (i < this.iTables) { 7910 vecVektor = (Vector) this.vecSourceColumnName.get(i); 7911 // this.iOffsetForTransColumns += vecVektor.size(); 7912 while (j < Integer.parseInt(this.vecValueColumnsTargetTables.get(i) 7913 .toString())) { 7914 strQuery = strQuery + vecVektor.get(j).toString() + ", "; 7915 j++; 7916 this.iColumnsInSourceTable++; 7917 } 7918 j = 0; 7919 i++; 7920 } 7921 ArrayList trans = this.transformations.getTransformations(); 7922 // int numTransSourceColumns = 0; 7923 // read all source columns for all transformations 7924 // i = 0; 7925 // while (i < this.iTables) { 7926 for (int k = 0; k < trans.size(); k++) { 7927 Transformation transformation = (Transformation) trans.get(k); 7928 // if( i != Integer.parseInt( transformation.getTargetTableID() ) ) 7929 // continue; 7930 Vector sourceColumnNames = transformation.getSourceColumnNames(); 7931 for (int kk = 0; kk < sourceColumnNames.size(); kk++) { 7932 strQuery = strQuery + sourceColumnNames.get(kk).toString() 7933 + ", "; 7934 // numTransSourceColumns++; 7935 } 7936 } 7937 // this.vecTransformColumnsTargetTables.add( 7938 // String.valueOf(numTransSourceColumns) ); 7939 // numTransSourceColumns=0; 7940 // i++; 7941 // } 7942 strQuery = strQuery.substring(0, strQuery.length() - 2); 7943 strQuery += " from " 7944 + importDefinitionElement.strImportDefinitionTableName; 7945 if (importDefinitionElement.vecRestartCounterSortColumn.size() != 0) { 7946 if (configReaderSource.getEnableOrderBy()) { 7947 strQuery += " order by "; 7948 for (j = 0; j < importDefinitionElement.vecRestartCounterSortColumn 7949 .size(); j++) { 7950 strQuery += importDefinitionElement.vecRestartCounterSortColumn 7951 .get(j).toString() 7952 + ", "; 7953 } 7954 strQuery = strQuery.substring(0, strQuery.length() - 2); 7955 } 7956 } 7957 7958 this.logger.write("full", "\tquerySource method is finished."); 7959 return strQuery; 7960 } 7961 7962 /*** 7963 * Method targetColumnTypes is used to put source table column types into 7964 * Vector "vecSourceColumnType". This includes columns from the querySource 7965 * method. If there is an error, Exception "SQLException" or 7966 * NullPointerException is thrown. 7967 * 7968 * @param connTarget 7969 * Connection to the target table. 7970 * @throws SQLException 7971 * Constructs an SQLException object with a reason. 7972 * @throws NullPointerException 7973 * Constructs a NullPointerException with the specified detail 7974 * message. 7975 */ 7976 private void targetColumnTypes(Connection connTarget) throws SQLException, 7977 NullPointerException { 7978 int iColumn; 7979 String strQueryTypes = ""; 7980 this.logger.write("full", "\ttargetColumnTypes method is started."); 7981 try { 7982 for (int i = 0; i < this.iTables; i++) { 7983 Vector vecKeyTypesRelations = new Vector(); 7984 Vector vecVektor = new Vector(); 7985 iColumn = 0; 7986 Statement stmtTypes = connTarget.createStatement(); 7987 // ZK added 11.6.2004 because of new parameter 7988 // GetMaxRowsSupported 7989 if (this.configReaderTarget.getMaxRowsSupported()) { 7990 stmtTypes.setMaxRows(1); 7991 } 7992 7993 strQueryTypes = "select "; 7994 for (int j = 0; j < ((Vector) this.vecTargetColumnName.get(i)) 7995 .size(); j++) { 7996 strQueryTypes += (((Vector) this.vecTargetColumnName.get(i)) 7997 .get(j).toString()) 7998 + ","; 7999 } 8000 for (int j = 0; j < ((Vector) this.vecRelationKeyColumns.get(i)) 8001 .size(); j++) { 8002 strQueryTypes += (((Vector) this.vecRelationKeyColumns 8003 .get(i)).get(j).toString()) 8004 + ","; 8005 } 8006 strQueryTypes = strQueryTypes.substring(0, strQueryTypes 8007 .length() - 1); 8008 strQueryTypes += " from "; 8009 strQueryTypes += " " + this.vecTableTableName.get(i).toString(); 8010 8011 if (((Vector) this.vecTargetColumnName.get(i)).size() != 0 8012 || ((Vector) this.vecRelationKeyColumns.get(i)).size() != 0) { 8013 8014 this.logger.write("full", "\tQuery '" + strQueryTypes 8015 + "' will be executed"); 8016 ResultSet rsetTypes = stmtTypes.executeQuery(strQueryTypes); 8017 for (int j = 0; j < ((Vector) this.vecValueMode.get(i)) 8018 .size(); j++) { 8019 iColumn++; 8020 if (this.iTargetFirstColumnResult == 1) 8021 vecVektor.add(rsetTypes.getMetaData() 8022 .getColumnTypeName(iColumn)); 8023 else 8024 vecVektor.add(rsetTypes.getMetaData() 8025 .getColumnTypeName(iColumn - 1)); 8026 } 8027 for (int j = 0; j < ((Vector) this.vecRelationKeyColumns 8028 .get(i)).size(); j++) { 8029 iColumn++; 8030 if (this.iTargetFirstColumnResult == 1) 8031 vecKeyTypesRelations.add(rsetTypes.getMetaData() 8032 .getColumnTypeName(iColumn)); 8033 else 8034 vecKeyTypesRelations.add(rsetTypes.getMetaData() 8035 .getColumnTypeName(iColumn - 1)); 8036 } 8037 rsetTypes.close(); 8038 } 8039 stmtTypes.close(); 8040 this.vecRelationKeyTypes.setElementAt(vecKeyTypesRelations, i); 8041 this.vecTargetColumnType.add(vecVektor); 8042 } 8043 Statement stmtVariableTypes = connTarget.createStatement(); 8044 if (this.configReaderTarget.getMaxRowsSupported()) { 8045 stmtVariableTypes.setMaxRows(1); 8046 } 8047 for (int j = 0; j < this.vecVariableColumnTargetTableName.size(); j++) { 8048 strQueryTypes = "select "; 8049 strQueryTypes += this.vecVariableColumnTargetColumnName.get(j) 8050 .toString() 8051 + " from "; 8052 strQueryTypes += this.vecVariableColumnTargetTableName.get(j) 8053 .toString(); 8054 ResultSet rsetVariableTypes; 8055 this.logger.write("full", "\tQuery '" + strQueryTypes 8056 + "' will be executed"); 8057 rsetVariableTypes = stmtVariableTypes 8058 .executeQuery(strQueryTypes); 8059 if (this.iTargetFirstColumnResult == 1) 8060 this.vecVariableColumnTypes.add(rsetVariableTypes 8061 .getMetaData().getColumnTypeName(1)); 8062 else 8063 this.vecVariableColumnTypes.add(rsetVariableTypes 8064 .getMetaData().getColumnTypeName(0)); 8065 rsetVariableTypes.close(); 8066 } 8067 stmtVariableTypes.close(); 8068 } catch (SQLException ex) { 8069 throw ex; 8070 } catch (NullPointerException ex) { 8071 throw ex; 8072 } 8073 this.logger.write("full", "\ttargetColumnTypes method is finished."); 8074 } 8075 8076 /*** 8077 * Metod createCurrentDate is used to create current date and time in format 8078 * that supported by SQL server. 8079 * 8080 * @return String representation of current date and time. 8081 */ 8082 private String createCurrentDate() { 8083 8084 // it is read from configReaderSource because before call to setDate on 8085 // target database, it will be parsed using date format 8086 // from source config and transformed into java.sql.Date 8087 String strDateTimeFormat = this.configReaderSource.getDateFormat(); 8088 SimpleDateFormat tmpDate = new SimpleDateFormat(strDateTimeFormat); 8089 String strDate = tmpDate.format(new Date(System.currentTimeMillis())); 8090 return strDate; 8091 8092 } 8093 8094 /*** 8095 * Method constantColumnTypes is used to put types of constant columns into 8096 * global vector sorted in target tables.If there is an error, Exception 8097 * "SQLException" or "NullPointerException" is thrown. 8098 * 8099 * @param c 8100 * Connection to target database. 8101 * @throws SQLException 8102 * Constructs an SQLException object with a reason. 8103 * @throws NullPointerException 8104 * Constructs a NullPointerException with the specified detail 8105 * message. 8106 */ 8107 private void constantColumnTypes(Connection c) throws SQLException, 8108 NullPointerException { 8109 int iCnt = 0; 8110 this.logger.write("full", "\tconstantColumnTypes method is started."); 8111 try { 8112 for (int i = 0; i < this.iTables; i++) { 8113 Vector vecTempConstantType = new Vector(); 8114 Vector vecTempConstantName = new Vector(); 8115 String strQuery = "select "; 8116 vecTempConstantName = (Vector) this.vecConstantTargetColumnName 8117 .get(i); 8118 if (vecTempConstantName.size() != 0) { 8119 Statement stmtConstant = c.createStatement(); 8120 for (int j = 0; j < vecTempConstantName.size(); j++) 8121 strQuery += vecTempConstantName.get(j).toString() 8122 + ", "; 8123 strQuery = strQuery.substring(0, strQuery.length() - 2); 8124 strQuery += " from " 8125 + this.vecTableTableName.get(i).toString(); 8126 this.logger.write("full", "\tQuery '" + strQuery 8127 + "' will be executed"); 8128 ResultSet rsetConstant = stmtConstant 8129 .executeQuery(strQuery); 8130 iCnt = vecTempConstantName.size(); 8131 for (int k = 0; k < iCnt; k++) { 8132 if (this.iTargetFirstColumnResult == 1) 8133 vecTempConstantType.add(rsetConstant.getMetaData() 8134 .getColumnTypeName(k + 1)); 8135 else 8136 vecTempConstantType.add(rsetConstant.getMetaData() 8137 .getColumnTypeName(k)); 8138 } 8139 rsetConstant.close(); 8140 stmtConstant.close(); 8141 } 8142 this.vecConstantColumnType.setElementAt(vecTempConstantType, i); 8143 } 8144 } catch (SQLException ex) { 8145 throw ex; 8146 } catch (NullPointerException ex) { 8147 throw ex; 8148 } 8149 this.logger.write("full", "\tconstantColumnTypes method is finished."); 8150 } 8151 8152 /*** 8153 * Method inputUser is used to give a user the possibility to connect to 8154 * Source and Target database using user name and password. If missing, user 8155 * and password parameters for database in XML file, Loader asks user for 8156 * these parameters. If there is an error, Exception "IOException" is 8157 * thrown. 8158 * 8159 * @param b 8160 * Boolean type. If b is true- source database, false- target 8161 * database 8162 * @throws IOException 8163 * Constructs an IOException with the specified detail message. 8164 */ 8165 private void inputUser(boolean b) throws java.io.IOException { 8166 if (b) { 8167 if (BufferOctopusClass.getInstance().IsUsed()) 8168 throw new IOException( 8169 "Missing user name and password for the Source DB. Check LoaderJob.olj file!"); 8170 else 8171 this.logger.write("normal", 8172 "Missing user name and password for the Source DB."); 8173 } else { 8174 if (BufferOctopusClass.getInstance().IsUsed()) 8175 throw new IOException( 8176 "Missing user name and password for the Target DB. Check LoaderJob.olj file!"); 8177 else 8178 this.logger.write("normal", 8179 "Missing user name and password for the Target DB."); 8180 } 8181 String strUserName; 8182 String strPassword; 8183 char cu; 8184 char cp; 8185 StringBuffer bufu = new StringBuffer(); 8186 StringBuffer bufp = new StringBuffer(); 8187 System.out.println("User name: "); 8188 try { 8189 while ((cu = (char) System.in.read()) != '\n') 8190 bufu.append(cu); 8191 strUserName = bufu.toString(); 8192 strUserName = strUserName.substring(0, strUserName.length() - 1); 8193 System.out.println("Password: "); 8194 while ((cp = (char) System.in.read()) != '\n') 8195 bufp.append(cp); 8196 strPassword = bufp.toString(); 8197 if (strPassword.length() != 0) 8198 strPassword = strPassword 8199 .substring(0, strPassword.length() - 1); 8200 if (b) { 8201 jdbcParametersElement.setJDBCSourceParameterUser(strUserName); 8202 jdbcParametersElement 8203 .setJDBCSourceParameterPassword(strPassword); 8204 } else { 8205 jdbcParametersElement.setJDBCTargetParameterUser(strUserName); 8206 jdbcParametersElement 8207 .setJDBCTargetParameterPassword(strPassword); 8208 } 8209 } catch (IOException ex) { 8210 throw ex; 8211 } 8212 } 8213 8214 /*** 8215 * Method changeTableOrder change order of Tables into public Vector 8216 * vecTableTableName Relation source tables puts before the others target 8217 * tables. 8218 */ 8219 private void changeTableOrder() { 8220 Vector vecTempTableTableName = new Vector(); 8221 Vector vecTempTableTableID = new Vector(); 8222 Vector vecTempTableInsert = new Vector(); 8223 Vector vecTempTableTableMode = new Vector(); 8224 Vector vecTempTableOidLogic = new Vector(); 8225 Vector vecNumberOfTable = new Vector(); 8226 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) { 8227 int iNumberOfTable = 0; 8228 for (int j = 0; j < this.vecTableTableName.size(); j++) { 8229 if (this.vecTableTableName.get(j).toString() 8230 .equalsIgnoreCase( 8231 this.vecRelationColumnSourceTableName.get(i) 8232 .toString()) 8233 && this.vecTableTableID.get(j).toString() 8234 .equalsIgnoreCase( 8235 this.vecRelationColumnSourceTableID 8236 .get(i).toString())) { 8237 iNumberOfTable = j; 8238 boolean bEqualsRelationSource = false; 8239 for (int k = 0; k < vecNumberOfTable.size(); k++) { 8240 if (j == (new Integer(vecNumberOfTable.get(k) 8241 .toString())).intValue()) 8242 bEqualsRelationSource = true; 8243 } 8244 if (!bEqualsRelationSource) { 8245 vecTempTableTableName.addElement(this.vecTableTableName 8246 .get(j).toString()); 8247 vecTempTableTableID.addElement(this.vecTableTableID 8248 .get(j).toString()); 8249 vecTempTableInsert.addElement(this.vecTableInsert 8250 .get(j).toString()); 8251 vecTempTableTableMode.addElement(this.vecTableTableMode 8252 .get(j).toString()); 8253 vecTempTableOidLogic.addElement(this.vecTableOidLogic 8254 .get(j).toString()); 8255 vecNumberOfTable 8256 .addElement(new Integer(iNumberOfTable)); 8257 } 8258 } 8259 } 8260 } 8261 if (this.vecRelationColumnSourceTableName.size() != 0) { 8262 for (int i = 0; i < this.vecTableTableName.size(); i++) { 8263 boolean bEquals = false; 8264 for (int j = 0; j < vecNumberOfTable.size(); j++) { 8265 if (i == (new Integer(vecNumberOfTable.get(j).toString())) 8266 .intValue()) { 8267 bEquals = true; 8268 } 8269 } 8270 if (!bEquals) { 8271 vecTempTableTableName.addElement(this.vecTableTableName 8272 .get(i).toString()); 8273 vecTempTableTableID.addElement(this.vecTableTableID.get(i) 8274 .toString()); 8275 vecTempTableInsert.addElement(this.vecTableInsert.get(i) 8276 .toString()); 8277 vecTempTableTableMode.addElement(this.vecTableTableMode 8278 .get(i).toString()); 8279 vecTempTableOidLogic.addElement(this.vecTableOidLogic 8280 .get(i).toString()); 8281 } 8282 } 8283 this.vecTableTableName = new Vector(); 8284 this.vecTableTableID = new Vector(); 8285 this.vecTableInsert = new Vector(); 8286 this.vecTableTableMode = new Vector(); 8287 this.vecTableOidLogic = new Vector(); 8288 for (int i = 0; i < vecTempTableTableName.size(); i++) { 8289 this.vecTableTableName.addElement(vecTempTableTableName.get(i) 8290 .toString()); 8291 this.vecTableTableID.addElement(vecTempTableTableID.get(i) 8292 .toString()); 8293 this.vecTableInsert.addElement(vecTempTableInsert.get(i) 8294 .toString()); 8295 this.vecTableTableMode.addElement(vecTempTableTableMode.get(i) 8296 .toString()); 8297 this.vecTableOidLogic.addElement(vecTempTableOidLogic.get(i) 8298 .toString()); 8299 } 8300 } 8301 } 8302 8303 /*** 8304 * Method changeRelationsOrder change order of relation tags. Order of 8305 * relation tags depends of 'complex relations'. Method puts at the begining 8306 * of relation global Vectors relations which is used only to read source 8307 * values for another relation. 8308 * 8309 */ 8310 private void changeRelationsOrder() { 8311 Vector vecTempSourceTableName = new Vector(); 8312 Vector vecTempSourceTableID = new Vector(); 8313 Vector vecTempSourceColumnName = new Vector(); 8314 Vector vecTempTargetTableName = new Vector(); 8315 Vector vecTempTargetTableID = new Vector(); 8316 Vector vecTempTargetColumnName = new Vector(); 8317 Vector vecTempRelationMode = new Vector(); 8318 Vector vecRelationsOrder = new Vector(); 8319 vecRelationsOrder.setSize(this.vecRelationColumnSourceTableName.size()); 8320 for (int i = 0; i < vecRelationsOrder.size(); i++) 8321 vecRelationsOrder.setElementAt(new Integer(i), i); 8322 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) { 8323 if (this.vecRelationColumnRelationMode.get(i).toString() 8324 .equalsIgnoreCase("Key")) { 8325 for (int j = 0; j < this.vecRelationColumnSourceTableName 8326 .size(); j++) { 8327 if (this.vecRelationColumnSourceTableName.get(i).toString() 8328 .equalsIgnoreCase( 8329 this.vecRelationColumnTargetTableName 8330 .get(j).toString()) 8331 && this.vecRelationColumnSourceTableID.get(i) 8332 .toString().equalsIgnoreCase( 8333 this.vecRelationColumnTargetTableID 8334 .get(j).toString())) 8335 vecRelationsOrder = this.setAfter(vecRelationsOrder, i, 8336 j); 8337 } 8338 } else { 8339 vecRelationsOrder = this.setLast(vecRelationsOrder, i); 8340 } 8341 } 8342 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) { 8343 vecTempSourceTableName.add(this.vecRelationColumnSourceTableName 8344 .get(i)); 8345 vecTempSourceTableID 8346 .add(this.vecRelationColumnSourceTableID.get(i)); 8347 vecTempSourceColumnName.add(this.vecRelationColumnSourceColumnName 8348 .get(i)); 8349 vecTempTargetTableName.add(this.vecRelationColumnTargetTableName 8350 .get(i)); 8351 vecTempTargetTableID 8352 .add(this.vecRelationColumnTargetTableID.get(i)); 8353 vecTempTargetColumnName.add(this.vecRelationColumnTargetColumnName 8354 .get(i)); 8355 vecTempRelationMode.add(this.vecRelationColumnRelationMode.get(i)); 8356 } 8357 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) { 8358 this.vecRelationColumnSourceTableName.setElementAt( 8359 vecTempSourceTableName.get(Integer 8360 .parseInt(vecRelationsOrder.get(i).toString())), i); 8361 this.vecRelationColumnSourceTableID.setElementAt( 8362 vecTempSourceTableID.get(Integer.parseInt(vecRelationsOrder 8363 .get(i).toString())), i); 8364 this.vecRelationColumnSourceColumnName.setElementAt( 8365 vecTempSourceColumnName.get(Integer 8366 .parseInt(vecRelationsOrder.get(i).toString())), i); 8367 this.vecRelationColumnTargetTableName.setElementAt( 8368 vecTempTargetTableName.get(Integer 8369 .parseInt(vecRelationsOrder.get(i).toString())), i); 8370 this.vecRelationColumnTargetTableID.setElementAt( 8371 vecTempTargetTableID.get(Integer.parseInt(vecRelationsOrder 8372 .get(i).toString())), i); 8373 this.vecRelationColumnTargetColumnName.setElementAt( 8374 vecTempTargetColumnName.get(Integer 8375 .parseInt(vecRelationsOrder.get(i).toString())), i); 8376 this.vecRelationColumnRelationMode.setElementAt( 8377 vecTempRelationMode.get(Integer.parseInt(vecRelationsOrder 8378 .get(i).toString())), i); 8379 } 8380 } 8381 8382 /*** 8383 * Method setLast changes order of vecOrder's elements. Element at 8384 * iRelationTag position will be removed and inserted at the end of Vector. 8385 * 8386 * @param vecOrder 8387 * Vector - order of relation tags 8388 * @param iRelationTag 8389 * integer - position of element in Vector which changes its 8390 * position. 8391 * @return Vector - order of relation tags after changing positions of 8392 * elements. 8393 */ 8394 private Vector setLast(Vector vecOrder, int iRelationTag) { 8395 int iLast = vecOrder.indexOf(new Integer(iRelationTag)); 8396 vecOrder.remove(iLast); 8397 vecOrder.add(new Integer(iRelationTag)); 8398 return vecOrder; 8399 } 8400 8401 /*** 8402 * Method setAfter changes order of vecOrder's elements. Element at 8403 * iIndexCurrent position will be removed and inserted after element at 8404 * iIndexTarget position. 8405 * 8406 * @param vecOrder 8407 * Vector - order of relation tags 8408 * @param iIndexCurrent 8409 * integer - position of element in Vector which changes its 8410 * position. 8411 * @param iIndexTarget 8412 * integer - position of 'target' element in Vector . 8413 * @return Vector - order of relation tags after changing element's 8414 * positions. 8415 */ 8416 Vector setAfter(Vector vecOrder, int iIndexCurrent, int iIndexTarget) { 8417 if (iIndexCurrent < iIndexTarget) { 8418 int iCurrent = vecOrder.indexOf(new Integer(iIndexCurrent)); 8419 vecOrder.remove(iCurrent); 8420 int iTarget = vecOrder.indexOf(new Integer(iIndexTarget)); 8421 vecOrder.insertElementAt(new Integer(iIndexCurrent), iTarget + 1); 8422 } 8423 return vecOrder; 8424 } 8425 8426 /*** 8427 * Method executeSQLStatement is used to execute SQL statement. This method 8428 * executes and commit changes immediately. JDBC parameters, Continue on 8429 * Error parameters and SQL statements are set in XML file. If there is an 8430 * error Exception "Exception" is thrown. 8431 * 8432 * @throws Exception 8433 */ 8434 private void executeSQLStatement() throws Exception { 8435 Connection conn = null; 8436 try { 8437 this.logger 8438 .write("full", "\tmethod executeSQLStatement is started"); 8439 // this.logger.write("normal", "SQL statement " + this.strSqlName + 8440 // " is started"); 8441 Class.forName(jdbcParametersElement.getJDBCTargetParameterDriver()); 8442 conn = DriverManager.getConnection(jdbcParametersElement 8443 .getJDBCTargetParameterConnection(), jdbcParametersElement 8444 .getJDBCTargetParameterUser(), jdbcParametersElement 8445 .getJDBCTargetParameterPassword()); 8446 Statement stmtSeparate = conn.createStatement(); 8447 for (int i = 0; i < this.vecSqlStmt.size(); i++) { 8448 this.logger.write("full", "\tSQL_stmt : '" 8449 + this.vecSqlStmt.get(i).toString() 8450 + "' will be executed"); 8451 Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt 8452 .get(i).toString()); 8453 for (int j = 0; j < vecSingleSqlStmt.size(); j++) { 8454 executeSql(stmtSeparate, 8455 vecSingleSqlStmt.get(j).toString(), 0); 8456 } 8457 } 8458 stmtSeparate.close(); 8459 conn.close(); 8460 } catch (SQLException e) { 8461 throw e; 8462 } finally { 8463 if (conn != null && !conn.isClosed()) 8464 conn.close(); 8465 } 8466 } 8467 8468 /*** 8469 * Method executeSQLStatement is used to execute SQL statement. This method 8470 * commit changes immediately only if is commit paremeter true. If it is 8471 * false commit changes after all aql stetements. JDBC parameters, Continue 8472 * on Error parameters and SQL statements are set in XML file. If there is 8473 * an error Exception "Exception" is thrown. 8474 * 8475 * @param conn 8476 * represents connection to target table 8477 * @throws Exception 8478 */ 8479 private void executeSQLStatement(Connection conn) throws Exception { 8480 try { 8481 this.timeCounter.setStartJobTime(); 8482 this.logger 8483 .write("full", "\tmethod executeSQLStatement is started"); 8484 this.logger.write("normal", "SQL statement " 8485 + sqlElement.getSqlName() + " is started"); 8486 boolean isCreateDatabaseStatement = false; 8487 out: for (int i = 0; i < this.vecSqlStmt.size(); i++) { 8488 if (this.vecSqlStmt.get(i).toString().toUpperCase().trim() 8489 .startsWith("CREATE DATABASE") 8490 || this.vecSqlStmt.get(i).toString().toUpperCase() 8491 .trim().startsWith("DROP DATABASE")) { 8492 isCreateDatabaseStatement = true; 8493 break out; 8494 } 8495 } 8496 if (isCreateDatabaseStatement) { 8497 executeSQLStatement(); 8498 } else { 8499 8500 Statement stmtSeparate = conn.createStatement(); 8501 for (int i = 0; i < this.vecSqlStmt.size(); i++) { 8502 this.logger.write("full", "\tSQL_stmt : '" 8503 + this.vecSqlStmt.get(i).toString() 8504 + "' will be executed"); 8505 Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt 8506 .get(i).toString()); 8507 for (int j = 0; j < vecSingleSqlStmt.size(); j++) { 8508 executeSql(stmtSeparate, vecSingleSqlStmt.get(j) 8509 .toString(), j + 1); 8510 } 8511 } 8512 if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) { 8513 if (!conn.getAutoCommit()) 8514 conn.commit(); 8515 } 8516 stmtSeparate.close(); 8517 } 8518 8519 this.logger.write("normal", "SQL statement " 8520 + sqlElement.getSqlName() + " is finished"); 8521 this.logger.write("full", 8522 "\tmethod executeSQLStatement is finished"); 8523 this.logger.write("normal", " Duration :" 8524 + this.timeCounter.getJobTime()); 8525 } catch (SQLException e) { 8526 throw e; 8527 } 8528 } 8529 8530 /*** 8531 * Method sqlStringToVector is used to cut Sql string with number of 8532 * statements into vector whose elements are single Sql statemnets. 8533 * 8534 * @param sql 8535 * Sql string with number of statements. 8536 * @return vector of sql statemetns 8537 */ 8538 private Vector sqlStringToVector(String sql) { 8539 Vector vecSqlString = new Vector(); 8540 int i = sql.indexOf(";"); 8541 if (i != -1) { 8542 while (i != -1) { 8543 // vecSqlString.add(sql.substring(0, i + 1)); 8544 vecSqlString.add(sql.substring(0, i)); 8545 sql = sql.substring(i + 1); 8546 i = sql.indexOf(";"); 8547 } 8548 } else 8549 8550 // vecSqlString.add(sql.trim() + ";"); 8551 vecSqlString.add(sql.trim()); 8552 return vecSqlString; 8553 } 8554 8555 /*** 8556 * Method executeSql is used to execute singl Sql statement. If there is an 8557 * error depends on OnErrorContinue parameter throws exception or not. Error 8558 * message is always shown. If there is an error, message with the error 8559 * message, statement and number of statement is shown. 8560 * 8561 * @param stmtSql 8562 * Statement. 8563 * @param sqlStmt 8564 * Sql statement to execute. 8565 * @param i 8566 * Number of the Sql statement. 8567 * @throws SQLException 8568 */ 8569 private void executeSql(Statement stmtSql, String sqlStmt, int i) 8570 throws SQLException { 8571 try { 8572 if (bReplaceInData) { 8573 sqlStmt = this.replaceInData(sqlStmt); 8574 } 8575 sqlStmt.trim(); 8576 if (sqlStmt.length() != 0) 8577 stmtSql.execute(sqlStmt); 8578 } catch (SQLException e) { 8579 if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase("true")) { 8580 if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) 8581 this.logger.write("normal", "\t Error in SQL statement: " 8582 + sqlStmt 8583 + " executing SQL statements continue..."); 8584 else 8585 this.logger 8586 .write( 8587 "normal", 8588 "\t Error in SQL statement: " 8589 + sqlStmt 8590 + " \n\tStatement is number: " 8591 + i 8592 + " all statements before it is not commited, executing SQL statements continue..."); 8593 LoaderException le = new LoaderException("SQLException: ", 8594 (Throwable) e); 8595 this.logger.write("full", le.getStackTraceAsString()); 8596 // this.logger.write("normal", "\t " + e.getMessage()); 8597 } else { 8598 this.logger.write("normal", "\t Error in SQL statement: " 8599 + sqlStmt); 8600 throw e; 8601 } 8602 } 8603 } 8604 8605 /*** 8606 * Method checkSortColumns checks if sort columns in source table have 8607 * unique values. If source table have more rows with equal values in sort 8608 * columns return true, if not return false. 8609 * 8610 * @param connSource - 8611 * Connection to the source table. 8612 * @return boolean - true - source table has more rows with equal values in 8613 * sort columns, false - if source table has unique values in sort 8614 * columns. 8615 * @throws LoaderException 8616 * with the specified detail message. 8617 */ 8618 private boolean checkSortColumns(Connection connSource) 8619 throws LoaderException { 8620 boolean isEqualValues = false; 8621 String strQuery = "select "; 8622 try { 8623 this.logger.write("full", "\tmethod checkSortColumns is started"); 8624 for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn 8625 .size(); i++) 8626 strQuery += importDefinitionElement.vecRestartCounterSortColumn 8627 .get(i).toString() 8628 + ","; 8629 strQuery = strQuery.substring(0, strQuery.length() - 1); 8630 strQuery += " from " 8631 + importDefinitionElement.strImportDefinitionTableName; 8632 strQuery += " order by "; 8633 for (int j = 0; j < importDefinitionElement.vecRestartCounterSortColumn 8634 .size(); j++) 8635 strQuery += importDefinitionElement.vecRestartCounterSortColumn 8636 .get(j).toString() 8637 + ", "; 8638 strQuery = strQuery.substring(0, strQuery.length() - 2); 8639 this.logger.write("full", "\tQuery '" + strQuery + "' executes"); 8640 Statement stmtSort = connSource.createStatement(); 8641 ResultSet rsetSort = stmtSort.executeQuery(strQuery); 8642 endWhile: while (rsetSort.next()) { 8643 Vector vecSortNewValues = new Vector(); 8644 for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn 8645 .size(); i++) 8646 vecSortNewValues.add(rsetSort.getString(i + 1)); 8647 if (vecSortNewValues.equals(this.vecSortValues)) { 8648 isEqualValues = true; 8649 break endWhile; 8650 } else { 8651 this.vecSortValues = new Vector(); 8652 for (int i = 0; i < importDefinitionElement.vecRestartCounterSortColumn 8653 .size(); i++) 8654 this.vecSortValues.add(vecSortNewValues.get(i)); 8655 } 8656 } 8657 rsetSort.close(); 8658 stmtSort.close(); 8659 } catch (SQLException e) { 8660 LoaderException le = new LoaderException("SQLException: ", 8661 (Throwable) e); 8662 // this.logger.write("normal", le.getCause().toString()); 8663 this.logger.write("full", le.getStackTraceAsString()); 8664 throw le; 8665 } 8666 this.logger.write("full", "\tmethod checkSortColumns is finished"); 8667 return isEqualValues; 8668 } 8669 8670 /*** 8671 * put your documentation comment here 8672 * 8673 * @param conn 8674 * represents connection 8675 * @exception LoaderException 8676 */ 8677 private void createObjectIDTable(Connection conn) throws LoaderException { 8678 try { 8679 Statement stmt = conn.createStatement(); 8680 String sqlStmt = ""; 8681 if (!(importDefinitionElement.strObjectIDNameColumnName.equals("") || importDefinitionElement.strObjectIDNameColumnValue 8682 .equals(""))) { 8683 sqlStmt = "create table " 8684 + importDefinitionElement.strObjectIDTableName + " (" 8685 + importDefinitionElement.strObjectIDColumnName 8686 + " VARCHAR(30) ," 8687 + importDefinitionElement.strObjectIDNameColumnName 8688 + " VARCHAR(30)) NOT NULL;"; 8689 8690 } else { 8691 sqlStmt = "create table " 8692 + importDefinitionElement.strObjectIDTableName + " (" 8693 + importDefinitionElement.strObjectIDColumnName 8694 + " DECIMAL(19,0) NOT NULL);"; 8695 } 8696 stmt.execute(sqlStmt); 8697 String insert = ""; 8698 if (!(importDefinitionElement.strObjectIDNameColumnName.equals("") || importDefinitionElement.strObjectIDNameColumnValue 8699 .equals(""))) { 8700 insert = "insert " 8701 + importDefinitionElement.strObjectIDTableName + " (" 8702 + importDefinitionElement.strObjectIDNameColumnName 8703 + "," + importDefinitionElement.strObjectIDColumnName 8704 + ") values ('" 8705 + importDefinitionElement.strObjectIDNameColumnValue 8706 + "','" + importDefinitionElement.iObjectIDStartValue 8707 + "');"; 8708 } else { 8709 insert = "insert " 8710 + importDefinitionElement.strObjectIDTableName + " (" 8711 + importDefinitionElement.strObjectIDColumnName 8712 + ") values (" 8713 + importDefinitionElement.iObjectIDStartValue + ");"; 8714 } 8715 if (bReplaceInData) { 8716 insert = this.replaceInData(insert); 8717 } 8718 stmt.execute(insert); 8719 conn.commit(); 8720 stmt.close(); 8721 } catch (SQLException e) { 8722 LoaderException le = new LoaderException("SQLException: ", 8723 (Throwable) e); 8724 // this.logger.write("normal", le.getCause().toString()); 8725 this.logger.write("full", le.getStackTraceAsString()); 8726 throw le; 8727 } 8728 } 8729 8730 /*** 8731 * put your documentation comment here 8732 * 8733 * @param values 8734 * represents map values 8735 * @return those values 8736 */ 8737 private static Map convertToMap(String values) { 8738 Map mapValues = new HashMap(); 8739 int i = values.indexOf(";"); 8740 int k = 0; 8741 String part = new String(values); 8742 if (i != -1) { 8743 while (i != -1) { 8744 part = new String(values.substring(k, k + i)); 8745 int j = part.indexOf("="); 8746 String strObject = part.substring(0, j); 8747 String strValue = part.substring(j + 1); 8748 if (strValue.equals("")) 8749 strValue = null; 8750 mapValues.put(strObject, strValue); 8751 k += i + 1; 8752 i = values.substring(k).indexOf(";"); 8753 } 8754 if (!(values.substring(k).trim().equals("") || values.substring(k) 8755 .trim().equals(";"))) { 8756 part = new String(values.substring(k)); 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 } 8764 } else { 8765 int j = values.indexOf("="); 8766 String strObject = values.substring(k, j); 8767 String strValue = values.substring(j + 1); 8768 if (strValue.equals("")) 8769 strValue = null; 8770 mapValues.put(strObject, strValue); 8771 } 8772 return mapValues; 8773 } 8774 8775 /*** 8776 * Method replaceInData replace data in string if there is the same variable 8777 * as in attribut prefix+name+suffix in variable tag. 8778 * 8779 * @param s - 8780 * String to replace. 8781 * @return s 8782 */ 8783 private String replaceInData(String s) { 8784 // going throw vector 8785 for (int k = 0; k < this.vecReplaceInData.size(); k++) { 8786 // if this is to change... 8787 if (this.vecReplaceInData.get(k).toString() 8788 .equalsIgnoreCase("true")) { 8789 String sPreNameSu = this.vecVariablePrefix.get(k).toString() 8790 + this.vecVariableName.get(k).toString() 8791 + this.vecVariableSufix.get(k).toString(); 8792 int j = s.indexOf(sPreNameSu); 8793 // if costant is variable 8794 while (j != -1) { 8795 s = s.substring(0, j) 8796 + this.vecVariableValue.get(k).toString() 8797 + s.substring(j + sPreNameSu.length(), s.length()); 8798 j = s.indexOf(sPreNameSu); 8799 } 8800 } 8801 } 8802 return s; 8803 } 8804 8805 /*** 8806 * Method replaceInSelectStatement replace data in string if there is the 8807 * same variable as in attribut prefix+name+suffix in variable tag. 8808 * 8809 * @param s - 8810 * String to replace. 8811 * @return s 8812 */ 8813 // private String replaceInSelectStatement(String s) { 8814 // // going throw vector 8815 // for (int k = 0; k < this.vecVariableValue.size(); k++) { 8816 // if( this.vecReplaceInSQL.get(k).toString().equalsIgnoreCase("false")) 8817 // continue; 8818 // String sPreNameSu = this.vecVariablePrefix.get(k).toString() 8819 // + this.vecVariableName.get(k).toString() + 8820 // this.vecVariableSufix.get(k).toString(); 8821 // int j = s.indexOf(sPreNameSu); 8822 // 8823 // while (j != -1) { 8824 // s = s.substring(0, j) + this.vecVariableValue.get(k).toString() 8825 // + s.substring(j + sPreNameSu.length(), s.length()); 8826 // j = s.indexOf(sPreNameSu); 8827 // } 8828 // } 8829 // return s; 8830 // } 8831 /*** 8832 * @param s - 8833 * String to replace. 8834 * @param oldChar - 8835 * Char 8836 * @param newValue - 8837 * String 8838 * @return s 8839 */ 8840 private String replaceChar(String s, char oldChar, String newValue) { 8841 8842 int j = s.indexOf(oldChar); 8843 String replacedString = ""; 8844 while (j != -1) { 8845 replacedString = replacedString + s.substring(0, j) + newValue; 8846 s = s.substring(j + 1); 8847 j = s.indexOf(oldChar); 8848 } 8849 replacedString = replacedString + s; 8850 return replacedString; 8851 } 8852 8853 /*** 8854 * Method resetGlobalVariables reset all global variables to the start 8855 * values after each importDefinition job. 8856 */ 8857 private void resetGlobalVariables() { 8858 importDefinitionElement.strImportDefinitionName = ""; 8859 importDefinitionElement.strImportDefinitionTableName = ""; 8860 importDefinitionElement.iImportDefinitionCommitCount = 0; 8861 // importDefinitionElement.strImportDefinitionLogMode = "normal"; 8862 importDefinitionElement.strImportDefinitionSelectStatement = ""; 8863 importDefinitionElement.bObjectIDAutoCreate = loaderJobReader 8864 .getDefaultObjectIDAutoCreate(); 8865 importDefinitionElement.iObjectIDStartValue = loaderJobReader 8866 .getDefaultObjectIDStartValue(); 8867 8868 importDefinitionElement.vecRestartCounterSortColumn = new Vector(); 8869 this.iValueColumns = 0; 8870 this.vecValueColumnsTargetTables = new Vector(); 8871 // this.vecTransformColumnsTargetTables = new Vector(); 8872 this.vecSourceColumnName = new Vector(); 8873 this.vecTargetColumnName = new Vector(); 8874 this.vecValueMode = new Vector(); 8875 this.vecTargetColumnValue = new Vector(); 8876 this.vecTargetKeyColumnName = new Vector(); 8877 this.iConstantColumns = 0; 8878 this.vecConstantTargetColumnName = new Vector(); 8879 this.vecConstantValueMode = new Vector(); 8880 this.vecConstantConstantValue = new Vector(); 8881 this.vecConstantColumnTargetTableName = new Vector(); 8882 this.vecConstantColumnTargetTableID = new Vector(); 8883 this.iRelationColumns = 0; 8884 this.vecRelationColumnSourceTableName = new Vector(); 8885 this.vecRelationColumnSourceTableID = new Vector(); 8886 this.vecRelationColumnSourceColumnName = new Vector(); 8887 this.vecRelationColumnTargetTableName = new Vector(); 8888 this.vecRelationColumnTargetColumnName = new Vector(); 8889 this.vecRelationColumnTargetTableID = new Vector(); 8890 this.vecRelationColumnRelationMode = new Vector(); 8891 this.iTables = 0; 8892 this.vecTableTableName = new Vector(); 8893 this.vecTableTableID = new Vector(); 8894 this.vecTableInsert = new Vector(); 8895 this.vecTableTableMode = new Vector(); 8896 this.vecTableOidLogic = new Vector(); 8897 this.vecRelationSourceValue = new Vector(); 8898 this.vecRelationSourceType = new Vector(); 8899 this.vecTargetColumnType = new Vector(); 8900 this.vecConstantColumnType = new Vector(); 8901 this.bdecOidNumber = new BigDecimal(0); 8902 this.bdecOidNumber2000 = new BigDecimal(0); 8903 importDefinitionElement.iObjectID = 0; 8904 importDefinitionElement.iObjectIDCT = 0; 8905 importDefinitionElement.strObjectIDTableName = ""; 8906 importDefinitionElement.strObjectIDColumnName = ""; 8907 // TOS 8908 importDefinitionElement.strObjectIDNameColumnName = ""; 8909 importDefinitionElement.strObjectIDNameColumnValue = ""; 8910 8911 this.vecVariableUseIDTableName = new Vector(); 8912 this.vecVariableUseIDTableID = new Vector(); 8913 this.vecVariableUseIDColumnName = new Vector(); 8914 this.vecVariableUseIDValueMode = new Vector(); 8915 this.vecVariableColumnName = new Vector(); 8916 this.vecVariableColumnTargetTableName = new Vector(); 8917 this.vecVariableColumnTargetTableID = new Vector(); 8918 this.vecVariableColumnTargetColumnName = new Vector(); 8919 this.vecVariableColumnValueMode = new Vector(); 8920 this.vecVariableColumnTypes = new Vector(); 8921 this.vecVariableTimesTableName = new Vector(); 8922 this.vecVariableTimesTableID = new Vector(); 8923 this.vecVariableTimesColumnName = new Vector(); 8924 this.vecVariableTimesValueMode = new Vector(); 8925 this.vecRelationKeyColumns = new Vector(); 8926 this.vecRelationKeyTypes = new Vector(); 8927 this.vecSortValues = new Vector(); 8928 this.vecSqlStmt = new Vector(); 8929 this.strSourceDriverName = ""; 8930 this.strTargetDriverName = ""; 8931 this.iFirstColumnResult = 1; 8932 this.iTargetFirstColumnResult = 1; 8933 this.iColumnsInSourceTable = 0; 8934 // copy table 8935 this.vecCTAutoMapp = new Vector(); 8936 this.vecCTDefaultMode = new Vector(); 8937 this.vecBlobVector = new Vector(); 8938 // added for transformations 8939 this.transformationsColumnNames = new Vector(); 8940 this.indexDTransformationOver = new Hashtable(); 8941 this.indexDTransformationNull = new Hashtable(); 8942 this.transformationsValueModes = new Vector(); 8943 this.transformationsColumnTypes = new Vector(); 8944 this.transformationValues = new Vector(); 8945 8946 } 8947 8948 private String replaceFirst(String input, String forReplace, 8949 String replaceWith) { 8950 String retVal = input; 8951 int start = input.indexOf(forReplace); 8952 int end = start + forReplace.length(); 8953 if (start != -1) { 8954 retVal = input.substring(0, start) + replaceWith 8955 + input.substring(end); 8956 } 8957 return retVal; 8958 } 8959 8960 /*** 8961 * This method write values for all input parameters to log file when log 8962 * level is full 8963 * 8964 * @throws LoaderException 8965 */ 8966 public String inputToString() throws LoaderException { 8967 String resString = ""; 8968 try { 8969 logger.write("full", "Log mode =" + getDefaultLogMode()); 8970 logger.write("full", "Restart indicator =" + getRestartIndicator()); 8971 logger.write("full", "UserID =" + getUserID()); 8972 Hashtable resHashtable = new Hashtable(); 8973 resHashtable = (Hashtable) getVariableValues(); 8974 String pom2 = ""; 8975 8976 if (resHashtable != null) { 8977 logger.write("full", "Variables =" + resHashtable.toString()); 8978 pom2 = "Variables =" + resHashtable.toString(); 8979 } else { 8980 logger.write("full", "Variables = null"); 8981 pom2 = "Variables = null"; 8982 } 8983 logger.write("full", "Log directory =" + getLogDirName()); 8984 logger.write("full", "Log file name =" + getLogFileName()); 8985 logger.write("full", "LoadJob file name =" + getLoadJobFileName()); 8986 logger.write("full", "On error continue =" + getOnErrorContinue()); 8987 logger.write("full", "Commit count =" + getCommitCount()); 8988 logger.write("full", "Return code =" + getDefaultReturnCode()); 8989 logger.write("full", "Vendor conf file =" + getVendorFileName()); 8990 8991 logger.write("full", "Include list ="); 8992 String pom1 = ""; 8993 pom1 = "Include list ="; 8994 String[] listOfJobs = getIncludedJobs(); 8995 for (int j = 0; j < listOfJobs.length; j++) { 8996 logger.write("full", listOfJobs[j].toString()); 8997 pom1 += listOfJobs[j].toString() + "\n"; 8998 } 8999 logger.write("full", "Path to conf files in jar =" 9000 + getConfJarStructure()); 9001 logger.write("full", "Additional paths =" + getAdditionalPaths()); 9002 resString = "Log mode =" + getDefaultLogMode() + "\n" 9003 + "Restart indicator =" + getRestartIndicator() + "\n" 9004 + "UserID =" + getUserID() + "\n" + pom2 + "\n" 9005 + "Log directory =" + getLogDirName() + "\n" 9006 + "Log file name =" + getLogFileName() + "\n" 9007 + "LoadJob file name =" + getLoadJobFileName() + "\n" 9008 + "On error continue =" + getOnErrorContinue() + "\n" 9009 + "Commit count =" + getCommitCount() + "\n" 9010 + "Return code =" + getDefaultReturnCode() + "\n" 9011 + "Vendor conf file =" + getVendorFileName() + "\n" + pom1 9012 + "\n" + "Path to conf files in jar =" 9013 + getConfJarStructure() + "\n" + "Additional paths =" 9014 + getAdditionalPaths() + "\n"; 9015 9016 return resString; 9017 } catch (Exception e) { 9018 9019 LoaderException le = new LoaderException("Exception:" 9020 + e.getMessage(), e); 9021 this.logger.write("full", le.getStackTraceAsString()); 9022 throw le; 9023 } 9024 9025 } 9026 9027 protected java.util.Date getDateFromString(String date) throws Exception { 9028 Date tmpDate = null; 9029 try { 9030 this.logger.write("full", "Try to parse date with src config: " 9031 + date); 9032 String format = this.configReaderSource.getDateFormat(); 9033 SimpleDateFormat formatDate = new SimpleDateFormat(format); 9034 tmpDate = formatDate.parse(date); 9035 } catch (ParseException e) { 9036 try { 9037 this.logger.write("full", 9038 "Try to parse date with target config: " + date); 9039 String format = this.configReaderTarget.getDateFormat(); 9040 SimpleDateFormat formatDate = new SimpleDateFormat(format); 9041 tmpDate = formatDate.parse(date); 9042 } catch (ParseException e1) { 9043 } 9044 } 9045 if (tmpDate != null) { 9046 return tmpDate; 9047 } else { 9048 throw new LoaderException("Unable to parse date: " + date); 9049 } 9050 } 9051 9052 protected void setValueOnStatement(String value, int javaTypeInt, int i, 9053 PreparedStatement pstmt) throws Exception { 9054 if (javaTypeInt == 2) { // java.math.BigDecimal 9055 if (!value.equalsIgnoreCase("null")) { 9056 BigDecimal number = new BigDecimal(0); 9057 if (!value.equalsIgnoreCase("")) 9058 number = new BigDecimal(value); 9059 pstmt.setBigDecimal(i, number); 9060 } else { 9061 pstmt.setNull(i, java.sql.Types.DECIMAL); 9062 } 9063 } else if (javaTypeInt == 3) { // java.lang.Double 9064 if (!value.equalsIgnoreCase("null")) { 9065 double number = 0; 9066 if (!value.equalsIgnoreCase("")) 9067 number = Double.parseDouble(value); 9068 pstmt.setDouble(i, number); 9069 } else { 9070 pstmt.setNull(i, java.sql.Types.DOUBLE); 9071 } 9072 } else if (javaTypeInt == 4) { // java.lang.Float 9073 if (!value.equalsIgnoreCase("null")) { 9074 float number = 0; 9075 if (!value.equalsIgnoreCase("")) 9076 number = Float.parseFloat(value); 9077 pstmt.setFloat(i, number); 9078 } else { 9079 pstmt.setNull(i, java.sql.Types.FLOAT); 9080 } 9081 } else if (javaTypeInt == 5) { // java.lang.Integer 9082 if (!value.equalsIgnoreCase("null")) { 9083 int number = 0; 9084 if (!value.equalsIgnoreCase("")) 9085 number = Integer.parseInt(value); 9086 pstmt.setInt(i, number); 9087 } else { 9088 pstmt.setNull(i, java.sql.Types.INTEGER); 9089 } 9090 9091 } else if (javaTypeInt == 6) { // java.lang.Long 9092 if (!value.equalsIgnoreCase("null")) { 9093 long number = 0; 9094 if (!value.equalsIgnoreCase("")) 9095 number = Long.parseLong(value); 9096 pstmt.setLong(i, number); 9097 } else { 9098 pstmt.setNull(i, java.sql.Types.DOUBLE); 9099 } 9100 } else if (javaTypeInt == 7) { // java.lang.Short 9101 if (!value.equalsIgnoreCase("null")) { 9102 short number = 0; 9103 if (!value.equalsIgnoreCase("")) 9104 number = Short.parseShort(value); 9105 pstmt.setShort(i, number); 9106 } else { 9107 pstmt.setNull(i, java.sql.Types.SMALLINT); 9108 } 9109 } else if (javaTypeInt == 8) { // java.lang.String 9110 if (!value.equalsIgnoreCase("null")) { 9111 // all '' back to ' (original value) 9112 if (value.indexOf("''") != -1) { 9113 value = Utils.replaceAll(value, "''", "'"); 9114 } 9115 pstmt.setString(i, value); 9116 } else { 9117 pstmt.setNull(i, java.sql.Types.VARCHAR); 9118 } 9119 } else if (javaTypeInt == 9) { // java.sql.Date 9120 if (!value.equalsIgnoreCase("null")) { 9121 // String format = this.configReaderSource.getDateFormat(); 9122 // SimpleDateFormat formatDate = new SimpleDateFormat(format); 9123 // Date tmpDate = formatDate.parse(value); 9124 try { 9125 pstmt.setDate(i, new java.sql.Date(getDateFromString(value) 9126 .getTime())); 9127 } catch (Exception e) { 9128 this.logger.write("normal", "call setString on date: " 9129 + value); 9130 pstmt.setString(i, value); 9131 } 9132 // } 9133 9134 } else { 9135 pstmt.setNull(i, java.sql.Types.DATE); 9136 } 9137 } else if (javaTypeInt == 10) { // java.sql.Time 9138 if (!value.equalsIgnoreCase("null")) { 9139 // String format = this.configReaderSource.getDateFormat(); 9140 // SimpleDateFormat formatDate = new SimpleDateFormat(format); 9141 // Date tmpDate = formatDate.parse(value); 9142 try { 9143 pstmt.setTime(i, new java.sql.Time(getDateFromString(value) 9144 .getTime())); 9145 } catch (Exception e) { 9146 pstmt.setString(i, value); 9147 } 9148 } else { 9149 pstmt.setNull(i, java.sql.Types.TIME); 9150 } 9151 9152 } else if (javaTypeInt == 11) { // java.sql.Timestamp 9153 if (!value.equalsIgnoreCase("null")) { 9154 // String format = this.configReaderSource.getDateFormat(); 9155 // SimpleDateFormat formatDate = new SimpleDateFormat(format); 9156 // Date tmpDate = formatDate.parse(value); 9157 try { 9158 pstmt.setTimestamp(i, new Timestamp( 9159 getDateFromString(value).getTime())); 9160 } catch (Exception e) { 9161 pstmt.setString(i, value); 9162 } 9163 } else { 9164 pstmt.setNull(i, java.sql.Types.TIMESTAMP); 9165 } 9166 9167 } else if (javaTypeInt == 12) { // java.lang.Boolean 9168 if (!value.equalsIgnoreCase("null")) { 9169 boolean bool = new Boolean(value).booleanValue(); 9170 pstmt.setBoolean(i, bool); 9171 } else { 9172 // TODO test this peace of code 9173 pstmt.setNull(i, java.sql.Types.BIT); 9174 } 9175 } else if (javaTypeInt == 13) { // java.lang.Byte 9176 if (!value.equalsIgnoreCase("null")) { 9177 pstmt.setString(i, value); 9178 } else { 9179 pstmt.setNull(i, java.sql.Types.BIT); 9180 } 9181 } else if (javaTypeInt == 14) { // java.lang.Object 9182 if (!value.equalsIgnoreCase("null")) { 9183 pstmt.setString(i, value); 9184 } else { 9185 // TODO zoran pogledati ovo 9186 try { 9187 pstmt.setNull(i, java.sql.Types.NULL); 9188 } catch (Exception e) { 9189 pstmt.setString(i, null); 9190 } 9191 } 9192 } 9193 } 9194 9195 //senka added 9196 protected String getSQLRelationString(ResultSet rs){ 9197 String res=""; 9198 String r=""; 9199 String temp=""; 9200 int col=0; 9201 int counter=1; 9202 9203 if (this.iTargetFirstColumnResult == 1) col=1; 9204 try { 9205 try { 9206 if (!configReaderTarget.isNumber(rs.getMetaData().getColumnTypeName(col))) temp="'"; 9207 } catch (LoaderException e) { 9208 e.printStackTrace(); 9209 } 9210 Object obj=rs.getObject(col); 9211 if (obj!=null){ 9212 res=res+temp+obj.toString()+temp+","; 9213 while (rs.next()){ 9214 obj=rs.getObject(col); 9215 if (obj!=null){ 9216 res=res+temp+obj.toString()+temp; 9217 res=res+","; 9218 counter++; 9219 } 9220 } 9221 } else{ 9222 res=res+temp+"null"+temp+","; 9223 } 9224 9225 9226 } catch (SQLException e) { 9227 e.printStackTrace(); 9228 } 9229 9230 if (counter==1) { 9231 r=res.substring(temp.length(),res.length()-1-temp.length()); 9232 } 9233 else{ 9234 r=" IN ("+res.substring(0,res.length()-1)+")"; 9235 } 9236 return r; 9237 } 9238 9239 }

This page was automatically generated by Maven