1 23 24 package org.dbforms.devgui; 25 26 import org.dbforms.config.ForeignKey; 27 import org.dbforms.config.Reference; 28 29 import java.sql.*; 30 31 import java.util.*; 32 33 34 35 41 public class XMLConfigGenerator implements PropertyNames { 42 static final String [] knownFieldTypes = { 44 "tinyint", 45 "int", 46 "smallint", 47 "integer", 48 "bigint", "float", 50 "real", "double", "numeric", 53 "decimal", 54 "number", "char", 56 "varchar", 57 "longchar", 58 "nvarchar", "blob", 60 "image", "diskblob", "date", "timestamp" }; 65 private static final int DBMS_MYSQL = 1; 66 private static final int DBMS_IBMDB2 = 2; 67 68 84 public static HashMap getForeignKeyInformation(DatabaseMetaData dbmd, 85 boolean includeCatalog, 86 String catalogSeparator, 87 boolean includeSchema, 88 String schemaSeparator, 89 Vector knownTables, 90 boolean foreignKeyTryGetCrossReferences, 91 Vector catalogNames, 92 Vector schemaNames, 93 Vector tableNames) { 94 HashMap hm = null; 95 96 if (foreignKeyTryGetCrossReferences) { 97 try { 98 hm = new HashMap(); 99 100 ResultSet rsk = dbmd.getCrossReference(null, null, null, null, 103 null, null); 104 105 while (rsk.next()) { 106 addSingleReference(hm, rsk, knownTables, includeCatalog, 107 catalogSeparator, includeSchema, 108 schemaSeparator); 109 } 110 } catch (SQLException ex) { 111 ex.printStackTrace(); 112 hm = null; 113 } 114 } 115 116 if (hm == null) { 118 try { 119 hm = new HashMap(); 120 121 for (int i = 0; i < tableNames.size(); i++) { 122 String catalogName = (String ) catalogNames.get(i); 123 String schemaName = (String ) schemaNames.get(i); 124 String tableName = (String ) tableNames.get(i); 125 ResultSet rsk = dbmd.getImportedKeys(catalogName, 126 schemaName, tableName); 127 128 while (rsk.next()) { 129 addSingleReference(hm, rsk, knownTables, includeCatalog, 130 catalogSeparator, includeSchema, 131 schemaSeparator); 132 } 133 } 134 } catch (SQLException ex) { 135 ex.printStackTrace(); 136 } 137 } 138 139 return hm; 140 } 141 142 143 153 public static String getForeignKeyTags(HashMap hm, 154 String catalog, 155 String schema, 156 String table) { 157 String hashKey = emptyIfNull(schema) + "\t" + table; 158 HashMap keyInfo = (HashMap) hm.get(hashKey); 159 160 if (keyInfo == null) { 161 return ""; 162 } 163 164 StringBuffer sb = new StringBuffer (""); 165 Collection col = keyInfo.values(); 166 Iterator forKeyIt = col.iterator(); 167 168 while (forKeyIt.hasNext()) { 169 ForeignKey fk = (ForeignKey) forKeyIt.next(); 170 java.util.Vector v = fk.getReferencesVector(); 171 sb.append("\n\t\t<foreign-key name=\"") 172 .append(fk.getName()) 173 .append("\"") 174 .append("\n\t\t foreignTable=\"") 175 .append(fk.getForeignTable()) 176 .append("\"") 177 .append("\n\t\t displayType=\"") 178 .append((v.size() == 1) ? "select" 179 : "none") 180 .append("\"") 181 .append(">\n"); 182 183 for (int jj = 0; jj < v.size(); jj++) { 184 Reference ref = (Reference) v.get(jj); 185 sb.append("\t\t <reference local=\"") 186 .append(ref.getLocal()) 187 .append("\"") 188 .append("\n\t\t foreign=\"") 189 .append(ref.getForeign()) 190 .append("\"/>\n"); 191 } 192 193 sb.append("\t\t</foreign-key>\n"); 194 } 195 196 return sb.toString(); 197 } 198 199 200 211 public static String createXMLOutput(ProjectData projectData, 212 boolean createGuiMessagewindow) 213 throws Exception { 214 String jdbcDriver = projectData.getProperty("jdbcDriver"); 215 String jdbcURL = projectData.getProperty("jdbcURL"); 216 String username = projectData.getProperty("username"); 217 String password = projectData.getProperty("password"); 218 219 boolean includeCatalog = projectData.getProperty(INCLUDE_CATALOGNAME) 221 .equalsIgnoreCase(TRUESTRING); 222 boolean includeSchema = projectData.getProperty(INCLUDE_SCHEMANAME) 223 .equalsIgnoreCase(TRUESTRING); 224 boolean useAutoCommitMode = projectData.getProperty(AUTOCOMMIT_MODE) 225 .equalsIgnoreCase(TRUESTRING); 226 boolean useStdTypeNames = projectData.getProperty(WRITE_STD_TYPENAMES) 227 .equalsIgnoreCase(TRUESTRING); 228 229 boolean foreignKeyDetectionActivated = !DEACTIVATED.equalsIgnoreCase(projectData 230 .getProperty(FOREIGNKEY_DETECTION)); 231 boolean foreignKeyTryGetCrossReferences = USE_GETCROSSREFERENCES 232 .equalsIgnoreCase(projectData 233 .getProperty(FOREIGNKEY_DETECTION)); 234 boolean generateDefaultValues = true; 235 236 Vector typesVec = new Vector(); 238 239 if (projectData.getProperty(EXAMINE_TABLES) 240 .equalsIgnoreCase(TRUESTRING)) { 241 typesVec.add("TABLE"); 242 } 243 244 if (projectData.getProperty(EXAMINE_VIEWS) 245 .equalsIgnoreCase(TRUESTRING)) { 246 typesVec.add("VIEW"); 247 } 248 249 if (projectData.getProperty(EXAMINE_SYSTABS) 250 .equalsIgnoreCase(TRUESTRING)) { 251 typesVec.add("SYSTEM TABLE"); 252 } 253 254 String [] types = new String [typesVec.size()]; 255 256 for (int jj = 0; jj < typesVec.size(); jj++) { 257 types[jj] = (String ) typesVec.get(jj); 258 } 259 260 String catalog = projectData.getProperty(CATALOG_SELECTION) 262 .equalsIgnoreCase(ALL) ? null 263 : projectData 264 .getProperty(CATALOG); 265 266 String schemaPattern = projectData.getProperty(SCHEMA_SELECTION) 267 .equalsIgnoreCase(ALL) ? null 268 : projectData 269 .getProperty(SCHEMA); 270 271 String tableNamePattern = projectData.getProperty(TABLE_SELECTION) 272 .equalsIgnoreCase(ALL) ? null 273 : projectData 274 .getProperty(TABLE_NAME_PATTERN); 275 276 String dateFormatTag = projectData.getProperty(DATE_FORMAT) 277 .equalsIgnoreCase("") ? "" 278 : ("\n\t<date-format>" 279 + projectData 280 .getProperty(DATE_FORMAT) 281 + "</date-format>\n\n"); 282 283 System.out.println(": Retrieving metadata using the following properties "); 284 System.out.println("-----------------------------------------------------"); 285 System.out.println("jdbcDriver=" + jdbcDriver); 286 System.out.println("jdbcURL=" + jdbcURL); 287 System.out.println("username=" + username); 288 System.out.println("password=(hidden)"); 289 System.out.println("catalog=" + catalog); 290 System.out.println("schemaPattern=" + schemaPattern); 291 System.out.println("tableNamePattern=" + tableNamePattern); 292 293 StringBuffer result = new StringBuffer (); 294 295 boolean showWarning = false; 296 int catalogNameFailure = 0; 297 int schemaNameFailure = 0; 298 StringBuffer warningMessage = new StringBuffer ("<html><ul>"); 299 300 Connection con = null; 301 302 try { 303 con = createConnection(jdbcDriver, jdbcURL, username, password); 304 305 result.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n\n<dbforms-config>\n"); 306 307 result.append(dateFormatTag); 308 309 DatabaseMetaData dbmd = con.getMetaData(); 310 311 boolean checkForAutoIncFields = false; 320 String autoIncColumnsQuery = ""; 321 String catalogPlaceholder = ":catalog"; 322 String schemaPlaceholder = ":schema"; 323 String tabnamePlaceholder = ":tabname"; 324 int dbms = 0; 325 PreparedStatement spCall = null; 326 327 try { 329 String dbmsProductName = dbmd.getDatabaseProductName(); 330 331 if (dbmsProductName != null) { 332 dbmsProductName = dbmsProductName.toLowerCase(); 333 334 if (dbmsProductName.equals("mysql")) { 335 dbms = DBMS_MYSQL; 336 checkForAutoIncFields = true; 337 autoIncColumnsQuery = "SHOW COLUMNS FROM :tabname LIKE ?"; 338 } else if (dbmsProductName.startsWith("db2")) { 339 dbms = DBMS_IBMDB2; 340 checkForAutoIncFields = true; 341 autoIncColumnsQuery = "SELECT identity FROM sysibm.syscolumns " 342 + "WHERE tbcreator=':schema' and tbname = ':tabname' AND name = ?"; 343 } 344 } 345 } catch (SQLException ignored) { 346 ; 347 } 348 349 if (includeCatalog) { 352 boolean supportsCatalogInDML = false; 353 354 try { supportsCatalogInDML = dbmd.supportsCatalogsInDataManipulation(); 356 } catch (Exception ignored) { 357 ; 358 } 359 360 if (!supportsCatalogInDML) { 361 showWarning = true; 362 warningMessage.append("<li>Your database system does not seem to support use of <br>" 363 + " catalog names in data manipulation statements. You should<br> " 364 + " better not include catalog names in table names."); 365 } 366 } 367 368 if (includeSchema) { 371 boolean supportsSchemaInDML = false; 372 373 try { supportsSchemaInDML = dbmd.supportsSchemasInDataManipulation(); 375 } catch (Exception ignored) { 376 ; 377 } 378 379 if (!supportsSchemaInDML) { 380 showWarning = true; 381 warningMessage.append("<li>Your database system does not seem to support use of <br>" 382 + " schema names in data manipulation statements. You should <br>" 383 + " better not include schema names in table names."); 384 } 385 } 386 387 if ((!useAutoCommitMode) && (!dbmd.supportsTransactions())) { 390 showWarning = true; 391 warningMessage.append("<li>Transaction mode not supported by DBMS, connection is <br>" 392 + " automatically set to autocommit mode."); 393 useAutoCommitMode = true; 394 } 395 396 if (!useAutoCommitMode) { 398 con.setAutoCommit(false); 399 } 400 401 String catalogSeparator = "."; 404 if (includeCatalog) { 405 try { 406 catalogSeparator = dbmd.getCatalogSeparator(); 407 } catch (SQLException ex) { 408 showWarning = true; 409 warningMessage.append("<li>Error reading catalog separator from database: <br>" 410 + ex.getMessage() + "<br>" 411 + " Using default '" + catalogSeparator 412 + "' instead."); 413 } 414 } 415 416 String schemaSeparator = "."; 418 Vector tableNames = new Vector(); 419 Vector catalogNames = new Vector(); 420 Vector schemaNames = new Vector(); 421 Vector knownTables = new Vector(); 422 423 try { 424 ResultSet tablesRS = dbmd.getTables(catalog, schemaPattern, 425 tableNamePattern, types); 426 427 while (tablesRS.next()) { 428 catalogNames.add(tablesRS.getString(1)); 429 schemaNames.add(tablesRS.getString(2)); 430 tableNames.add(tablesRS.getString(3)); 431 knownTables.add("" + emptyIfNull(tablesRS.getString(2)) + "\t" 432 + emptyIfNull(tablesRS.getString(3))); 433 } 434 435 tablesRS.close(); 436 } catch (SQLException ex) { 437 showWarning = true; 438 warningMessage.append("<li>Error while trying to read table names with <br>" 439 + " catalog=" + catalog 440 + ",<br> schemapattern=" + schemaPattern 441 + ",<br> tableNamePattern=" 442 + tableNamePattern 443 + "<br> from database. <br>Error message:" 444 + ex.getMessage() + "<br>"); 445 } 446 447 if (!useAutoCommitMode) { 448 con.commit(); 449 } 450 451 HashMap forKeys = null; 452 453 if (foreignKeyDetectionActivated) { 454 forKeys = getForeignKeyInformation(dbmd, includeCatalog, 455 catalogSeparator, includeSchema, 456 schemaSeparator, knownTables, 457 foreignKeyTryGetCrossReferences, 458 catalogNames, schemaNames, 459 tableNames); 460 } 461 462 if (!useAutoCommitMode) { 463 con.commit(); 464 } 465 466 if (tableNames.size() == 0) { 467 showWarning = true; 468 warningMessage.append("<li> No tables of type <br>("); 469 470 for (int i = 0; i < types.length; i++) 471 warningMessage.append("'") 472 .append(types[i]) 473 .append("' "); 474 475 warningMessage.append(") <br>found with catalog='" + catalog 476 + "', schemapattern='" + schemaPattern 477 + "',<br>tablename pattern='" 478 + tableNamePattern + "'"); 479 } 480 481 boolean autoIncColumnsQueryAlwaysSucceeded = true; 482 483 for (int i = 0; i < tableNames.size(); i++) { 484 String catalogName = (String ) catalogNames.get(i); 485 String schemaName = (String ) schemaNames.get(i); 486 String tableName = (String ) tableNames.get(i); 487 488 result.append("\t<table name=\""); 489 490 if (includeCatalog 493 && (catalogName != null) 494 && (!catalogName.equalsIgnoreCase(""))) { 495 result.append(catalogName.trim()) 496 .append(catalogSeparator); 497 } 498 499 if (includeCatalog 500 && ((catalogName == null) 501 || catalogName.equalsIgnoreCase(""))) { 502 catalogNameFailure++; 503 } 504 505 if (includeSchema 506 && (schemaName != null) 507 && (!schemaName.equalsIgnoreCase(""))) { 508 result.append(schemaName.trim()) 509 .append(schemaSeparator); 510 } 511 512 if (includeSchema 513 && ((schemaName == null) 514 || schemaName.equalsIgnoreCase(""))) { 515 schemaNameFailure++; 516 } 517 518 ResultSet rsKeys = dbmd.getPrimaryKeys(catalogName, schemaName, 520 tableName); 521 Vector keys = new Vector(); 522 String defaultVisibleFields = ""; 523 boolean isFirst = true; 524 525 while (rsKeys.next()) { 526 String columnName = rsKeys.getString(4); 527 keys.addElement(columnName); 528 529 if (isFirst) { 530 defaultVisibleFields += columnName; 531 } else { 532 defaultVisibleFields += ("," + columnName); 533 } 534 535 isFirst = false; 536 } 537 538 rsKeys.close(); 539 540 result.append(tableName) 541 .append("\""); 542 543 if (defaultVisibleFields.length() > 0) { 544 result.append("\n\t defaultVisibleFields=\"" 545 + defaultVisibleFields + "\" "); 546 } 547 548 result.append(">\n"); 549 550 if (checkForAutoIncFields) { 556 String sqlStmtPS = autoIncColumnsQuery; 557 558 int pos = autoIncColumnsQuery.indexOf(tabnamePlaceholder); 565 566 if (pos >= 0) { 567 sqlStmtPS = autoIncColumnsQuery.substring(0, pos) + tableName 568 + autoIncColumnsQuery.substring(pos 569 + tabnamePlaceholder 570 .length()); 571 } 572 573 pos = sqlStmtPS.indexOf(schemaPlaceholder); 574 575 if (pos >= 0) { 576 sqlStmtPS = sqlStmtPS.substring(0, pos) + schemaName 577 + sqlStmtPS.substring(pos 578 + schemaPlaceholder.length()); 579 } 580 581 pos = sqlStmtPS.indexOf(catalogPlaceholder); 582 583 if (pos >= 0) { 584 sqlStmtPS = sqlStmtPS.substring(0, pos) + catalogName 585 + sqlStmtPS.substring(pos 586 + catalogPlaceholder.length()); 587 } 588 589 try { spCall = con.prepareStatement(sqlStmtPS); 593 } catch (SQLException ex) { 594 System.err.println("Warning: Prepare of Statement \n'" 595 + sqlStmtPS 596 + "'\n failed with message \n'" 597 + ex.getMessage() 598 + "'.\n No reason to panic, just detection auf auto-incremented \n " 599 + " columns will not work. However, better send a mail to \n" 600 + " DbForms Mailing list to get this corrected"); 601 } 602 } 603 604 ResultSet rsFields = dbmd.getColumns(catalogName, schemaName, 605 tableName, null); 606 607 while (rsFields.next()) { 608 String columnName = rsFields.getString(4); 609 String typeName = rsFields.getString(6); 610 int columnSize = rsFields.getInt(7); 611 int typeCode = rsFields.getInt(5); 612 String defaultValue = null; 613 614 if (generateDefaultValues) { 615 defaultValue = rsFields.getString(13); 616 617 if (defaultValue != null) { 619 if (defaultValue.length() == 0) { 620 defaultValue = null; 621 } else if (defaultValue.equals("0")) { 622 defaultValue = null; 623 } 624 } 625 } 626 627 typeName = remapType(dbms, typeName); 629 630 boolean isAutoIncColumn = false; 635 636 if (checkForAutoIncFields && (spCall != null)) { 637 try { 638 spCall.setString(1, columnName); 639 640 ResultSet rssp = spCall.executeQuery(); 641 642 switch (dbms) { 643 case DBMS_MYSQL: 644 isAutoIncColumn = (rssp.next() 645 && rssp.getString(1) 646 .equalsIgnoreCase(columnName) 647 && rssp.getString(6) 648 .equalsIgnoreCase("auto_increment")); 649 650 break; 651 652 case DBMS_IBMDB2: 653 isAutoIncColumn = (rssp.next() 654 && rssp.getString(1) 655 .equalsIgnoreCase("y")); 656 657 break; 658 } 659 660 rssp.close(); 661 } catch (SQLException ex) { 662 if (autoIncColumnsQueryAlwaysSucceeded) { 666 System.err.println("Warning: Reading of auto-incremented columns \n" 667 + "\n failed with message \n'" 668 + ex.getMessage() 669 + "'.\n No reason to panic, just detection auf auto-incremented \n " 670 + " columns will not work. However, better send a mail to \n" 671 + " DbForms Mailing list to get this corrected"); 672 autoIncColumnsQueryAlwaysSucceeded = false; 673 } 674 } 675 } else { 677 isAutoIncColumn = typeName.toLowerCase() 679 .endsWith(" identity"); 680 } 681 682 if (useStdTypeNames && (!fieldTypeIsKnown(typeName))) { 686 switch (typeCode) { 687 case java.sql.Types.BIGINT: 688 case java.sql.Types.INTEGER: 689 case java.sql.Types.SMALLINT: 690 case java.sql.Types.TINYINT: 691 typeName = "integer"; 692 693 break; 694 695 case java.sql.Types.CHAR: 696 case java.sql.Types.LONGVARCHAR: 697 case java.sql.Types.VARCHAR: 698 typeName = "char"; 699 700 break; 701 702 case java.sql.Types.DECIMAL: 703 typeName = "decimal"; 704 705 break; 706 707 case java.sql.Types.NUMERIC: 708 typeName = "numeric"; 709 710 break; 711 712 case java.sql.Types.FLOAT: 713 typeName = "float"; 714 715 break; 716 717 case java.sql.Types.REAL: 718 typeName = "real"; 719 720 break; 721 722 case java.sql.Types.DATE: 723 typeName = "date"; 724 725 break; 726 727 case java.sql.Types.TIMESTAMP: 728 typeName = "timestamp"; 729 730 break; 731 732 case java.sql.Types.BLOB: 733 typeName = "blob"; 734 735 break; 736 737 default: 738 System.out.println("unknown java.sql.Type '" + typeName 739 + "'"); 740 } 741 } 742 743 result.append("\t\t<field name=\""); 744 result.append(columnName); 745 result.append("\" fieldType=\""); 746 result.append(typeName.toLowerCase()); 747 result.append("\" size=\""); 748 result.append(columnSize); 749 result.append("\""); 750 751 if (keys.contains(columnName)) { 752 result.append(" isKey=\"true\""); 753 } 754 755 if (isAutoIncColumn) { 756 result.append(" autoInc=\"true\""); 757 } 758 759 if (generateDefaultValues && (defaultValue != null)) { 760 result.append(" defaultValue=\"" + defaultValue + "\""); 761 } 762 763 result.append("/>\n"); 764 } 765 766 rsFields.close(); 767 768 if (!useAutoCommitMode) { 769 con.commit(); 770 } 771 772 if (foreignKeyDetectionActivated) { 773 result.append(getForeignKeyTags(forKeys, catalogName, 774 schemaName, tableName)); 775 } 776 777 result.append("\n\t\t<!-- add \"granted-privileges\" element for security constraints -->\n\n\t</table>\n\n"); 778 } 779 780 if (catalogNameFailure > 0) { 781 showWarning = true; 782 warningMessage.append("<li> " + catalogNameFailure 783 + " empty catalog names not " 784 + "included in table name."); 785 } 786 787 if (schemaNameFailure > 0) { 788 showWarning = true; 789 warningMessage.append("<li> " + schemaNameFailure 790 + " empty schema names not " 791 + "included in table name."); 792 } 793 794 result.append("\t<!-- ========== Connection =================================== -->\n"); 795 result.append("\t<!--\n"); 796 result.append("\tuncomment this if you have access to JNDI of an application server (see users guide for more info)\n"); 797 result.append("\t<dbconnection\n"); 798 result.append("\t\tname = \"jdbc/dbformstest\"\n"); 799 result.append("\t\tisJndi = \"true\"\n"); 800 result.append("\t/>\n"); 801 result.append("\t-->\n\n"); 802 803 result.append("\t<dbconnection\n"); 804 result.append("\t\tname = \"" + xmlClean(jdbcURL) + "\"\n"); 805 result.append("\t\tisJndi = \"false\"\n"); 806 result.append("\t\tconClass = \"" + jdbcDriver + "\"\n"); 807 result.append("\t\tusername = \"" + username + "\"\n"); 808 result.append("\t\tpassword = \"" + password + "\"\n"); 809 result.append("\t/>\n"); 810 result.append("</dbforms-config>"); 811 812 System.out.println("finished"); 813 warningMessage.append("</ul></html>"); 814 } catch (Exception e) { 815 e.printStackTrace(); 816 throw new Exception (e.getMessage() + " in XMLConfigGenerator"); 817 } finally { 818 try { 819 if (showWarning) { 820 if (createGuiMessagewindow) { 821 javax.swing.JOptionPane.showMessageDialog(null, 822 warningMessage, 823 "Warning", 824 javax.swing.JOptionPane.WARNING_MESSAGE); 825 } else { 826 System.err.println("Warning:\n " + warningMessage); 827 } 828 } 829 830 if (con != null) { 831 con.close(); 832 } 833 } catch (SQLException sqle) { 834 836 840 } 841 } 842 843 return result.toString(); 844 } 845 846 847 863 protected static Connection createConnection(String jdbcDriver, 864 String jdbcURL, 865 String username, 866 String password) 867 throws SQLException, 868 ClassNotFoundException , 869 InstantiationException , 870 IllegalAccessException { 871 Class.forName(jdbcDriver) 872 .newInstance(); 873 874 return DriverManager.getConnection(jdbcURL, username, password); 875 } 876 877 878 static boolean fieldTypeIsKnown(String s) { 879 int i; 880 881 for (i = 0; i < knownFieldTypes.length; i++) 882 if (s.startsWith(knownFieldTypes[i])) { 883 return true; 884 } 885 886 return false; 887 } 888 889 890 private static void addSingleReference(HashMap hm, 891 ResultSet rsk, 892 Vector knownTables, 893 boolean includeCatalog, 894 String catalogSeparator, 895 boolean includeSchema, 896 String schemaSeparator) 897 throws SQLException { 898 String pCatalog = rsk.getString(1); 899 String pSchema = rsk.getString(2); 900 String pTable = rsk.getString(3); 901 902 if (!knownTables.contains("" + emptyIfNull(pSchema) + "\t" 903 + emptyIfNull(pTable))) { 904 return; 905 } 906 907 String pColName = rsk.getString(4); 908 909 String fSchema = rsk.getString(6); 910 String fTable = rsk.getString(7); 911 912 if (!knownTables.contains("" + emptyIfNull(fSchema) + "\t" 913 + emptyIfNull(fTable))) { 914 return; 915 } 916 917 String fColName = rsk.getString(8); 918 919 String fkName = rsk.getString(12); 920 921 if (fkName == null) { 923 fkName = pCatalog + "::" + pSchema + "::" + pTable; 924 } 925 926 String hashKey = emptyIfNull(fSchema) + "\t" + fTable; 927 928 HashMap tabForKeys = (HashMap) hm.get(hashKey); 930 if (tabForKeys == null) { 931 tabForKeys = new HashMap(); 932 hm.put(hashKey, tabForKeys); 933 } 934 935 ForeignKey fki = (ForeignKey) tabForKeys.get(fkName); 936 937 if (fki == null) { 938 fki = new ForeignKey(); 939 tabForKeys.put(fkName, fki); 940 941 String fullTabName = ""; 942 943 if (includeCatalog) { 944 fullTabName = pCatalog + catalogSeparator; 945 } 946 947 if (includeSchema) { 948 fullTabName += (pSchema + schemaSeparator); 949 } 950 951 fullTabName += pTable; 952 fki.setForeignTable(fullTabName); 953 fki.setName(fkName); 954 } 955 956 fki.addReference(new Reference(fColName, pColName)); 957 } 958 959 960 private static String emptyIfNull(String s) { 961 return (s == null) ? "" 962 : s; 963 } 964 965 966 974 private static String remapType(int dbms, 975 String typeName) { 976 if (dbms == DBMS_MYSQL) { 977 if (typeName.equalsIgnoreCase("longblob")) { 978 typeName = "blob"; 979 } 980 } 981 982 return typeName; 983 } 984 985 986 993 private static String xmlClean(String str) { 994 return str.replaceAll("&", "&"); 995 } 996 } 997 | Popular Tags |