?? abstractbasemanager.java
字號:
package org.apache.torque.manager;/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License") * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */import java.lang.ref.WeakReference;import java.util.Arrays;import java.util.List;import java.util.ArrayList;import java.util.Map;import java.util.HashMap;import java.util.Iterator;import java.io.Serializable;import java.io.IOException;import java.io.ObjectInputStream;import org.apache.commons.collections.FastArrayList;import org.apache.jcs.JCS;import org.apache.jcs.access.GroupCacheAccess;import org.apache.jcs.access.exception.CacheException;import org.apache.torque.Torque;import org.apache.torque.TorqueException;import org.apache.torque.om.ObjectKey;import org.apache.torque.om.Persistent;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * This class contains common functionality of a Manager for * instantiating OM's. * * @author <a href="mailto:jmcnally@collab.net">John McNally</a> * @version $Id: AbstractBaseManager.java,v 1.18 2005/01/31 19:43:58 tfischer Exp $ */public abstract class AbstractBaseManager implements Serializable{ /** the log */ protected static Log log = LogFactory.getLog(AbstractBaseManager.class); /** used to cache the om objects. cache is set by the region property */ protected transient GroupCacheAccess cache; /** method results cache */ protected MethodResultCache mrCache; /** the class that the service will instantiate */ private Class omClass; private String className; private String region; private boolean isNew = true; protected Map validFields; protected Map listenersMap = new HashMap(); /** * Get the Class instance * * @return the om class */ protected Class getOMClass() { return omClass; } /** * Set the Class that will be instantiated by this manager * * @param omClass the om class */ protected void setOMClass(Class omClass) { this.omClass = omClass; } /** * Get a fresh instance of an om * * @return an instance of the om class * @throws InstantiationException * @throws IllegalAccessException */ protected Persistent getOMInstance() throws InstantiationException, IllegalAccessException { return (Persistent) omClass.newInstance(); } /** * Get the classname to instantiate for getInstance() * @return value of className. */ public String getClassName() { return className; } /** * Set the classname to instantiate for getInstance() * @param v Value to assign to className. * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ public void setClassName(String v) throws TorqueException { this.className = v; try { setOMClass(Class.forName(getClassName())); } catch (ClassNotFoundException cnfe) { throw new TorqueException("Could not load " + getClassName()); } } /** * Return an instance of an om based on the id * * @param id * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected Persistent getOMInstance(ObjectKey id) throws TorqueException { return getOMInstance(id, true); } /** * Return an instance of an om based on the id * * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected Persistent getOMInstance(ObjectKey key, boolean fromCache) throws TorqueException { Persistent om = null; if (fromCache) { om = cacheGet(key); } if (om == null) { om = retrieveStoredOM(key); if (fromCache) { putInstanceImpl(om); } } return om; } protected Persistent cacheGet(Serializable key) { Persistent om = null; if (cache != null) { synchronized (this) { om = (Persistent) cache.get(key); } } return om; } /** * * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected void clearImpl() throws TorqueException { if (cache != null) { try { cache.remove(); } catch (CacheException ce) { throw new TorqueException( "Could not clear cache due to internal JCS error.", ce); } } } /** * * @param key * @return * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected Persistent removeInstanceImpl(Serializable key) throws TorqueException { Persistent oldOm = null; if (cache != null) { try { synchronized (this) { oldOm = (Persistent) cache.get(key); cache.remove(key); } } catch (CacheException ce) { throw new TorqueException ("Could not remove from cache due to internal JCS error", ce); } } return oldOm; } /** * * @param om * @return * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected Persistent putInstanceImpl(Persistent om) throws TorqueException { ObjectKey key = om.getPrimaryKey(); return putInstanceImpl(key, om); } /** * * @param key * @param om * @return * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected Persistent putInstanceImpl(Serializable key, Persistent om) throws TorqueException { if (getOMClass() != null && !getOMClass().isInstance(om)) { throw new TorqueException(om + "; class=" + om.getClass().getName() + "; id=" + om.getPrimaryKey() + " cannot be cached with " + getOMClass().getName() + " objects"); } Persistent oldOm = null; if (cache != null) { try { synchronized (this) { oldOm = (Persistent) cache.get(key); cache.put(key, om); } } catch (CacheException ce) { throw new TorqueException ("Could not cache due to internal JCS error", ce); } } return oldOm; } /** * * @param id * @return * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected abstract Persistent retrieveStoredOM(ObjectKey id) throws TorqueException; /** * Gets a list of om's based on id's. * * @param ids a <code>ObjectKey[]</code> value * @return a <code>List</code> value * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected List getOMs(ObjectKey[] ids)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -