| 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 &n
|