View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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.rice.krad.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 ObjectCachePerBrokerImpl {
26      private static final Logger LOG = Logger.getLogger(KualiObjectCachePerBrokerImpl.class);
27  
28  
29      private final String brokerId;
30  
31      public KualiObjectCachePerBrokerImpl(PersistenceBroker broker, Properties prop) {
32          super(broker, prop);
33          brokerId = broker.getClass().getName() + "@" + broker.hashCode();
34  
35          LOG.debug("created objectCache for broker " + brokerId);
36      }
37  
38      /**
39       * Clear ObjectCache. I.e. remove all entries for classes and objects.
40       */
41      public void clear() {
42          super.clear();
43  
44          LOG.debug("cleared objectCache for broker " + brokerId);
45      }
46  
47      /**
48       * @see org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl#cache(org.apache.ojb.broker.Identity, java.lang.Object)
49       */
50      public void cache(Identity oid, Object obj) {
51          super.cache(oid, obj);
52  
53          boolean cached = (super.lookup(oid) != null);
54          LOG.debug((cached ? "cached oid " : "unable to cache oid ") + oid + " in objectCache for broker " + brokerId);
55      }
56  
57      /**
58       * @see org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl#cacheIfNew(org.apache.ojb.broker.Identity, java.lang.Object)
59       */
60      public boolean cacheIfNew(Identity oid, Object obj) {
61          boolean cachedIfNew = super.cacheIfNew(oid, obj);
62  
63          boolean cached = (super.lookup(oid) != null);
64          LOG.debug((cached ? "cached new oid " : "unable to cache new oid ") + oid + " in objectCache for broker " + brokerId);
65  
66          return cachedIfNew;
67      }
68  
69      /**
70       * @see org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl#lookup(org.apache.ojb.broker.Identity)
71       */
72      public Object lookup(Identity oid) {
73          Object o = super.lookup(oid);
74  
75          LOG.debug((o != null ? "found oid " : "cannot find oid ") + oid + " in objectCache for broker " + brokerId);
76  
77          return o;
78      }
79  }