1 23 24 package org.apache.slide.store; 25 26 import java.util.Enumeration ; 27 import java.util.Hashtable ; 28 29 import javax.transaction.Transaction ; 30 import javax.transaction.xa.XAException ; 31 import javax.transaction.xa.Xid ; 32 33 import org.apache.slide.authenticate.CredentialsToken; 34 import org.apache.slide.common.AbstractSimpleService; 35 import org.apache.slide.common.Namespace; 36 import org.apache.slide.common.NamespaceAccessToken; 37 import org.apache.slide.common.Scope; 38 import org.apache.slide.common.Service; 39 import org.apache.slide.common.ServiceAccessException; 40 import org.apache.slide.common.ServiceConnectionFailedException; 41 import org.apache.slide.common.ServiceDisconnectionFailedException; 42 import org.apache.slide.common.ServiceInitializationFailedException; 43 import org.apache.slide.common.ServiceParameterErrorException; 44 import org.apache.slide.common.ServiceParameterMissingException; 45 import org.apache.slide.common.ServiceResetFailedException; 46 import org.apache.slide.common.SlideToken; 47 import org.apache.slide.common.Uri; 48 import org.apache.slide.content.NodeRevisionContent; 49 import org.apache.slide.content.NodeRevisionDescriptor; 50 import org.apache.slide.content.NodeRevisionDescriptors; 51 import org.apache.slide.content.NodeRevisionNumber; 52 import org.apache.slide.content.RevisionAlreadyExistException; 53 import org.apache.slide.content.RevisionDescriptorNotFoundException; 54 import org.apache.slide.content.RevisionNotFoundException; 55 import org.apache.slide.lock.LockTokenNotFoundException; 56 import org.apache.slide.lock.NodeLock; 57 import org.apache.slide.security.NodePermission; 58 import org.apache.slide.structure.ObjectAlreadyExistsException; 59 import org.apache.slide.structure.ObjectNode; 60 import org.apache.slide.structure.ObjectNotFoundException; 61 import org.apache.slide.util.Messages; 62 import org.apache.slide.util.logger.Logger; 63 64 69 public abstract class AbstractStore extends AbstractSimpleService 70 implements Store { 71 72 73 75 76 78 79 82 protected NodeStore nodeStore; 83 84 85 88 protected SecurityStore securityStore; 89 90 91 94 protected LockStore lockStore; 95 96 97 100 protected RevisionDescriptorsStore revisionDescriptorsStore; 101 102 103 106 protected RevisionDescriptorStore revisionDescriptorStore; 107 108 109 112 protected ContentStore contentStore; 113 114 117 protected IndexStore propertiesIndexer; 118 119 122 protected IndexStore contentIndexer; 123 124 127 protected SequenceStore sequenceStore = null; 128 129 132 protected Service resourceManagers[] = new Service[0]; 133 134 135 136 private String name; 138 139 140 143 public void setName(String name) { 144 this.name = name; 145 } 146 147 148 149 152 public String getName() { 153 return this.name; 154 } 155 156 157 158 161 public void setScope(Scope scope) { 162 super.setScope(scope); 163 for (int i = 0; i < resourceManagers.length; i++) { 164 resourceManagers[i].setScope(scope); 165 } 166 } 167 168 169 170 172 173 176 public void setNamespace(Namespace namespace) { 177 178 super.setNamespace(namespace); 179 180 for (int i = 0; i < resourceManagers.length; i++) { 181 resourceManagers[i].setNamespace(namespace); 182 } 183 184 } 185 186 187 protected Hashtable parameters = null; 188 189 197 public void setParameters(Hashtable parameters) 198 throws ServiceParameterErrorException, 199 ServiceParameterMissingException { 200 this.parameters = parameters; 201 } 202 203 public Object getParameter (Object key) { 204 return parameters.get (key); 205 } 206 207 212 public void connect(CredentialsToken crdtoken) 213 throws ServiceConnectionFailedException { 214 215 for (int i = 0; i < resourceManagers.length; i++) { 216 resourceManagers[i].connect(crdtoken); 217 } 218 219 } 220 221 222 223 228 public void connect() 229 throws ServiceConnectionFailedException { 230 231 for (int i = 0; i < resourceManagers.length; i++) { 232 resourceManagers[i].connect(); 233 } 234 235 } 236 237 238 243 public void disconnect() 244 throws ServiceDisconnectionFailedException { 245 246 for (int i = 0; i < resourceManagers.length; i++) { 247 resourceManagers[i].disconnect(); 248 } 249 250 } 251 252 253 259 public void initialize(NamespaceAccessToken token) 260 throws ServiceInitializationFailedException { 261 262 super.initialize(token); 263 264 for (int i = 0; i < resourceManagers.length; i++) { 265 resourceManagers[i].initialize(token); 266 } 267 268 } 269 270 271 276 public void reset() 277 throws ServiceResetFailedException { 278 279 for (int i = 0; i < resourceManagers.length; i++) { 280 resourceManagers[i].reset(); 281 } 282 283 } 284 285 286 292 public boolean isConnected() 293 throws ServiceAccessException { 294 295 for (int i = 0; i < resourceManagers.length; i++) { 296 if (!resourceManagers[i].isConnected()) 297 return false; 298 } 299 return true; 300 301 } 302 303 304 306 307 321 public void commit(Xid xid, boolean onePhase) 322 throws XAException { 323 super.commit(xid, onePhase); 324 } 325 326 327 337 public void end(Xid xid, int flags) 338 throws XAException { 339 super.end(xid, flags); 340 } 341 342 343 351 public void forget(Xid xid) 352 throws XAException { 353 super.forget(xid); 354 } 355 356 357 370 public int prepare(Xid xid) 371 throws XAException { 372 return super.prepare(xid); 373 } 374 375 376 383 public void rollback(Xid xid) 384 throws XAException { 385 super.rollback(xid); 386 } 387 388 389 399 public void start(Xid xid, int flags) 400 throws XAException { 401 super.start(xid, flags); 402 } 403 404 405 407 408 411 public void setNodeStore(NodeStore nodeStore) { 412 if (nodeStore == null) { 413 throw new IllegalArgumentException ("Nodestore must not be null"); 414 } 415 this.nodeStore = nodeStore; 416 addResourceManager(this.nodeStore); 417 } 418 419 420 423 public void setSecurityStore(SecurityStore securityStore) { 424 if (securityStore == null) { 425 throw new IllegalArgumentException ("Securitystore must not be null"); 426 } 427 this.securityStore = securityStore; 428 addResourceManager(this.securityStore); 429 } 430 431 432 435 public void setLockStore(LockStore lockStore) { 436 if (lockStore == null) { 437 throw new IllegalArgumentException ("Lockstore must not be null"); 438 } 439 this.lockStore = lockStore; 440 addResourceManager(this.lockStore); 441 } 442 443 444 447 public void setRevisionDescriptorsStore 448 (RevisionDescriptorsStore revisionDescriptorsStore) { 449 if (revisionDescriptorsStore == null) { 450 throw new IllegalArgumentException ("Revisiondescriptorsstore must not be null"); 451 } 452 this.revisionDescriptorsStore = revisionDescriptorsStore; 453 addResourceManager(this.revisionDescriptorsStore); 454 } 455 456 457 460 public void setRevisionDescriptorStore 461 (RevisionDescriptorStore revisionDescriptorStore) { 462 if (revisionDescriptorStore == null) { 463 throw new IllegalArgumentException ("Revisiondescriptorstore must not be null"); 464 } 465 this.revisionDescriptorStore = revisionDescriptorStore; 466 addResourceManager(this.revisionDescriptorStore); 467 } 468 469 470 473 public void setContentStore(ContentStore contentStore) { 474 if (contentStore == null) { 475 476 } 477 this.contentStore = contentStore; 478 addResourceManager(this.contentStore); 479 } 480 481 482 488 public void setPropertiesIndexer (IndexStore propertiesIndexer) { 489 if (propertiesIndexer == null) { 490 throw new IllegalArgumentException ("PropertiesIndexer must not be null"); 491 } 492 this.propertiesIndexer = propertiesIndexer; 493 addResourceManager(this.propertiesIndexer); 494 495 } 496 497 498 504 public void setContentIndexer (IndexStore contentIndexer) { 505 if (contentIndexer == null) { 506 throw new IllegalArgumentException ("ContentIndexer must not be null"); 507 } 508 this.contentIndexer = contentIndexer; 509 addResourceManager(this.contentIndexer); 510 511 } 512 513 519 public IndexStore getContentIndexer () { 520 return contentIndexer; 521 } 522 523 529 public IndexStore getPropertiesIndexer () { 530 return propertiesIndexer; 531 } 532 533 536 public void setSequenceStore(SequenceStore store) { 537 sequenceStore = store; 538 } 539 540 544 547 public boolean isSequenceSupported() { 548 return (sequenceStore != null && sequenceStore.isSequenceSupported()); 549 } 550 551 554 public boolean sequenceExists(String sequenceName) throws ServiceAccessException { 555 if (!isSequenceSupported()) { 556 throw new ServiceAccessException(this, "Sequences not supported"); 557 } 558 return sequenceStore.sequenceExists(sequenceName); 559 } 560 561 564 public boolean createSequence(String sequenceName) throws ServiceAccessException { 565 if (!isSequenceSupported()) { 566 throw new ServiceAccessException(this, "Sequences not supported"); 567 } 568 return sequenceStore.createSequence(sequenceName); 569 } 570 571 574 public long nextSequenceValue(String sequenceName) throws ServiceAccessException { 575 if (!isSequenceSupported()) { 576 throw new ServiceAccessException(this, "Sequences not supported"); 577 } 578 return sequenceStore.nextSequenceValue(sequenceName); 579 } 580 581 588 public ObjectNode retrieveObject(Uri uri) 589 throws ServiceAccessException, ObjectNotFoundException { 590 ObjectNode objectNode = null; 591 if (isForceStoreEnlistment(uri)) { 592 enlist(nodeStore); 593 try { 594 objectNode = nodeStore.retrieveObject(uri); 595 } catch (ServiceAccessException e) { 596 delist(nodeStore, false); 597 throw e; 598 } catch (ObjectNotFoundException e) { 599 delist(nodeStore); 602 throw e; 603 } catch (Throwable t) { 604 delist(nodeStore, false); 605 throw new ServiceAccessException(nodeStore, t); 607 } 608 delist(nodeStore); 609 } else { 610 try { 611 objectNode = nodeStore.retrieveObject(uri); 612 } catch (ServiceAccessException e) { 613 throw e; 614 } catch (ObjectNotFoundException e) { 615 throw e; 616 } catch (Throwable t) { 617 throw new ServiceAccessException(nodeStore, t); 619 } 620 } 621 objectNode.validate(uri.toString()); 622 return objectNode; 623 } 624 625 626 633 public void storeObject(Uri uri, ObjectNode object) 634 throws ServiceAccessException, ObjectNotFoundException { 635 ObjectNode tempObject = object.cloneObject(); 636 tempObject.validate(uri.toString()); 637 enlist(nodeStore); 638 try { 639 nodeStore.storeObject(uri, tempObject); 640 } catch (ServiceAccessException e) { 641 delist(nodeStore, false); 642 throw e; 643 } catch (ObjectNotFoundException e) { 644 delist(nodeStore); 645 throw e; 646 } catch (Throwable t) { 647 delist(nodeStore, false); 648 throw new ServiceAccessException(contentStore, t); 650 } 651 delist(nodeStore); 652 } 653 654 655 664 public void createObject(Uri uri, ObjectNode object) 665 throws ServiceAccessException, ObjectAlreadyExistsException { 666 ObjectNode tempObject = object.cloneObject(); 667 tempObject.validate(uri.toString()); 668 enlist(nodeStore); 669 try { 670 nodeStore.createObject(uri, tempObject); 671 if (useBinding()) { 672 String uuri = tempObject.getUuri(); 673 if (uuri == null) { 674 throw new IllegalStateException (); 675 } 676 object.setUuri(uuri); 677 } else { 678 object.setUuri(tempObject.getUri()); 679 } 680 } catch (ServiceAccessException e) { 681 delist(nodeStore, false); 682 throw e; 683 } catch (ObjectAlreadyExistsException e) { 684 delist(nodeStore); 685 throw e; 686 } catch (Throwable t) { 687 delist(nodeStore, false); 688 throw new ServiceAccessException(nodeStore, t); 690 } 691 delist(nodeStore); 692 } 693 694 695 702 public void removeObject(Uri uri, ObjectNode object) 703 throws ServiceAccessException, ObjectNotFoundException { 704 object.validate(uri.toString()); 705 enlist(nodeStore); 706 try { 707 nodeStore.removeObject(uri, object); 708 } catch (ServiceAccessException e) { 709 delist(nodeStore, false); 710 throw e; 711 } catch (ObjectNotFoundException e) { 712 delist(nodeStore); 713 throw e; 714 } catch (Throwable t) { 715 delist(nodeStore, false); 716 throw new ServiceAccessException(nodeStore, t); 718 } 719 delist(nodeStore); 720 } 721 722 723 729 public void grantPermission(Uri uri, NodePermission permission) 730 throws ServiceAccessException { 731 NodePermission tempPermission = permission.cloneObject(); 732 tempPermission.validate(uri.toString()); 733 enlist(securityStore); 734 try { 735 securityStore.grantPermission(uri, tempPermission); 736 } catch (ServiceAccessException e) { 737 delist(securityStore, false); 738 throw e; 739 } catch (Throwable t) { 740 delist(securityStore, false); 741 throw new ServiceAccessException(securityStore, t); 743 } 744 delist(securityStore); 745 } 746 747 748 754 public void revokePermission(Uri uri, NodePermission permission) 755 throws ServiceAccessException { 756 permission.validate(uri.toString()); 757 enlist(securityStore); 758 try { 759 securityStore.revokePermission(uri, permission); 760 } catch (ServiceAccessException e) { 761 delist(securityStore, false); 762 throw e; 763 } catch (Throwable t) { 764 delist(securityStore, false); 765 throw new ServiceAccessException(securityStore, t); 767 } 768 delist(securityStore); 769 } 770 771 772 778 public void revokePermissions(Uri uri) 779 throws ServiceAccessException { 780 enlist(securityStore); 781 try { 782 securityStore.revokePermissions(uri); 783 } catch (ServiceAccessException e) { 784 delist(securityStore, false); 785 throw e; 786 } catch (Throwable t) { 787 delist(securityStore, false); 788 throw new ServiceAccessException(securityStore, t); 790 } 791 delist(securityStore); 792 } 793 794 795 803 public Enumeration enumeratePermissions(Uri uri) 804 throws ServiceAccessException { 805 if (isForceStoreEnlistment(uri)) { 807 enlist(securityStore); 808 Enumeration permissions = null; 809 try { 810 permissions = securityStore.enumeratePermissions(uri); 811 } catch (ServiceAccessException e) { 812 delist(securityStore, false); 813 throw e; 814 } catch (Throwable t) { 815 delist(securityStore, false); 816 throw new ServiceAccessException 818 (securityStore, t); 819 } 820 delist(securityStore); 821 return permissions; 822 } else { 823 try { 824 return securityStore.enumeratePermissions(uri); 825 } catch (ServiceAccessException e) { 826 throw e; 827 } catch (Throwable t) { 828 throw new ServiceAccessException 830 (securityStore, t); 831 } 832 } 833 } 834 835 836 842 public void putLock(Uri uri, NodeLock lock) 843 throws ServiceAccessException { 844 lock.validate(uri.toString()); 845 enlist(lockStore); 846 try { 847 lockStore.putLock(uri, lock); 848 } catch (ServiceAccessException e) { 849 delist(lockStore, false); 850 throw e; 851 } catch (Throwable t) { 852 delist(lockStore, false); 853 throw new ServiceAccessException(lockStore, t); 855 } 856 delist(lockStore); 857 } 858 859 860 867 public void renewLock(Uri uri, NodeLock lock) 868 throws ServiceAccessException, LockTokenNotFoundException { 869 lock.validate(uri.toString()); 870 enlist(lockStore); 871 try { 872 lockStore.renewLock(uri, lock); 873 } catch (ServiceAccessException e) { 874 delist(lockStore, false); 875 throw e; 876 } catch (LockTokenNotFoundException e) { 877 delist(lockStore); 878 throw e; 879 } catch (Throwable t) { 880 delist(lockStore, false); 881 throw new ServiceAccessException(lockStore, t); 883 } 884 delist(lockStore); 885 } 886 887 888 895 public void removeLock(Uri uri, NodeLock lock) 896 throws ServiceAccessException, LockTokenNotFoundException { 897 lock.validate(uri.toString()); 898 enlist(lockStore); 899 try { 900 lockStore.removeLock(uri, lock); 901 } catch (ServiceAccessException e) { 902 delist(lockStore, false); 903 throw e; 904 } catch (LockTokenNotFoundException e) { 905 delist(lockStore); 906 throw e; 907 } catch (Throwable t) { 908 delist(lockStore, false); 909 throw new ServiceAccessException(lockStore, t); 911 } 912 delist(lockStore); 913 } 914 915 916 923 public void killLock(Uri uri, NodeLock lock) 924 throws ServiceAccessException, LockTokenNotFoundException { 925 lock.validate(uri.toString()); 926 enlist(lockStore); 927 try { 928 lockStore.killLock(uri, lock); 929 } catch (ServiceAccessException e) { 930 delist(lockStore, false); 931 throw e; 932 } catch (LockTokenNotFoundException e) { 933 delist(lockStore); 934 throw e; 935 } catch (Throwable t) { 936 delist(lockStore, false); 937 throw new ServiceAccessException(lockStore, t); 939 } 940 delist(lockStore); 941 } 942 943 944 952 public Enumeration enumerateLocks(Uri uri) 953 throws ServiceAccessException { 954 if (isForceStoreEnlistment(uri)) { 955 enlist(lockStore); 956 Enumeration locks = null; 957 try { 958 locks = lockStore.enumerateLocks(uri); 959 } catch (ServiceAccessException e) { 960 delist(lockStore, false); 961 throw e; 962 } catch (Throwable t) { 963 delist(lockStore, false); 964 throw new ServiceAccessException(lockStore, t); 966 } 967 delist(lockStore); 968 return locks; 969 } else { 970 try { 971 return lockStore.enumerateLocks(uri); 972 } catch (ServiceAccessException e) { 973 throw e; 974 } catch (Throwable t) { 975 throw new ServiceAccessException(lockStore, t); 977 } 978 } 979 } 980 981 982 990 public NodeRevisionDescriptors retrieveRevisionDescriptors(Uri uri) 991 throws ServiceAccessException, RevisionDescriptorNotFoundException { 992 NodeRevisionDescriptors revisionDescriptors = null; 993 if (isForceStoreEnlistment(uri)) { 994 enlist(revisionDescriptorsStore); 995 try { 996 revisionDescriptors = 997 revisionDescriptorsStore.retrieveRevisionDescriptors(uri); 998 } catch (ServiceAccessException e) { 999 delist(revisionDescriptorsStore, false); 1000 throw e; 1001 } catch (RevisionDescriptorNotFoundException e) { 1002 delist(revisionDescriptorsStore); 1004 throw e; 1005 } catch (Throwable t) { 1006 delist(revisionDescriptorsStore, false); 1007 throw new ServiceAccessException 1009 (revisionDescriptorsStore, t); 1010 } 1011 delist(revisionDescriptorsStore); 1012 } else { 1013 try { 1014 revisionDescriptors = 1015 revisionDescriptorsStore.retrieveRevisionDescriptors(uri); 1016 } catch (ServiceAccessException e) { 1017 throw e; 1018 } catch (RevisionDescriptorNotFoundException e) { 1019 throw e; 1020 } catch (Throwable t) { 1021 throw new ServiceAccessException 1023 (revisionDescriptorsStore, t); 1024 } 1025 } 1026 revisionDescriptors.validate(uri.toString()); 1027 return revisionDescriptors; 1028 } 1029 1030 1031 1038 public void createRevisionDescriptors 1039 (Uri uri, NodeRevisionDescriptors revisionDescriptors) 1040 throws ServiceAccessException { 1041 revisionDescriptors.validate(uri.toString()); 1042 enlist(revisionDescriptorsStore); 1043 try { 1044 revisionDescriptorsStore.createRevisionDescriptors 1045 (uri, revisionDescriptors); 1046 } catch (ServiceAccessException e) { 1047 delist(revisionDescriptorsStore, false); 1048 throw e; 1049 } catch (Throwable t) { 1050 delist(revisionDescriptorsStore, false); 1051 throw new ServiceAccessException 1053 (revisionDescriptorsStore, t); 1054 } 1055 delist(revisionDescriptorsStore); 1056 } 1057 1058 1059 1068 public void storeRevisionDescriptors 1069 (Uri uri, NodeRevisionDescriptors revisionDescriptors) 1070 throws ServiceAccessException, RevisionDescriptorNotFoundException { 1071 revisionDescriptors.validate(uri.toString()); 1072 enlist(revisionDescriptorsStore); 1073 try { 1074 revisionDescriptorsStore.storeRevisionDescriptors 1075 (uri, revisionDescriptors); 1076 } catch (ServiceAccessException e) { 1077 delist(revisionDescriptorsStore, false); 1078 throw e; 1079 } catch (RevisionDescriptorNotFoundException e) { 1080 delist(revisionDescriptorsStore); 1081 throw e; 1082 } catch (Throwable t) { 1083 delist(revisionDescriptorsStore, false); 1084 throw new ServiceAccessException 1086 (revisionDescriptorsStore, t); 1087 } 1088 delist(revisionDescriptorsStore); 1089 } 1090 1091 1092 1098 public void removeRevisionDescriptors(Uri uri) 1099 throws ServiceAccessException { 1100 enlist(revisionDescriptorsStore); 1101 try { 1102 revisionDescriptorsStore.removeRevisionDescriptors(uri); 1103 } catch (ServiceAccessException e) { 1104 delist(revisionDescriptorsStore, false); 1105 throw e; 1106 } catch (Throwable t) { 1107 delist(revisionDescriptorsStore, false); 1108 throw new ServiceAccessException 1110 (revisionDescriptorsStore, t); 1111 } 1112 delist(revisionDescriptorsStore); 1113 } 1114 1115 1116 1122 public NodeRevisionDescriptor retrieveRevisionDescriptor 1123 (Uri uri, NodeRevisionNumber revisionNumber) 1124 throws ServiceAccessException, RevisionDescriptorNotFoundException { 1125 NodeRevisionDescriptor revisionDescriptor = null; 1126 if (isForceStoreEnlistment(uri)) { 1127 enlist(revisionDescriptorStore); 1128 try { 1129 revisionDescriptor = 1130 revisionDescriptorStore.retrieveRevisionDescriptor 1131 (uri, revisionNumber); 1132 } catch (ServiceAccessException e) { 1133 delist(revisionDescriptorStore, false); 1134 throw e; 1135 } catch (RevisionDescriptorNotFoundException e) { 1136 delist(revisionDescriptorStore); 1138 throw e; 1139 } catch (Throwable t) { 1140 delist(revisionDescriptorStore, false); 1141 throw new ServiceAccessException 1143 (revisionDescriptorStore, t); 1144 } 1145 delist(revisionDescriptorStore); 1146 } else { 1147 try { 1148 revisionDescriptor = 1149 revisionDescriptorStore.retrieveRevisionDescriptor 1150 (uri, revisionNumber); 1151 } catch (ServiceAccessException e) { 1152 throw e; 1153 } catch (RevisionDescriptorNotFoundException e) { 1154 throw e; 1155 } catch (Throwable t) { 1156 throw new ServiceAccessException 1158 (revisionDescriptorStore, t); 1159 } 1160 } 1161 revisionDescriptor.validate(); 1162 return revisionDescriptor; 1163 } 1164 1165 1166 1173 public void createRevisionDescriptor 1174 (Uri uri, NodeRevisionDescriptor revisionDescriptor) 1175 throws ServiceAccessException { 1176 revisionDescriptor.validate(); 1177 1178 enlist(propertiesIndexer); 1179 enlist(revisionDescriptorStore); 1180 try { 1181 propertiesIndexer.createIndex (uri, revisionDescriptor, null); 1182 revisionDescriptorStore.createRevisionDescriptor 1183 (uri, revisionDescriptor); 1184 1185 } catch (ServiceAccessException e) { 1186 delist (propertiesIndexer, false); 1187 delist(revisionDescriptorStore, false); 1188 throw e; 1189 } catch (Throwable t) { 1190 delist (propertiesIndexer, false); 1191 delist(revisionDescriptorStore, false); 1192 throw new ServiceAccessException 1194 (revisionDescriptorStore, t); 1195 } 1196 delist (propertiesIndexer); 1197 delist (revisionDescriptorStore); 1198 } 1199 1200 1201 1210 public void storeRevisionDescriptor 1211 (Uri uri, NodeRevisionDescriptor revisionDescriptor) 1212 throws ServiceAccessException, RevisionDescriptorNotFoundException { 1213 revisionDescriptor.validate(); 1214 1215 enlist (propertiesIndexer); 1216 enlist(revisionDescriptorStore); 1217 try { 1218 propertiesIndexer.updateIndex (uri, revisionDescriptor, null); 1219 revisionDescriptorStore.storeRevisionDescriptor 1220 (uri, revisionDescriptor); 1221 1222 } catch (ServiceAccessException e) { 1223 delist (propertiesIndexer, false); 1224 delist(revisionDescriptorStore, false); 1225 throw e; 1226 } catch (RevisionDescriptorNotFoundException e) { 1227 delist (propertiesIndexer); 1228 delist(revisionDescriptorStore); 1229 throw e; 1230 } catch (Throwable t) { 1231 delist (propertiesIndexer, false); 1232 delist(revisionDescriptorStore, false); 1233 throw new ServiceAccessException 1235 (revisionDescriptorStore, t); 1236 } 1237 delist (propertiesIndexer); 1238 delist(revisionDescriptorStore); 1239 } 1240 1241 1242 1249 public void removeRevisionDescriptor (Uri uri, NodeRevisionNumber number) 1250 throws ServiceAccessException 1251 { 1252 number.validate(); 1253 1254 enlist(propertiesIndexer); 1255 enlist(revisionDescriptorStore); 1256 1257 try { 1258 propertiesIndexer.dropIndex (uri, number); 1259 revisionDescriptorStore.removeRevisionDescriptor(uri, number); 1260 } catch (ServiceAccessException e) { 1261 delist(propertiesIndexer, false); 1262 delist(revisionDescriptorStore, false); 1263 throw e; 1264 } catch (Throwable t) { 1265 delist(propertiesIndexer, false); 1266 delist(revisionDescriptorStore, false); 1267 1268 throw new ServiceAccessException 1270 (revisionDescriptorStore, t); 1271 } 1272 delist(propertiesIndexer); 1273 delist(revisionDescriptorStore); 1274 } 1275 1276 1277 1283 public NodeRevisionContent retrieveRevisionContent 1284 (Uri uri, NodeRevisionDescriptor revisionDescriptor) 1285 throws ServiceAccessException, RevisionNotFoundException { 1286 NodeRevisionContent revisionContent = null; 1287 if (isForceStoreEnlistment(uri)) { 1288 enlist(contentStore); 1289 try { 1290 revisionContent = 1291 contentStore.retrieveRevisionContent 1292 (uri, revisionDescriptor); 1293 1294 } catch (ServiceAccessException e) { 1295 delist(contentStore, false); 1296 throw e; 1297 } catch (RevisionNotFoundException e) { 1298 delist(contentStore); 1300 throw e; 1301 } catch (Throwable t) { 1302 delist(contentStore, false); 1303 throw new ServiceAccessException 1305 (contentStore, t); 1306 } 1307 delist(contentStore); 1308 } else { 1309 try { 1310 revisionContent = 1311 contentStore.retrieveRevisionContent 1312 (uri, revisionDescriptor); 1313 } catch (ServiceAccessException e) { 1314 throw e; 1315 } catch (RevisionNotFoundException e) { 1316 throw e; 1317 } catch (Throwable t) { 1318 throw new ServiceAccessException 1320 (contentStore, t); 1321 } 1322 } 1323 revisionContent.validate(); 1324 return revisionContent; 1325 } 1326 1327 1328 1335 public void createRevisionContent 1336 (Uri uri, NodeRevisionDescriptor revisionDescriptor, 1337 NodeRevisionContent revisionContent) 1338 throws ServiceAccessException, RevisionAlreadyExistException 1339 { 1340 revisionDescriptor.validate(); 1341 revisionContent.validate(); 1342 1343 enlist(contentIndexer); 1344 enlist(contentStore); 1345 try { 1346 contentIndexer.createIndex (uri, revisionDescriptor, revisionContent); 1347 contentStore.createRevisionContent(uri, revisionDescriptor, 1348 revisionContent); 1349 1350 } catch (ServiceAccessException e) { 1351 delist(contentIndexer, false); 1352 delist(contentStore, false); 1353 throw e; 1354 } catch (RevisionAlreadyExistException e) { 1355 delist(contentIndexer); 1356 delist(contentStore); 1357 throw e; 1358 } catch (Throwable t) { 1359 delist(contentIndexer, false); 1360 delist(contentStore, false); 1361 throw new ServiceAccessException(contentStore, t); 1363 } 1364 delist(contentIndexer); 1365 delist(contentStore); 1366 } 1367 1368 1369 1376 public void storeRevisionContent 1377 (Uri uri, NodeRevisionDescriptor revisionDescriptor, 1378 NodeRevisionContent revisionContent) 1379 throws ServiceAccessException, RevisionNotFoundException { 1380 revisionDescriptor.validate(); 1381 revisionContent.validate(); 1382 1383 enlist (contentIndexer); 1384 enlist(contentStore); 1385 try { 1386 contentIndexer.updateIndex (uri, revisionDescriptor, revisionContent); 1387 contentStore.storeRevisionContent(uri, revisionDescriptor, 1388 revisionContent); 1389 } catch (ServiceAccessException e) { 1390 delist (contentIndexer, false); 1391 delist (contentStore, false); 1392 throw e; 1393 } catch (RevisionNotFoundException e) { 1394 delist(contentIndexer); 1395 delist(contentStore); 1396 throw e; 1397 } catch (Throwable t) { 1398 delist(contentIndexer, false); 1399 delist(contentStore, false); 1400 1401 throw new ServiceAccessException (contentStore, t); 1403 } 1404 1405 delist(contentIndexer); 1406 delist(contentStore); 1407 } 1408 1409 1410 1416 public void removeRevisionContent 1417 (Uri uri, NodeRevisionDescriptor revisionDescriptor) 1418 throws ServiceAccessException { 1419 revisionDescriptor.validate(); 1420 1421 enlist(contentIndexer); 1422 enlist(contentStore); 1423 1424 try { 1425 contentIndexer.dropIndex (uri, revisionDescriptor.getRevisionNumber()); 1426 contentStore.removeRevisionContent(uri, revisionDescriptor); 1427 1428 } catch (ServiceAccessException e) { 1429 delist(contentIndexer, false); 1430 delist(contentStore, false); 1431 throw e; 1432 } catch (Throwable t) { 1433 delist(contentIndexer, false); 1434 delist(contentStore, false); 1435 1436 throw new ServiceAccessException(contentStore, t); 1438 } 1439 1440 delist(contentIndexer); 1441 delist(contentStore); 1442 } 1443 1444 1445 1447 1448 1451 protected boolean isForceStoreEnlistment(Uri uri) { 1452 1453 SlideToken token = uri.getToken(); 1454 1455 if (token == null) 1456 return false; 1457 1458 return token.isForceStoreEnlistment(); 1459 1460 } 1461 1462 1463 1468 protected void addResourceManager(Service service) { 1469 if (service == null) 1470 return; 1471 for (int i = 0; i < resourceManagers.length; i++) { 1473 try { 1474 if (resourceManagers[i].isSameRM(service)) 1475 return; 1476 } catch (XAException e) { 1477 } 1478 } 1479 Service results[] = new Service[resourceManagers.length + 1]; 1480 System.arraycopy(resourceManagers, 0, results, 0, 1481 resourceManagers.length); 1482 results[resourceManagers.length] = service; 1483 resourceManagers = results; 1484 } 1485 1486 1487 1490 protected void enlist() 1491 throws ServiceAccessException { 1492 enlist(this); 1493 } 1494 1495 1496 1499 protected void enlist(Service service) 1500 throws ServiceAccessException { 1501 boolean enlisted = false; 1503 int nbTry = 0; 1505 while ((!enlisted) && (nbTry++ < 20)) { 1506 Transaction transaction = null; 1507 try { 1508 transaction = 1509 namespace.getTransactionManager().getTransaction(); 1510 } catch (Exception e) { 1511 } 1512 if (transaction == null) { 1513 getLogger().log("WARNING: No active transaction", Logger.WARNING); 1514 return; 1515 } 1516 try { 1517 enlisted = transaction.enlistResource(service); 1518 } catch (Exception e) { 1519 setRollbackOnly(); 1521 throw new ServiceAccessException(this, e); 1522 } 1523 if (!enlisted) { 1524 try { 1525 Thread.sleep(200); 1526 } catch (InterruptedException e) { 1527 } 1529 } 1530 } 1531 if (!enlisted) { 1532 String exMessage = Messages.format 1533 (AbstractStore.class.getName() + ".enlistFail", service); 1534 setRollbackOnly(); 1535 throw new ServiceAccessException(this, exMessage); 1536 } 1537 if (getLogger().isEnabled(LOG_CHANNEL, Logger.DEBUG)) { 1538 String logMessage = Messages.format 1539 (AbstractStore.class.getName() + ".enlist", service); 1540 getLogger().log(logMessage, LOG_CHANNEL, Logger.DEBUG); 1541 } 1542 } 1543 1544 1545 1548 protected void delist(boolean success) 1549 throws ServiceAccessException { 1550 delist(this, success); 1551 } 1552 1553 1554 1557 protected void delist(Service service) 1558 throws ServiceAccessException { 1559 delist(service, true); 1560 } 1561 1562 1563 1566 protected void delist(Service service, boolean success) 1567 throws ServiceAccessException { 1568 try { 1569 Transaction transaction = 1570 namespace.getTransactionManager().getTransaction(); 1571 if (transaction == null) 1572 return; 1573 if (success) { 1574 transaction.delistResource(service, TMSUSPEND); 1575 if (getLogger().isEnabled(LOG_CHANNEL, Logger.DEBUG)) { 1576 String logMessage = Messages.format 1577 (AbstractStore.class.getName() + ".delist", service); 1578 getLogger().log(logMessage, LOG_CHANNEL, Logger.DEBUG); 1579 } 1580 } else { 1581 transaction.delistResource(service, TMFAIL); 1582 String logMessage = Messages.format 1583 (AbstractStore.class.getName() + ".delistFail", service); 1584 getLogger().log(logMessage, LOG_CHANNEL, Logger.DEBUG); 1585 } 1586 } catch (Exception e) { 1587 throw new ServiceAccessException(this, e); 1589 } 1590 } 1591 1592 1593 1596 protected void setRollbackOnly() { 1597 try { 1598 Transaction transaction = 1599 namespace.getTransactionManager().getTransaction(); 1600 if (transaction == null) 1601 return; 1602 transaction.setRollbackOnly(); 1603 } catch (Exception e) { 1604 } 1605 } 1606 1607 1611 public boolean useBinding() { 1612 return false; 1613 } 1614 1615 public void exclusiveTransientLock(String uri) throws ServiceAccessException { 1616 } 1617 1618} 1619 | Popular Tags |