You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2002/03/13 22:31:23 UTC

cvs commit: jakarta-turbine-torque/src/templates/om Interface.vm BaseManager.vm Control.vm ExtensionManager.vm ExtensionObject.vm ObjectWithManager.vm Peer.vm

jmcnally    02/03/13 13:31:23

  Modified:    src/dtd  database.dtd
               src/java/org/apache/torque Torque.java
               src/java/org/apache/torque/engine/database/model Table.java
               src/templates/om BaseManager.vm Control.vm
                        ExtensionManager.vm ExtensionObject.vm
                        ObjectWithManager.vm Peer.vm
  Added:       src/java/org/apache/torque/manager AbstractBaseManager.java
                        CacheListener.java MethodCacheKey.java
                        MethodResultCache.java
               src/templates/om Interface.vm
  Removed:     src/java/org/apache/torque/om AbstractBaseManager.java
  Log:
  added method result caching to managers and moved the managers code to its own
  package.
  
  Also allow the declaration of an interface to be implemented by the objects
  returned by a manager, so multiple implementations are possible.  The interface
  stub is created if not present.
  
  Revision  Changes    Path
  1.11      +6 -1      jakarta-turbine-torque/src/dtd/database.dtd
  
  Index: database.dtd
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/dtd/database.dtd,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- database.dtd	27 Dec 2001 20:49:32 -0000	1.10
  +++ database.dtd	13 Mar 2002 21:31:22 -0000	1.11
  @@ -1,6 +1,6 @@
   <!--
       Torque XML database schema DTD
  -    $Id: database.dtd,v 1.10 2001/12/27 20:49:32 jmcnally Exp $
  +    $Id: database.dtd,v 1.11 2002/03/13 21:31:22 jmcnally Exp $
   -->
   
   <!--
  @@ -43,6 +43,10 @@
     heavyIndexing (true|false) "false"
   >
   
  +<!-- 
  +     note: the interface="true", requires that useManagers=true in the
  +     properties file. 
  +-->
   <!ELEMENT table (column+,(foreign-key|index|unique|id-method-parameter)*)>
   <!ATTLIST table
     name CDATA #REQUIRED
  @@ -53,6 +57,7 @@
     baseClass CDATA #IMPLIED
     basePeer CDATA #IMPLIED
     alias CDATA #IMPLIED
  +  interface (true|false) #IMPLIED
     javaNamingMethod (nochange|underscore|javaname) #IMPLIED
     heavyIndexing (true|false) #IMPLIED
     description CDATA #IMPLIED
  
  
  
  1.49      +2 -2      jakarta-turbine-torque/src/java/org/apache/torque/Torque.java
  
  Index: Torque.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- Torque.java	13 Mar 2002 20:57:36 -0000	1.48
  +++ Torque.java	13 Mar 2002 21:31:23 -0000	1.49
  @@ -76,7 +76,7 @@
   import org.apache.torque.pool.ConnectionPool;
   import org.apache.torque.pool.DBConnection;
   import org.apache.torque.util.BasePeer;
  -import org.apache.torque.om.AbstractBaseManager;
  +import org.apache.torque.manager.AbstractBaseManager;
   import org.apache.stratum.configuration.Configuration;
   import org.apache.stratum.configuration.PropertiesConfiguration;
   import org.apache.stratum.lifecycle.Configurable;
  @@ -90,7 +90,7 @@
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  - * @version $Id: Torque.java,v 1.48 2002/03/13 20:57:36 jmcnally Exp $
  + * @version $Id: Torque.java,v 1.49 2002/03/13 21:31:23 jmcnally Exp $
    */
   public class Torque implements Initializable, Configurable
   {
  
  
  
  1.25      +23 -1     jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Table.java
  
  Index: Table.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Table.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Table.java	1 Mar 2002 14:16:01 -0000	1.24
  +++ Table.java	13 Mar 2002 21:31:23 -0000	1.25
  @@ -75,7 +75,7 @@
    * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
    * @author <a href="mailto:dlr@collab.net>Daniel Rall</a>
    * @author <a href="mailto:byron_foster@byron_foster@yahoo.com>Byron Foster</a>
  - * @version $Id: Table.java,v 1.24 2002/03/01 14:16:01 mpoeschl Exp $
  + * @version $Id: Table.java,v 1.25 2002/03/13 21:31:23 jmcnally Exp $
    */
   public class Table implements IDMethod
   {
  @@ -100,6 +100,7 @@
       private boolean skipSql;
       private boolean abstractValue;
       private String alias;
  +    private String enterface;
       // private String pkg;
       private String baseClass;
       private String basePeer;
  @@ -171,6 +172,7 @@
               || (!"false".equals(attrib.getValue("heavyIndexing")) &&
                   getDatabase().isHeavyIndexing());
           description = attrib.getValue("description");
  +        enterface = attrib.getValue("interface");
       }
   
       /**
  @@ -710,6 +712,26 @@
       {
           this.alias = v;
       }
  +
  +    
  +    /**
  +     * Interface which objects for this table will implement
  +     * @return value of interface.
  +     */
  +    public String getInterface() 
  +    {
  +        return enterface;
  +    }
  +    
  +    /**
  +     * Interface which objects for this table will implement
  +     * @param v  Value to assign to interface.
  +     */
  +    public void setInterface(String  v) 
  +    {
  +        this.enterface = v;
  +    }
  +    
   
       /**
        * When a table is abstract, it marks the business object class that is
  
  
  
  1.1                  jakarta-turbine-torque/src/java/org/apache/torque/manager/AbstractBaseManager.java
  
  Index: AbstractBaseManager.java
  ===================================================================
  package org.apache.torque.manager;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.lang.ref.WeakReference;
  import java.util.Arrays;
  import java.util.List;
  import java.util.ArrayList;
  import java.util.LinkedList;
  import java.util.Map;
  import java.util.HashMap;
  import java.util.Iterator;
  
  import org.apache.stratum.jcs.JCS;
  import org.apache.stratum.jcs.access.behavior.ICacheAccess;
  import org.apache.stratum.jcs.access.exception.CacheException;
  
  import org.apache.torque.TorqueException;
  import org.apache.torque.om.ObjectKey;
  import org.apache.torque.om.Persistent;
  import org.apache.log4j.Category;
  
  /**
   * 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.1 2002/03/13 21:31:23 jmcnally Exp $
   */
  public abstract class AbstractBaseManager
  {
      protected static final Category category =
          Category.getInstance(AbstractBaseManager.class.getName());
  
      /** used to cache the om objects */
      protected ICacheAccess 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 lockCache;
      private int inGet;
  
      protected Map validFields;
      protected Map listenersMap = new HashMap();
  
      /**
       * Get the Class instance
       */
      protected Class getOMClass()
      {
          return omClass;
      }
  
      /**
       * Set the Class that will be instantiated by this manager
       */
      protected void setOMClass(Class omClass)
      {
          this.omClass = omClass;
      }
  
      /**
       * Get a fresh instance of an om
       */
      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.
       */
      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
       */
      protected Persistent getOMInstance(ObjectKey id)
          throws TorqueException
      {
          return getOMInstance(id, true);
      }
  
      /**
       * Return an instance of an om based on the id
       */
      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;
      }
  
      private Persistent cacheGet(ObjectKey key)
      {
          Persistent om = null;
          if (cache != null)
          {
              if (lockCache)
              {
                  synchronized (this)
                  {
                      om = (Persistent)cache.get(key);
                  }
              }
              else
              {
                  inGet++;
                  om = (Persistent)cache.get(key);
                  inGet--;
              }
          }
          return om;
      }
  
      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);
              }
          }
      }
  
  
      protected Persistent removeInstanceImpl(ObjectKey key)
          throws TorqueException
      {
          Persistent oldOm = null;
          if (cache != null)
          {
              synchronized (this)
              {
                  lockCache = true;
                  try
                  {
                      oldOm = (Persistent)cache.get(key);
                      while (inGet > 0) 
                      {
                          Thread.yield();
                      }                    
                      cache.remove(key);
                  }
                  catch (CacheException ce)
                  {
                      lockCache = false;
                      throw new TorqueException(
                      "Could not remove from cache due to internal JCS error.", 
                          ce);
                  }
                  finally
                  {
                      lockCache = false;
                  }
              }
          }
          return oldOm;
      }
  
      protected Persistent putInstanceImpl(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)
          {
              synchronized (this)
              {
                  lockCache = true;
                  try
                  {
                      ObjectKey key = om.getPrimaryKey();
                      oldOm = (Persistent)cache.get(key);
                      while (inGet > 0) 
                      {
                          Thread.yield();
                      }                    
                      cache.put(key, om);
                  }
                  catch (CacheException ce)
                  {
                      lockCache = false;
                      throw new TorqueException(
                          "Could not cache due to internal JCS error.", ce);
                  }
                  finally
                  {
                      lockCache = false;
                  }
              }
          }
          return oldOm;
      }
  
      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
       * @exception TorqueException if an error occurs
       */
      protected List getOMs(ObjectKey[] ids)
          throws TorqueException
      {
          return getOMs(Arrays.asList(ids));
      }
  
      /**
       * Gets a list of om's based on id's.
       *
       * @param ids a <code>List</code> of <code>ObjectKey</code>'s
       * @return a <code>List</code> value
       * @exception TorqueException if an error occurs
       */
      protected List getOMs(List ids)
          throws TorqueException
      {
          return getOMs(ids, true);
      }
  
      /**
       * Gets a list of om's based on id's.
       *
       * @param ids a <code>List</code> of <code>ObjectKey</code>'s
       * @return a <code>List</code> value
       * @exception TorqueException if an error occurs
       */
      protected List getOMs(List ids, boolean fromCache)
          throws TorqueException
      {
          List 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());
              for ( int i=0; i<ids.size(); i++ )
              {
                  ObjectKey key = (ObjectKey)ids.get(i);
                  Persistent om = null;
                  if (fromCache)
                  {
                      om = cacheGet(key);
                  }
                  if (om == null)
                  {
                      newIds.add(key);
                  }
                  else
                  {
                      oms.set(i, om);
                  }
              }
  
              if ( newIds.size() > 0 )
              {
                  List newOms = retrieveStoredOMs(newIds);
                  for ( int i=0; i<oms.size(); i++ )
                  {
                      if ( oms.get(i) instanceof ObjectKey )
                      {
                          for ( int j=newOms.size(); 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;
                              }
                          }
                      }
                  }
              }
          }
          return oms;
      }
  
      protected abstract List retrieveStoredOMs(List ids)
          throws TorqueException;
  
      /**
       * Get the value of region.
       * @return value of region.
       */
      public String getRegion()
      {
          return region;
      }
  
      /**
       * Set the value of region.
       * @param v  Value to assign to region.
       */
      public void setRegion(String  v)
          throws TorqueException
      {
          this.region = v;
          try
          {
              cache = JCS.getInstance(getRegion());
              mrCache = new MethodResultCache(cache);
          }
          catch (Exception e)
          {
              throw new TorqueException(
                  "Cache could not be initialized", e);
          }
          if (cache == null)
          {
              category.info("Cache was not be initialized for region: " + v);
          }
      }
  
      public MethodResultCache getMethodResultCache()
      {
          return mrCache;
      }
  
      public void addCacheListenerImpl(CacheListener listener)
      {
          List subsetKeys = listener.getInterestedFields();
          Iterator i = subsetKeys.iterator();
          while (i.hasNext()) 
          {
              Object[] ie = (Object[])i.next();
              String key1 = (String)ie[0];
           
              // Peer.column names are the fields
              if (validFields != null && validFields.containsKey(key1)) 
              {
                  ObjectKey key2 = (ObjectKey)ie[1];
                  Map subsetMap = (Map)listenersMap.get(key1);
                  if (subsetMap == null) 
                  {
                      subsetMap = createSubsetMap(key1);
                  }
                  
                  List listeners = (List)subsetMap.get(key2);
                  if (listeners == null) 
                  {
                      listeners = createIdList(subsetMap, key2);
                  }
                  synchronized (listeners)
                  {
                      listeners.add(new WeakReference(listener));
                  }
              }            
          }
      }
  
      synchronized private Map createSubsetMap(String key)
      {
          Map map = null;
          if (listenersMap.containsKey(key)) 
          {
              map = (Map)listenersMap.get(key);
          }
          else 
          {
              map = new HashMap();
              listenersMap.put(key, map);
          }
          return map;
      }
  
      synchronized private List createIdList(Map map, ObjectKey key)
      {
          List l = null;
          if (map.containsKey(key)) 
          {
              l = (List)map.get(key);
          }
          else 
          {
              l = new LinkedList();
              map.put(key, l);
          }
          return l;
      }
  
      protected void notifyListeners(List listeners, 
                                     Persistent oldOm, Persistent om)
      {
          if (listeners != null) 
          {
              synchronized (listeners)
              {
                  Iterator i = listeners.iterator();
                  while (i.hasNext()) 
                  {
                      CacheListener listener = (CacheListener)
                          ((WeakReference)i.next()).get();
                      if (listener == null) 
                      {
                          // remove reference as its object was cleared
                          i.remove();
                      }
                      else 
                      {
                          if (oldOm == null) 
                          {
                              // object was added
                              listener.addedObject(om);
                          }
                          else 
                          {
                              // object was refreshed
                              listener.refreshedObject(om);
                          }
                      }
                  }
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-turbine-torque/src/java/org/apache/torque/manager/CacheListener.java
  
  Index: CacheListener.java
  ===================================================================
  package org.apache.torque.manager;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.List;
  import org.apache.torque.om.Persistent;
  
  /**
   * Listener for cache events
   *
   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
   * @version $Id: CacheListener.java,v 1.1 2002/03/13 21:31:23 jmcnally Exp $
   */
  public interface CacheListener
  {
      public void addedObject(Persistent om);
      public void refreshedObject(Persistent om);
      //public void removedObject(Persistent om);
      public List getInterestedFields();
  }
  
  
  
  1.1                  jakarta-turbine-torque/src/java/org/apache/torque/manager/MethodCacheKey.java
  
  Index: MethodCacheKey.java
  ===================================================================
  package org.apache.torque.manager;
  
  /* ================================================================
   * Copyright (c) 2001 Collab.Net.  All rights reserved.
   * 
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are
   * met:
   * 
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   * 
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in the
   * documentation and/or other materials provided with the distribution.
   * 
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement: "This product includes
   * software developed by Collab.Net <http://www.Collab.Net/>."
   * Alternately, this acknowlegement may appear in the software itself, if
   * and wherever such third-party acknowlegements normally appear.
   * 
   * 4. The hosted project names must not be used to endorse or promote
   * products derived from this software without prior written
   * permission. For written permission, please contact info@collab.net.
   * 
   * 5. Products derived from this software may not use the "Tigris" or 
   * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without 
   * prior written permission of Collab.Net.
   * 
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
   * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   * 
   * This software consists of voluntary contributions made by many
   * individuals on behalf of Collab.Net.
   */ 
  
  import java.io.Serializable;
  import org.apache.commons.lang.Objects;
  import org.apache.log4j.Category;
  import org.apache.stratum.pool.AbstractPoolable;
  
  public class MethodCacheKey
      extends AbstractPoolable
      implements Serializable
  {
      //private static final Category log = 
      //    Category.getInstance("org.apache.torque");
  
      int n;
      private Serializable instanceOrClass;
      private String method;
      private Serializable arg1;
      private Serializable arg2;
      private Serializable arg3;
      private Serializable[] moreThanThree;
      private boolean lenient; 
  
      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);
      }
  
      /**
       * Initialize key for method with no 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
       */
      public void init(Serializable instanceOrClass, String method) 
      {
          n = 0;
          this.instanceOrClass = instanceOrClass;
          this.method = 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)
      {
          n = 1;
          this.instanceOrClass = instanceOrClass;
          this.method = method;
          this.arg1 = arg1;
      }
  
      /**
       * 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)
      {
          n = 2;
          this.instanceOrClass = instanceOrClass;
          this.method = method;
          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)
      {
          n = 3;
          this.instanceOrClass = instanceOrClass;
          this.method = method;
          this.arg1 = arg1;
          this.arg2 = arg2;
          this.arg3 = arg3;
      }
  
      /**
       * Initialize key for method with more than two arguments.
       *
       * @param 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
       */
      public void init(Serializable[] keys)
      {
          n = keys.length-2;
          this.instanceOrClass = keys[0];
          this.method = (String)keys[1];
          if (n>0) 
          {
              this.arg1 = keys[2];
              if (n>1) 
              {
                  this.arg2 = keys[3];
                  if (n>2) 
                  {
                      this.arg2 = keys[4];
                      if (n>3) 
                      {
                          this.moreThanThree = keys;                
                      }
                  }
              }
          }
      }
  
      public void setLenient(boolean v)
      {
          lenient = v;
      }
  
      public boolean equals(Object obj)
      {
          boolean equal = false;
          if ( obj instanceof MethodCacheKey ) 
          {
              MethodCacheKey sck = (MethodCacheKey)obj;
              equal = lenient || sck.n == n;
              equal &= Objects.equals(sck.method, method);
              equal &= Objects.equals(sck.instanceOrClass, instanceOrClass);
              if (equal && n > 0 && !lenient && !sck.lenient) 
              {
                  equal &= Objects.equals(sck.arg1, arg1);
                  if (equal && n > 1) 
                  {
                      equal &= Objects.equals(sck.arg2, arg2);
                      if (equal && n > 2) 
                      {
                          equal &= Objects.equals(sck.arg3, arg3);
                          if (equal && n > 3) 
                          {
                              for (int i=5; i<n+2; i++) 
                              {
                                  equal &= Objects.equals(sck.moreThanThree[i], 
                                                          moreThanThree[i]);
                              }
                          }
                      }
                  }
              }
          }            
  
          return equal;
      }
  
      public int hashCode()
      {
          int h = instanceOrClass.hashCode();
          h += method.hashCode();
          /* lenient equals requires hashCode only reflect the
             object and method name
          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());
                          }
                      }        
                  }    
              }
          }
          */
          return h;
      }
  
      public String toString()
      {
          StringBuffer sb = new StringBuffer(50);
          sb.append(instanceOrClass.toString());
          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();
      }
  
      // ****************** Poolable implementation ************************
  
      /**
       * Disposes the object after use. The method is called when the
       * object is returned to its pool.  The dispose method must call
       * its super.
       */
      public void dispose()
      {
          super.dispose();
          instanceOrClass = null;
          method = null;
          arg1 = null;
          arg2 = null;
          arg3 = null;
          moreThanThree = null;
          lenient = false;
      }
  }
  
  
  
  1.1                  jakarta-turbine-torque/src/java/org/apache/torque/manager/MethodResultCache.java
  
  Index: MethodResultCache.java
  ===================================================================
  package org.apache.torque.manager;
  
  /* ================================================================
   * Copyright (c) 2001 Collab.Net.  All rights reserved.
   * 
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are
   * met:
   * 
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   * 
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in the
   * documentation and/or other materials provided with the distribution.
   * 
   * 3. The end-user documentation included with the redistribution, if
   * any, must include the following acknowlegement: "This product includes
   * software developed by Collab.Net <http://www.Collab.Net/>."
   * Alternately, this acknowlegement may appear in the software itself, if
   * and wherever such third-party acknowlegements normally appear.
   * 
   * 4. The hosted project names must not be used to endorse or promote
   * products derived from this software without prior written
   * permission. For written permission, please contact info@collab.net.
   * 
   * 5. Products derived from this software may not use the "Tigris" or 
   * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without 
   * prior written permission of Collab.Net.
   * 
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
   * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   * 
   * This software consists of voluntary contributions made by many
   * individuals on behalf of Collab.Net.
   */ 
  
  import java.util.Map;
  import java.util.HashMap;
  import java.util.WeakHashMap;
  import java.util.Iterator;
  import java.io.Serializable;
  import org.apache.log4j.Category;
  //import org.apache.stratum.configuration.Configuration;
  import org.apache.stratum.pool.DefaultPoolManager;
  import org.apache.stratum.jcs.access.behavior.ICacheAccess;
  import org.apache.stratum.jcs.access.exception.CacheException;
  
  import org.apache.torque.TorqueException;
  
  /**
   * This class provides a cache for convenient storage of method results
   *
   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
   * @version $Id: MethodResultCache.java,v 1.1 2002/03/13 21:31:23 jmcnally Exp $
   */
  public class MethodResultCache 
  {
      private static final Category log = 
          Category.getInstance("org.apache.torque");
  
      private static final String keyClassName =
          "org.apache.torque.manager.MethodCacheKey";
      private DefaultPoolManager pool;
      private Map keys;
      private ICacheAccess jcsCache;
      private Class keyClass;
      private boolean lockCache;
      private int inGet;
  
      /*
      public MethodResultCache()
      {
          keyClass = Class
              .forName(keyClassName);
      }
      */
  
      public MethodResultCache(ICacheAccess cache)
          throws ClassNotFoundException
      {
          keys = new WeakHashMap();            
          keyClass = Class.forName(keyClassName);
          this.jcsCache = cache;            
          pool =  new DefaultPoolManager();
          pool.setCapacity(keyClassName, 10000);
      }
  
      public void clear()
      {
          if (jcsCache != null)
          {
              try
              {
                  jcsCache.remove();
  
                  // clear out local map of keys, return to pool
                  Iterator i = keys.keySet().iterator();
                  while (i.hasNext()) 
                  {
                      pool.putInstance(i.next());
                  }
                  keys.clear();
              }
              catch (CacheException ce)
              {
                  log.error(new TorqueException(
                      "Could not clear cache due to internal JCS error.", ce));
              }
          }
      }
  
      protected Object getImpl(MethodCacheKey key)
      {
          Object result = null;
          if (jcsCache != null)
          {
              if (lockCache)
              {
                  synchronized (this)
                  {
                      result = jcsCache.get(key);
                  }
              }
              else
              {
                  inGet++;
                  result = jcsCache.get(key);
                  inGet--;
              }
          }
  
          if (result != null) 
          {
              log.debug("MethodResultCache saved expensive operation: " + key);
          }
          
          return result;
      }
  
  
      protected Object putImpl(MethodCacheKey key, Object value)
          throws TorqueException
      {
          Object old = null;
          if (jcsCache != null)
          {
              synchronized (this)
              {
                  lockCache = true;
                  try
                  {
                      old = jcsCache.get(key);
                      while (inGet > 0) 
                      {
                          Thread.yield();
                      }                    
                      jcsCache.put(key, value);
                      keys.put(key, key);
                  }
                  catch (CacheException ce)
                  {
                      lockCache = false;
                      throw new TorqueException(
                          "Could not cache due to internal JCS error.", ce);
                  }
                  finally
                  {
                      lockCache = false;
                  }
              }
          }
          return old;
      }
  
      protected Object removeImpl(MethodCacheKey key)
          throws TorqueException
      {
          Object old = null;
          if (jcsCache != null)
          {
              synchronized (this)
              {
                  lockCache = true;
                  try
                  {
                      old = jcsCache.get(key);
                      while (inGet > 0) 
                      {
                          Thread.yield();
                      }
                      jcsCache.remove(key);
                      pool.putInstance(keys.remove(key));
                  }
                  catch (CacheException ce)
                  {
                      lockCache = false;
                      throw new TorqueException(
                          "Could not cache due to internal JCS error.", ce);
                  }
                  finally
                  {
                      lockCache = false;
                  }
              }
          }
          return old;
      }
  
  
      public Object get(Serializable instanceOrClass, String method)
      {
          Object result = null;
          if (jcsCache != null) 
          {
              try
              {
                  MethodCacheKey key = 
                      (MethodCacheKey)pool.getInstance(keyClass);
                  key.init(instanceOrClass, method);
                  result = getImpl(key);
                  pool.putInstance(key);
              }
              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.getInstance(keyClass);
                  key.init(instanceOrClass, method, arg1);
                  result = getImpl(key);
                  pool.putInstance(key);
              }
              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.getInstance(keyClass);
                  key.init(instanceOrClass, method, arg1, arg2);
                  result = getImpl(key);
                  pool.putInstance(key);
              }
              catch (Exception e)
              {
                  log.error(e);
              }
          }
          return result;
      }
  
      public Object get(Serializable instanceOrClass, String method,
                        Serializable arg1, Serializable arg2,
                        Serializable arg3)
      {
          Object result = null;
          if (jcsCache != null) 
          {
              try
              {
                  MethodCacheKey key = 
                      (MethodCacheKey)pool.getInstance(keyClass);
                  key.init(instanceOrClass, method, arg1, arg2, arg3);
                  result = getImpl(key);
                  pool.putInstance(key);
              }
              catch (Exception e)
              {
                  log.error(e);
              }
          }
          return result;
      }
  
      public Object get(Serializable[] keys)
      {
          Object result = null;
          if (jcsCache != null) 
          {
              try
              {
                  MethodCacheKey key = 
                      (MethodCacheKey)pool.getInstance(keyClass);
                  key.init(keys);
                  result = getImpl(key);
                  pool.putInstance(key);
              }
              catch (Exception e)
              {
                  log.error(e);
              }
          }
          return result;
      }
  
      public void put(Object value, Serializable instanceOrClass,  String method)
      {
          try
          {
              MethodCacheKey key =  
                  (MethodCacheKey)pool.getInstance(keyClass);
              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.getInstance(keyClass);
              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.getInstance(keyClass);
              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.getInstance(keyClass);
              key.init(instanceOrClass, method, arg1, arg2, arg3);
              putImpl(key, value);
          }
          catch (Exception e)
          {
              log.error(e);
          }
      }
  
      public void put(Object value, Serializable[] keys)
      {
          try
          {
              MethodCacheKey key =  
                  (MethodCacheKey)pool.getInstance(keyClass);
              key.init(keys);
              putImpl(key, value);
          }
          catch (Exception e)
          {
              log.error(e);
          }
      }
  
  
      public int removeAll(Serializable instanceOrClass, String method)
      {
          int result = -1;
          if (jcsCache != null) 
          {
              try
              {
                  MethodCacheKey key = 
                      (MethodCacheKey)pool.getInstance(keyClass);
                  key.init(instanceOrClass, method);
                  key.setLenient(true);
                  Object obj = null;
                  do 
                  {
                      obj = removeImpl(key);
                      result++;
                  }
                  while (obj != null);
                  pool.putInstance(key);
              }
              catch (Exception e)
              {
                  log.error(e);
              }            
          }
          return result;
      }
  
  
      public Object remove(Serializable instanceOrClass, String method)
      {
          Object result = null;
          if (jcsCache != null) 
          {
              try
              {
                  MethodCacheKey key = 
                      (MethodCacheKey)pool.getInstance(keyClass);
                  key.init(instanceOrClass, method);
                  result = removeImpl(key);
                  pool.putInstance(key);
              }
              catch (Exception e)
              {
                  log.error(e);
              }            
          }
          return result;
      }
  
      public Object remove(Serializable instanceOrClass, String method,
                           Serializable arg1)
      {
          Object result = null;
          if (jcsCache != null) 
          {
              try
              {
                  MethodCacheKey key = 
                      (MethodCacheKey)pool.getInstance(keyClass);
                  key.init(instanceOrClass, method, arg1);
                  result = removeImpl(key);
                  pool.putInstance(key);
              }
              catch (Exception e)
              {
                  log.error(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.getInstance(keyClass);
                  key.init(instanceOrClass, method, arg1, arg2);
                  result = removeImpl(key);
                  pool.putInstance(key);
              }
              catch (Exception e)
              {
                  log.error(e);
              }
          }
          return result;
      }
  
      public Object remove(Serializable instanceOrClass, String method,
                           Serializable arg1, Serializable arg2,
                           Serializable arg3)
      {
          Object result = null;
          if (jcsCache != null) 
          {
              try
              {
                  MethodCacheKey key = 
                      (MethodCacheKey)pool.getInstance(keyClass);
                  key.init(instanceOrClass, method, arg1, arg2, arg3);
                  result = removeImpl(key);
                  pool.putInstance(key);
              }
              catch (Exception e)
              {
                  log.error(e);
              }
          }
          return result;
      }
  
      public Object remove(Serializable[] keys)
      {
          Object result = null;
          if (jcsCache != null) 
          {
              try
              {
                  MethodCacheKey key = 
                      (MethodCacheKey)pool.getInstance(keyClass);
                  key.init(keys);
                  result = removeImpl(key);
                  pool.putInstance(key);
              }
              catch (Exception e)
              {
                  log.error(e);
              }
          }
          return result;
      }
  }
  
  
  
  1.5       +55 -38    jakarta-turbine-torque/src/templates/om/BaseManager.vm
  
  Index: BaseManager.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/templates/om/BaseManager.vm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BaseManager.vm	13 Mar 2002 17:30:57 -0000	1.4
  +++ BaseManager.vm	13 Mar 2002 21:31:23 -0000	1.5
  @@ -1,7 +1,11 @@
   #*
    * author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * version $Id: BaseManager.vm,v 1.4 2002/03/13 17:30:57 jon Exp $
  + * version $Id: BaseManager.vm,v 1.5 2002/03/13 21:31:23 jmcnally Exp $
    *#
  +#set ($interfaceName = $table.JavaName)
  +#if ($table.Interface)
  +   #set ($interfaceName = $table.Interface)
  +#end
   
   #set ($db = $table.Database)
   #if ($db.Package)
  @@ -15,13 +19,15 @@
   
   import org.apache.torque.om.ObjectKey;
   import org.apache.torque.om.Persistent;
  -import org.apache.torque.om.AbstractBaseManager;
  +import org.apache.torque.manager.AbstractBaseManager;
  +import org.apache.torque.manager.MethodResultCache;
  +import org.apache.torque.manager.CacheListener;
   import org.apache.torque.util.Criteria;
   import org.apache.torque.Torque;
   import org.apache.torque.TorqueException;
   
   /** 
  - * This class manages $table.JavaName objects.  
  + * This class manages $interfaceName objects.  
    * This class was autogenerated by Torque #if ($addTimeStamp)on:
    *
    * [$now]
  @@ -29,33 +35,33 @@
    #end
    *
    * You should not use this class directly.  It should not even be
  - * extended all references should be to ${table.JavaName}Manager 
  + * extended all references should be to ${interfaceName}Manager 
    */
  -public abstract class $basePrefix${table.JavaName}Manager
  +public abstract class $basePrefix${interfaceName}Manager
       extends AbstractBaseManager
   {
       /** The name of the manager */
  -    protected static String MANAGER_NAME = "${table.JavaName}Manager";
  +    protected static String MANAGER_NAME = "${interfaceName}Manager";
   
       /**
        * Retrieves an implementation of the manager, based on the settings in
        * the configuration.
        *
  -     * @return an implementation of ${table.JavaName}Manager.
  +     * @return an implementation of ${interfaceName}Manager.
        */
  -    public static ${table.JavaName}Manager getManager()
  +    public static ${interfaceName}Manager getManager()
       {
  -        return (${table.JavaName}Manager)
  -            Torque.getManager(${table.JavaName}Manager.MANAGER_NAME);    
  +        return (${interfaceName}Manager)
  +            Torque.getManager(${interfaceName}Manager.MANAGER_NAME);    
       }
   
       /**
        * Static accessor for the @see #getInstanceImpl().
        *
  -     * @return a <code>${table.JavaName}</code> value
  +     * @return a <code>${interfaceName}</code> value
        * @exception TorqueException if an error occurs
        */
  -    public static ${table.JavaName} getInstance()
  +    public static ${interfaceName} getInstance()
           throws TorqueException
       {
           return getManager().getInstance();
  @@ -65,10 +71,10 @@
        * Static accessor for the @see #getInstanceImpl(ObjectKey).
        *
        * @param id an <code>ObjectKey</code> value
  -     * @return a <code>${table.JavaName}</code> value
  +     * @return a <code>${interfaceName}</code> value
        * @exception TorqueException if an error occurs
        */
  -    public static ${table.JavaName} getInstance(ObjectKey id)
  +    public static ${interfaceName} getInstance(ObjectKey id)
           throws TorqueException
       {
           return getManager().getInstanceImpl(id);
  @@ -78,10 +84,10 @@
        * Static accessor for the @see #getInstanceImpl(ObjectKey, boolean).
        *
        * @param id an <code>ObjectKey</code> value
  -     * @return a <code>${table.JavaName}</code> value
  +     * @return a <code>${interfaceName}</code> value
        * @exception TorqueException if an error occurs
        */
  -    public static ${table.JavaName} getInstance(ObjectKey id, boolean fromCache)
  +    public static ${interfaceName} getInstance(ObjectKey id, boolean fromCache)
           throws TorqueException
       {
           return getManager().getInstanceImpl(id, fromCache);
  @@ -125,35 +131,45 @@
           getManager().clearImpl();
       }
   
  -    public static boolean exists(${table.JavaName} obj)
  +    public static boolean exists(${interfaceName} obj)
           throws TorqueException
       {
           return getManager().existsImpl(obj);
       }
   
  +    public static MethodResultCache getMethodResult()
  +    {
  +        return getManager().getMethodResultCache();
  +    }
  +
  +    public static void addCacheListener(CacheListener listener)
  +    {
  +        getManager().addCacheListenerImpl(listener);
  +    }
  +
       /**
  -     * Creates a new <code>$basePrefix${table.JavaName}Manager</code> instance.
  +     * Creates a new <code>$basePrefix${interfaceName}Manager</code> instance.
        *
        * @exception TorqueException if an error occurs
        */
  -    public $basePrefix${table.JavaName}Manager()
  +    public $basePrefix${interfaceName}Manager()
           throws TorqueException
       {
  -        setRegion("org_tigris_scarab_om_${table.JavaName}");
  -        setClassName("org.tigris.scarab.om.${table.JavaName}");
  +        setRegion("org_tigris_scarab_om_${interfaceName}");
  +        setClassName("org.tigris.scarab.om.${interfaceName}");
       }
   
   
       /**
  -     * Get a fresh instance of a ${table.JavaName}Manager
  +     * Get a fresh instance of a ${interfaceName}Manager
        */
  -    protected ${table.JavaName} getInstanceImpl()
  +    protected ${interfaceName} getInstanceImpl()
           throws TorqueException
       {
  -        ${table.JavaName} obj = null;
  +        ${interfaceName} obj = null;
           try
           {
  -            obj = (${table.JavaName}) getOMInstance();
  +            obj = (${interfaceName}) getOMInstance();
           }
           catch (Exception e)
           {
  @@ -168,30 +184,30 @@
        *
        * @param id <code>ObjectKey</code> value
        */
  -    protected ${table.JavaName} getInstanceImpl(ObjectKey id)
  +    protected ${interfaceName} getInstanceImpl(ObjectKey id)
           throws TorqueException
       {
  -        return (${table.JavaName}) getOMInstance(id);
  +        return (${interfaceName}) getOMInstance(id);
       }
   
       /**
  -     * Get a ${table.JavaName} with the given id.
  +     * Get a ${interfaceName} with the given id.
        *
        * @param id <code>ObjectKey</code> value
  -     * @param fromCache if true, look for cached ${table.JavaName}s before loading
  +     * @param fromCache if true, look for cached ${interfaceName}s before loading
        * from storage.
        */
  -    protected ${table.JavaName} getInstanceImpl(ObjectKey id, boolean fromCache)
  +    protected ${interfaceName} getInstanceImpl(ObjectKey id, boolean fromCache)
           throws TorqueException
       {
  -        return (${table.JavaName}) getOMInstance(id, fromCache);
  +        return (${interfaceName}) getOMInstance(id, fromCache);
       }
   
       /**
  -     * Gets a list of ${table.JavaName}s based on id's.
  +     * Gets a list of ${interfaceName}s based on id's.
        *
        * @param ids a List of <code>ObjectKeys</code> value
  -     * @return a <code>List</code> of ${table.JavaName}s
  +     * @return a <code>List</code> of ${interfaceName}s
        * @exception TorqueException if an error occurs
        */
       protected List getInstancesImpl(List ids) 
  @@ -201,12 +217,12 @@
       }
   
       /**
  -     * Gets a list of ${table.JavaName}s based on id's.
  +     * Gets a list of ${interfaceName}s based on id's.
        *
        * @param userIds a List of <code>ObjectKeys</code> value
  -     * @param fromCache if true, look for cached ${table.JavaName}s before loading
  +     * @param fromCache if true, look for cached ${interfaceName}s before loading
        * from storage.
  -     * @return a <code>List</code> of ${table.JavaName}s
  +     * @return a <code>List</code> of ${interfaceName}s
        * @exception TorqueException if an error occurs
        */
       protected List getInstancesImpl(List ids, boolean fromCache) 
  @@ -218,10 +234,11 @@
       /**
        * check for a duplicate project name
        */
  -    protected boolean existsImpl(${table.JavaName} om)
  +    protected boolean existsImpl(${interfaceName} om)
           throws TorqueException
       {
  -        Criteria crit = ${table.JavaName}Peer.buildCriteria(om);
  +        Criteria crit = ${table.JavaName}Peer
  +            .buildCriteria((${table.JavaName})om);
           return ${table.JavaName}Peer.doSelect(crit).size() > 0;
       }
   
  
  
  
  1.7       +17 -2     jakarta-turbine-torque/src/templates/om/Control.vm
  
  Index: Control.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/templates/om/Control.vm,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Control.vm	8 Mar 2002 23:16:51 -0000	1.6
  +++ Control.vm	13 Mar 2002 21:31:23 -0000	1.7
  @@ -46,11 +46,16 @@
   
   #if ($useManagers && $tbl.PrimaryKeys.size() > 0)
   
  -    #set ( $fname = "${basePrefix}${firstcap}Manager.java" )
  +    #set ($interfaceName = $table.JavaName)
  +    #if ($table.Interface)
  +        #set ($interfaceName = $table.Interface)
  +    #end
  +
  +    #set ( $fname = "${basePrefix}${interfaceName}Manager.java" )
       #set ( $path = "${strings.getPackageAsPath($pkbase)}$fname" )
       $generator.parse("om/BaseManager.vm",$path,"table",$tbl)
   
  -    #set ( $fname = "${firstcap}Manager.java" )
  +    #set ( $fname = "${interfaceName}Manager.java" )
       #set ( $path = "${strings.getPackageAsPath($package)}$fname" )    
       #if (!$files.file($basePath,$path).exists())
         $generator.parse("om/ExtensionManager.vm",$path,"table",$tbl)
  @@ -81,6 +86,16 @@
       #set ( $path = "${strings.getPackageAsPath($pkpeer)}$fname" )
       #if (!$files.file($basePath,$path).exists())
         $generator.parse("om/ExtensionPeer.vm",$path,"table",$tbl)
  +    #end
  +
  +    #if ($tbl.Interface)
  +
  +        #set ( $fname = "${tbl.Interface}.java" )
  +        #set ( $path = "${strings.getPackageAsPath($pkbase)}$fname" )
  +        #if (!$files.file($basePath,$path).exists())
  +            $generator.parse("om/Interface.vm",$path,"table",$tbl)
  +        #end
  +
       #end
   
       #if ($tbl.ChildrenColumn)
  
  
  
  1.2       +10 -6     jakarta-turbine-torque/src/templates/om/ExtensionManager.vm
  
  Index: ExtensionManager.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/templates/om/ExtensionManager.vm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExtensionManager.vm	2 Mar 2002 02:23:55 -0000	1.1
  +++ ExtensionManager.vm	13 Mar 2002 21:31:23 -0000	1.2
  @@ -1,7 +1,11 @@
   #*
    * author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * version $Id: ExtensionManager.vm,v 1.1 2002/03/02 02:23:55 jmcnally Exp $
  + * version $Id: ExtensionManager.vm,v 1.2 2002/03/13 21:31:23 jmcnally Exp $
    *#
  +#set ($interfaceName = $table.JavaName)
  +#if ($table.Interface)
  +   #set ($interfaceName = $table.Interface)
  +#end
   
   #set ($db = $table.Database)
   #if ($db.Package)
  @@ -20,7 +24,7 @@
   import org.apache.torque.om.Persistent;
   
   /** 
  - * This class manages $table.JavaName objects.  
  + * This class manages $interfaceName objects.  
    * The skeleton for this class was autogenerated by Torque #if ($addTimeStamp)on:
    *
    * [$now]
  @@ -30,15 +34,15 @@
    * application requirements.  This class will only be generated as
    * long as it does not already exist in the output directory.
    */
  -public class ${table.JavaName}Manager
  -    extends $basePrefix${table.JavaName}Manager
  +public class ${interfaceName}Manager
  +    extends $basePrefix${interfaceName}Manager
   {
       /**
  -     * Creates a new <code>${table.JavaName}Manager</code> instance.
  +     * Creates a new <code>${interfaceName}Manager</code> instance.
        *
        * @exception TorqueException if an error occurs
        */
  -    public ${table.JavaName}Manager()
  +    public ${interfaceName}Manager()
           throws TorqueException
       {
           super();
  
  
  
  1.4       +6 -1      jakarta-turbine-torque/src/templates/om/ExtensionObject.vm
  
  Index: ExtensionObject.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/templates/om/ExtensionObject.vm,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ExtensionObject.vm	28 Oct 2001 19:46:02 -0000	1.3
  +++ ExtensionObject.vm	13 Mar 2002 21:31:23 -0000	1.4
  @@ -1,3 +1,8 @@
  +#set ($interface = "")
  +#if ($table.Interface)
  +    #set ($interface = ", $table.Interface")
  +#end
  +
   #set ($db = $table.Database)
   #if ($db.Package)
       #set ($package = $db.Package)
  @@ -25,6 +30,6 @@
    */
   public $!abstract class $table.JavaName 
       extends ${package}.$basePrefix$table.JavaName
  -    implements Persistent
  +    implements Persistent$interface
   {
   }
  
  
  
  1.3       +30 -13    jakarta-turbine-torque/src/templates/om/ObjectWithManager.vm
  
  Index: ObjectWithManager.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/templates/om/ObjectWithManager.vm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObjectWithManager.vm	11 Mar 2002 05:21:04 -0000	1.2
  +++ ObjectWithManager.vm	13 Mar 2002 21:31:23 -0000	1.3
  @@ -155,11 +155,15 @@
           #if ($complexObjectModel)
             #if ($col.isForeignKey())
               #set ( $tblFK = $table.Database.getTable($col.RelatedTableName) )
  +            #set ($interfaceName = $tblFK.JavaName)
  +            #if ($tblFK.Interface)
  +                #set ($interfaceName = $tblFK.Interface)
  +            #end    
               #set ( $colFK = $tblFK.getColumn($col.RelatedColumnName) )
               #if ($col.isMultipleFK() || $col.RelatedTableName.equals($table.Name))
  -              #set ( $varName = "a${tblFK.JavaName}RelatedBy$col.JavaName" )
  +              #set ( $varName = "a${interfaceName}RelatedBy$col.JavaName" )
               #else
  -              #set ( $varName = "a$tblFK.JavaName" )
  +              #set ( $varName = "a$interfaceName" )
               #end
   
           if ($varName != null &&  !Objects.equals(${varName}.get${colFK.JavaName}(), v) )
  @@ -217,6 +221,10 @@
   
      #set ( $tblFK = $table.Database.getTable($fk.ForeignTableName) )
      #set ( $className = $tblFK.JavaName )
  +   #set ($interfaceName = $tblFK.JavaName)
  +   #if ($tblFK.Interface)
  +       #set ($interfaceName = $tblFK.Interface)
  +   #end    
   
      #set ( $relCol = "" )
      #foreach ($columnName in $fk.LocalColumns)
  @@ -229,16 +237,16 @@
      #if ($relCol != "")
          #set ( $relCol = "RelatedBy$relCol" )
      #end
  -   #set ( $pVarName = "$className$relCol" )
  +   #set ( $pVarName = "$interfaceName$relCol" )
      #set ( $varName = "a$pVarName" )
  -    private $className $varName;
  +    private $interfaceName $varName;
   
       /**
  -     * Declares an association between this object and a $className object
  +     * Declares an association between this object and a $interfaceName object
        *
  -     * @param $className v
  +     * @param $interfaceName v
        */
  -    public void set${pVarName}($className v) throws TorqueException
  +    public void set${pVarName}($interfaceName v) throws TorqueException
       {
      #foreach ($columnName in $fk.LocalColumns)
       #set ( $column = $table.getColumn($columnName) )
  @@ -268,8 +276,8 @@
       #set ( $comma = ", " )
       #set ( $argsize = $argsize + 1 )
      #end
  -    
  -    public $className get${pVarName}() throws TorqueException
  +
  +    public $interfaceName get${pVarName}() throws TorqueException
       {
           if ( $conditional )
           {
  @@ -280,9 +288,9 @@
     #else
      #if ($argsize > 1)
          SimpleKey[] keys = { $arglist };
  -        return ${className}Manager.getInstance(new ComboKey(keys));
  +        return ${interfaceName}Manager.getInstance(new ComboKey(keys));
      #else
  -        return ${className}Manager.getInstance($arglist);
  +        return ${interfaceName}Manager.getInstance($arglist);
      #end
     #end
           }
  @@ -365,6 +373,11 @@
           }
       }
   
  +   #set ($interfaceName = $table.JavaName)
  +   #if ($table.Interface)
  +       #set ($interfaceName = $table.Interface)
  +   #end    
  +
       /**
        * Method called to associate a $tblFK.JavaName object to this object
        * through the $className foreign key attribute
  @@ -374,7 +387,7 @@
       public void add${relColMs}($className l) throws TorqueException
       {
           get${relCol}().add(l);
  -        l.set${table.JavaName}${suffix}(($table.JavaName)this);
  +        l.set${interfaceName}${suffix}(($table.JavaName)this);
       }
   
       /**
  @@ -896,9 +909,13 @@
               }
   
   #if ($table.PrimaryKeys.size() > 0)
  +    #set ($interfaceName = $table.JavaName)
  +    #if ($table.Interface)
  +        #set ($interfaceName = $table.Interface)
  +    #end
               if (isCacheOnSave())
               {
  -                ${table.JavaName}Manager.putInstance(this);
  +                ${interfaceName}Manager.putInstance(this);
               }
   #end
           }
  
  
  
  1.17      +14 -4     jakarta-turbine-torque/src/templates/om/Peer.vm
  
  Index: Peer.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/templates/om/Peer.vm,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Peer.vm	8 Mar 2002 23:07:47 -0000	1.16
  +++ Peer.vm	13 Mar 2002 21:31:23 -0000	1.17
  @@ -1040,13 +1040,19 @@
   
        #set ( $joinTable = $table.Database.getTable($fk.ForeignTableName) )
        #set ( $joinClassName = $joinTable.JavaName )
  +     #set ($interfaceName = $joinTable.JavaName)
  +     #if ($joinTable.Interface)
  +       #set ($interfaceName = $joinTable.Interface)
  +     #end    
   
        #if ($partJoinName == "")
           #set ( $joinColumnId = $joinClassName )
  +        #set ( $joinInterface = $interfaceName )
           #set ( $collThisTable = "${className}s" )
           #set ( $collThisTableMs = $className )
        #else
           #set ( $joinColumnId= "${joinClassName}RelatedBy$partJoinName" )
  +        #set ( $joinInterface= "${interfaceName}RelatedBy$partJoinName" )
           #set ( $collThisTable="${className}sRelatedBy$partJoinName" )
           #set ( $collThisTableMs="${className}RelatedBy$partJoinName" )
        #end
  @@ -1163,7 +1169,7 @@
               for (int j=0; j<results.size(); j++)
               {
                   $className temp_obj1 = ($className)results.elementAt(j);
  -                $joinClassName temp_obj2 = temp_obj1.get${joinColumnId}();
  +                $joinClassName temp_obj2 = ($joinClassName)temp_obj1.get${joinInterface}();
                   if ( temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey() ) )
                   {
                       newObject = false;
  @@ -1319,6 +1325,10 @@
         #if ( !($fk.ForeignTableName.equals($table.Name)) )
           #set ( $joinTable = $table.Database.getTable($fk.ForeignTableName) )
           #set ( $joinClassName = $joinTable.JavaName )
  +        #set ($interfaceName = $joinTable.JavaName)
  +        #if ($joinTable.Interface)
  +            #set ($interfaceName = $joinTable.Interface)
  +        #end    
   
           #if (!$joinClassName.equals($excludeClassName))
               #set ( $partJoinName = "" )
  @@ -1330,11 +1340,11 @@
               #end
   
               #if ($partJoinName == "")
  -                #set ( $joinString = $joinClassName )
  +                #set ( $joinString = $interfaceName )
                   #set ( $collThisTable = "${className}s" )
                   #set ( $collThisTableMs = $className )
               #else
  -                #set ( $joinString="${joinClassName}RelatedBy$partJoinName" )
  +                #set ( $joinString="${interfaceName}RelatedBy$partJoinName" )
                   #set ( $collThisTable="${className}sRelatedBy$partJoinName" )
                   #set ( $collThisTableMs="${className}RelatedBy$partJoinName" )
               #end
  @@ -1354,7 +1364,7 @@
               for (int j=0; j<results.size(); j++)
               {
                   $className temp_obj1 = ($className)results.elementAt(j);
  -                $joinClassName temp_obj$index = temp_obj1.get${joinString}();
  +                $joinClassName temp_obj$index = ($joinClassName)temp_obj1.get${joinString}();
                   if ( temp_obj${index}.getPrimaryKey().equals(obj${index}.getPrimaryKey() ) )
                   {
                       newObject = false;
  
  
  
  1.1                  jakarta-turbine-torque/src/templates/om/Interface.vm
  
  Index: Interface.vm
  ===================================================================
  #*
   * author <a href="mailto:jmcnally@collab.net">John McNally</a>
   * version $Id: Interface.vm,v 1.1 2002/03/13 21:31:23 jmcnally Exp $
   *#
  
  #set ($db = $table.Database)
  #if ($db.Package)
      #set ($package = $db.Package)
  #else
      #set ($package = $targetPackage)
  #end
  package $package;
  
  /** 
   * This is an interface that should be filled with the public api of the 
   * $table.JavaName objects.  
   * The skeleton for this class was autogenerated by Torque #if ($addTimeStamp)on:
   *
   * [$now]
   * #end
   * You should add additional methods to this class to meet the
   * application requirements.  This class will only be generated as
   * long as it does not already exist in the output directory.
   */
  public interface ${table.Interface}
  {
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>