001 /*
002 * Copyright 2006-2008 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kns.util;
017
018 import java.util.Properties;
019
020 import org.apache.log4j.Logger;
021 import org.apache.ojb.broker.Identity;
022 import org.apache.ojb.broker.PersistenceBroker;
023 import org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl;
024
025 public class KualiObjectCachePerBrokerImpl extends ObjectCachePerBrokerImpl {
026 private static final Logger LOG = Logger.getLogger(KualiObjectCachePerBrokerImpl.class);
027
028
029 private final String brokerId;
030
031 public KualiObjectCachePerBrokerImpl(PersistenceBroker broker, Properties prop) {
032 super(broker, prop);
033 brokerId = broker.getClass().getName() + "@" + broker.hashCode();
034
035 LOG.debug("created objectCache for broker " + brokerId);
036 }
037
038 /**
039 * Clear ObjectCache. I.e. remove all entries for classes and objects.
040 */
041 public void clear() {
042 super.clear();
043
044 LOG.debug("cleared objectCache for broker " + brokerId);
045 }
046
047 /**
048 * @see org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl#cache(org.apache.ojb.broker.Identity, java.lang.Object)
049 */
050 public void cache(Identity oid, Object obj) {
051 super.cache(oid, obj);
052
053 boolean cached = (super.lookup(oid) != null);
054 LOG.debug((cached ? "cached oid " : "unable to cache oid ") + oid + " in objectCache for broker " + brokerId);
055 }
056
057 /**
058 * @see org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl#cacheIfNew(org.apache.ojb.broker.Identity, java.lang.Object)
059 */
060 public boolean cacheIfNew(Identity oid, Object obj) {
061 boolean cachedIfNew = super.cacheIfNew(oid, obj);
062
063 boolean cached = (super.lookup(oid) != null);
064 LOG.debug((cached ? "cached new oid " : "unable to cache new oid ") + oid + " in objectCache for broker " + brokerId);
065
066 return cachedIfNew;
067 }
068
069 /**
070 * @see org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl#lookup(org.apache.ojb.broker.Identity)
071 */
072 public Object lookup(Identity oid) {
073 Object o = super.lookup(oid);
074
075 LOG.debug((o != null ? "found oid " : "cannot find oid ") + oid + " in objectCache for broker " + brokerId);
076
077 return o;
078 }
079 }