KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > cache > Cache


1 /*
2  * $Id: Cache.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.entity.cache;
26
27 import java.util.List JavaDoc;
28
29 import org.ofbiz.base.util.Debug;
30 import org.ofbiz.entity.GenericEntity;
31 import org.ofbiz.entity.GenericPK;
32 import org.ofbiz.entity.condition.EntityCondition;
33
34 public class Cache {
35
36     public static final String JavaDoc module = Cache.class.getName();
37
38     protected EntityCache entityCache;
39     protected EntityListCache entityListCache;
40     protected EntityObjectCache entityObjectCache;
41
42     protected String JavaDoc delegatorName;
43
44     public Cache(String JavaDoc delegatorName) {
45         this.delegatorName = delegatorName;
46         entityCache = new EntityCache(delegatorName);
47         entityObjectCache = new EntityObjectCache(delegatorName);
48         entityListCache = new EntityListCache(delegatorName);
49     }
50
51     public void clear() {
52         entityCache.clear();
53         entityListCache.clear();
54         entityObjectCache.clear();
55     }
56
57     public void remove(String JavaDoc entityName) {
58         entityCache.remove(entityName);
59         entityListCache.remove(entityName);
60     }
61
62     public GenericEntity get(GenericPK pk) {
63         return entityCache.get(pk);
64     }
65
66     public List JavaDoc get(String JavaDoc entityName, EntityCondition condition, List JavaDoc orderBy) {
67         return entityListCache.get(entityName, condition, orderBy);
68     }
69
70     public Object JavaDoc get(String JavaDoc entityName, EntityCondition condition, String JavaDoc name) {
71         return entityObjectCache.get(entityName, condition, name);
72     }
73
74     public List JavaDoc put(String JavaDoc entityName, EntityCondition condition, List JavaDoc orderBy, List JavaDoc entities) {
75         return entityListCache.put(entityName, condition, orderBy, entities);
76     }
77
78     public Object JavaDoc put(String JavaDoc entityName, EntityCondition condition, String JavaDoc name, Object JavaDoc value) {
79         return entityObjectCache.put(entityName, condition, name, value);
80     }
81
82     public GenericEntity put(GenericEntity entity) {
83         GenericEntity oldEntity = entityCache.put(entity.getPrimaryKey(), entity);
84         if (entity.getModelEntity().getAutoClearCache()) {
85             entityListCache.storeHook(entity);
86             entityObjectCache.storeHook(entity);
87         }
88         return oldEntity;
89     }
90     
91     public GenericEntity put(GenericPK pk, GenericEntity entity) {
92         GenericEntity oldEntity = entityCache.put(pk, entity);
93         if (pk.getModelEntity().getAutoClearCache()) {
94             entityListCache.storeHook(pk, entity);
95             entityObjectCache.storeHook(pk, entity);
96         }
97         return oldEntity;
98     }
99
100     public List JavaDoc remove(String JavaDoc entityName, EntityCondition condition, List JavaDoc orderBy) {
101         entityCache.remove(entityName, condition);
102         entityObjectCache.remove(entityName, condition);
103         return entityListCache.remove(entityName, condition, orderBy);
104     }
105
106     public void remove(String JavaDoc entityName, EntityCondition condition) {
107         entityCache.remove(entityName, condition);
108         entityListCache.remove(entityName, condition);
109         entityObjectCache.remove(entityName, condition);
110     }
111
112     public Object JavaDoc remove(String JavaDoc entityName, EntityCondition condition, String JavaDoc name) {
113         return entityObjectCache.remove(entityName, condition, name);
114     }
115
116     public GenericEntity remove(GenericEntity entity) {
117         if (Debug.verboseOn()) Debug.logVerbose("Cache remove GenericEntity: " + entity, module);
118         GenericEntity oldEntity = entityCache.remove(entity.getPrimaryKey());
119         entityListCache.storeHook(entity, null);
120         entityObjectCache.storeHook(entity, null);
121         return oldEntity;
122     }
123
124     public GenericEntity remove(GenericPK pk) {
125         if (Debug.verboseOn()) Debug.logVerbose("Cache remove GenericPK: " + pk, module);
126         GenericEntity oldEntity = entityCache.remove(pk);
127         entityListCache.storeHook(pk, null);
128         entityObjectCache.storeHook(pk, null);
129         return oldEntity;
130     }
131 }
132
Popular Tags