1 16 package org.apache.juddi.datastore.jdbc; 17 18 import java.sql.Connection ; 19 import java.sql.PreparedStatement ; 20 import java.sql.ResultSet ; 21 import java.util.Vector ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.apache.juddi.datatype.KeyedReference; 26 import org.apache.juddi.datatype.assertion.PublisherAssertion; 27 import org.apache.juddi.datatype.response.AssertionStatusItem; 28 import org.apache.juddi.datatype.response.CompletionStatus; 29 import org.apache.juddi.datatype.response.KeysOwned; 30 31 34 class PublisherAssertionTable 35 { 36 private static Log log = LogFactory.getLog(PublisherAssertionTable.class); 38 39 static String insertSQL = null; 40 static String selectSQL = null; 41 static String deleteDeadAssertionsSQL = null; 42 static String updateFromCheckSQL = null; 43 static String updateToCheckSQL = null; 44 static String updateFromCheckByFromKeySQL = null; 45 static String updateToCheckByToKeySQL = null; 46 static String selectAssertionsSQL = null; 47 static String selectRelationships = null; 48 49 static { 50 StringBuffer sql = null; 52 53 sql = new StringBuffer (150); 55 sql.append("INSERT INTO PUBLISHER_ASSERTION ("); 56 sql.append("FROM_KEY,"); 57 sql.append("TO_KEY,"); 58 sql.append("TMODEL_KEY,"); 59 sql.append("KEY_NAME,"); 60 sql.append("KEY_VALUE,"); 61 sql.append("FROM_CHECK,"); 62 sql.append("TO_CHECK) "); 63 sql.append("VALUES (?,?,?,?,?,?,?)"); 64 insertSQL = sql.toString(); 65 66 sql = new StringBuffer (200); 68 sql.append("SELECT "); 69 sql.append("FROM_KEY,"); 70 sql.append("TO_KEY,"); 71 sql.append("TMODEL_KEY,"); 72 sql.append("KEY_NAME,"); 73 sql.append("KEY_VALUE "); 74 sql.append("FROM PUBLISHER_ASSERTION "); 75 sql.append("WHERE FROM_KEY=? "); 76 sql.append("AND TO_KEY=? "); 77 sql.append("AND TMODEL_KEY=? "); 78 sql.append("AND KEY_NAME=? "); 79 sql.append("AND KEY_VALUE=?"); 80 selectSQL = sql.toString(); 81 82 sql = new StringBuffer (200); 84 sql.append("DELETE FROM PUBLISHER_ASSERTION "); 85 sql.append("WHERE FROM_CHECK='false' "); 86 sql.append("AND TO_CHECK='false'"); 87 deleteDeadAssertionsSQL = sql.toString(); 88 89 sql = new StringBuffer (200); 91 sql.append("UPDATE PUBLISHER_ASSERTION "); 92 sql.append("SET FROM_CHECK=? "); 93 sql.append("WHERE FROM_KEY=? "); 94 sql.append("AND TO_KEY=? "); 95 sql.append("AND TMODEL_KEY=? "); 96 sql.append("AND KEY_NAME=? "); 97 sql.append("AND KEY_VALUE=?"); 98 updateFromCheckSQL = sql.toString(); 99 100 sql = new StringBuffer (200); 102 sql.append("UPDATE PUBLISHER_ASSERTION "); 103 sql.append("SET TO_CHECK=? "); 104 sql.append("WHERE FROM_KEY=? "); 105 sql.append("AND TO_KEY=? "); 106 sql.append("AND TMODEL_KEY=? "); 107 sql.append("AND KEY_NAME=? "); 108 sql.append("AND KEY_VALUE=?"); 109 updateToCheckSQL = sql.toString(); 110 111 sql = new StringBuffer (200); 113 sql.append("UPDATE PUBLISHER_ASSERTION "); 114 sql.append("SET FROM_CHECK=? "); 115 sql.append("WHERE FROM_KEY IN "); 116 updateFromCheckByFromKeySQL = sql.toString(); 117 118 sql = new StringBuffer (200); 120 sql.append("UPDATE PUBLISHER_ASSERTION "); 121 sql.append("SET TO_CHECK=? "); 122 sql.append("WHERE TO_KEY IN "); 123 updateFromCheckByFromKeySQL = sql.toString(); 124 125 sql = new StringBuffer (200); 127 sql.append("SELECT "); 128 sql.append("FROM_KEY,"); 129 sql.append("TO_KEY,"); 130 sql.append("TMODEL_KEY,"); 131 sql.append("KEY_NAME,"); 132 sql.append("KEY_VALUE,"); 133 sql.append("FROM_CHECK,"); 134 sql.append("TO_CHECK "); 135 sql.append("FROM PUBLISHER_ASSERTION "); 136 selectAssertionsSQL = sql.toString(); 137 138 sql = new StringBuffer (200); 140 sql.append("SELECT TMODEL_KEY,KEY_NAME,KEY_VALUE "); 141 sql.append("FROM PUBLISHER_ASSERTION "); 142 sql.append( 143 "WHERE ((FROM_KEY = ? AND TO_KEY = ?) OR (FROM_KEY = ? AND TO_KEY = ?)) "); 144 sql.append("AND FROM_CHECK = 'true' "); 145 sql.append("AND TO_CHECK = 'true' "); 146 selectRelationships = sql.toString(); 147 } 148 149 158 public static void insert( 159 PublisherAssertion assertion, 160 boolean fromCheck, 161 boolean toCheck, 162 Connection connection) 163 throws java.sql.SQLException 164 { 165 PreparedStatement statement = null; 166 167 try 168 { 169 String tModelKey = null; 171 String keyedRefName = null; 172 String keyedRefValue = null; 173 174 if (assertion.getKeyedReference() != null) 175 { 176 tModelKey = assertion.getKeyedReference().getTModelKey(); 177 keyedRefName = assertion.getKeyedReference().getKeyName(); 178 keyedRefValue = assertion.getKeyedReference().getKeyValue(); 179 } 180 181 statement = connection.prepareStatement(insertSQL); 182 statement.setString(1, assertion.getFromKey()); 183 statement.setString(2, assertion.getToKey()); 184 statement.setString(3, tModelKey); 185 statement.setString(4, keyedRefName); 186 statement.setString(5, keyedRefValue); 187 statement.setString(6, String.valueOf(fromCheck)); 188 statement.setString(7, String.valueOf(toCheck)); 189 190 log.debug( 191 "insert into PUBLISHER_ASSERTION table:\n\n\t" 192 + insertSQL 193 + "\n\t FROM_KEY=" 194 + assertion.getFromKey() 195 + "\n\t TO_KEY=" 196 + assertion.getToKey() 197 + "\n\t TMODEL_KEY=" 198 + tModelKey 199 + "\n\t KEY_NAME=" 200 + keyedRefName 201 + "\n\t KEY_VALUE=" 202 + keyedRefValue 203 + "\n\t FROM_CHECK=" 204 + fromCheck 205 + "\n\t TO_CHECK=" 206 + toCheck 207 + "\n"); 208 209 statement.executeUpdate(); 211 } 212 catch (java.sql.SQLException sqlex) 213 { 214 log.error(sqlex.getMessage()); 215 throw sqlex; 216 } 217 finally 218 { 219 try 220 { 221 statement.close(); 222 } 223 catch (Exception e) 224 { 225 } 226 } 227 } 228 229 236 public static PublisherAssertion select( 237 PublisherAssertion assertionIn, 238 Connection connection) 239 throws java.sql.SQLException 240 { 241 PublisherAssertion assertionOut = null; 242 PreparedStatement statement = null; 243 ResultSet resultSet = null; 244 245 try 246 { 247 KeyedReference keyedRefIn = assertionIn.getKeyedReference(); 248 249 statement = connection.prepareStatement(selectSQL); 250 statement.setString(1, assertionIn.getFromKey()); 251 statement.setString(2, assertionIn.getToKey()); 252 statement.setString(3, keyedRefIn.getTModelKey()); 253 statement.setString(4, keyedRefIn.getKeyName()); 254 statement.setString(5, keyedRefIn.getKeyValue()); 255 256 log.debug( 257 "select from PUBLISHER_ASSERTION table:\n\n\t" 258 + selectSQL 259 + "\n\t FROM_KEY=" 260 + assertionIn.getFromKey() 261 + "\n\t TO_KEY=" 262 + assertionIn.getToKey() 263 + "\n\t TMODEL_KEY=" 264 + keyedRefIn.getTModelKey() 265 + "\n\t KEY_NAME=" 266 + keyedRefIn.getKeyName() 267 + "\n\t KEY_VALUE=" 268 + keyedRefIn.getKeyValue() 269 + "\n"); 270 271 resultSet = statement.executeQuery(); 272 if (resultSet.next()) 273 { 274 KeyedReference keyedRefOut = new KeyedReference(); 275 keyedRefOut.setKeyName(resultSet.getString(4)); keyedRefOut.setKeyValue(resultSet.getString(5)); keyedRefOut.setTModelKey(resultSet.getString(3)); 279 assertionOut = new PublisherAssertion(); 280 assertionOut.setFromKey(resultSet.getString(1)); assertionOut.setToKey(resultSet.getString(2)); assertionOut.setKeyedReference(keyedRefOut); 283 } 284 285 return assertionOut; 286 } 287 catch (java.sql.SQLException sqlex) 288 { 289 log.error(sqlex.getMessage()); 290 throw sqlex; 291 } 292 finally 293 { 294 try 295 { 296 resultSet.close(); 297 } 298 catch (Exception e) 299 { 300 } 301 try 302 { 303 statement.close(); 304 } 305 catch (Exception e) 306 { 307 } 308 } 309 } 310 311 316 public static void deleteDeadAssertions(Connection connection) 317 throws java.sql.SQLException 318 { 319 PreparedStatement statement = null; 320 321 try 322 { 323 statement = connection.prepareStatement(deleteDeadAssertionsSQL); 325 326 log.debug( 327 "delete from PUBLISHER_ASSERTION table:\n\n\t" 328 + deleteDeadAssertionsSQL 329 + "\n"); 330 331 statement.executeUpdate(); 333 } 334 catch (java.sql.SQLException sqlex) 335 { 336 log.error(sqlex.getMessage()); 337 throw sqlex; 338 } 339 finally 340 { 341 try 342 { 343 statement.close(); 344 } 345 catch (Exception e) 346 { 347 } 348 } 349 } 350 351 360 public static void updateFromCheck( 361 PublisherAssertion assertion, 362 boolean fromCheck, 363 Connection connection) 364 throws java.sql.SQLException 365 { 366 KeyedReference keyedRef = assertion.getKeyedReference(); 367 PreparedStatement statement = null; 368 ResultSet resultSet = null; 369 370 try 371 { 372 log.debug( 373 "update PUBLISHER_ASSERTION table:\n\n\t" 374 + updateFromCheckSQL 375 + "\n\t FROM_CHECK=" 376 + String.valueOf(fromCheck) 377 + "\n\t FROM_KEY=" 378 + assertion.getFromKey() 379 + "\n\t TO_KEY=" 380 + assertion.getToKey() 381 + "\n\t TMODEL_KEY=" 382 + keyedRef.getTModelKey() 383 + "\n\t KEY_NAME=" 384 + keyedRef.getKeyName() 385 + "\n\t KEY_VALUE=" 386 + keyedRef.getKeyValue() 387 + "\n"); 388 389 statement = connection.prepareStatement(updateFromCheckSQL); 391 statement.setString(1, String.valueOf(fromCheck)); 392 statement.setString(2, assertion.getFromKey()); 393 statement.setString(3, assertion.getToKey()); 394 statement.setString(4, keyedRef.getTModelKey()); 395 statement.setString(5, keyedRef.getKeyName()); 396 statement.setString(6, keyedRef.getKeyValue()); 397 398 statement.executeUpdate(); 400 } 401 catch (java.sql.SQLException sqlex) 402 { 403 log.error(sqlex.getMessage()); 404 throw sqlex; 405 } 406 finally 407 { 408 try 409 { 410 resultSet.close(); 411 } 412 catch (Exception e) 413 { 414 } 415 try 416 { 417 statement.close(); 418 } 419 catch (Exception e) 420 { 421 } 422 } 423 } 424 425 434 public static void updateToCheck( 435 PublisherAssertion assertion, 436 boolean toCheck, 437 Connection connection) 438 throws java.sql.SQLException 439 { 440 KeyedReference keyedRef = assertion.getKeyedReference(); 441 PreparedStatement statement = null; 442 ResultSet resultSet = null; 443 444 try 445 { 446 log.debug( 447 "update PUBLISHER_ASSERTION table:\n\n\t" 448 + updateToCheckSQL 449 + "\n\t TO_CHECK=" 450 + String.valueOf(toCheck) 451 + "\n\t FROM_KEY=" 452 + assertion.getFromKey() 453 + "\n\t TO_KEY=" 454 + assertion.getToKey() 455 + "\n\t TMODEL_KEY=" 456 + keyedRef.getTModelKey() 457 + "\n\t KEY_NAME=" 458 + keyedRef.getKeyName() 459 + "\n\t KEY_VALUE=" 460 + keyedRef.getKeyValue() 461 + "\n"); 462 463 statement = connection.prepareStatement(updateToCheckSQL); 465 statement.setString(1, String.valueOf(toCheck)); 466 statement.setString(2, assertion.getFromKey()); 467 statement.setString(3, assertion.getToKey()); 468 statement.setString(4, keyedRef.getTModelKey()); 469 statement.setString(5, keyedRef.getKeyName()); 470 statement.setString(6, keyedRef.getKeyValue()); 471 472 statement.executeUpdate(); 474 } 475 catch (java.sql.SQLException sqlex) 476 { 477 log.error(sqlex.getMessage()); 478 throw sqlex; 479 } 480 finally 481 { 482 try 483 { 484 resultSet.close(); 485 } 486 catch (Exception e) 487 { 488 } 489 try 490 { 491 statement.close(); 492 } 493 catch (Exception e) 494 { 495 } 496 } 497 } 498 499 508 public static void updateFromCheckByFromKey( 509 Vector fromKeysIn, 510 boolean fromCheck, 511 Connection connection) 512 throws java.sql.SQLException 513 { 514 StringBuffer sql = new StringBuffer (); 515 sql.append(updateFromCheckByFromKeySQL); 516 sql.append("WHERE FROM_KEY IN "); 517 appendIn(sql, fromKeysIn); 518 519 PreparedStatement statement = null; 520 ResultSet resultSet = null; 521 522 try 523 { 524 statement = connection.prepareStatement(sql.toString()); 526 statement.setString(1, String.valueOf(fromCheck)); 527 528 log.debug( 529 "update PUBLISHER_ASSERTION table:\n\n\t" + sql.toString() + "\n"); 530 531 statement.executeUpdate(); 533 } 534 catch (java.sql.SQLException sqlex) 535 { 536 log.error(sqlex.getMessage()); 537 throw sqlex; 538 } 539 finally 540 { 541 try 542 { 543 resultSet.close(); 544 } 545 catch (Exception e) 546 { 547 } 548 try 549 { 550 statement.close(); 551 } 552 catch (Exception e) 553 { 554 } 555 } 556 } 557 558 567 public static void updateToCheckByToKey( 568 Vector toKeysIn, 569 boolean toCheck, 570 Connection connection) 571 throws java.sql.SQLException 572 { 573 StringBuffer sql = new StringBuffer (); 574 sql.append(updateFromCheckByFromKeySQL); 575 sql.append("WHERE TO_KEY IN "); 576 appendIn(sql, toKeysIn); 577 578 PreparedStatement statement = null; 579 ResultSet resultSet = null; 580 581 try 582 { 583 statement = connection.prepareStatement(sql.toString()); 585 statement.setString(1, String.valueOf(toCheck)); 586 587 log.debug( 588 "update PUBLISHER_ASSERTION table:\n\n\t" + sql.toString() + "\n"); 589 590 statement.executeUpdate(); 592 } 593 catch (java.sql.SQLException sqlex) 594 { 595 log.error(sqlex.getMessage()); 596 throw sqlex; 597 } 598 finally 599 { 600 try 601 { 602 resultSet.close(); 603 } 604 catch (Exception e) 605 { 606 } 607 try 608 { 609 statement.close(); 610 } 611 catch (Exception e) 612 { 613 } 614 } 615 } 616 617 635 public static Vector selectBothKeysOwnedAssertion( 636 Vector keysIn, 637 Connection connection) 638 throws java.sql.SQLException 639 { 640 if ((keysIn == null) || (keysIn.size() == 0)) 641 return null; 642 643 StringBuffer sql = new StringBuffer (); 644 sql.append(selectAssertionsSQL); 645 sql.append("WHERE FROM_KEY IN "); 646 appendIn(sql, keysIn); 647 sql.append("AND TO_KEY IN "); 648 appendIn(sql, keysIn); 649 650 Vector itemList = new Vector (); 651 PreparedStatement statement = null; 652 ResultSet resultSet = null; 653 654 try 655 { 656 statement = connection.prepareStatement(sql.toString()); 657 658 log.debug( 659 "select from PUBLISHER_ASSERTION table:\n\n\t" + selectSQL + "\n"); 660 661 resultSet = statement.executeQuery(); 662 while (resultSet.next()) 663 { 664 AssertionStatusItem item = new AssertionStatusItem(); 665 item.setFromKey(resultSet.getString(1)); item.setToKey(resultSet.getString(2)); 668 KeyedReference keyedRef = new KeyedReference(); 670 keyedRef.setTModelKey(resultSet.getString(3)); keyedRef.setKeyName(resultSet.getString(4)); keyedRef.setKeyValue(resultSet.getString(5)); item.setKeyedReference(keyedRef); 674 675 KeysOwned keysOwned = new KeysOwned(); 677 keysOwned.setFromKey(item.getFromKey()); 678 keysOwned.setToKey(item.getToKey()); 679 item.setKeysOwned(keysOwned); 680 681 item.setCompletionStatus( 683 new CompletionStatus(CompletionStatus.COMPLETE)); 684 685 itemList.addElement(item); 687 } 688 689 return itemList; 690 } 691 catch (java.sql.SQLException sqlex) 692 { 693 log.error(sqlex.getMessage()); 694 throw sqlex; 695 } 696 finally 697 { 698 try 699 { 700 resultSet.close(); 701 } 702 catch (Exception e) 703 { 704 } 705 try 706 { 707 statement.close(); 708 } 709 catch (Exception e) 710 { 711 } 712 } 713 } 714 715 728 public static Vector selectFromKeyOwnedAssertion( 729 Vector keysIn, 730 Connection connection) 731 throws java.sql.SQLException 732 { 733 if ((keysIn == null) || (keysIn.size() == 0)) 734 return null; 735 736 StringBuffer sql = new StringBuffer (); 737 sql.append(selectAssertionsSQL); 738 sql.append("WHERE FROM_KEY IN "); 739 appendIn(sql, keysIn); 740 sql.append("AND TO_KEY NOT IN "); 741 appendIn(sql, keysIn); 742 743 Vector itemList = new Vector (); 744 PreparedStatement statement = null; 745 ResultSet resultSet = null; 746 747 try 748 { 749 statement = connection.prepareStatement(sql.toString()); 750 751 log.debug( 752 "select from PUBLISHER_ASSERTION table:\n\n\t" + selectSQL + "\n"); 753 754 resultSet = statement.executeQuery(); 755 while (resultSet.next()) 756 { 757 AssertionStatusItem item = new AssertionStatusItem(); 758 item.setFromKey(resultSet.getString(1)); item.setToKey(resultSet.getString(2)); 761 KeyedReference keyedRef = new KeyedReference(); 763 keyedRef.setTModelKey(resultSet.getString(3)); keyedRef.setKeyName(resultSet.getString(4)); keyedRef.setKeyValue(resultSet.getString(5)); item.setKeyedReference(keyedRef); 767 768 KeysOwned keysOwned = new KeysOwned(); 770 keysOwned.setFromKey(item.getFromKey()); 771 keysOwned.setToKey(null); 772 item.setKeysOwned(keysOwned); 773 774 CompletionStatus status = null; 776 boolean fromCheck = 777 new Boolean (resultSet.getString(6)).booleanValue(); boolean toCheck = 779 new Boolean (resultSet.getString(7)).booleanValue(); if ((fromCheck) && (toCheck)) 781 status = new CompletionStatus(CompletionStatus.COMPLETE); 782 else if ((fromCheck) && (!toCheck)) 783 status = new CompletionStatus(CompletionStatus.TOKEY_INCOMPLETE); 784 else if ((!fromCheck) && (toCheck)) 785 status = new CompletionStatus(CompletionStatus.FROMKEY_INCOMPLETE); 786 item.setCompletionStatus(status); 787 788 itemList.addElement(item); 790 } 791 792 return itemList; 793 } 794 catch (java.sql.SQLException sqlex) 795 { 796 log.error(sqlex.getMessage()); 797 throw sqlex; 798 } 799 finally 800 { 801 try 802 { 803 resultSet.close(); 804 } 805 catch (Exception e) 806 { 807 } 808 try 809 { 810 statement.close(); 811 } 812 catch (Exception e) 813 { 814 } 815 } 816 } 817 818 831 public static Vector selectToKeyOwnedAssertion( 832 Vector keysIn, 833 Connection connection) 834 throws java.sql.SQLException 835 { 836 if ((keysIn == null) || (keysIn.size() == 0)) 837 return null; 838 839 StringBuffer sql = new StringBuffer (); 840 sql.append(selectAssertionsSQL); 841 sql.append("WHERE FROM_KEY NOT IN "); 842 appendIn(sql, keysIn); 843 sql.append("AND TO_KEY IN "); 844 appendIn(sql, keysIn); 845 846 Vector itemList = new Vector (); 847 PreparedStatement statement = null; 848 ResultSet resultSet = null; 849 850 try 851 { 852 statement = connection.prepareStatement(sql.toString()); 853 854 log.debug( 855 "select from PUBLISHER_ASSERTION table:\n\n\t" + selectSQL + "\n"); 856 857 resultSet = statement.executeQuery(); 858 while (resultSet.next()) 859 { 860 AssertionStatusItem item = new AssertionStatusItem(); 861 item.setFromKey(resultSet.getString(1)); item.setToKey(resultSet.getString(2)); 864 KeyedReference keyedRef = new KeyedReference(); 866 keyedRef.setKeyName(resultSet.getString(4)); keyedRef.setKeyValue(resultSet.getString(5)); keyedRef.setTModelKey(resultSet.getString(3)); item.setKeyedReference(keyedRef); 870 871 KeysOwned keysOwned = new KeysOwned(); 873 keysOwned.setFromKey(null); 874 keysOwned.setToKey(item.getToKey()); 875 item.setKeysOwned(keysOwned); 876 877 CompletionStatus status = null; 879 boolean fromCheck = 880 new Boolean (resultSet.getString(6)).booleanValue(); boolean toCheck = 882 new Boolean (resultSet.getString(7)).booleanValue(); if ((fromCheck) && (toCheck)) 884 status = new CompletionStatus(CompletionStatus.COMPLETE); 885 else if ((fromCheck) && (!toCheck)) 886 status = new CompletionStatus(CompletionStatus.TOKEY_INCOMPLETE); 887 else if ((!fromCheck) && (toCheck)) 888 status = new CompletionStatus(CompletionStatus.FROMKEY_INCOMPLETE); 889 item.setCompletionStatus(status); 890 891 itemList.addElement(item); 893 } 894 895 return itemList; 896 } 897 catch (java.sql.SQLException sqlex) 898 { 899 log.error(sqlex.getMessage()); 900 throw sqlex; 901 } 902 finally 903 { 904 try 905 { 906 resultSet.close(); 907 } 908 catch (Exception e) 909 { 910 } 911 try 912 { 913 statement.close(); 914 } 915 catch (Exception e) 916 { 917 } 918 } 919 } 920 921 931 public static Vector selectAssertions(Vector keysIn, Connection connection) 932 throws java.sql.SQLException 933 { 934 if ((keysIn == null) || (keysIn.size() == 0)) 935 return null; 936 937 StringBuffer sql = new StringBuffer (); 938 sql.append(selectAssertionsSQL); 939 sql.append("WHERE (FROM_KEY IN "); 940 appendIn(sql, keysIn); 941 sql.append("AND FROM_CHECK = 'true') "); 942 sql.append("OR (TO_KEY IN "); 943 appendIn(sql, keysIn); 944 sql.append("AND TO_CHECK = 'true')"); 945 946 Vector assertionList = new Vector (); 947 PreparedStatement statement = null; 948 ResultSet resultSet = null; 949 950 try 951 { 952 statement = connection.prepareStatement(sql.toString()); 953 954 log.debug( 955 "select from PUBLISHER_ASSERTION table:\n\n\t" + selectSQL + "\n"); 956 957 resultSet = statement.executeQuery(); 958 while (resultSet.next()) 959 { 960 PublisherAssertion assertion = new PublisherAssertion(); 961 assertion.setFromKey(resultSet.getString(1)); assertion.setToKey(resultSet.getString(2)); 964 KeyedReference keyedRef = new KeyedReference(); 966 keyedRef.setKeyName(resultSet.getString(4)); keyedRef.setKeyValue(resultSet.getString(5)); keyedRef.setTModelKey(resultSet.getString(3)); assertion.setKeyedReference(keyedRef); 970 971 assertionList.addElement(assertion); 973 } 974 975 return assertionList; 976 } 977 catch (java.sql.SQLException sqlex) 978 { 979 log.error(sqlex.getMessage()); 980 throw sqlex; 981 } 982 finally 983 { 984 try 985 { 986 resultSet.close(); 987 } 988 catch (Exception e) 989 { 990 } 991 try 992 { 993 statement.close(); 994 } 995 catch (Exception e) 996 { 997 } 998 } 999 } 1000 1001 1012 public static Vector selectRelatedBusinesses( 1013 String businessKey, 1014 String relatedKey, 1015 Connection connection) 1016 throws java.sql.SQLException 1017 { 1018 Vector refList = new Vector (); 1019 PreparedStatement statement = null; 1020 ResultSet resultSet = null; 1021 1022 try 1023 { 1024 statement = connection.prepareStatement(selectRelationships); 1025 statement.setString(1, businessKey); 1026 statement.setString(2, relatedKey); 1027 statement.setString(3, relatedKey); 1028 statement.setString(4, businessKey); 1029 1030 log.debug( 1031 "select from PUBLISHER_ASSERTION table:\n\n\t" 1032 + selectRelationships 1033 + "\n\t BUSINESS_KEY=" 1034 + businessKey.toString() 1035 + "\n\t RELATED_BUSINESS_KEY=" 1036 + relatedKey.toString() 1037 + "\n"); 1038 1039 resultSet = statement.executeQuery(); 1040 if (resultSet.next()) 1041 { 1042 KeyedReference keyedRef = new KeyedReference(); 1043 keyedRef.setKeyName(resultSet.getString(2)); keyedRef.setKeyValue(resultSet.getString(3)); keyedRef.setTModelKey(resultSet.getString(1)); 1047 refList.addElement(keyedRef); 1049 } 1050 1051 return refList; 1052 } 1053 catch (java.sql.SQLException sqlex) 1054 { 1055 log.error(sqlex.getMessage()); 1056 throw sqlex; 1057 } 1058 finally 1059 { 1060 try 1061 { 1062 resultSet.close(); 1063 } 1064 catch (Exception e) 1065 { 1066 } 1067 try 1068 { 1069 statement.close(); 1070 } 1071 catch (Exception e) 1072 { 1073 } 1074 } 1075 } 1076 1077 1086 private static void appendIn(StringBuffer sql, Vector keysIn) 1087 { 1088 if (keysIn == null) 1089 return; 1090 1091 sql.append("("); 1092 1093 int keyCount = keysIn.size(); 1094 for (int i = 0; i < keyCount; i++) 1095 { 1096 String key = (String ) keysIn.elementAt(i); 1097 sql.append("'").append(key).append("'"); 1098 1099 if ((i + 1) < keyCount) 1100 sql.append(","); 1101 } 1102 1103 sql.append(") "); 1104 } 1105} 1106 | Popular Tags |