1 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.text.DateFormat ; 41 import java.text.SimpleDateFormat ; 42 import java.util.ArrayList ; 43 import java.util.Date ; 44 import java.util.HashMap ; 45 import java.util.Hashtable ; 46 import java.util.Iterator ; 47 import java.util.List ; 48 import java.util.Map ; 49 import java.util.StringTokenizer ; 50 import java.util.Vector ; 51 52 import javax.xml.parsers.DocumentBuilder ; 53 import javax.xml.parsers.DocumentBuilderFactory ; 54 55 import org.w3c.dom.Document ; 56 import org.w3c.dom.Element ; 57 import org.w3c.dom.NamedNodeMap ; 58 import org.w3c.dom.Node ; 59 import org.w3c.dom.NodeList ; 60 import org.webdocwf.util.loader.logging.Logger; 61 import org.webdocwf.util.loader.logging.StandardLogger; 62 import org.webdocwf.util.loader.transformation.QueryTransformationSet; 63 import org.webdocwf.util.loader.transformation.Transformation; 64 import org.webdocwf.util.loader.transformation.Transformations; 65 import org.xml.sax.SAXException ; 66 67 110 public class Loader { 111 int iValueColumns; 113 Vector vecValueColumnsTargetTables = new Vector (); 114 Vector vecSourceColumnName = new Vector (); 116 Vector vecTargetColumnName = new Vector (); 117 Vector vecValueMode = new Vector (); 118 Vector vecTargetColumnValue = new Vector (); 119 Vector vecTargetKeyColumnName = new Vector (); 120 Vector vecVariableUseIDTableName = new Vector (); 121 Vector vecVariableUseIDTableID = new Vector (); 122 Vector vecVariableUseIDColumnName = new Vector (); 123 Vector vecVariableUseIDValueMode = new Vector (); 124 Vector vecVariableColumnName = new Vector (); 125 Vector vecVariableColumnTargetTableName = new Vector (); 126 Vector vecVariableColumnTargetTableID = new Vector (); 127 Vector vecVariableColumnTargetColumnName = new Vector (); 128 Vector vecVariableColumnValueMode = new Vector (); 129 Vector vecVariableColumnTypes = new Vector (); 130 Vector vecVariableTimesTableName = new Vector (); 131 Vector vecVariableTimesTableID = new Vector (); 132 Vector vecVariableTimesColumnName = new Vector (); 133 Vector vecVariableTimesValueMode = new Vector (); 134 int iConstantColumns; 135 Vector vecConstantTargetColumnName = new Vector (); 136 Vector vecConstantValueMode = new Vector (); 137 Vector vecConstantConstantValue = new Vector (); 138 Vector vecConstantColumnTargetTableName = new Vector (); 139 Vector vecConstantColumnTargetTableID = new Vector (); 140 int iRelationColumns; 141 Vector vecRelationColumnSourceTableName = new Vector (); 142 Vector vecRelationColumnSourceTableID = new Vector (); 143 Vector vecRelationColumnSourceColumnName = new Vector (); 144 Vector vecRelationColumnTargetTableName = new Vector (); 145 Vector vecRelationColumnTargetColumnName = new Vector (); 146 Vector vecRelationColumnTargetTableID = new Vector (); 147 Vector vecRelationColumnRelationMode = new Vector (); 148 int iTables; 149 Vector vecTableTableName = new Vector (); 150 Vector vecTableTableID = new Vector (); 151 Vector vecTableInsert = new Vector (); 152 Vector vecTableTableMode = new Vector (); 153 Vector vecTableOidLogic = new Vector (); 154 Vector vecRelationSourceValue = new Vector (); 155 Vector vecRelationSourceType = new Vector (); 156 Vector vecTargetColumnType = new Vector (); 157 Vector vecConstantColumnType = new Vector (); 158 BigDecimal bdecOidNumber = new BigDecimal (0); 159 BigDecimal bdecOidNumber2000 = new BigDecimal (0); 160 String strLoaderJobFileName = ""; 161 boolean bRestartIndicator; 162 Map mapVariableValues = new HashMap (); 163 boolean bOnErrorContinue; 164 String strUserID = ""; 165 String strLogDirName = ""; 166 String strLogFileName = ""; 167 String strVendorFileName = ""; 168 String strAdditionalPaths = ""; 169 String confJarStructure = ""; 170 171 boolean hasRestartCounter; 173 boolean hasUserID; 174 Vector vecRelationKeyColumns = new Vector (); 175 Vector vecRelationKeyTypes = new Vector (); 176 Vector vecSortValues = new Vector (); 177 178 Vector vecSqlStmt = new Vector (); 179 String strSourceDriverName = ""; 180 String strTargetDriverName = ""; 181 182 int iFirstColumnResult = 1; 184 int iTargetFirstColumnResult = 1; 185 Vector vecVariableName = new Vector (); 187 Vector vecVariableValue = new Vector (); 188 Vector vecVariablePrefix = new Vector (); 189 Vector vecVariableSufix = new Vector (); 190 Vector vecVariableOverride = new Vector (); 191 Vector vecReplaceInConstants = new Vector (); 192 Vector vecReplaceInSQL = new Vector (); 193 Vector vecReplaceInData = new Vector (); 194 Vector vecReplaceInJDBC = new Vector (); 195 public static final String LOGMODE_NONE = "none"; 196 public static final String LOGMODE_NORMAL = "normal"; 197 public static final String LOGMODE_FULL = "full"; 198 ByteArrayOutputStream foStreamTmp = new ByteArrayOutputStream (); 199 boolean bReplaceInData = false; 200 int iColumnsInSourceTable = 0; 201 boolean isDefaultJdbc = false; 202 private String defaultLogMode = LOGMODE_NORMAL; 203 ArrayList logModes = new ArrayList (); 204 205 private Cache cacheValues; 206 private Logger logger; 208 private CounterColumns counterColumns; 209 private TimeWatch timeCounter; 210 private Transformations transformations; 211 212 private JdbcParametersElement jdbcParametersElement = new JdbcParametersElement(); 214 private SqlElement sqlElement = new SqlElement(); 215 private ConfigReader configReaderSource = new ConfigReader(); 216 private ConfigReader configReaderTarget = new ConfigReader(); 217 private LoaderJobAttrReader loaderJobReader = new LoaderJobAttrReader(); 218 private ImportDefinitionElement importDefinitionElement = new ImportDefinitionElement(); 219 private DataCleaning dataCleaning = new DataCleaning(configReaderTarget); 220 221 private String strQuerySet = ""; 223 QueryWhereSet queryWhereSet = null; 224 QueryConstantSet queryConstantSet = null; 225 QueryTransformationSet queryTransformationSet = null; 226 227 Hashtable queryStatement = new Hashtable (); 228 Hashtable indexDValue = new Hashtable (); 229 Hashtable indexDRelationValue = new Hashtable (); 230 Hashtable indexConstantDValue = new Hashtable (); 231 Hashtable indexDVariableValue = new Hashtable (); 232 Hashtable indexDTransformationValue = new Hashtable (); 233 234 Hashtable updateStatement = new Hashtable (); 235 Hashtable indexDOverwrite = new Hashtable (); 236 Hashtable indexDSetNull = new Hashtable (); 237 238 Hashtable updateConstantStatement = new Hashtable (); 239 Hashtable indexDConstantOver = new Hashtable (); 240 Hashtable indexDConstantNull = new Hashtable (); 241 Hashtable resultVector = new Hashtable (); 243 Hashtable updateTransformationStatement = new Hashtable (); 244 Hashtable indexDTransformationOver = new Hashtable (); 245 Hashtable indexDTransformationNull = new Hashtable (); 246 Hashtable indexDTransformationUpdate = new Hashtable (); 247 Hashtable queryInsertRow = new Hashtable (); 249 Hashtable indexIsNotRelationsColumns = new Hashtable (); 250 Hashtable pstmtForInsert = new Hashtable (); 251 Hashtable pstmtColumnNames = new Hashtable (); 252 254 Vector pstmtKeys = new Vector (); 255 256 Vector vecDefaultValue = new Vector (); 258 Vector vecDefaultVariableValue = new Vector (); 259 Vector vecDefaultVariableName = new Vector (); 260 Vector vecDefaultRelationValue = new Vector (); 261 Vector vecTempUserID = new Vector (); 262 boolean userIDExists = false; 263 private int currentRow = 0; 264 265 Hashtable allSourceColumnNameNoMap = new Hashtable (); 268 Hashtable allSourceColumnValueNoMap = new Hashtable (); 269 Hashtable allSourceColumnTypeNoMap = new Hashtable (); 270 Vector ImportDefinitionSourceColumnName = new Vector (); 271 Vector ImportDefinitionTargetColumnName = new Vector (); 272 private String currentJobName = ""; 273 Vector vecCTAutoMapp = new Vector (); 274 Vector vecCTDefaultMode = new Vector (); 275 Vector vecBlobVector = new Vector (); 276 Vector vecToHex = new Vector (); 277 Vector vecFromHex = new Vector (); 278 279 RelationsCache relationsCache = new RelationsCache(); 281 private Vector includeTables = new Vector (); 282 283 CheckRowCache checkRowCache = new CheckRowCache(); 285 286 DataTransmition dataTransmition = new DataTransmition(importDefinitionElement); 288 289 private String currentOidColumnName = "oid"; 291 private String currentVersionColumnName = "version"; 292 293 private Vector transformationsColumnNames = new Vector (); 295 private Vector transformationsValueModes = new Vector (); 296 private Vector transformationsColumnValueMode = new Vector (); 297 private Vector transformationsColumnTypes = new Vector (); 298 private Vector transformationsResultVectorTypes = new Vector (); 299 private Vector resultVectorTypes = new Vector (); 300 302 private int iOffsetForTransColumns = 0; 304 305 Vector transformationValues = new Vector (); 308 309 310 311 312 329 public Loader(String loadJobFileName, String mode, String userID, 330 String logDirName, String logFileName, boolean restartIndicator, 331 Map variableValues, String vendorFileName, boolean onErrorContinue, 332 String additionalPaths, int commitCount, int returnCode, 333 String [] includeTables, String confJarStructure) { 334 this.strLoaderJobFileName = loadJobFileName; 335 if (mode != null) { 337 if ( mode.equalsIgnoreCase("none") || 338 mode.equalsIgnoreCase("normal") || 339 mode.equalsIgnoreCase("full") ) 340 { 341 this.defaultLogMode = mode; 343 } } 348 349 if (userID != null) { 350 this.strUserID = userID; 351 this.hasUserID = true; 352 } else 353 this.hasUserID = false; 354 if (logDirName != null) 355 this.strLogDirName = logDirName; 356 else { 357 File fCurrent = new File (""); 358 this.strLogDirName = fCurrent.getAbsolutePath(); 359 } 360 if (logFileName != null) { 361 this.strLogFileName = logFileName; 362 } else 363 this.strLogFileName = "default"; 364 this.bRestartIndicator = restartIndicator; 365 if (this.bRestartIndicator == true) 366 this.hasRestartCounter = true; 367 else 368 this.hasRestartCounter = false; 369 this.mapVariableValues = variableValues; 370 if (vendorFileName != null) { 371 this.strVendorFileName = vendorFileName; 372 } 373 this.bOnErrorContinue = onErrorContinue; 374 if (additionalPaths != null) { 375 try { 376 this.strAdditionalPaths = additionalPaths; 377 StringTokenizer st = new StringTokenizer (this.strAdditionalPaths, ";"); 378 URL [] urls = new URL [st.countTokens()]; 379 int count = 0; 380 while (st.hasMoreTokens()) { 381 urls[count] = new File (st.nextElement().toString()).toURL(); 382 count++; 383 } 384 for (int i = 0; i < urls.length; i++) { 385 OctopusClassLoader.addURL(urls[i]); 386 } 387 } 388 catch (Exception ne) { 389 ne.printStackTrace(); 390 } 391 } 392 if (includeTables != null) { 393 for (int i = 0; i < includeTables.length; i++) { 394 this.includeTables.add(includeTables[i]); 395 } 396 } 397 importDefinitionElement.iCommitCount = commitCount; 398 ReturnCode.setDefaultErrorReturnCode(returnCode); 399 this.confJarStructure = confJarStructure; 400 } 401 402 418 public Loader(String loadJobFileName, String mode, String userID, 419 String logDirName, 420 String logFileName, boolean restartIndicator, 421 Map variableValues, 422 String vendorFileName, boolean onErrorContinue, 423 String additionalPaths, 424 int commitCount, int returnCode) { 425 426 this(loadJobFileName, mode, userID, logDirName, logFileName, restartIndicator, 427 variableValues, vendorFileName, onErrorContinue, additionalPaths, 428 commitCount, returnCode, null, null); 429 430 } 431 432 448 public Loader(String loadJobFileName, String mode, String userID, 449 String logDirName, 450 String logFileName, boolean restartIndicator, 451 Map variableValues, 452 String vendorFileName, boolean onErrorContinue, 453 String additionalPaths, 454 int commitCount, int returnCode, String [] includeTables) { 455 456 this(loadJobFileName, mode, userID, logDirName, logFileName, restartIndicator, 457 variableValues, vendorFileName, onErrorContinue, additionalPaths, 458 commitCount, returnCode, includeTables, null); 459 460 } 461 462 478 public Loader(String loadJobFileName, String mode, String userID, 479 String logDirName, 480 String logFileName, boolean restartIndicator, 481 Map variableValues, 482 String vendorFileName, boolean onErrorContinue, 483 String additionalPaths, 484 int commitCount, int returnCode, String confJarStructure) { 485 486 this(loadJobFileName, mode, userID, logDirName, logFileName, restartIndicator, 487 variableValues, vendorFileName, onErrorContinue, additionalPaths, 488 commitCount, returnCode, null, confJarStructure); 489 490 } 491 492 498 private String addClassPath(String oldClassPath, String add) { 499 500 String classPath = oldClassPath; 501 if (System.getProperty("os.name").toLowerCase().startsWith("win")) { 502 if (!classPath.trim().endsWith(";")) 503 classPath += ";"; 504 add = add.replace('\n', '\\'); 505 add = add.replace('\t', '\\'); 506 add = add.replace('\b', '\\'); 507 add = add.replace('\r', '\\'); 508 add = add.replace('\f', '\\'); 509 classPath = classPath.concat(add); 510 } else { 511 if (!classPath.trim().endsWith(":")) 512 classPath += ":"; 513 add = add.replace('\n', '/'); 514 add = add.replace('\t', '/'); 515 add = add.replace('\b', '/'); 516 add = add.replace('\r', '/'); 517 add = add.replace('\f', '/'); 518 classPath = classPath.concat(add); 519 520 } 521 return classPath; 522 } 523 524 530 public Loader(String loadJobFileName) { 531 this(loadJobFileName, null); 532 } 533 534 540 public Loader(String loadJobFileName, String confJarStructure) { 541 this.strLoaderJobFileName = loadJobFileName; 542 this.hasUserID = false; 544 File fCurrent = new File (""); 545 this.strLogDirName = fCurrent.getAbsolutePath(); 546 this.strLogFileName = "default"; 547 this.bRestartIndicator = false; 548 this.hasRestartCounter = false; 549 this.bOnErrorContinue = false; 550 importDefinitionElement.iCommitCount = 100; 551 ReturnCode.setDefaultErrorReturnCode(1); 552 this.confJarStructure = confJarStructure; 553 } 554 555 559 public String getLoadJobFileName() { 560 return this.strLoaderJobFileName; 561 } 562 563 567 public void setLoadJobFileName(String loadJobFileName) { 568 this.strLoaderJobFileName = loadJobFileName; 569 } 570 571 575 579 584 588 592 public String getUserID() { 593 return this.strUserID; 594 } 595 596 600 public void setUserID(String userID) { 601 this.strUserID = userID; 602 } 603 604 608 public String getLogDirName() { 609 return this.strLogDirName; 610 } 611 612 616 public void setLogDirName(String logDirName) { 617 this.strLogDirName = logDirName; 618 } 619 620 624 public String getLogFileName() { 625 return this.strLogFileName; 626 } 627 628 632 public void setLogFileName(String logFileName) { 633 this.strLogFileName = logFileName; 634 } 635 636 640 public boolean getRestartIndicator() { 641 return this.bRestartIndicator; 642 } 643 644 648 public void setRestartIndicator(boolean restartIndicator) { 649 this.bRestartIndicator = restartIndicator; 650 } 651 652 656 public Map getVariableValues() { 657 return this.mapVariableValues; 658 } 659 660 664 public void setVariableValues(Map variableValue) { 665 this.mapVariableValues = variableValue; 666 } 667 668 672 public String getVendorFileName() { 673 return this.strVendorFileName; 674 } 675 676 680 public void setVendorFileName(String vendorFileName) { 681 this.strVendorFileName = vendorFileName; 682 } 683 684 688 public boolean getOnErrorContinue() { 689 return this.bOnErrorContinue; 690 } 691 692 696 public void setOnErrorContinue(boolean onErrorContinue) { 697 this.bOnErrorContinue = onErrorContinue; 698 } 699 700 704 public String getAdditionalPaths() { 705 return this.strAdditionalPaths; 706 } 707 708 712 public void setAdditionalPaths(String additionalPaths) { 713 this.strAdditionalPaths = additionalPaths; 714 String strClassPath = System.getProperty("java.class.path"); 715 strClassPath = this.addClassPath(strClassPath, this.strAdditionalPaths); 716 try { 717 this.getClass().getClassLoader().loadClass(strClassPath); 718 } 719 catch (ClassNotFoundException ne) { 720 ne.printStackTrace(); 721 } 722 } 724 725 729 public int getCommitCount() { 730 return importDefinitionElement.iCommitCount; 731 } 732 733 737 public void setCommitCount(int commitCount) { 738 importDefinitionElement.iCommitCount = commitCount; 739 } 740 741 745 public int getDefaultReturnCode() { 746 return ReturnCode.getDefaultErrorReturnCode(); 747 } 748 749 753 public void setDefaultReturnCode(int code) { 754 ReturnCode.setDefaultErrorReturnCode(code); 755 } 756 757 761 public void setIncludedJobs(String include_Tables[]) { 762 for (int i = 0; i < include_Tables.length; i++) { 763 includeTables.add(include_Tables[i]); 764 } 765 } 766 767 771 public String [] getIncludedJobs() { 772 String ret[] = new String [this.includeTables.size()]; 773 for (int i = 0; i < includeTables.size(); i++) { 774 ret[i] = includeTables.get(i).toString(); 775 } 776 return ret; 777 } 778 782 public String getConfJarStructure(){ 783 784 return this.confJarStructure; 785 } 786 790 public String getDefaultLogMode(){ 791 792 return this.defaultLogMode; 793 } 794 814 public static void main(String argv[]) { 815 String loadJobFileName = null; 816 String mode = null; 817 String userID = null; 818 String logDirName = null; 819 String logFileName = null; 820 boolean restartIndicator = false; 821 Map variableValues = null; 822 String strVariableValues = null; 823 String vendorFileName = null; 824 boolean onErrorContinue = false; 825 String additionalPaths = null; 826 int defaultReturnCode = 1; 827 int commitCount = 0; 828 String [] includeTables = null; 829 String confJarStructure = null; 830 831 if (argv.length > 0 && argv.length < 26) { 832 loadJobFileName = argv[argv.length - 1]; 833 for (int i = 0; i < argv.length - 1; i = i + 1) { 834 if (argv[i].equalsIgnoreCase("-m")) 835 mode = argv[++i]; 836 else if (argv[i].equalsIgnoreCase("-r")) 837 restartIndicator = true; 838 else if (argv[i].equalsIgnoreCase("-u")) 839 userID = argv[++i]; 840 else if (argv[i].equalsIgnoreCase("-l")) 841 logDirName = argv[++i]; 842 else if (argv[i].equalsIgnoreCase("-f")) 843 logFileName = argv[++i]; 844 else if (argv[i].equalsIgnoreCase("-d")) 845 vendorFileName = argv[++i]; 846 else if (argv[i].equalsIgnoreCase("-e")) 847 onErrorContinue = true; 848 else if (argv[i].equalsIgnoreCase("-p")) 849 additionalPaths = argv[++i]; 850 else if (argv[i].equalsIgnoreCase("-c")) 851 commitCount = (new Integer (argv[++i])).intValue(); 852 else if (argv[i].equalsIgnoreCase("-v")) { 853 strVariableValues = argv[++i]; 854 variableValues = new HashMap (convertToMap(strVariableValues)); 855 } else if (argv[i].equalsIgnoreCase("-rc")) { 856 defaultReturnCode = (new Integer (argv[++i])).intValue(); 857 ReturnCode.isParameter = true; 858 } else if (argv[i].equalsIgnoreCase("-it")) { 859 String array = argv[++i]; 860 StringTokenizer st = new StringTokenizer (array, ";"); 861 includeTables = new String [st.countTokens()]; 862 int pos = 0; 863 while (st.hasMoreTokens()) { 864 includeTables[pos] = st.nextToken(); 865 pos++; 866 } 867 } else if (argv[i].equalsIgnoreCase("-cjs")) { 868 confJarStructure = argv[++i]; 869 } 870 } 871 } else 872 printUsage(); 873 Loader l = new Loader(loadJobFileName, mode, userID, logDirName, 874 logFileName, restartIndicator, variableValues, vendorFileName, 875 onErrorContinue, additionalPaths, commitCount, defaultReturnCode, 876 includeTables, confJarStructure); 877 try { 878 l.load(); 879 BufferOctopusClass.getInstance().writeToBuffer(String.valueOf(ReturnCode.getOKReturnCode())); 880 } 881 catch (LoaderException le) { 882 BufferOctopusClass.getInstance().writeToBuffer(le.getCause() + "\n"); 883 BufferOctopusClass.getInstance().writeToBuffer(String.valueOf(ReturnCode.getErrorReturnCode())); 884 System.exit(ReturnCode.getErrorReturnCode()); 885 } 886 } 887 888 891 static void printUsage() { 892 System.out.println("Usage: java org.webdocwf.util.loader.Loader [options] loadJob_xml_filename"); 893 System.out.println(" Options:"); 894 System.out.println( 895 " -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'."); 896 System.out.println( 897 " -r starts the Loader in restart mode after abnormal termination in a prior execution. \n"); 898 System.out.println(" -u defines the current UserID used in UserID value columns. \n"); 899 System.out.println(" -v defines variables used in variable columns. \n"); 900 System.out.println( 901 " -l defines the logfile directory. The default is the current working directory. \n"); 902 System.out.println( 903 " -f defines the logfile name. The default is 'LoaderLog-YYYY-MM-DD-HH-mm-SS.txt'. \n"); 904 System.out.println(" -d the filename of the XML DB-vendor configuration file. The default is 'OctopusDBVendors.xml'. \n"); 905 System.out.println( 906 " -e defines to set the default of 'onErrorContinue' to 'true'. Is false otherwise. \n"); 907 System.out.println(" -p Extend the classpath with additional paths \n"); 908 System.out.println(" -c Sets the default commit count. System default is '100'. \n"); 909 System.out.println(" -rc Sets the default error return code. System default is '1'. \n"); 910 System.out.println(" -it Sets the table names which will be proccesed "); 911 System.exit(ReturnCode.getErrorReturnCode()); 912 } 913 914 921 public void load() throws LoaderException { 922 int iImportJobs = 0; 923 int iCopyTable = 0; 924 int iConnection = 0; 925 int iSqlTags = 0; 926 int iEchoElements = 0; 927 int iLastImportDefinition = 0; 928 Vector vecXmlElements = new Vector (); 929 Vector vecJDBCTargetConnections = new Vector (); 930 931 ParseLoggerParam loggerParam = new ParseLoggerParam(this.strLoaderJobFileName); 934 String logClassName = loggerParam.getLogClassName(); 935 936 String pathToLoggerConf = loggerParam.getPathToLoggerConf(); 937 String strLoggerParam = ""; 938 boolean standardLogger = false; 939 try { 940 this.logger = (org.webdocwf.util.loader.logging.Logger)Class.forName(logClassName). 941 newInstance(); 942 if (pathToLoggerConf != null && pathToLoggerConf.length() != 0) 943 strLoggerParam = pathToLoggerConf; 944 else 945 strLoggerParam = this.strLogDirName + ";" + this.strLogFileName; 946 } 947 catch (Exception e) { 948 this.logger = new StandardLogger(); 949 strLoggerParam = this.strLogDirName + ";" + this.strLogFileName; 950 standardLogger = true; 951 } 952 953 try { 954 logger.configure(strLoggerParam); 955 logger.setEnabledLogLevels(this.defaultLogMode); 956 if (standardLogger == true) { 957 this.logger.write("normal", "Default (Standard) Logger is load."); 959 } 961 962 } 963 catch (Exception ex) { 964 String msg = "Error while configuring logger."; 965 LoaderException le = new LoaderException(msg + "\n" + ex.getMessage(), (Throwable )ex); 966 BufferOctopusClass.getInstance().writeToBuffer(msg + "\n" + ex.getMessage() + "\n"); 967 this.logger.write("full", le.getStackTraceAsString()); 969 throw le; 970 } 971 972 this.timeCounter = new TimeWatch(); 973 974 978 jdbcParametersElement.setLogger(this.logger); 979 jdbcParametersElement.setConfigReaderSource(this.configReaderSource); 980 jdbcParametersElement.setLoaderJobPath(this.strLoaderJobFileName); 981 982 configReaderSource.setLogger(this.logger); 983 configReaderTarget.setLogger(this.logger); 984 configReaderSource.setConfJarStructure(this.confJarStructure); 985 configReaderTarget.setConfJarStructure(this.confJarStructure); 986 987 loaderJobReader.setLogger(this.logger); 988 loaderJobReader.setDefaultOnErrorContinue(this.bOnErrorContinue); 989 sqlElement.setLogger(this.logger); 990 sqlElement.setLoaderJob(this.loaderJobReader); 991 sqlElement.setConfigReader(this.configReaderTarget); 992 sqlElement.setJdbcParametersElement(this.jdbcParametersElement); 993 checkRowCache.setLogger(this.logger); 994 dataTransmition.setLogger(this.logger); 995 996 997 this.logger.write("normal", "\nApplication is started."); 999 1001 this.timeCounter.setStartTime(); 1002 ByteArrayInputStream inStream = null; 1003 ByteArrayOutputStream foStream = new ByteArrayOutputStream (); 1004 LoaderXIncluder loaderInclude = new LoaderXIncluder(foStream); 1006 LocationOfException locationOfException = new LocationOfException(this.strLoaderJobFileName); 1007 loaderInclude.parseURI(this.strLoaderJobFileName); 1008 inStream = new ByteArrayInputStream (foStream.toByteArray()); 1009 1010 1020 try { 1022 OctopusValidator validator = new OctopusValidator(); 1023 validator.validate(new ByteArrayInputStream (foStream.toByteArray())); 1024 } 1025 catch (Exception e) { 1026 this.logger.write("normal", "Sorry, validation error occurred . Message was: " + e.getMessage()); 1027 1028 BufferOctopusClass.getInstance().writeToBuffer( 1029 "Sorry, validation error occurred . Message was: " + e.getMessage()); 1030 LoaderException le = new LoaderException("Exception:"+e.getMessage(),(Throwable )e); 1031 this.logger.write("full", le.getStackTraceAsString()); 1032 throw le; 1033 1034 } 1035 this.logger.write("normal", "\nXML document is valid."); 1037 1038 1040 this.importVariable(inStream); 1042 for (int i = 0; i < this.vecReplaceInData.size(); i++) { 1045 if (this.vecReplaceInData.get(i).toString().equalsIgnoreCase("true")) 1046 bReplaceInData = true; 1047 } 1048 this.foStreamTmp = foStream; 1050 foStream = new ByteArrayOutputStream (); 1051 LoadVariable loadVariable = new LoadVariable(foStream, this); 1052 loadVariable.parseURI(); 1053 inStream = new ByteArrayInputStream (foStream.toByteArray()); 1055 loaderJobReader.setDefaultLogMode(this.defaultLogMode); 1056 loaderJobReader.importLoaderJobAttributes(inStream); 1057 iImportJobs = this.parseImportJob(inStream); 1058 iCopyTable = this.parseCopyTable(inStream); 1059 iSqlTags = sqlElement.parseSql(inStream); 1060 iEchoElements = this.parseEcho(inStream); 1061 this.importRestartCounter(inStream); 1062 vecXmlElements = this.parseMainElements(inStream); 1063 1064 iLastImportDefinition = 0; 1066 for (int i = 0; i < vecXmlElements.size(); i++) { 1067 if (vecXmlElements.get(i).toString().equalsIgnoreCase("importDefinition")) 1068 iLastImportDefinition = i; 1069 } 1070 jdbcParametersElement.parseTargetJDBCParameters(inStream); 1071 DBConnectionManager connManager = new DBConnectionManager(jdbcParametersElement. 1072 getTargetConnections()); 1073 Connection connToPools = null; 1074 1075 try { 1076 this.isDefaultJdbc = jdbcParametersElement.parseImportJDBCDefaultParameters(inStream); 1077 1078 if (this.strVendorFileName != null && !this.strVendorFileName.equals("")) 1079 configReaderTarget.setVendorFileName(this.strVendorFileName); 1080 configReaderTarget.readConfigValues(jdbcParametersElement.getTargetDBVendor(), 1082 jdbcParametersElement.getTargetDriverName(), "target"); 1083 this.currentOidColumnName = configReaderTarget.getOidColumnName(); 1084 this.currentVersionColumnName = configReaderTarget.getVersionColumnName(); 1085 1086 if (jdbcParametersElement.getJDBCTargetParameterDriver().equals("") || 1087 jdbcParametersElement.getJDBCTargetParameterDriver() == null) 1088 jdbcParametersElement.setJDBCTargetParameterDriver(configReaderTarget.getDriverClassName()); 1089 Class.forName(jdbcParametersElement.getJDBCTargetParameterDriver()); 1090 1091 int iImport = 0; 1092 int iCopy = 0; 1093 int iSql = 0; 1094 int iEcho = 0; 1095 for (int l = 0; l < (iImportJobs + iCopyTable + iSqlTags + iEchoElements); l++) { 1097 Object tempLogMode = this.logModes.get(l); 1098 if( tempLogMode != null && !tempLogMode.equals("") ) 1099 this.logger.setEnabledLogLevels(tempLogMode.toString()); 1100 else 1101 this.logger.setEnabledLogLevels(loaderJobReader.getDefaultLogMode()); 1102 this.resetGlobalVariables(); 1104 relationsCache.resetRelationsCache(); 1105 checkRowCache.resetCheckRowCache(); 1106 this.logger.write("normal", 1108 "\nImport job No. " + (iImport + iCopy + iSql + 1) + " is started."); 1109 1111 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) { 1112 this.logger.write("full", "Importing and parsing XML file is started."); 1113 this.parseAndImport(inStream, iImport); 1115 jdbcParametersElement.parseImportJDBCParameters(inStream, iImport + 1, "importDefinition"); 1116 1117 configReaderSource.readConfigValues(jdbcParametersElement.getDbVendor(), 1118 jdbcParametersElement.getDriverName(), "source"); 1119 configReaderTarget.readConfigValues(jdbcParametersElement.getTargetDBVendor(), 1120 jdbcParametersElement.getTargetDriverName(), "target"); 1121 this.currentOidColumnName = configReaderTarget.getOidColumnName(); 1123 this.currentVersionColumnName = configReaderTarget.getVersionColumnName(); 1124 1125 } 1126 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("copyTable")) { 1128 this.logger.write("full", "Importing and parsing XML file is started."); 1129 this.parseAndImport(inStream, iCopy); 1130 jdbcParametersElement.parseImportJDBCParameters(inStream, iCopy + 1, "copyTable"); 1132 1133 configReaderSource.readConfigValues(jdbcParametersElement.getDbVendor(), 1134 jdbcParametersElement.getDriverName(), 1135 "source"); 1136 configReaderTarget.readConfigValues(jdbcParametersElement.getTargetDBVendor(), 1137 jdbcParametersElement.getTargetDriverName(), 1138 "target"); 1139 this.currentOidColumnName = configReaderTarget.getOidColumnName(); 1140 this.currentVersionColumnName = configReaderTarget.getVersionColumnName(); 1141 } else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) { 1142 configReaderTarget.readConfigValues(jdbcParametersElement.getTargetDBVendor(), 1143 jdbcParametersElement.getTargetDriverName(), "target"); 1144 1145 this.currentOidColumnName = configReaderTarget.getOidColumnName(); 1146 this.currentVersionColumnName = configReaderTarget.getVersionColumnName(); 1147 1148 this.logger.write("full", "Importing and parsing XML file is started."); 1150 this.vecSqlStmt = sqlElement.importSQLStatement(inStream, iSql); 1151 1157 this.logger.write("full", "Importing and parsing XML file is started."); 1159 jdbcParametersElement.parseImportJDBCParameters(inStream, iSql + 1, "sql"); 1160 } 1161 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition") || 1162 vecXmlElements.get(l).toString().equalsIgnoreCase("sql") || 1163 vecXmlElements.get(l).toString().equalsIgnoreCase("copyTable")) { 1164 1165 if (jdbcParametersElement.getJDBCSourceParameterDriver().equals("") || 1166 jdbcParametersElement.getJDBCSourceParameterDriver() == null) 1167 jdbcParametersElement.setJDBCSourceParameterDriver(configReaderSource. 1168 getDriverClassName()); 1169 1170 if (jdbcParametersElement.getJDBCTargetParameterDriver().equals("") || 1171 jdbcParametersElement.getJDBCTargetParameterDriver() == null) 1172 jdbcParametersElement.setJDBCTargetParameterDriver(configReaderTarget. 1173 getDriverClassName()); 1174 } 1175 this.logger.write("full", "Importing and parsing XML file is finished."); 1176 1177 connManager.setLoaderJobPath(this.strLoaderJobFileName); 1178 connManager.setConnectionPrefix(configReaderTarget.getConnectionPrefix()); 1179 connManager.setParsePermission(configReaderTarget.getFileSystemDatabase()); 1180 1181 try { 1182 connToPools = connManager.getConnection(jdbcParametersElement. 1183 getJDBCTargetParameterConnection()); 1184 connToPools.setAutoCommit(false); 1186 }catch (Exception ex) { 1187 String message = "Can't get connection to Target Database." + "\n" + 1188 "Maybe connection " 1189 + jdbcParametersElement.getJDBCTargetParameterConnection() 1190 + " is wrong. "; 1191 LoaderException le = new LoaderException("SQLException: " + message + "\n" + 1192 ex.getMessage() + "\n", (Throwable )ex); 1193 this.logger.write("full", le.getStackTraceAsString()); 1194 throw le; 1195 } 1196 if (vecXmlElements.get(l).toString().equalsIgnoreCase("importDefinition")) { 1197 if (importDefinitionElement.bRestartAutoCreate == true) { 1198 dataTransmition.createRestartCounterTable(connToPools); 1199 } 1200 this.currentJobName = "importDefinition"; 1201 String importName = importDefinitionElement.strImportDefinitionName; 1202 boolean doJob = true; 1203 for (int i = 0; i < this.includeTables.size(); i++) { 1204 if (importName.equalsIgnoreCase(this.includeTables.get(i).toString())) { 1205 doJob = true; 1206 break; 1207 } else { 1208 doJob = false; 1209 } 1210 } 1211 if (doJob) { 1212 try { 1213 this.loadSource(connToPools); 1214 1215 } 1216 catch (Exception ex) { 1217 LoaderException le = new LoaderException("SQLException: ", (Throwable )ex); 1219 this.logger.write("full", le.getStackTraceAsString()); 1220 if (importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("true")) { 1221 this.logger.write("normal", 1222 "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'"); 1223 } else { 1224 this.logger.write("normal", 1225 "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'"); 1226 connManager.release("true"); 1227 throw le; 1228 } 1229 } 1230 finally { 1232 for (int i = 0; i < pstmtForInsert.size(); i++) { 1233 String key = pstmtKeys.get(i).toString(); 1234 PreparedStatement pstmt = (PreparedStatement )pstmtForInsert.get(key); 1235 pstmt.close(); 1236 } 1237 pstmtKeys.clear(); 1238 pstmtForInsert.clear(); 1239 List transformations = this.transformations.getTransformations(); 1241 for(int iCount = 0; iCount < transformations.size(); iCount++ ) { 1242 ((Transformation)transformations.get(iCount)).release(); 1243 } 1244 } 1245 } else 1246 this.logger.write("normal", 1247 "\tImportDefinition " + importName + " is excluded from process"); 1248 iImport++; 1250 } 1251 else if (vecXmlElements.get(l).toString().equalsIgnoreCase("copyTable")) { 1253 if (importDefinitionElement.bRestartAutoCreate == true) { 1254 dataTransmition.createRestartCounterTable(connToPools); 1255 } 1256 this.currentJobName = "copyTable"; 1257 String importName = importDefinitionElement.strCopyTableName; 1258 boolean doJob = true; 1259 for (int i = 0; i < this.includeTables.size(); i++) { 1260 if (importName.equalsIgnoreCase(this.includeTables.get(i).toString())) { 1261 doJob = true; 1262 break; 1263 } else { 1264 doJob = false; 1265 } 1266 } 1267 if (doJob) { 1268 try { 1269 this.loadSourceCT(connToPools); 1270 } 1271 catch (Exception e) { 1272 LoaderException le = new LoaderException("SQLException: ", (Throwable )e); 1274 this.logger.write("full", le.getStackTraceAsString()); 1275 if (importDefinitionElement.strCopyTableOnErrorContinue.equalsIgnoreCase("true")) { 1276 this.logger.write("normal", 1277 "\tError : Application is not terminated because 'OnErrorContinue' attribute has value 'true'"); 1278 } else { 1279 this.logger.write("normal", 1280 "\tError : Application is terminated because 'OnErrorContinue' attribute has value 'false'"); 1281 connManager.release("true"); 1282 throw le; 1283 } 1284 } 1285 } else { 1286 this.logger.write("normal", "\tCopyTable " + importName + " is excluded from process"); 1287 } 1288 iCopy++; 1290 } else if (vecXmlElements.get(l).toString().equalsIgnoreCase("echo")) { 1291 this.currentJobName = "echo"; 1292 logger.writeEcho(this.logger.getMessage(new Integer (iEcho).toString())); 1293 iEcho++; 1294 } else if (vecXmlElements.get(l).toString().equalsIgnoreCase("sql")) { 1295 this.currentJobName = "sql"; 1296 String sqlName = sqlElement.getSqlName(); 1297 boolean doJob = true; 1298 for (int i = 0; i < this.includeTables.size(); i++) { 1299 if (sqlName.equalsIgnoreCase(this.includeTables.get(i).toString())) { 1300 doJob = true; 1301 break; 1302 } else { 1303 doJob = false; 1304 } 1305 } 1306 if (doJob) { 1307 try { 1308 if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) { 1309 connToPools.setAutoCommit(true); 1310 try{ 1312 this.executeSQLStatement(connToPools); 1313 }catch(Exception e){ 1314 throw e; 1315 } 1316 finally{ 1317 connToPools.setAutoCommit(false); 1318 } 1319 } else 1320 this.executeSQLStatement(connToPools); 1321 } 1322 catch (Exception e) { 1323 LoaderException le = new LoaderException("SQLException: ", 1324 (Throwable )e); 1325 this.logger.write("full", le.getStackTraceAsString()); 1327 if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase("true")) { 1328 this.logger.write("normal", 1329 "\tError : Because OnErrorContinue Attribute is true application is not terminated"); 1330 } 1331 else if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase("")&& 1332 loaderJobReader.getDefaultOnErrorContinue()==true) { 1333 1334 this.logger.write("normal", 1335 "\tError : Because OnErrorContinue Attribute is true application is not terminated"); 1336 } 1337 else { 1338 this.logger.write("normal", 1339 "\tError : Because OnErrorContinue Attribute is false application is terminated"); 1340 connManager.release("true"); 1341 throw le; 1342 } 1343 } 1344 } else { 1345 this.logger.write("normal", "\tSql statement " + sqlName + " is excluded from process"); 1346 } 1347 iSql++; 1348 } else { 1350 LoaderException le = new LoaderException("SQLException: ", 1353 (Throwable ) (new SQLException ( 1354 "Error : Loader supports loading data up to maximum 3 SQL database"))); 1355 this.logger.write("full", le.getStackTraceAsString()); 1356 if (connToPools != null) 1357 connManager.release("true"); 1358 throw le; 1359 } 1360 1361 if (!this.hasRestartCounter && iLastImportDefinition == l) { 1362 if (connToPools!=null && !connToPools.isClosed()) 1363 1364 connToPools.commit(); 1365 } 1366 1367 } 1368 this.logger.setEnabledLogLevels(this.defaultLogMode); 1369 connManager.release("false"); 1370 this.logger.write("normal", "All rows are commited."); 1371 this.logger.write("normal", "Application is finished."); 1372 this.logger.write("normal", "All jobs duration: " + this.timeCounter.getTotalTime()); 1373 } 1374 catch (IOException e) { 1375 LoaderException le = new LoaderException("IOException: ", (Throwable )e); 1376 this.logger.write("full", le.getStackTraceAsString()); 1378 throw le; 1379 } 1380 catch (ClassNotFoundException e) { 1381 LoaderException le = new LoaderException("ClassNotFoundException: ", 1382 (Throwable )e); 1383 this.logger.write("full", le.getStackTraceAsString()); 1385 1386 throw le; 1387 } 1388 catch (SQLException e) { 1389 LoaderException le = new LoaderException("SQLException: ", (Throwable )e); 1390 this.logger.write("full", le.getStackTraceAsString()); 1392 throw le; 1393 } 1394 catch (NullPointerException e) { 1395 LoaderException le = new LoaderException("NullPointerException: " + 1396 e.getMessage(), 1397 (Throwable )e); 1398 this.logger.write("full", le.getStackTraceAsString()); 1400 throw le; 1401 } 1402 catch (SAXException e) { 1403 LoaderException le = new LoaderException("SAXException: ", (Throwable )e); 1404 this.logger.write("full", le.getStackTraceAsString()); 1406 throw le; 1407 } 1408 catch (Exception e) { 1409 LoaderException le = new LoaderException("Exception: ", (Throwable )e); 1410 this.logger.write("full", le.getStackTraceAsString()); 1412 throw le; 1413 } 1414 finally { 1415 try { 1416 if (connToPools != null && !connToPools.isClosed()) 1417 connToPools.close(); 1418 this.logger.close(); 1419 } 1420 catch (SQLException e) { 1421 LoaderException le = new LoaderException("SQLException: ", 1422 (Throwable )e); 1423 this.logger.write("full", le.getStackTraceAsString()); 1425 throw le; 1426 } 1427 } 1428 } 1429 1430 1436 private void loadSourceCT(Connection connTarget) throws Exception { 1437 1438 this.timeCounter.setStartJobTime(); 1439 DateFormat dfNow = DateFormat.getDateTimeInstance(); 1440 Date currentDate = new Date (); 1441 1442 this.logger.write("full", "\tloadSourceCT method is started."); 1443 this.logger.write("normal", "Copy Table " + 1444 importDefinitionElement.strCopyTableName 1445 + " is started at " + dfNow.format(currentDate) + "."); 1446 1447 Connection connSource = null; 1448 ResultSet rsetSource = null; 1449 ResultSet rsetTarget = null; 1450 Statement stmtSource = null; 1451 Statement stmtTarget = null; 1452 String logStatement = ""; 1453 String strQuery = ""; 1454 Vector vecNewColumnNames = new Vector (); 1455 Vector vecNewColumnTypes = new Vector (); 1456 Hashtable tmpColumnReader = new Hashtable (); 1457 1458 boolean bOidLogicCurrentTable = new Boolean (importDefinitionElement.strCopyTableOidLogic). 1459 booleanValue(); 1460 boolean isTOS = ! (importDefinitionElement.strObjectIDNameColumnName.equals( 1461 "") || importDefinitionElement.strObjectIDNameColumnValue.equals("")); 1462 try { 1463 this.checkOidLogic(connTarget); 1464 if (configReaderSource.getRequiredUser()) { 1465 if (jdbcParametersElement.getJDBCSourceParameterUser().equals("")) 1466 this.inputUser(true); 1467 Class.forName(jdbcParametersElement.getJDBCSourceParameterDriver()); 1468 connSource = DriverManager.getConnection(jdbcParametersElement. 1469 getJDBCSourceParameterConnection(), 1470 jdbcParametersElement. 1471 getJDBCSourceParameterUser(), 1472 jdbcParametersElement. 1473 getJDBCSourceParameterPassword()); 1474 } else { 1475 Class.forName(jdbcParametersElement.getJDBCSourceParameterDriver()); 1476 connSource = DriverManager.getConnection(jdbcParametersElement. 1477 getJDBCSourceParameterConnection()); 1478 } 1479 1480 int iRowNumber = 0; 1481 boolean isEndFlag = false; 1482 stmtSource = connSource.createStatement(); 1483 stmtTarget = connTarget.createStatement(); 1484 1485 boolean setCursorName = false; 1487 if (!importDefinitionElement.setCursorNameCT.equalsIgnoreCase("")) 1488 setCursorName = new Boolean (importDefinitionElement.setCursorNameCT).booleanValue(); 1489 else 1490 setCursorName = configReaderSource.getSetCursorNameEnabled(); 1491 1492 if (setCursorName) { 1493 long cursorName = System.currentTimeMillis(); 1494 stmtSource.setCursorName(String.valueOf(cursorName)); 1495 } 1496 boolean setFetchSize = false; 1498 if (!importDefinitionElement.setFetchSizeCT.equalsIgnoreCase("")) 1499 setFetchSize = new Boolean (importDefinitionElement.setFetchSizeCT).booleanValue(); 1500 else 1501 setFetchSize = configReaderSource.getSetFetchSizeEnabled(); 1502 1503 if (setFetchSize) 1504 stmtSource.setFetchSize(importDefinitionElement.iCopyTableCommitCount); 1505 1510 boolean columnsSuportedTarget = configReaderTarget.getColumnsSupported(); 1511 boolean columnsSuportedSource = configReaderSource.getColumnsSupported(); 1512 1513 strQuery = "select * from "; 1514 1515 rsetSource = stmtSource.executeQuery(strQuery + importDefinitionElement.strCopyTableSourceTableName); 1517 int sourceColumnCount = rsetSource.getMetaData().getColumnCount(); 1518 try { 1519 if (columnsSuportedSource){ 1520 ResultSet rsetSourceTemp = connSource.getMetaData(). 1521 getColumns( connSource.getCatalog(), null, importDefinitionElement.strCopyTableSourceTableName, "%" ); 1522 while(rsetSourceTemp.next()){ 1523 vecNewColumnNames.add(rsetSourceTemp.getString(4)); 1524 } 1525 rsetSourceTemp.close(); 1526 1527 }else{ 1528 for (int i = 1; i < sourceColumnCount + 1; i++) { 1530 vecNewColumnNames.add(rsetSource.getMetaData().getColumnName(i)); 1531 } 1532 } 1533 1534 if (columnsSuportedTarget){ 1535 ResultSet rsetTargetTemp = connTarget.getMetaData(). 1536 getColumns( connTarget.getCatalog(), null, importDefinitionElement.strCopyTableTargetTableName, "%" ); 1537 1538 while (rsetTargetTemp.next()) { 1539 String targetColumnName = rsetTargetTemp.getString(4); 1540 String targetColumnType = rsetTargetTemp.getString(6); 1541 tmpColumnReader.put(targetColumnName.toUpperCase(), targetColumnType); 1542 } 1543 rsetTargetTemp.close(); 1544 1545 }else{ 1546 if (configReaderTarget.getMaxRowsSupported()){ 1547 stmtTarget.setMaxRows(1); 1548 } 1549 1550 rsetTarget = stmtTarget.executeQuery(strQuery + 1551 importDefinitionElement.strCopyTableTargetTableName); 1552 int targetColumnCount=0; 1553 targetColumnCount = rsetTarget.getMetaData().getColumnCount(); 1554 for (int i = 1; i < targetColumnCount + 1; i++) { 1555 String targetColumnName = rsetTarget.getMetaData().getColumnName(i); 1556 String targetColumnType = rsetTarget.getMetaData().getColumnTypeName(i); 1557 tmpColumnReader.put(targetColumnName.toUpperCase(), targetColumnType); 1558 } 1559 rsetTarget.close(); 1560 } 1561 1562 1563 for (int i = 0; i < vecNewColumnNames.size(); i++) { 1565 String columnName=vecNewColumnNames.get(i).toString().toUpperCase(); 1566 String tmpTargetColumnType = tmpColumnReader.get(columnName).toString(); 1567 vecNewColumnTypes.add(tmpTargetColumnType); 1568 } 1569 1570 } 1571 1572 1573 1574 catch (Exception ex) { 1575 1576 String msg = "In copy table job '" + importDefinitionElement.strCopyTableName + "'," + 1577 " Source and Target table are not compatibile."; 1578 Exception e = new Exception (msg + "\n" + ex.getMessage()); 1579 throw e; 1580 } 1581 1582 int currentBlock = 0; 1583 int blockNumber = 0; 1584 int bdecRowCount = 0; 1585 int currentVersion = 0; 1586 BigDecimal bdecCounter = new BigDecimal (0); 1587 1588 if (configReaderSource.getRowCountEnabled()) { 1589 String countSQL = ""; 1590 try { 1591 countSQL = " select count(*) from " 1594 + importDefinitionElement.strCopyTableName; 1595 Statement stmtSourceCount = connSource.createStatement(); 1596 ResultSet rsetSourceCount = stmtSourceCount.executeQuery(countSQL); 1597 rsetSourceCount.next(); 1598 iRowNumber = rsetSourceCount.getInt(configReaderSource.getFirstColumnResult()); 1600 blockNumber = iRowNumber / importDefinitionElement.iCopyTableCommitCount + 1; 1601 rsetSourceCount.close(); 1602 stmtSourceCount.close(); 1603 }catch(Exception e) { 1604 this.logger.write(Logger.LOGMODE_NORMAL, "Error while execute count sql: "+countSQL); 1605 } 1606 } 1607 1608 boolean main = true; 1609 if (!importDefinitionElement.strRestartCounterTableName.equals("")) { 1610 if (this.hasRestartCounter) { 1611 bdecCounter = dataTransmition.checkDataTransmition(connTarget, rsetSource, 1612 this.currentJobName, configReaderTarget.getFirstColumnResult()); 1613 1614 if (bdecCounter != null) { 1615 if (bdecCounter.toString().equalsIgnoreCase("0")) { 1616 main = false; 1618 } 1619 } else { 1620 bdecCounter = new BigDecimal (0); 1621 } 1622 } 1623 } 1624 1625 while (main) { 1626 this.logger.write("normal", "Import block is started."); 1628 currentBlock++; 1629 if (configReaderSource.getRowCountEnabled()) { 1630 this.logger.write("normal", "Working... " + currentBlock + ". block of " + blockNumber); 1631 } else { 1632 this.logger.write("normal", "Working... " + currentBlock + ". block"); 1633 } 1634 this.logger.write("full", "\tStarted from the " + bdecCounter.add( 1635 new BigDecimal (1)).toString() + ". row."); 1636 iRowNumber = 0; 1637 1638 QueryInsertRowCt queryInsertRowCt = new QueryInsertRowCt( 1639 bOidLogicCurrentTable, 1640 isTOS, 1641 vecNewColumnNames, 1642 vecNewColumnTypes, 1643 importDefinitionElement.strCopyTableTargetTableName, 1644 this.bdecOidNumber, 1645 this.currentOidColumnName, 1646 this.currentVersionColumnName, 1647 configReaderTarget.getOidDbType(), 1648 configReaderTarget.getVersionDbType(), 1649 configReaderTarget.getJavaTypeMapings()); 1650 1651 String pstmtInsert = queryInsertRowCt.getPreperedStatementForInsert(); 1652 PreparedStatement pstmt = connTarget.prepareStatement(pstmtInsert); 1653 1654 while (iRowNumber < importDefinitionElement.iCopyTableCommitCount) { 1655 if (!rsetSource.next()) { 1656 isEndFlag = true; 1657 break; 1658 } 1659 currentRow = iRowNumber; 1660 if (bOidLogicCurrentTable) { 1661 if (this.bdecOidNumber.compareTo(this.bdecOidNumber2000) == 0) { 1662 this.checkOidLogic(connTarget); 1663 this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal (1)); 1664 } else { 1665 this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal (1)); 1666 } 1667 } 1668 try { 1669 int mnemonic = -1; 1670 String insertForOut = pstmtInsert; 1671 for (int i = 1; i < sourceColumnCount + 1; i++) { 1672 String columnType=vecNewColumnTypes.get(i - 1).toString(); 1673 String javaType =(String )configReaderTarget.getJavaTypeMapings().get(columnType.toUpperCase()); 1674 1675 if(javaType == null) { 1676 this.logger.write("normal", "There is no java type defined for sql type "+columnType.toUpperCase()); 1677 LoaderException le = new LoaderException("Exception:",new Exception ("There is no java type defined for sql type "+columnType.toUpperCase())); 1678 this.logger.write("full", le.getStackTraceAsString()); 1679 throw le; 1680 } 1681 1682 1683 int javaTypeInt=Integer.parseInt(javaType); 1684 if (javaTypeInt==1) { 1685 byte[] isBlob = rsetSource.getBytes(i); 1686 if (isBlob == null || isBlob.length == 0) { 1687 pstmt.setBytes(i, null); 1688 mnemonic = insertForOut.indexOf("?"); 1689 insertForOut = insertForOut.substring(0, mnemonic) + "BinaryObject(null)" + 1690 insertForOut.substring(mnemonic + 1); 1691 } else { 1692 ByteArrayInputStream bais = new ByteArrayInputStream (isBlob); 1693 pstmt.setBytes(i, isBlob); 1695 1697 mnemonic = insertForOut.indexOf("?"); 1698 insertForOut = insertForOut.substring(0, mnemonic) + "BinaryObject" + 1699 insertForOut.substring(mnemonic + 1); 1700 } 1701 } else { 1702 String value = rsetSource.getString(i); 1703 if (value == null) 1704 value = "null"; 1705 if (bReplaceInData) 1706 value = this.replaceInData(value); 1707 1708 if (javaTypeInt == 2) { if (!value.equalsIgnoreCase("null")) { 1710 BigDecimal number = new BigDecimal (0); 1711 if (!value.equalsIgnoreCase("")) 1712 number = new BigDecimal (value); 1713 pstmt.setBigDecimal(i, number); 1714 } else { 1715 pstmt.setNull(i, java.sql.Types.DECIMAL); 1716 } 1717 } else if (javaTypeInt == 3) { if (!value.equalsIgnoreCase("null")) { 1719 double number = 0; 1720 if (!value.equalsIgnoreCase("")) 1721 number = Double.parseDouble(value); 1722 pstmt.setDouble(i, number); 1723 } else { 1724 pstmt.setNull(i, java.sql.Types.DOUBLE); 1725 } 1726 } else if (javaTypeInt == 4) { if (!value.equalsIgnoreCase("null")) { 1728 float number = 0; 1729 if (!value.equalsIgnoreCase("")) 1730 number = Float.parseFloat(value); 1731 pstmt.setFloat(i, number); 1732 } else { 1733 pstmt.setNull(i, java.sql.Types.FLOAT); 1734 } 1735 } else if (javaTypeInt == 5) { if (!value.equalsIgnoreCase("null")) { 1737 int number = 0; 1738 if (!value.equalsIgnoreCase("")) 1739 number = Integer.parseInt(value); 1740 pstmt.setInt(i, number); 1741 } else { 1742 pstmt.setNull(i, java.sql.Types.INTEGER); 1743 } 1744 1745 } else if (javaTypeInt == 6) { if (!value.equalsIgnoreCase("null")) { 1747 long number = 0; 1748 if (!value.equalsIgnoreCase("")) 1749 number = Long.parseLong(value); 1750 pstmt.setLong(i , number); 1751 } else { 1752 pstmt.setNull(i, java.sql.Types.DOUBLE); 1753 } 1754 } else if (javaTypeInt == 7) { if (!value.equalsIgnoreCase("null")) { 1756 short number = 0; 1757 if (!value.equalsIgnoreCase("")) 1758 number = Short.parseShort(value); 1759 pstmt.setShort(i , number); 1760 } else { 1761 pstmt.setNull(i , java.sql.Types.SMALLINT); 1762 } 1763 } else if (javaTypeInt == 8) { if (!value.equalsIgnoreCase("null")) { 1765 if (value.indexOf("''") != -1) { 1767 value = Utils.replaceAll(value, "''", "'"); 1768 } 1769 pstmt.setString(i, value); 1770 } else { 1771 pstmt.setNull(i , java.sql.Types.VARCHAR); 1772 } 1773 } else if (javaTypeInt == 9) { if (!value.equalsIgnoreCase("null")) { 1775 pstmt.setString(i, value); 1776 } else { 1777 pstmt.setNull(i , java.sql.Types.DATE); 1778 } 1779 } else if (javaTypeInt == 10) { if (!value.equalsIgnoreCase("null")) { 1781 pstmt.setString(i, value); 1782 } else { 1783 pstmt.setNull(i, java.sql.Types.TIME); 1784 } 1785 1786 } else if (javaTypeInt == 11) { if (!value.equalsIgnoreCase("null")) { 1788 pstmt.setString(i, value); 1789 } else { 1790 pstmt.setNull(i , java.sql.Types.TIMESTAMP); 1791 } 1792 1793 } else if (javaTypeInt == 12) { if (!value.equalsIgnoreCase("null")) { 1795 boolean bool = Boolean.getBoolean(value); 1796 pstmt.setBoolean(i, bool); 1797 } else { 1798 pstmt.setNull(i , java.sql.Types.BIT); 1800 } 1801 } else if (javaTypeInt == 13) { if (!value.equalsIgnoreCase("null")) { 1803 pstmt.setString(i, value); 1804 } else { 1805 pstmt.setNull(i, java.sql.Types.BIT); 1806 } 1807 } else if (javaTypeInt == 14) { if (!value.equalsIgnoreCase("null")) { 1809 pstmt.setString(i, value); 1810 } else { 1811 pstmt.setNull(i, java.sql.Types.NULL); 1813 } 1815 } 1816 1817 mnemonic = insertForOut.indexOf("?"); 1818 insertForOut = insertForOut.substring(0, mnemonic) + value + 1819 insertForOut.substring(mnemonic + 1); 1820 1821 1822 1823 } } logStatement = insertForOut; 1826 this.logger.write("full", "\tQuery '" + insertForOut + "' will be executed"); 1827 pstmt.executeUpdate(); 1828 pstmt.clearParameters(); 1829 } 1830 catch (Exception ex) { 1831 if (importDefinitionElement.strCopyTableOnErrorContinue.equalsIgnoreCase("true")) { 1832 dataCleaning.cleaningInsert(importDefinitionElement.strCopyTableTargetTableName, 1833 connTarget, currentRow, "INSERT", ex.getMessage(), 1834 "COPY TABLE", logStatement); 1835 } else { 1836 throw ex; 1837 } 1838 } 1839 this.logger.write("full", "\tinsertRow method is finished."); 1840 iRowNumber++; 1841 } 1843 if (!importDefinitionElement.strRestartCounterTableName.equals("")) { 1845 if (this.hasRestartCounter) { 1846 bdecCounter = bdecCounter.add(new BigDecimal (iRowNumber)); 1847 dataTransmition.insertCounter(this.currentJobName, bdecCounter, connTarget); 1848 } 1849 } 1850 if (this.hasRestartCounter) { 1851 1852 connTarget.commit(); 1853 this.logger.write("normal", "Imported block is commited."); 1854 this.logger.write("full", Integer.toString(iRowNumber) + " rows are commited."); 1855 } 1856 1857 iRowNumber = 0; 1858 if (isEndFlag) { 1859 break; 1860 } 1861 pstmt.close(); 1862 } 1864 strQuery = ""; 1865 rsetSource.close(); 1866 stmtSource.close(); 1868 stmtTarget.close(); 1869 if (!connSource.isClosed()) 1870 connSource.close(); 1871 1872 if (!importDefinitionElement.strRestartCounterTableName.equals("")) { 1874 if (this.hasRestartCounter) { 1875 dataTransmition.resetRestartCounter(connTarget, this.currentJobName); 1876 } 1877 } 1878 currentDate = new Date (); 1879 dfNow = DateFormat.getDateTimeInstance(); 1880 this.logger.write("normal", "Copy table " + importDefinitionElement.strCopyTableName 1881 + " is finished at " + dfNow.format(currentDate) + "."); 1882 this.logger.write("normal", " Duration of copyTable:" + 1883 this.timeCounter.getJobTime()); 1884 } 1885 catch (Exception e) { 1886 throw e; 1887 } 1888 } 1889 1890 1899 private void loadSource(Connection connTarget) throws LoaderException { 1900 int iRowNumber = 0; 1901 BigDecimal bdecCounter = new BigDecimal (0); 1902 BigDecimal k = new BigDecimal (0); 1903 Date currentDate = new Date (); 1904 DateFormat dfNow = DateFormat.getDateTimeInstance(); 1905 boolean columnsSuportedTarget = configReaderTarget.getColumnsSupported(); 1906 this.timeCounter.setStartJobTime(); 1907 this.logger.write("full", "\tloadSource method is started."); 1908 this.logger.write("normal", "Import definition " + 1909 importDefinitionElement.strImportDefinitionName 1910 + " is started at " + dfNow.format(currentDate) + "."); 1911 Connection connSource = null; 1912 1913 try { 1914 1915 for (int i = 0; i < this.iTables; i++) { 1916 this.counterColumns.setTargetColumnStartValues(this.vecTableTableName. 1917 get(i).toString(), 1918 this.vecTableTableID.get(i).toString(), connTarget, 1919 this.iTargetFirstColumnResult); 1920 this.counterColumns.counterColumnTypes(this.vecTableTableName.get(i). 1921 toString(), 1922 this.vecTableTableID.get(i). 1923 toString(), 1924 connTarget, 1925 this.iTargetFirstColumnResult, columnsSuportedTarget, configReaderTarget); 1926 1927 } 1928 1929 if (configReaderSource.getRequiredUser()) { 1931 if (jdbcParametersElement.getJDBCSourceParameterUser().equals("")) 1932 this.inputUser(true); 1933 Class.forName(jdbcParametersElement.getJDBCSourceParameterDriver()); 1934 connSource = DriverManager.getConnection(jdbcParametersElement. 1935 getJDBCSourceParameterConnection(), 1936 jdbcParametersElement.getJDBCSourceParameterUser(), 1937 jdbcParametersElement.getJDBCSourceParameterPassword()); 1938 1939 } else { 1940 Class.forName(jdbcParametersElement.getJDBCSourceParameterDriver()); 1941 connSource = DriverManager.getConnection(jdbcParametersElement. 1942 getJDBCSourceParameterConnection()); 1943 } 1944 1945 Statement stmtSource = null; 1946 stmtSource = connSource.createStatement(); 1947 1948 if (importDefinitionElement.bObjectIDAutoCreate == true) { 1950 createObjectIDTable(connTarget); 1951 connTarget.commit(); 1952 } 1953 1955 this.constantColumnTypes(connTarget); 1956 this.targetColumnTypes(connTarget); 1957 this.checkOidLogic(connTarget); 1958 1959 int currentBlock = 0; 1960 String strQueryWhere = ""; 1961 1962 for (int i = 0; i < this.iTables; i++) { 1963 ArrayList trans = this.transformations.getTransformations(); 1971 Iterator iTrans = trans.iterator(); 1972 1973 while(iTrans.hasNext()) { 1974 Transformation temp = (Transformation)iTrans.next(); 1975 1976 temp.transformationColumnTypes(connTarget, 1978 this.iTargetFirstColumnResult, 1979 columnsSuportedTarget, configReaderTarget); 1980 1981 } 1982 Vector pomTypes; 1985 Vector pomNames; 1986 Vector pomValueModes; 1987 Vector targetKeyColumnNames; 1988 Vector targetColumnNames; 1989 Vector targetColumnTypes; 1990 targetColumnNames = new Vector (); 1991 targetKeyColumnNames = new Vector (); 1992 Vector targetValueModes = new Vector (); 1993 targetColumnTypes = new Vector (); 1994 pomNames = new Vector (); 1995 pomTypes = new Vector (); 1996 pomValueModes = new Vector (); 1997 1998 String tableId = this.vecTableTableID.get(i).toString(); 1999 ArrayList transTableIDs = this.transformations.getTransformationsTableIDs(); 2000 if (transTableIDs.contains(tableId)){ 2001 2002 for (int j=0; j < trans.size();j++){ 2003 Transformation pom = (Transformation)trans.get(j); 2004 targetColumnNames = pom.getTargetColumnNames(i); 2005 targetColumnTypes = pom.getTargetColumnTypes(i); 2006 targetKeyColumnNames = pom.getTargetKeyColumnNames(i); 2007 targetValueModes = pom.getTargetValueModes(i); 2008 2009 for (int o=0; o < targetColumnTypes.size();o++){ 2010 pomTypes.add(targetColumnTypes.get(o).toString()); 2011 } 2012 for (int o=0; o < targetColumnNames.size();o++){ 2013 pomNames.add(targetColumnNames.get(o).toString()); 2014 } 2015 for (int o=0; o < targetValueModes.size();o++){ 2016 pomValueModes.add(targetValueModes.get(o).toString()); 2017 } 2018 } 2019 2020 } 2021 2022 this.transformationsColumnTypes.add(pomTypes); 2023 this.transformationsColumnNames.add(pomNames); 2024 this.transformationsValueModes.add(pomValueModes); 2025 boolean bOidLogicCurrentTable = new Boolean (this.vecTableOidLogic.get(i). 2027 toString()).booleanValue(); 2028 boolean isTOS = ! (importDefinitionElement.strObjectIDNameColumnName. 2029 equals("") || 2030 importDefinitionElement.strObjectIDNameColumnValue. 2031 equals("")); 2032 boolean oid = false; 2033 if (bOidLogicCurrentTable && !isTOS) 2034 oid = true; 2035 2036 LoadAllSourceData allSourceData = null; 2038 Vector vecRelationColumns = this.vecRelationColumnTargetColumnName; 2039 Vector vecVariableColumns = this.vecVariableColumnTargetColumnName; 2040 Vector vecConstantColumns = (Vector )this.vecConstantTargetColumnName.get(i); 2041 2042 Vector vecUseIDColumns = this.vecVariableUseIDColumnName; 2043 Vector vecTimesColumns = this.vecVariableTimesColumnName; 2044 2045 String ctAutoMapColumns = this.vecCTAutoMapp.get(i).toString(); 2046 String ctDefaultMode = this.vecCTDefaultMode.get(i).toString(); 2047 String sourceTableName = importDefinitionElement.strImportDefinitionTableName; 2048 2050 if (ctAutoMapColumns.equalsIgnoreCase("true")) { 2051 allSourceData = new LoadAllSourceData(connSource, sourceTableName, 2052 ImportDefinitionSourceColumnName, 2053 vecTableTableName.get(i).toString(), 2054 connTarget, logger, vecRelationColumns, 2055 vecVariableColumns, vecConstantColumns, 2056 vecUseIDColumns, vecTimesColumns, columnsSuportedTarget,configReaderTarget); 2057 } else { 2058 } 2060 2061 if (allSourceData != null) { 2063 String keySource = String.valueOf(i); 2064 allSourceColumnNameNoMap.put(keySource, allSourceData.getNoMapSourceColumnName()); 2065 allSourceColumnTypeNoMap.put(keySource, allSourceData.getNoMapSourceColumnType()); 2066 allSourceColumnValueNoMap.put(keySource, allSourceData.getNoMapSourceColumnValue()); 2067 } 2068 2069 if (allSourceData != null) { 2072 if (allSourceData.getNoMapSourceColumnName().size() > 0) { 2073 for (int o = 0; o < allSourceData.getNoMapSourceColumnName().size(); o++) { 2074 ( (Vector )this.vecTargetColumnName.get(i)).add(allSourceData. 2075 getNoMapSourceColumnName().get(o).toString()); 2076 ( (Vector )this.vecSourceColumnName.get(i)).add(allSourceData. 2077 getNoMapSourceColumnName().get(o).toString()); 2078 ( (Vector )this.vecToHex.get(i)).add(""); 2079 ( (Vector )this.vecFromHex.get(i)).add(""); 2080 ( (Vector )this.vecDefaultValue.get(i)).add(""); 2081 } 2082 int map = Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString()); 2083 int noMap = allSourceData.getNoMapSourceColumnName().size(); 2084 int all = map + noMap; 2085 this.vecValueColumnsTargetTables.set(i, new Integer (all)); 2086 } 2087 } 2088 if (allSourceData != null) { 2089 if (allSourceData.getNoMapSourceColumnName().size() > 0) { 2090 for (int o = 0; o < allSourceData.getNoMapSourceColumnName().size(); o++) { 2091 ( (Vector )this.vecValueMode.get(i)).add(ctDefaultMode); 2092 } 2093 } 2094 } 2095 if (allSourceData != null) { 2096 if (allSourceData.getNoMapSourceColumnType().size() > 0) { 2097 for (int o = 0; o < allSourceData.getNoMapSourceColumnType().size(); o++) { 2098 ( (Vector )this.vecTargetColumnType.get(i)).add(allSourceData. 2099 getNoMapSourceColumnType().get(o).toString()); 2100 } 2101 } 2102 } 2103 2104 Vector vecColumnNames = (Vector )this.vecTargetColumnName.get(i); 2105 Vector vecColumnTypes = (Vector )this.vecTargetColumnType.get(i); 2106 Vector vecValueModes = (Vector )this.vecValueMode.get(i); 2107 2108 QuerySet querySet = new QuerySet(i, bOidLogicCurrentTable, isTOS, 2110 vecColumnNames, vecTableTableName, 2111 this.currentOidColumnName, 2112 this.currentVersionColumnName); 2113 2114 queryWhereSet = new QueryWhereSet(vecColumnNames, vecColumnTypes, 2116 vecTableTableName.get(i).toString(), 2117 vecTableTableID.get(i).toString()); 2118 2119 QueryUpdateSet queryUpdateSet = new QueryUpdateSet(vecColumnNames, 2121 vecColumnTypes, 2122 vecValueModes, vecTableTableName.get(i).toString(), oid, 2123 this.currentVersionColumnName, configReaderTarget); 2124 2125 if ( ( (Vector )this.vecTargetKeyColumnName.get(i)).size() > 0) 2126 queryWhereSet.getKeyColumns( (Vector )this.vecTargetKeyColumnName.get( 2128 i), configReaderTarget); 2129 2130 if ( targetKeyColumnNames.size() > 0) 2132 queryWhereSet.getTransformationKeyColumns(targetColumnNames, 2133 targetKeyColumnNames, 2134 targetColumnTypes, 2135 configReaderTarget); 2136 2138 2139 if ( ( (Vector )this.vecRelationKeyColumns.get(i)).size() > 0) 2140 queryWhereSet.getRelationKeyColumns( (Vector )vecRelationKeyColumns. 2141 get(i), iRelationColumns, 2142 vecRelationColumnTargetTableName, 2143 vecRelationColumnTargetTableID, 2144 vecRelationColumnTargetColumnName, 2145 (Vector )vecRelationKeyTypes.get(i), configReaderTarget); 2147 if ( ( (Vector )this.vecConstantTargetColumnName.get(i)).size() > 0) 2148 queryWhereSet.getConstantKeyColumns( (Vector )this. 2149 vecConstantTargetColumnName.get(i), 2150 (Vector )this.vecConstantValueMode. 2151 get(i), 2152 (Vector )this. 2153 vecConstantColumnType.get(i), 2154 configReaderTarget); 2155 2156 if (vecVariableColumnTargetTableName.size() > 0) 2157 queryWhereSet.getVariableKeyColumns(vecVariableColumnTargetTableName, 2158 vecVariableColumnTargetTableID, 2159 vecVariableColumnValueMode, 2160 vecVariableName, 2161 vecVariableColumnName, 2162 vecVariableColumnTargetColumnName, 2163 vecVariableColumnTypes, logger, configReaderTarget); 2164 2166 InsertRowQuerySet insertRowQuerySet = new InsertRowQuerySet(connTarget, 2167 (Vector )this.vecTargetColumnName.get(i), 2168 (Vector )this.vecValueMode.get(i), 2169 vecTableTableName.get(i).toString(), 2170 vecTableTableID.get(i).toString(), 2171 i, 2172 (Vector )this.vecConstantTargetColumnName.get(i), 2173 vecVariableTimesTableName, 2174 vecVariableTimesTableID, 2175 vecVariableTimesColumnName, 2176 vecVariableColumnTargetTableName, 2177 vecVariableColumnTargetTableID, 2178 vecVariableColumnTargetColumnName, 2179 vecRelationColumnTargetColumnName, 2180 vecRelationColumnTargetTableName, 2181 vecRelationColumnTargetTableID, 2182 vecRelationColumnRelationMode, 2183 counterColumns, 2184 transformations, 2185 bOidLogicCurrentTable, isTOS, 2186 this.currentOidColumnName, 2187 this.currentVersionColumnName); 2188 2189 if ( ( (Vector )this.vecConstantTargetColumnName.get(i)).size() > 0) 2191 queryConstantSet = new QueryConstantSet(vecTableTableName.get(i). 2192 toString(), 2193 (Vector )this. 2194 vecConstantTargetColumnName. 2195 get(i), 2196 (Vector )this. 2197 vecConstantValueMode. 2198 get(i), 2199 (Vector )this. 2200 vecConstantColumnType.get(i), 2201 configReaderTarget); 2202 strQuerySet = querySet.getQuerySet(); 2203 strQueryWhere = queryWhereSet.getQueryWhere(); 2204 2205 if (! (strQueryWhere.length() < 8)) { 2206 strQueryWhere = strQueryWhere.substring(0, strQueryWhere.length() - 4); 2207 } else { 2208 strQueryWhere = ""; 2209 } 2210 2211 2212 if ( ( ((Vector )this.transformationsColumnNames).size() > 0)) 2213 queryTransformationSet = new QueryTransformationSet(vecTableTableName.get(i).toString(), 2214 (Vector )this.transformationsColumnNames.get(i), 2215 (Vector )this.transformationsValueModes.get(i), 2216 (Vector )this.transformationsColumnTypes.get(i), 2217 configReaderTarget); 2218 2219 String strQueryTarget = strQuerySet + strQueryWhere; 2221 String key = String.valueOf(i); 2222 Vector indexDommyValue = queryWhereSet.getIndexDummyValue(); 2223 Vector indexDommyRelationValue = queryWhereSet. 2224 getIndexDummyRelationValue(); 2225 Vector indexDommyConstantValue = queryWhereSet. 2226 getIndexDummyConstantValue(); 2227 Vector indexDommyVariableValue = queryWhereSet. 2228 getIndexDummyVariableValue(); 2229 2230 Vector indexDummyTransformationValue = queryWhereSet. 2232 getTransformationKeyColumns(); 2233 queryStatement.put(key, strQueryTarget); 2235 indexDValue.put(key, indexDommyValue); 2236 indexDRelationValue.put(key, indexDommyRelationValue); 2237 indexConstantDValue.put(key, indexDommyConstantValue); 2238 indexDVariableValue.put(key, indexDommyVariableValue); 2239 indexDTransformationValue.put(key, indexDummyTransformationValue); 2241 String strUpdateTarget = queryUpdateSet.getQueryUpdate(); 2244 Vector indexDommyOverwrite = queryUpdateSet.getIndexDummyOverwrite(); 2245 Vector indexDommySetNull = queryUpdateSet.getIndexDummySetNull(); 2246 2247 updateStatement.put(key, strUpdateTarget); 2248 indexDOverwrite.put(key, indexDommyOverwrite); 2249 indexDSetNull.put(key, indexDommySetNull); 2250 2251 if (queryConstantSet != null) { 2253 String strUpdateConstant = queryConstantSet.getQueryConstant(); 2254 Vector indexConstantOver = queryConstantSet.getIndexDummyOverwrite(); 2255 Vector indexConstantNull = queryConstantSet.getIndexDummyNull(); 2256 2257 updateConstantStatement.put(key, strUpdateConstant); 2258 indexDConstantOver.put(key, indexConstantOver); 2259 indexDConstantNull.put(key, indexConstantNull); 2260 } 2261 2262 if (queryTransformationSet != null) { 2263 2264 String strUpdateTransformation = queryTransformationSet.getQueryTransformation(); 2265 Vector indexTransformationOver = queryTransformationSet.getIndexDummyOverwrite(); 2266 Vector indexTransformationNull = queryTransformationSet.getIndexDummyNull(); 2267 Vector indexTransformationUpdate = queryTransformationSet.getIndexDummyUpdate(); 2268 2269 updateTransformationStatement.put(key, strUpdateTransformation); 2270 indexDTransformationOver.put(key, indexTransformationOver); 2271 indexDTransformationNull.put(key, indexTransformationNull); 2272 indexDTransformationUpdate.put(key, indexTransformationUpdate); 2273 } 2274 String strInsertRow = insertRowQuerySet.getStrQuery(); 2276 Vector indexRelations = insertRowQuerySet.getIndexDummyIsNotRelationsColumn(); 2277 PreparedStatement pstmt = insertRowQuerySet.getPreparedStatementForInsert(); 2279 Vector pstmtCNames = insertRowQuerySet.getColumnNames(); 2280 2282 pstmtKeys.add(key); 2284 queryInsertRow.put(key, strInsertRow); 2285 indexIsNotRelationsColumns.put(key, indexRelations); 2286 pstmtForInsert.put(key, pstmt); 2287 pstmtColumnNames.put(key, pstmtCNames); 2288 } 2290 2291 String strQuery = ""; 2292 if (importDefinitionElement.strImportDefinitionSelectStatement != null && 2294 !importDefinitionElement.strImportDefinitionSelectStatement.equals("")) { 2295 strQuery = importDefinitionElement.strImportDefinitionSelectStatement; 2296 if(this.transformations.getTransformations().size() > 0) { 2303 SqlParser parser = new SqlParser(); 2304 try { 2305 parser.parse(strQuery); 2306 } catch (Throwable e) { 2307 this.logger.write("full","Unable to parse sql query from 'selectStatement' attribute. This is needed by transformations if they exists."); 2308 } 2309 String [] columnNames = parser.getColumnNames(); 2310 List allSourceColNames = this.transformations.getAllTransformationSourceColNames(); 2311 for(int br1 = 0; br1 < columnNames.length; br1++) { 2312 for(int br2 = 0; br2 < allSourceColNames.size(); br2++) { 2313 if( allSourceColNames.get(br2).toString().toUpperCase().equals( columnNames[br1] ) ) 2314 this.iOffsetForTransColumns = br1; 2315 break; 2316 } 2317 } 2318 } 2319 2320 if (!configReaderSource.getReadingOrderRelevant()) { 2321 int in = 0; 2322 int jn = 0; 2323 Vector vecVector = new Vector (); 2324 while (in < this.iTables) { 2325 vecVector = (Vector )this.vecSourceColumnName.get(in); 2326 while (jn < 2327 Integer.parseInt(this.vecValueColumnsTargetTables.get(in).toString())) { 2328 jn++; 2329 this.iColumnsInSourceTable++; 2330 } 2331 jn = 0; 2332 in++; 2333 } 2334 } 2335 } else { 2336 strQuery = this.querySource(); 2338 } 2339 2340 if (strQuery.indexOf("order by") != -1) { 2341 if (checkSortColumns(connSource)) { 2342 this.logger.write("normal", 2343 "Error : Sort columns have more rows with equals values."); 2344 LoaderException le = new LoaderException("SQLException: ", 2345 (Throwable ) (new SQLException ( 2346 "Error : Sort columns have more rows with equals values."))); 2347 this.logger.write("full", le.getStackTraceAsString()); 2348 throw le; 2349 } 2350 } 2351 2352 ResultSet rsetSource = null; 2353 int blockNumber = 0; 2354 boolean usingSelectStmt = false; 2355 if (importDefinitionElement.strImportDefinitionSelectStatement != null && 2356 !importDefinitionElement.strImportDefinitionSelectStatement.equals("")) { 2357 usingSelectStmt = true; 2358 } else { 2359 if (configReaderSource.getRowCountEnabled()) { 2360 String countSQL = " select count(*) as \"counter\" from " + 2361 importDefinitionElement.strImportDefinitionTableName; 2362 Statement stmtSourceCount = connSource.createStatement(); 2363 ResultSet rsetSourceCount = stmtSourceCount.executeQuery(countSQL); 2364 rsetSourceCount.next(); 2365 iRowNumber = rsetSourceCount.getInt("counter"); 2366 blockNumber = iRowNumber / importDefinitionElement.iImportDefinitionCommitCount + 1; 2367 rsetSourceCount.close(); 2368 stmtSourceCount.close(); 2369 } 2370 } 2371 iRowNumber = 0; 2372 2373 boolean setCursorName = false; 2376 if (!importDefinitionElement.setCursorNameID.equalsIgnoreCase("")) 2377 setCursorName = new Boolean (importDefinitionElement.setCursorNameID).booleanValue(); 2378 else 2379 setCursorName = configReaderSource.getSetCursorNameEnabled(); 2380 2381 if (setCursorName) { 2382 long cursorName = System.currentTimeMillis(); 2383 stmtSource.setCursorName(String.valueOf(cursorName)); 2384 } 2385 boolean setFetchSize = false; 2387 if (!importDefinitionElement.setFetchSizeID.equalsIgnoreCase("")) 2388 setFetchSize = new Boolean (importDefinitionElement.setFetchSizeID).booleanValue(); 2389 else 2390 setFetchSize = configReaderSource.getSetFetchSizeEnabled(); 2391 2392 if (setFetchSize) 2393 stmtSource.setFetchSize(importDefinitionElement.iImportDefinitionCommitCount); 2394 2395 this.logger.write("full", "\tQuery '" + strQuery + "' will be executed"); 2396 rsetSource = stmtSource.executeQuery(strQuery); 2397 2398 boolean main = true; 2400 if (!importDefinitionElement.strRestartCounterTableName.equals("")) { 2401 if (this.hasRestartCounter) { 2402 bdecCounter = dataTransmition.checkDataTransmition(connTarget, rsetSource, 2403 this.currentJobName, configReaderTarget.getFirstColumnResult()); 2404 2405 if (bdecCounter != null) { 2406 if (bdecCounter.toString().equalsIgnoreCase("0")) { 2407 main = false; 2409 } 2410 } else { 2411 bdecCounter = new BigDecimal (0); 2412 } 2413 } 2414 2415 if (!bdecCounter.toString().equalsIgnoreCase("0")) { 2416 int num1 = Integer.parseInt(bdecCounter.toString()); 2417 int num2 = Integer.parseInt(this.bdecOidNumber.toString()); 2418 this.bdecOidNumber = new BigDecimal (num1 + num2); 2419 } 2420 } 2421 2422 while (main) { 2423 boolean isEndFlag = false; 2424 this.logger.write("normal", "Import block is started."); 2425 currentBlock++; 2426 if (configReaderSource.getRowCountEnabled()) { 2427 if (!usingSelectStmt) 2428 this.logger.write("normal", "Working... " + currentBlock + ". block of " + 2429 blockNumber); 2430 else 2431 this.logger.write("normal", "Working... " + currentBlock + ". block"); 2432 } else 2433 this.logger.write("normal", "Working... " + currentBlock + ". block"); 2434 this.logger.write("full", "\tStarted from the " + bdecCounter.add( 2435 new BigDecimal (1)).toString() + ". row."); 2436 int bdecRowCount = 0; 2437 while (iRowNumber < importDefinitionElement.iImportDefinitionCommitCount) { 2438 if (!rsetSource.next()) { 2439 isEndFlag = true; 2440 break; 2441 } 2442 currentRow = iRowNumber; 2443 boolean readingOrderRelevant = false; 2444 if (configReaderSource.getReadingOrderRelevant()) 2445 readingOrderRelevant = true; 2446 2447 for (int i = 0; i < this.iTables; i++) { 2448 Vector vecVektor = new Vector (); 2449 this.vecBlobVector.clear(); 2450 2451 Hashtable orderRelevantColumnValues = new Hashtable (); 2453 if (readingOrderRelevant) { 2454 int orderRelevantColumnCount = rsetSource.getMetaData().getColumnCount(); 2455 for (int j = 1; j < orderRelevantColumnCount + 1; j++) { 2456 String orderRelevantColumnName = rsetSource.getMetaData().getColumnName(j); 2457 orderRelevantColumnName = orderRelevantColumnName.toUpperCase(); 2458 Object orderRelevantColumnValue; 2459 if( configReaderSource.isDate( rsetSource.getMetaData().getColumnTypeName(j) ) ) { 2460 orderRelevantColumnValue = rsetSource.getDate(j); 2461 }else if( configReaderSource.isBinaryObject( rsetSource.getMetaData().getColumnTypeName(j) ) ) { 2462 orderRelevantColumnValue = rsetSource.getBytes(j); 2463 } 2464 else { 2465 orderRelevantColumnValue = rsetSource.getString(j); 2466 } 2467 if (orderRelevantColumnValue == null) { 2468 orderRelevantColumnValues.put(orderRelevantColumnName, "null"); 2469 } else { 2470 orderRelevantColumnValues.put(orderRelevantColumnName, orderRelevantColumnValue); 2471 } 2472 } 2473 } 2474 if (importDefinitionElement.strImportDefinitionSelectStatement != null && 2477 !importDefinitionElement.strImportDefinitionSelectStatement.equals("")) { 2478 Vector srcNames = new Vector (); 2480 srcNames = (Vector )this.vecSourceColumnName.get(i); 2481 String readValue = ""; 2482 for (int s = 0; s < srcNames.size(); s++) { 2483 if (srcNames.get(s) != null) { 2484 String columnName = srcNames.get(s).toString(); 2485 if (!readingOrderRelevant) 2486 readValue = rsetSource.getString(columnName); 2487 else { 2488 columnName = columnName.toUpperCase(); 2489 readValue = orderRelevantColumnValues.get(columnName).toString(); 2491 } 2492 parseInputData(readValue, vecVektor, rsetSource, i, columnName, s + 1, 2493 readingOrderRelevant, orderRelevantColumnValues); 2494 } 2495 } 2496 this.transformationValues.clear(); 2499 for (int j = this.iOffsetForTransColumns+1; j < (this.iOffsetForTransColumns + 2500 this.transformations.getTransformationSourceColumsCnt() + 1 2501 ); j++) { 2502 Object value = ""; 2503 String columnName = rsetSource.getMetaData().getColumnName(j); 2504 if (!readingOrderRelevant) { 2505 if (this.iFirstColumnResult == 0) { 2506 value = rsetSource.getString(j - 1); 2507 } else { 2508 value = rsetSource.getString(j); 2509 } 2510 } else { 2511 columnName = columnName.toUpperCase(); 2512 value = orderRelevantColumnValues.get(columnName); 2513 } 2514 this.transformationValues.add(value); 2515 } 2516 orderRelevantColumnValues.clear(); 2517 } else { 2518 int iCounterCol = 0; 2521 for (int m = 0; m < i; m++) { 2522 iCounterCol = iCounterCol + 2523 Integer.parseInt(this.vecValueColumnsTargetTables.get(m).toString()) 2524 ; 2527 } 2528 iCounterCol++; 2529 for (int j = iCounterCol; j < (iCounterCol + 2531 Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString()) 2532 ); j++) { 2535 String readValue = ""; 2536 String columnName = rsetSource.getMetaData().getColumnName(j); 2537 if (!readingOrderRelevant) { 2538 if (this.iFirstColumnResult == 0) { 2539 readValue = rsetSource.getString(j - 1); 2540 } else { 2541 readValue = rsetSource.getString(j); 2542 } 2543 } else { 2544 columnName = columnName.toUpperCase(); 2545 readValue = orderRelevantColumnValues.get(columnName).toString(); 2546 } 2547 parseInputData(readValue, vecVektor, rsetSource, i, columnName, j - iCounterCol + 1, 2548 readingOrderRelevant, orderRelevantColumnValues); 2549 } 2550 this.transformationValues.clear(); 2552 for (int j = this.iOffsetForTransColumns+1; j < (this.iOffsetForTransColumns + 2553 this.transformations.getTransformationSourceColumsCnt() + 1 2554 ); j++) { 2555 Object value = ""; 2556 String columnName = rsetSource.getMetaData().getColumnName(j); 2557 if (!readingOrderRelevant) { 2558 if (this.iFirstColumnResult == 0) { 2559 value = rsetSource.getString(j - 1); 2560 } else { 2561 value= rsetSource.getString(j); 2562 } 2563 } else { 2564 columnName = columnName.toUpperCase(); 2565 value = orderRelevantColumnValues.get(columnName); 2566 } 2567 this.transformationValues.add(value); 2568 } 2569 } 2570 for (int l = 0; l < this.vecVariableUseIDTableName.size(); l++) { 2571 if (this.vecTableTableName.get(i).toString().equalsIgnoreCase(this. 2572 vecVariableUseIDTableName.get(l).toString()) 2573 && 2574 this.vecVariableUseIDTableID.get(l).toString(). 2575 equalsIgnoreCase(this.vecTableTableID.get(i).toString())) 2576 vecVektor.add(this.strUserID); 2577 } 2578 Vector transformedValues = new Vector (); 2579 Vector resultVectorTypes = new Vector (); 2580 List trans = this.transformations.getTransformations(); 2581 Vector vecTransformedValues = new Vector (); 2582 Vector pomResultVectorTypes = new Vector (); 2583 String tableId = this.vecTableTableID.get(i).toString(); 2584 List transTableIDs = this.transformations.getTransformationsTableIDs(); 2585 if (transTableIDs.contains(tableId)){ 2586 this.logger.write("full", "\ttransformation of values is started"); 2587 int offset = 0; 2588 for( int j=0; j < trans.size(); j++ ){ 2589 Transformation transformation = (Transformation)trans.get(j); 2590 Vector sourceColumnNames = transformation.getSourceColumnNames(); 2591 Vector valuesForTrans = new Vector (); 2592 for ( int n = offset; n < offset + sourceColumnNames.size(); n++ ) { 2593 valuesForTrans.add(this.transformationValues.elementAt(n)); 2594 } 2595 offset += sourceColumnNames.size(); 2596 vecTransformedValues = transformation.transformValues(valuesForTrans); 2597 pomResultVectorTypes = transformation.getOrderedTargetColumnTypes(i); 2598 if (vecTransformedValues != null){ 2599 for (int m = 0; m < vecTransformedValues.size(); m++) { 2600 if( pomResultVectorTypes.get(m) == null ) 2602 continue; 2603 transformedValues.add(vecTransformedValues.get(m)); 2604 resultVectorTypes.add(pomResultVectorTypes.get(m).toString()); 2605 } 2606 } 2607 } 2608 this.logger.write("full", "\ttransformation of values is finished"); 2609 } 2610 2611 this.insertTargetTable(i, 2613 vecVektor, 2614 (Vector )this.vecTargetColumnName.get(i), 2615 (Vector )this.vecValueMode.get(i), 2616 (Vector )this.vecTargetColumnType.get(i), 2617 connTarget, 2618 transformedValues, 2619 resultVectorTypes); 2620 2621 2622 } 2623 iRowNumber++; 2624 } 2625 if (!importDefinitionElement.strRestartCounterTableName.equals("")) { 2627 if (this.hasRestartCounter) { 2628 bdecCounter = bdecCounter.add(new BigDecimal (iRowNumber)); 2629 dataTransmition.insertCounter(this.currentJobName, bdecCounter, connTarget); 2630 } 2631 } 2632 2633 2634 if (this.hasRestartCounter) { 2635 this.counterColumns.updateCounter(connTarget); 2638 connTarget.commit(); 2639 this.logger.write("normal", "Imported block is commited."); 2640 this.logger.write("full", Integer.toString(iRowNumber) + " rows are commited."); 2641 } 2642 iRowNumber = 0; 2643 if (isEndFlag == true) 2644 break; 2645 } 2647 2648 rsetSource.close(); 2649 stmtSource.close(); 2650 connSource.close(); 2651 2652 if (!importDefinitionElement.strRestartCounterTableName.equals("")) { 2653 if (this.hasRestartCounter) { 2654 dataTransmition.resetRestartCounter(connTarget, this.currentJobName); 2655 } 2656 } 2657 if (!this.hasRestartCounter){ 2659 this.counterColumns.updateCounter(connTarget); 2660 } 2661 currentDate = new Date (); 2663 dfNow = DateFormat.getDateTimeInstance(); 2664 this.logger.write("normal", "Import definition " + 2665 importDefinitionElement.strImportDefinitionName 2666 + " is finished at " + dfNow.format(currentDate) + "."); 2667 this.logger.write("normal", " Duration of importDefinition:" + 2668 this.timeCounter.getJobTime()); 2669 } 2670 2671 catch (Exception e) { 2672 try { 2673 if (connSource != null) 2674 connSource.close(); 2675 } 2676 catch (Exception ex) { 2677 this.logger.write("normal", "\t" + ex.getMessage()); 2678 } 2679 String msq = "Error: In import job '" + importDefinitionElement.strImportDefinitionName 2680 + "', " + 2681 "some error has occured:"; 2682 this.logger.write("normal", "\t" + msq); 2683 LoaderException le = new LoaderException("Exception:"+e.getMessage(),(Throwable )e); 2684 this.logger.write("full", "\t" + le.getStackTraceAsString()); 2685 2686 throw le; 2687 } 2688 finally { 2689 try { 2690 2691 this.logger.write("full", "loadSource method is finished."); 2692 if (connSource != null && !connSource.isClosed()) 2693 connSource.close(); 2694 } 2695 catch (SQLException e) { 2696 LoaderException le = new LoaderException("SQLException: ", 2697 (Throwable )e); 2698 this.logger.write("full", le.getStackTraceAsString()); 2700 throw le; 2701 } 2702 } 2703 } 2704 2705 2716 public void parseInputData(String readValue, Vector vecVektor, ResultSet rsetSource, 2717 int i, String columnName, int blobCount, boolean isMicrosoftDriver, 2718 Hashtable columnValuesMicrosoft) throws LoaderException { 2719 try { 2720 if (readValue == null || readValue.equalsIgnoreCase("null")) { 2721 vecVektor.add(null); 2722 } else if (readValue.equalsIgnoreCase("")) { 2723 if (configReaderTarget.getSetEmptyStringAsNull()) 2724 vecVektor.add(null); 2725 else 2726 vecVektor.add(""); 2727 } else { 2728 int index = blobCount-1; 2730 byte[] blob; 2736 2737 String type = ( (Vector )this.vecTargetColumnType.get(i)).get(index).toString(); 2738 2740 2742 String mode = ( (Vector )this.vecValueMode.get(i)).get(index).toString(); 2743 String toHex = ( (Vector )this.vecToHex.get(i)).get(index).toString(); 2744 String fromHex = ( (Vector )this.vecFromHex.get(i)).get(index).toString(); 2745 String blobObjectName = "binaryObject" + blobCount; 2746 2747 if (toHex.equalsIgnoreCase("true") && !fromHex.equalsIgnoreCase("true")) { 2748 if (isMicrosoftDriver) 2749 blob = (byte[])columnValuesMicrosoft.get(columnName); 2750 else 2751 blob = rsetSource.getBytes(columnName); 2752 2753 String toHexString = ToAndFromHex.getStringFromBlob(blob); 2754 vecVektor.add(toHexString); 2755 } else if (fromHex.equalsIgnoreCase("true") && !toHex.equalsIgnoreCase("true")) { 2756 if (configReaderTarget.isBinaryObject(type)) { 2758 byte[] newBlob = ToAndFromHex.getByteArrayFromString( 2760 readValue); 2761 if (mode.equalsIgnoreCase("Update")) { 2762 this.vecBlobVector.add(columnName); 2763 this.vecBlobVector.add(newBlob); 2764 this.vecBlobVector.add(" where " + columnName + 2765 " is null and "); 2766 this.vecBlobVector.add(mode); 2767 this.vecBlobVector.add(blobObjectName); 2768 vecVektor.add(blobObjectName); 2769 } else { 2770 this.vecBlobVector.add(columnName); 2771 this.vecBlobVector.add(newBlob); 2772 this.vecBlobVector.add(null); 2773 this.vecBlobVector.add(mode); 2774 this.vecBlobVector.add(blobObjectName); 2775 vecVektor.add(blobObjectName); 2776 } 2777 } else { 2778 if (readValue.indexOf("'") != -1) 2779 readValue = replaceChar(readValue, '\'', "\'\'"); 2780 vecVektor.add(readValue); 2781 } 2782 } else { 2783 if (configReaderTarget.isBinaryObject(type)) { 2785 if (isMicrosoftDriver) 2787 blob = (byte[])columnValuesMicrosoft.get(columnName); 2788 else 2789 blob = rsetSource.getBytes(columnName); 2790 if (mode.equalsIgnoreCase("Update")) { 2791 this.vecBlobVector.add(columnName); 2792 this.vecBlobVector.add(blob); 2793 this.vecBlobVector.add(" where " + columnName + " is null and "); 2794 this.vecBlobVector.add(mode); 2795 this.vecBlobVector.add(blobObjectName); 2796 vecVektor.add(blobObjectName); 2797 } else { 2798 this.vecBlobVector.add(columnName); 2799 this.vecBlobVector.add(blob); 2800 this.vecBlobVector.add(null); 2801 this.vecBlobVector.add(mode); 2802 this.vecBlobVector.add(blobObjectName); 2803 vecVektor.add(blobObjectName); 2804 } 2805 }else if(configReaderTarget.isDate(type)){ 2807 Date tmpDate = null; 2808 boolean sourceTypeIsNotDate = false; 2809 String tmpDateStr =""; 2810 if (isMicrosoftDriver) 2811 tmpDate = (java.sql.Date )columnValuesMicrosoft.get(columnName); 2812 else{ 2813 ResultSetMetaData rsMetaDataSource = rsetSource.getMetaData(); 2814 int columnPos = rsetSource.findColumn(columnName); 2815 String typeName = rsMetaDataSource.getColumnTypeName(columnPos); 2816 if (!configReaderSource.isDate(typeName)){ 2817 tmpDateStr = rsetSource.getString(columnName); 2818 sourceTypeIsNotDate = true; 2819 }else{ 2820 tmpDate=rsetSource.getDate(columnName); 2821 } 2822 } 2823 if (sourceTypeIsNotDate){ 2824 vecVektor.add(tmpDateStr); 2825 }else{ 2826 String format=this.configReaderTarget.getDateFormat(); 2827 SimpleDateFormat formatDate=new SimpleDateFormat (format); 2828 readValue=formatDate.format(tmpDate); 2829 vecVektor.add(readValue); 2830 } 2831 } else { 2832 if (readValue.indexOf("'") != -1) 2833 readValue = replaceChar(readValue, '\'', "\'\'"); 2834 vecVektor.add(readValue); 2835 } 2836 } 2837 } 2838 } 2840 catch (Exception ex) { 2841 LoaderException le = new LoaderException("Error in parseInputData.",ex); 2842 this.logger.write("full",le.getStackTraceAsString()); 2843 throw le; 2844 } 2845 } 2846 2847 2854 private int parseImportJob(InputStream inStream) throws LoaderException { 2855 int iNumTagsImportJob = 0; 2856 Document doc = null; 2857 this.logger.write("full", "\tparseImportJob method is started."); 2858 try { 2859 2860 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 2861 DocumentBuilder db = null; 2862 db = dbf.newDocumentBuilder(); 2863 doc = db.parse(inStream); 2864 } 2865 catch (Exception e) { 2866 this.logger.write("normal", "Sorry, an error occurred: " + e); 2867 LoaderException le = new LoaderException("Exception: ", 2868 (Throwable )e); 2869 this.logger.write("full", le.getStackTraceAsString()); 2870 throw le; 2871 } 2872 if (doc != null) { 2873 NodeList tagBasic = doc.getElementsByTagName("importDefinition"); 2874 iNumTagsImportJob = tagBasic.getLength(); 2875 Vector vecNames = new Vector (); 2876 String strName = ""; 2877 for (int i = 0; i < iNumTagsImportJob; i++) { 2878 strName = new String (""); 2879 strName = OctopusXMLUtil.importAttributeValue(doc, "importDefinition", 2880 "name", i); 2881 for (int j = 0; j < vecNames.size(); j++) { 2882 if (strName.equals("")) { 2883 this.logger.write("normal", 2884 "Sorry, an error occurred: No importDefinition name ."); 2885 LoaderException le = new LoaderException("Exception: ", 2886 (Throwable ) (new Exception ( 2887 "Sorry, an error occurred: No importDefinition name ."))); 2888 this.logger.write("full", le.getStackTraceAsString()); 2889 throw le; 2890 } 2891 if (strName.equalsIgnoreCase(vecNames.get(j).toString())) { 2892 this.logger.write("normal", 2893 "Sorry, an error occurred: More importDefinition with same name :" 2894 + strName); 2895 LoaderException le = new LoaderException("Exception: ", 2896 (Throwable ) (new Exception ( 2897 "Sorry, an error occurred: More importDefinition with same name :"))); 2898 this.logger.write("full", le.getStackTraceAsString()); 2899 throw le; 2900 } 2901 } 2902 vecNames.addElement(strName); 2903 } 2904 } 2905 try { 2906 inStream.reset(); 2907 } 2908 catch (IOException e) { 2909 LoaderException le = new LoaderException("IOException: ", 2911 (Throwable )e); 2912 this.logger.write("full", le.getStackTraceAsString()); 2913 throw le; 2914 } 2915 this.logger.write("full", "\tparseImportJob method is finished."); 2916 return iNumTagsImportJob; 2917 } 2918 2919 2926 2927 private int parseCopyTable(InputStream inStream) throws LoaderException { 2928 int iNumTagsCopyTable = 0; 2929 Document doc = null; 2930 this.logger.write("full", "\tparseCopyTable method is started."); 2931 try { 2932 2933 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 2934 DocumentBuilder db = null; 2935 db = dbf.newDocumentBuilder(); 2936 doc = db.parse(inStream); 2937 } 2938 catch (Exception e) { 2939 this.logger.write("normal", "Sorry, an error occurred: " + e); 2940 LoaderException le = new LoaderException("Exception: ", 2941 (Throwable )e); 2942 this.logger.write("full", le.getStackTraceAsString()); 2943 throw le; 2944 } 2945 if (doc != null) { 2946 NodeList tagCopyTable = doc.getElementsByTagName("copyTable"); 2947 iNumTagsCopyTable = tagCopyTable.getLength(); 2948 Vector vecNames = new Vector (); 2949 String strName = ""; 2950 for (int i = 0; i < iNumTagsCopyTable; i++) { 2951 strName = new String (""); 2952 strName = OctopusXMLUtil.importAttributeValue(doc, "copyTable", "name", i); 2953 for (int j = 0; j < vecNames.size(); j++) { 2954 if (strName.equals("")) { 2955 this.logger.write("normal", "Sorry, an error occurred: No copyTable name ."); 2956 LoaderException le = new LoaderException("Exception: ", 2957 (Throwable ) (new Exception ( 2958 "Sorry, an error occurred: No copyTable name ."))); 2959 this.logger.write("full", le.getStackTraceAsString()); 2960 throw le; 2961 } 2962 if (strName.equalsIgnoreCase(vecNames.get(j).toString())) { 2963 this.logger.write("normal", 2964 "Sorry, an error occurred: More copyTable with same name :" 2965 + strName); 2966 LoaderException le = new LoaderException("Exception: ", 2967 (Throwable ) (new Exception ( 2968 "Sorry, an error occurred: More copyTable with same name :"))); 2969 this.logger.write("full", le.getStackTraceAsString()); 2970 throw le; 2971 } 2972 } 2973 vecNames.addElement(strName); 2974 } 2975 } 2976 try { 2977 inStream.reset(); 2978 } 2979 catch (IOException e) { 2980 this.logger.write("normal", "Sorry, an error occurred: " + e); 2981 LoaderException le = new LoaderException("IOException: ", 2982 (Throwable )e); 2983 this.logger.write("full", le.getStackTraceAsString()); 2984 throw le; 2985 } 2986 this.logger.write("full", "\tparseImportJob method is finished."); 2987 return iNumTagsCopyTable; 2988 } 2989 2990 2997 private int parseEcho(InputStream inStream) throws LoaderException { 2998 int iNumTagsEcho = 0; 2999 Document doc = null; 3000 this.logger.write("full", "\tparseEcho method is started."); 3001 try { 3002 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3003 DocumentBuilder db = null; 3004 db = dbf.newDocumentBuilder(); 3005 doc = db.parse(inStream); 3006 } 3007 catch (Exception e) { 3008 this.logger.write("normal", "Sorry, an error occurred: " + e); 3009 LoaderException le = new LoaderException("Exception: ", 3010 (Throwable )e); 3011 this.logger.write("full", le.getStackTraceAsString()); 3012 throw le; 3013 } 3014 if (doc != null) { 3015 NodeList tagBasic = doc.getElementsByTagName("echo"); 3016 iNumTagsEcho = tagBasic.getLength(); 3017 String strMessage = ""; 3018 for (int i = 0; i < iNumTagsEcho; i++) { 3019 strMessage = new String (""); 3020 strMessage = OctopusXMLUtil.importAttributeValue(doc, "echo", "message", i); 3021 if (strMessage != null) 3022 logger.setMessage( (new Integer (i)).toString(), strMessage); 3023 } 3024 } 3025 try { 3026 inStream.reset(); 3027 } 3028 catch (IOException e) { 3029 this.logger.write("normal", "Sorry, an error occurred: " + e); 3030 LoaderException le = new LoaderException("IOxception: ", 3031 (Throwable )e); 3032 this.logger.write("full", le.getStackTraceAsString()); 3033 throw le; 3034 } 3036 this.logger.write("full", "\tparseSql method is finished."); 3037 return iNumTagsEcho; 3038 } 3039 3040 3047 private Vector parseMainElements(InputStream inStream) throws LoaderException { 3048 3049 Vector vecLoaderElements = new Vector (); 3050 Vector vecLoaderNamesOfElements = new Vector (); 3051 3052 Document doc = null; 3053 this.logger.write("full", "\tparseMainElements method is started."); 3054 try { 3055 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3056 DocumentBuilder db = null; 3057 db = dbf.newDocumentBuilder(); 3058 doc = db.parse(inStream); 3059 } 3060 catch (Exception e) { 3061 this.logger.write("normal", "Sorry, an error occurred: " + e); 3062 LoaderException le = new LoaderException("Exception: ", 3063 (Throwable )e); 3064 this.logger.write("full", le.getStackTraceAsString()); 3065 throw le; 3066 } 3067 if (doc != null) { 3068 NodeList tagBasic = doc.getElementsByTagName("loaderJob"); 3069 NodeList nlMainElements = tagBasic.item(0).getChildNodes(); 3070 for (int i = 0; i < nlMainElements.getLength(); i++) { 3071 String strTagName = nlMainElements.item(i).getNodeName(); 3072 if (strTagName.equalsIgnoreCase("sql") || 3073 strTagName.equalsIgnoreCase("importDefinition") || 3074 strTagName.equalsIgnoreCase("echo") || 3075 strTagName.equalsIgnoreCase("copyTable")) 3076 if (nlMainElements.item(i).getNodeType() == Node.ELEMENT_NODE) { 3077 String strTagJobName = ( ( (Element )nlMainElements.item(i)).getAttribute("name")); 3078 String strLogMode = ( ( (Element )nlMainElements.item(i)).getAttribute("logMode")); 3079 vecLoaderElements.addElement(strTagName); 3080 this.logModes.add(strLogMode); 3081 boolean addJobName = true; 3082 if (!strTagJobName.equalsIgnoreCase("")) { 3083 for (int j = 0; j < vecLoaderNamesOfElements.size(); j++) { 3084 if (strTagJobName.equalsIgnoreCase(vecLoaderNamesOfElements.get(j).toString())) { 3085 addJobName = false; 3086 break; 3087 } 3088 } 3089 if (addJobName) { 3090 vecLoaderNamesOfElements.add(strTagJobName); 3091 } else { 3092 String msg = "Sorry, an error occurred: More import jobs with same name :" 3093 + strTagJobName; 3094 LoaderException le = new LoaderException("Exception:", new Exception (msg)); 3095 3096 throw le; 3097 } 3098 } 3099 } 3100 } 3101 } 3102 try { 3103 inStream.reset(); 3104 } 3105 catch (IOException e) { 3106 this.logger.write("normal", "Sorry, an error occurred: " + e.getMessage()); 3107 LoaderException le = new LoaderException("IOException: ", 3108 (Throwable )e); 3109 this.logger.write("full", le.getStackTraceAsString()); 3110 throw le; 3111 } 3112 this.logger.write("full", "\tparseMainElements method is finished."); 3113 return vecLoaderElements; 3114 } 3115 3116 3122 private void importRestartCounter(InputStream inStream) throws 3123 LoaderException { 3124 Document doc = null; 3125 this.logger.write("full", "\timportRestartCounter method is started."); 3126 try { 3127 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3128 DocumentBuilder db = null; 3129 db = dbf.newDocumentBuilder(); 3130 doc = db.parse(inStream); 3131 } 3132 catch (Exception e) { 3133 this.logger.write("normal", "Sorry, an error occurred: " + e); 3134 LoaderException le = new LoaderException("Exception: ", 3135 (Throwable )e); 3136 this.logger.write("full", le.getStackTraceAsString()); 3137 throw le; 3138 } 3140 if (doc != null) { 3141 NodeList tagRestartCounter = doc.getElementsByTagName("restartCounter"); 3142 if (tagRestartCounter.getLength() != 0) { 3143 this.hasRestartCounter = true; 3144 NamedNodeMap attrs = tagRestartCounter.item(0).getAttributes(); 3145 Node nodeResult = attrs.getNamedItem("tableName"); 3146 if (nodeResult != null) 3147 importDefinitionElement.strRestartCounterTableName = nodeResult. 3148 getNodeValue(); 3149 else 3150 importDefinitionElement.strRestartCounterTableName = "LOADERRESTART"; 3151 nodeResult = attrs.getNamedItem("importDefinitionColumnName"); 3152 if (nodeResult != null) 3153 importDefinitionElement.strRestartCounterImportDefinitionName = 3154 nodeResult.getNodeValue(); 3155 else 3156 importDefinitionElement.strRestartCounterImportDefinitionName = 3157 "IMPORTDEFINITION"; 3158 nodeResult = attrs.getNamedItem("restartCounterColumnName"); 3159 if (nodeResult != null) 3160 importDefinitionElement.strRestartCounterValue = nodeResult. 3161 getNodeValue(); 3162 else 3163 importDefinitionElement.strRestartCounterValue = "RESTARTCOUNTER"; 3164 nodeResult = attrs.getNamedItem("restartAutoCreate"); 3165 if (nodeResult != null) 3166 importDefinitionElement.bRestartAutoCreate = (new Boolean (nodeResult. 3167 getNodeValue())).booleanValue(); 3168 else 3169 importDefinitionElement.bRestartAutoCreate = false; 3170 } 3171 } 3172 try { 3173 inStream.reset(); 3174 } 3175 catch (IOException e) { 3176 this.logger.write("normal", "Sorry, an error occurred: " + e); 3177 LoaderException le = new LoaderException("IOException: ", 3178 (Throwable )e); 3179 this.logger.write("full", le.getStackTraceAsString()); 3180 throw le; 3181 } 3183 this.logger.write("full", "\timportRestartCounter method is finished."); 3184 } 3185 3186 3192 private void importVariable(InputStream inStream) throws LoaderException { 3193 Document doc = null; 3194 String strNodeValue = ""; 3195 String strDefaultVariableOverride = ""; 3196 String strDefaultReplaceInConstants = ""; 3197 String strDefaultReplaceInSQL = ""; 3198 String strDefaultReplaceInData = ""; 3199 String strDefaultReplaceInJDBC = ""; 3200 String strDefaultVariablePrefix = ""; 3201 String strDefaultVariableSufix = ""; 3202 this.logger.write("full", "\timportVariable method is started."); 3203 try { 3204 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3205 DocumentBuilder db = null; 3206 db = dbf.newDocumentBuilder(); 3207 doc = db.parse(inStream); 3208 if (doc != null) { 3209 NodeList tagBasic = doc.getElementsByTagName("variables"); 3210 if (tagBasic.getLength() != 0) { 3211 Element docFragment = (Element )tagBasic.item(0); 3212 strDefaultVariablePrefix = docFragment.getAttribute("prefix"); 3213 if (strDefaultVariablePrefix.equals("")) 3214 strDefaultVariablePrefix = "%"; 3215 strDefaultVariableSufix = docFragment.getAttribute("suffix"); 3216 if (strDefaultVariableSufix.equals("")) 3217 strDefaultVariableSufix = "%"; 3218 strDefaultVariableOverride = docFragment.getAttribute("override"); 3219 if (strDefaultVariableOverride.equals("")) 3220 strDefaultVariableOverride = "true"; 3221 strDefaultReplaceInConstants = docFragment.getAttribute( 3222 "replaceInConstants"); 3223 if (strDefaultReplaceInConstants.equals("")) 3224 strDefaultReplaceInConstants = "false"; 3225 strDefaultReplaceInSQL = docFragment.getAttribute("replaceInSQL"); 3226 if (strDefaultReplaceInSQL.equals("")) 3227 strDefaultReplaceInSQL = "false"; 3228 strDefaultReplaceInData = docFragment.getAttribute("replaceInData"); 3229 if (strDefaultReplaceInData.equals("")) 3230 strDefaultReplaceInData = "false"; 3231 strDefaultReplaceInJDBC = docFragment.getAttribute("replaceInJDBC"); 3232 if (strDefaultReplaceInJDBC.equals("")) 3233 strDefaultReplaceInJDBC = "false"; 3234 NodeList tag = docFragment.getElementsByTagName("variable"); 3235 this.vecVariableName = OctopusXMLUtil.getAttributeValues(tag, "name", null); 3236 this.vecVariableValue = OctopusXMLUtil.getAttributeValues(tag, 3237 "value", null); 3238 this.vecVariablePrefix = OctopusXMLUtil.getAttributeValues(tag, 3239 "prefix", 3240 strDefaultVariablePrefix); 3241 this.vecVariableSufix = OctopusXMLUtil.getAttributeValues(tag, 3242 "suffix", 3243 strDefaultVariableSufix); 3244 this.vecVariableOverride = OctopusXMLUtil.getAttributeValues(tag, 3245 "override", 3246 strDefaultVariableOverride); 3247 this.vecReplaceInConstants = OctopusXMLUtil.getAttributeValues(tag, 3248 "replaceInConstants", 3249 strDefaultReplaceInConstants); 3250 this.vecReplaceInSQL = OctopusXMLUtil.getAttributeValues(tag, 3251 "replaceInSQL", 3252 strDefaultReplaceInSQL); 3253 this.vecReplaceInData = OctopusXMLUtil.getAttributeValues(tag, 3254 "replaceInData", 3255 strDefaultReplaceInData); 3256 this.vecReplaceInJDBC = OctopusXMLUtil.getAttributeValues(tag, 3257 "replaceInJDBC", 3258 strDefaultReplaceInJDBC); 3259 for (int i = 0; i < this.vecVariableOverride.size(); i++) { 3260 if (this.vecVariableOverride.get(i).toString().equalsIgnoreCase( 3261 "true")) { 3262 if (this.mapVariableValues.get(this.vecVariableName.get(i)) == null) 3263 this.vecVariableValue.setElementAt(null, i); 3264 else 3265 this.vecVariableValue.setElementAt(this.mapVariableValues.get(this. 3266 vecVariableName.get(i).toString()).toString(), 3267 i); 3268 } 3269 } 3270 } 3271 } 3272 } 3273 catch (Exception e) { 3274 this.logger.write("normal", 3275 "Sorry, an error with the variables occurred: " + e); 3276 LoaderException le = new LoaderException("Exception: ", (Throwable )e); 3277 this.logger.write("full", le.getStackTraceAsString()); 3278 throw le; 3279 } 3280 try { 3281 inStream.reset(); 3282 } 3283 catch (IOException e) { 3284 this.logger.write("normal", "Sorry, an error occurred: " + e); 3285 LoaderException le = new LoaderException("IOException: ", 3286 (Throwable )e); 3287 this.logger.write("full", le.getStackTraceAsString()); 3288 throw le; 3289 } 3290 this.logger.write("full", "\timportVariable method is finished."); 3291 } 3292 3293 3303 private void parseAndImport(InputStream inStream, int l) throws SAXException , 3304 LoaderException, 3305 Exception { 3306 this.logger.write("full", "\tparseAndImport method is started."); 3307 Document doc = null; 3308 try { 3309 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 3310 DocumentBuilder db = null; 3311 db = dbf.newDocumentBuilder(); 3312 doc = db.parse(inStream); 3313 } 3314 catch (SAXException e) { 3315 throw e; 3316 } 3317 catch (Exception e) { 3318 throw e; 3319 } 3320 if (doc != null) 3321 this.importXMLFile(doc, l); 3322 try { 3323 inStream.reset(); 3324 } 3325 catch (IOException e) { 3326 this.logger.write("normal", "Sorry, an error occurred: " + e); 3327 LoaderException le = new LoaderException("IOException: ", 3328 (Throwable )e); 3329 this.logger.write("full", le.getStackTraceAsString()); 3330 throw le; 3331 } 3332 this.logger.write("full", "\tparseAndImport method is finished."); 3333 } 3334 3335 3345 private void importXMLFile(Document doc, int iJobNumber) throws 3346 NullPointerException , 3347 Exception { 3348 this.logger.write("full", "\timportXMLFile method is started."); 3349 Vector vecValueColumnSourceColumnName = new Vector (); 3350 Vector vecValueColumnTargetTableName = new Vector (); 3351 Vector vecValueColumnTargetColumnName = new Vector (); 3352 Vector vecValueColumnTargetTableID = new Vector (); 3353 Vector vecValueColumnValueMode = new Vector (); 3354 Vector vecConstantColumnTargetColumnName = new Vector (); 3355 Vector vecConstantColumnValueMode = new Vector (); 3356 Vector vecConstantColumnConstantValue = new Vector (); 3357 Vector vecRestartCounterVector = new Vector (); 3358 Vector vecJDBCSourceName = new Vector (); 3359 Vector vecJDBCSourceValue = new Vector (); 3360 Vector vecJDBCTargetName = new Vector (); 3361 Vector vecJDBCTargetValue = new Vector (); 3362 Vector vecDefaultValueTemp = new Vector (); 3364 this.vecDefaultValue = new Vector (); 3365 this.vecDefaultRelationValue = null; 3366 this.vecDefaultVariableValue = null; 3367 this.vecDefaultVariableName = null; 3368 this.vecTempUserID = null; 3369 int iNumberOfColumns = 0; 3370 Vector vecToHexTemp = new Vector (); 3372 Vector vecFromHexTemp = new Vector (); 3373 this.vecToHex = new Vector (); 3374 this.vecFromHex = new Vector (); 3375 3376 try { 3377 3378 importDefinitionElement.setLogger(this.logger); 3379 dataCleaning.setLogger(this.logger); 3380 3381 if (!this.loaderJobReader.getLogTableName().equalsIgnoreCase("")) 3382 dataCleaning.setLogTableName(this.loaderJobReader.getLogTableName()); 3383 3384 if (!this.loaderJobReader.getLogTable().equalsIgnoreCase("")) 3385 dataCleaning.setLogTable(this.loaderJobReader.getLogTable()); 3386 3387 if (!this.loaderJobReader.getLogColumnName().equalsIgnoreCase("")) 3388 dataCleaning.setLogColumnName(this.loaderJobReader.getLogColumnName()); 3389 3390 if (!this.loaderJobReader.getLogRowNumber().equalsIgnoreCase("")) 3391 dataCleaning.setLogRowNumber(this.loaderJobReader.getLogRowNumber()); 3392 3393 if (!this.loaderJobReader.getLogOriginalValue().equalsIgnoreCase("")) 3394 dataCleaning.setLogOriginalValue(this.loaderJobReader. 3395 getLogOriginalValue()); 3396 3397 if (!this.loaderJobReader.getLogNewValue().equalsIgnoreCase("")) 3398 dataCleaning.setLogNewValue(this.loaderJobReader.getLogNewValue()); 3399 3400 if (!this.loaderJobReader.getLogImportDefinitionName().equalsIgnoreCase( 3401 "")) 3402 dataCleaning.setLogImportDefinitionName(this.loaderJobReader. 3403 getLogImportDefinitionName()); 3404 3405 if (!this.loaderJobReader.getLogOperationName().equalsIgnoreCase("")) 3406 dataCleaning.setLogOperationName(this.loaderJobReader. 3407 getLogOperationName()); 3408 if (!this.loaderJobReader.getLogTime().equalsIgnoreCase("")) 3409 dataCleaning.setLogTime(this.loaderJobReader.getLogTime()); 3410 3411 if (!this.loaderJobReader.getLogFailedStatement().equalsIgnoreCase("")) 3412 dataCleaning.setLogPrimaryKeyValue(this.loaderJobReader.getLogFailedStatement()); 3413 3414 if (!this.loaderJobReader.getLogTypeName().equalsIgnoreCase("")) 3415 dataCleaning.setLogTypeName(this.loaderJobReader.getLogTypeName()); 3416 3417 importDefinitionElement.setLoaderJob(this.loaderJobReader); 3418 importDefinitionElement.importXMLFile(doc, iJobNumber); 3420 3421 if (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("")) 3423 importDefinitionElement.strDefaultCutOffData = loaderJobReader. 3424 getDefaultDataCutOff(); 3425 3426 if (importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("")) 3428 importDefinitionElement.strOnErrorContinueXml = "" + 3429 loaderJobReader.getDefaultOnErrorContinue(); 3430 3431 if (importDefinitionElement.strCopyTableOnErrorContinue.equalsIgnoreCase( 3432 "")) 3433 importDefinitionElement.strCopyTableOnErrorContinue = "" + 3434 loaderJobReader. 3435 getDefaultOnErrorContinue(); 3436 3437 vecJDBCSourceValue = OctopusXMLUtil.importValue(doc, 3438 "jdbcSourceParameter", 3439 "value", iJobNumber); 3440 vecJDBCSourceName = OctopusXMLUtil.importValue(doc, "jdbcSourceParameter", 3441 "name", iJobNumber); 3442 if (vecJDBCSourceValue.size() != 0) { 3443 for (int i = 0; i < vecJDBCSourceValue.size(); i++) { 3444 if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("JdbcDriver")) 3445 jdbcParametersElement.setJDBCSourceParameterDriver( 3446 vecJDBCSourceValue.get(i).toString()); 3447 else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase( 3448 "Connection.Url")) { 3449 if (vecJDBCSourceValue.get(i).toString().indexOf( 3451 "jdbc:microsoft:sqlserver") != -1) { 3452 if (vecJDBCSourceValue.get(i).toString().indexOf("SelectMethod") == 3453 -1) { 3454 jdbcParametersElement.setJDBCSourceParameterConnection( 3455 vecJDBCSourceValue.get(i).toString() + 3456 ";SelectMethod=cursor"); 3457 } else if (vecJDBCSourceValue.get(i).toString().indexOf("cursor") != 3458 -1) { 3459 jdbcParametersElement.setJDBCSourceParameterConnection( 3460 vecJDBCSourceValue.get(i).toString()); 3461 } else { 3462 this.logger.write("normal", 3463 "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor"); 3464 LoaderException le = new LoaderException( 3465 "Exception:", new Exception ("Value of Connection.Url perameter SelectMethod has to be cursor")); 3466 this.logger.write("full", le.getStackTraceAsString()); 3467 throw le; 3468 } 3469 } else { 3470 jdbcParametersElement.setJDBCSourceParameterConnection( 3471 vecJDBCSourceValue.get(i).toString()); 3472 } 3473 } else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("User")) 3474 jdbcParametersElement.setJDBCSourceParameterUser(vecJDBCSourceValue. 3475 get(i).toString()); 3476 else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase( 3477 "Password")) 3478 jdbcParametersElement.setJDBCSourceParameterPassword( 3479 vecJDBCSourceValue.get(i).toString()); 3480 } 3481 } 3482 vecJDBCTargetValue = OctopusXMLUtil.importValue(doc, 3483 "jdbcTargetParameter", 3484 "value", iJobNumber); 3485 vecJDBCTargetName = OctopusXMLUtil.importValue(doc, "jdbcTargetParameter", 3486 "name", iJobNumber); 3487 3488 if (vecJDBCTargetValue.size() != 0) { 3489 for (int i = 0; i < vecJDBCTargetValue.size(); i++) { 3490 if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("JdbcDriver")) 3491 jdbcParametersElement.setJDBCTargetParameterDriver( 3492 vecJDBCTargetValue.get(i).toString()); 3493 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase( 3494 "Connection.Url")) { 3495 if (vecJDBCTargetValue.get(i).toString().indexOf( 3497 "jdbc:microsoft:sqlserver") != -1) { 3498 if (vecJDBCTargetValue.get(i).toString().indexOf("SelectMethod") == 3499 -1) { 3500 jdbcParametersElement.setJDBCTargetParameterConnection( 3501 vecJDBCTargetValue.get(i).toString() + 3502 ";SelectMethod=cursor"); 3503 } else if (vecJDBCTargetValue.get(i).toString().indexOf("cursor") != 3504 -1) { 3505 jdbcParametersElement.setJDBCTargetParameterConnection( 3506 vecJDBCTargetValue.get(i).toString()); 3507 } else { 3508 this.logger.write("normal", 3509 "Sorry, an error occurred: value of Connection.Url parameter SelectMethod has to be cursor"); 3510 LoaderException le = new LoaderException( 3511 "Exception:",new Exception ("value of Connection.Url parameter SelectMethod has to be cursor")); 3512 this.logger.write("full", le.getStackTraceAsString()); 3513 throw le; 3514 } 3515 } else { 3516 jdbcParametersElement.setJDBCTargetParameterConnection( 3517 vecJDBCTargetValue.get(i).toString()); 3518 } 3519 } else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("User")) 3520 jdbcParametersElement.setJDBCTargetParameterUser(vecJDBCTargetValue. 3521 get(i).toString()); 3522 else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase( 3523 "Password")) 3524 jdbcParametersElement.setJDBCTargetParameterPassword( 3525 vecJDBCTargetValue.get(i).toString()); 3526 } 3527 } 3528 vecToHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn", 3530 "toHex", iJobNumber); 3531 vecFromHexTemp = OctopusXMLUtil.importValue(doc, "valueColumn", 3532 "fromHex", iJobNumber); 3533 vecDefaultValueTemp = OctopusXMLUtil.importValue(doc, "valueColumn", 3535 "defaultValue", iJobNumber); 3536 this.vecDefaultVariableValue = OctopusXMLUtil.importValue(doc, 3537 "variableColumn", 3538 "defaultValue", iJobNumber); 3539 this.vecDefaultVariableName = OctopusXMLUtil.importValue(doc, 3540 "variableColumn", 3541 "name", iJobNumber); 3542 this.vecDefaultRelationValue = OctopusXMLUtil.importValue(doc, 3543 "relationColumn", 3544 "defaultValue", iJobNumber); 3545 this.vecTempUserID = OctopusXMLUtil.importValue(doc, "userIDColumn", 3546 "defaultValue", iJobNumber); 3547 vecValueColumnSourceColumnName = OctopusXMLUtil.importValue(doc, 3548 "valueColumn", 3549 "sourceColumnName", iJobNumber); 3550 vecValueColumnTargetTableName = OctopusXMLUtil.importValue(doc, 3551 "valueColumn", 3552 "targetTableName", iJobNumber); 3553 this.iValueColumns = vecValueColumnTargetTableName.size(); 3554 vecValueColumnTargetColumnName = OctopusXMLUtil.importValue(doc, 3555 "valueColumn", 3556 "targetColumnName", iJobNumber); 3557 vecValueColumnTargetTableID = OctopusXMLUtil.importValue(doc, 3558 "valueColumn", 3559 "targetTableID", iJobNumber); 3560 vecValueColumnValueMode = OctopusXMLUtil.importValue(doc, "valueColumn", 3561 "valueMode", iJobNumber); 3562 this.vecVariableColumnName = OctopusXMLUtil.importValue(doc, 3563 "variableColumn", 3564 "name", iJobNumber); 3565 this.vecVariableColumnTargetTableName = OctopusXMLUtil.importValue(doc, 3566 "variableColumn", 3567 "targetTableName", iJobNumber); 3568 this.vecVariableColumnTargetColumnName = OctopusXMLUtil.importValue(doc, 3569 "variableColumn", "targetColumnName", iJobNumber); 3570 this.vecVariableColumnTargetTableID = OctopusXMLUtil.importValue(doc, 3571 "variableColumn", 3572 "targetTableID", iJobNumber); 3573 this.vecVariableColumnValueMode = OctopusXMLUtil.importValue(doc, 3574 "variableColumn", 3575 "valueMode", iJobNumber); 3576 this.vecVariableUseIDTableName = OctopusXMLUtil.importValue(doc, 3577 "userIDColumn", 3578 "targetTableName", iJobNumber); 3579 this.vecVariableUseIDColumnName = OctopusXMLUtil.importValue(doc, 3580 "userIDColumn", 3581 "targetColumnName", iJobNumber); 3582 this.vecVariableUseIDTableID = OctopusXMLUtil.importValue(doc, 3583 "userIDColumn", 3584 "targetTableID", iJobNumber); 3585 this.vecVariableUseIDValueMode = OctopusXMLUtil.importValue(doc, 3586 "userIDColumn", 3587 "valueMode", iJobNumber); 3588 this.vecVariableTimesTableName = OctopusXMLUtil.importValue(doc, 3589 "timeStampColumn", 3590 "targetTableName", iJobNumber); 3591 this.vecVariableTimesColumnName = OctopusXMLUtil.importValue(doc, 3592 "timeStampColumn", 3593 "targetColumnName", iJobNumber); 3594 this.vecVariableTimesTableID = OctopusXMLUtil.importValue(doc, 3595 "timeStampColumn", 3596 "targetTableID", iJobNumber); 3597 this.vecVariableTimesValueMode = OctopusXMLUtil.importValue(doc, 3598 "timeStampColumn", 3599 "valueMode", iJobNumber); 3600 this.vecConstantColumnTargetTableName = OctopusXMLUtil.importValue(doc, 3601 "constantColumn", 3602 "targetTableName", iJobNumber); 3603 this.iConstantColumns = this.vecConstantColumnTargetTableName.size(); 3604 vecConstantColumnTargetColumnName = OctopusXMLUtil.importValue(doc, 3605 "constantColumn", 3606 "targetColumnName", iJobNumber); 3607 this.vecConstantColumnTargetTableID = OctopusXMLUtil.importValue(doc, 3608 "constantColumn", 3609 "targetTableID", iJobNumber); 3610 vecConstantColumnValueMode = OctopusXMLUtil.importValue(doc, 3611 "constantColumn", "valueMode", iJobNumber); 3612 3613 vecConstantColumnConstantValue = OctopusXMLUtil.importValue(doc, 3614 "constantColumn", 3615 "constantValue", iJobNumber, null); 3616 this.vecRelationColumnSourceTableName = OctopusXMLUtil.importValue(doc, 3617 "relationColumn", 3618 "relationSourceTableName", iJobNumber); 3619 this.iRelationColumns = this.vecRelationColumnSourceTableName.size(); 3620 this.vecRelationColumnSourceTableID = OctopusXMLUtil.importValue(doc, 3621 "relationColumn", 3622 "relationSourceTableID", iJobNumber); 3623 this.vecRelationColumnSourceColumnName = OctopusXMLUtil.importValue(doc, 3624 "relationColumn", "relationSourceColumnName", 3625 iJobNumber); 3626 this.vecRelationColumnTargetTableName = OctopusXMLUtil.importValue(doc, 3627 "relationColumn", 3628 "relationTargetTableName", iJobNumber); 3629 this.vecRelationColumnTargetColumnName = OctopusXMLUtil.importValue(doc, 3630 "relationColumn", "relationTargetColumnName", 3631 iJobNumber); 3632 this.vecRelationColumnTargetTableID = OctopusXMLUtil.importValue(doc, 3633 "relationColumn", 3634 "relationTargetTableID", iJobNumber); 3635 this.vecRelationColumnRelationMode = OctopusXMLUtil.importValue(doc, 3636 "relationColumn", 3637 "relationMode", iJobNumber); 3638 3640 ImportDefinitionSourceColumnName = vecValueColumnSourceColumnName; 3641 ImportDefinitionTargetColumnName = vecValueColumnTargetColumnName; 3642 3643 this.counterColumns = new CounterColumns(); 3645 this.counterColumns.setLogger(this.logger); 3646 this.counterColumns.resetSubCounterCache(); 3647 this.counterColumns.readConstantColumnAttributes(doc, iJobNumber); 3648 this.counterColumns.readConstantColumnsParameters(doc, iJobNumber); 3649 3651 this.transformations = new Transformations(this.logger); 3653 this.transformations.createTransformationElements(doc, iJobNumber); 3655 ArrayList trans = this.transformations.getTransformations(); 3656 Iterator iTrans = trans.iterator(); 3657 3658 3659 while(iTrans.hasNext()) { 3660 Transformation temp = (Transformation)iTrans.next(); 3661 temp.setLogger(this.logger); 3662 3663 3668 } 3669 3670 3672 this.vecTableTableName = OctopusXMLUtil.importValue(doc, "table", 3673 "tableName", 3674 iJobNumber); 3675 this.iTables = this.vecTableTableName.size(); 3676 this.vecTableTableID = OctopusXMLUtil.importValue(doc, "table", "tableID", 3677 iJobNumber); 3678 this.vecTableInsert = OctopusXMLUtil.importValue(doc, "table", "insert", 3679 iJobNumber); 3680 this.vecTableTableMode = OctopusXMLUtil.importValue(doc, "table", 3681 "tableMode", iJobNumber, loaderJobReader.getDefaultTableMode()); 3682 this.vecTableOidLogic = OctopusXMLUtil.importValue(doc, "table", 3683 "oidLogic", 3684 iJobNumber, 3685 (new Boolean (loaderJobReader.getDefaultOidLogic())).toString()); 3686 3687 this.vecCTAutoMapp = OctopusXMLUtil.importValue(doc, "table", 3688 "autoMapColumns", iJobNumber); 3689 this.vecCTDefaultMode = OctopusXMLUtil.importValue(doc, "table", 3690 "defaultMode", iJobNumber); 3691 3692 if (this.vecRelationColumnSourceTableName.size() != 0) { 3693 this.changeRelationsOrder(); 3694 this.changeTableOrder(); 3695 } 3696 this.vecRelationKeyColumns.setSize(this.iTables); 3697 this.vecRelationKeyTypes.setSize(this.iTables); 3698 this.vecConstantTargetColumnName.setSize(this.iTables); 3699 3702 this.vecConstantValueMode.setSize(this.iTables); 3703 this.vecConstantConstantValue.setSize(this.iTables); 3704 this.vecConstantColumnType.setSize(this.iTables); 3705 for (int k = 0; k < vecValueColumnTargetTableName.size(); k++) { 3706 boolean isImportColumn = false; 3707 for (int l = 0; l < this.iTables; l++) { 3708 if (vecValueColumnTargetTableName.get(k).toString().equalsIgnoreCase(this. 3709 vecTableTableName.get(l).toString()) 3710 && 3711 vecValueColumnTargetTableID.get(k).toString().equalsIgnoreCase(this. 3712 vecTableTableID. 3713 get(l).toString())) { 3714 isImportColumn = true; 3715 } 3716 } 3717 if (!isImportColumn) { 3718 this.logger.write("normal", 3719 "Incorrect XML import variables - TABLE ID"); 3720 LoaderException le = new LoaderException("Exception: ", 3721 (Throwable ) (new Exception ( 3722 "Incorrect XML import variables - TABLE ID"))); 3723 this.logger.write("full", le.getStackTraceAsString()); 3724 throw le; 3725 } 3726 } 3727 3728 if (this.vecVariableUseIDTableName.size() != 0) { 3729 String tempUserID = this.vecTempUserID.get(0).toString(); 3730 if (userIDExists) 3731 this.strUserID = ""; 3732 if (this.strUserID.equals("")) { 3733 if (!tempUserID.equalsIgnoreCase("")) { 3734 this.strUserID = tempUserID; 3735 this.userIDExists = true; 3736 } else { 3737 this.logger.write("normal", "Error : User parametar missing"); 3738 LoaderException le = new LoaderException("Exception: ", 3739 (Throwable ) (new Exception ("Error : User parametar missing"))); 3740 this.logger.write("full", le.getStackTraceAsString()); 3741 throw le; 3742 } 3743 } 3744 } 3745 for (int k = 0; k < this.iTables; k++) { 3746 iNumberOfColumns = 0; 3747 Vector vecTargetTable1 = new Vector (); 3748 Vector vecTargetTable2 = new Vector (); 3749 Vector vecTargetTable3 = new Vector (); 3750 Vector vecTargetTable4 = new Vector (); 3751 Vector vecTargetTable5 = new Vector (); 3752 Vector vecTargetTable6 = new Vector (); 3753 Vector vecTargetTable7 = new Vector (); 3754 Vector vecTargetTable8 = new Vector (); 3755 Vector vecTargetTable9 = new Vector (); 3756 Vector vecTargetTable10 = new Vector (); 3757 Vector vecTargetTable11 = new Vector (); 3758 3759 for (int l = 0; l < this.iValueColumns; l++) { 3760 if (this.vecTableTableName.get(k).toString().equalsIgnoreCase( 3761 vecValueColumnTargetTableName.get(l).toString()) 3762 && 3763 vecValueColumnTargetTableID.get(l).toString().equalsIgnoreCase(this. 3764 vecTableTableID. 3765 get(k).toString())) { 3766 iNumberOfColumns++; 3767 vecTargetTable1.addElement(vecValueColumnSourceColumnName.get(l). 3768 toString()); 3769 vecTargetTable2.addElement(vecValueColumnTargetColumnName.get(l). 3770 toString()); 3771 vecTargetTable4.addElement(vecValueColumnValueMode.get(l).toString()); 3772 vecTargetTable9.addElement(vecDefaultValueTemp.get(l).toString()); 3774 vecTargetTable10.addElement(vecToHexTemp.get(l).toString()); 3775 vecTargetTable11.addElement(vecFromHexTemp.get(l).toString()); 3776 if (vecValueColumnValueMode.get(l).toString().equalsIgnoreCase( 3777 "Key")) 3778 vecTargetTable5.addElement(vecValueColumnTargetColumnName.get(l). 3779 toString()); 3780 } 3781 } 3782 for (int l = 0; l < this.vecVariableUseIDTableName.size(); l++) { 3783 if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(this. 3784 vecVariableUseIDTableName.get(l).toString()) 3785 && 3786 this.vecVariableUseIDTableID.get(l).toString(). 3787 equalsIgnoreCase(this.vecTableTableID.get(k).toString())) { 3788 vecTargetTable2.addElement(this.vecVariableUseIDColumnName.get(l). 3789 toString()); 3790 vecTargetTable4.addElement(this.vecVariableUseIDValueMode.get(l). 3791 toString()); 3792 3797 if (this.vecVariableUseIDValueMode.get(l).toString(). 3798 equalsIgnoreCase("Key")) 3799 vecTargetTable5.addElement(this.vecVariableUseIDColumnName.get(l). 3800 toString()); 3801 } 3802 } 3803 for (int l = 0; l < this.vecRelationColumnSourceColumnName.size(); l++) { 3804 if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(this. 3805 vecRelationColumnTargetTableName.get(l).toString()) 3806 && 3807 this.vecRelationColumnTargetTableID.get(l).toString(). 3808 equalsIgnoreCase(this.vecTableTableID.get(k).toString()) 3809 && 3810 this.vecRelationColumnRelationMode.get(l).toString(). 3811 equalsIgnoreCase("Key")) { 3812 vecTargetTable3.addElement(this.vecRelationColumnTargetColumnName.get(l).toString()); 3813 } 3814 } 3815 3816 this.vecToHex.addElement(vecToHexTemp); 3818 this.vecFromHex.addElement(vecFromHexTemp); 3819 this.vecDefaultValue.addElement(vecTargetTable9); 3820 this.vecSourceColumnName.addElement(vecTargetTable1); 3821 this.vecTargetColumnName.addElement(vecTargetTable2); 3822 this.vecRelationKeyColumns.setElementAt(vecTargetTable3, k); 3823 this.vecValueMode.addElement(vecTargetTable4); 3824 this.vecTargetKeyColumnName.addElement(vecTargetTable5); 3825 this.vecValueColumnsTargetTables.addElement(new Integer ( 3826 iNumberOfColumns)); 3827 for (int p = 0; p < this.iConstantColumns; p++) { 3828 if (this.vecTableTableName.get(k).toString().equalsIgnoreCase(this. 3829 vecConstantColumnTargetTableName.get(p).toString()) 3830 && 3831 this.vecConstantColumnTargetTableID.get(p).toString(). 3832 equalsIgnoreCase(this.vecTableTableID.get(k).toString())) { 3833 vecTargetTable6.addElement(vecConstantColumnTargetColumnName.get(p). 3834 toString()); 3835 vecTargetTable7.addElement(vecConstantColumnValueMode.get(p). 3836 toString()); 3837 if (vecConstantColumnConstantValue.get(p) == null) 3838 vecTargetTable8.addElement(null); 3839 else 3840 vecTargetTable8.addElement(vecConstantColumnConstantValue.get(p). 3841 toString()); 3842 } 3843 } 3844 this.vecConstantTargetColumnName.setElementAt(vecTargetTable6, 3845 k); 3846 this.vecConstantValueMode.setElementAt(vecTargetTable7, k); 3847 this.vecConstantConstantValue.setElementAt(vecTargetTable8, 3848 k); 3849 3850 3852 this.counterColumns.setConstantColumnsParameters(this.vecTableTableName. 3853 get(k).toString(), this.vecTableTableID.get(k).toString()); 3854 } 3856 3857 for (int i = 0; i < this.vecRelationColumnSourceColumnName.size(); i++) { 3858 if (this.vecRelationColumnSourceColumnName.get(i).toString().equals("")) { 3859 for (int k = 0; k < this.vecTableTableName.size(); k++) { 3860 if (this.vecRelationColumnSourceTableName.get(i).toString(). 3861 equalsIgnoreCase(this.vecTableTableName.get(k).toString()) 3862 && 3863 this.vecRelationColumnSourceTableID.get(i).toString(). 3864 equalsIgnoreCase(this.vecTableTableID.get(k).toString())) { 3865 if (this.vecTableOidLogic.get(k).toString().equalsIgnoreCase("true")) 3866 this.vecRelationColumnSourceColumnName.setElementAt(this.currentOidColumnName, i); 3867 } 3869 } 3870 } 3871 } 3872 this.vecRelationSourceValue.setSize(this.iRelationColumns); 3873 this.vecRelationSourceType.setSize(this.iRelationColumns); 3874 } 3875 catch (NullPointerException ex) { 3876 throw ex; 3877 } 3878 catch (Exception ex) { 3879 throw ex; 3880 } 3881 this.logger.write("full", "\timportXMLFile method is finished."); 3882 } 3883 3884 3895 private boolean updateCurrentTime(Connection c, int iTable, 3896 String strQueryWhereSQL, 3897 int currentVersion, boolean oid) throws 3898 SQLException , NullPointerException { 3899 String strQueryInsertTime = ""; 3900 boolean bWriteData = false; 3901 String oidVersion = ""; 3902 if (oid) 3905 oidVersion = ", " + this.currentVersionColumnName + "=" + currentVersion; 3906 this.logger.write("full", "\t updateCurrentTime method is started."); 3907 try { 3908 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) { 3909 if (this.vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(this. 3910 vecTableTableName.get(iTable).toString()) 3911 && 3912 this.vecVariableTimesTableID.get(i).toString().equalsIgnoreCase(this. 3913 vecTableTableID. 3914 get(iTable).toString())) { 3915 Statement stmtRelations = c.createStatement(); 3916 strQueryInsertTime = "update " + 3917 this.vecVariableTimesTableName.get(i).toString() 3918 + " set " + this.vecVariableTimesColumnName.get(i).toString() 3919 + " = "; 3920 if (this.vecVariableTimesValueMode.get(i).toString().equalsIgnoreCase( 3921 "Overwrite")) 3922 3923 strQueryInsertTime += " '" + this.createCurrentDate() + 3925 "'" + oidVersion + " where " + strQueryWhereSQL; 3926 else 3927 strQueryInsertTime += " '" + this.createCurrentDate() 3928 + "'" + oidVersion + " where " + 3929 this.vecVariableTimesColumnName.get(i).toString() 3930 + " is null and " + strQueryWhereSQL; 3931 this.logger.write("full", "\tQuery '" + strQueryInsertTime 3932 + "' will be executed"); 3933 if (bReplaceInData) { 3934 strQueryInsertTime = this.replaceInData(strQueryInsertTime); 3935 } 3936 int num = stmtRelations.executeUpdate(strQueryInsertTime); 3937 if (num != 0) { 3938 bWriteData = true; 3939 } 3940 stmtRelations.close(); 3941 } 3942 } 3943 } 3944 catch (SQLException ex) { 3945 throw ex; 3946 } 3947 catch (NullPointerException ex) { 3948 throw ex; 3949 } 3950 this.logger.write("full", "\tupdateCurrentTime method is finished."); 3951 return bWriteData; 3952 } 3953 3954 3966 private boolean updateNameValue(Connection c, int iTable, 3967 String strQueryWhereSQL, int currentVersion, 3968 boolean oid) throws SQLException , 3969 NullPointerException , LoaderException { 3970 3971 String strQueryInsertName = ""; 3972 boolean bWriteData = false; 3973 String oidVersion = ""; 3974 if (oid) 3977 oidVersion = ", " + this.currentVersionColumnName + "=" + currentVersion; 3978 3979 this.logger.write("full", "\t updateNameValue method is started."); 3980 try { 3981 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) { 3982 boolean bInsert = true; 3983 if (this.vecVariableColumnTargetTableName.get(i).toString(). 3984 equalsIgnoreCase(this.vecTableTableName.get(iTable).toString()) 3985 && 3986 this.vecVariableColumnTargetTableID.get(i).toString(). 3987 equalsIgnoreCase(this.vecTableTableID.get(iTable).toString())) { 3988 int iPositionInVector = this.vecVariableName.indexOf(this. 3989 vecVariableColumnName.get(i).toString()); 3990 if (iPositionInVector != -1) { 3991 Statement stmtRelations = c.createStatement(); 3992 strQueryInsertName = "update " + 3993 this.vecVariableColumnTargetTableName.get(i).toString() 3994 + " set " + 3995 this.vecVariableColumnTargetColumnName.get(i).toString() 3996 + " = "; 3997 if (this.vecVariableColumnValueMode.get(i).toString(). 3998 equalsIgnoreCase("Overwrite")) { 3999 if (this.vecVariableValue.get(iPositionInVector) == null) { 4000 String variableName = this.vecVariableColumnName.get(i). 4001 toString(); 4002 for (int k = 0; k < this.vecDefaultVariableName.size(); k++) { 4003 if (this.vecDefaultVariableName.get(k).toString(). 4004 equalsIgnoreCase(variableName)) { 4005 if (!this.vecDefaultVariableValue.get(k).toString(). 4006 equalsIgnoreCase("")) { 4007 4011 if (!configReaderTarget.isNumber(this.vecVariableColumnTypes.get(i). 4012 toString())) 4013 4014 strQueryInsertName += " '" + 4015 this.vecDefaultVariableValue.get(k).toString() + 4016 "' " + 4017 oidVersion + " where " + strQueryWhereSQL; 4018 else 4019 strQueryInsertName += " " + 4020 this.vecDefaultVariableValue.get(k) + " " + 4021 oidVersion + " where " + strQueryWhereSQL; 4022 4023 } else { 4024 strQueryInsertName += " null" + oidVersion + " where " + 4025 strQueryWhereSQL; 4026 } 4027 break; 4028 } 4029 } 4030 } else { 4031 if (!configReaderTarget.isNumber(this.vecVariableColumnTypes.get(i). 4033 toString())) 4034 strQueryInsertName += " '" + 4035 this.vecVariableValue.get(iPositionInVector).toString() 4036 + "'" + oidVersion + " where " + strQueryWhereSQL; 4037 else 4038 strQueryInsertName += 4039 this.vecVariableValue.get(iPositionInVector).toString() 4040 + oidVersion + " where " + strQueryWhereSQL; 4041 } 4042 } else if (this.vecVariableColumnValueMode.get(i).toString(). 4043 equalsIgnoreCase("SetNull")) { 4044 if (this.vecVariableValue.get(iPositionInVector) == null) 4045 strQueryInsertName += " null" + oidVersion + " where " + 4046 strQueryWhereSQL; 4047 else 4048 bInsert = false; 4049 } else { 4050 if (this.vecVariableValue.get(iPositionInVector) == null) { 4051 String variableName = this.vecVariableColumnName.get(i). 4052 toString(); 4053 for (int k = 0; k < this.vecDefaultVariableName.size(); k++) { 4054 if (this.vecDefaultVariableName.get(k).toString(). 4055 equalsIgnoreCase(variableName)) { 4056 if (!this.vecDefaultVariableValue.get(k).toString(). 4057 equalsIgnoreCase("")) { 4058 if (!configReaderTarget.isNumber(this.vecVariableColumnTypes.get(i). 4060 toString())) 4061 strQueryInsertName += " '" + 4062 this.vecDefaultVariableValue.get(k).toString() + 4063 "' " + 4064 oidVersion + " where " + 4065 this.vecVariableColumnTargetColumnName.get(i). 4066 toString() 4067 + " is null and " + strQueryWhereSQL; 4068 else 4069 strQueryInsertName += " " + 4070 this.vecDefaultVariableValue.get(k) + " " + 4071 oidVersion + " where " + 4072 this.vecVariableColumnTargetColumnName.get(i). 4073 toString() 4074 + " is null and " + strQueryWhereSQL; 4075 } else { 4076 strQueryInsertName += " null" + oidVersion + " where " + 4077 this.vecVariableColumnTargetColumnName.get(i). 4078 toString() 4079 + " is null and " + strQueryWhereSQL; 4080 } 4081 break; 4082 } 4083 } 4084 } else { 4085 if (!configReaderTarget.isNumber(this.vecVariableColumnTypes.get(i). 4087 toString())) 4088 strQueryInsertName += " '" + 4089 this.vecVariableValue.get(iPositionInVector).toString() 4090 + "'" + oidVersion + " where " + 4091 this.vecVariableColumnTargetColumnName.get(i).toString() 4092 + " is null and " + strQueryWhereSQL; 4093 else 4094 strQueryInsertName += 4095 this.vecVariableValue.get(iPositionInVector).toString() 4096 + oidVersion + " where " + 4097 this.vecVariableColumnTargetColumnName.get(i).toString() 4098 + " is null and " + strQueryWhereSQL; 4099 } 4100 } 4101 if (bInsert) 4102 this.logger.write("full", "\tQuery '" + strQueryInsertName 4103 + "' will be executed"); 4104 4105 if (bReplaceInData) { 4106 strQueryInsertName = this.replaceInData(strQueryInsertName); 4107 } 4108 if (bInsert) { 4109 int num = 0; 4110 try { 4111 num = stmtRelations.executeUpdate(strQueryInsertName); 4112 } 4113 catch (SQLException ex) { 4114 stmtRelations.close(); 4115 stmtRelations = c.createStatement(); 4116 if ( (importDefinitionElement.strDefaultCutOffData. 4117 equalsIgnoreCase("true"))) { 4118 dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName. 4119 get(iTable).toString(), c, 4120 "", currentRow, strQueryInsertName, 4121 importDefinitionElement.strOnErrorContinueXml, 4122 importDefinitionElement.strImportDefinitionName, strQueryInsertName); 4123 } else 4124 throw ex; 4125 } 4126 } 4127 } else { 4129 this.logger.write("normal", 4130 "\tError: Cannot find value for variable column :" 4131 + this.vecVariableColumnName.get(i).toString()); 4132 LoaderException le = new LoaderException("Exception: ", 4133 (Throwable ) (new Exception ( 4134 "Error: Cannot find value for variable column :"))); 4135 this.logger.write("full", le.getStackTraceAsString()); 4136 throw le; 4137 } 4138 } 4139 } 4140 } 4141 catch (SQLException ex) { 4142 throw ex; 4143 } 4144 catch (NullPointerException ex) { 4145 throw ex; 4146 } 4147 this.logger.write("full", "\tupdateNameValue method is finished."); 4148 return bWriteData; 4149 } 4150 4151 4166 private String queryRelations(int iTableInt, int iNumberOfRelationColumn, 4167 String strQueryWhere, Connection conn, 4168 int currentVersion, 4169 boolean oid) throws NullPointerException , 4170 LoaderException { 4171 this.logger.write("full", "\tqueryRelations method is started."); 4172 String strQueryRelations = ""; 4173 String oidVersion = ""; 4174 String selectValueInRel = ""; 4175 String currentValueInRel = ""; 4176 if (oid) 4179 oidVersion = ", " + this.currentVersionColumnName + "=" + currentVersion; 4180 4181 try { 4182 strQueryRelations = "update " + 4183 this.vecRelationColumnTargetTableName.get(iNumberOfRelationColumn). 4184 toString() + " set " + 4185 this.vecRelationColumnTargetColumnName.get(iNumberOfRelationColumn). 4186 toString(); 4187 if (this.vecRelationSourceValue.get(iNumberOfRelationColumn) == null) { 4188 String replacementValueInRel = vecDefaultRelationValue.get( 4189 iNumberOfRelationColumn).toString(); 4190 if (!replacementValueInRel.equalsIgnoreCase("")) { 4191 try { 4192 Statement stmt = conn.createStatement(); 4193 ResultSet newRelationValue; 4194 String relationValue; 4195 boolean isFull = false; 4196 if (!replacementValueInRel.equalsIgnoreCase(selectValueInRel)) { 4197 selectValueInRel = replacementValueInRel; 4198 newRelationValue = stmt.executeQuery(replacementValueInRel); 4199 isFull = newRelationValue.next(); 4200 if (isFull) { 4201 relationValue = newRelationValue.getString(1); 4202 currentValueInRel = relationValue; 4203 } else { 4204 relationValue = ""; 4205 currentValueInRel = ""; 4206 } 4207 newRelationValue.close(); 4208 } else { 4209 if (!currentValueInRel.equalsIgnoreCase("") && currentValueInRel != null) { 4210 relationValue = currentValueInRel; 4211 isFull = true; 4212 } else { 4213 relationValue = ""; 4214 } 4215 } 4216 if (isFull) { 4217 strQueryRelations += 4218 dataCleaning.cleaningRelationValues(this.vecTableTableName. 4219 get(iTableInt).toString(), 4220 this.vecRelationColumnTargetColumnName.get( 4221 iNumberOfRelationColumn).toString(), relationValue, 4222 this.vecRelationSourceType.get(iNumberOfRelationColumn). 4223 toString(), 4224 currentRow, conn, "UPDATE", currentVersion, oid, 4225 importDefinitionElement.strImportDefinitionName, 4226 this.currentVersionColumnName, replacementValueInRel); 4227 4228 } else { 4229 dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt). 4230 toString(), conn, currentRow, "UPDATE", 4231 "Default value '" + replacementValueInRel + 4232 "' for relations is not valid.", 4233 importDefinitionElement.strImportDefinitionName,replacementValueInRel); 4234 strQueryRelations += " = null " + oidVersion + " where "; 4235 } 4236 } 4237 catch (SQLException ex) { 4238 String msg = "Default value for foreign key(" + 4239 replacementValueInRel + 4240 ") is not valid. Import definition name: " + 4241 importDefinitionElement.strImportDefinitionName; 4242 LoaderException le = new LoaderException("SQLException: " + msg, 4243 (Throwable )ex); 4244 this.logger.write("full", le.getStackTraceAsString()); 4245 throw le; 4246 } 4247 4248 } else 4249 strQueryRelations += " = null " + oidVersion + " where "; 4250 } else { 4251 if (configReaderTarget.isNumber(this.vecRelationSourceType.get( 4253 iNumberOfRelationColumn). 4254 toString())) { 4255 strQueryRelations += " = " + 4256 this.vecRelationSourceValue.get(iNumberOfRelationColumn).toString() 4257 + oidVersion + " where "; 4258 } 4259 else { 4260 strQueryRelations += " = "; 4261 if(configReaderTarget.isWithN( 4262 this.vecRelationSourceType.get( 4263 iNumberOfRelationColumn). 4264 toString())) { 4265 strQueryRelations += "N"; 4266 } 4267 strQueryRelations += "'" + 4268 this.vecRelationSourceValue.get(iNumberOfRelationColumn).toString() + 4269 "'" 4270 + oidVersion + " where "; 4271 } 4272 4273 } 4274 strQueryRelations += strQueryWhere; 4275 if (strQueryRelations.trim().endsWith("where")) 4276 strQueryRelations = strQueryRelations.substring(0, 4277 strQueryRelations.length() 4278 - 6); 4279 else { 4280 if (!this.vecRelationColumnRelationMode.get(iNumberOfRelationColumn). 4281 toString().equalsIgnoreCase("overwrite")) { 4282 4286 strQueryRelations += " and " + 4287 this.vecRelationColumnTargetColumnName. 4288 get(iNumberOfRelationColumn).toString() 4289 + " is null"; 4290 } 4291 } 4292 } 4293 catch (NullPointerException ex) { 4294 throw ex; 4295 } 4296 this.logger.write("full", "\tqueryRelations method is finished."); 4297 return strQueryRelations; 4298 } 4299 4300 4315 private void insertTargetTable(int iTableInt, Vector vecColumnValues, 4316 Vector vecColumnNames, 4317 Vector vecColumnMode, Vector vecColumnTypes, 4318 Connection c, Vector vecTransformationValue, Vector transTargetColumnTypes) throws SQLException , 4319 NullPointerException , Exception { 4320 4321 this.logger.write("full", "\tinsertTargetTable method is started."); 4322 boolean bInsertTable = false; 4323 int iVersionValue = 0; 4324 int iVersionMax = 0; 4325 boolean bWriteData = false; 4326 String strQueryWhere = ""; 4327 String strQuery = new String ("select "); 4328 String exceptionInRelations = ""; 4330 String replacementValueInRel = ""; 4331 String replacementTable = ""; 4332 String replacementColumn = ""; 4333 boolean relationIsOk = false; 4335 boolean updateQueryIsOk = false; 4336 boolean updateConstantIsOk = false; 4337 String strQueryConstantApendix = ""; 4338 4339 boolean bOidLogicCurrentTable = new Boolean (this.vecTableOidLogic.get( 4340 iTableInt).toString()).booleanValue(); 4341 boolean isTOS = ! (importDefinitionElement.strObjectIDNameColumnName.equals( 4342 "") || importDefinitionElement.strObjectIDNameColumnValue.equals("")); 4343 boolean oid = false; 4344 if (bOidLogicCurrentTable && !isTOS) 4345 oid = true; 4346 4347 Vector vecTempKeyColumns = (Vector )this.vecTargetKeyColumnName.get(iTableInt); 4348 4349 String key = String.valueOf(iTableInt); 4350 String query = (String )queryStatement.get(key); 4351 String update = (String )updateStatement.get(key); 4353 String updateConstant = (String )updateConstantStatement.get(key); 4354 4355 String updateTransformation = (String )updateTransformationStatement.get(key); 4356 4357 Statement stmtTarget = null; 4359 String logStatement = ""; 4365 try { 4366 if (query.indexOf(" where ") == -1) { 4368 this.insertRow(c, vecColumnValues, vecColumnTypes, vecColumnNames, 4369 vecColumnMode, bOidLogicCurrentTable, iTableInt, vecTransformationValue, transTargetColumnTypes); 4370 bInsertTable = true; 4371 } else { 4372 Vector dv = (Vector )indexDValue.get(key); 4373 Vector drv = (Vector )indexDRelationValue.get(key); 4374 Vector dcv = (Vector )indexConstantDValue.get(key); 4375 Vector dvv = (Vector )indexDVariableValue.get(key); 4376 Vector dtv = (Vector )indexDTransformationValue.get(key); 4377 4378 if (dv.size() > 0) { 4379 for (int i = 0; i < dv.size(); i++) { 4380 int index = Integer.parseInt(dv.get(i).toString()); 4381 if (vecColumnValues.get(index) == null) { 4382 int str = query.indexOf("'dummyValue'"); 4383 int num = query.indexOf("dummyValue"); 4384 if (str != -1 && (num == -1 || str < num)) 4385 query = replaceFirst(query, "= 'dummyValue'", " is null "); 4386 else 4387 query = replaceFirst(query, "= dummyValue", " is null "); 4388 } else { 4389 query = replaceFirst(query, "dummyValue", 4390 vecColumnValues.get(index).toString()); 4391 } 4392 } 4393 } 4394 if (drv.size() > 0) { 4395 for (int i = 0; i < drv.size(); i++) { 4396 int index = Integer.parseInt(drv.get(i).toString()); 4397 if (this.vecRelationSourceValue.get(index) == null) { 4398 int str = query.indexOf("'dummyRelationValue'"); 4399 int num = query.indexOf("dummyRelationValue"); 4400 if (str != -1 && (num == -1 || str < num)) 4401 query = replaceFirst(query, "= 'dummyRelationValue'", 4402 " is null "); 4403 else 4404 query = replaceFirst(query, "= dummyRelationValue", " is null "); 4405 } else { 4406 query = replaceFirst(query, "dummyRelationValue", 4407 this.vecRelationSourceValue.get(index). 4408 toString()); 4409 } 4410 } 4411 } 4412 4413 Vector vecTempConstantColumns = (Vector )this.vecConstantTargetColumnName.get(iTableInt); 4414 Vector vecTempConstantValues = (Vector )this.vecConstantConstantValue.get(iTableInt); 4415 Vector vecTempConstantMode = (Vector )this.vecConstantValueMode.get(iTableInt); 4416 Vector vecTempConstantType = (Vector )this.vecConstantColumnType.get(iTableInt); 4417 4419 4421 if (dcv.size() > 0) { 4422 for (int i = 0; i < dcv.size(); i++) { 4423 int index = Integer.parseInt(dcv.get(i).toString()); 4424 if (vecTempConstantValues.get(index) == null) { 4425 int str = query.indexOf("'dummyConstantValue'"); 4426 int num = query.indexOf("dummyConstantValue"); 4427 if (str != -1 && (num == -1 || str < num)) 4428 query = replaceFirst(query, "= 'dummyConstantValue'", 4429 " is null "); 4430 else 4431 query = replaceFirst(query, "= dummyConstantValue", " is null "); 4432 } else { 4433 query = replaceFirst(query, "dummyConstantValue", 4434 vecTempConstantValues.get(index).toString()); 4435 } 4436 } 4437 } 4438 4439 if (dvv.size() > 0) { 4440 for (int i = 0; i < dvv.size(); i++) { 4441 int index = Integer.parseInt(dvv.get(i).toString()); 4442 if (vecVariableValue.get(index) == null) { 4443 int str = query.indexOf("'dummyVariableValue'"); 4444 int num = query.indexOf("dummyVariableValue"); 4445 if (str != -1 && (num == -1 || str < num)) 4446 query = replaceFirst(query, "= 'dummyVariableValue'", 4447 " is null "); 4448 else 4449 query = replaceFirst(query, "= dummyVariableValue", " is null "); 4450 } else { 4451 query = replaceFirst(query, "dummyVariableValue", 4452 vecVariableValue.get(index).toString()); 4453 } 4454 } 4455 } 4456 if (dtv.size() > 0) { 4458 for (int i = 0; i < dtv.size(); i++) { 4459 int index = Integer.parseInt(dtv.get(i).toString()); 4460 if (vecTransformationValue.get(index) == null) { 4461 int str = query.indexOf("'dummyTransformationValue'"); 4462 int num = query.indexOf("dummyTransformationValue"); 4463 if (str != -1 && (num == -1 || str < num)) 4464 query = replaceFirst(query, "= 'dummyTransformationValue'", 4465 " is null "); 4466 else 4467 query = replaceFirst(query, "= dummyTransformationValue", " is null "); 4468 } else { 4469 query = replaceFirst(query, "dummyTransformationValue", 4470 vecTransformationValue.get(index).toString()); 4471 } 4472 } 4473 } 4474 if (query.indexOf("where") != -1) 4476 strQueryWhere = query.substring(query.indexOf("where") + 5); 4477 4478 stmtTarget = c.createStatement(); 4479 boolean rowExist; 4480 if (bOidLogicCurrentTable && !isTOS) 4481 rowExist = this.checkRowCache.getCheckRowValue(query, c, this.iTargetFirstColumnResult, 4482 this.currentVersionColumnName); 4483 else 4484 rowExist = this.checkRowCache.getCheckRowValue(query, c, 100, 4485 this.currentVersionColumnName); 4486 4487 if (!rowExist) { 4488 this.insertRow(c, vecColumnValues, vecColumnTypes, vecColumnNames, 4489 vecColumnMode, bOidLogicCurrentTable, iTableInt, vecTransformationValue, transTargetColumnTypes); 4490 bInsertTable = true; 4491 } else { if (bOidLogicCurrentTable && !isTOS) { 4493 iVersionValue = this.checkRowCache.getCheckRowVersionValue(); 4494 if (iVersionValue > iVersionMax) 4495 iVersionMax = iVersionValue; 4496 } 4497 if (!bInsertTable) { 4498 Vector dOverwrite = (Vector )indexDOverwrite.get(key); 4499 Vector dSetNull = (Vector )indexDSetNull.get(key); 4500 4501 if ( ( (update + strQueryWhere).indexOf("update") != -1 || 4502 (update + strQueryWhere).indexOf("UPDATE") != -1)) { 4503 if (dOverwrite.size() > 0) { 4504 int start = 0; 4505 for (int i = 0; i < dOverwrite.size(); i++) { 4506 Vector replacedValue = (Vector )vecDefaultValue.get(iTableInt); 4507 int index = Integer.parseInt(dOverwrite.get(i).toString()); 4508 if (vecColumnValues.get(index) == null) { 4509 int str = update.indexOf("'dummyOverwrite'"); 4510 int num = update.indexOf("dummyOverwrite"); 4511 if (replacedValue.get(index) != "") { 4512 if (str != -1 && (num == -1 || str < num)) 4513 update = replaceFirst(update, "'dummyOverwrite'", " '" + 4514 replacedValue.get(index).toString() + "' "); 4515 else 4516 update = replaceFirst(update, "dummyOverwrite", " " + 4517 replacedValue.get(index).toString() + " "); 4518 4519 dataCleaning.cleaningColumnValues(this.vecTableTableName. 4520 get(iTableInt).toString(), 4521 vecColumnNames.get(index).toString(), 4522 replacedValue.get(index).toString(), 4523 currentRow, c, "UPDATE", 4524 importDefinitionElement.strImportDefinitionName); 4525 } else { 4526 if (str != -1 && (num == -1 || str < num)) { 4527 String forReplace = "'dummyOverwrite'"; 4528 if(update.indexOf("N'dummyOverwrite'") != -1) 4529 forReplace = "N'dummyOverwrite'"; 4530 update = replaceFirst(update, forReplace, " null "); 4531 } 4532 else { 4533 update = replaceFirst(update, "dummyOverwrite", " null "); 4534 } 4535 } 4536 } else { 4537 String replacement = vecColumnValues.get(index).toString(); 4538 start = update.indexOf("dummyOverwrite", start); 4539 update = update.substring(0, start) + replacement + update.substring(start + 14); 4540 start = replacement.length(); 4541 } 4542 } 4543 } 4544 if (dSetNull.size() > 0) { 4545 for (int j = 0; j < dSetNull.size(); j++) { 4546 int index = Integer.parseInt(dSetNull.get(j).toString()); 4547 if (vecColumnValues.get(index) == null) { 4548 update = replaceFirst(update, "dummySetNull", 4549 vecColumnNames.get(index).toString() + "=" + " null "); 4550 } else { 4551 update = replaceFirst(update, "dummySetNull,", ""); 4552 } 4553 } 4554 } 4555 if (dOverwrite.size() > 0 || dSetNull.size() > 0) { 4556 if (bWriteData) 4557 update = replaceFirst(update, "dummyVersionOverwrite", 4558 String.valueOf(iVersionMax)); 4559 else 4560 update = replaceFirst(update, "dummyVersionOverwrite", 4561 String.valueOf(iVersionMax + 1)); 4562 if (bReplaceInData) { 4563 update = this.replaceInData(update); 4564 strQueryWhere = this.replaceInData(strQueryWhere); 4565 } 4566 relationIsOk = true; 4567 updateConstantIsOk = true; 4568 updateQueryIsOk = false; 4569 int iNumRowUp = 0; 4570 int ver = update.indexOf(this.currentVersionColumnName); 4572 int equals = update.indexOf("="); 4573 try { 4574 if (equals != ver + 8) { this.logger.write("full", 4576 "\tQuery '" + update + strQueryWhere + 4577 "' will be executed"); 4578 logStatement = update + strQueryWhere; 4579 iNumRowUp = stmtTarget.executeUpdate(update + strQueryWhere); 4580 } 4581 if (iNumRowUp != 0) { 4582 if (!bWriteData) 4583 iVersionMax = iVersionMax + 1; 4584 bWriteData = true; 4585 } 4586 String tableName = this.vecTableTableName.get(iTableInt). 4587 toString(); 4588 for (int i = 0; i < this.vecBlobVector.size(); i = i + 5) { 4589 if (!this.vecBlobVector.get(i + 3).toString(). 4590 equalsIgnoreCase("update")) { 4591 String version = ""; 4592 if (oid) { 4593 if (bWriteData) { 4594 version += ", " + this.currentVersionColumnName + " = " + iVersionMax; 4596 } else { 4597 version += ", " + this.currentVersionColumnName + "= " + (iVersionMax + 1); 4599 } 4600 } 4601 String columnName = this.vecBlobVector.get(i).toString(); 4602 byte[] isBlob = (byte[])this.vecBlobVector.get(i + 1); 4603 if (isBlob != null) { 4604 ByteArrayInputStream bais = new ByteArrayInputStream ( 4605 isBlob); 4606 logStatement = "update " + 4607 tableName + " set " + columnName + "=(?)" 4608 + version + " where " + columnName + " is null"; 4609 PreparedStatement pstmt = c.prepareStatement("update " + 4610 tableName + " set " + columnName + "=(?)" 4611 + version + " where " + columnName + " is null"); 4612 pstmt.setBytes(1, isBlob); 4613 int intRowStmt = pstmt.executeUpdate(); 4614 pstmt.close(); 4615 if (intRowStmt != 0) { 4616 if (!bWriteData) 4617 iVersionMax = iVersionMax + 1; 4618 bWriteData = true; 4619 } 4620 } 4621 } 4622 } 4623 } 4624 catch (SQLException ex) { 4625 stmtTarget.close(); 4626 stmtTarget = c.createStatement(); 4627 4628 if ( (importDefinitionElement.strDefaultCutOffData. 4629 equalsIgnoreCase("true"))) { 4630 dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName. 4631 get(iTableInt).toString(), c, 4632 strQueryWhere, currentRow, update, 4633 importDefinitionElement.strOnErrorContinueXml, 4634 importDefinitionElement.strImportDefinitionName, update + strQueryWhere); 4635 } else 4636 4637 throw ex; 4638 } 4639 } 4640 for (int j = 0; j < vecColumnNames.size(); j++) { 4641 if (vecColumnMode.get(j).toString().equalsIgnoreCase("Update")) { 4642 if (configReaderTarget.isBinaryObject(vecColumnTypes.get(j).toString())) { 4646 for (int i = 0; i < vecBlobVector.size(); i = i + 5) { 4649 if (vecBlobVector.get(i + 3).toString().equalsIgnoreCase( 4650 "update")) { 4651 if (vecBlobVector.get(i).toString().equalsIgnoreCase( 4652 vecColumnNames.get(j).toString())) { 4653 String version = ""; 4654 if (oid) { 4655 if (bWriteData) { 4656 version += ", " + this.currentVersionColumnName + " = " 4658 + (iVersionMax); 4659 } else { 4660 version += ", " + this.currentVersionColumnName + " = " 4662 + (iVersionMax + 1); 4663 } 4664 } 4665 String tableName = this.vecTableTableName.get( 4666 iTableInt). 4667 toString(); 4668 String columnName = this.vecBlobVector.get(i). 4669 toString(); 4670 byte[] isBlob = (byte[])this.vecBlobVector.get(i + 1); 4671 String condition = this.vecBlobVector.get(i + 2). 4672 toString(); 4673 if (isBlob != null) { 4674 ByteArrayInputStream bais = new 4675 ByteArrayInputStream ( 4676 isBlob); 4677 PreparedStatement pstmt = c.prepareStatement( 4678 "update " + tableName + " set " 4679 + columnName + 4680 "=(?)" 4681 + version + condition + strQueryWhere); 4682 pstmt.setBytes(1, isBlob); 4683 this.logger.write("full", 4684 "\tQuery '" + "update " + 4685 tableName + 4686 " set " 4687 + columnName + "=BlobObject" + 4688 version + condition + 4689 " where " + 4690 strQueryWhere + 4691 "' will be executed"); 4692 int intRowStmt = 0; 4693 logStatement = "update " + 4694 tableName + 4695 " set " 4696 + columnName + "=BlobObject" + 4697 version + condition + 4698 " where " + 4699 strQueryWhere; 4700 intRowStmt = pstmt.executeUpdate(); 4701 pstmt.close(); 4702 if (intRowStmt != 0) { 4703 if (!bWriteData) 4704 iVersionMax = iVersionMax + 1; 4705 bWriteData = true; 4706 } 4707 } 4708 } 4709 } 4710 } } else { 4712 String strQueryUpdate = "update " + 4713 this.vecTableTableName.get(iTableInt).toString() 4714 + " set "; 4715 strQueryUpdate += vecColumnNames.get(j).toString() 4716 + "="; 4717 if (vecColumnValues.get(j) == null) 4718 strQueryUpdate += " null "; 4719 else { 4720 if (!configReaderTarget.isNumber(vecColumnTypes.get(j).toString())) 4722 strQueryUpdate += "'" + vecColumnValues.get(j).toString() 4723 + "' "; 4724 else 4725 strQueryUpdate += vecColumnValues.get(j).toString() + " "; 4726 } 4727 if (oid) { 4728 if (bWriteData) { 4729 strQueryUpdate += ", " + this.currentVersionColumnName + " = " 4731 + (iVersionMax) + " where "; 4732 } else { 4733 strQueryUpdate += ", " + this.currentVersionColumnName + " = " 4735 + (iVersionMax + 1) + " where "; 4736 } 4737 } else 4738 strQueryUpdate += " where "; 4739 strQueryUpdate += vecColumnNames.get(j).toString() 4740 + " is null and "; 4741 if (bReplaceInData) { 4742 strQueryUpdate = this.replaceInData(strQueryUpdate); 4743 strQueryWhere = this.replaceInData(strQueryWhere); 4744 } 4745 this.logger.write("full", "\tQuery '" + 4746 strQueryUpdate + strQueryWhere + 4747 "' will be executed"); 4748 int iNumRow = 0; 4749 try { 4750 iNumRow = stmtTarget.executeUpdate(strQueryUpdate + strQueryWhere); 4751 } 4752 catch (SQLException ex) { 4753 stmtTarget.close(); 4754 stmtTarget = c.createStatement(); 4755 if ( (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("true"))) { 4756 dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName.get(iTableInt). 4757 toString(), c, strQueryWhere, currentRow, update, 4758 importDefinitionElement.strOnErrorContinueXml, 4759 importDefinitionElement.strImportDefinitionName,strQueryUpdate + strQueryWhere); 4760 } else 4761 throw ex; 4762 } 4763 if (iNumRow != 0) { 4764 if (!bWriteData) 4765 iVersionMax = iVersionMax + 1; 4766 bWriteData = true; 4767 } 4768 } 4769 } } 4771 } 4772 for (int i = 0; i < this.iRelationColumns; i++) { 4773 outLoop:if (this.vecRelationColumnSourceTableName.get(i).toString(). 4774 equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString()) 4775 && 4776 this.vecRelationColumnSourceTableID.get(i).toString(). 4777 equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) { 4778 for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) { 4779 if (this.vecRelationColumnSourceTableName.get(i).toString(). 4780 equalsIgnoreCase(this.vecVariableUseIDTableName.get(m).toString()) 4781 && 4782 this.vecRelationColumnSourceTableID.get(i).toString(). 4783 equalsIgnoreCase(this.vecVariableUseIDTableID.get(m).toString())) { 4784 String strQueryRelations = "select " + 4785 this.vecRelationColumnSourceColumnName.get(i). 4786 toString() + " from " + 4787 this.vecRelationColumnSourceTableName.get(i). 4788 toString() + " where "; 4789 strQueryRelations += vecTempKeyColumns.get(0).toString() + " = "; 4790 if (!configReaderTarget.isNumber(vecColumnTypes.get(0).toString())) 4792 strQueryRelations += "'" + this.strUserID + "'"; 4793 else 4794 strQueryRelations += this.strUserID; 4795 4796 if (this.vecTableTableMode.get(iTableInt).toString().equalsIgnoreCase("cache")) { 4797 Object obj = relationsCache.getRelationsCacheValue(strQueryRelations); 4798 if (obj != null) { 4799 if (!obj.toString().equalsIgnoreCase("#$Together#$")) { 4800 this.vecRelationSourceValue.setElementAt(obj, i); 4801 String type = relationsCache.getRelationsCachType(strQueryRelations); 4802 this.vecRelationSourceType.setElementAt(type, i); 4803 } 4804 } else { 4805 Statement stmtForUserID1 = c.createStatement(); 4806 ResultSet rsForUserID1 = null; 4807 try { 4808 this.logger.write("full", 4809 "\tQuery '" + strQueryRelations + "' will be executed"); 4810 rsForUserID1 = stmtForUserID1.executeQuery(strQueryRelations); 4811 } 4812 catch (SQLException ex) { 4813 rsForUserID1.close(); 4814 stmtForUserID1.close(); 4815 dataCleaning.cutingDataLenghtUpdate(this. 4816 vecTableTableName. 4817 get(iTableInt).toString(), c, 4818 strQueryWhere, currentRow, update, 4819 importDefinitionElement.strOnErrorContinueXml, 4820 importDefinitionElement.strImportDefinitionName, strQueryRelations); 4821 } 4822 if (rsForUserID1.next()) { 4823 if (this.iTargetFirstColumnResult == 1) { 4824 this.vecRelationSourceValue.setElementAt(rsForUserID1.getObject(1), i); 4825 this.vecRelationSourceType.setElementAt(rsForUserID1.getMetaData(). 4826 getColumnTypeName(1), i); 4827 relationsCache.setRelationsCacheValue(strQueryRelations, 4828 rsForUserID1.getObject(1)); 4829 relationsCache.setRelationsCacheType(strQueryRelations, 4830 rsForUserID1.getMetaData().getColumnTypeName(1)); 4831 } 4832 } else { 4833 relationsCache.setRelationsCacheValue(strQueryRelations, "#$Together#$"); 4834 relationsCache.setRelationsCacheType(strQueryRelations, "#$Together#$"); 4835 } 4836 rsForUserID1.close(); 4837 stmtForUserID1.close(); 4838 break outLoop; 4839 } 4840 } else { this.logger.write("full", 4842 "\tQuery '" + strQueryRelations + "' will be executed"); 4843 Statement stmtForUserID2 = c.createStatement(); 4844 ResultSet rsForUserID2 = null; 4845 try { 4846 rsForUserID2 = stmtForUserID2.executeQuery(strQueryRelations); 4847 } 4848 catch (SQLException ex) { 4849 rsForUserID2.close(); 4850 stmtForUserID2.close(); 4851 dataCleaning.cutingDataLenghtUpdate(this. 4852 vecTableTableName. 4853 get(iTableInt).toString(), c, 4854 strQueryWhere, currentRow, update, 4855 importDefinitionElement.strOnErrorContinueXml, 4856 importDefinitionElement.strImportDefinitionName, strQueryRelations); 4857 4858 } 4859 if (rsForUserID2.next()) { 4860 if (this.iTargetFirstColumnResult == 1) { 4861 this.vecRelationSourceValue.setElementAt(rsForUserID2.getObject(1), i); 4862 this.vecRelationSourceType.setElementAt(rsForUserID2.getMetaData(). 4863 getColumnTypeName(1), i); 4864 4865 } else { 4866 this.vecRelationSourceValue.setElementAt(rsForUserID2.getObject(0), i); 4867 this.vecRelationSourceType.setElementAt(rsForUserID2.getMetaData(). 4868 getColumnTypeName(0), i); 4869 } 4870 } 4871 rsForUserID2.close(); 4872 stmtForUserID2.close(); 4873 break outLoop; 4874 } 4875 } 4876 } String strQueryRelations = "select " + 4878 this.vecRelationColumnSourceColumnName.get(i).toString() 4879 + " from " + 4880 this.vecRelationColumnSourceTableName.get(i).toString() 4881 + " where " + strQueryWhere; 4882 if (this.vecTableTableMode.get(iTableInt).toString().equalsIgnoreCase("cache")) { 4883 Object obj = relationsCache.getRelationsCacheValue(strQueryRelations); 4884 if (obj != null) { 4885 if (!obj.toString().equalsIgnoreCase("#$Together#$")) { 4886 this.vecRelationSourceValue.setElementAt(obj, i); 4887 String type = relationsCache.getRelationsCachType( 4888 strQueryRelations); 4889 this.vecRelationSourceType.setElementAt(type, i); 4890 } 4891 } else { 4892 Statement stmtForRel1 = c.createStatement(); 4893 ResultSet rsForRel1 = null; 4894 try { 4895 this.logger.write("full", "\tQuery '" + strQueryRelations + 4896 "' will be executed"); 4897 rsForRel1 = stmtForRel1.executeQuery(strQueryRelations); 4898 } 4899 catch (SQLException ex) { 4900 rsForRel1.close(); 4901 stmtForRel1.close(); 4902 dataCleaning.cutingDataLenghtUpdate(this. 4903 vecTableTableName. 4904 get(iTableInt).toString(), c, 4905 strQueryWhere, currentRow, update, 4906 importDefinitionElement.strOnErrorContinueXml, 4907 importDefinitionElement.strImportDefinitionName, strQueryRelations); 4908 } 4909 4910 if (rsForRel1.next()) { 4911 if (this.iTargetFirstColumnResult == 1) { 4912 this.vecRelationSourceValue.setElementAt(rsForRel1.getObject(1), i); 4913 this.vecRelationSourceType.setElementAt(rsForRel1.getMetaData(). 4914 getColumnTypeName(1), i); 4915 relationsCache.setRelationsCacheValue(strQueryRelations, 4916 rsForRel1.getObject(1)); 4917 relationsCache.setRelationsCacheType(strQueryRelations, 4918 rsForRel1.getMetaData().getColumnTypeName(1)); 4919 } else { 4920 this.vecRelationSourceValue.setElementAt(rsForRel1.getObject(0), i); 4921 this.vecRelationSourceType.setElementAt(rsForRel1.getMetaData(). 4922 getColumnTypeName(0), i); 4923 relationsCache.setRelationsCacheValue(strQueryRelations, 4924 rsForRel1.getObject(0)); 4925 relationsCache.setRelationsCacheType(strQueryRelations, 4926 rsForRel1.getMetaData().getColumnTypeName(0)); 4927 } 4928 } else { 4929 relationsCache.setRelationsCacheValue(strQueryRelations, "#$Together#$"); 4930 relationsCache.setRelationsCacheType(strQueryRelations, "#$Together#$"); 4931 } 4932 rsForRel1.close(); 4933 stmtForRel1.close(); 4934 } 4935 } else { 4937 Statement stmtForRel2 = c.createStatement(); 4938 ResultSet rsForRel2 = null; 4939 try { 4940 this.logger.write("full", 4941 "\tQuery '" + strQueryRelations + "' will be executed"); 4942 rsForRel2 = stmtForRel2.executeQuery(strQueryRelations); 4943 } 4944 catch (SQLException ex) { 4945 rsForRel2.close(); 4946 stmtForRel2.close(); 4947 dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName. 4948 get(iTableInt).toString(), c, 4949 strQueryWhere, currentRow, update, 4950 importDefinitionElement.strOnErrorContinueXml, 4951 importDefinitionElement.strImportDefinitionName, strQueryRelations); 4952 } 4953 if (rsForRel2.next()) { 4954 if (this.iTargetFirstColumnResult == 1) { 4955 this.vecRelationSourceValue.setElementAt(rsForRel2.getObject(1), i); 4956 this.vecRelationSourceType.setElementAt(rsForRel2.getMetaData(). 4957 getColumnTypeName(1), i); 4958 } else { 4959 this.vecRelationSourceValue.setElementAt(rsForRel2.getObject(0), i); 4960 this.vecRelationSourceType.setElementAt(rsForRel2.getMetaData(). 4961 getColumnTypeName(0), i); 4962 } 4963 } 4964 rsForRel2.close(); 4965 stmtForRel2.close(); 4966 } 4967 } 4968 } 4969 4970 for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) { 4971 if (this.vecRelationColumnTargetTableName.get(i).toString(). 4972 equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString()) 4973 && 4974 this.vecRelationColumnTargetTableID.get(i).toString(). 4975 equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) { 4976 int currentVersion = 0; 4977 if (bWriteData) 4978 currentVersion = iVersionMax; 4979 else 4980 currentVersion = iVersionMax + 1; 4981 4982 if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("SetNull")) { 4983 if (this.vecRelationSourceValue.get(i) == null) { 4984 String strUpdateRelations = this.queryRelations(iTableInt, 4985 i, strQueryWhere, c, currentVersion, oid); 4986 this.logger.write("full", "\tQuery '" + strUpdateRelations + 4987 "' will be executed"); 4988 if (bReplaceInData) { 4989 strUpdateRelations = this.replaceInData( 4990 strUpdateRelations); 4991 } 4992 int iNumRow = 0; 4993 logStatement = strUpdateRelations; 4994 iNumRow = stmtTarget.executeUpdate(strUpdateRelations); 4995 this.vecRelationSourceValue.setElementAt(null, i); 4996 if (iNumRow != 0) { 4998 if (!bWriteData) 4999 iVersionMax = iVersionMax + 1; 5000 bWriteData = true; 5001 } 5002 } 5003 } else if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase( 5004 "Overwrite") || 5005 (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase("Update"))) { 5006 5007 replacementValueInRel = vecDefaultRelationValue.get(i).toString(); 5009 replacementTable = vecRelationColumnTargetTableName.get(i).toString(); 5010 replacementColumn = vecRelationColumnTargetColumnName.get(i).toString(); 5011 String strUpdateRelations = this.queryRelations(iTableInt, i, 5013 strQueryWhere, c, currentVersion, oid); 5014 this.logger.write("full", "\tQuery '" + strUpdateRelations + 5015 "' will be executed"); 5016 if (bReplaceInData) { 5017 strUpdateRelations = this.replaceInData(strUpdateRelations); 5018 } 5019 exceptionInRelations = strUpdateRelations; 5021 updateQueryIsOk = true; 5022 updateConstantIsOk = true; 5023 relationIsOk = false; 5024 int iNumRow = 0; 5025 try { 5026 logStatement = strUpdateRelations; 5027 iNumRow = stmtTarget.executeUpdate(strUpdateRelations); 5028 this.vecRelationSourceValue.setElementAt(null, i); 5029 } 5031 catch (SQLException ex) { 5032 stmtTarget.close(); 5033 5034 stmtTarget = c.createStatement(); 5035 if ( (importDefinitionElement.strDefaultCutOffData. 5036 equalsIgnoreCase("true"))) { 5037 dataCleaning.cutingDataLenghtUpdate(this. 5038 vecTableTableName.get(iTableInt).toString(), c, 5039 strQueryWhere, currentRow, update, 5040 importDefinitionElement.strOnErrorContinueXml, 5041 importDefinitionElement.strImportDefinitionName, strUpdateRelations); 5042 } else 5043 throw ex; 5044 } 5045 if (iNumRow != 0) { 5046 if (!bWriteData) 5047 iVersionMax = iVersionMax + 1; 5048 bWriteData = true; 5049 } 5050 } 5051 } 5052 } 5053 5054 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) { 5055 if ( ( (update + strQueryWhere).indexOf("update") != -1 || 5056 (update + strQueryWhere).indexOf("UPDATE") != -1)) { 5057 if (vecTempConstantColumns.size() > 0) { 5058 if (updateConstant.indexOf(",") != -1) 5059 updateConstant = updateConstant.substring(0,updateConstant.lastIndexOf(",")); 5060 5061 Vector cOverwrite = (Vector )indexDConstantOver.get(key); 5062 Vector cNull = (Vector )indexDConstantNull.get(key); 5063 strQueryConstantApendix = ""; 5064 if (cOverwrite.size() > 0) { 5065 int startOver = 0; 5066 for (int i = 0; i < cOverwrite.size(); i++) { 5067 int index = Integer.parseInt(cOverwrite.get(i).toString()); 5068 if (vecTempConstantValues.get(index) == null) { 5069 int str = updateConstant.indexOf("'dummyConstantOver'"); 5070 int num = updateConstant.indexOf("dummyConstantOver"); 5071 if (str != -1 && (num == -1 || str < num)) 5072 updateConstant = replaceFirst(updateConstant, 5073 "'dummyConstantOver'", " null "); 5074 else 5075 updateConstant = replaceFirst(updateConstant, 5076 "dummyConstantOver", " null "); 5077 } else { 5078 String replacement = vecTempConstantValues.get(index). 5079 toString(); 5080 startOver = updateConstant.indexOf("dummyConstantOver", 5081 startOver); 5082 updateConstant = updateConstant.substring(0, startOver) + 5083 replacement + 5084 updateConstant.substring(startOver + 17); 5085 startOver = replacement.length(); 5086 } 5087 } 5088 } 5089 if (cNull.size() > 0) { 5090 int startNull = 0; 5091 for (int i = 0; i < cNull.size(); i++) { 5092 int index = Integer.parseInt(cNull.get(i).toString()); 5093 if (vecTempConstantValues.get(index) == null) { 5094 int str = updateConstant.indexOf("'dummyConstantNull'"); 5095 int num = updateConstant.indexOf("dummyConstantNull"); 5096 if (str != -1 && (num == -1 || str < num)) 5097 updateConstant = replaceFirst(updateConstant, 5098 "'dummyConstantNull'", " null "); 5099 else 5100 updateConstant = replaceFirst(updateConstant, 5101 "dummyConstantNull", " null "); 5102 5103 strQueryConstantApendix += " and " + 5104 vecTempConstantColumns.get(index).toString() + 5105 " is null "; 5106 } else { 5107 String replacement = vecTempConstantValues.get(index). 5108 toString(); 5109 startNull = updateConstant.indexOf("dummyConstantNull", 5110 startNull); 5111 updateConstant = updateConstant.substring(0, startNull) + 5112 replacement + 5113 updateConstant.substring(startNull + 17); 5114 startNull = replacement.length(); 5115 } 5116 } 5117 } 5118 5119 if (bReplaceInData) { 5120 updateConstant = this.replaceInData(updateConstant); 5122 strQueryWhere = this.replaceInData(strQueryWhere); 5123 } 5124 5125 if (oid) { 5126 if (bWriteData) { 5127 updateConstant += ", " + this.currentVersionColumnName + " = " + (iVersionMax); 5129 } else { 5130 updateConstant += ", " + this.currentVersionColumnName + " = " + (iVersionMax 5132 + 1); 5133 } 5134 } 5135 updateQueryIsOk = true; 5136 relationIsOk = true; 5137 updateConstantIsOk = false; 5138 int iNumRow = 0; 5139 try { 5140 if (!updateConstant.endsWith(" set ")) { 5141 this.logger.write("full", "\tQuery '" + updateConstant + " where " + 5142 strQueryWhere + strQueryConstantApendix + "' will be executed"); 5143 logStatement = updateConstant + " where " + strQueryWhere; 5144 iNumRow = stmtTarget.executeUpdate(updateConstant + " where " + strQueryWhere + 5145 strQueryConstantApendix); 5146 } 5147 } 5148 catch (SQLException ex) { 5149 stmtTarget.close(); 5150 5151 stmtTarget = c.createStatement(); 5152 if ( (importDefinitionElement.strDefaultCutOffData. 5153 equalsIgnoreCase("true"))) { 5154 dataCleaning.cutingDataLenghtUpdate(this. 5155 vecTableTableName.get(iTableInt).toString(), c, 5156 " where " + strQueryWhere + strQueryConstantApendix, 5157 currentRow, updateConstant, 5158 importDefinitionElement.strOnErrorContinueXml, 5159 importDefinitionElement.strImportDefinitionName, 5160 updateConstant + " where " + 5161 strQueryWhere + strQueryConstantApendix); 5162 } else 5163 throw ex; 5164 } 5165 if (iNumRow != 0) { 5166 if (!bWriteData) 5167 iVersionMax = iVersionMax + 1; 5168 bWriteData = true; 5169 } 5170 } 5171 if (this.vecVariableTimesTableName.size() != 0) { 5172 int currentVersion = 0; 5173 boolean bool = false; 5174 if (!bWriteData) 5175 currentVersion = iVersionMax + 1; 5176 else 5177 currentVersion = iVersionMax; 5178 bool = this.updateCurrentTime(c, iTableInt, strQueryWhere, 5179 currentVersion, oid); 5180 if (bool) { 5181 if (!bWriteData) 5182 iVersionMax = iVersionMax + 1; 5183 bWriteData = true; 5184 } 5185 } 5186 if (this.vecVariableColumnTargetTableName.size() != 0) { 5187 int currentVersion = 0; 5188 boolean bool = false; 5189 if (!bWriteData) 5190 currentVersion = iVersionMax + 1; 5191 else 5192 currentVersion = iVersionMax; 5193 try { 5194 bool = this.updateNameValue(c, iTableInt, strQueryWhere, 5195 currentVersion, oid); 5196 } 5197 catch (SQLException ex) { 5198 throw ex; 5199 } 5200 if (bool) { 5201 if (!bWriteData) 5202 iVersionMax = iVersionMax + 1; 5203 bWriteData = true; 5204 } 5205 } 5206 } 5207 } 5212 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) { 5213 if (((update + strQueryWhere).indexOf("update") != -1 || 5214 (update + strQueryWhere).indexOf("UPDATE") != -1)) { 5215 5216 5218 5219 5222 5223 Vector tOverwrite = (Vector )indexDTransformationOver.get(key); 5224 Vector tNull = (Vector )indexDTransformationNull.get(key); 5225 5226 if ((updateTransformation.indexOf(",") != -1)) 5227 updateTransformation = updateTransformation.substring(0,updateTransformation.lastIndexOf(",")); 5228 5229 if (tOverwrite.size() > 0) { 5230 int startOver = 0; 5231 for (int i = 0; i < tOverwrite.size(); i++) { 5232 int index = Integer.parseInt(tOverwrite.get(i).toString()); 5233 if (vecTransformationValue.get(index) == null) { 5234 5235 int str = updateTransformation.indexOf("'dummyTransformationOver'"); 5236 int num = updateTransformation.indexOf("dummyTransformationOver"); 5237 if (str != -1 && (num == -1 || str < num)) 5238 updateTransformation = replaceFirst(updateTransformation, 5239 "'dummyTransformationOver'", " null "); 5240 else 5241 updateTransformation = replaceFirst(updateTransformation, 5242 "dummyTransformationOver", " null "); 5243 } else { 5244 String replacement = vecTransformationValue.get(index).toString(); 5245 startOver = updateTransformation.indexOf("dummyTransformationOver", 5246 startOver); 5247 updateTransformation = updateTransformation.substring(0, startOver) + 5248 replacement + 5249 updateTransformation.substring(startOver + 23); 5250 startOver = replacement.length(); 5251 5252 } 5253 5254 } 5255 } 5256 5257 if (tNull.size() > 0) { 5258 int startNull = 0; 5259 for (int i = 0; i < tNull.size(); i++) { 5260 int index = Integer.parseInt(tNull.get(i).toString()); 5261 String colName=((Vector )transformationsColumnNames.get(iTableInt)).get(index).toString(); 5262 if (vecTransformationValue.get(index) == null) { 5263 updateTransformation = replaceFirst(updateTransformation, 5264 "dummyTransformationNull", 5265 colName+ " = null "); 5266 } else { 5267 updateTransformation = replaceFirst(updateTransformation, 5268 "dummyTransformationNull,", " "); 5269 } 5270 } 5271 } 5272 5273 5274 if ((tOverwrite.size() > 0) || (tNull.size() > 0)){ 5275 5276 5277 if (bReplaceInData) { 5278 updateTransformation = this.replaceInData(updateTransformation); 5279 strQueryWhere = this.replaceInData(strQueryWhere); 5280 } 5281 5282 if (oid) { 5283 if (bWriteData) { 5284 updateTransformation += ", " + this.currentVersionColumnName + " = " + (iVersionMax); 5285 } else { 5286 updateTransformation += ", " + this.currentVersionColumnName + " = " + (iVersionMax 5287 + 1); 5288 } 5289 } 5290 5291 int iNumRow = 0; 5292 try { 5293 if (!updateTransformation.endsWith(" set ")) { 5294 this.logger.write("full", "\tQuery '" + updateTransformation + " where " + 5295 strQueryWhere + "' will be executed"); 5296 logStatement = updateTransformation + " where " + strQueryWhere; 5297 iNumRow = stmtTarget.executeUpdate(updateTransformation + " where " + 5298 strQueryWhere); 5299 } 5300 } 5301 catch (SQLException ex) { 5302 stmtTarget.close(); 5303 throw ex; 5304 } 5305 5306 if (iNumRow != 0) { 5307 if (!bWriteData) 5308 iVersionMax = iVersionMax + 1; 5309 bWriteData = true; 5310 } 5311 5312 } 5313 5314 5315 5316 5317 5318 5319 5320 5321 } } if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) { 5325 if (((update + strQueryWhere).indexOf("update") != -1 || 5326 (update + strQueryWhere).indexOf("UPDATE") != -1)) { 5327 5328 Vector tUpdate = (Vector ) indexDTransformationUpdate.get(key); 5330 if(tUpdate.size() > 0){ 5331 for (int j = 0; j < tUpdate.size(); j++) { 5333 int index = Integer.parseInt(tUpdate.get(j).toString()); 5334 Vector tempTransValueModes = (Vector )transformationsValueModes.get(iTableInt); 5335 Vector tempTransColumnNames = (Vector )transformationsColumnNames.get(iTableInt); 5336 Vector tempTransColumnTypes = (Vector )transformationsColumnTypes.get(iTableInt); 5337 if (tempTransValueModes.get(index).toString().equalsIgnoreCase("Update")) { 5338 5339 String strQueryUpdate = "update " + 5340 this.vecTableTableName.get(iTableInt).toString() 5341 + " set "; 5342 strQueryUpdate += tempTransColumnNames.get(index).toString() 5343 + "="; 5344 if (vecTransformationValue.get(index) == null) 5345 strQueryUpdate += " null "; 5346 else { 5347 5348 if (!configReaderTarget.isNumber(tempTransColumnTypes.get(index).toString())) 5349 strQueryUpdate += "'" + vecTransformationValue.get(index).toString() 5350 + "' "; 5351 else 5352 strQueryUpdate += vecTransformationValue.get(index).toString() + " "; 5353 } 5354 if (oid) { 5355 if (bWriteData) { 5356 5357 strQueryUpdate += ", " + this.currentVersionColumnName + " = " 5358 + (iVersionMax) + " where "; 5359 } else { 5360 5361 strQueryUpdate += ", " + this.currentVersionColumnName + " = " 5362 + (iVersionMax + 1) + " where "; 5363 } 5364 } 5365 strQueryUpdate += tempTransColumnNames.get(j).toString() 5367 + " is null and "; 5368 5369 if (bReplaceInData) { 5370 strQueryUpdate = this.replaceInData(strQueryUpdate); 5371 strQueryWhere = this.replaceInData(strQueryWhere); 5372 } 5373 this.logger.write("full", "\tQuery '" + 5374 strQueryUpdate + strQueryWhere + "' will be executed"); 5375 int iNumRow = 0; 5376 try { 5377 logStatement = strQueryUpdate + strQueryWhere; 5378 iNumRow = stmtTarget.executeUpdate(strQueryUpdate + strQueryWhere); 5379 } 5380 catch (SQLException ex) { 5381 stmtTarget.close(); 5382 stmtTarget = c.createStatement(); 5383 if ( (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("true"))) { 5384 dataCleaning.cutingDataLenghtUpdate(this.vecTableTableName.get(iTableInt). 5385 toString(), c, strQueryWhere, currentRow, update, 5386 importDefinitionElement.strOnErrorContinueXml, 5387 importDefinitionElement.strImportDefinitionName, strQueryUpdate + strQueryWhere); 5388 } else 5389 throw ex; 5390 } 5391 if (iNumRow != 0) { 5392 if (!bWriteData) 5393 iVersionMax = iVersionMax + 1; 5394 bWriteData = true; 5395 } 5396 5397 } 5398 } 5400 } 5401 } 5402 } 5403 5404 } 5406 5407 checkRowCache.setCheckRowVersionValue(String.valueOf(iVersionMax - 1)); 5408 } 5409 stmtTarget.close(); 5410 5411 } 5412 } 5413 catch (SQLException ex) { 5415 5416 if (stmtTarget != null) 5417 stmtTarget.close(); 5418 if ( (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("true"))) { 5419 dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).toString(), 5420 c, currentRow, "UPDATE", ex.getMessage(), 5421 importDefinitionElement.strImportDefinitionName,logStatement); 5422 } else { 5429 this.logger.write("normal", "\tDataCleaning features is not turn on."); 5430 throw ex; 5431 } 5432 } 5433 catch (NullPointerException ex) { 5434 throw ex; 5435 } 5436 catch (Exception ex) { 5437 5438 throw ex; 5439 } 5440 this.logger.write("full", "\tinsertTargetTable method is finished."); 5441 } 5442 5443 5459 private void insertRow(Connection c, Vector vecColumnValues, 5460 Vector vecColumnNamesTypes, 5461 Vector vecColumnNames, Vector vecColumnMode, 5462 boolean bOIDlogicValue, 5463 int iTableInt, Vector vecTransformationValue,Vector transformationTargetColumnTypes) throws SQLException ,NullPointerException , Exception { 5464 5465 String key = String.valueOf(iTableInt); 5466 String strInsertRow = (String )queryInsertRow.get(key); 5467 Vector indexOfNotRelationColumns = (Vector )indexIsNotRelationsColumns.get(key); 5468 5469 PreparedStatement pstmt = (PreparedStatement )pstmtForInsert.get(key); 5470 5471 Vector pstmtColNames = (Vector )pstmtColumnNames.get(key); 5472 Vector pstmtValues = new Vector (); 5473 Vector pstmtTypes = new Vector (); 5474 String selectValueInRel = ""; 5476 String currentValueInRel = ""; 5477 5478 this.logger.write("full", "\tinsertRow method is started."); 5479 String strQuery = ""; 5480 boolean isTOS = ! (importDefinitionElement.strObjectIDNameColumnName.equals( 5481 "") || importDefinitionElement.strObjectIDNameColumnValue.equals("")); 5482 Vector subCounterKeyColumns = this.counterColumns.getSubCounterKeyColumns( 5484 this.vecTableTableName.get(iTableInt).toString(), 5485 this.vecTableTableID.get(iTableInt).toString()); 5486 5487 Hashtable subKeyValues = new Hashtable (); 5488 try { 5489 Vector vecTempConstantColumns = (Vector )this.vecConstantTargetColumnName. 5490 get(iTableInt); 5491 Vector vecTempConstantValues = (Vector )this.vecConstantConstantValue.get( 5492 iTableInt); 5493 strInsertRow = strInsertRow.trim(); 5494 int comma = strInsertRow.lastIndexOf(","); 5495 if (comma == (strInsertRow.length() - 1)) 5496 strQuery = strInsertRow.substring(0, strInsertRow.length() - 1); 5497 else 5498 strQuery = strInsertRow; 5499 if (bOIDlogicValue) { 5500 if (isTOS) { 5501 pstmtValues.add(this.bdecOidNumber); 5502 pstmtTypes.add("java.math.BigDecimal"); 5503 } else { 5504 pstmtValues.add(this.bdecOidNumber); 5505 pstmtValues.add(String.valueOf(0)); 5506 pstmtTypes.add("java.math.BigDecimal"); 5507 pstmtTypes.add("java.lang.Integer"); 5508 } 5509 } 5510 5511 strQuery = strQuery + ") VALUES ("; 5512 5513 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) { 5514 if (indexOfNotRelationColumns.size() > 0) { 5515 for (int k = 0; k < indexOfNotRelationColumns.size(); k++) { 5516 int index = Integer.parseInt(indexOfNotRelationColumns.get(k). 5517 toString()); 5518 Vector replacedValue = (Vector )vecDefaultValue.get(iTableInt); 5519 if (vecColumnValues.get(index) == null) { 5520 if (replacedValue.get(index) != "") { 5521 pstmtValues.add(replacedValue.get(index).toString()); 5522 pstmtTypes.add(vecColumnNamesTypes.get(index).toString()); 5523 dataCleaning.cleaningColumnValues(this.vecTableTableName.get( 5524 iTableInt).toString(), vecColumnNames.get(index).toString(), 5525 replacedValue.get(index).toString(), currentRow, c, "INSERT", 5526 importDefinitionElement.strImportDefinitionName); 5527 } else { 5528 pstmtValues.add("null"); 5529 pstmtTypes.add(vecColumnNamesTypes.get(index).toString()); 5530 } 5531 } else { 5532 pstmtValues.add(vecColumnValues.get(index).toString()); 5533 pstmtTypes.add(vecColumnNamesTypes.get(index).toString()); 5534 } 5535 5536 for (int l = 0; l < subCounterKeyColumns.size(); l++) { 5538 if (subCounterKeyColumns.get(l) != null && 5539 ( (Vector )subCounterKeyColumns.get(l)).size() != 0 && 5540 ( (Vector )subCounterKeyColumns.get(l)).contains( 5541 vecColumnNames.get(index).toString())) { 5542 if (vecColumnValues.get(index) != null) { 5543 subKeyValues.put(vecColumnNames.get(index).toString(), 5544 vecColumnValues.get(index).toString()); 5545 } 5546 } 5547 } 5548 } 5549 } 5550 } 5551 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) { 5552 for (int p = 0; p < vecTempConstantValues.size(); p++) { 5553 if (vecTempConstantValues.get(p) == null) { 5554 pstmtValues.add("null"); 5555 pstmtTypes.add( ( (Vector )this.vecConstantColumnType.get(iTableInt)).get(p).toString()); 5556 } else { 5557 pstmtValues.add(vecTempConstantValues.get(p).toString()); 5558 pstmtTypes.add( ( (Vector )this.vecConstantColumnType.get(iTableInt)).get(p).toString()); 5559 5560 } 5561 for (int l = 0; l < subCounterKeyColumns.size(); l++) { 5563 if (subCounterKeyColumns.get(l) != null && 5564 ( (Vector )subCounterKeyColumns.get(l)).size() != 0 && 5565 ( (Vector )subCounterKeyColumns.get(l)).contains( 5566 vecTempConstantColumns.get(p))) { 5567 if (vecTempConstantValues.get(p) != null) 5568 subKeyValues.put(vecTempConstantColumns.get(p).toString(), 5569 vecTempConstantValues.get(p).toString()); 5570 } 5571 } 5572 } 5573 } 5574 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) { 5575 for (int i = 0; i < this.vecVariableTimesTableName.size(); i++) { 5576 if (this.vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(this. 5577 vecTableTableName.get(iTableInt).toString()) 5578 && 5579 this.vecVariableTimesTableID.get(i).toString(). 5580 equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) { 5581 pstmtValues.add(createCurrentDate()); 5582 pstmtTypes.add("java.sql.Date"); 5583 } 5584 } 5585 for (int i = 0; i < this.vecVariableColumnTargetTableName.size(); i++) { 5586 if (this.vecVariableColumnTargetTableName.get(i).toString(). 5587 equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString()) 5588 && 5589 this.vecVariableColumnTargetTableID.get(i).toString(). 5590 equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) { 5591 int iPositionInVector = this.vecVariableName.indexOf(this. 5592 vecVariableColumnName.get(i).toString()); 5593 if (iPositionInVector != -1) { 5594 if (this.vecVariableValue.get(iPositionInVector) == null) { 5595 String variableName = this.vecVariableColumnName.get(i). 5596 toString(); 5597 for (int k = 0; k < this.vecDefaultVariableName.size(); k++) { 5598 if (this.vecDefaultVariableName.get(k).toString(). 5599 equalsIgnoreCase(variableName)) { 5600 if (!this.vecDefaultVariableValue.get(k).toString().equalsIgnoreCase("")) { 5601 pstmtValues.add(this.vecDefaultVariableValue.get(k).toString()); 5602 pstmtTypes.add(this.vecVariableColumnTypes.get(i).toString()); 5603 } else { 5604 pstmtValues.add("null"); 5605 pstmtTypes.add(this.vecVariableColumnTypes.get(i).toString()); 5606 } 5607 break; 5608 } 5609 } 5610 } else { 5611 pstmtValues.add(this.vecVariableValue.get(iPositionInVector).toString()); 5612 pstmtTypes.add(this.vecVariableColumnTypes.get(i).toString()); 5613 } 5614 } else { 5615 this.logger.write("normal", "\tError: Cannot find value for variable column :" 5616 + this.vecVariableColumnName.get(i).toString()); 5617 LoaderException le = new LoaderException("Exception: ", (Throwable ) (new Exception ( 5618 "Error: Cannot find value for variable column :"))); 5619 this.logger.write("full", le.getStackTraceAsString()); 5620 throw le; 5621 } 5622 for (int l = 0; l < subCounterKeyColumns.size(); l++) { 5624 if (subCounterKeyColumns.get(l) != null && 5625 ( (Vector )subCounterKeyColumns.get(l)).size() != 0 && 5626 ( (Vector )subCounterKeyColumns.get(l)).contains(this. 5627 vecVariableColumnName.get(iPositionInVector))) { 5628 if (this.vecVariableValue.get(iPositionInVector) != null) 5629 subKeyValues.put(this.vecVariableColumnName.get( 5630 iPositionInVector).toString(), 5631 this.vecVariableValue.get(iPositionInVector). 5632 toString()); 5633 } 5634 } 5635 } 5636 } 5637 } 5638 for (int i = 0; i < this.iRelationColumns; i++) { 5640 outLoop1:if (this.vecRelationColumnSourceTableName.get(i).toString(). 5641 equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString()) 5642 && 5643 this.vecRelationColumnSourceTableID.get(i).toString(). 5644 equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) { 5645 for (int m = 0; m < this.vecVariableUseIDTableName.size(); m++) { 5646 if (this.vecRelationColumnSourceTableName.get(i).toString(). 5647 equalsIgnoreCase(this.vecVariableUseIDTableName.get(m).toString()) 5648 && 5649 this.vecRelationColumnSourceTableID.get(i).toString(). 5650 equalsIgnoreCase(this.vecVariableUseIDTableID.get(m).toString())) { 5651 String strQueryRelations = "select " + 5652 this.vecRelationColumnSourceColumnName.get(i).toString() 5653 + " from " + 5654 this.vecRelationColumnSourceTableName.get(i).toString() 5655 + " where "; 5656 strQueryRelations += 5657 ( (Vector )this.vecTargetKeyColumnName.get(iTableInt)).get(0). 5658 toString() 5659 + " = "; 5660 if (!configReaderTarget.isNumber(vecColumnNamesTypes.get(0).toString())) 5662 strQueryRelations += "'" + this.strUserID 5663 + "'"; 5664 else 5665 strQueryRelations += this.strUserID; 5666 this.logger.write("full", "\tQuery '" + strQueryRelations 5667 + "' will be executed"); 5668 Statement stmt = c.createStatement(); 5669 ResultSet rsetTarget = stmt.executeQuery(strQueryRelations); 5670 if (rsetTarget.next()) { 5671 if (this.iTargetFirstColumnResult == 1) { 5672 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(1), i); 5673 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData(). 5674 getColumnTypeName( 5675 1), i); 5676 } else { 5677 this.vecRelationSourceValue.setElementAt(rsetTarget.getObject(0), i); 5678 this.vecRelationSourceType.setElementAt(rsetTarget.getMetaData(). 5679 getColumnTypeName( 5680 0), i); 5681 } 5682 } 5683 rsetTarget.close(); 5684 stmt.close(); 5685 break outLoop1; 5686 } 5687 } 5688 if (bOIDlogicValue) { 5689 String oidType = configReaderTarget.getOidDbType(); 5690 int end = oidType.indexOf("("); 5691 if (end != -1) 5692 oidType = (oidType.substring(0, end)).trim(); 5693 else 5694 oidType = oidType.trim(); 5695 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) { 5696 this.vecRelationSourceValue.setElementAt(this.bdecOidNumber, i); 5698 this.vecRelationSourceType.setElementAt(oidType.toLowerCase(), i); 5699 5700 } else { 5701 this.vecRelationSourceValue.setElementAt(null, i); 5703 this.vecRelationSourceType.setElementAt(oidType.toLowerCase(), i); 5704 5705 } 5706 } else { if (this.iRelationColumns > 0) { 5708 for (int j = 0; j < vecColumnNames.size(); j++) { 5709 if (this.vecRelationColumnSourceColumnName.get(i).toString(). 5710 equalsIgnoreCase(vecColumnNames.get(j).toString())) { 5711 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) { 5712 this.vecRelationSourceValue.setElementAt(vecColumnValues.get( 5714 j).toString(), i); 5715 this.vecRelationSourceType.setElementAt(vecColumnNamesTypes. 5716 get(j).toString(), i); 5717 } else { 5718 this.vecRelationSourceValue.setElementAt(null, i); 5720 this.vecRelationSourceType.setElementAt(vecColumnNamesTypes. 5721 get(j).toString(), i); 5722 } 5723 } 5724 } } 5726 } 5727 } 5728 } 5729 5730 for (int i = 0; i < this.vecRelationColumnTargetColumnName.size(); i++) { 5731 String tmpRelationForCount = ""; 5732 if (this.vecRelationColumnTargetTableName.get(i).toString(). 5733 equalsIgnoreCase(this.vecTableTableName.get(iTableInt).toString()) 5734 && 5735 this.vecRelationColumnTargetTableID.get(i).toString(). 5736 equalsIgnoreCase(this.vecTableTableID.get(iTableInt).toString())) { 5737 if (this.vecRelationSourceValue.get(i) == null) { 5738 String replacementValueInRel = vecDefaultRelationValue.get(i).toString(); 5739 if (!replacementValueInRel.equalsIgnoreCase("")) { 5740 try { 5742 Object obj = relationsCache.getRelationsCacheValue(replacementValueInRel); 5743 String relationValue; 5744 String relationType; 5745 if (obj != null) { 5746 relationValue = obj.toString(); 5748 relationType = relationsCache.getRelationsCachType(replacementValueInRel); 5749 pstmtValues.add(relationValue); 5750 pstmtTypes.add(relationType); 5751 } else { 5752 ResultSet newRelationValue = null; 5754 Statement newRelationsStmt = c.createStatement(); 5755 try { 5756 this.logger.write("full", 5757 "\tQuery '" + replacementValueInRel + "' will be executed"); 5758 newRelationValue = newRelationsStmt.executeQuery(replacementValueInRel); 5759 if (newRelationValue.next()) { 5760 relationValue = newRelationValue.getString(1); 5761 relationsCache.setRelationsCacheValue(replacementValueInRel, relationValue); 5762 relationType = newRelationValue.getMetaData().getColumnTypeName(1); 5763 relationsCache.setRelationsCacheType(replacementValueInRel, relationType); 5764 5765 newRelationValue.close(); 5766 newRelationsStmt.close(); 5767 5768 String strDataCleaning = dataCleaning.cleaningRelationValues(this. 5769 vecTableTableName.get(iTableInt).toString(), 5770 this.vecRelationColumnTargetColumnName.get(i). 5771 toString(), 5772 relationValue, 5773 relationType, currentRow, 5774 c, "INSERT", 0, false, 5775 importDefinitionElement.strImportDefinitionName, 5776 this.currentVersionColumnName, replacementValueInRel); 5777 pstmtValues.add(strDataCleaning); 5778 pstmtTypes.add(relationType); 5779 } else { newRelationValue.close(); 5781 newRelationsStmt.close(); 5782 relationValue = "null"; 5783 dataCleaning.cleaningInsert(this.vecTableTableName.get( 5784 iTableInt).toString(), c, currentRow, "INSERT", 5785 "Default value '" + replacementValueInRel 5786 + "' for relations is not valid.", 5787 importDefinitionElement.strImportDefinitionName, replacementValueInRel); 5788 5789 pstmtValues.add("null"); 5790 pstmtTypes.add(this.vecRelationSourceType.get(i).toString()); 5791 } 5792 } 5793 catch (SQLException ex) { 5794 newRelationValue.close(); 5795 newRelationsStmt.close(); 5796 LoaderException le = new LoaderException("\n" + "SQLException: " 5797 + ex.getMessage(), 5798 (Throwable )ex); 5799 this.logger.write("full", le.getStackTraceAsString()); 5800 throw le; 5801 } 5802 } 5803 5804 } 5805 catch (SQLException ex) { 5806 String msg = "Default value for foreign key(" + replacementValueInRel + 5807 ") is not valid. Import definition name: " + 5808 importDefinitionElement.strImportDefinitionName; 5809 LoaderException le = new LoaderException("SQLException: " + msg, 5810 (Throwable )ex); 5811 this.logger.write("full", le.getStackTraceAsString()); 5812 throw le; 5813 } 5814 5815 } else { pstmtValues.add("null"); 5817 if (this.vecRelationSourceType.get(i) != null) 5818 pstmtTypes.add(this.vecRelationSourceType.get(i).toString()); 5819 else 5820 pstmtTypes.add("java.lang.Object"); 5821 } 5822 } else { pstmtValues.add(this.vecRelationSourceValue.get(i).toString()); 5824 pstmtTypes.add(this.vecRelationSourceType.get(i).toString()); 5825 5826 tmpRelationForCount=this.vecRelationSourceValue.get(i).toString(); this.vecRelationSourceValue.setElementAt(null,i); 5828 5829 } 5830 5831 for (int l = 0; l < subCounterKeyColumns.size(); l++) { 5833 if (subCounterKeyColumns.get(l) != null && 5834 ( (Vector )subCounterKeyColumns.get(l)).size() != 0 && 5835 ( (Vector )subCounterKeyColumns.get(l)).contains(this. 5836 vecRelationColumnTargetColumnName.get(i))) { 5837 if (tmpRelationForCount != null) { 5838 subKeyValues.put(this.vecRelationColumnTargetColumnName.get(i).toString(), 5839 tmpRelationForCount); 5840 } 5841 } 5842 } 5843 } 5844 } 5845 5846 Vector counterColValues = this.counterColumns.getCounterValue( 5848 this.vecTableTableName.get(iTableInt).toString(), 5849 this.vecTableTableID.get(iTableInt).toString()); 5850 for (int i = 0; i < counterColValues.size(); i++) { 5851 if (counterColValues.get(i) != null) { 5852 int strInt = new BigDecimal (counterColValues.get(i).toString()). 5853 intValue(); 5854 pstmtValues.add(String.valueOf(strInt)); 5855 pstmtTypes.add("java.lang.Integer"); 5856 } else { 5857 pstmtValues.add("null"); 5858 pstmtTypes.add("java.lang.Integer"); 5859 } 5860 } 5861 this.counterColumns.setCounterValue(this.vecTableTableName.get(iTableInt). 5862 toString(), 5863 this.vecTableTableID.get(iTableInt). 5864 toString()); 5865 5867 if (this.vecTableInsert.get(iTableInt).toString().equalsIgnoreCase("true")) { 5869 this.counterColumns.setSubCounterKeyValues( 5870 this.vecTableTableName.get(iTableInt).toString(), 5871 this.vecTableTableID.get(iTableInt).toString(), subKeyValues); 5872 Vector subCounterColValues = this.counterColumns.readSubCounterValue( 5873 this.vecTableTableName.get(iTableInt).toString(), 5874 this.vecTableTableID.get(iTableInt).toString(), c, 5875 this.iTargetFirstColumnResult, 5876 this.vecTableTableMode.get(iTableInt).toString(), configReaderTarget); 5877 for (int i = 0; i < subCounterColValues.size(); i++) { 5878 if (subCounterColValues.get(i) != null) { 5879 pstmtValues.add(new BigDecimal (subCounterColValues.get(i).toString())); 5880 pstmtTypes.add("java.math.BigDecimal"); 5881 } else { 5882 pstmtValues.add("null"); 5883 pstmtTypes.add("java.math.BigDecimal"); 5884 } 5885 } 5886 if (bOIDlogicValue) { 5887 if (this.bdecOidNumber.compareTo(this.bdecOidNumber2000) == 0) { 5888 this.checkOidLogic(c); 5889 this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal (1)); 5890 } else 5891 this.bdecOidNumber = this.bdecOidNumber.add(new BigDecimal (1)); 5892 } 5893 5894 for (int i = 0; i < vecTransformationValue.size(); i++) { 5896 if ((vecTransformationValue.get(i))== null){ 5897 String valueForPstmt = "null"; 5898 pstmtValues.add(valueForPstmt); 5899 }else{ 5900 pstmtValues.add(vecTransformationValue.get(i).toString()); 5901 } 5902 5903 pstmtTypes.add(transformationTargetColumnTypes.get(i).toString()); 5904 5905 } 5906 5907 5908 5929 String pstmtColumnValue; 5932 for (int i = 0; i < pstmtValues.size(); i++) { 5933 5934 String javaType = pstmtTypes.get(i).toString().toUpperCase(); 5935 if (javaType.indexOf("JAVA") == -1){ 5936 javaType = Utils.replaceAll(javaType," ","_"); 5938 javaType = (String )configReaderTarget.getJavaTypeMapings().get(javaType.toUpperCase()); 5939 if (javaType == null){ 5940 LoaderException le = new LoaderException("Exception:",new Exception ("This type of data "+pstmtTypes.get(i).toString().toUpperCase()+" doesn't exists in the target table conf file!")); 5941 this.logger.write("full", le.getStackTraceAsString()); 5942 throw le; 5943 } 5944 } else { 5945 if (javaType.equalsIgnoreCase("java.math.BigDecimal")) 5946 javaType = "2"; 5947 else if (javaType.equalsIgnoreCase("java.lang.Integer")) 5948 javaType = "5"; 5949 else if (javaType.equalsIgnoreCase("java.sql.Date")) 5950 javaType = "9"; 5951 else if (javaType.equalsIgnoreCase("java.lang.Object")) 5952 javaType = "14"; 5953 5954 } 5955 5956 int javaTypeInt=Integer.parseInt(javaType); 5957 pstmtColumnValue = pstmtValues.get(i).toString(); 5958 if (javaTypeInt == 1){ 5961 if (!pstmtColumnValue.equalsIgnoreCase("null")){ 5962 String binaryName = pstmtValues.get(i).toString(); 5963 for (int j = 0; j < vecBlobVector.size(); j = j + 5) { 5964 if (binaryName.equalsIgnoreCase(vecBlobVector.get(j + 4).toString())) { 5965 byte[] isBlob = (byte[])this.vecBlobVector.get(j + 1); 5966 strQuery = strQuery + binaryName + ","; 5967 pstmt.setBytes(i + 1, isBlob); 5968 strQuery = strQuery + "BlobObject"+i + ","; 5969 break; 5970 } 5971 } 5972 }else{ 5973 pstmt.setNull(i + 1, java.sql.Types.BINARY); 5974 strQuery = strQuery + "null" + ","; 5975 } 5976 } else { 5977 if (javaTypeInt == 2) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 5979 BigDecimal number = new BigDecimal (0); 5980 if (!pstmtColumnValue.equalsIgnoreCase("")) 5981 number = new BigDecimal (pstmtColumnValue); 5982 strQuery = strQuery + pstmtColumnValue + ","; 5983 pstmt.setBigDecimal(i + 1, number); 5984 } else { 5985 pstmt.setNull(i + 1, java.sql.Types.DECIMAL); 5986 strQuery = strQuery + "null" + ","; 5987 } 5988 } else if (javaTypeInt == 3) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 5990 double number = 0; 5991 if (!pstmtColumnValue.equalsIgnoreCase("")) 5992 number = Double.parseDouble(pstmtColumnValue); 5993 strQuery = strQuery + pstmtColumnValue + ","; 5994 pstmt.setDouble(i + 1, number); 5995 } else { 5996 strQuery = strQuery + "null" + ","; 5997 pstmt.setNull(i + 1, java.sql.Types.DOUBLE); 5998 } 5999 } else if (javaTypeInt == 4) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6001 float number = 0; 6002 if (!pstmtColumnValue.equalsIgnoreCase("")) 6003 number = Float.parseFloat(pstmtColumnValue); 6004 pstmt.setFloat(i + 1, number); 6005 strQuery = strQuery + pstmtColumnValue + ","; 6006 } else { 6007 pstmt.setNull(i + 1, java.sql.Types.FLOAT); 6008 strQuery = strQuery + "null" + ","; 6009 } 6010 } else if (javaTypeInt == 5) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6012 int number = 0; 6013 if (!pstmtColumnValue.equalsIgnoreCase("")) 6014 number = Integer.parseInt(pstmtColumnValue); 6015 pstmt.setInt(i + 1, number); 6016 strQuery = strQuery + pstmtColumnValue + ","; 6017 } else { 6018 pstmt.setNull(i + 1, java.sql.Types.INTEGER); 6019 strQuery = strQuery + "null" + ","; 6020 } 6021 6022 } else if (javaTypeInt == 6) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6024 long number = 0; 6025 if (!pstmtColumnValue.equalsIgnoreCase("")) 6026 number = Long.parseLong(pstmtColumnValue); 6027 pstmt.setLong(i + 1, number); 6028 strQuery = strQuery + pstmtColumnValue + ","; 6029 } else { 6030 pstmt.setNull(i + 1, java.sql.Types.DOUBLE); 6031 strQuery = strQuery + "null" + ","; 6032 } 6033 } else if (javaTypeInt == 7) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6035 short number = 0; 6036 if (!pstmtColumnValue.equalsIgnoreCase("")) 6037 number = Short.parseShort(pstmtColumnValue); 6038 pstmt.setShort(i + 1, number); 6039 strQuery = strQuery + pstmtColumnValue + ","; 6040 } else { 6041 pstmt.setNull(i + 1, java.sql.Types.SMALLINT); 6042 strQuery = strQuery + "null" + ","; 6043 } 6044 } else if (javaTypeInt == 8) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6046 if (pstmtColumnValue.indexOf("''") != -1) { 6048 pstmtColumnValue = Utils.replaceAll(pstmtColumnValue, "''", "'"); 6049 } 6050 pstmt.setString(i + 1, pstmtColumnValue); 6051 strQuery = strQuery + "'"+pstmtColumnValue+"'" + ","; 6052 } else { 6053 pstmt.setNull(i + 1, java.sql.Types.VARCHAR); 6054 strQuery = strQuery + "null" + ","; 6055 6056 6057 } 6058 } else if (javaTypeInt == 9) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6060 pstmt.setString(i + 1, pstmtColumnValue); 6061 strQuery = strQuery + "'"+pstmtColumnValue+"'" + ","; 6062 } else { 6063 pstmt.setNull(i + 1, java.sql.Types.DATE); 6064 strQuery = strQuery + "null" + ","; 6065 } 6066 } else if (javaTypeInt == 10) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6068 pstmt.setString(i + 1, pstmtColumnValue); 6069 strQuery = strQuery + "'"+pstmtColumnValue+"'" + ","; 6070 } else { 6071 pstmt.setNull(i + 1, java.sql.Types.TIME); 6072 strQuery = strQuery + "null" + ","; 6073 } 6074 6075 } else if (javaTypeInt == 11) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6077 pstmt.setString(i + 1, pstmtColumnValue); 6078 strQuery = strQuery + "'"+pstmtColumnValue+"'" + ","; 6079 } else { 6080 pstmt.setNull(i + 1, java.sql.Types.TIMESTAMP); 6081 strQuery = strQuery + "null" + ","; 6082 } 6083 6084 } else if (javaTypeInt == 12) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6086 boolean bool = Boolean.getBoolean(pstmtColumnValue); 6087 pstmt.setBoolean(i + 1, bool); 6088 strQuery = strQuery + pstmtColumnValue + ","; 6089 } else { 6090 pstmt.setNull(i + 1, java.sql.Types.BIT); 6091 strQuery = strQuery + "null" + ","; 6092 } 6093 } else if (javaTypeInt == 13) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6095 pstmt.setString(i + 1,pstmtColumnValue); 6096 strQuery = strQuery + "'"+pstmtColumnValue+"'" + ","; 6097 } else { 6098 pstmt.setNull(i + 1, java.sql.Types.BIT); 6099 strQuery = strQuery + "null" + ","; 6100 } 6101 } else if (javaTypeInt == 14) { if (!pstmtColumnValue.equalsIgnoreCase("null")) { 6103 pstmt.setString(i + 1, pstmtColumnValue); 6104 strQuery = strQuery + "'"+pstmtColumnValue+"'" + ","; 6105 } else { 6106 pstmt.setNull(i + 1, java.sql.Types.NULL); 6108 strQuery = strQuery + "null" + ","; 6110 } 6111 }else{ 6112 LoaderException le = new LoaderException("Exception:",new Exception ("This java type is not supported!")); 6113 this.logger.write("full", le.getStackTraceAsString()); 6114 throw le; 6115 } 6116 } pstmtColumnValue=null; 6118 } 6119 strQuery = strQuery.substring(0, strQuery.length() - 1) + ")"; 6120 this.logger.write("full", "\tQuery '" + strQuery + "' will be executed"); 6121 6122 int pstmtInsert = 0; 6123 pstmtInsert = pstmt.executeUpdate(); 6124 if (pstmtInsert != 0) 6126 this.checkRowCache.setCheckRowValue(); 6127 pstmt.clearParameters(); 6128 pstmtValues.clear(); 6129 pstmtTypes.clear(); 6130 6131 6135 } else { 6136 this.checkRowCache.setCheckRowValue(); 6137 } 6138 } 6139 catch (SQLException ex) { 6140 pstmt.clearParameters(); 6141 pstmtValues.clear(); 6142 pstmtTypes.clear(); 6143 LoaderException le = new LoaderException("SQLException: ", (Throwable )ex); 6144 if (importDefinitionElement.strDefaultCutOffData.equalsIgnoreCase("true")) { 6145 dataCleaning.cutingDataLenght(this.vecTableTableName.get(iTableInt). 6146 toString(), c, 6147 strQuery, currentRow, 6148 importDefinitionElement. 6149 strOnErrorContinueXml, 6150 ex.getMessage(), 6151 importDefinitionElement.strImportDefinitionName, strQuery); 6152 } else if (importDefinitionElement.strOnErrorContinueXml.equalsIgnoreCase("true")) { 6153 pstmt.clearParameters(); 6154 pstmtValues.clear(); 6155 pstmtTypes.clear(); 6156 this.logger.write("full", "\tError in SQL statement: " +le.getStackTraceAsString()); 6158 dataCleaning.cleaningInsert(this.vecTableTableName.get(iTableInt).toString(), 6159 c, currentRow, "INSERT", ex.getMessage(), 6160 importDefinitionElement.strImportDefinitionName,strQuery); 6161 } else { 6162 pstmt.clearParameters(); 6163 pstmtValues.clear(); 6164 pstmtTypes.clear(); 6165 this.logger.write("normal", "\tError in SQL statement: " + le.getCause()); 6166 this.logger.write("full", le.getStackTraceAsString()); 6167 throw le; 6169 } 6170 } 6171 catch (NullPointerException ex) { 6172 throw ex; 6173 } 6174 catch (Exception ex) { 6175 throw ex; 6176 } 6177 this.logger.write("full", "\tinsertRow method is finished."); 6178 } 6179 6180 6187 private boolean isRelationColumn(String strColumnName, int iTable) { 6188 boolean bFind = false; 6189 endFor:for (int i = 0; i < this.vecRelationColumnTargetTableName.size(); i++) { 6190 if (this.vecRelationColumnTargetTableName.get(i).toString(). 6191 equalsIgnoreCase(this.vecTableTableName.get(iTable).toString()) 6192 && 6193 this.vecRelationColumnTargetTableID.get(i).toString(). 6194 equalsIgnoreCase(this.vecTableTableID.get(iTable).toString()) 6195 && 6196 this.vecRelationColumnTargetColumnName.get(i).toString(). 6197 equalsIgnoreCase(strColumnName)) { 6198 bFind = true; 6199 break endFor; 6200 } 6201 } 6202 return bFind; 6203 } 6204 6205 6213 private void checkOidLogic(Connection c) throws SQLException , 6214 NullPointerException { 6215 String strQuery = ""; 6216 this.logger.write("full", "\tcheckOidLogic method is started."); 6217 Boolean bTemp = new Boolean ("false"); 6218 6219 if (currentJobName.equalsIgnoreCase("importDefinition")) { 6220 for (int i = 0; i < this.iTables; i++) { 6221 if (this.vecTableOidLogic.get(i).toString().equalsIgnoreCase("true")) { 6222 bTemp = new Boolean ("true"); 6223 } 6224 } 6225 } else if (currentJobName.equalsIgnoreCase("copyTable")) { 6226 if (importDefinitionElement.strCopyTableOidLogic.equalsIgnoreCase("true")) { 6227 bTemp = new Boolean ("true"); 6228 } 6229 } 6230 6231 if (bTemp.booleanValue()) { 6232 try { 6233 if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") || 6234 importDefinitionElement.strObjectIDNameColumnValue.equals(""))) { 6235 strQuery = new String ("SELECT " + 6236 importDefinitionElement.strObjectIDColumnName 6237 + " FROM " + 6238 importDefinitionElement.strObjectIDTableName + 6239 " WHERE " 6240 + 6241 importDefinitionElement. 6242 strObjectIDNameColumnName + 6243 " = '" + 6244 importDefinitionElement. 6245 strObjectIDNameColumnValue + 6246 "'"); 6247 } else { 6248 strQuery = new String ("SELECT " + 6249 importDefinitionElement.strObjectIDColumnName 6250 + " FROM " + 6251 importDefinitionElement.strObjectIDTableName); 6252 } 6253 this.logger.write("full","\tQuery '" + strQuery + "' will be executed"); 6254 Statement stmtOid = c.createStatement(); 6255 ResultSet rsetOid = stmtOid.executeQuery(strQuery); 6256 if (rsetOid.next()) { 6257 if (this.iTargetFirstColumnResult == 1) 6258 this.bdecOidNumber = new BigDecimal (Integer.parseInt(rsetOid. 6259 getString(1))); 6260 else 6261 this.bdecOidNumber = new BigDecimal (Integer.parseInt(rsetOid. 6262 getString(0))); 6263 } else { 6264 if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") || 6265 importDefinitionElement.strObjectIDNameColumnValue.equals(""))) { 6266 String insert = "insert into " + 6267 importDefinitionElement.strObjectIDTableName + " (" + 6268 importDefinitionElement.strObjectIDNameColumnName + "," + 6269 importDefinitionElement.strObjectIDColumnName + ") values ('" + 6270 importDefinitionElement.strObjectIDNameColumnValue 6271 + "','" + importDefinitionElement.iObjectIDStartValue + "');"; 6272 stmtOid.execute(insert); 6273 } 6274 } 6275 rsetOid.close(); 6276 stmtOid.close(); 6277 6278 if (currentJobName.equalsIgnoreCase("copyTable")) { 6279 this.bdecOidNumber2000 = this.bdecOidNumber.add(new BigDecimal ( 6280 importDefinitionElement.iObjectIDCT)); 6281 } else { 6282 this.bdecOidNumber2000 = this.bdecOidNumber.add(new BigDecimal ( 6283 importDefinitionElement.iObjectID)); 6284 } 6285 Statement stmtOid2 = c.createStatement(); 6286 if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") || 6287 importDefinitionElement.strObjectIDNameColumnValue.equals(""))) { 6288 this.logger.write("full", 6289 "\tQuery '" + "UPDATE " + 6290 importDefinitionElement.strObjectIDTableName 6291 + " SET " + 6292 importDefinitionElement.strObjectIDColumnName + 6293 " = " + this.bdecOidNumber2000 6294 + " where " + 6295 importDefinitionElement. 6296 strObjectIDNameColumnName + 6297 " = '" + 6298 importDefinitionElement. 6299 strObjectIDNameColumnValue + 6300 "'' will be executed"); 6301 stmtOid2.executeUpdate("UPDATE " + 6302 importDefinitionElement.strObjectIDTableName 6303 + " SET " + 6304 importDefinitionElement.strObjectIDColumnName + 6305 " = " + this.bdecOidNumber2000 6306 + " where " + 6307 importDefinitionElement. 6308 strObjectIDNameColumnName + 6309 " = '" + 6310 importDefinitionElement. 6311 strObjectIDNameColumnValue + 6312 "'"); 6313 } else { 6314 this.logger.write("full", 6315 "\tQuery '" + "UPDATE " + 6316 importDefinitionElement.strObjectIDTableName 6317 + " SET " + 6318 importDefinitionElement.strObjectIDColumnName + 6319 " = " + this.bdecOidNumber2000 6320 + " where " + 6321 importDefinitionElement.strObjectIDColumnName + 6322 " = " + 6323 this.bdecOidNumber + "' will be executed"); 6324 stmtOid2.executeUpdate("UPDATE " + 6325 importDefinitionElement.strObjectIDTableName 6326 + " SET " + 6327 importDefinitionElement.strObjectIDColumnName + 6328 " = " + this.bdecOidNumber2000 6329 + " where " + 6330 importDefinitionElement.strObjectIDColumnName + 6331 " = " + 6332 this.bdecOidNumber); 6333 } 6334 stmtOid2.close(); 6335 } 6336 catch (SQLException ex) { 6337 throw ex; 6338 } 6339 catch (NullPointerException ex) { 6340 throw ex; 6341 } 6342 } 6343 this.logger.write("full", "\tcheckOidLogic method is finished."); 6344 } 6345 6346 6352 private String querySource() throws LoaderException { 6353 int i = 0; 6354 int j = 0; 6355 this.logger.write("full", "\tquerySource method is started."); 6356 Vector vecVektor = new Vector (); 6357 String strQuery = "select "; 6358 this.iOffsetForTransColumns = 0; 6360 while (i < this.iTables) { 6361 vecVektor = (Vector )this.vecSourceColumnName.get(i); 6362 this.iOffsetForTransColumns += vecVektor.size(); 6363 while (j < 6364 Integer.parseInt(this.vecValueColumnsTargetTables.get(i).toString())) { 6365 strQuery = strQuery + vecVektor.get(j).toString() + ", "; 6366 j++; 6367 this.iColumnsInSourceTable++; 6368 } 6369 j = 0; 6370 i++; 6371 } 6372 ArrayList trans = this.transformations.getTransformations(); 6373 for( int k = 0; k < trans.size(); k++ ) { 6378 Transformation transformation = (Transformation)trans.get(k); 6379 Vector sourceColumnNames = transformation.getSourceColumnNames(); 6382 for( int kk = 0 ; kk < sourceColumnNames.size(); kk++ ) { 6383 strQuery = strQuery + sourceColumnNames.get(kk).toString() + ", "; 6384 } 6386 } 6387 strQuery = strQuery.substring(0, strQuery.length() - 2); 6392 strQuery += " from " + importDefinitionElement.strImportDefinitionTableName; 6393 if (importDefinitionElement.vecRestartCounterSortColumn.size() != 0) { 6394 if (configReaderSource.getEnableOrderBy()) { 6395 strQuery += " order by "; 6396 for (j = 0; 6397 j < importDefinitionElement.vecRestartCounterSortColumn.size(); j++) { 6398 strQuery += importDefinitionElement.vecRestartCounterSortColumn.get(j). 6399 toString() + ", "; 6400 } 6401 strQuery = strQuery.substring(0, strQuery.length() - 2); 6402 } 6403 } 6404 6405 this.logger.write("full", "\tquerySource method is finished."); 6406 return strQuery; 6407 } 6408 6409 6418 private void targetColumnTypes(Connection connTarget) throws SQLException , 6419 NullPointerException { 6420 int iColumn; 6421 String strQueryTypes = ""; 6422 this.logger.write("full", "\ttargetColumnTypes method is started."); 6423 try { 6424 for (int i = 0; i < this.iTables; i++) { 6425 Vector vecKeyTypesRelations = new Vector (); 6426 Vector vecVektor = new Vector (); 6427 iColumn = 0; 6428 Statement stmtTypes = connTarget.createStatement(); 6429 if (this.configReaderTarget.getMaxRowsSupported()){ 6431 stmtTypes.setMaxRows(1); 6432 } 6433 6434 6435 strQueryTypes = "select "; 6436 for (int j = 0; j < ( (Vector )this.vecTargetColumnName.get(i)).size(); 6437 j++) { 6438 strQueryTypes += 6439 ( ( (Vector )this.vecTargetColumnName.get(i)).get(j).toString()) 6440 + ","; 6441 } 6442 for (int j = 0; j < ( (Vector )this.vecRelationKeyColumns.get(i)).size(); 6443 j++) { 6444 strQueryTypes += 6445 ( ( (Vector )this.vecRelationKeyColumns.get(i)).get(j).toString()) 6446 + ","; 6447 } 6448 strQueryTypes = strQueryTypes.substring(0, strQueryTypes.length() - 1); 6449 strQueryTypes += " from "; 6450 strQueryTypes += " " + this.vecTableTableName.get(i).toString(); 6451 6452 6453 if ( ( (Vector )this.vecTargetColumnName.get(i)).size() != 0 || 6454 ( (Vector )this.vecRelationKeyColumns.get(i)).size() != 0) { 6455 6456 this.logger.write("full", "\tQuery '" + strQueryTypes + 6457 "' will be executed"); 6458 ResultSet rsetTypes = stmtTypes.executeQuery(strQueryTypes); 6459 for (int j = 0; j < ( (Vector )this.vecValueMode.get(i)).size(); j++) { 6460 iColumn++; 6461 if (this.iTargetFirstColumnResult == 1) 6462 vecVektor.add(rsetTypes.getMetaData().getColumnTypeName(iColumn)); 6463 else 6464 vecVektor.add(rsetTypes.getMetaData().getColumnTypeName(iColumn - 6465 1)); 6466 } 6467 for (int j = 0; j < ( (Vector )this.vecRelationKeyColumns.get(i)).size(); 6468 j++) { 6469 iColumn++; 6470 if (this.iTargetFirstColumnResult == 1) 6471 vecKeyTypesRelations.add(rsetTypes.getMetaData(). 6472 getColumnTypeName(iColumn)); 6473 else 6474 vecKeyTypesRelations.add(rsetTypes.getMetaData(). 6475 getColumnTypeName(iColumn - 1)); 6476 } 6477 rsetTypes.close(); 6478 } 6479 stmtTypes.close(); 6480 this.vecRelationKeyTypes.setElementAt(vecKeyTypesRelations, i); 6481 this.vecTargetColumnType.add(vecVektor); 6482 } 6483 Statement stmtVariableTypes = connTarget.createStatement(); 6484 if (this.configReaderTarget.getMaxRowsSupported()){ 6485 stmtVariableTypes.setMaxRows(1); 6486 } 6487 for (int j = 0; j < this.vecVariableColumnTargetTableName.size(); j++) { 6488 strQueryTypes = "select "; 6489 strQueryTypes += this.vecVariableColumnTargetColumnName.get(j).toString() 6490 + " from "; 6491 strQueryTypes += this.vecVariableColumnTargetTableName.get(j).toString(); 6492 ResultSet rsetVariableTypes; 6493 this.logger.write("full", 6494 "\tQuery '" + strQueryTypes + "' will be executed"); 6495 rsetVariableTypes = stmtVariableTypes.executeQuery(strQueryTypes); 6496 if (this.iTargetFirstColumnResult == 1) 6497 this.vecVariableColumnTypes.add(rsetVariableTypes.getMetaData(). 6498 getColumnTypeName(1)); 6499 else 6500 this.vecVariableColumnTypes.add(rsetVariableTypes.getMetaData(). 6501 getColumnTypeName(0)); 6502 rsetVariableTypes.close(); 6503 } 6504 stmtVariableTypes.close(); 6505 } 6506 catch (SQLException ex) { 6507 throw ex; 6508 } 6509 catch (NullPointerException ex) { 6510 throw ex; 6511 } 6512 this.logger.write("full", "\ttargetColumnTypes method is finished."); 6513 } 6514 6515 6520 private String createCurrentDate() { 6521 6522 String strDateTimeFormat=this.configReaderTarget.getDateFormat(); 6523 SimpleDateFormat tmpDate=new SimpleDateFormat (strDateTimeFormat); 6524 String strDate=tmpDate.format(new Date (System.currentTimeMillis())); 6525 return strDate; 6526 6527 } 6576 6577 6585 private void constantColumnTypes(Connection c) throws SQLException , 6586 NullPointerException { 6587 int iCnt = 0; 6588 this.logger.write("full", "\tconstantColumnTypes method is started."); 6589 try { 6590 for (int i = 0; i < this.iTables; i++) { 6591 Vector vecTempConstantType = new Vector (); 6592 Vector vecTempConstantName = new Vector (); 6593 String strQuery = "select "; 6594 vecTempConstantName = (Vector )this.vecConstantTargetColumnName.get(i); 6595 if (vecTempConstantName.size() != 0) { 6596 Statement stmtConstant = c.createStatement(); 6597 for (int j = 0; j < vecTempConstantName.size(); j++) 6598 strQuery += vecTempConstantName.get(j).toString() + 6599 ", "; 6600 strQuery = strQuery.substring(0, strQuery.length() - 2); 6601 strQuery += " from " + this.vecTableTableName.get(i).toString(); 6602 this.logger.write("full", 6603 "\tQuery '" + strQuery + "' will be executed"); 6604 ResultSet rsetConstant = stmtConstant.executeQuery(strQuery); 6605 iCnt = vecTempConstantName.size(); 6606 for (int k = 0; k < iCnt; k++) { 6607 if (this.iTargetFirstColumnResult == 1) 6608 vecTempConstantType.add(rsetConstant.getMetaData(). 6609 getColumnTypeName(k + 1)); 6610 else 6611 vecTempConstantType.add(rsetConstant.getMetaData(). 6612 getColumnTypeName(k)); 6613 } 6614 rsetConstant.close(); 6615 stmtConstant.close(); 6616 } 6617 this.vecConstantColumnType.setElementAt(vecTempConstantType, i); 6618 } 6619 } 6620 catch (SQLException ex) { 6621 throw ex; 6622 } 6623 catch (NullPointerException ex) { 6624 throw ex; 6625 } 6626 this.logger.write("full", "\tconstantColumnTypes method is finished."); 6627 } 6628 6629 6638 private void inputUser(boolean b) throws java.io.IOException { 6639 if (b) { 6640 if (BufferOctopusClass.getInstance().IsUsed()) 6641 throw new IOException ( 6642 "Missing user name and password for the Source DB. Check LoaderJob.olj file!"); 6643 else 6644 this.logger.write("normal", 6645 "Missing user name and password for the Source DB."); 6646 } else { 6647 if (BufferOctopusClass.getInstance().IsUsed()) 6648 throw new IOException ( 6649 "Missing user name and password for the Target DB. Check LoaderJob.olj file!"); 6650 else 6651 this.logger.write("normal", 6652 "Missing user name and password for the Target DB."); 6653 } 6654 String strUserName; 6655 String strPassword; 6656 char cu; 6657 char cp; 6658 StringBuffer bufu = new StringBuffer (); 6659 StringBuffer bufp = new StringBuffer (); 6660 System.out.println("User name: "); 6661 try { 6662 while ( (cu = (char)System.in.read()) != '\n') 6663 bufu.append(cu); 6664 strUserName = bufu.toString(); 6665 strUserName = strUserName.substring(0, strUserName.length() - 1); 6666 System.out.println("Password: "); 6667 while ( (cp = (char)System.in.read()) != '\n') 6668 bufp.append(cp); 6669 strPassword = bufp.toString(); 6670 if (strPassword.length() != 0) 6671 strPassword = strPassword.substring(0, strPassword.length() - 1); 6672 if (b) { 6673 jdbcParametersElement.setJDBCSourceParameterUser(strUserName); 6674 jdbcParametersElement.setJDBCSourceParameterPassword(strPassword); 6675 } else { 6676 jdbcParametersElement.setJDBCTargetParameterUser(strUserName); 6677 jdbcParametersElement.setJDBCTargetParameterPassword(strPassword); 6678 } 6679 } 6680 catch (IOException ex) { 6681 throw ex; 6682 } 6683 } 6684 6685 6689 private void changeTableOrder() { 6690 Vector vecTempTableTableName = new Vector (); 6691 Vector vecTempTableTableID = new Vector (); 6692 Vector vecTempTableInsert = new Vector (); 6693 Vector vecTempTableTableMode = new Vector (); 6694 Vector vecTempTableOidLogic = new Vector (); 6695 Vector vecNumberOfTable = new Vector (); 6696 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) { 6697 int iNumberOfTable = 0; 6698 for (int j = 0; j < this.vecTableTableName.size(); j++) { 6699 if (this.vecTableTableName.get(j).toString().equalsIgnoreCase(this. 6700 vecRelationColumnSourceTableName.get(i).toString()) 6701 && 6702 this.vecTableTableID.get(j).toString().equalsIgnoreCase(this. 6703 vecRelationColumnSourceTableID. 6704 get(i).toString())) { 6705 iNumberOfTable = j; 6706 boolean bEqualsRelationSource = false; 6707 for (int k = 0; k < vecNumberOfTable.size(); k++) { 6708 if (j == (new Integer (vecNumberOfTable.get(k).toString())).intValue()) 6709 bEqualsRelationSource = true; 6710 } 6711 if (!bEqualsRelationSource) { 6712 vecTempTableTableName.addElement(this.vecTableTableName.get(j). 6713 toString()); 6714 vecTempTableTableID.addElement(this.vecTableTableID.get(j).toString()); 6715 vecTempTableInsert.addElement(this.vecTableInsert.get(j).toString()); 6716 vecTempTableTableMode.addElement(this.vecTableTableMode.get(j). 6717 toString()); 6718 vecTempTableOidLogic.addElement(this.vecTableOidLogic.get(j). 6719 toString()); 6720 vecNumberOfTable.addElement(new Integer (iNumberOfTable)); 6721 } 6722 } 6723 } 6724 } 6725 if (this.vecRelationColumnSourceTableName.size() != 0) { 6726 for (int i = 0; i < this.vecTableTableName.size(); i++) { 6727 boolean bEquals = false; 6728 for (int j = 0; j < vecNumberOfTable.size(); j++) { 6729 if (i == (new Integer (vecNumberOfTable.get(j).toString())).intValue()) { 6730 bEquals = true; 6731 } 6732 } 6733 if (!bEquals) { 6734 vecTempTableTableName.addElement(this.vecTableTableName.get(i). 6735 toString()); 6736 vecTempTableTableID.addElement(this.vecTableTableID.get(i).toString()); 6737 vecTempTableInsert.addElement(this.vecTableInsert.get(i).toString()); 6738 vecTempTableTableMode.addElement(this.vecTableTableMode.get(i). 6739 toString()); 6740 vecTempTableOidLogic.addElement(this.vecTableOidLogic.get(i).toString()); 6741 } 6742 } 6743 this.vecTableTableName = new Vector (); 6744 this.vecTableTableID = new Vector (); 6745 this.vecTableInsert = new Vector (); 6746 this.vecTableTableMode = new Vector (); 6747 this.vecTableOidLogic = new Vector (); 6748 for (int i = 0; i < vecTempTableTableName.size(); i++) { 6749 this.vecTableTableName.addElement(vecTempTableTableName.get(i).toString()); 6750 this.vecTableTableID.addElement(vecTempTableTableID.get(i).toString()); 6751 this.vecTableInsert.addElement(vecTempTableInsert.get(i).toString()); 6752 this.vecTableTableMode.addElement(vecTempTableTableMode.get(i).toString()); 6753 this.vecTableOidLogic.addElement(vecTempTableOidLogic.get(i).toString()); 6754 } 6755 } 6756 } 6757 6758 6764 private void changeRelationsOrder() { 6765 Vector vecTempSourceTableName = new Vector (); 6766 Vector vecTempSourceTableID = new Vector (); 6767 Vector vecTempSourceColumnName = new Vector (); 6768 Vector vecTempTargetTableName = new Vector (); 6769 Vector vecTempTargetTableID = new Vector (); 6770 Vector vecTempTargetColumnName = new Vector (); 6771 Vector vecTempRelationMode = new Vector (); 6772 Vector vecRelationsOrder = new Vector (); 6773 vecRelationsOrder.setSize(this.vecRelationColumnSourceTableName.size()); 6774 for (int i = 0; i < vecRelationsOrder.size(); i++) 6775 vecRelationsOrder.setElementAt(new Integer (i), i); 6776 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) { 6777 if (this.vecRelationColumnRelationMode.get(i).toString().equalsIgnoreCase( 6778 "Key")) { 6779 for (int j = 0; j < this.vecRelationColumnSourceTableName.size(); j++) { 6780 if (this.vecRelationColumnSourceTableName.get(i).toString(). 6781 equalsIgnoreCase(this.vecRelationColumnTargetTableName.get(j). 6782 toString()) 6783 && 6784 this.vecRelationColumnSourceTableID.get(i).toString(). 6785 equalsIgnoreCase(this.vecRelationColumnTargetTableID.get(j). 6786 toString())) 6787 vecRelationsOrder = this.setAfter(vecRelationsOrder, 6788 i, j); 6789 } 6790 } else { 6791 vecRelationsOrder = this.setLast(vecRelationsOrder, i); 6792 } 6793 } 6794 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) { 6795 vecTempSourceTableName.add(this.vecRelationColumnSourceTableName.get(i)); 6796 vecTempSourceTableID.add(this.vecRelationColumnSourceTableID.get(i)); 6797 vecTempSourceColumnName.add(this.vecRelationColumnSourceColumnName.get(i)); 6798 vecTempTargetTableName.add(this.vecRelationColumnTargetTableName.get(i)); 6799 vecTempTargetTableID.add(this.vecRelationColumnTargetTableID.get(i)); 6800 vecTempTargetColumnName.add(this.vecRelationColumnTargetColumnName.get(i)); 6801 vecTempRelationMode.add(this.vecRelationColumnRelationMode.get(i)); 6802 } 6803 for (int i = 0; i < this.vecRelationColumnSourceTableName.size(); i++) { 6804 this.vecRelationColumnSourceTableName.setElementAt(vecTempSourceTableName. 6805 get(Integer.parseInt(vecRelationsOrder.get(i).toString())), 6806 i); 6807 this.vecRelationColumnSourceTableID.setElementAt(vecTempSourceTableID.get( 6808 Integer.parseInt(vecRelationsOrder.get(i).toString())), 6809 i); 6810 this.vecRelationColumnSourceColumnName.setElementAt( 6811 vecTempSourceColumnName.get(Integer.parseInt(vecRelationsOrder.get(i). 6812 toString())), 6813 i); 6814 this.vecRelationColumnTargetTableName.setElementAt(vecTempTargetTableName. 6815 get(Integer.parseInt(vecRelationsOrder.get(i).toString())), 6816 i); 6817 this.vecRelationColumnTargetTableID.setElementAt(vecTempTargetTableID.get( 6818 Integer.parseInt(vecRelationsOrder.get(i).toString())), 6819 i); 6820 this.vecRelationColumnTargetColumnName.setElementAt( 6821 vecTempTargetColumnName.get(Integer.parseInt(vecRelationsOrder.get(i). 6822 toString())), 6823 i); 6824 this.vecRelationColumnRelationMode.setElementAt(vecTempRelationMode.get( 6825 Integer.parseInt(vecRelationsOrder.get(i).toString())), 6826 i); 6827 } 6828 } 6829 6830 6837 private Vector setLast(Vector vecOrder, int iRelationTag) { 6838 int iLast = vecOrder.indexOf(new Integer (iRelationTag)); 6839 vecOrder.remove(iLast); 6840 vecOrder.add(new Integer (iRelationTag)); 6841 return vecOrder; 6842 } 6843 6844 6852 Vector setAfter(Vector vecOrder, int iIndexCurrent, int iIndexTarget) { 6853 if (iIndexCurrent < iIndexTarget) { 6854 int iCurrent = vecOrder.indexOf(new Integer (iIndexCurrent)); 6855 vecOrder.remove(iCurrent); 6856 int iTarget = vecOrder.indexOf(new Integer (iIndexTarget)); 6857 vecOrder.insertElementAt(new Integer (iIndexCurrent), iTarget + 6858 1); 6859 } 6860 return vecOrder; 6861 } 6862 6863 6870 private void executeSQLStatement() throws Exception { 6871 Connection conn = null; 6872 try { 6873 this.logger.write("full", "\tmethod executeSQLStatement is started"); 6874 Class.forName(jdbcParametersElement.getJDBCTargetParameterDriver()); 6877 conn = DriverManager.getConnection(jdbcParametersElement. 6878 getJDBCTargetParameterConnection(), 6879 jdbcParametersElement. 6880 getJDBCTargetParameterUser(), 6881 jdbcParametersElement. 6882 getJDBCTargetParameterPassword()); 6883 Statement stmtSeparate = conn.createStatement(); 6884 for (int i = 0; i < this.vecSqlStmt.size(); i++) { 6885 this.logger.write("full", "\tSQL_stmt : '" + this.vecSqlStmt.get(i).toString() 6886 + "' will be executed"); 6887 Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt.get(i).toString()); 6888 for (int j = 0; j < vecSingleSqlStmt.size(); j++) { 6889 executeSql(stmtSeparate, vecSingleSqlStmt.get(j).toString(), 0); 6890 } 6891 } 6892 stmtSeparate.close(); 6893 conn.close(); 6894 } 6895 catch (SQLException e) { 6896 throw e; 6897 } 6898 finally { 6899 if (conn != null && !conn.isClosed()) 6900 conn.close(); 6901 } 6902 } 6903 6904 6913 private void executeSQLStatement(Connection conn) throws Exception { 6914 try { 6915 this.timeCounter.setStartJobTime(); 6916 this.logger.write("full", "\tmethod executeSQLStatement is started"); 6917 this.logger.write("normal", "SQL statement " + sqlElement.getSqlName() + 6918 " is started"); 6919 boolean isCreateDatabaseStatement = false; 6920 out: 6921 for (int i = 0; i < this.vecSqlStmt.size(); i++) { 6922 if (this.vecSqlStmt.get(i).toString().toUpperCase().trim().startsWith( 6923 "CREATE DATABASE") || 6924 this.vecSqlStmt.get(i).toString().toUpperCase().trim().startsWith( 6925 "DROP DATABASE")) { 6926 isCreateDatabaseStatement = true; 6927 break out; 6928 } 6929 } 6930 if (isCreateDatabaseStatement) { 6931 executeSQLStatement(); 6932 } else { 6933 6934 Statement stmtSeparate = conn.createStatement(); 6935 for (int i = 0; i < this.vecSqlStmt.size(); i++) { 6936 this.logger.write("full", "\tSQL_stmt : '" + this.vecSqlStmt.get(i).toString() 6937 + "' will be executed"); 6938 Vector vecSingleSqlStmt = sqlStringToVector(this.vecSqlStmt.get(i).toString()); 6939 for (int j = 0; j < vecSingleSqlStmt.size(); j++) { 6940 executeSql(stmtSeparate, vecSingleSqlStmt.get(j).toString(), j + 1); 6941 } 6942 } 6943 if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) { 6944 if (!conn.getAutoCommit()) 6945 conn.commit(); 6946 } 6947 stmtSeparate.close(); 6948 } 6949 6950 this.logger.write("normal", "SQL statement " + sqlElement.getSqlName() + " is finished"); 6951 this.logger.write("full", "\tmethod executeSQLStatement is finished"); 6952 this.logger.write("normal", " Duration :" + this.timeCounter.getJobTime()); 6953 } 6954 catch (SQLException e) { 6955 throw e; 6956 } 6957 } 6958 6959 6965 private Vector sqlStringToVector(String sql) { 6966 Vector vecSqlString = new Vector (); 6967 int i = sql.indexOf(";"); 6968 if (i != -1) { 6969 while (i != -1) { 6970 vecSqlString.add(sql.substring(0, i)); 6972 sql = sql.substring(i + 1); 6973 i = sql.indexOf(";"); 6974 } 6975 } else 6976 6977 vecSqlString.add(sql.trim()); 6979 return vecSqlString; 6980 } 6981 6982 6992 private void executeSql(Statement stmtSql, String sqlStmt, int i) throws 6993 SQLException { 6994 try { 6995 if (bReplaceInData) { 6996 sqlStmt = this.replaceInData(sqlStmt); 6997 } 6998 sqlStmt.trim(); 6999 if (sqlStmt.length() != 0) 7000 stmtSql.execute(sqlStmt); 7001 } 7002 catch (SQLException e) { 7003 if (sqlElement.getSqlOnErrorContinue().equalsIgnoreCase("true")) { 7004 if (sqlElement.getSqlCommit().equalsIgnoreCase("true")) 7005 this.logger.write("normal", "\t Error in SQL statement: " + sqlStmt + 7006 " executing SQL statements continue..."); 7007 else 7008 this.logger.write("normal", "\t Error in SQL statement: " + sqlStmt + 7009 " \n\tStatement is number: " + i 7010 + " all statements before it is not commited, executing SQL statements continue..."); 7011 LoaderException le = new LoaderException("SQLException: ", 7012 (Throwable )e); 7013 this.logger.write("full", le.getStackTraceAsString()); 7014 } else { 7016 this.logger.write("normal", "\t Error in SQL statement: " + sqlStmt); 7017 throw e; 7018 } 7019 } 7020 } 7021 7022 7030 private boolean checkSortColumns(Connection connSource) throws 7031 LoaderException { 7032 boolean isEqualValues = false; 7033 String strQuery = "select "; 7034 try { 7035 this.logger.write("full", "\tmethod checkSortColumns is started"); 7036 for (int i = 0; 7037 i < importDefinitionElement.vecRestartCounterSortColumn.size(); i++) 7038 strQuery += importDefinitionElement.vecRestartCounterSortColumn.get(i). 7039 toString() 7040 + ","; 7041 strQuery = strQuery.substring(0, strQuery.length() - 1); 7042 strQuery += " from " + 7043 importDefinitionElement.strImportDefinitionTableName; 7044 strQuery += " order by "; 7045 for (int j = 0; 7046 j < importDefinitionElement.vecRestartCounterSortColumn.size(); j++) 7047 strQuery += importDefinitionElement.vecRestartCounterSortColumn.get(j). 7048 toString() 7049 + ", "; 7050 strQuery = strQuery.substring(0, strQuery.length() - 2); 7051 this.logger.write("full", "\tQuery '" + strQuery + "' executes"); 7052 Statement stmtSort = connSource.createStatement(); 7053 ResultSet rsetSort = stmtSort.executeQuery(strQuery); 7054 endWhile:while (rsetSort.next()) { 7055 Vector vecSortNewValues = new Vector (); 7056 for (int i = 0; 7057 i < importDefinitionElement.vecRestartCounterSortColumn.size(); i++) 7058 vecSortNewValues.add(rsetSort.getString(i + 1)); 7059 if (vecSortNewValues.equals(this.vecSortValues)) { 7060 isEqualValues = true; 7061 break endWhile; 7062 } else { 7063 this.vecSortValues = new Vector (); 7064 for (int i = 0; 7065 i < importDefinitionElement.vecRestartCounterSortColumn.size(); 7066 i++) 7067 this.vecSortValues.add(vecSortNewValues.get(i)); 7068 } 7069 } 7070 rsetSort.close(); 7071 stmtSort.close(); 7072 } 7073 catch (SQLException e) { 7074 LoaderException le = new LoaderException("SQLException: ", (Throwable )e); 7075 this.logger.write("full", le.getStackTraceAsString()); 7077 throw le; 7078 } 7079 this.logger.write("full", "\tmethod checkSortColumns is finished"); 7080 return isEqualValues; 7081 } 7082 7083 7088 private void createObjectIDTable(Connection conn) throws LoaderException { 7089 try { 7090 Statement stmt = conn.createStatement(); 7091 String sqlStmt = ""; 7092 if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") || 7093 importDefinitionElement.strObjectIDNameColumnValue.equals(""))) { 7094 sqlStmt = "create table " + 7095 importDefinitionElement.strObjectIDTableName + 7096 " (" + importDefinitionElement.strObjectIDColumnName + 7097 " VARCHAR(30) ," 7098 + importDefinitionElement.strObjectIDNameColumnName + 7099 " VARCHAR(30)) NOT NULL;"; 7100 7101 } else { 7102 sqlStmt = "create table " + 7103 importDefinitionElement.strObjectIDTableName + 7104 " (" + importDefinitionElement.strObjectIDColumnName + 7105 " DECIMAL(19,0) NOT NULL);"; 7106 } 7107 stmt.execute(sqlStmt); 7108 String insert = ""; 7109 if (! (importDefinitionElement.strObjectIDNameColumnName.equals("") || 7110 importDefinitionElement.strObjectIDNameColumnValue.equals(""))) { 7111 insert = "insert " + importDefinitionElement.strObjectIDTableName + 7112 " (" + 7113 importDefinitionElement.strObjectIDNameColumnName + "," + 7114 importDefinitionElement.strObjectIDColumnName + ") values ('" + 7115 importDefinitionElement.strObjectIDNameColumnValue 7116 + "','" + importDefinitionElement.iObjectIDStartValue + "');"; 7117 } else { 7118 insert = "insert " + importDefinitionElement.strObjectIDTableName + 7119 " (" + 7120 importDefinitionElement.strObjectIDColumnName + ") values (" + 7121 importDefinitionElement.iObjectIDStartValue 7122 + ");"; 7123 } 7124 if (bReplaceInData) { 7125 insert = this.replaceInData(insert); 7126 } 7127 stmt.execute(insert); 7128 conn.commit(); 7129 stmt.close(); 7130 } 7131 catch (SQLException e) { 7132 LoaderException le = new LoaderException("SQLException: ", (Throwable )e); 7133 this.logger.write("full", le.getStackTraceAsString()); 7135 throw le; 7136 } 7137 } 7138 7139 7144 private static Map convertToMap(String values) { 7145 Map mapValues = new HashMap (); 7146 int i = values.indexOf(";"); 7147 int k = 0; 7148 String part = new String (values); 7149 if (i != -1) { 7150 while (i != -1) { 7151 part = new String (values.substring(k, k + i)); 7152 int j = part.indexOf("="); 7153 String strObject = part.substring(0, j); 7154 String strValue = part.substring(j + 1); 7155 if (strValue.equals("")) 7156 strValue = null; 7157 mapValues.put(strObject, strValue); 7158 k += i + 1; 7159 i = values.substring(k).indexOf(";"); 7160 } 7161 if (! (values.substring(k).trim().equals("") || 7162 values.substring(k).trim().equals(";"))) { 7163 part = new String (values.substring(k)); 7164 int j = part.indexOf("="); 7165 String strObject = part.substring(0, j); 7166 String strValue = part.substring(j + 1); 7167 if (strValue.equals("")) 7168 strValue = null; 7169 mapValues.put(strObject, strValue); 7170 } 7171 } else { 7172 int j = values.indexOf("="); 7173 String strObject = values.substring(k, j); 7174 String strValue = values.substring(j + 1); 7175 if (strValue.equals("")) 7176 strValue = null; 7177 mapValues.put(strObject, strValue); 7178 } 7179 return mapValues; 7180 } 7181 7182 7188 private String replaceInData(String s) { 7189 for (int k = 0; k < this.vecReplaceInData.size(); k++) { 7191 if (this.vecReplaceInData.get(k).toString().equalsIgnoreCase("true")) { 7193 String sPreNameSu = this.vecVariablePrefix.get(k).toString() 7194 + this.vecVariableName.get(k).toString() + 7195 this.vecVariableSufix.get(k).toString(); 7196 int j = s.indexOf(sPreNameSu); 7197 while (j != -1) { 7199 s = s.substring(0, j) + this.vecVariableValue.get(k).toString() 7200 + s.substring(j + sPreNameSu.length(), s.length()); 7201 j = s.indexOf(sPreNameSu); 7202 } 7203 } 7204 } 7205 return s; 7206 } 7207 7208 7214 7233 7239 private String replaceChar(String s, char oldChar, String newValue) { 7240 7241 int j = s.indexOf(oldChar); 7242 String replacedString = ""; 7243 while (j != -1) { 7244 replacedString = replacedString + s.substring(0, j) + newValue; 7245 s = s.substring(j + 1); 7246 j = s.indexOf(oldChar); 7247 } 7248 replacedString = replacedString + s; 7249 return replacedString; 7250 } 7251 7252 7256 private void resetGlobalVariables() { 7257 importDefinitionElement.strImportDefinitionName = ""; 7258 importDefinitionElement.strImportDefinitionTableName = ""; 7259 importDefinitionElement.iImportDefinitionCommitCount = 0; 7260 importDefinitionElement.strImportDefinitionSelectStatement = ""; 7262 importDefinitionElement.bObjectIDAutoCreate = loaderJobReader. 7263 getDefaultObjectIDAutoCreate(); 7264 importDefinitionElement.iObjectIDStartValue = loaderJobReader. 7265 getDefaultObjectIDStartValue(); 7266 7267 importDefinitionElement.vecRestartCounterSortColumn = new Vector (); 7268 this.iValueColumns = 0; 7269 this.vecValueColumnsTargetTables = new Vector (); 7270 this.vecSourceColumnName = new Vector (); 7272 this.vecTargetColumnName = new Vector (); 7273 this.vecValueMode = new Vector (); 7274 this.vecTargetColumnValue = new Vector (); 7275 this.vecTargetKeyColumnName = new Vector (); 7276 this.iConstantColumns = 0; 7277 this.vecConstantTargetColumnName = new Vector (); 7278 this.vecConstantValueMode = new Vector (); 7279 this.vecConstantConstantValue = new Vector (); 7280 this.vecConstantColumnTargetTableName = new Vector (); 7281 this.vecConstantColumnTargetTableID = new Vector (); 7282 this.iRelationColumns = 0; 7283 this.vecRelationColumnSourceTableName = new Vector (); 7284 this.vecRelationColumnSourceTableID = new Vector (); 7285 this.vecRelationColumnSourceColumnName = new Vector (); 7286 this.vecRelationColumnTargetTableName = new Vector (); 7287 this.vecRelationColumnTargetColumnName = new Vector (); 7288 this.vecRelationColumnTargetTableID = new Vector (); 7289 this.vecRelationColumnRelationMode = new Vector (); 7290 this.iTables = 0; 7291 this.vecTableTableName = new Vector (); 7292 this.vecTableTableID = new Vector (); 7293 this.vecTableInsert = new Vector (); 7294 this.vecTableTableMode = new Vector (); 7295 this.vecTableOidLogic = new Vector (); 7296 this.vecRelationSourceValue = new Vector (); 7297 this.vecRelationSourceType = new Vector (); 7298 this.vecTargetColumnType = new Vector (); 7299 this.vecConstantColumnType = new Vector (); 7300 this.bdecOidNumber = new BigDecimal (0); 7301 this.bdecOidNumber2000 = new BigDecimal (0); 7302 importDefinitionElement.iObjectID = 0; 7303 importDefinitionElement.iObjectIDCT = 0; 7304 importDefinitionElement.strObjectIDTableName = ""; 7305 importDefinitionElement.strObjectIDColumnName = ""; 7306 importDefinitionElement.strObjectIDNameColumnName = ""; 7308 importDefinitionElement.strObjectIDNameColumnValue = ""; 7309 7310 this.vecVariableUseIDTableName = new Vector (); 7311 this.vecVariableUseIDTableID = new Vector (); 7312 this.vecVariableUseIDColumnName = new Vector (); 7313 this.vecVariableUseIDValueMode = new Vector (); 7314 this.vecVariableColumnName = new Vector (); 7315 this.vecVariableColumnTargetTableName = new Vector (); 7316 this.vecVariableColumnTargetTableID = new Vector (); 7317 this.vecVariableColumnTargetColumnName = new Vector (); 7318 this.vecVariableColumnValueMode = new Vector (); 7319 this.vecVariableColumnTypes = new Vector (); 7320 this.vecVariableTimesTableName = new Vector (); 7321 this.vecVariableTimesTableID = new Vector (); 7322 this.vecVariableTimesColumnName = new Vector (); 7323 this.vecVariableTimesValueMode = new Vector (); 7324 this.vecRelationKeyColumns = new Vector (); 7325 this.vecRelationKeyTypes = new Vector (); 7326 this.vecSortValues = new Vector (); 7327 this.vecSqlStmt = new Vector (); 7328 this.strSourceDriverName = ""; 7329 this.strTargetDriverName = ""; 7330 this.iFirstColumnResult = 1; 7331 this.iTargetFirstColumnResult = 1; 7332 this.iColumnsInSourceTable = 0; 7333 this.vecCTAutoMapp = new Vector (); 7335 this.vecCTDefaultMode = new Vector (); 7336 this.vecBlobVector = new Vector (); 7337 this.transformationsColumnNames = new Vector (); 7339 this.indexDTransformationOver = new Hashtable (); 7340 this.indexDTransformationNull = new Hashtable (); 7341 this.transformationsValueModes = new Vector (); 7342 this.transformationsColumnTypes = new Vector (); 7343 this.transformationValues = new Vector (); 7344 7345 } 7346 7347 private String replaceFirst(String input, String forReplace, 7348 String replaceWith) { 7349 String retVal = input; 7350 int start = input.indexOf(forReplace); 7351 int end = start + forReplace.length(); 7352 if (start != -1) { 7353 retVal = input.substring(0, start) + replaceWith + input.substring(end); 7354 } 7355 return retVal; 7356 } 7357 7361 public String inputToString() throws LoaderException{ 7362 String resString = ""; 7363 try { 7364 logger.write("full","Log mode ="+getDefaultLogMode()); 7365 logger.write("full","Restart indicator ="+getRestartIndicator()); 7366 logger.write("full","UserID ="+getUserID()); 7367 Hashtable resHashtable = new Hashtable (); 7368 resHashtable = (Hashtable )getVariableValues(); 7369 String pom2 =""; 7370 7371 if (resHashtable != null){ 7372 logger.write("full","Variables ="+resHashtable.toString()); 7373 pom2 = "Variables ="+resHashtable.toString(); 7374 }else{ 7375 logger.write("full","Variables = null"); 7376 pom2 = "Variables = null"; 7377 } 7378 logger.write("full","Log directory ="+getLogDirName()); 7379 logger.write("full","Log file name ="+getLogFileName()); 7380 logger.write("full","LoadJob file name ="+getLoadJobFileName()); 7381 logger.write("full","On error continue ="+getOnErrorContinue()); 7382 logger.write("full","Commit count ="+getCommitCount()); 7383 logger.write("full","Return code ="+getDefaultReturnCode()); 7384 logger.write("full","Vendor conf file ="+getVendorFileName()); 7385 7386 logger.write("full","Include list ="); 7387 String pom1=""; 7388 pom1 = "Include list ="; 7389 String [] listOfJobs = getIncludedJobs(); 7390 for (int j=0; j < listOfJobs.length;j++){ 7391 logger.write("full",listOfJobs[j].toString()); 7392 pom1 +=listOfJobs[j].toString()+"\n"; 7393 } 7394 logger.write("full","Path to conf files in jar ="+getConfJarStructure()); 7395 logger.write("full","Additional paths ="+getAdditionalPaths()); 7396 resString = "Log mode ="+getDefaultLogMode()+"\n"+ 7397 "Restart indicator ="+getRestartIndicator()+"\n"+ 7398 "UserID ="+getUserID()+"\n" 7399 +pom2+"\n"+ 7400 "Log directory ="+getLogDirName()+"\n"+ 7401 "Log file name ="+getLogFileName()+"\n"+ 7402 "LoadJob file name ="+getLoadJobFileName()+"\n"+ 7403 "On error continue ="+getOnErrorContinue()+"\n"+ 7404 "Commit count ="+getCommitCount()+"\n"+ 7405 "Return code ="+getDefaultReturnCode()+"\n"+ 7406 "Vendor conf file ="+getVendorFileName()+"\n"+pom1+"\n"+ 7407 "Path to conf files in jar ="+getConfJarStructure()+"\n"+ 7408 "Additional paths ="+getAdditionalPaths()+"\n"; 7409 7410 7411 return resString; 7412 } catch (Exception e) { 7413 7414 LoaderException le = new LoaderException("Exception:"+e.getMessage(),e); 7415 this.logger.write("full", le.getStackTraceAsString()); 7416 throw le; 7417 } 7418 7419 } 7420 7421 7422} 7423 | Popular Tags |