db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1103201 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/ torque-runtime/src/main/java/org/apache/torque/adapter/ torque-runtime/src/main/java/org/apache/torque/avalon/ torque-runtime/src/main/java/org/apache/t...
Date Sat, 14 May 2011 19:56:59 GMT
Author: tfischer
Date: Sat May 14 19:56:58 2011
New Revision: 1103201

URL: http://svn.apache.org/viewvc?rev=1103201&view=rev
Log:
TORQUE-150: use generics in runtime 

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueRuntimeException.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/Torque.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/TorqueComponent.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java
    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/MethodResultCache.java
    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/Torque.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java?rev=1103201&r1=1103200&r2=1103201&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java Sat
May 14 19:56:58 2011
@@ -420,7 +420,7 @@ public class Torque
      * @return a Map containing all Databases known to Torque, never null.
      * @throws TorqueException if Torque is not yet initialized.
      */
-    public static Map getDatabases() throws TorqueException
+    public static Map<String, Database> getDatabases() throws TorqueException
     {
         return getInstance().getDatabases();
     }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java?rev=1103201&r1=1103200&r2=1103201&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
Sat May 14 19:56:58 2011
@@ -73,10 +73,11 @@ public class TorqueInstance
      * and other operations where the databaase map needs to stay
      * in a defined state must be synchronized to this map.
      */
-    private Map databases = Collections.synchronizedMap(new HashMap());
+    private Map<String, Database> databases
+            = Collections.synchronizedMap(new HashMap<String, Database>());
 
     /** A repository of Manager instances. */
-    private Map managers;
+    private Map<String, AbstractBaseManager> managers;
 
     /** Torque-specific configuration. */
     private Configuration conf;
@@ -98,7 +99,7 @@ public class TorqueInstance
      * are serialized then unserialized prior to Torque being reinitialized.
      * This condition exists in a normal catalina restart.
      */
-    private Map mapBuilderCache = null;
+    private Map<String, MapBuilder> mapBuilderCache = null;
 
     /**
      * Creates a new instance with default configuration.
@@ -163,16 +164,15 @@ public class TorqueInstance
         // re-build any MapBuilders that may have gone lost during serialization
         synchronized (mapBuilderCache)
         {
-            for (Iterator i = mapBuilderCache.entrySet().iterator(); i.hasNext();)
+            for (Map.Entry<String, MapBuilder> entry
+                    : mapBuilderCache.entrySet())
             {
-                Map.Entry entry = (Map.Entry)i.next();
-
                 if (null == entry.getValue())
                 {
                     try
                     {
                         // create and build the MapBuilder
-                        MapBuilder builder = (MapBuilder) Class.forName((String) entry.getKey()).newInstance();
+                        MapBuilder builder = (MapBuilder) Class.forName(entry.getKey()).newInstance();
 
                         if (!builder.isBuilt())
                         {
@@ -253,7 +253,7 @@ public class TorqueInstance
 
         try
         {
-            for (Iterator it = c.getKeys(); it.hasNext();)
+            for (Iterator<?> it = c.getKeys(); it.hasNext();)
             {
                 String key = (String) it.next();
                 if (key.endsWith(DB.ADAPTER_KEY)
@@ -312,7 +312,7 @@ public class TorqueInstance
 
         // check that at least the default database has got an adapter.
         Database defaultDatabase
-                = (Database) databases.get(Torque.getDefaultDB());
+                = databases.get(Torque.getDefaultDB());
         if (defaultDatabase == null
             || defaultDatabase.getAdapter() == null)
         {
@@ -363,7 +363,7 @@ public class TorqueInstance
 
         try
         {
-            for (Iterator it = c.getKeys(); it.hasNext();)
+            for (Iterator<?> it = c.getKeys(); it.hasNext();)
             {
                 String key = (String) it.next();
                 if (key.endsWith(DataSourceFactory.FACTORY_KEY))
@@ -372,7 +372,7 @@ public class TorqueInstance
                     String handle = key.substring(0, key.indexOf('.'));
                     log.debug("handle: " + handle
                             + " DataSourceFactory: " + classname);
-                    Class dsfClass = Class.forName(classname);
+                    Class<?> dsfClass = Class.forName(classname);
                     DataSourceFactory dsf =
                             (DataSourceFactory) dsfClass.newInstance();
                     dsf.initialize(c.subset(handle));
@@ -394,7 +394,7 @@ public class TorqueInstance
         }
 
         Database defaultDatabase
-                = (Database) databases.get(defaultDBName);
+                = databases.get(defaultDBName);
         if (defaultDatabase == null
             || defaultDatabase.getDataSourceFactory() == null)
         {
@@ -515,7 +515,7 @@ public class TorqueInstance
         int pref = Torque.MANAGER_PREFIX.length();
         int suff = Torque.MANAGER_SUFFIX.length();
 
-        for (Iterator it = conf.getKeys(); it.hasNext();)
+        for (Iterator<?> it = conf.getKeys(); it.hasNext();)
         {
             String key = (String) it.next();
 
@@ -558,7 +558,7 @@ public class TorqueInstance
     private synchronized void initManager(String name, String className)
             throws TorqueException
     {
-        AbstractBaseManager manager = (AbstractBaseManager) managers.get(name);
+        AbstractBaseManager manager = managers.get(name);
 
         if (manager == null)
         {
@@ -622,7 +622,7 @@ public class TorqueInstance
      */
     public AbstractBaseManager getManager(String name)
     {
-        AbstractBaseManager m = (AbstractBaseManager) managers.get(name);
+        AbstractBaseManager m = managers.get(name);
         if (m == null)
         {
             log.error("No configured manager for key " + name + ".");
@@ -641,7 +641,7 @@ public class TorqueInstance
     public AbstractBaseManager getManager(String name,
             String defaultClassName)
     {
-        AbstractBaseManager m = (AbstractBaseManager) managers.get(name);
+        AbstractBaseManager m = managers.get(name);
         if (m == null)
         {
             log.debug("Added late Manager mapping for Class: "
@@ -657,7 +657,7 @@ public class TorqueInstance
             }
 
             // Try again now that the default manager should be in the map
-            m = (AbstractBaseManager) managers.get(name);
+            m = managers.get(name);
         }
 
         return m;
@@ -679,9 +679,8 @@ public class TorqueInstance
         // stop the idbrokers
         synchronized (databases)
         {
-            for (Iterator it = databases.values().iterator(); it.hasNext();)
+            for (Database database : databases.values())
             {
-                Database database = (Database) it.next();
                 IDBroker idBroker = database.getIDBroker();
                 if (idBroker != null)
                 {
@@ -693,11 +692,13 @@ public class TorqueInstance
         // shut down the cache managers
         synchronized (managers)
         {
-            for (Iterator it = managers.entrySet().iterator(); it.hasNext();)
+            for (Iterator<Map.Entry<String, AbstractBaseManager>> it
+                    = managers.entrySet().iterator(); it.hasNext();)
             {
-                Map.Entry mentry = (Map.Entry)it.next();
+                Map.Entry<String, AbstractBaseManager> mentry
+                        = it.next();
 
-                AbstractBaseManager manager = (AbstractBaseManager)mentry.getValue();
+                AbstractBaseManager manager = mentry.getValue();
                 manager.dispose();
                 it.remove();
             }
@@ -707,16 +708,15 @@ public class TorqueInstance
         TorqueException exception = null;
         synchronized (databases)
         {
-            for (Iterator it = databases.keySet().iterator(); it.hasNext();)
+            for (Map.Entry<String, Database> databaseMapEntry
+                    : databases.entrySet())
             {
-                Object databaseKey = it.next();
-
-                Database database
-                        = (Database) databases.get(databaseKey);
+                Object databaseKey = databaseMapEntry.getKey();
+                Database database = databaseMapEntry.getValue();
                 if (DEFAULT_NAME.equals(databaseKey) && defaultDsfIsReference)
                 {
                     // the DataSourceFactory of the database with the name
-                    // DEFAULT_NAME is just a reference to aynother entry.
+                    // DEFAULT_NAME is just a reference to another entry.
                     // Do not close because this leads to closing
                     // the same DataSourceFactory twice.
                     database.setDataSourceFactory(null);
@@ -758,8 +758,9 @@ public class TorqueInstance
      */
     private void resetConfiguration()
     {
-        mapBuilderCache = Collections.synchronizedMap(new HashMap());
-        managers = new HashMap();
+        mapBuilderCache = Collections.synchronizedMap(
+                new HashMap<String, MapBuilder>());
+        managers = new HashMap<String, AbstractBaseManager>();
         isInit = false;
     }
 
@@ -804,7 +805,7 @@ public class TorqueInstance
      * @return the MapBuilder cache
      *
      */
-    public Map getMapBuilders()
+    public Map<String, MapBuilder> getMapBuilders()
     {
         return mapBuilderCache;
     }
@@ -843,7 +844,7 @@ public class TorqueInstance
     {
         try
         {
-            MapBuilder mb = (MapBuilder)mapBuilderCache.get(className);
+            MapBuilder mb = mapBuilderCache.get(className);
 
             if (mb == null)
             {
@@ -1079,7 +1080,7 @@ public class TorqueInstance
         {
             throw new TorqueException("Torque is not initialized.");
         }
-        return (Database) databases.get(databaseName);
+        return databases.get(databaseName);
     }
 
     /**
@@ -1094,7 +1095,7 @@ public class TorqueInstance
      * @return a Map containing all Databases known to Torque, never null.
      * @throws TorqueException if Torque is not yet initialized.
      */
-    public Map getDatabases() throws TorqueException
+    public Map<String, Database> getDatabases() throws TorqueException
     {
         if (!isInit())
         {
@@ -1116,7 +1117,7 @@ public class TorqueInstance
     {
         synchronized (databases)
         {
-            Database result = (Database) databases.get(databaseName);
+            Database result = databases.get(databaseName);
             if (result == null)
             {
                 result = new Database(databaseName);

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueRuntimeException.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueRuntimeException.java?rev=1103201&r1=1103200&r2=1103201&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueRuntimeException.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueRuntimeException.java
Sat May 14 19:56:58 2011
@@ -217,7 +217,7 @@ public class TorqueRuntimeException
     {
         String linebreak = System.getProperty("line.separator");
         StringTokenizer st = new StringTokenizer(stackTrace, linebreak);
-        LinkedList list = new LinkedList();
+        LinkedList<String> list = new LinkedList<String>();
         while (st.hasMoreTokens())
         {
             list.add(st.nextToken());

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java?rev=1103201&r1=1103200&r2=1103201&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
Sat May 14 19:56:58 2011
@@ -30,6 +30,7 @@ import org.apache.torque.TorqueException
 import org.apache.torque.sql.Query;
 import org.apache.torque.util.functions.Aggregate;
 import org.apache.torque.util.functions.FunctionEnum;
+import org.apache.torque.util.functions.SQLFunction;
 
 /**
  * This class is the abstract base for any database adapter
@@ -68,7 +69,9 @@ public abstract class AbstractDBAdapter 
     /**
      * The default look up table for function classes.
      */
-    private Map functionClasses = new Hashtable(10);
+    private Map<FunctionEnum, Class<? extends SQLFunction>> functionClasses
+            = new Hashtable<FunctionEnum, Class<? extends SQLFunction>>();
+
     /*
      * Initialize the functionClasses lookup table with SQL99 standard
      * functions. Uses this method because DB implementations don't
@@ -79,11 +82,11 @@ public abstract class AbstractDBAdapter 
      * constructor.
      */
     {
-        functionClasses.put( FunctionEnum.AVG, Aggregate.Avg.class );
-        functionClasses.put( FunctionEnum.COUNT, Aggregate.Count.class );
-        functionClasses.put( FunctionEnum.MAX, Aggregate.Max.class );
-        functionClasses.put( FunctionEnum.MIN, Aggregate.Min.class );
-        functionClasses.put( FunctionEnum.SUM, Aggregate.Sum.class );
+        functionClasses.put(FunctionEnum.AVG, Aggregate.Avg.class);
+        functionClasses.put(FunctionEnum.COUNT, Aggregate.Count.class);
+        functionClasses.put(FunctionEnum.MAX, Aggregate.Max.class);
+        functionClasses.put(FunctionEnum.MIN, Aggregate.Min.class);
+        functionClasses.put(FunctionEnum.SUM, Aggregate.Sum.class);
     }
 
     /**
@@ -314,9 +317,9 @@ public abstract class AbstractDBAdapter 
      *         will work with this type of DB. Null indicates a class was not
      *         found.
      */
-    public Class getFunctionClass( FunctionEnum function )
+    public Class<? extends SQLFunction> getFunctionClass(FunctionEnum function)
     {
-        return (Class) functionClasses.get( function );
+        return functionClasses.get(function);
     }
 
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java?rev=1103201&r1=1103200&r2=1103201&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
Sat May 14 19:56:58 2011
@@ -284,5 +284,5 @@ public interface DB extends Serializable
      * @see AbstractFunction
      * @see Aggregate
      */
-    Class getFunctionClass( FunctionEnum function );
+    Class<?> getFunctionClass(FunctionEnum function);
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java?rev=1103201&r1=1103200&r2=1103201&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java
Sat May 14 19:56:58 2011
@@ -231,17 +231,17 @@ public class DBOracle extends AbstractDB
         // the query must not contain same column names or aliases.
         // Find double column names and aliases and create unique aliases
         // TODO: does not work for functions yet
-        UniqueList selectColumns = query.getSelectClause();
+        UniqueList<String> selectColumns = query.getSelectClause();
         int replacementSuffix = 0;
-        Set columnNames = new HashSet();
+        Set<String> columnNames = new HashSet<String>();
         // first pass: only remember aliased columns
         // No replacements need to take place because double aliases
         // are not allowed anyway
         // So alias names will be retained
-        for (ListIterator columnIt = selectColumns.listIterator();
+        for (ListIterator<String> columnIt = selectColumns.listIterator();
                 columnIt.hasNext();)
         {
-            String selectColumn = (String) columnIt.next();
+            String selectColumn = columnIt.next();
 
             // check for sql function
             if ((selectColumn.indexOf('(') != -1)
@@ -264,10 +264,10 @@ public class DBOracle extends AbstractDB
         }
 
         // second pass. Regard ordinary columns only
-        for (ListIterator columnIt = selectColumns.listIterator();
+        for (ListIterator<String> columnIt = selectColumns.listIterator();
                 columnIt.hasNext();)
         {
-            String selectColumn = (String) columnIt.next();
+            String selectColumn = columnIt.next();
 
             // check for sql function
             if ((selectColumn.indexOf('(') != -1)

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/Torque.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/Torque.java?rev=1103201&r1=1103200&r2=1103201&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/Torque.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/Torque.java
Sat May 14 19:56:58 2011
@@ -231,7 +231,7 @@ public interface Torque
      * @return a Map containing all Databases known to Torque, never null.
      * @throws TorqueException if Torque is not yet initialized.
      */
-    Map getDatabases() throws TorqueException;
+    Map<String, Database> getDatabases() throws TorqueException;
 
     /**
      * Returns the database for the key <code>databaseName</code>.

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/TorqueComponent.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/TorqueComponent.java?rev=1103201&r1=1103200&r2=1103201&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/TorqueComponent.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/avalon/TorqueComponent.java
Sat May 14 19:56:58 2011
@@ -20,7 +20,6 @@ package org.apache.torque.avalon;
  */
 
 import java.io.File;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.avalon.framework.activity.Disposable;
@@ -36,6 +35,7 @@ import org.apache.avalon.framework.logge
 import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.commons.lang.StringUtils;
 import org.apache.torque.TorqueInstance;
+import org.apache.torque.map.MapBuilder;
 
 /**
  * Avalon component for Torque.
@@ -164,14 +164,13 @@ public class TorqueComponent
 
         TorqueInstance instance = org.apache.torque.Torque.getInstance();
 
-        Map mapBuilders = instance.getMapBuilders();
+        Map<String, MapBuilder> mapBuilders = instance.getMapBuilders();
 
         if (mapBuilders != null)
         {
             // Copy the registered MapBuilders and take care that they will be built again
-            for (Iterator  i = mapBuilders.keySet().iterator(); i.hasNext();)
+            for (String className : mapBuilders.keySet())
             {
-                String className = (String)i.next();
                 registerMapBuilder(className);
             }
         }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java?rev=1103201&r1=1103200&r2=1103201&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java
Sat May 14 19:56:58 2011
@@ -202,7 +202,7 @@ public abstract class AbstractDataSource
         {
             try
             {
-                for (Iterator i = c.getKeys(); i.hasNext();)
+                for (Iterator<?> i = c.getKeys(); i.hasNext();)
                 {
                     String key = (String) i.next();
                     setProperty(key, c, o);

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=1103201&r1=1103200&r2=1103201&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
Sat May 14 19:56:58 2011
@@ -62,24 +62,29 @@ public abstract class AbstractBaseManage
     /** method results cache */
     protected MethodResultCache mrCache;
 
-    /** the class that the service will instantiate */
-    private Class omClass;
+    /** The OM class that the service will instantiate. */
+    private Class<? extends Persistent> omClass;
 
+    /** The name of the OM class that the service will instantiate. */
     private String className;
 
+    /** The cache region used for JCS. */
     private String region;
 
+    /** Whether the cache manager has already registered its cache Listeners. */
     private boolean isNew = true;
 
-    protected Map validFields;
-    protected Map listenersMap = new HashMap();
+    protected Map<String, ?> validFields;
+
+    protected Map<String, FastArrayList> listenersMap 
+        = new HashMap<String, FastArrayList>();
 
     /**
      * Get the Class instance
      *
      * @return the om class
      */
-    protected Class getOMClass()
+    protected Class<? extends Persistent> getOMClass()
     {
         return omClass;
     }
@@ -89,7 +94,7 @@ public abstract class AbstractBaseManage
      *
      * @param omClass the om class
      */
-    protected void setOMClass(Class omClass)
+    protected void setOMClass(Class<? extends Persistent> omClass)
     {
         this.omClass = omClass;
     }
@@ -104,11 +109,12 @@ public abstract class AbstractBaseManage
     protected Persistent getOMInstance()
         throws InstantiationException, IllegalAccessException
     {
-        return (Persistent) omClass.newInstance();
+        return omClass.newInstance();
     }
 
     /**
      * Get the classname to instantiate for getInstance()
+     *
      * @return value of className.
      */
     public String getClassName()
@@ -122,14 +128,25 @@ public abstract class AbstractBaseManage
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public void setClassName(String  v)
+    @SuppressWarnings("unchecked")
+    public void setClassName(String v)
         throws TorqueException
     {
         this.className = v;
 
         try
         {
-            setOMClass(Class.forName(getClassName()));
+            Class<?> clazz = Class.forName(getClassName());
+            if (Persistent.class.isAssignableFrom(clazz))
+            {
+                setOMClass((Class<? extends Persistent>) clazz);
+            }
+            else
+            {
+                throw new TorqueException(
+                        getClassName()
+                        + " does not implement the interface Persistent");
+            }
         }
         catch (ClassNotFoundException cnfe)
         {
@@ -345,7 +362,7 @@ public abstract class AbstractBaseManage
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    protected List getOMs(ObjectKey[] ids)
+    protected List<? extends Object> getOMs(ObjectKey[] ids)
         throws TorqueException
     {
         return getOMs(Arrays.asList(ids));
@@ -359,7 +376,7 @@ public abstract class AbstractBaseManage
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    protected List getOMs(List ids)
+    protected List<? extends Object> getOMs(List<ObjectKey>  ids)
         throws TorqueException
     {
         return getOMs(ids, true);
@@ -373,18 +390,18 @@ public abstract class AbstractBaseManage
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    protected List getOMs(List ids, boolean fromCache)
+    protected List<? extends Object> getOMs(List<ObjectKey> ids, boolean fromCache)
         throws TorqueException
     {
-        List oms = null;
+        List<Object> 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(ids);
-            List newIds = new ArrayList(ids.size());
+            oms = new ArrayList<Object>(ids);
+            List<ObjectKey> newIds = new ArrayList<ObjectKey>(ids.size());
             for (int i = 0; i < ids.size(); i++)
             {
-                ObjectKey key = (ObjectKey) ids.get(i);
+                ObjectKey key = ids.get(i);
                 Persistent om = null;
                 if (fromCache)
                 {
@@ -402,7 +419,7 @@ public abstract class AbstractBaseManage
 
             if (newIds.size() > 0)
             {
-                List newOms = retrieveStoredOMs(newIds);
+                List<? extends Object> newOms = retrieveStoredOMs(newIds);
                 for (int i = 0; i < oms.size(); i++)
                 {
                     if (oms.get(i) instanceof ObjectKey)
@@ -432,20 +449,21 @@ public abstract class AbstractBaseManage
 
     /**
      * Gets a list of om's based on id's.
-     * This method must be implemented in the drived class
+     * This method must be implemented in the derived class
      *
      * @param ids a <code>List</code> of <code>ObjectKey</code>'s
      * @return a <code>List</code> value
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    protected abstract List retrieveStoredOMs(List ids)
+    protected abstract List<? extends Object> retrieveStoredOMs(
+            List<ObjectKey> ids)
         throws TorqueException;
 
     /**
-     * Get the value of region.
+     * Get the cache region used for JCS.
      *
-     * @return value of region.
+     * @return the cache region used for JCS.
      */
     public String getRegion()
     {
@@ -453,7 +471,7 @@ public abstract class AbstractBaseManage
     }
 
     /**
-     * Set the value of region.
+     * Set the cache region used for JCS.
      *
      * @param v  Value to assign to region.
      * @throws TorqueException Any exceptions caught during processing will be
@@ -489,18 +507,12 @@ public abstract class AbstractBaseManage
     /**
      * @return The cache instance.
      */
-    public MethodResultCache getMethodResultCache()
+    public synchronized MethodResultCache getMethodResultCache()
     {
         if (isNew)
         {
-            synchronized (this)
-            {
-                if (isNew)
-                {
-                    registerAsListener();
-                    isNew = false;
-                }
-            }
+            registerAsListener();
+            isNew = false;
         }
         return mrCache;
     }
@@ -519,26 +531,24 @@ public abstract class AbstractBaseManage
      */
     public void addCacheListenerImpl(CacheListener listener)
     {
-        List keys = listener.getInterestedFields();
-        Iterator i = keys.iterator();
-        while (i.hasNext())
+        List<String> keys = listener.getInterestedFields();
+        for (String key : keys)
         {
-            String key = (String) i.next();
             // Peer.column names are the fields
             if (validFields != null && validFields.containsKey(key))
             {
-                List listeners = (List) listenersMap.get(key);
+                FastArrayList listeners = listenersMap.get(key);
                 if (listeners == null)
                 {
                     listeners = createSubsetList(key);
                 }
 
                 boolean isNew = true;
-                Iterator j = listeners.iterator();
+                Iterator<?> j = listeners.iterator();
                 while (j.hasNext())
                 {
                     Object listener2 =
-                        ((WeakReference) j.next()).get();
+                        ((WeakReference<?>) j.next()).get();
                     if (listener2 == null)
                     {
                         // do a little cleanup while checking for dupes
@@ -554,7 +564,7 @@ public abstract class AbstractBaseManage
                 }
                 if (isNew)
                 {
-                    listeners.add(new WeakReference(listener));
+                    listeners.add(new WeakReference<CacheListener>(listener));
                 }
             }
         }
@@ -565,7 +575,7 @@ public abstract class AbstractBaseManage
      * @param key
      * @return A subset of the list identified by <code>key</code>.
      */
-    private synchronized List createSubsetList(String key)
+    private synchronized FastArrayList createSubsetList(String key)
     {
         FastArrayList list = null;
         if (listenersMap.containsKey(key))
@@ -587,18 +597,18 @@ public abstract class AbstractBaseManage
      * @param oldOm
      * @param om
      */
-    protected void notifyListeners(List listeners,
+    protected void notifyListeners(List<?> listeners,
                                    Persistent oldOm, Persistent om)
     {
         if (listeners != null)
         {
             synchronized (listeners)
             {
-                Iterator i = listeners.iterator();
+                Iterator<?> i = listeners.iterator();
                 while (i.hasNext())
                 {
                     CacheListener listener = (CacheListener)
-                        ((WeakReference) i.next()).get();
+                        ((WeakReference<?>) 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=1103201&r1=1103200&r2=1103201&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
Sat May 14 19:56:58 2011
@@ -47,5 +47,5 @@ public interface CacheListener
     /**
      *
      */
-    List getInterestedFields();
+    List<String> getInterestedFields();
 }

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=1103201&r1=1103200&r2=1103201&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
Sat May 14 19:56:58 2011
@@ -45,7 +45,7 @@ public class MethodResultCache
 {
     private ObjectPool pool;
     private GroupCacheAccess jcsCache;
-    private Map groups;
+    private Map<String, Object> groups;
 
     /** Logging */
     private static Log log = LogFactory.getLog(MethodResultCache.class);
@@ -54,7 +54,7 @@ public class MethodResultCache
         throws TorqueException
     {
         this.jcsCache = cache;
-        groups = new HashMap();
+        groups = new HashMap<String, Object>();
         pool = new StackObjectPool(new MethodCacheKey.Factory(), 10000);
     }
 

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=1103201&r1=1103200&r2=1103201&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
Sat May 14 19:56:58 2011
@@ -293,7 +293,7 @@ $torqueGen.mergepoint("serialVersionUid"
     protected List<${dbObjectClassName}> getInstancesImpl(List<ObjectKey> ids)
         throws TorqueException
     {
-        return getOMs(ids);
+        return (List<${dbObjectClassName}>) getOMs(ids);
     }
 
     /**
@@ -308,7 +308,7 @@ $torqueGen.mergepoint("serialVersionUid"
     protected List<${dbObjectClassName}> getInstancesImpl(List<ObjectKey> ids,
boolean fromCache)
         throws TorqueException
     {
-        return getOMs(ids, fromCache);
+        return (List<${dbObjectClassName}>) getOMs(ids, fromCache);
     }
 
     /**
@@ -335,7 +335,7 @@ $torqueGen.mergepoint("serialVersionUid"
      * @return a <code>List</code> value
      * @exception TorqueException if an error occurs
      */
-    protected List<${dbObjectClassName}> retrieveStoredOMs(List ids)
+    protected List<${dbObjectClassName}> retrieveStoredOMs(List<ObjectKey> ids)
         throws TorqueException
     {
         return ${peerClassName}.retrieveByPKs(ids);



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message