001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.entity.cache;
019:
020: import java.util.List;
021:
022: import org.ofbiz.base.util.Debug;
023: import org.ofbiz.entity.GenericEntity;
024: import org.ofbiz.entity.GenericPK;
025: import org.ofbiz.entity.condition.EntityCondition;
026:
027: public class Cache {
028:
029: public static final String module = Cache.class.getName();
030:
031: protected EntityCache entityCache;
032: protected EntityListCache entityListCache;
033: protected EntityObjectCache entityObjectCache;
034:
035: protected String delegatorName;
036:
037: public Cache(String delegatorName) {
038: this .delegatorName = delegatorName;
039: entityCache = new EntityCache(delegatorName);
040: entityObjectCache = new EntityObjectCache(delegatorName);
041: entityListCache = new EntityListCache(delegatorName);
042: }
043:
044: public void clear() {
045: entityCache.clear();
046: entityListCache.clear();
047: entityObjectCache.clear();
048: }
049:
050: public void remove(String entityName) {
051: entityCache.remove(entityName);
052: entityListCache.remove(entityName);
053: }
054:
055: public GenericEntity get(GenericPK pk) {
056: return entityCache.get(pk);
057: }
058:
059: public List get(String entityName, EntityCondition condition,
060: List orderBy) {
061: return entityListCache.get(entityName, condition, orderBy);
062: }
063:
064: public Object get(String entityName, EntityCondition condition,
065: String name) {
066: return entityObjectCache.get(entityName, condition, name);
067: }
068:
069: public List put(String entityName, EntityCondition condition,
070: List orderBy, List entities) {
071: return entityListCache.put(entityName, condition, orderBy,
072: entities);
073: }
074:
075: public Object put(String entityName, EntityCondition condition,
076: String name, Object value) {
077: return entityObjectCache
078: .put(entityName, condition, name, value);
079: }
080:
081: public GenericEntity put(GenericEntity entity) {
082: GenericEntity oldEntity = entityCache.put(entity
083: .getPrimaryKey(), entity);
084: if (entity.getModelEntity().getAutoClearCache()) {
085: entityListCache.storeHook(entity);
086: entityObjectCache.storeHook(entity);
087: }
088: return oldEntity;
089: }
090:
091: public GenericEntity put(GenericPK pk, GenericEntity entity) {
092: GenericEntity oldEntity = entityCache.put(pk, entity);
093: if (pk.getModelEntity().getAutoClearCache()) {
094: entityListCache.storeHook(pk, entity);
095: entityObjectCache.storeHook(pk, entity);
096: }
097: return oldEntity;
098: }
099:
100: public List remove(String entityName, EntityCondition condition,
101: List orderBy) {
102: entityCache.remove(entityName, condition);
103: entityObjectCache.remove(entityName, condition);
104: return entityListCache.remove(entityName, condition, orderBy);
105: }
106:
107: public void remove(String entityName, EntityCondition condition) {
108: entityCache.remove(entityName, condition);
109: entityListCache.remove(entityName, condition);
110: entityObjectCache.remove(entityName, condition);
111: }
112:
113: public Object remove(String entityName, EntityCondition condition,
114: String name) {
115: return entityObjectCache.remove(entityName, condition, name);
116: }
117:
118: public GenericEntity remove(GenericEntity entity) {
119: if (Debug.verboseOn())
120: Debug.logVerbose("Cache remove GenericEntity: " + entity,
121: module);
122: GenericEntity oldEntity = entityCache.remove(entity
123: .getPrimaryKey());
124: entityListCache.storeHook(entity, null);
125: entityObjectCache.storeHook(entity, null);
126: return oldEntity;
127: }
128:
129: public GenericEntity remove(GenericPK pk) {
130: if (Debug.verboseOn())
131: Debug.logVerbose("Cache remove GenericPK: " + pk, module);
132: GenericEntity oldEntity = entityCache.remove(pk);
133: entityListCache.storeHook(pk, null);
134: entityObjectCache.storeHook(pk, null);
135: return oldEntity;
136: }
137: }
|