1 23 24 32 package org.enhydra.dods.xslt; 33 34 import java.io.File ; 35 import java.io.FileReader ; 36 import java.io.FileWriter ; 37 import java.text.ParseException ; 38 import java.text.SimpleDateFormat ; 39 import java.util.HashMap ; 40 import java.util.Vector ; 41 import org.apache.xalan.extensions.XSLProcessorContext; 42 import org.apache.xalan.templates.ElemExtensionCall; 43 import org.apache.xml.utils.WrappedRuntimeException; 44 import org.apache.xpath.objects.XString; 45 import org.ejen.util.XSLUtil; 46 import org.enhydra.dods.Common; 47 48 53 public class XSLTUtil { 54 55 public String strVectorValues_1 = new String (); 56 public String strVectorValues_2 = new String (); 57 public String strVectorValues_3 = new String (); 58 public String strVectorValues_4 = new String (); 59 public static String strAttribut_0 = new String (); 60 public static String strAttribut_1 = new String (); 61 public String strAttribut_11 = new String (); 62 public static String strAttribut_2 = new String (); 63 public static String strAttribut_3 = new String (); 64 public static String strAttribut_4 = new String (); 65 public static String strAttribut_5 = new String (); 66 67 public static Vector vecDropPrimaryKey = new Vector (); 68 public static Vector vecDropUnique = new Vector (); 69 public static Vector vecDropIndex = new Vector (); 70 public static Vector vecDropTable = new Vector (); 71 72 public static Vector vecXSLUtil_01 = new Vector (); 73 public static Vector vecXSLUtilDrop_01 = new Vector (); 74 public static Vector vecXSLUtilDrop_11 = new Vector (); 75 public static Vector vecFKcreate_01 = new Vector (); 76 public static Vector vecFKdrop_01 = new Vector (); 77 public static Vector vecXSLUtil_02 = new Vector (); 78 public static Vector vecXSLUtilDrop_02 = new Vector (); 79 public static Vector vecXSLUtilDrop_12 = new Vector (); 80 public static Vector vecFKcreate_02 = new Vector (); 81 public static Vector vecFKdrop_02 = new Vector (); 82 public static Vector vecXSLUtil_11 = new Vector (); 83 public static Vector vecXSLUtil_12 = new Vector (); 84 public static Vector vecXSLUtil_2 = new Vector (); 85 public static Vector vecXSLUtil_3 = new Vector (); 86 public static Vector vecXSLUtil_41 = new Vector (); 87 public static Vector vecXSLUtil_42 = new Vector (); 88 public static Vector vecXSLUtil_5 = new Vector (); 89 public static String strPathProjectRoot = new String (); 90 public static String strPathDomlFile = new String (); 91 public static String strPathDodsConf = new String (); 92 public static String strPathTypesConf = new String (); 93 94 public static String strDatabase = new String (); 95 96 97 private static final int minKeyLength = 4; 98 private static final int maxCounterLength = 3; 99 private static HashMap counterMap = new HashMap (); 100 private static HashMap nameMap = new HashMap (); 101 public static String dbVendorName="Standard"; 102 103 protected XSLTUtil() {} 104 105 112 public static java.util.Date str2date(String s) { 113 String [] formats = { 114 "yyyy-MM-dd H:mm:ss a", "yyyy MM dd H:mm:ss a", "yyyy-MM-dd H:mm:ss", 115 "yyyy MM dd H:mm:ss", "yyyy-MM-dd H:mm a", "yyyy MM dd H:mm a", 116 "yyyy-MM-dd H:mm", "yyyy MM dd H:mm", "yyyy-MM-dd", "yyyy MM dd", 117 "MMM dd yyyy h:mm:ss a", "MMM dd, yyyy h:mm:ss a", 118 "MMM dd yyyy h:mm:ss", "MMM dd, yyyy h:mm:ss", "MMM dd yyyy h:mm a", 119 "MMM dd, yyyy h:mm a", "MMM dd yyyy h:mm", "MMM dd, yyyy h:mm" }; 120 java.util.Date ret = null; 121 122 for (int i = 0; i < formats.length; i++) { 123 SimpleDateFormat df = new SimpleDateFormat (formats[ i ]); 124 125 try { 126 ret = df.parse(s); 127 break; 128 } catch (ParseException e) {} 129 } 130 return ret; 131 } 132 133 142 public static String fixDefault(String type, String value) { 143 if (null == value) { 145 value = ""; 146 } 147 String fixedValue = value; 148 String defaultValue = null; 149 150 if (type.endsWith("DO")) { 151 fixedValue = "null"; 152 } else if (type.equals("String")) { 154 if (fixedValue.length() == 0) { 155 fixedValue = "null"; 156 } else { 157 fixedValue = "\"" + value + "\""; 158 } 159 } else if (type.equals("java.math.BigDecimal")) { 160 if (value.length() == 0) { 161 fixedValue = "null"; 162 } else { 163 try { 164 java.math.BigDecimal test = new java.math.BigDecimal (fixedValue); 165 166 fixedValue = "new " + type + "(" + fixedValue + ")"; 167 } catch (RuntimeException e) { 168 defaultValue = "null"; 169 } 170 } 171 } else if (type.equals("java.sql.Date")) { 172 if (value.length() == 0) { 173 fixedValue = "null"; 174 } else { 175 try { 176 java.util.Date d = str2date(fixedValue); 177 java.sql.Date test = new java.sql.Date (d.getTime()); 178 179 fixedValue = "new " + type + "(" + fixedValue + ")"; 180 } catch (RuntimeException e) { 181 defaultValue = "null"; 182 } 183 } 184 } else if (type.equals("java.sql.Time")) { 185 if (value.length() == 0) { 186 fixedValue = "null"; 187 } else { 188 try { 189 java.util.Date d = str2date(fixedValue); 190 java.sql.Time test = new java.sql.Time (d.getTime()); 191 192 fixedValue = "new " + type + "(" + fixedValue + ")"; 193 } catch (RuntimeException e) { 194 defaultValue = "null"; 195 } 196 } 197 } else if (type.equals("java.sql.Timestamp")) { 198 if (value.length() == 0) { 199 fixedValue = "null"; 200 } else { 201 try { 202 java.util.Date d = str2date(fixedValue); 203 java.sql.Timestamp test = new java.sql.Timestamp (d.getTime()); 204 205 fixedValue = "new " + type + "(" + fixedValue + ")"; 206 } catch (RuntimeException e) { 207 defaultValue = "null"; 208 } 209 } 210 } else if (type.equals("int")) { 211 if (value.length() == 0) { 212 fixedValue = "0"; 213 } else { 214 try { 215 int i = Integer.parseInt(value); 216 } catch (Exception e) { 217 defaultValue = "0"; 218 } 219 } 220 } else if (type.equals("boolean")) { 221 if (value.length() == 0) { 222 fixedValue = "false"; 223 } else { 224 try { 225 if (Boolean.valueOf(value).booleanValue()) { 226 fixedValue = "true"; 227 } else { 228 fixedValue = "false"; 229 } 230 } catch (Exception e) { 231 defaultValue = "false"; 232 } 233 } 234 } else if (type.equals("float")) { 235 if (value.length() == 0) { 236 fixedValue = "0f"; 237 } else { 238 try { 239 Float.valueOf(value); 240 if (!value.endsWith("f")) { 241 fixedValue = value + "f"; 242 } 243 } catch (Exception e) { 244 defaultValue = "0f"; 245 } 246 } 247 } else if (type.equals("byte")) { 248 if (value.length() == 0) { 249 fixedValue = "0"; 250 } else { 251 try { 252 Byte.parseByte(value); 253 } catch (Exception e) { 254 defaultValue = "0"; 255 } 256 } 257 } else if (type.equals("short")) { 258 if (value.length() == 0) { 259 fixedValue = "0"; 260 } else { 261 try { 262 Short.parseShort(value); 263 } catch (Exception e) { 264 defaultValue = "0"; 265 } 266 } 267 } else if (type.equals("long")) { 268 if (value.length() == 0) { 269 fixedValue = "0L"; 270 } else { 271 try { 272 Long.parseLong(value); 273 if (!value.endsWith("L")) { 274 fixedValue = value + "L"; 275 } 276 } catch (Exception e) { 277 defaultValue = "0L"; 278 } 279 } 280 } else if (type.equals("double")) { 281 if (value.length() == 0) { 282 fixedValue = "0d"; 283 } else { 284 try { 285 Double.valueOf(value); 286 if (!value.endsWith("d")) { 287 fixedValue = value + "d"; 288 } 289 } catch (Exception e) { 290 defaultValue = "0d"; 291 } 292 } 293 } else if (type.equals("byte[]")) { 294 try { 295 defaultValue = "{0}"; 297 } catch (RuntimeException e) {} 298 } else { 299 defaultValue = "null"; 300 } 301 if (null != defaultValue) { 302 fixedValue = defaultValue; 303 } 304 return fixedValue; 305 } 306 307 314 static public String adjustJavaType(String type) { 315 if (type.startsWith("root.")) { 316 return type.substring(5); 317 } 318 return type; 319 } 320 321 328 static public String getAdjustedPackageName(String pckg) { 329 if (pckg.startsWith("root.")) { 330 return pckg.substring(5); 331 } 332 return pckg; 333 } 334 335 344 static public String cloneValue(String name, String javaType, String isObjectRef) throws Exception { 345 String type = adjustJavaType(javaType); 353 String retClone = null; 354 String primitiveTypes = ":boolean:char:byte:short:int:long:float:double:"; 355 String timeTypes = ":java.sql.Date:java.sql.Time:java.sql.Timestamp:"; 356 357 if (-1 != primitiveTypes.indexOf(":" + type + ":")) { 358 retClone = name; 359 } else if (-1 != timeTypes.indexOf(":" + type + ":")) { 360 String shortType = type.substring(type.lastIndexOf('.') + 1); 361 362 retClone = "GenericDO.copy" + shortType + "(" + name + ")"; 363 } else if (type.equals("String")) { 364 retClone = "GenericDO.copyString(" + name + ")"; 365 } else if (type.equals("byte[]")) { 366 retClone = "GenericDO.copyByteArray(" + name + ")"; 367 } else if (type.equals("java.math.BigDecimal")) { 368 retClone = "GenericDO.copyBigDecimal(" + name + ")"; 369 } else { 370 if (isObjectRef.equals("true")) { 371 retClone = type + ".createCopy( " + name + " )"; 372 } else { retClone = "(" + type + ") " + name + ".clone()"; 374 } 375 } 376 return retClone; 377 } 378 379 386 static public String capitalizeJavaBasicObject(String type) throws Exception { 387 String javaType = type; 388 String primitiveTypes = ":boolean:char:byte:short:int:long:float:double:"; 389 390 if (-1 != primitiveTypes.indexOf(":" + type + ":")) { 391 javaType = Common.capitalizeName(type); 392 } 393 return javaType; 394 } 395 396 403 static public String javaType(String type) { 404 String jt = type.replace('.', '_'); 405 406 return convertArrayType(jt); 407 } 408 409 416 static public String jdbcType(String javaType) { 417 String type = javaType; 418 int dot = type.lastIndexOf('.'); 419 420 if (-1 != dot) { 421 type = type.substring(dot + 1); 422 } 423 String firstChar = type.substring(0, 1).toUpperCase(); 424 425 return convertArrayType(firstChar + type.substring(1)); 426 } 427 428 435 static public String convertArrayType(String type) { 436 String at = type; 437 int i = type.indexOf("[]"); 438 439 if (-1 != i) { 440 at = type.substring(0, i) + "s"; 441 } 442 return at; 443 } 444 445 453 static public void createVector(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 454 vecDropPrimaryKey.clear(); vecDropUnique.clear(); vecDropIndex.clear(); vecDropTable.clear(); vecFKcreate_01.clear(); vecFKcreate_02.clear(); vecFKdrop_01.clear(); vecFKdrop_02.clear(); vecXSLUtil_01.clear(); vecXSLUtil_02.clear(); vecXSLUtilDrop_01.clear(); vecXSLUtilDrop_11.clear(); vecXSLUtilDrop_02.clear(); vecXSLUtilDrop_12.clear(); vecXSLUtil_11.clear(); vecXSLUtil_12.clear(); vecXSLUtil_2.clear(); vecXSLUtil_3.clear(); vecXSLUtil_41.clear(); vecXSLUtil_42.clear(); vecXSLUtil_5.clear(); } 502 503 511 static public void resetCreateVectors(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 512 vecFKcreate_01.clear(); vecFKcreate_02.clear(); vecXSLUtil_01.clear(); vecXSLUtil_02.clear(); vecXSLUtil_11.clear(); vecXSLUtil_12.clear(); vecXSLUtil_2.clear(); vecXSLUtil_3.clear(); vecXSLUtil_41.clear(); vecXSLUtil_42.clear(); vecXSLUtil_5.clear(); } 545 546 555 static public void fillVector(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 556 Object obj0 = null; 557 Object obj1 = null; 558 Object obj2 = null; 559 Object obj3 = null; 560 Object obj4 = null; 561 Object obj5 = null; 562 String s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 563 "attribut0", false); 564 String s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 565 "attribut1", false); 566 String s2 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 567 "attribut2", false); 568 String s3 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 569 "attribut3", false); 570 String s4 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 571 "attribut4", false); 572 String s5 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 573 "attribut5", false); 574 int i = 0; 575 String strTemp = new String (); 576 577 obj5 = new XString(""); 578 if (s5 != null) { 579 obj5 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s5); 580 if (obj5 != null) { 581 String s51 = XSLUtil.getAttribute(xslprocessorcontext, 582 elemextensioncall, "attribute5", false); 583 584 if (s51 != null) { 585 obj5 = new XString(s51); 586 } 587 } 588 } 589 590 if (s0 != null) { 591 obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0); 592 if (obj0 == null) { 593 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 594 } 595 } else { 596 String s01 = XSLUtil.getAttribute(xslprocessorcontext, 597 elemextensioncall, "attribute0", false); 598 599 if (s01 != null) { 600 obj0 = new XString(s01); 601 } 602 } 603 if (obj0 == null) { 604 obj0 = new XString("(no value)"); 605 } 606 607 if (s1 != null) { 608 obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1); 609 if (obj1 == null) { 610 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 611 } 612 } else { 613 String s11 = XSLUtil.getAttribute(xslprocessorcontext, 614 elemextensioncall, "attribute1", false); 615 616 if (s11 != null) { 617 obj1 = new XString(s11); 618 } 619 } 620 if (obj1 == null) { 621 obj1 = new XString("(no value)"); 622 } 623 if (s2 != null) { 624 obj2 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s2); 625 if (obj2 == null) { 626 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 627 } 628 } else { 629 String s21 = XSLUtil.getAttribute(xslprocessorcontext, 630 elemextensioncall, "attribute2", false); 631 632 if (s21 != null) { 633 obj2 = new XString(s21); 634 } 635 } 636 if (obj2 == null) { 637 obj2 = new XString("(no value)"); 638 } 639 if (s3 != null) { 640 obj3 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s3); 641 if (obj3 == null) { 642 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 643 } 644 } else { 645 String s31 = XSLUtil.getAttribute(xslprocessorcontext, 646 elemextensioncall, "attribute3", false); 647 648 if (s31 != null) { 649 obj3 = new XString(s31); 650 } 651 } 652 if (obj3 == null) { 653 obj3 = new XString("(no value)"); 654 } 655 if (s4 != null) { 656 obj4 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s4); 657 if (obj4 == null) { 658 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 659 } 660 } else { 661 String s41 = XSLUtil.getAttribute(xslprocessorcontext, 662 elemextensioncall, "attribute4", false); 663 664 if (s41 != null) { 665 obj4 = new XString(s41); 666 } 667 } 668 if (obj4 == null) { 669 obj4 = new XString("(no value)"); 670 } else { 671 strAttribut_0 = obj0.toString(); strAttribut_1 = obj1.toString(); strAttribut_2 = obj2.toString(); strAttribut_3 = obj3.toString(); strAttribut_4 = obj4.toString(); strAttribut_5 = obj5.toString(); 678 if (strAttribut_3.length() == 0) { 679 if (strAttribut_5.equalsIgnoreCase("")) { 680 strAttribut_3 = getDodsProperty("OidDbColumnName"); 681 } else { 682 strAttribut_3 = getDodsProperty("OidDbColumnName", 683 strAttribut_5); 684 } 685 } 686 if (strAttribut_2.length() != 0 && strAttribut_4.length() == 0) { 687 vecXSLUtil_01.addElement(strAttribut_0); 688 vecXSLUtil_11.addElement(strAttribut_1); 689 vecXSLUtilDrop_01.addElement(strAttribut_0); 690 vecXSLUtilDrop_11.addElement(strAttribut_1); 691 vecXSLUtil_2.addElement(strAttribut_2); 692 vecXSLUtil_41.addElement(strAttribut_3); 693 } 694 if (strAttribut_2.length() != 0 && strAttribut_4.length() != 0) { 695 if (!vecXSLUtil_5.contains(strAttribut_4)) { 696 vecXSLUtil_02.addElement(strAttribut_0); 697 vecXSLUtilDrop_02.addElement(strAttribut_0); 698 vecXSLUtilDrop_12.addElement(strAttribut_1); 699 vecXSLUtil_12.addElement(strAttribut_1); 700 vecXSLUtil_3.addElement(strAttribut_2); 701 vecXSLUtil_42.addElement(strAttribut_3); 702 vecXSLUtil_5.addElement(strAttribut_4); 703 } else { 704 i = vecXSLUtil_5.indexOf(strAttribut_4); 705 strTemp = vecXSLUtil_12.elementAt(i).toString(); 706 strTemp = strTemp + ", " + strAttribut_1; 707 vecXSLUtil_12.setElementAt(strTemp, i); 708 strTemp = vecXSLUtil_42.elementAt(i).toString(); 709 strTemp = strTemp + ", " + strAttribut_3; 710 vecXSLUtil_42.setElementAt(strTemp, i); 711 } 712 } 713 } 714 } 715 716 724 static public void fillVecDropPrimaryKey(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 725 726 Object obj0 = null; 727 Object obj1 = null; 728 Object obj2 = null; 729 730 String s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 731 "tableName", false); 732 String s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 733 "vendorName", false); 734 735 String s2 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 736 "columnName", false); 737 738 if (s2 != null) { 739 obj2 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s2); 740 if (obj2 == null) { 741 throw new WrappedRuntimeException(new IllegalArgumentException ("bad database vendor attribute ?!")); 742 } 743 } 744 if (obj2 == null) { 745 obj2 = new XString("(no value)"); 746 } 747 748 749 750 if (s1 != null) { 751 obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1); 752 if (obj1 == null) { 753 throw new WrappedRuntimeException(new IllegalArgumentException ("bad database vendor attribute ?!")); 754 } 755 } 756 if (obj1 == null) { 757 obj1 = new XString("Standard"); 758 } 759 760 761 762 if (s0 != null) { 763 obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0); 764 if (obj0 == null) { 765 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 766 } 767 } 768 if (obj0 == null) { 769 obj0 = new XString("(no value)"); 770 } else { 771 String strTableName = obj0.toString(); 772 String strVendorName= obj1.toString(); 773 String strColumnName= obj2.toString(); 774 String strTmp = "ALTER TABLE " + strTableName 775 + " DROP CONSTRAINT " + returnFixedConstraintName(strTableName, strColumnName , "DROP", "PK", strTableName,strColumnName ,strVendorName)+ " ;"; 776 vecDropPrimaryKey.addElement(strTmp); 777 } 778 } 779 780 788 static public void fillVecDropUnique(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 789 Object obj0 = null; 790 Object obj1 = null; 791 Object obj2 = null; 792 793 String s2 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 794 "columnName", false); 795 796 797 String s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 798 "tableName", false); 799 800 String s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 801 "vendorName", false); 802 803 if (s2 != null) { 804 obj2 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s2); 805 if (obj2 == null) { 806 throw new WrappedRuntimeException(new IllegalArgumentException ("bad database vendor attribute ?!")); 807 } 808 } 809 if (obj2 == null) { 810 obj2 = new XString("(no value)"); 811 } 812 813 if (s1 != null) { 814 obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1); 815 if (obj1 == null) { 816 throw new WrappedRuntimeException(new IllegalArgumentException ("bad database vendor attribute ?!")); 817 } 818 } 819 if (obj1 == null) { 820 obj1 = new XString("Standard"); 821 } 822 823 if (s0 != null) { 824 obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0); 825 if (obj0 == null) { 826 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 827 } 828 } 829 if (obj0 == null) { 830 obj0 = new XString("(no value)"); 831 } else { 832 String strTableName = obj0.toString(); 833 String strVendorName = obj1.toString(); 834 String strColumnName = obj2.toString(); 835 String strTmp = "ALTER TABLE " + strTableName 836 + " DROP CONSTRAINT " + returnFixedConstraintName(strTableName , strColumnName, "DROP", "U", strTableName , strColumnName, strVendorName)+ " ;"; 837 vecDropUnique.addElement(strTmp); 838 } 839 } 840 841 849 static public void fillVecDropIndex(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 850 Object obj0 = null; 851 Object obj1 = null; 852 Object obj2 = null; 853 854 String s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 855 "tableName", false); 856 String s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 857 "indexName", false); 858 String s2 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 859 "vendorName", false); 860 861 if (s2 != null) { 862 obj2 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s2); 863 if (obj2 == null) { 864 throw new WrappedRuntimeException(new IllegalArgumentException ("bad database vendor attribute ?!")); 865 } 866 } 867 if (obj2 == null) { 868 obj2 = new XString("Standard"); 869 } 870 871 if (s0 != null) { 872 obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0); 873 if (obj0 == null) { 874 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 875 } 876 } 877 if (obj0 == null) { 878 obj0 = new XString("(no value)"); 879 } 880 881 if (s1 != null) { 882 obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1); 883 if (obj1 == null) { 884 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 885 } 886 } 887 if (obj1 == null) { 888 obj1 = new XString("(no value)"); 889 } else { 890 String strTableName = obj0.toString(); 891 String strIndexName = obj1.toString(); 892 String strVendorName = obj2.toString(); 893 String strTmp = "DROP INDEX " + returnFixedConstraintName(strTableName, strIndexName ,"DROP", "I", strTableName, strIndexName , strVendorName)+ " ;"; 894 895 vecDropIndex.addElement(strTmp); 896 } 897 } 898 899 907 static public void fillVecDropTable(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 908 Object obj0 = null; 909 String s0 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 910 "tableName", false); 911 912 if (s0 != null) { 913 obj0 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s0); 914 if (obj0 == null) { 915 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 916 } 917 } 918 if (obj0 == null) { 919 obj0 = new XString("(no value)"); 920 } else { 921 String strTmp = "DROP TABLE " + obj0.toString() + " ;"; 922 923 vecDropTable.addElement(strTmp); 924 } 925 } 926 927 934 static public String returnForeignKeyConstraints(String dbVendor) throws Exception { 935 String strTemp11 = new String (); 936 String strTemp41 = new String (); 937 String strTemp = ""; 938 boolean delCascade = Common.getDodsConfProperty("DeleteCascade", dbVendor).equalsIgnoreCase("true"); 939 String keyLengthStr = Common.getDodsConfProperty("ConstraintNameLength", dbVendor); 940 String tempName = null; 941 int keyLength = -1; 942 if (keyLengthStr!=null){ 943 keyLength = new Integer (keyLengthStr).intValue(); 944 } 945 int i = 0; 946 int j = 0; 947 948 if (vecXSLUtil_01.size() > 0) { 951 i = 0; 952 tempName = returnFixedConstraintName(vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),"CREATE","FK",vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),dbVendor); 955 strTemp = " CONSTRAINT " + tempName 959 + " FOREIGN KEY (" + vecXSLUtil_11.elementAt(i).toString() 960 + ") REFERENCES " + vecXSLUtil_2.get(i).toString() + " (" 961 + vecXSLUtil_41.get(i).toString() + ")"; 962 if (delCascade) { 963 strTemp = strTemp + " ON DELETE CASCADE ,\n"; 964 } else { 965 strTemp = strTemp + " ,\n"; 966 } 967 vecFKcreate_01.addElement(strTemp); 968 i = 1; 969 j = 2; 970 while (i < vecXSLUtil_01.size()) { 971 strTemp = vecXSLUtil_01.elementAt(i - 1).toString(); 972 if (strTemp.equals(vecXSLUtil_01.elementAt(i).toString())) { 973 tempName = returnFixedConstraintName(vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),"CREATE","FK",vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),dbVendor); 976 977 strTemp = " CONSTRAINT " + tempName 981 + " FOREIGN KEY (" 982 + vecXSLUtil_11.elementAt(i).toString() 983 + ") REFERENCES " + vecXSLUtil_2.get(i).toString() 984 + " (" + vecXSLUtil_41.get(i).toString() + ")"; 985 if (delCascade) { 986 strTemp = strTemp + " ON DELETE CASCADE ,\n"; 987 } else { 988 strTemp = strTemp + " ,\n"; 989 } 990 vecFKcreate_01.addElement(strTemp); 991 } else { 992 j = 1; 993 tempName = returnFixedConstraintName(vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),"CREATE","FK",vecXSLUtil_01.elementAt(i).toString(),vecXSLUtil_11.elementAt(i).toString(),dbVendor); 994 995 strTemp = " CONSTRAINT " + tempName 996 + " FOREIGN KEY (" 997 + vecXSLUtil_11.elementAt(i).toString() 998 + ") REFERENCES " + vecXSLUtil_2.get(i).toString() 999 + " (" + vecXSLUtil_41.get(i).toString() + ")"; 1000 if (delCascade) { 1001 strTemp = strTemp + " ON DELETE CASCADE ,\n"; 1002 } else { 1003 strTemp = strTemp + " ,\n"; 1004 } 1005 vecFKcreate_01.addElement(strTemp); 1006 } 1007 j++; 1008 i++; 1009 } } if (vecXSLUtil_02.size() > 0) { 1015 i = 0; 1016 tempName = returnFixedConstraintName("FKG", vecXSLUtil_02.elementAt(i).toString(),"CREATE","FKG","FKG", vecXSLUtil_02.elementAt(i).toString(),dbVendor); 1021 1022 strTemp = " CONSTRAINT " 1023 + tempName 1024 + " FOREIGN KEY (" + vecXSLUtil_12.elementAt(i).toString() 1025 + ") REFERENCES " + vecXSLUtil_3.get(i).toString() + " (" 1026 + vecXSLUtil_42.get(i).toString() + ")"; 1027 if (delCascade) { 1028 strTemp = strTemp + " ON DELETE CASCADE ,\n"; 1029 } else { 1030 strTemp = strTemp + " ,\n"; 1031 } 1032 vecFKcreate_02.addElement(strTemp); 1033 i = 1; 1034 j = 2; 1035 while (i < vecXSLUtil_02.size()) { 1036 strTemp = vecXSLUtil_02.elementAt(i - 1).toString(); 1037 if (strTemp.equals(vecXSLUtil_02.elementAt(i).toString())) { 1038 tempName = returnFixedConstraintName("FKG", vecXSLUtil_02.elementAt(i).toString(),"CREATE","FKG","FKG", vecXSLUtil_02.elementAt(i).toString(),dbVendor); 1043 1044 strTemp = " CONSTRAINT " 1045 + tempName 1046 + " FOREIGN KEY (" 1047 + vecXSLUtil_12.elementAt(i).toString() 1048 + ") REFERENCES " + vecXSLUtil_3.get(i).toString() 1049 + " (" + vecXSLUtil_42.get(i).toString() + ")"; 1050 if (delCascade) { 1051 strTemp = strTemp + " ON DELETE CASCADE ,\n"; 1052 } else { 1053 strTemp = strTemp + " ,\n"; 1054 } 1055 vecFKcreate_02.addElement(strTemp); 1056 } else { 1057 j = 1; 1058 tempName = returnFixedConstraintName("FKG", vecXSLUtil_02.elementAt(i).toString(),"CREATE","FKG","FKG", vecXSLUtil_02.elementAt(i).toString(),dbVendor); 1063 1064 strTemp = " CONSTRAINT " 1065 + tempName + "_" + j 1066 + " FOREIGN KEY (" 1067 + vecXSLUtil_12.elementAt(i).toString() 1068 + ") REFERENCES " + vecXSLUtil_3.get(i).toString() 1069 + " (" + vecXSLUtil_42.get(i).toString() + ")"; 1070 if (delCascade) { 1071 strTemp = strTemp + " ON DELETE CASCADE ,\n"; 1072 } else { 1073 strTemp = strTemp + " ,\n"; 1074 } 1075 vecFKcreate_02.addElement(strTemp); 1076 } 1077 j++; 1078 i++; 1079 } } int i_fk = vecFKcreate_01.size(); 1082 int i_fkg = vecFKcreate_02.size(); 1083 1084 strTemp = ""; 1085 if (i_fk != 0) { 1086 i = 0; 1087 while (i < i_fk) { 1088 strTemp = strTemp + vecFKcreate_01.elementAt(i).toString(); 1089 i++; 1090 } 1091 } 1092 1093 if (i_fkg != 0) { 1094 i = 0; 1095 while (i < i_fkg) { 1096 strTemp = strTemp + vecFKcreate_02.elementAt(i).toString(); 1097 i++; 1098 } 1099 } 1100 1101 if (strTemp.length() != 0) { 1102 strTemp = strTemp.substring(0, strTemp.length() - 3); 1103 } 1104 return strTemp; 1105 } 1106 1107 1230 1239 static public void createSQLdrop(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 1240 String strTmp = new String (); 1241 String strTemp = new String (); 1242 String strProjectRoot = Common.getProjectRoot(); 1243 String strFileSep = System.getProperty("file.separator"); 1244 String strSqlDrop = new String (); 1245 1246 strSqlDrop = strProjectRoot + strFileSep + "SQLdrop.sql"; 1247 File fileSqlDrop = new File (strSqlDrop); 1248 1249 if (fileSqlDrop.exists()) { 1250 fileSqlDrop.delete(); 1251 } 1252 fileSqlDrop.createNewFile(); 1253 FileReader fileRead; 1254 FileWriter fileWrite = new FileWriter (fileSqlDrop); 1255 int i = 0; 1256 int j = 0; 1257 1258 if (vecXSLUtilDrop_01.size() > 0) { 1261 i = 0; 1262 strTemp = vecXSLUtilDrop_01.elementAt(i).toString(); 1263 strTemp = returnFixedConstraintName(vecXSLUtilDrop_01.elementAt(i).toString(),vecXSLUtilDrop_11.elementAt(i).toString(),"DROP","FK",vecXSLUtilDrop_01.elementAt(i).toString(),vecXSLUtilDrop_11.elementAt(i).toString(),dbVendorName); 1264 1265 vecFKdrop_01.addElement(strTemp); 1266 i = 1; 1267 j = 2; 1268 while (i < vecXSLUtilDrop_01.size()) { 1269 strTemp = vecXSLUtilDrop_01.elementAt(i - 1).toString(); 1270 if (strTemp.equals(vecXSLUtilDrop_01.elementAt(i).toString())) { 1271 strTemp = vecXSLUtilDrop_01.elementAt(i).toString(); 1272 strTemp = returnFixedConstraintName(strTemp,vecXSLUtilDrop_11.elementAt(i).toString(),"DROP","FK",strTemp,vecXSLUtilDrop_11.elementAt(i).toString(),dbVendorName); 1273 vecFKdrop_01.addElement(strTemp); 1274 } else { 1275 j = 1; 1276 strTemp = vecXSLUtilDrop_01.elementAt(i).toString(); 1277 strTemp = returnFixedConstraintName(strTemp,vecXSLUtilDrop_11.elementAt(i).toString(),"DROP","FK",strTemp,vecXSLUtilDrop_11.elementAt(i).toString(),dbVendorName); 1278 vecFKdrop_01.addElement(strTemp); 1279 } 1280 j++; 1281 i++; 1282 } } if (vecXSLUtilDrop_02.size() > 0) { 1288 i = 0; 1289 strTemp = vecXSLUtilDrop_02.elementAt(i).toString() + "_1"; 1290 vecFKdrop_02.addElement(strTemp); 1291 i = 1; 1292 j = 2; 1293 while (i < vecXSLUtilDrop_02.size()) { 1294 strTemp = vecXSLUtilDrop_02.elementAt(i - 1).toString(); 1295 if (strTemp.equals(vecXSLUtilDrop_02.elementAt(i).toString())) { 1296 strTemp = vecXSLUtilDrop_02.elementAt(i).toString(); 1297 strTemp = returnFixedConstraintName(strTemp,vecXSLUtilDrop_12.elementAt(i).toString(),"DROP","FKG",strTemp,vecXSLUtilDrop_12.elementAt(i).toString(),dbVendorName); 1298 vecFKdrop_02.addElement(strTemp); 1299 } else { 1300 j = 1; 1301 strTemp = vecXSLUtilDrop_02.elementAt(i).toString(); 1302 strTemp = returnFixedConstraintName(strTemp,vecXSLUtilDrop_12.elementAt(i).toString(),"DROP","FKG",strTemp,vecXSLUtilDrop_12.elementAt(i).toString(),dbVendorName); 1303 vecFKdrop_02.addElement(strTemp); 1304 } 1305 j++; 1306 i++; 1307 } } i = 0; 1311 if (vecXSLUtilDrop_01.size() != 0) { 1312 while (i < vecXSLUtilDrop_01.size()) { 1313 StringBuffer buf = new StringBuffer (); 1314 1315 buf.append("ALTER TABLE "); 1316 buf.append(vecXSLUtilDrop_01.elementAt(i).toString()); 1317 buf.append(" DROP CONSTRAINT "); 1318 buf.append(vecFKdrop_01.get(i).toString()); 1319 buf.append(" ;"); 1320 fileWrite.write(buf.toString()); 1321 fileWrite.write(13); 1322 fileWrite.write(10); i++; 1324 } 1325 fileWrite.write(13); 1326 fileWrite.write(10); } 1328 i = 0; 1330 if (vecXSLUtilDrop_02.size() != 0) { 1331 while (i < vecXSLUtilDrop_02.size()) { 1332 StringBuffer buf = new StringBuffer (); 1333 1334 buf.append("ALTER TABLE "); 1335 buf.append(vecXSLUtilDrop_02.elementAt(i).toString()); 1336 buf.append(" DROP CONSTRAINT "); 1337 buf.append(vecFKdrop_02.get(i).toString()); 1338 buf.append(" ;"); 1339 fileWrite.write(buf.toString()); 1340 fileWrite.write(13); 1341 fileWrite.write(10); i++; 1343 } 1344 fileWrite.write(13); 1345 fileWrite.write(10); } 1347 i = 0; 1349 if (vecDropUnique.size() != 0) { 1350 while (i < vecDropUnique.size()) { 1351 StringBuffer buf = new StringBuffer (); 1352 1353 buf.append(vecDropUnique.elementAt(i).toString()); 1354 fileWrite.write(buf.toString()); 1355 fileWrite.write(13); 1356 fileWrite.write(10); i++; 1358 } 1359 fileWrite.write(13); 1360 fileWrite.write(10); } 1362 i = 0; 1364 if (vecDropIndex.size() != 0) { 1365 while (i < vecDropIndex.size()) { 1366 StringBuffer buf = new StringBuffer (); 1367 1368 buf.append(vecDropIndex.elementAt(i).toString()); 1369 fileWrite.write(buf.toString()); 1370 fileWrite.write(13); 1371 fileWrite.write(10); i++; 1373 } 1374 fileWrite.write(13); 1375 fileWrite.write(10); } 1377 i = 0; 1379 if (vecDropTable.size() != 0) { 1380 while (i < vecDropTable.size()) { 1381 StringBuffer buf = new StringBuffer (); 1382 1383 buf.append(vecDropTable.elementAt(i).toString()); 1384 fileWrite.write(buf.toString()); 1385 fileWrite.write(13); 1386 fileWrite.write(10); i++; 1388 } 1389 fileWrite.write(13); 1390 fileWrite.write(10); fileWrite.write("DROP TABLE objectid ;"); 1392 fileWrite.write(13); 1393 fileWrite.write(10); } 1395 fileWrite.close(); 1396 } 1397 1398 1406 public static void fillHashtables(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 1407 Object obj1 = null; 1408 String s1 = XSLUtil.getAttribute(xslprocessorcontext, elemextensioncall, 1409 "database", false); 1410 1411 if (s1 != null) { 1412 obj1 = XSLUtil.evaluate(xslprocessorcontext, elemextensioncall, s1); 1413 if (obj1 == null) { 1414 throw new WrappedRuntimeException(new IllegalArgumentException ("bad \"select\" attribute ?!")); 1415 } 1416 } 1417 strDatabase = obj1.toString(); 1418 } 1419 1420 1428 public static void fillHashtables(String strUsedDatabase, String s2) throws Exception { 1429 strDatabase = strUsedDatabase; 1430 1431 } 1432 1433 1442 public static String getDodsProperty(String strKey, String dbVendor) throws Exception { 1443 String strTemp; 1444 1445 if (dbVendor != null) { 1446 strTemp = Common.getDodsConfProperty(strKey, dbVendor); 1447 } else { 1448 strTemp = Common.getDodsConfProperty(strKey, strDatabase); 1449 } 1450 return strTemp; 1451 } 1452 1453 1460 public static String getDodsProperty(String strKey) throws Exception { 1461 String strTemp = Common.getDodsConfProperty(strKey, strDatabase); 1462 1463 return strTemp; 1464 } 1465 1466 1473 public static String getDataType(String strKey) throws Exception { 1474 String strDataType = "JDBCtype/" + strKey; 1475 1476 strDataType = getDodsProperty(strDataType); 1477 return strDataType; 1478 } 1479 1480 1487 public static String getDataType(String strKey, String dbVendor) throws Exception { 1488 String strDataType = "JDBCtype/" + strKey; 1489 1490 strDataType = getDodsProperty(strDataType, dbVendor); 1491 return strDataType; 1492 } 1493 1494 1503 public static void createSQLcomplete(XSLProcessorContext xslprocessorcontext, ElemExtensionCall elemextensioncall) throws Exception { 1504 String strProjectRoot = Common.getProjectRoot(); 1505 Vector vecUrlOfSqlFiles = new Vector (); 1506 1507 vecUrlOfSqlFiles = findSQLFiles(new File (strProjectRoot)); 1508 String strUrlOfSqlFile; 1509 String strFileSep = System.getProperty("file.separator"); 1510 String strSqlDrop = new String (); 1511 1512 strSqlDrop = strProjectRoot + strFileSep + "SQLdrop.sql"; 1513 strSqlDrop = strSqlDrop.replace('/', '\\'); 1514 strSqlDrop = strSqlDrop.replace('\\', '/'); 1515 if (System.getProperty("os.name").toLowerCase().startsWith("win")) { 1516 if (strFileSep != "/") { 1517 strSqlDrop = strSqlDrop.replace('/', '\\'); 1518 } 1519 } 1520 String strSqlComplete = new String (); 1521 1522 strSqlComplete = strProjectRoot + strFileSep + "SQLcreate.sql"; 1523 strSqlComplete = strSqlComplete.replace('/', '\\'); 1524 strSqlComplete = strSqlComplete.replace('\\', '/'); 1525 if (System.getProperty("os.name").toLowerCase().startsWith("win")) { 1526 if (strFileSep != "/") { 1527 strSqlComplete = strSqlComplete.replace('/', '\\'); 1528 } 1529 } 1530 File fileSqlComplete = new File (strSqlComplete); 1531 1532 if (fileSqlComplete.exists()) { 1533 fileSqlComplete.delete(); 1534 } 1535 fileSqlComplete.createNewFile(); 1536 FileReader fileRead; 1537 FileWriter fileWrite = new FileWriter (fileSqlComplete); 1538 int i = 0; 1539 int ii; 1540 1541 while (i < vecUrlOfSqlFiles.size()) { 1542 strUrlOfSqlFile = vecUrlOfSqlFiles.get(i).toString(); 1543 if (!strUrlOfSqlFile.equalsIgnoreCase(strSqlDrop) 1544 && !strUrlOfSqlFile.equalsIgnoreCase(strSqlComplete)) { 1545 fileRead = new FileReader (strUrlOfSqlFile); 1546 ii = fileRead.read(); 1547 while (ii != -1) { 1548 fileWrite.write(ii); 1549 ii = fileRead.read(); 1550 } 1551 fileRead.close(); 1552 } 1553 i++; 1554 } 1555 fileWrite.write(13); 1556 fileWrite.write(10); fileWrite.write(13); 1558 fileWrite.write(10); fileWrite.write(13); 1560 fileWrite.write(10); fileWrite.write("create table objectid"); 1562 fileWrite.write(13); 1563 fileWrite.write(10); fileWrite.write("("); 1565 fileWrite.write(13); 1566 fileWrite.write(10); fileWrite.write(" next " + getDodsProperty("OidDbType") 1568 + " NOT NULL PRIMARY KEY"); 1569 fileWrite.write(13); 1570 fileWrite.write(10); fileWrite.write(");"); 1572 fileWrite.write(13); 1573 fileWrite.write(10); fileWrite.close(); 1575 } 1576 1577 1588 public static Vector findSQLFiles(File fDirectory) { 1589 Vector vPathDirectory = new Vector (); 1590 File [] arrFileSql; 1591 1592 try { 1593 if ((arrFileSql = fDirectory.listFiles()) != null) { 1594 int i = 0; 1595 1596 while (i < arrFileSql.length) { 1597 if (arrFileSql[i].isDirectory()) { 1598 Vector vTemp = findSQLFiles(arrFileSql[i]); 1599 1600 for (int j = 0; j < vTemp.size(); j++) { 1601 vPathDirectory.addElement(vTemp.get(j)); 1602 } 1603 } else if (arrFileSql[i].toString().toUpperCase().indexOf(".SQL") 1604 != -1) { 1605 vPathDirectory.addElement(arrFileSql[i]); 1606 } 1607 i++; 1608 } 1609 } else { 1610 System.out.println("Directory " + fDirectory.toString() 1611 + " doesn't exist"); 1612 } 1613 } catch (Exception se) { 1614 System.out.println("error " + se.getMessage()); 1615 } 1616 return vPathDirectory; 1617 } 1618 1619 1628 public static String fixDefaultSQL(String type, String value) { 1629 if (null == value) { 1630 value = ""; 1631 } 1632 String fixedValue = value; 1633 String defaultValue = ""; 1634 1635 if (type.equals("DECIMAL") || type.equals("NUMERIC")) { 1636 if (value.length() == 0) { 1637 fixedValue = "0.0"; 1638 } else { 1639 try { 1640 java.math.BigDecimal test = new java.math.BigDecimal (fixedValue); 1641 } catch (RuntimeException e) { 1642 defaultValue = "0.0"; 1643 } 1644 } 1645 } else if (type.equals("INTEGER") || type.equals("tinyint") 1646 || type.equals("TINYINT") || type.equals("smallint") 1647 || type.equals("SMALLINT") || type.equals("INT4") 1648 || type.equals("INT8") || type.equals("MEDIUMINT")) { 1649 if (value.length() == 0) { 1650 fixedValue = "0"; 1651 } else { 1652 try { 1653 Integer.parseInt(value); 1654 } catch (Exception e) { 1655 defaultValue = "0"; 1656 } 1657 } 1658 } else if (type.equals("REAL") || type.equals("FLOAT")) { 1659 if (value.length() == 0) { 1660 fixedValue = "0.0"; 1661 } else { 1662 try { 1663 Float.valueOf(value); 1664 } catch (Exception e) { 1665 defaultValue = "0.0"; 1666 } 1667 } 1668 } else if (type.equals("BIGINT")) { 1669 if (value.length() == 0) { 1670 fixedValue = "0"; 1671 } else { 1672 try { 1673 Long.parseLong(value); 1674 } catch (Exception e) { 1675 defaultValue = "0"; 1676 } 1677 } 1678 } else if (type.equals("DOUBLE")) { 1679 if (value.length() == 0) { 1680 fixedValue = "0.0"; 1681 } else { 1682 try { 1683 Double.valueOf(value); 1684 } catch (Exception e) { 1685 defaultValue = "0.0"; 1686 } 1687 } 1688 } else { 1689 defaultValue = "0"; 1690 } 1691 1692 if ("" != defaultValue) { 1693 fixedValue = defaultValue; 1694 } 1695 1696 return fixedValue; 1697 } 1698 1699 static public String returnFixedConstraintName(String namePrefix, String nameSufix ,String operation ,String counterType, String counterKeyPrefix , String counterKey, String dbVendor ){ 1700 1703 if(dbVendor!="" && (!dbVendorName.equalsIgnoreCase(dbVendor))){ 1704 dbVendorName=dbVendor; 1705 } 1706 Integer keyLength=null; 1707 String result=""; 1708 if(namePrefix.equalsIgnoreCase("")||nameSufix.equalsIgnoreCase("")){ 1709 result=namePrefix+nameSufix; 1710 }else{ 1711 result=namePrefix+"_"+nameSufix; 1712 } 1713 1714 String keyLengthStr = Common.getDodsConfProperty("ConstraintNameLength", dbVendorName); 1715 if (keyLengthStr!=null){ 1716 try { 1717 keyLength = new Integer (keyLengthStr); 1718 } catch (NumberFormatException e) {} 1719 } 1720 String counterMapKey; 1721 if (counterType.equalsIgnoreCase("PK") || counterType.equalsIgnoreCase("PKG")){ 1722 counterMapKey=counterType+":://"; }else if(counterType.equalsIgnoreCase("I")){ 1724 counterMapKey=counterType+":://"; 1725 }else{ 1726 counterMapKey=counterType+":://"; } 1728 String nameMapKey=counterType+counterKeyPrefix+counterKey; 1729 int counter = 0; 1730 if (operation.equalsIgnoreCase("CREATE")){ 1731 boolean cuted=false; 1732 if (keyLength!=null && keyLength.intValue()>=minKeyLength && result.length()>keyLength.intValue()){ 1733 result=result.substring(0,keyLength.intValue()-maxCounterLength-1); 1734 counterMapKey=counterMapKey+":///"+result; 1735 if (!counterMap.containsKey(counterMapKey)){ 1736 counter = 1; 1737 }else{ 1738 counter = ((Integer )counterMap.get(counterMapKey)).intValue()+1; 1739 } 1740 counterMap.put(counterMapKey,new Integer (counter)); 1741 1742 cuted=true; 1743 } 1744 if( cuted || counterType.equalsIgnoreCase("FKG")){ 1745 result=result+"_"+counter; 1746 } 1747 nameMap.put(nameMapKey,result); 1748 }else if (operation.equalsIgnoreCase("DROP")){ 1749 result=(String )nameMap.get(nameMapKey); 1750 if (result==null){ 1751 } 1752 } 1753 return result; 1754 } 1755} 1756 | Popular Tags |