1 16 17 package org.webdocwf.util.loader.generator; 18 19 import java.io.File ; 20 import java.util.Hashtable ; 21 import java.util.StringTokenizer ; 22 import java.util.Vector ; 23 24 import org.webdocwf.util.loader.LoaderException; 25 import org.webdocwf.util.loader.logging.Logger; 26 import org.webdocwf.util.loader.logging.StandardLogger; 27 32 public class InputParameters { 33 34 private String sourceType = "msql"; 35 private String targetType = "msql"; 36 private String sourceDataBase = null; 37 private String targetDataBase = null; 38 39 private String valueMode = "Overwrite"; 40 private String generatorOutput = ""; 41 private String sourceUser = ""; 42 private String sourcePassword = ""; 43 private String targetUser = ""; 44 private String targetPassword = ""; 45 private String sourceDriverName = ""; 46 private String targetDriverName = ""; 47 private String domlPath = ""; 48 49 private String packageName = null; 50 51 private String alterTablePrimaryKey = null; 52 private String pathToSourceConf = null; 53 private String pathToTargetConf = null; 54 55 private String path = "OctopusDBVendors.xml"; 57 private SearchXmlFile searchXmlFile = null; 58 59 private Vector sqlToGenerate = new Vector (); 61 private boolean generateSomeSql = false; 62 private boolean generateSqlForAllVendors = false; 63 64 private Vector allVendors = new Vector (); 65 private String generateXml = "false"; 66 private String generateDoml = "false"; 67 private String restoreMode = "false"; 68 69 private boolean fullMode = true; 71 private String [] excludedTables = null; 72 73 private Vector includeTableList = new Vector (); 74 75 private String confJarStructure = ""; 76 77 private String oidColumnName = "oid"; 79 private String versionColumnName = "version"; 80 private String oidColumnType = "decimal"; 81 private String versionColumnType = "bigint"; 82 83 private String maxConstraintLength = ""; 84 85 private Hashtable htHasSize = new Hashtable (); 87 private Hashtable htIsDecimal = new Hashtable (); 88 private Logger logger; 89 91 94 95 public void setHasSize() throws LoaderException { 96 try { 97 setLogger(); 98 SearchXmlFile searchXmlFile = new SearchXmlFile("absolute", getPathToSourceConf(), getConfJarStructure()); 102 this.htHasSize = searchXmlFile.getHasSize(); 103 107 } catch (Exception ex) { 108 109 LoaderException le = new LoaderException("Exception:" + ex.getMessage(), ex); 110 if (this.logger != null) { 111 this.logger.write("full", "Exception:" + le.getStackTraceAsString()); 112 } 113 throw le; 114 } 115 } 116 122 public String getHasSize(String sqlType) throws LoaderException { 123 try { 124 setLogger(); 125 if (htHasSize.containsKey((sqlType).toUpperCase())) { 127 return this.htHasSize.get((sqlType).toUpperCase()).toString(); 131 } else { 132 return "false"; 136 } 137 138 } catch (Exception e) { 139 140 LoaderException le = new LoaderException("Exception:", (Throwable ) e); 141 if (this.logger != null) { 142 this.logger.write("full", "Exception:" + le.getStackTraceAsString()); 143 } 144 throw le; 145 } 146 147 } 148 152 public void setIsDecimal() throws LoaderException { 153 try { 154 setLogger(); 155 SearchXmlFile searchXmlFile = new SearchXmlFile("absolute", getPathToSourceConf(), getConfJarStructure()); 159 this.htIsDecimal = searchXmlFile.getIsDecimal(); 160 161 } catch (Exception ex) { 162 163 LoaderException le = new LoaderException("Exception" + ex.getMessage(), ex); 164 if (this.logger != null) { 165 this.logger.write("full", "Exception:" + le.getStackTraceAsString()); 166 } 167 throw le; 168 } 169 } 173 179 public String getIsDecimal(String sqlType) throws LoaderException { 180 try { 181 setLogger(); 182 if (htIsDecimal.containsKey((sqlType).toUpperCase())) { 186 return this.htIsDecimal.get((sqlType).toUpperCase()).toString(); 188 } else { 189 return "false"; 193 } 194 } catch (Exception e) { 195 LoaderException le = new LoaderException("Exception:" + e.getMessage(), e); 196 if (this.logger != null) { 197 this.logger.write("full", "Exception:" + le.getStackTraceAsString()); 198 } 199 throw le; 200 } 201 202 } 203 204 public void setOidAndVersionColumnName() throws LoaderException { 205 206 try { 207 setLogger(); 208 SearchXmlFile searchXmlFile = new SearchXmlFile("absolute", getPathToTargetConf(), getConfJarStructure()); 212 213 this.oidColumnName = searchXmlFile.getOidDbColumn(); 214 this.versionColumnName = searchXmlFile.getVersionDbColumn(); 215 this.oidColumnType = searchXmlFile.getOidDB(); 216 this.versionColumnType = searchXmlFile.getVersionDb(); 217 218 } catch (Exception ex) { 219 LoaderException le = new LoaderException("Exception:" + ex.getMessage(), ex); 220 if (this.logger != null) { 221 this.logger.write("full", "Exception:" + le.getStackTraceAsString()); 222 } 223 throw le; 224 } 225 } 229 230 public String getOidColumnName() { 231 return this.oidColumnName; 232 } 233 234 public String getVersionColumnName() { 235 return this.versionColumnName; 236 } 237 238 public String getOidColumnType() { 239 return this.oidColumnType; 240 } 241 242 public String getVersionColumnType() { 243 return this.versionColumnType; 244 } 245 246 251 public void setIncludeTableList(String include_table_list) throws LoaderException { 252 setLogger(); 253 if (include_table_list.indexOf(",") != -1) { 257 String msg = "\tDelimiter for tables in 'Include Table List' parameter is ';' and not ','"; 258 LoaderException le = new LoaderException("Exception:", new Exception (msg + "\n")); 259 if (this.logger != null) { 260 this.logger.write("full", "Exception:" + "\tDelimiter for tables in 'Include Table List' parameter is ';' and not ','"+le.getStackTraceAsString()); 261 } 262 throw le; 263 } 264 265 StringTokenizer st = new StringTokenizer (include_table_list, ";"); 266 while (st.hasMoreTokens()) { 267 String tableName = st.nextElement().toString(); 268 if (tableName.length() > 0) 269 this.includeTableList.add(tableName); 270 } 271 } 275 276 280 public Vector getIncludeTableList() { 281 return this.includeTableList; 282 } 283 284 288 public void setRestoreMode(String restoreMode) { 289 this.restoreMode = restoreMode; 290 } 291 292 296 public String getRestoreMode() { 297 return this.restoreMode; 298 } 299 300 304 public void setFullMode(String full_mode) { 305 if (full_mode.equalsIgnoreCase("true")) 306 fullMode = true; 307 else 308 fullMode = false; 309 } 310 311 315 public boolean getFullMode() { 316 return fullMode; 317 } 318 319 323 public void setGenerateXml(String generate_Xml) { 324 this.generateXml = generate_Xml; 325 } 326 327 331 public String getGenerateXml() { 332 return this.generateXml; 333 } 334 335 339 public String getGenerateDoml() { 340 return this.generateDoml; 341 } 342 343 347 public void setGenerateDoml(String generate_Doml) { 348 this.generateDoml = generate_Doml; 349 } 350 351 355 public boolean getSqlForAllVendors() { 356 return generateSqlForAllVendors; 357 } 358 359 363 public void setAllVendors(String generate) { 364 if (generate.equalsIgnoreCase("true")) { 365 generateSqlForAllVendors = true; 366 allVendors = searchXmlFile.getAllVendors(); 367 } 368 } 369 370 374 public Vector getAllVendors() { 375 return allVendors; 376 } 377 378 382 public boolean isGenerateSql() { 383 return generateSomeSql; 384 } 385 386 private void setDefaultSqlStmt() { 387 sqlToGenerate.add(0, null); 388 sqlToGenerate.add(1, null); 389 sqlToGenerate.add(2, null); 390 sqlToGenerate.add(3, null); 391 sqlToGenerate.add(4, null); 392 sqlToGenerate.add(5, null); 393 } 394 395 399 public void setSqlStmtDropTable(String generate_DropTableStmt) { 400 401 if (generate_DropTableStmt.equalsIgnoreCase("true")) { 402 generateSomeSql = true; 403 sqlToGenerate.setElementAt("DropTables", 1); 404 } 405 } 406 407 411 public void setSqlStmtDropIntegrity(String generate_DropIntegrityStmt) { 412 if (generate_DropIntegrityStmt.equalsIgnoreCase("true")) { 413 generateSomeSql = true; 414 sqlToGenerate.setElementAt("DropIntegrity", 0); 415 } 416 } 417 418 422 public void setSqlStmtCreateTable(String generate_CreateTableStmt) { 423 if (generate_CreateTableStmt.equalsIgnoreCase("true")) { 424 generateSomeSql = true; 425 sqlToGenerate.setElementAt("CreateTables", 2); 426 } 427 } 428 429 433 public void setSqlStmtCreatePK(String generate_CreatePKStmt) { 434 if (generate_CreatePKStmt.equalsIgnoreCase("true")) { 435 if (!this.alterTablePrimaryKey.equalsIgnoreCase("false")) { 436 generateSomeSql = true; 437 sqlToGenerate.setElementAt("CreatePrimary", 4); 438 } 439 } 440 } 441 442 446 public void setSqlStmtCreateFK(String generate_CreateFKStmt) { 447 if (generate_CreateFKStmt.equalsIgnoreCase("true")) { 448 generateSomeSql = true; 449 sqlToGenerate.setElementAt("CreateForeigin", 5); 450 } 451 } 452 453 457 public void setSqlStmtCreateIndex(String generate_CreateIndexStmt) { 458 if (generate_CreateIndexStmt.equalsIgnoreCase("true")) { 459 generateSomeSql = true; 460 sqlToGenerate.setElementAt("CreateIndexes", 3); 461 } 462 } 463 464 468 public Vector getSqlToGenerate() { 469 return sqlToGenerate; 470 } 471 472 475 public void setSqlToGenerate() { 476 477 if (this.alterTablePrimaryKey.equalsIgnoreCase("false")) { 478 sqlToGenerate.setElementAt(null, 4); 479 } 480 } 481 482 486 public String getPath() { 487 return path; 488 } 489 490 494 public InputParameters(String confJarStructure) throws LoaderException { 495 setDefaultSqlStmt(); 497 searchXmlFile = new SearchXmlFile("relative", path, confJarStructure); 498 } 499 500 504 public void setPathToSourceConf(String path_ToSourceConf) { 505 pathToSourceConf = path_ToSourceConf; 506 } 507 508 512 public String getPathToSourceConf() { 513 return pathToSourceConf; 514 } 515 516 521 public void setSourceType(String source_Type) throws LoaderException { 522 setLogger(); 523 if (source_Type != null) { 527 if (searchXmlFile.getPathToConf(source_Type) != null) { 528 setPathToSourceConf(searchXmlFile.getPathToConf(source_Type)); 529 sourceType = source_Type; 530 } else { 531 String msg = "This type of source database (" + source_Type + ") is not supported!" + " See documentation!"; 532 LoaderException le = new LoaderException("Exception:", new Exception (msg + "\n")); 533 if (this.logger != null) { 534 this.logger.write("full", "Exception:" + "This type of source database (" + source_Type + ") is not supported!" + " See documentation!"+le.getStackTraceAsString()); 535 } 536 537 throw le; 538 } 539 } 540 } 544 545 549 public String getSourceType() { 550 return sourceType; 551 } 552 553 557 public void setPathToTargetConf(String path_ToTargetConf) { 558 pathToTargetConf = path_ToTargetConf; 559 } 560 561 565 public String getPathToTargetConf() { 566 return pathToTargetConf; 567 } 568 569 574 public void setTargetType(String target_Type) throws LoaderException { 575 setLogger(); 576 if (target_Type != null) { 580 if (searchXmlFile.getPathToConf(target_Type) != null) { 582 setPathToTargetConf(searchXmlFile.getPathToConf(target_Type)); 583 targetType = target_Type; 584 setAlterTablePrimaryKey2(pathToTargetConf); 585 } else { 586 String msg = "This type of target database (" + target_Type + ") is not supported!" + " See documentation!"; 587 LoaderException le = new LoaderException("Exception:", new Exception (msg)); 588 if (this.logger != null) { 589 this.logger.write("full", "Exception:" + "This type of target database (" + target_Type + ") is not supported!" + " See documentation!"+le.getStackTraceAsString()); 590 } 591 throw le; 592 } 593 } 594 } 598 599 private void setAlterTablePrimaryKey2(String pathToTargetConf) throws LoaderException { 600 SearchXmlFile searchXmlFile = new SearchXmlFile("absolute", getPathToTargetConf(), getConfJarStructure()); 601 if ((searchXmlFile.getAlterTablePrimaryKey(getTargetDriverName()) != null)) 602 setAlterTablePrimaryKey(searchXmlFile.getAlterTablePrimaryKey(getTargetDriverName())); 603 } 604 605 public void setSourceDriverProperties() throws LoaderException { 606 setLogger(); 607 SearchXmlFile searchXmlFile = new SearchXmlFile("absolute", getPathToSourceConf(), getConfJarStructure()); 611 Vector tmpVector = searchXmlFile.getFileSystemDatabase(getSourceDriverName()); 612 String fileSystemDatabse = tmpVector.get(0).toString(); 613 String connectionPrefix = tmpVector.get(1).toString(); 614 615 if (fileSystemDatabse.equalsIgnoreCase("true")) { 616 File file = new File (getSourceDataBase()); 617 File fileOut = new File (getGeneratorOutput()); 618 if (!file.isAbsolute()) { 619 try { 620 String main = ""; 621 if (!getGeneratorOutput().equalsIgnoreCase("")) 622 main = fileOut.getCanonicalPath() + System.getProperty("file.separator") + getSourceDataBase(); 623 else 624 main = getSourceDataBase(); 625 626 File mainFile = new File (main); 627 setSourceDataBase(mainFile.getCanonicalPath()); 628 } catch (Exception ex) { 629 LoaderException le = new LoaderException("Exception:" + ex.getMessage(), ex); 630 if (this.logger != null) { 631 this.logger.write("full", "Exception:" + le.getStackTraceAsString()); 632 } 633 634 throw le; 635 } 637 } 638 } 639 } 643 644 public void setTargetDriverProperties() throws LoaderException { 645 setLogger(); 646 SearchXmlFile searchXmlFile = new SearchXmlFile("absolute", getPathToTargetConf(), getConfJarStructure()); 650 try { 651 this.maxConstraintLength = searchXmlFile.getMaxConstraintLength(getTargetDriverName()); 652 } catch (Exception ex) { 653 LoaderException le = new LoaderException("Exception:" + ex.getMessage(), ex); 654 this.logger.write("full", "Exception:" + le.getStackTraceAsString()); 655 throw le; 656 } 657 661 } 662 663 public String getMaxConstraintLength() { 664 return this.maxConstraintLength; 665 } 666 667 671 public String getTargetType() { 672 return targetType; 673 } 674 675 680 public void setSourceDataBase(String source_DataBase) throws LoaderException { 681 setLogger(); 682 if (source_DataBase != null) { 686 if (this.sourceDriverName.equalsIgnoreCase("microsoft")) { 687 int num1 = source_DataBase.indexOf("SelectMethod="); 688 int num2 = source_DataBase.indexOf("selectMethod="); 689 if (num2 != -1) { 690 if (source_DataBase.indexOf("selectMethod=") != -1) 692 source_DataBase = Utils.replaceAll(source_DataBase, "selectMethod=", "SelectMethod="); 693 694 num1 = 0; 695 } 696 if (num1 != -1) 697 sourceDataBase = source_DataBase; 698 else 699 sourceDataBase = source_DataBase + ";SelectMethod=cursor"; 700 } else 701 sourceDataBase = source_DataBase; 702 } else { 703 String msg = "You must enter the place where is source database is placed (param -sdb)!"; 704 LoaderException le = new LoaderException("Exception:", new Exception (msg)); 705 this.logger.write("full", "Exception:" + "You must enter the place where is source database is placed (param -sdb)!"+le.getStackTraceAsString()); 706 throw le; 707 } 708 } 712 713 717 public String getSourceDataBase() { 718 return sourceDataBase; 719 } 720 721 726 public void setTargetDataBase(String target_DataBase) throws LoaderException { 727 setLogger(); 728 if (target_DataBase != null) { 732 if (this.targetDriverName.equalsIgnoreCase("microsoft")) { 733 int num1 = target_DataBase.indexOf("SelectMethod="); 734 int num2 = target_DataBase.indexOf("selectMethod="); 735 if (num2 != -1) { 736 if (target_DataBase.indexOf("selectMethod=") != -1) 738 target_DataBase = Utils.replaceAll(target_DataBase, "selectMethod=", "SelectMethod="); 739 num1 = 0; 740 } 741 if (num1 != -1) 742 targetDataBase = target_DataBase; 743 else 744 targetDataBase = target_DataBase + ";SelectMethod=cursor"; 745 } else 746 targetDataBase = target_DataBase; 747 } else { 748 String msg = "You must enter the place where is target database is placed (param -tdb)!"; 749 LoaderException le = new LoaderException("Exception:", new Exception (msg)); 750 if (this.logger != null) { 751 this.logger.write("full", "Exception:" + "You must enter the place where is target database is placed (param -tdb)!"+le.getStackTraceAsString()); 752 } 753 throw le; 754 } 755 } 759 760 764 public String getTargetDataBase() { 765 return targetDataBase; 766 } 767 768 773 public void setValueMode(String value_Mode) throws LoaderException { 774 setLogger(); 775 if (value_Mode != null) { 779 if (value_Mode.equalsIgnoreCase("copy")) { 780 valueMode = "Overwrite"; 781 } else if (value_Mode.equalsIgnoreCase("sync")) { 782 valueMode = "Update"; 783 } else { 784 String msg = "The possible value of value modes (param -m) are 'copy' or 'sync'.!"; 785 LoaderException le = new LoaderException("Exception:", new Exception (msg)); 786 if (this.logger != null) { 787 this.logger.write("full", "Exception:" + "The possible value of value modes (param -m) are 'copy' or 'sync'.!"+le.getStackTraceAsString()); 788 } 789 throw le; 790 } 791 } 792 } 796 797 801 public String getValueMode() { 802 return valueMode; 803 } 804 805 809 public void setGeneratorOutput(String generator_Output) { 810 if (generator_Output != null) 811 generatorOutput = generator_Output; 812 } 813 814 818 public String getGeneratorOutput() { 819 return generatorOutput; 820 } 821 822 826 public void setSourceUser(String source_User) { 827 if (source_User != null) 828 sourceUser = source_User; 829 } 830 831 835 public String getSourceUser() { 836 return sourceUser; 837 } 838 839 843 public void setSourcePassword(String source_Password) { 844 if (source_Password != null) 845 sourcePassword = source_Password; 846 847 } 848 849 853 public String getSourcePassword() { 854 return sourcePassword; 855 } 856 857 861 public void setTargetUser(String target_User) { 862 if (target_User != null) 863 targetUser = target_User; 864 } 865 866 870 public String getTargetUser() { 871 return targetUser; 872 } 873 874 878 public void setTargetPassword(String target_Password) { 879 if (target_Password != null) 880 targetPassword = target_Password; 881 } 882 883 887 public String getTargetPassword() { 888 return targetPassword; 889 } 890 891 895 public void setSourceDriverName(String source_DriverName) { 896 if (source_DriverName != null) 897 sourceDriverName = source_DriverName; 898 } 899 900 904 public String getSourceDriverName() { 905 return sourceDriverName; 906 } 907 908 912 public void setTargetDriverName(String target_DriverName) { 913 if (target_DriverName != null) 914 targetDriverName = target_DriverName; 915 } 916 917 921 public String getTargetDriverName() { 922 return targetDriverName; 923 } 924 925 929 public void setDomlPath(String doml_Path) { 930 if (doml_Path != null) 931 domlPath = doml_Path; 932 } 933 934 938 public String getDomlPath() { 939 return domlPath; 940 } 941 942 947 public void setPackageName(String package_Name) throws LoaderException { 948 setLogger(); 949 if (generateDoml.equalsIgnoreCase("true")) { 953 if (package_Name != null) { 954 packageName = package_Name; 955 } else { 956 String msg = "Sorry, but you must enter the package name (param -pack) for the doml file!"; 957 LoaderException le = new LoaderException("Exception", new Exception (msg)); 958 if (this.logger != null) { 959 this.logger.write("full", "Exception:" + "Sorry, but you must enter the package name (param -pack) for the doml file!"+le.getStackTraceAsString()); 960 } 961 throw le; 962 } 963 } 964 } 968 969 973 public String getPackageName() { 974 return packageName; 975 } 976 977 981 public void setAlterTablePrimaryKey(String alter_TablePrimaryKey) { 982 alterTablePrimaryKey = alter_TablePrimaryKey; 983 } 984 985 989 public String getAlterTablePrimaryKey() { 990 return alterTablePrimaryKey; 991 } 992 993 997 public void setExcludedTables(String value) { 998 StringTokenizer st = new StringTokenizer (value, ","); 999 this.excludedTables = new String [st.countTokens()]; 1000 int i = 0; 1001 while (st.hasMoreTokens()) { 1002 this.excludedTables[i] = st.nextToken(); 1003 i++; 1004 } 1005 } 1006 1007 1011 public String [] getExcludedTables() { 1012 return this.excludedTables; 1013 } 1014 1015 1018 public void setConfJarStructure(String confJarStructure) { 1019 if (confJarStructure != null) 1020 this.confJarStructure = confJarStructure; 1021 } 1022 1023 1027 public String getConfJarStructure() { 1028 return this.confJarStructure; 1029 } 1030 1034 private void setLogger() { 1035 this.logger = StandardLogger.getCentralLogger(); 1036 } 1037} 1038 | Popular Tags |