You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tv...@apache.org on 2012/05/13 21:49:35 UTC
svn commit: r1337973 - in /db/torque/torque4/trunk:
torque-runtime/src/main/java/org/apache/torque/manager/
torque-site/src/changes/
torque-templates/src/main/resources/org/apache/torque/templates/om/templates/manager/base/
Author: tv
Date: Sun May 13 19:49:35 2012
New Revision: 1337973
URL: http://svn.apache.org/viewvc?rev=1337973&view=rev
Log:
- Use variable arguments for MethodCacheKey and MethodResultCache and remove obsolete code
- Make AbstractBaseManager generic. This saves a lot of code in the generated classes.
- Fix baseManager.vm to use the AbstractBaseManager methods
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/CacheListener.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodResultCache.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/NoOpMethodResultCache.java
db/torque/torque4/trunk/torque-site/src/changes/changes.xml
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/manager/base/baseManager.vm
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java?rev=1337973&r1=1337972&r2=1337973&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java Sun May 13 19:49:35 2012
@@ -19,30 +19,28 @@ package org.apache.torque.manager;
* under the License.
*/
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
import java.lang.ref.WeakReference;
-import java.util.Arrays;
-import java.util.List;
import java.util.ArrayList;
-import java.util.Map;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
-import java.io.Serializable;
-import java.io.IOException;
-import java.io.ObjectInputStream;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.collections.FastArrayList;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
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.
@@ -50,9 +48,12 @@ import org.apache.commons.logging.LogFac
* @author <a href="mailto:jmcnally@collab.net">John McNally</a>
* @version $Id$
*/
-public abstract class AbstractBaseManager
+public abstract class AbstractBaseManager<T extends Persistent>
implements Serializable
{
+ /** serial version */
+ private static final long serialVersionUID = 509798299473481305L;
+
/** the log */
protected static final Log log = LogFactory.getLog(AbstractBaseManager.class);
@@ -63,7 +64,7 @@ public abstract class AbstractBaseManage
protected MethodResultCache mrCache;
/** The OM class that the service will instantiate. */
- private Class<? extends Persistent> omClass;
+ private Class<T> omClass;
/** The name of the OM class that the service will instantiate. */
private String className;
@@ -76,7 +77,7 @@ public abstract class AbstractBaseManage
protected Map<String, ?> validFields;
- protected Map<String, FastArrayList> listenersMap
+ protected Map<String, FastArrayList> listenersMap
= new HashMap<String, FastArrayList>();
/**
@@ -84,7 +85,7 @@ public abstract class AbstractBaseManage
*
* @return the om class
*/
- protected Class<? extends Persistent> getOMClass()
+ protected Class<T> getOMClass()
{
return omClass;
}
@@ -94,7 +95,7 @@ public abstract class AbstractBaseManage
*
* @param omClass the om class
*/
- protected void setOMClass(Class<? extends Persistent> omClass)
+ protected void setOMClass(Class<T> omClass)
{
this.omClass = omClass;
}
@@ -103,13 +104,24 @@ public abstract class AbstractBaseManage
* Get a fresh instance of an om
*
* @return an instance of the om class
- * @throws InstantiationException
- * @throws IllegalAccessException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
- protected Persistent getOMInstance()
- throws InstantiationException, IllegalAccessException
+ protected T getOMInstance()
+ throws TorqueException
{
- return omClass.newInstance();
+ try
+ {
+ return omClass.newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new TorqueException("Could not instantiate " + getClassName(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new TorqueException("Could not access " + getClassName(), e);
+ }
}
/**
@@ -139,7 +151,7 @@ public abstract class AbstractBaseManage
Class<?> clazz = Class.forName(getClassName());
if (Persistent.class.isAssignableFrom(clazz))
{
- setOMClass((Class<? extends Persistent>) clazz);
+ setOMClass((Class<T>) clazz);
}
else
{
@@ -150,7 +162,7 @@ public abstract class AbstractBaseManage
}
catch (ClassNotFoundException cnfe)
{
- throw new TorqueException("Could not load " + getClassName());
+ throw new TorqueException("Could not load " + getClassName(), cnfe);
}
}
@@ -163,7 +175,7 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected Persistent getOMInstance(ObjectKey id)
+ protected T getOMInstance(ObjectKey id)
throws TorqueException
{
return getOMInstance(id, true);
@@ -178,10 +190,10 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected Persistent getOMInstance(ObjectKey key, boolean fromCache)
+ protected T getOMInstance(ObjectKey key, boolean fromCache)
throws TorqueException
{
- Persistent om = null;
+ T om = null;
if (fromCache)
{
om = cacheGet(key);
@@ -205,14 +217,15 @@ public abstract class AbstractBaseManage
* @param key the primary key of the object
* @return the object from cache
*/
- protected Persistent cacheGet(Serializable key)
+ @SuppressWarnings("unchecked")
+ protected T cacheGet(Serializable key)
{
- Persistent om = null;
+ T om = null;
if (cache != null)
{
synchronized (this)
{
- om = (Persistent) cache.get(key);
+ om = (T) cache.get(key);
}
}
return om;
@@ -263,17 +276,18 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected Persistent removeInstanceImpl(Serializable key)
+ @SuppressWarnings("unchecked")
+ protected T removeInstanceImpl(Serializable key)
throws TorqueException
{
- Persistent oldOm = null;
+ T oldOm = null;
if (cache != null)
{
try
{
synchronized (this)
{
- oldOm = (Persistent) cache.get(key);
+ oldOm = (T) cache.get(key);
cache.remove(key);
}
}
@@ -296,7 +310,7 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected Persistent putInstanceImpl(Persistent om)
+ protected T putInstanceImpl(T om)
throws TorqueException
{
ObjectKey key = om.getPrimaryKey();
@@ -313,7 +327,8 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected Persistent putInstanceImpl(Serializable key, Persistent om)
+ @SuppressWarnings("unchecked")
+ protected T putInstanceImpl(Serializable key, T om)
throws TorqueException
{
if (getOMClass() != null && !getOMClass().isInstance(om))
@@ -323,14 +338,14 @@ public abstract class AbstractBaseManage
+ getOMClass().getName() + " objects");
}
- Persistent oldOm = null;
+ T oldOm = null;
if (cache != null)
{
try
{
synchronized (this)
{
- oldOm = (Persistent) cache.get(key);
+ oldOm = (T) cache.get(key);
cache.put(key, om);
}
}
@@ -351,7 +366,7 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected abstract Persistent retrieveStoredOM(ObjectKey id)
+ protected abstract T retrieveStoredOM(ObjectKey id)
throws TorqueException;
/**
@@ -362,7 +377,7 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected List<? extends Object> getOMs(ObjectKey[] ids)
+ protected List<T> getOMs(ObjectKey[] ids)
throws TorqueException
{
return getOMs(Arrays.asList(ids));
@@ -376,7 +391,7 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected List<? extends Object> getOMs(List<ObjectKey> ids)
+ protected List<T> getOMs(List<? extends ObjectKey> ids)
throws TorqueException
{
return getOMs(ids, true);
@@ -390,19 +405,18 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected List<? extends Object> getOMs(List<ObjectKey> ids, boolean fromCache)
+ protected List<T> getOMs(List<? extends ObjectKey> ids, boolean fromCache)
throws TorqueException
{
- List<Object> oms = null;
+ List<T> oms = null;
if (ids != null && ids.size() > 0)
{
// start a new list where we will replace the id's with om's
- oms = new ArrayList<Object>(ids);
+ Map<ObjectKey, T> omsMap = new HashMap<ObjectKey, T>();
List<ObjectKey> newIds = new ArrayList<ObjectKey>(ids.size());
- for (int i = 0; i < ids.size(); i++)
+ for (ObjectKey key : ids)
{
- ObjectKey key = ids.get(i);
- Persistent om = null;
+ T om = null;
if (fromCache)
{
om = cacheGet(key);
@@ -413,36 +427,28 @@ public abstract class AbstractBaseManage
}
else
{
- oms.set(i, om);
+ omsMap.put(key, om);
}
}
if (newIds.size() > 0)
{
- List<? extends Object> newOms = retrieveStoredOMs(newIds);
- for (int i = 0; i < oms.size(); i++)
+ List<T> newOms = retrieveStoredOMs(newIds);
+ for(T om : newOms)
{
- if (oms.get(i) instanceof ObjectKey)
+ omsMap.put(om.getPrimaryKey(), om);
+ if (fromCache)
{
- for (int j = newOms.size() - 1; j >= 0; j--)
- {
- Persistent om = (Persistent) newOms.get(j);
- if (om.getPrimaryKey().equals(oms.get(i)))
- {
- // replace the id with the om and add the om
- // to the cache
- oms.set(i, om);
- newOms.remove(j);
- if (fromCache)
- {
- putInstanceImpl(om);
- }
- break;
- }
- }
+ putInstanceImpl(om);
}
}
}
+
+ oms = new ArrayList<T>(ids.size());
+ for (ObjectKey key : ids)
+ {
+ oms.add(omsMap.get(key));
+ }
}
return oms;
}
@@ -456,8 +462,7 @@ public abstract class AbstractBaseManage
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected abstract List<? extends Object> retrieveStoredOMs(
- List<ObjectKey> ids)
+ protected abstract List<T> retrieveStoredOMs(List<? extends ObjectKey> ids)
throws TorqueException;
/**
@@ -523,13 +528,14 @@ public abstract class AbstractBaseManage
*/
protected void registerAsListener()
{
+ // empty
}
/**
*
* @param listener A new listener for cache events.
*/
- public void addCacheListenerImpl(CacheListener listener)
+ public void addCacheListenerImpl(CacheListener<? extends Persistent> listener)
{
List<String> keys = listener.getInterestedFields();
for (String key : keys)
@@ -564,7 +570,7 @@ public abstract class AbstractBaseManage
}
if (isNew)
{
- listeners.add(new WeakReference<CacheListener>(listener));
+ listeners.add(new WeakReference<CacheListener<? extends Persistent>>(listener));
}
}
}
@@ -580,7 +586,7 @@ public abstract class AbstractBaseManage
FastArrayList list = null;
if (listenersMap.containsKey(key))
{
- list = (FastArrayList) listenersMap.get(key);
+ list = listenersMap.get(key);
}
else
{
@@ -597,18 +603,17 @@ public abstract class AbstractBaseManage
* @param oldOm
* @param om
*/
- protected void notifyListeners(List<?> listeners,
- Persistent oldOm, Persistent om)
+ protected <TT extends Persistent> void notifyListeners(List<WeakReference<CacheListener<TT>>> listeners,
+ TT oldOm, TT om)
{
if (listeners != null)
{
synchronized (listeners)
{
- Iterator<?> i = listeners.iterator();
+ Iterator<WeakReference<CacheListener<TT>>> i = listeners.iterator();
while (i.hasNext())
{
- CacheListener listener = (CacheListener)
- ((WeakReference<?>) i.next()).get();
+ CacheListener<TT> listener = i.next().get();
if (listener == null)
{
// remove reference as its object was cleared
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/CacheListener.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/CacheListener.java?rev=1337973&r1=1337972&r2=1337973&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/CacheListener.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/CacheListener.java Sun May 13 19:49:35 2012
@@ -20,6 +20,7 @@ package org.apache.torque.manager;
*/
import java.util.List;
+
import org.apache.torque.om.Persistent;
/**
@@ -28,21 +29,21 @@ import org.apache.torque.om.Persistent;
* @author <a href="mailto:jmcnally@collab.net">John McNally</a>
* @version $Id$
*/
-public interface CacheListener
+public interface CacheListener<T extends Persistent>
{
/**
*
* @param om
*/
- void addedObject(Persistent om);
+ void addedObject(T om);
/**
*
* @param om
*/
- void refreshedObject(Persistent om);
+ void refreshedObject(T om);
- //public void removedObject(Persistent om);
+ //public void removedObject(T om);
/**
*
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java?rev=1337973&r1=1337972&r2=1337973&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java Sun May 13 19:49:35 2012
@@ -20,9 +20,8 @@ package org.apache.torque.manager;
*/
import java.io.Serializable;
+
import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.pool.BasePoolableObjectFactory;
-import org.apache.torque.TorqueException;
/**
* @version $Id$
@@ -34,149 +33,50 @@ public class MethodCacheKey implements S
*/
private static final long serialVersionUID = -1831486431185021200L;
- int n;
private Serializable instanceOrClass;
private String method;
- private Serializable arg1;
- private Serializable arg2;
- private Serializable arg3;
- private Serializable[] moreThanThree;
+ private Serializable[] args;
private String groupKey;
public MethodCacheKey()
{
- }
-
- public MethodCacheKey(Serializable instanceOrClass, String method)
- {
- init(instanceOrClass, method);
- }
-
- public MethodCacheKey(Serializable instanceOrClass, String method,
- Serializable arg1)
- {
- init(instanceOrClass, method, arg1);
- }
-
- public MethodCacheKey(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2)
- {
- init(instanceOrClass, method, arg1, arg2);
- }
-
- public MethodCacheKey(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2,
- Serializable arg3)
- {
- init(instanceOrClass, method, arg1, arg2, arg3);
- }
-
- public MethodCacheKey(Serializable[] moreThanThree)
- {
- init(moreThanThree);
+ // empty
}
/**
- * Initialize key for method with no arguments.
+ * Construct key
*
* @param instanceOrClass the Object on which the method is invoked. if
* the method is static, a String representing the class name is used.
* @param method the method name
+ * @param arg optional arguments for the method
*/
- public void init(Serializable instanceOrClass, String method)
+ public MethodCacheKey(Serializable instanceOrClass, String method, Serializable ... arg)
{
- n = 0;
- this.instanceOrClass = instanceOrClass;
- this.method = method;
- groupKey = instanceOrClass.toString() + method;
- }
-
- /**
- * Initialize key for method with one argument.
- *
- * @param instanceOrClass the Object on which the method is invoked. if
- * the method is static, a String representing the class name is used.
- * @param method the method name
- * @param arg1 first method arg, may be null
- */
- public void init(Serializable instanceOrClass, String method,
- Serializable arg1)
- {
- init(instanceOrClass, method);
- n = 1;
- this.arg1 = arg1;
+ init(instanceOrClass, method, arg);
}
/**
- * Initialize key for method with two arguments.
+ * Initialize the key
*
* @param instanceOrClass the Object on which the method is invoked. if
* the method is static, a String representing the class name is used.
* @param method the method name
- * @param arg1 first method arg, may be null
- * @param arg2 second method arg, may be null
+ * @param arg optional arguments for the method
*/
- public void init(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2)
+ public void init(Serializable instanceOrClass, String method, Serializable ... arg)
{
- init(instanceOrClass, method);
- n = 2;
- this.arg1 = arg1;
- this.arg2 = arg2;
- }
-
-
- /**
- * Initialize key for method with two arguments.
- *
- * @param instanceOrClass the Object on which the method is invoked. if
- * the method is static, a String representing the class name is used.
- * @param method the method name
- * @param arg1 first method arg, may be null
- * @param arg2 second method arg, may be null
- */
- public void init(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2,
- Serializable arg3)
- {
- init(instanceOrClass, method);
- n = 3;
- this.arg1 = arg1;
- this.arg2 = arg2;
- this.arg3 = arg3;
+ this.instanceOrClass = instanceOrClass;
+ this.method = method;
+ groupKey = instanceOrClass.toString() + method;
+ this.args = arg;
}
/**
- * Initialize key for method with more than three arguments.
+ * Return the group key
*
- * @param keys Serializable[] where
- * [0]=>the Object on which the method is invoked
- * if the method is static, a String representing the class name is used.
- * [1]=>the method name
- * [n] where n>1 are the method arguments
+ * @return the group key
*/
- public void init(Serializable[] keys)
- {
- init(keys[0], (String) keys[1]);
- n = keys.length - 2;
- if (n > 0)
- {
- this.arg1 = keys[2];
- if (n > 1)
- {
- this.arg2 = keys[3];
- if (n > 2)
- {
- this.arg3 = keys[4];
- if (n > 3)
- {
- this.moreThanThree = keys;
- }
- }
- }
- }
- }
-
public String getGroupKey()
{
return groupKey;
@@ -188,28 +88,11 @@ public class MethodCacheKey implements S
if (obj instanceof MethodCacheKey)
{
MethodCacheKey sck = (MethodCacheKey) obj;
- equal = (sck.n == n);
- equal &= ObjectUtils.equals(sck.method, method);
+ equal = ObjectUtils.equals(sck.method, method);
equal &= ObjectUtils.equals(sck.instanceOrClass, instanceOrClass);
- if (equal && n > 0)
+ if (equal)
{
- equal &= ObjectUtils.equals(sck.arg1, arg1);
- if (equal && n > 1)
- {
- equal &= ObjectUtils.equals(sck.arg2, arg2);
- if (equal && n > 2)
- {
- equal &= ObjectUtils.equals(sck.arg3, arg3);
- if (equal && n > 3)
- {
- for (int i = 5; i < n + 2; i++)
- {
- equal &= ObjectUtils.equals(
- sck.moreThanThree[i], moreThanThree[i]);
- }
- }
- }
- }
+ equal &= ObjectUtils.equals(sck.args, args);
}
}
@@ -220,26 +103,7 @@ public class MethodCacheKey implements S
{
int h = instanceOrClass.hashCode();
h += method.hashCode();
- if (n > 0)
- {
- h += (arg1 == null ? 0 : arg1.hashCode());
- if (n > 1)
- {
- h += (arg2 == null ? 0 : arg2.hashCode());
- if (n > 2)
- {
- h += (arg3 == null ? 0 : arg3.hashCode());
- if (n > 3)
- {
- for (int i = 5; i < n + 2; i++)
- {
- h += (moreThanThree[i] == null ? 0
- : moreThanThree[i].hashCode());
- }
- }
- }
- }
- }
+ h += args.hashCode();
return h;
}
@@ -249,64 +113,15 @@ public class MethodCacheKey implements S
sb.append(instanceOrClass);
sb.append("::");
sb.append(method).append('(');
- if (n > 0)
- {
- sb.append(arg1);
- if (n > 1)
- {
- sb.append(", ").append(arg2);
- if (n > 2)
- {
- sb.append(", ").append(arg3);
- if (n > 3)
- {
- for (int i = 5; i < n + 2; i++)
- {
- sb.append(", ").append(moreThanThree[i]);
- }
- }
- }
- }
- }
- sb.append(')');
- return sb.toString();
- }
-
- // ************* PoolableObjectFactory implementation *******************
-
- public static class Factory
- extends BasePoolableObjectFactory
- {
- /**
- * Creates an instance that can be returned by the pool.
- * @return an instance that can be returned by the pool.
- */
- public Object makeObject()
- throws Exception
- {
- return new MethodCacheKey();
- }
-
- /**
- * Uninitialize an instance to be returned to the pool.
- * @param obj the instance to be passivated
- */
- public void passivateObject(Object obj)
- throws Exception
+ for (int i = 0; i < args.length; i++)
{
- MethodCacheKey key = (MethodCacheKey) obj;
- if (key.instanceOrClass == null && key.method == null)
+ sb.append(args[i]);
+ if (i < args.length - 1)
{
- throw new TorqueException(
- "Attempted to return key to pool twice.");
+ sb.append(", ");
}
- key.instanceOrClass = null;
- key.method = null;
- key.arg1 = null;
- key.arg2 = null;
- key.arg3 = null;
- key.moreThanThree = null;
- key.groupKey = null;
}
+ sb.append(')');
+ return sb.toString();
}
}
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodResultCache.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodResultCache.java?rev=1337973&r1=1337972&r2=1337973&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodResultCache.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodResultCache.java Sun May 13 19:49:35 2012
@@ -23,15 +23,10 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.pool.ObjectPool;
-import org.apache.commons.pool.impl.StackObjectPool;
-
-import org.apache.jcs.access.GroupCacheAccess;
-import org.apache.jcs.access.exception.CacheException;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
+import org.apache.jcs.access.GroupCacheAccess;
+import org.apache.jcs.access.exception.CacheException;
import org.apache.torque.TorqueException;
/**
@@ -43,19 +38,21 @@ import org.apache.torque.TorqueException
*/
public class MethodResultCache
{
- private ObjectPool pool;
private GroupCacheAccess jcsCache;
private Map<String, Object> groups;
/** Logging */
private static Log log = LogFactory.getLog(MethodResultCache.class);
+ /**
+ * Constructor
+ *
+ * @param cache the cache instance to use
+ */
public MethodResultCache(GroupCacheAccess cache)
- throws TorqueException
{
this.jcsCache = cache;
groups = new HashMap<String, Object>();
- pool = new StackObjectPool(new MethodCacheKey.Factory(), 10000);
}
/**
@@ -65,8 +62,12 @@ public class MethodResultCache
*/
protected MethodResultCache()
{
+ //empty
}
+ /**
+ * Clear the cache
+ */
public void clear()
{
if (jcsCache != null)
@@ -95,13 +96,11 @@ public class MethodResultCache
}
}
- if (result != null)
+ if (result != null && log.isDebugEnabled())
{
- if (log.isDebugEnabled())
- {
- log.debug("MethodResultCache saved expensive operation: " + key);
- }
+ log.debug("MethodResultCache saved expensive operation: " + key);
}
+
return result;
}
@@ -137,7 +136,6 @@ public class MethodResultCache
}
protected Object removeImpl(MethodCacheKey key)
- throws TorqueException
{
Object old = null;
if (jcsCache != null)
@@ -151,395 +149,110 @@ public class MethodResultCache
return old;
}
-
- public Object get(Serializable instanceOrClass, String method)
- {
- Object result = null;
- if (jcsCache != null)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method);
- result = getImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error. Could not return key to pool", e);
- }
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
- return result;
- }
-
- public Object get(Serializable instanceOrClass, String method,
- Serializable arg1)
- {
- Object result = null;
- if (jcsCache != null)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method, arg1);
- result = getImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error. Could not return key to pool", e);
- }
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
- return result;
- }
-
- public Object get(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2)
- {
- Object result = null;
- if (jcsCache != null)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method, arg1, arg2);
- result = getImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error. Could not return key to pool", e);
- }
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
- return result;
- }
-
- public Object get(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2,
- Serializable arg3)
+ /**
+ * Get an object from the method cache
+ *
+ * @param instanceOrClass the Object on which the method is invoked. if
+ * the method is static, a String representing the class name is used.
+ * @param method the method name
+ * @param arg optional arguments for the method
+ *
+ * @return the object or null if it does not exist
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T get(Serializable instanceOrClass, String method, Serializable ... arg)
{
- Object result = null;
+ T result = null;
if (jcsCache != null)
{
try
{
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method, arg1, arg2, arg3);
- result = getImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error. Could not return key to pool", e);
- }
+ MethodCacheKey key = new MethodCacheKey(instanceOrClass, method, arg);
+ result = (T) getImpl(key);
}
catch (Exception e)
{
- log.error("", e);
+ log.error("Problem getting object from cache", e);
}
}
- return result;
- }
- public Object get(Serializable[] keys)
- {
- Object result = null;
- if (jcsCache != null)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(keys);
- result = getImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error. Could not return key to pool", e);
- }
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
return result;
}
- public void put(Object value, Serializable instanceOrClass, String method)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method);
- putImpl(key, value);
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
-
- public void put(Object value, Serializable instanceOrClass,
- String method, Serializable arg1)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method, arg1);
- putImpl(key, value);
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
-
- public void put(Object value, Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method, arg1, arg2);
- putImpl(key, value);
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
-
- public void put(Object value, Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2, Serializable arg3)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method, arg1, arg2, arg3);
- putImpl(key, value);
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
-
- public void put(Object value, Serializable[] keys)
+ /**
+ * Put an object into the method cache
+ *
+ * @param value the object to put into the cache
+ * @param instanceOrClass the Object on which the method is invoked. if
+ * the method is static, a String representing the class name is used.
+ * @param method the method name
+ * @param arg optional arguments for the method
+ */
+ public <T> void put(T value, Serializable instanceOrClass, String method, Serializable ... arg)
{
try
{
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(keys);
+ MethodCacheKey key = new MethodCacheKey(instanceOrClass, method, arg);
putImpl(key, value);
}
catch (Exception e)
{
- log.error("", e);
+ log.error("Problem putting object into cache", e);
}
}
-
+ /**
+ * Remove all objects of the same group
+ *
+ * @param instanceOrClass the Object on which the method is invoked. if
+ * the method is static, a String representing the class name is used.
+ * @param method the method name
+ */
public void removeAll(Serializable instanceOrClass, String method)
{
if (jcsCache != null)
{
try
{
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method);
+ MethodCacheKey key = new MethodCacheKey(instanceOrClass, method);
String groupName = key.getGroupKey();
jcsCache.invalidateGroup(groupName);
groups.remove(groupName);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error. Could not return key to pool", e);
- }
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
- }
-
-
- public Object remove(Serializable instanceOrClass, String method)
- {
- Object result = null;
- if (jcsCache != null)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method);
- result = removeImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error. Could not return key to pool", e);
- }
}
catch (Exception e)
{
- log.error("", e);
+ log.error("Problem removing all", e);
}
}
- return result;
}
- public Object remove(Serializable instanceOrClass, String method,
- Serializable arg1)
- {
- Object result = null;
- if (jcsCache != null)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method, arg1);
- result = removeImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error. Could not return key to pool", e);
- }
- }
- catch (Exception e)
- {
- log.error("Error removing element", e);
- }
- }
- return result;
- }
-
- public Object remove(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2)
- {
- Object result = null;
- if (jcsCache != null)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method, arg1, arg2);
- result = removeImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error: Could not return key to pool", e);
- }
- }
- catch (Exception e)
- {
- log.error("Error removing element from cache", e);
- }
- }
- return result;
- }
-
- public Object remove(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2,
- Serializable arg3)
+ /**
+ * Remove object from method cache
+ *
+ * @param instanceOrClass the Object on which the method is invoked. if
+ * the method is static, a String representing the class name is used.
+ * @param method the method name
+ * @param arg optional arguments for the method
+ *
+ * @return the removed object
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T remove(Serializable instanceOrClass, String method, Serializable ... arg)
{
- Object result = null;
+ T result = null;
if (jcsCache != null)
{
try
{
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(instanceOrClass, method, arg1, arg2, arg3);
- result = removeImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error. Could not return key to pool", e);
- }
+ MethodCacheKey key = new MethodCacheKey(instanceOrClass, method, arg);
+ result = (T) removeImpl(key);
}
catch (Exception e)
{
- log.error("Error removing element from cache", e);
+ log.error("Problem removing object from cache", e);
}
}
- return result;
- }
- public Object remove(Serializable[] keys)
- {
- Object result = null;
- if (jcsCache != null)
- {
- try
- {
- MethodCacheKey key = (MethodCacheKey) pool.borrowObject();
- key.init(keys);
- result = removeImpl(key);
- try
- {
- pool.returnObject(key);
- }
- catch (Exception e)
- {
- log.warn(
- "Nonfatal error: Could not return key to pool", e);
- }
- }
- catch (Exception e)
- {
- log.error("Error removing element from cache", e);
- }
- }
return result;
}
}
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/NoOpMethodResultCache.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/NoOpMethodResultCache.java?rev=1337973&r1=1337972&r2=1337973&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/NoOpMethodResultCache.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/NoOpMethodResultCache.java Sun May 13 19:49:35 2012
@@ -20,11 +20,12 @@ package org.apache.torque.manager;
*/
import java.io.Serializable;
+
import org.apache.jcs.access.GroupCacheAccess;
import org.apache.torque.TorqueException;
/**
- * This class provides a cache for convenient storage of method results
+ * This class provides a no-op cache for convenient storage of method results
*
* @author <a href="mailto:jmcnally@collab.net">John McNally</a>
* @version $Id$
@@ -33,117 +34,77 @@ public class NoOpMethodResultCache
extends MethodResultCache
{
public NoOpMethodResultCache(GroupCacheAccess cache)
- throws TorqueException
{
super();
}
+ /**
+ * Clear the cache
+ */
public void clear()
{
+ //empty
}
+ /**
+ * @see org.apache.torque.manager.MethodResultCache#getImpl(org.apache.torque.manager.MethodCacheKey)
+ */
+ @Override
protected Object getImpl(MethodCacheKey key)
{
return null;
}
-
- protected Object putImpl(MethodCacheKey key, Object value)
- throws TorqueException
+ /**
+ * @see org.apache.torque.manager.MethodResultCache#putImpl(org.apache.torque.manager.MethodCacheKey, java.lang.Object)
+ */
+ @Override
+ protected Object putImpl(MethodCacheKey key, Object value) throws TorqueException
{
return null;
}
+ /**
+ * @see org.apache.torque.manager.MethodResultCache#removeImpl(org.apache.torque.manager.MethodCacheKey)
+ */
+ @Override
protected Object removeImpl(MethodCacheKey key)
- throws TorqueException
- {
- return null;
- }
-
-
- public Object get(Serializable instanceOrClass, String method)
{
return null;
}
- public Object get(Serializable instanceOrClass, String method,
- Serializable arg1)
+ /**
+ * @see org.apache.torque.manager.MethodResultCache#get(java.io.Serializable, java.lang.String, java.io.Serializable[])
+ */
+ @Override
+ public <T> T get(Serializable instanceOrClass, String method, Serializable... arg)
{
return null;
}
- public Object get(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2)
- {
- return null;
- }
-
- public Object get(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2,
- Serializable arg3)
- {
- return null;
- }
-
- public Object get(Serializable[] keys)
- {
- return null;
- }
-
- public void put(Object value, Serializable instanceOrClass, String method)
- {
- }
-
- public void put(Object value, Serializable instanceOrClass,
- String method, Serializable arg1)
- {
- }
-
- public void put(Object value, Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2)
+ /**
+ * @see org.apache.torque.manager.MethodResultCache#put(java.lang.Object, java.io.Serializable, java.lang.String, java.io.Serializable[])
+ */
+ @Override
+ public <T> void put(T value, Serializable instanceOrClass, String method, Serializable... arg)
{
+ //empty
}
- public void put(Object value, Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2, Serializable arg3)
- {
- }
-
- public void put(Object value, Serializable[] keys)
- {
- }
-
-
+ /**
+ * @see org.apache.torque.manager.MethodResultCache#removeAll(java.io.Serializable, java.lang.String)
+ */
+ @Override
public void removeAll(Serializable instanceOrClass, String method)
{
+ //empty
}
-
- public Object remove(Serializable instanceOrClass, String method)
- {
- return null;
- }
-
- public Object remove(Serializable instanceOrClass, String method,
- Serializable arg1)
- {
- return null;
- }
-
- public Object remove(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2)
- {
- return null;
- }
-
- public Object remove(Serializable instanceOrClass, String method,
- Serializable arg1, Serializable arg2,
- Serializable arg3)
- {
- return null;
- }
-
- public Object remove(Serializable[] keys)
+ /**
+ * @see org.apache.torque.manager.MethodResultCache#remove(java.io.Serializable, java.lang.String, java.io.Serializable[])
+ */
+ @Override
+ public <T> T remove(Serializable instanceOrClass, String method, Serializable... arg)
{
return null;
}
Modified: db/torque/torque4/trunk/torque-site/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/changes/changes.xml?rev=1337973&r1=1337972&r2=1337973&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/changes/changes.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/changes/changes.xml Sun May 13 19:49:35 2012
@@ -24,6 +24,14 @@
<body>
<release version="4.0-alpha1-SNAPSHOT" date="in SVN">
+ <action type="update" dev="tv">
+ Use variable arguments for MethodCacheKey and MethodResultCache and
+ remove obsolete code.
+ </action>
+ <action type="update" dev="tv">
+ Make AbstractBaseManager generic. This saves a lot of code in the
+ generated classes.
+ </action>
<action type="add" dev="tv">
Add auto-detection of the database adapter. Use xxx.adapter=auto in
Torque.properties.
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/manager/base/baseManager.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/manager/base/baseManager.vm?rev=1337973&r1=1337972&r2=1337973&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/manager/base/baseManager.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/manager/base/baseManager.vm Sun May 13 19:49:35 2012
@@ -51,7 +51,7 @@ import ${dbObjectPackage}.${dbObjectClas
$torqueGen.mergepoint("classJavadoc")
public abstract class ${baseManagerClassName}
- extends AbstractBaseManager
+ extends AbstractBaseManager<${dbObjectClassName}>
{
$torqueGen.mergepoint("serialVersionUid")
/** The name of the manager */
@@ -75,7 +75,7 @@ $torqueGen.mergepoint("serialVersionUid"
}
/**
- * Static accessor for the @see #getInstanceImpl().
+ * Static accessor for the @see #getOMInstance().
*
* @return a <code>${dbObjectClassName}</code> value
* @exception TorqueException if an error occurs
@@ -83,11 +83,11 @@ $torqueGen.mergepoint("serialVersionUid"
public static ${dbObjectClassName} getInstance()
throws TorqueException
{
- return getManager().getInstanceImpl();
+ return getManager().getOMInstance();
}
/**
- * Static accessor for the @see #getInstanceImpl(ObjectKey).
+ * Static accessor for the @see #getOMInstance(ObjectKey).
*
* @param id an <code>ObjectKey</code> value
* @return a <code>${dbObjectClassName}</code> value
@@ -96,11 +96,11 @@ $torqueGen.mergepoint("serialVersionUid"
public static ${dbObjectClassName} getInstance(ObjectKey id)
throws TorqueException
{
- return getManager().getInstanceImpl(id);
+ return getManager().getOMInstance(id);
}
/**
- * Static accessor for the @see #getCachedInstanceImpl(ObjectKey).
+ * Static accessor for the @see #cacheGet(ObjectKey).
* Loads <code>${dbObjectClassName}</code> from cache, returns
* <code>null</code>, if instance is not in cache
*
@@ -111,11 +111,11 @@ $torqueGen.mergepoint("serialVersionUid"
public static ${dbObjectClassName} getCachedInstance(ObjectKey id)
throws TorqueException
{
- return getManager().getCachedInstanceImpl(id);
+ return getManager().cacheGet(id);
}
/**
- * Static accessor for the @see #getInstanceImpl(ObjectKey, boolean).
+ * Static accessor for the @see #getOMInstance(ObjectKey, boolean).
*
* @param id an <code>ObjectKey</code> value
* @param fromCache if true, look for cached ${dbObjectClassName}s before loading
@@ -126,7 +126,7 @@ $torqueGen.mergepoint("serialVersionUid"
public static ${dbObjectClassName} getInstance(ObjectKey id, boolean fromCache)
throws TorqueException
{
- return getManager().getInstanceImpl(id, fromCache);
+ return getManager().getOMInstance(id, fromCache);
}
#set ($primaryKeyColumnElements = $torqueGen.getChild("primary-keys").getChildren("column"))
@@ -134,7 +134,7 @@ $torqueGen.mergepoint("serialVersionUid"
#set ($primaryKeyColumnElement = $primaryKeyColumnElements.get(0))
#set ($columnFieldType = $primaryKeyColumnElement.getAttribute("fieldType"))
/**
- * Static accessor for the @see #getInstanceImpl(ObjectKey).
+ * Static accessor for the @see #getOMInstance(ObjectKey).
*
* @param id an <code>ObjectKey</code> value
* @return a <code>${dbObjectClassName}</code> value
@@ -143,11 +143,11 @@ $torqueGen.mergepoint("serialVersionUid"
public static ${dbObjectClassName} getInstance($columnFieldType id)
throws TorqueException
{
- return getManager().getInstanceImpl(SimpleKey.keyFor(id));
+ return getManager().getOMInstance(SimpleKey.keyFor(id));
}
/**
- * Static accessor for the @see #getInstanceImpl(ObjectKey).
+ * Static accessor for the @see #getOMInstance(ObjectKey).
*
* @param id an <code>ObjectKey</code> value
* @param fromCache if true, look for cached ${dbObjectClassName}s before loading
@@ -158,25 +158,25 @@ $torqueGen.mergepoint("serialVersionUid"
public static ${dbObjectClassName} getInstance($columnFieldType id, boolean fromCache)
throws TorqueException
{
- return getManager().getInstanceImpl(SimpleKey.keyFor(id), fromCache);
+ return getManager().getOMInstance(SimpleKey.keyFor(id), fromCache);
}
#end
/**
- * Static accessor for the @see #getInstancesImpl(List).
+ * Static accessor for the @see #getOMs(List).
*
* @param ids a <code>List</code> value
* @return a <code>List</code> value
* @exception TorqueException if an error occurs
*/
- public static List<${dbObjectClassName}> getInstances(List<ObjectKey> ids)
+ public static List<${dbObjectClassName}> getInstances(List<? extends ObjectKey> ids)
throws TorqueException
{
- return getManager().getInstancesImpl(ids);
+ return getManager().getOMs(ids);
}
/**
- * Static accessor for the @see #getInstancesImpl(List, boolean).
+ * Static accessor for the @see #getOMs(List, boolean).
*
* @param ids a <code>List</code> value
* @param fromCache if true, look for cached ${dbObjectClassName}s before loading
@@ -184,13 +184,13 @@ $torqueGen.mergepoint("serialVersionUid"
* @return a <code>List</code> value
* @exception TorqueException if an error occurs
*/
- public static List<${dbObjectClassName}> getInstances(List<ObjectKey> ids, boolean fromCache)
+ public static List<${dbObjectClassName}> getInstances(List<? extends ObjectKey> ids, boolean fromCache)
throws TorqueException
{
- return getManager().getInstancesImpl(ids, fromCache);
+ return getManager().getOMs(ids, fromCache);
}
- public static void putInstance(Persistent om)
+ public static void putInstance(${dbObjectClassName} om)
throws TorqueException
{
getManager().putInstanceImpl(om);
@@ -199,7 +199,7 @@ $torqueGen.mergepoint("serialVersionUid"
public static void clear()
throws TorqueException
{
- getManager().clearImpl();
+ getManager().clear();
}
public static boolean exists(${dbObjectClassName} obj)
@@ -213,7 +213,7 @@ $torqueGen.mergepoint("serialVersionUid"
return getManager().getMethodResultCache();
}
- public static void addCacheListener(CacheListener listener)
+ public static void addCacheListener(CacheListener<? extends Persistent> listener)
{
getManager().addCacheListenerImpl(listener);
}
@@ -230,88 +230,6 @@ $torqueGen.mergepoint("serialVersionUid"
}
/**
- * Get a fresh instance of a ${dbObjectClassName}Manager
- */
- protected ${dbObjectClassName} getInstanceImpl()
- throws TorqueException
- {
- ${dbObjectClassName} obj = null;
- try
- {
- obj = (${dbObjectClassName}) getOMInstance();
- }
- catch (Exception e)
- {
- throw new TorqueException(e);
- }
- return obj;
- }
-
- /**
- * Get a ${dbObjectClassName} with the given id.
- *
- * @param id <code>ObjectKey</code> value
- */
- protected ${dbObjectClassName} getInstanceImpl(ObjectKey id)
- throws TorqueException
- {
- return (${dbObjectClassName}) getOMInstance(id);
- }
-
- /**
- * Get a ${interfaceName} with the given id from the cache. Returns
- * <code>null</code> if instance is not in cache
- *
- * @param id <code>ObjectKey</code> value
- */
- protected ${dbObjectClassName} getCachedInstanceImpl(ObjectKey id)
- throws TorqueException
- {
- return (${dbObjectClassName}) cacheGet(id);
- }
-
- /**
- * Get a ${dbObjectClassName} with the given id.
- *
- * @param id <code>ObjectKey</code> value
- * @param fromCache if true, look for cached ${dbObjectClassName}s before loading
- * from storage.
- */
- protected ${dbObjectClassName} getInstanceImpl(ObjectKey id, boolean fromCache)
- throws TorqueException
- {
- return (${dbObjectClassName}) getOMInstance(id, fromCache);
- }
-
- /**
- * Gets a list of ${dbObjectClassName}s based on id's.
- *
- * @param ids a List of <code>ObjectKeys</code> value
- * @return a <code>List</code> of ${dbObjectClassName}s
- * @exception TorqueException if an error occurs
- */
- protected List<${dbObjectClassName}> getInstancesImpl(List<ObjectKey> ids)
- throws TorqueException
- {
- return (List<${dbObjectClassName}>) getOMs(ids);
- }
-
- /**
- * Gets a list of ${dbObjectClassName}s based on id's.
- *
- * @param ids a List of <code>ObjectKeys</code> value
- * @param fromCache if true, look for cached ${dbObjectClassName}s before loading
- * from storage.
- * @return a <code>List</code> of ${dbObjectClassName}s
- * @exception TorqueException if an error occurs
- */
- protected List<${dbObjectClassName}> getInstancesImpl(List<ObjectKey> ids, boolean fromCache)
- throws TorqueException
- {
- return (List<${dbObjectClassName}>) getOMs(ids, fromCache);
- }
-
- /**
* check for a duplicate project name
*/
protected boolean existsImpl(${dbObjectClassName} om)
@@ -321,6 +239,11 @@ $torqueGen.mergepoint("serialVersionUid"
return ${peerClassName}.doSelect(crit).size() > 0;
}
+ /**
+ * Gets a ModuleEntity based on id.
+ *
+ * @param id a <code>NumberKey</code> value
+ */
protected ${dbObjectClassName} retrieveStoredOM(ObjectKey id)
throws TorqueException
{
@@ -334,10 +257,10 @@ $torqueGen.mergepoint("serialVersionUid"
* @return a <code>List</code> value
* @exception TorqueException if an error occurs
*/
- protected List<${dbObjectClassName}> retrieveStoredOMs(List<ObjectKey> ids)
+ protected List<${dbObjectClassName}> retrieveStoredOMs(List<? extends ObjectKey> ids)
throws TorqueException
{
- return ${peerClassName}.retrieveByPKs(ids);
+ return ${peerClassName}.retrieveByPKs((List<ObjectKey>)ids);
}
$torqueGen.mergepoint("extensions")
}
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org