KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2006 Jahia Ltd
3  *
4  * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (JCDDL),
5  * Version 1.0 (the "License"), or (at your option) any later version; you may
6  * not use this file except in compliance with the License. You should have
7  * received a copy of the License along with this program; if not, you may obtain
8  * a copy of the License at
9  *
10  * http://www.jahia.org/license/
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
package org.jahia.services.webdav.stores;
18
19 import org.apache.slide.common.ServiceAccessException;
20 import org.apache.slide.common.Uri;
21 import org.apache.slide.content.NodeRevisionDescriptor;
22 import org.apache.slide.content.RevisionDescriptorNotFoundException;
23 import org.apache.slide.store.BindingStore;
24 import org.apache.slide.store.ExtendedStore;
25 import org.apache.slide.structure.ObjectNode;
26 import org.apache.slide.structure.ObjectNotFoundException;
27 import org.apache.slide.util.ByteSizeLimitedObjectCache;
28 import org.apache.slide.util.TxLRUObjectCache;
29 import org.apache.slide.util.logger.Logger;
30 import org.jahia.exceptions.JahiaInitializationException;
31 import org.jahia.services.cache.Cache;
32 import org.jahia.services.cache.CacheFactory;
33
34 import java.util.Collection JavaDoc;
35 import java.util.HashSet JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.Set JavaDoc;
38
39 /**
40  * Created by IntelliJ IDEA.
41  * Date: 4 oct. 2005 - 14:58:07
42  *
43  * @author toto
44  * @version $Id: JahiaBindingStore.java 14815 2006-07-31 14:23:42Z tdraier $
45  */

46 public class JahiaBindingStore extends BindingStore {
47     // overwrites inherited
48
public void storeRevisionDescriptor(Uri uri, NodeRevisionDescriptor revisionDescriptor) throws ServiceAccessException, RevisionDescriptorNotFoundException {
49         super.storeRevisionDescriptor(uri, revisionDescriptor);
50         if (uri.toString().startsWith("/users")) {
51             ((TxCacheWrapper)objectsCache).remove("/users");
52         }
53         if (uri.toString().startsWith("/groups")) {
54             ((TxCacheWrapper)objectsCache).remove("/groups");
55         }
56     }
57
58     // overwrites inherited
59
public void storeObject(Uri uri, ObjectNode object) throws ServiceAccessException, ObjectNotFoundException {
60         super.storeObject(uri, object);
61         objectsCache.remove(uri.toString());
62     }
63
64     // have it outside ctor to make it overloadable
65
protected void init(
66         int globalObjectCacheSize,
67         int globalPermissionCacheSize,
68         int globalLockCacheSize,
69         int globalDescrtiptorsCacheSize,
70         int globalDescrtiptorCacheSize,
71         boolean contentCachingEnabled,
72         int globalContentCacheSize,
73         long contentCacheBytes,
74         int txContentCacheSize,
75         long txContentCacheBytes,
76         long maxByteSizePerEntry,
77         boolean noGlobalCacheInTx) {
78         try {
79             objectsCache = new TxCacheWrapper(globalObjectCacheSize, "object", noGlobalCacheInTx);
80             permissionsCache = new TxCacheWrapper(globalPermissionCacheSize, "permission", noGlobalCacheInTx);
81             locksCache = new TxCacheWrapper(globalLockCacheSize, "lock", noGlobalCacheInTx);
82             descriptorsCache = new TxCacheWrapper(globalDescrtiptorsCacheSize, "descriptors", noGlobalCacheInTx);
83             descriptorCache = new TxCacheWrapper(globalDescrtiptorCacheSize, "descriptor", noGlobalCacheInTx);
84
85             if (contentCachingEnabled) {
86                 contentCache =
87                     new TxContentCacheWrapper(
88                         new ByteSizeLimitedObjectCache(
89                             globalContentCacheSize,
90                             txContentCacheSize,
91                             contentCacheBytes,
92                             txContentCacheBytes,
93                             maxByteSizePerEntry,
94                             getName() + ".content",
95                             getLogger(),
96                             noGlobalCacheInTx));
97             } else {
98                 contentCache = null;
99             }
100         } catch (Error JavaDoc e) {
101             fatalError(e);
102         } catch (RuntimeException JavaDoc re) {
103             fatalError(re);
104         }
105     }
106
107     protected void invalidateCacheUponError(Uri uri) {
108         return;
109     }
110
111     protected class TxCacheWrapper extends ExtendedStore.TxCacheWrapper {
112         public TxCacheWrapper(int globalCacheSize, String JavaDoc name, boolean noGlobalCacheInTx) {
113             super(new JahiaTxLRUObjectCache(globalCacheSize, getName() + "." + name, getLogger(), noGlobalCacheInTx));
114         }
115     }
116
117     private class JahiaTxLRUObjectCache extends TxLRUObjectCache {
118         private Cache jahiaCache;
119
120         protected void prune(Map JavaDoc map, Object JavaDoc key, String JavaDoc delimiter) {
121             map.clear();
122         }
123
124         protected void deprune(Set JavaDoc set, Object JavaDoc key, String JavaDoc delimiter) {
125             return;
126         }
127
128         public JahiaTxLRUObjectCache(int globalCacheSize, String JavaDoc name, Logger logger, boolean noGlobalCachingInsideTx) {
129             super(globalCacheSize, name, logger, noGlobalCachingInsideTx);
130
131             try {
132                 jahiaCache = CacheFactory.getInstance().createCacheInstance(name);
133                 globalCache = new Map JavaDoc() {
134                     public Collection JavaDoc values() {
135                         return null;
136                     }
137
138                     public int size() {
139                         return jahiaCache.size();
140                     }
141
142                     public Object JavaDoc remove(Object JavaDoc key) {
143                         if (namespace == null) {
144                             return null;
145                         }
146                         key = namespace.getName() + "." + key;
147                         Object JavaDoc r = jahiaCache.get(key);
148                         jahiaCache.remove(key);
149                         return r;
150                     }
151
152                     public void putAll(Map JavaDoc t) {
153                     }
154
155                     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
156                         if (namespace == null) {
157                             return null;
158                         }
159                         key = namespace.getName() + "." + key;
160                         Object JavaDoc r = jahiaCache.get(key);
161                         jahiaCache.put(key, value);
162                         return r;
163                     }
164
165                     public Set JavaDoc keySet() {
166                         return new HashSet JavaDoc();
167                     }
168
169                     public boolean isEmpty() {
170                         return false;
171                     }
172
173                     public Object JavaDoc get(Object JavaDoc key) {
174                         if (namespace == null) {
175                             return null;
176                         }
177                         key = namespace.getName() + "." + key;
178                         return jahiaCache.get(key);
179                     }
180
181                     public Set JavaDoc entrySet() {
182                         return null;
183                     }
184
185                     public boolean containsValue(Object JavaDoc value) {
186                         return false;
187                     }
188
189                     public boolean containsKey(Object JavaDoc key) {
190                         return false;
191                     }
192
193                     public void clear() {
194                         jahiaCache.flush();
195                     }
196                 };
197             } catch (JahiaInitializationException e) {
198                 e.printStackTrace();
199             }
200         }
201
202         public synchronized Object JavaDoc get(Object JavaDoc txId, Object JavaDoc key) {
203             return super.get(null, key);
204         }
205
206         public synchronized void put(Object JavaDoc txId, Object JavaDoc key, Object JavaDoc value, long timeout) {
207             super.put(null, key, value, timeout);
208         }
209
210         public synchronized void put(Object JavaDoc txId, Object JavaDoc key, Object JavaDoc value) {
211             super.put(null, key, value);
212         }
213
214         public synchronized void remove(Object JavaDoc txId, Object JavaDoc key) {
215             super.remove(null, key);
216         }
217
218         public synchronized void remove(Object JavaDoc txId, Object JavaDoc key, String JavaDoc delimiter) {
219             super.remove(null, key, delimiter);
220         }
221
222         public synchronized void start(Object JavaDoc txId) {
223             return;
224         }
225
226         public synchronized void rollback(Object JavaDoc txId) {
227             return;
228         }
229
230         public synchronized void forget(Object JavaDoc txId) {
231             return;
232         }
233
234         protected void hit(Object JavaDoc txId, Object JavaDoc key) {
235             super.hit(null, key);
236         }
237
238         protected void miss(Object JavaDoc txId, Object JavaDoc key) {
239             super.miss(null, key);
240         }
241
242         protected void log(Object JavaDoc txId, Object JavaDoc key, boolean hit) {
243             super.log(null, key, hit);
244         }
245
246         public synchronized void commit(Object JavaDoc txId) {
247             return;
248         }
249     }
250
251 }
252 /**
253  *$Log $
254  */
Popular Tags