KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > webdav > stores > CachedStore


1 package org.jahia.services.webdav.stores;
2
3 import org.apache.slide.common.*;
4 import org.apache.slide.content.*;
5 import org.apache.slide.lock.LockTokenNotFoundException;
6 import org.apache.slide.lock.NodeLock;
7 import org.apache.slide.security.NodePermission;
8 import org.apache.slide.store.AbstractStore;
9 import org.apache.slide.structure.ObjectAlreadyExistsException;
10 import org.apache.slide.structure.ObjectNode;
11 import org.apache.slide.structure.ObjectNotFoundException;
12 import org.jahia.services.cache.Cache;
13 import org.jahia.services.cache.CacheEntry;
14 import org.jahia.services.cache.CacheFactory;
15
16 import javax.transaction.xa.Xid JavaDoc;
17 import javax.transaction.xa.XAException JavaDoc;
18 import java.util.Date JavaDoc;
19 import java.util.Enumeration JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 /**
23  * Created by IntelliJ IDEA.
24  * User: toto
25  * Date: Jun 26, 2003
26  * Time: 1:29:06 PM
27  * To change this template use Options | File Templates.
28  */

29 public class CachedStore extends AbstractStore {
30     public static final String JavaDoc CACHE_NAME = "WebdavCache";
31
32     private static final int TEMP_CACHE_DELAY = 5000;
33
34     final private org.apache.log4j.Logger logger =
35             org.apache.log4j.Logger.getLogger (CachedStore.class);
36
37     // ----------------------------------------------------------- Constructors
38

39
40     /**
41      * Constructor. Handles caches initialization.
42      */

43     public CachedStore () {
44         super ();
45     }
46
47     // ----------------------------------------------------- Instance Variables
48

49     protected Cache internalCache;
50
51
52     // ---------------------------------------------------- ServiceImpl Methods
53

54
55     /**
56      * Initializes descriptors store.
57      *
58      * @throws org.apache.slide.common.ServiceInitializationFailedException
59      * Throws an exception
60      * if the descriptors store has already been initialized before
61      */

62     public void initialize (NamespaceAccessToken token)
63             throws ServiceInitializationFailedException {
64         super.initialize (token);
65         try {
66             internalCache = CacheFactory.createCache (CACHE_NAME);
67
68         } catch (Exception JavaDoc e) {
69             logger.warn ("Error while creating cache for slide store", e);
70             throw new ServiceInitializationFailedException (this, e);
71         }
72         logger.debug ("New Cache [" + CACHE_NAME + "] successfully instanciated!");
73     }
74
75
76     // ----------------------------------------------- DescriptorsStore Methods
77

78
79     /**
80      * Retrive an object from the Descriptors Store.
81      *
82      * @param uri Uri of the object we want to retrieve
83      *
84      * @throws org.apache.slide.common.ServiceAccessException
85      * Error accessing the Descriptors Store
86      * @throws org.apache.slide.structure.ObjectNotFoundException
87      * The object to retrieve was not found
88      */

89     public ObjectNode retrieveObject (Uri uri)
90             throws ServiceAccessException, ObjectNotFoundException {
91         if (nodeStore.cacheResults ()) {
92             Object JavaDoc tempObject = internalCache.get (
93                     "o" + uri.getNamespace ().getName () + uri.toString ());
94             if (tempObject != null) {
95                 return ((ObjectNode) tempObject).cloneObject ();
96             } else {
97                 ObjectNode objectNode = super.retrieveObject (uri);
98                 objectNode.validate (uri.toString ());
99                 if (!isForceStoreEnlistment (uri)) {
100                     cacheEntry ("o", (JahiaDescriptorsStore) nodeStore, uri, objectNode);
101                 }
102                 return objectNode;
103             }
104         } else {
105             return super.retrieveObject (uri);
106         }
107     }
108
109
110     /**
111      * Store an object in the Descriptors Store.
112      *
113      * @param object Object to update
114      *
115      * @throws org.apache.slide.common.ServiceAccessException
116      * Error accessing the Descriptors Store
117      * @throws org.apache.slide.structure.ObjectNotFoundException
118      * The object to update was not found
119      */

120     public void storeObject (Uri uri, ObjectNode object)
121             throws ServiceAccessException, ObjectNotFoundException {
122         super.storeObject (uri, object);
123         if (nodeStore.cacheResults ()) {
124             cacheEntry ("o", (JahiaDescriptorsStore) nodeStore, uri, object.cloneObject ());
125             flushParentFromCache("o", uri);
126         }
127     }
128
129
130     /**
131      * Create a new object in the Descriptors Store.
132      *
133      * @param object SlideObject
134      * @param uri Uri of the object we want to create
135      *
136      * @throws org.apache.slide.common.ServiceAccessException
137      * Error accessing the Descriptors Store
138      * @throws org.apache.slide.structure.ObjectAlreadyExistsException
139      * An object already exists
140      * at this Uri
141      */

142     public void createObject (Uri uri, ObjectNode object)
143             throws ServiceAccessException, ObjectAlreadyExistsException {
144         super.createObject (uri, object);
145         if (nodeStore.cacheResults ()) {
146             cacheEntry ("o", (JahiaDescriptorsStore) nodeStore, uri, object.cloneObject ());
147             flushParentFromCache("o", uri);
148         }
149     }
150
151     /**
152      * Remove an object from the Descriptors Store.
153      *
154      * @param object Object to remove
155      *
156      * @throws org.apache.slide.common.ServiceAccessException
157      * Error accessing the Descriptors Store
158      * @throws org.apache.slide.structure.ObjectNotFoundException
159      * The object to remove was not found
160      */

161     public void removeObject (Uri uri, ObjectNode object)
162             throws ServiceAccessException, ObjectNotFoundException {
163         super.removeObject (uri, object);
164         if (nodeStore.cacheResults ()) {
165             internalCache.remove ("o" + uri.getNamespace ().getName () + uri.toString ());
166             flushParentFromCache("o", uri);
167         }
168     }
169
170     public void removeObjectFromCache (Uri uri) {
171         if (nodeStore.cacheResults ()) {
172             internalCache.remove ("o" + uri.getNamespace ().getName () + uri.toString ());
173         }
174     }
175
176
177     /**
178      * Store an object permissions in the Descriptors Store.
179      *
180      * @param permission Permission we want to create
181      *
182      * @throws org.apache.slide.common.ServiceAccessException
183      * Error accessing the Descriptors Store
184      */

185     public void grantPermission (Uri uri, NodePermission permission)
186             throws ServiceAccessException {
187         super.grantPermission (uri, permission);
188         if (securityStore.cacheResults ()) {
189             NodePermission tempPermission = permission.cloneObject ();
190             Object JavaDoc value = internalCache.get (
191                     "p" + uri.getNamespace ().getName () + uri.toString ());
192             if (value == null) {
193                 // populate the cache with the existing entries
194
enumeratePermissions (uri);
195                 // and check if the cache contains a corresponding entry now
196
value = internalCache.get ("p" + uri.getNamespace ().getName () + uri.toString ());
197                 if (value == null) {
198                     // no permissions for the Uri in the cache, so create a new
199
// entry
200
Vector JavaDoc permissionsVector = new Vector JavaDoc ();
201                     permissionsVector.addElement (tempPermission);
202                     if (!isForceStoreEnlistment (uri)) {
203                         cacheEntry ("p", (JahiaDescriptorsStore) securityStore, uri,
204                                 permissionsVector);
205                     }
206                 }
207             } else {
208                 Vector JavaDoc permissionsVector = (Vector JavaDoc) value;
209                 permissionsVector.addElement (tempPermission);
210                 internalCache.put ("p" + uri.getNamespace ().getName () + uri.toString (), value);
211             }
212         }
213     }
214
215
216     /**
217      * Store an object permissions in the Descriptors Store.
218      *
219      * @param permission Permission we want to create
220      *
221      * @throws org.apache.slide.common.ServiceAccessException
222      * Error accessing the Descriptors Store
223      */

224     public void revokePermission (Uri uri, NodePermission permission)
225             throws ServiceAccessException {
226         super.revokePermission (uri, permission);
227         if (securityStore.cacheResults ()) {
228             internalCache.remove (
229                     "p" + uri.getNamespace ().getName () + uri.toString ());
230         }
231     }
232
233
234     /**
235      * Revoke all the permissions on the object.
236      *
237      * @param uri
238      *
239      * @throws org.apache.slide.common.ServiceAccessException
240      * Error accessing the Descriptors Store
241      */

242     public void revokePermissions (Uri uri)
243             throws ServiceAccessException {
244         super.revokePermissions (uri);
245         if (securityStore.cacheResults ()) {
246             Object JavaDoc value = internalCache.get (
247                     "p" + uri.getNamespace ().getName () + uri.toString ());
248             Vector JavaDoc permissionsVector = null;
249             if (value != null) {
250                 permissionsVector = (Vector JavaDoc) value;
251                 permissionsVector.removeAllElements ();
252                 internalCache.put("p" + uri.getNamespace ().getName () + uri.toString (), value);
253             }
254         }
255     }
256
257
258     /**
259      * Read an object permissions.
260      *
261      * @param uri
262      *
263      * @throws org.apache.slide.common.ServiceAccessException
264      * Error accessing the Descriptors Store
265      */

266     public Enumeration JavaDoc enumeratePermissions (Uri uri)
267             throws ServiceAccessException {
268         // TODO : The vectors elements MUST be cloned
269
if (securityStore.cacheResults ()) {
270             Object JavaDoc value = internalCache.get (
271                     "p" + uri.getNamespace ().getName () + uri.toString ());
272             Vector JavaDoc permissionsVector = null;
273             if (value != null) {
274                 permissionsVector = new Vector JavaDoc ((Vector JavaDoc) value);
275                 return permissionsVector.elements ();
276             } else {
277                 permissionsVector = new Vector JavaDoc ();
278                 Enumeration JavaDoc tempEnum = super.enumeratePermissions (uri);
279                 while (tempEnum.hasMoreElements ()) {
280                     NodePermission tempPermission =
281                             (NodePermission) tempEnum.nextElement ();
282                     tempPermission.validate (uri.toString ());
283                     permissionsVector.addElement (tempPermission);
284                 }
285                 if (!isForceStoreEnlistment (uri)) {
286                     cacheEntry ("p", (JahiaDescriptorsStore) securityStore, uri,
287                             permissionsVector);
288                 }
289                 return ((Vector JavaDoc) permissionsVector.clone ()).elements ();
290             }
291         } else {
292             return super.enumeratePermissions (uri);
293         }
294     }
295
296
297     /**
298      * Puts a lock on a subject.
299      *
300      * @param lock Lock token
301      *
302      * @throws org.apache.slide.common.ServiceAccessException
303      * Service access error
304      */

305     public void putLock (Uri uri, NodeLock lock)
306             throws ServiceAccessException {
307         super.putLock (uri, lock);
308         if (lockStore.cacheResults ()) {
309             Object JavaDoc value = internalCache.get (
310                     "l" + uri.getNamespace ().getName () + uri.toString ());
311             Vector JavaDoc locksVector = null;
312             if (value == null) {
313                 locksVector = new Vector JavaDoc ();
314                 cacheEntry ("l", (JahiaDescriptorsStore) lockStore, uri, locksVector);
315             } else {
316                 locksVector = (Vector JavaDoc) value;
317             }
318             locksVector.addElement (lock.cloneObject ());
319             cacheEntry ("l", (JahiaDescriptorsStore) lockStore, uri, locksVector);
320         }
321     }
322
323
324     /**
325      * Renews a lock.
326      *
327      * @param lock Token to renew
328      *
329      * @throws org.apache.slide.common.ServiceAccessException
330      * Service access error
331      * @throws org.apache.slide.lock.LockTokenNotFoundException
332      * Lock token was not found
333      */

334     public void renewLock (Uri uri, NodeLock lock)
335             throws ServiceAccessException, LockTokenNotFoundException {
336         super.renewLock (uri, lock);
337         if (lockStore.cacheResults ()) {
338             Object JavaDoc value = internalCache.get (
339                     "l" + uri.getNamespace ().getName () + uri.toString ());
340             Vector JavaDoc locksVector = null;
341             if (value != null) {
342                 locksVector = (Vector JavaDoc) value;
343                 boolean wasPresent = locksVector.removeElement (lock);
344                 if (!wasPresent) {
345                     throw new LockTokenNotFoundException (lock);
346                 }
347                 locksVector.addElement (lock.cloneObject ());
348                 internalCache.put (
349                     "l" + uri.getNamespace ().getName () + uri.toString (), value);
350             }
351         }
352     }
353
354
355     /**
356      * Removes (cancels) a lock.
357      *
358      * @param lock Token to remove
359      *
360      * @throws org.apache.slide.common.ServiceAccessException
361      * Service access error
362      * @throws org.apache.slide.lock.LockTokenNotFoundException
363      * Lock token was not found
364      */

365     public void removeLock (Uri uri, NodeLock lock)
366             throws ServiceAccessException, LockTokenNotFoundException {
367         super.removeLock (uri, lock);
368         if (lockStore.cacheResults ()) {
369             Object JavaDoc value = internalCache.get (
370                     "l" + uri.getNamespace ().getName () + uri.toString ());
371             Vector JavaDoc locksVector = null;
372             if (value != null) {
373                 locksVector = (Vector JavaDoc) value;
374                 boolean wasPresent = locksVector.removeElement (lock);
375                 if (!wasPresent) {
376                     throw new LockTokenNotFoundException (lock);
377                 }
378                 internalCache.put (
379                     "l" + uri.getNamespace ().getName () + uri.toString (), value);
380             }
381         }
382     }
383
384
385     /**
386      * Kills a lock.
387      *
388      * @param lock Token to remove
389      *
390      * @throws org.apache.slide.common.ServiceAccessException
391      * Service access error
392      * @throws org.apache.slide.lock.LockTokenNotFoundException
393      * Lock token was not found
394      */

395     public void killLock (Uri uri, NodeLock lock)
396             throws ServiceAccessException, LockTokenNotFoundException {
397         super.killLock (uri, lock);
398         if (lockStore.cacheResults ()) {
399             Object JavaDoc value = internalCache.get (
400                     "l" + uri.getNamespace ().getName () + uri.toString ());
401             Vector JavaDoc locksVector = null;
402             if (value != null) {
403                 locksVector = (Vector JavaDoc) value;
404                 boolean wasPresent = locksVector.removeElement (lock);
405                 if (!wasPresent) {
406                     throw new LockTokenNotFoundException (lock);
407                 }
408                 internalCache.put (
409                     "l" + uri.getNamespace ().getName () + uri.toString (), value);
410             }
411         }
412     }
413
414
415     /**
416      * Returns the list of locks put on a subject.
417      *
418      * @param uri
419      *
420      * @return Enumeration List of locks which have been put on the subject
421      *
422      * @throws org.apache.slide.common.ServiceAccessException
423      * Service access error
424      */

425     public Enumeration JavaDoc enumerateLocks (Uri uri)
426             throws ServiceAccessException {
427         if (lockStore.cacheResults ()) {
428             Object JavaDoc value = internalCache.get (
429                     "l" + uri.getNamespace ().getName () + uri.toString ());
430             Vector JavaDoc locksVector = null;
431             if (value == null) {
432                 locksVector = new Vector JavaDoc ();
433                 Enumeration JavaDoc lockList = super.enumerateLocks (uri);
434                 while (lockList.hasMoreElements ()) {
435                     NodeLock tempLock = (NodeLock) lockList.nextElement ();
436                     tempLock.validate (uri.toString ());
437                     locksVector.addElement (tempLock);
438                 }
439                 if (!isForceStoreEnlistment (uri)) {
440                     cacheEntry ("l", (JahiaDescriptorsStore) lockStore, uri, locksVector);
441                 }
442             } else {
443                 locksVector = (Vector JavaDoc) value;
444             }
445             return ((Vector JavaDoc) locksVector.clone ()).elements ();
446         } else {
447             return super.enumerateLocks (uri);
448         }
449     }
450
451
452     /**
453      * Retrieve a revision descriptors.
454      *
455      * @param uri Uri
456      *
457      * @throws org.apache.slide.common.ServiceAccessException
458      * Service access error
459      * @throws org.apache.slide.content.RevisionDescriptorNotFoundException
460      * Revision descriptor
461      * was not found
462      */

463     public NodeRevisionDescriptors retrieveRevisionDescriptors (Uri uri)
464             throws ServiceAccessException, RevisionDescriptorNotFoundException {
465         if (revisionDescriptorsStore.cacheResults ()) {
466             Object JavaDoc tempObject = internalCache.get (
467                     "d" + uri.getNamespace ().getName () + uri.toString ());
468             if (tempObject != null) {
469                 return ((NodeRevisionDescriptors) tempObject).cloneObject ();
470             } else {
471                 NodeRevisionDescriptors revisionDescriptors =
472                         super.retrieveRevisionDescriptors (uri);
473                 revisionDescriptors = revisionDescriptors.cloneObject ();
474                 if (!isForceStoreEnlistment (uri)) {
475                     cacheEntry ("d", (JahiaDescriptorsStore) revisionDescriptorsStore, uri,
476                             revisionDescriptors);
477                 }
478                 revisionDescriptors.validate (uri.toString ());
479                 return revisionDescriptors;
480             }
481         } else {
482             return super.retrieveRevisionDescriptors (uri);
483         }
484     }
485
486
487     /**
488      * Create new revision descriptors.
489      *
490      * @param uri Uri
491      * @param revisionDescriptors Node revision descriptors
492      *
493      * @throws org.apache.slide.common.ServiceAccessException
494      * Service access error
495      */

496     public void createRevisionDescriptors
497             (Uri uri, NodeRevisionDescriptors revisionDescriptors)
498             throws ServiceAccessException {
499         super.createRevisionDescriptors (uri, revisionDescriptors);
500         if (revisionDescriptorsStore.cacheResults ()) {
501             cacheEntry ("d", (JahiaDescriptorsStore) revisionDescriptorsStore, uri,
502                     revisionDescriptors.cloneObject ());
503         }
504     }
505
506
507     /**
508      * Update revision descriptors.
509      *
510      * @param uri Uri
511      * @param revisionDescriptors Node revision descriptors
512      *
513      * @throws org.apache.slide.common.ServiceAccessException
514      * Service access error
515      * @throws org.apache.slide.content.RevisionDescriptorNotFoundException
516      * Revision descriptor
517      * was not found
518      */

519     public void storeRevisionDescriptors
520             (Uri uri, NodeRevisionDescriptors revisionDescriptors)
521             throws ServiceAccessException, RevisionDescriptorNotFoundException {
522         super.storeRevisionDescriptors (uri, revisionDescriptors);
523         if (revisionDescriptorsStore.cacheResults ()) {
524             cacheEntry ("d", (JahiaDescriptorsStore) revisionDescriptorsStore, uri,
525                     revisionDescriptors.cloneObject ());
526         }
527     }
528
529
530     /**
531      * Remove revision descriptors.
532      *
533      * @param uri Uri
534      *
535      * @throws org.apache.slide.common.ServiceAccessException
536      * Service access error
537      */

538     public void removeRevisionDescriptors (Uri uri)
539             throws ServiceAccessException {
540         if (revisionDescriptorsStore.cacheResults ()) {
541             internalCache.remove ("d" + uri.getNamespace ().getName () + uri.toString ());
542         }
543         super.removeRevisionDescriptors (uri);
544     }
545
546
547     /**
548      * Retrieve revision descriptor.
549      *
550      * @param uri
551      * @param revisionNumber Node revision number
552      */

553     public NodeRevisionDescriptor retrieveRevisionDescriptor
554             (Uri uri, NodeRevisionNumber revisionNumber)
555             throws ServiceAccessException, RevisionDescriptorNotFoundException {
556         if (revisionDescriptorStore.cacheResults ()) {
557             Object JavaDoc result = internalCache.get (
558                     "D" + revisionNumber + "-" + uri.getNamespace ().getName () + uri);
559             if (result != null) {
560                 return ((NodeRevisionDescriptor) result).cloneObject ();
561             } else {
562                 NodeRevisionDescriptor revisionDescriptor =
563                         super
564                         .retrieveRevisionDescriptor (uri, revisionNumber)
565                         .cloneObject ();
566                 revisionDescriptor.validate ();
567                 if (!isForceStoreEnlistment (uri)) {
568                     cacheEntry ("D" + revisionNumber + "-",
569                             (JahiaDescriptorsStore) revisionDescriptorStore, uri,
570                             revisionDescriptor);
571                 }
572                 return revisionDescriptor;
573             }
574         } else {
575             return super.retrieveRevisionDescriptor (uri, revisionNumber);
576         }
577     }
578
579
580     /**
581      * Create new revision descriptor.
582      *
583      * @param uri Uri
584      * @param revisionDescriptor Node revision descriptor
585      *
586      * @throws org.apache.slide.common.ServiceAccessException
587      * Service access error
588      */

589     public void createRevisionDescriptor
590             (Uri uri, NodeRevisionDescriptor revisionDescriptor)
591             throws ServiceAccessException {
592         super.createRevisionDescriptor (uri, revisionDescriptor);
593         if (revisionDescriptorStore.cacheResults ()) {
594             cacheEntry ("D" + revisionDescriptor.getRevisionNumber () + "-",
595                     (JahiaDescriptorsStore) revisionDescriptorStore, uri,
596                     revisionDescriptor.cloneObject ());
597         }
598     }
599
600
601     /**
602      * Update revision descriptor.
603      *
604      * @param uri Uri
605      * @param revisionDescriptor Node revision descriptor
606      *
607      * @throws org.apache.slide.common.ServiceAccessException
608      * Service access error
609      * @throws org.apache.slide.content.RevisionDescriptorNotFoundException
610      * Revision descriptor
611      * was not found
612      */

613     public void storeRevisionDescriptor
614             (Uri uri, NodeRevisionDescriptor revisionDescriptor)
615             throws ServiceAccessException, RevisionDescriptorNotFoundException {
616         super.storeRevisionDescriptor (uri, revisionDescriptor);
617         if (revisionDescriptorStore.cacheResults ()) {
618             cacheEntry ("D" + revisionDescriptor.getRevisionNumber () + "-",
619                     (JahiaDescriptorsStore) revisionDescriptorStore, uri,
620                     revisionDescriptor.cloneObject ());
621         }
622     }
623
624
625     /**
626      * Remove revision descriptor.
627      *
628      * @param uri Uri
629      * @param number Revision number
630      *
631      * @throws org.apache.slide.common.ServiceAccessException
632      * Service access error
633      */

634     public void removeRevisionDescriptor (Uri uri, NodeRevisionNumber number)
635             throws ServiceAccessException {
636         super.removeRevisionDescriptor (uri, number);
637         if (revisionDescriptorStore.cacheResults ()) {
638             internalCache.remove ("D" + number + "-" + uri.getNamespace ().getName () + uri);
639         }
640     }
641
642
643     /**
644      * Retrive revision content.
645      *
646      * @param uri Uri
647      * @param revisionDescriptor
648      */

649     public NodeRevisionContent retrieveRevisionContent
650             (Uri uri, NodeRevisionDescriptor revisionDescriptor)
651             throws ServiceAccessException, RevisionNotFoundException {
652         return super.retrieveRevisionContent (uri, revisionDescriptor);
653     }
654
655
656     /**
657      * Create a new revision
658      *
659      * @param uri Uri
660      * @param revisionDescriptor Node revision descriptor
661      * @param revisionContent Node revision content
662      */

663     public void createRevisionContent
664             (Uri uri, NodeRevisionDescriptor revisionDescriptor,
665              NodeRevisionContent revisionContent)
666             throws ServiceAccessException, RevisionAlreadyExistException {
667         super.createRevisionContent (uri, revisionDescriptor, revisionContent);
668     }
669
670
671     /**
672      * Modify the latest revision of an object.
673      *
674      * @param uri Uri
675      * @param revisionDescriptor Node revision descriptor
676      * @param revisionContent Node revision content
677      */

678     public void storeRevisionContent
679             (Uri uri, NodeRevisionDescriptor revisionDescriptor,
680              NodeRevisionContent revisionContent)
681             throws ServiceAccessException, RevisionNotFoundException {
682         super.storeRevisionContent (uri, revisionDescriptor, revisionContent);
683     }
684
685
686     /**
687      * Remove revision.
688      *
689      * @param uri Uri
690      * @param revisionDescriptor Node revision number
691      */

692     public void removeRevisionContent (Uri uri,
693                                        NodeRevisionDescriptor revisionDescriptor)
694             throws ServiceAccessException {
695         super.removeRevisionContent (uri, revisionDescriptor);
696     }
697
698
699     /**
700      * Return the name of this store
701      */

702     public String JavaDoc toString () {
703         return getName () + "(" + getClass ().getName () + ")";
704     }
705
706
707     // ------------------------------------------------------ Protected Methods
708

709
710     /**
711      * Reset the caches.
712      */

713     protected void resetCaches () {
714         internalCache.flush ();
715     }
716
717     private void cacheEntry (String JavaDoc keyPrefix, JahiaDescriptorsStore store, Uri uri,
718                              Object JavaDoc object) {
719         try {
720             PathItem pathItem = store.getPathItem(uri);
721             if ((pathItem.type & JahiaDescriptorsStore.TEMP_CACHEABLE) != 0) {
722                 CacheEntry cEntry = new CacheEntry (object);
723                 cEntry.setExpirationDate (new Date JavaDoc (System.currentTimeMillis () + TEMP_CACHE_DELAY));
724                 internalCache.putCacheEntry (
725                         keyPrefix + uri.getNamespace ().getName () + uri.toString (), cEntry, true);
726             } else if ((pathItem.type & JahiaDescriptorsStore.UNCACHEABLE) == 0)
727                 internalCache.put (keyPrefix + uri.getNamespace ().getName () + uri.toString (),
728                         object);
729         } catch (ServiceAccessException e) {
730         }
731     }
732
733     private void flushParentFromCache(String JavaDoc keyPrefix, Uri uri) {
734         if ("o".equals(keyPrefix)) {
735             // let's look for the parent entry and flush it from the cache.
736
Uri parentUri = uri.getParentUri();
737             if (parentUri != null) {
738                 logger.debug("Flusing parent entry : [" + "o" +
739                              parentUri.getNamespace().getName() +
740                              parentUri.toString() + "]");
741                 internalCache.remove("o" + parentUri.getNamespace().getName() +
742                                      parentUri.toString());
743             }
744         }
745     }
746
747     public void rollback(Xid JavaDoc xid) throws XAException JavaDoc {
748         resetCaches();
749         super.rollback(xid);
750     }
751
752     protected void enlist(Service service) throws ServiceAccessException {
753         if (service instanceof JahiaDescriptorsStore) {
754             super.enlist(this);
755         }
756         super.enlist(service);
757     }
758
759     protected void delist(Service service, boolean b) throws ServiceAccessException {
760         super.delist(service, b);
761         if (service instanceof JahiaDescriptorsStore) {
762             super.delist(this, b);
763         }
764     }
765
766 }
767
Popular Tags