01: /*
02: * Copyright 2006 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.util;
17:
18: import java.util.Properties;
19:
20: import org.apache.log4j.Logger;
21: import org.apache.ojb.broker.Identity;
22: import org.apache.ojb.broker.PersistenceBroker;
23: import org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl;
24:
25: public class KualiObjectCachePerBrokerImpl extends
26: ObjectCachePerBrokerImpl {
27: private static final Logger LOG = Logger
28: .getLogger(KualiObjectCachePerBrokerImpl.class);
29:
30: private final String brokerId;
31:
32: public KualiObjectCachePerBrokerImpl(PersistenceBroker broker,
33: Properties prop) {
34: super (broker, prop);
35: brokerId = broker.getClass().getName() + "@"
36: + broker.hashCode();
37:
38: LOG.debug("created objectCache for broker " + brokerId);
39: }
40:
41: /**
42: * Clear ObjectCache. I.e. remove all entries for classes and objects.
43: */
44: public void clear() {
45: super .clear();
46:
47: LOG.debug("cleared objectCache for broker " + brokerId);
48: }
49:
50: /**
51: * @see org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl#cache(org.apache.ojb.broker.Identity, java.lang.Object)
52: */
53: public void cache(Identity oid, Object obj) {
54: super .cache(oid, obj);
55:
56: boolean cached = (super .lookup(oid) != null);
57: LOG.debug((cached ? "cached oid " : "unable to cache oid ")
58: + oid + " in objectCache for broker " + brokerId);
59: }
60:
61: /**
62: * @see org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl#cacheIfNew(org.apache.ojb.broker.Identity, java.lang.Object)
63: */
64: public boolean cacheIfNew(Identity oid, Object obj) {
65: boolean cachedIfNew = super .cacheIfNew(oid, obj);
66:
67: boolean cached = (super .lookup(oid) != null);
68: LOG.debug((cached ? "cached new oid "
69: : "unable to cache new oid ")
70: + oid + " in objectCache for broker " + brokerId);
71:
72: return cachedIfNew;
73: }
74:
75: /**
76: * @see org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl#lookup(org.apache.ojb.broker.Identity)
77: */
78: public Object lookup(Identity oid) {
79: Object o = super .lookup(oid);
80:
81: LOG.debug((o != null ? "found oid " : "cannot find oid ") + oid
82: + " in objectCache for broker " + brokerId);
83:
84: return o;
85: }
86: }
|