head	1.15;
access;
symbols
	TIGRIS_1_1_0RC2:1.6
	TIGRIS_1_1_0RC1:1.6
	TIGRIS_1_1:1.6.0.4
	TIGRIS_1_0_8:1.6
	TIGRIS_1_0_8RC3:1.6
	TIGRIS_1_0_8RC2:1.6
	TIGRIS_1_0_8RC1:1.6
	TIGRIS_1_0_7:1.6
	TIGRIS_1_0_7RC3:1.6
	TIGRIS_1_0_7RC2:1.6
	TIGRIS_1_0_7RC1:1.6
	TIGRIS_1_0_6:1.6
	TIGRIS_1_0_6RC5:1.6
	TIGRIS_1_0_6RC4:1.6
	TIGRIS_1_0_6RC3:1.6
	TIGRIS_1_0_6RC2:1.6
	TIGRIS_1_0_6RC1:1.6
	TIGRIS_1_0_5:1.6
	TIGRIS_1_0_5RC6:1.6
	TIGRIS_1_0_5RC5:1.6
	TIGRIS_1_0_5RC4:1.6
	TIGRIS_1_0_5RC3:1.6
	TIGRIS_1_0_5RC2:1.6
	TIGRIS_1_0_5RC1:1.6
	TIGRIS_1_0_4:1.6
	TIGRIS_1_0_3:1.6
	TIGRIS_1_0_2:1.6
	TIGRIS_1_0_1:1.6
	TIGRIS_1_0:1.6.0.6
	TIGRIS_1_0_0:1.6
	TIGRIS_1_0_0_RC1:1.6.0.2;
locks; strict;
comment	@# @;


1.15
date	2001.08.11.09.08.02;	author dlr;	state Exp;
branches;
next	1.14;

1.14
date	2001.06.08.21.52.09;	author leonardr;	state Exp;
branches;
next	1.13;

1.13
date	2001.05.30.20.15.25;	author leonardr;	state Exp;
branches;
next	1.12;

1.12
date	2001.05.23.01.50.13;	author dlr;	state Exp;
branches;
next	1.11;

1.11
date	2001.05.23.00.35.00;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2001.05.21.21.06.01;	author leonardr;	state Exp;
branches;
next	1.9;

1.9
date	2001.04.20.15.30.21;	author dlr;	state Exp;
branches;
next	1.8;

1.8
date	2001.04.12.04.41.05;	author leonardr;	state Exp;
branches;
next	1.7;

1.7
date	2001.04.12.02.27.10;	author dlr;	state Exp;
branches;
next	1.6;

1.6
date	2001.03.16.01.13.00;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2001.03.13.03.04.41;	author dlr;	state Exp;
branches;
next	1.4;

1.4
date	2001.03.13.02.21.16;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2001.03.13.01.14.37;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2001.03.07.01.53.21;	author lucas;	state Exp;
branches;
next	1.1;

1.1
date	2001.03.07.01.13.15;	author lucas;	state Exp;
branches;
next	;


desc
@@


1.15
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@/* ================================================================
 * Copyright (c) 2000-2001 CollabNet.  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 CollabNet (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" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * 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 COLLABNET 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 CollabNet.
 */

package org.tigris.helm.om;

import java.util.*;
import java.rmi.RemoteException;

import org.apache.torque.om.NumberKey;
import org.apache.torque.util.Criteria;

import org.apache.commons.util.exception.NestableException;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.Action;
import org.tigris.helm.tool.PeerTool;
import org.tigris.helm.tool.cache.RegisterableCache;
import org.apache.turbine.util.Log;

/**
 * Extension of generated Peer BaseActionPeer.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: ActionPeer.java,v 1.14 2001/06/08 21:52:09 leonardr Exp $
 */
public class ActionPeer extends BaseActionPeer
{
    /**
     * Flag indicating whether in debug mode.
     */
    private static final boolean DEBUG = true;

    /**
     * Object cache for this peer.
     */
    private static ActionCache cache;

    public static Action getInstance(String id)
        throws Exception
    {
        Action action = (Action) cache.actionsByID.get(id);
        if (action == null)
        {
            synchronized (cache.actionsByID)
            {
                action = (Action) cache.actionsByID.get(id);
                if (action == null)
                {
                    action = retrieveByPK(new NumberKey(id));
                    cache.actionsByID.put(action.getID(), action);
                    cache.actionsByName.put(action.getName(), action);
                }
            }
        }
        return action;
    }

    public static Action getInstanceByName(String name)
        throws DoesNotExist, Exception
    {
        Action action = (Action) cache.actionsByName.get(name);
        if (action == null)
        {
            synchronized (cache.actionsByName)
            {
                action = (Action) cache.actionsByName.get(name);
                if (action == null)
                {
                    Criteria c = new Criteria().add(NAME, name);
                    action = (Action)PeerTool.getFirstBO
                        (doSelect(c), "Action named " + name);
                    cache.actionsByID.put(action.getID(), action);
                    cache.actionsByName.put(action.getName(), action);
                }
            }
        }
        return action;
    }

    public static List getHostActions()
        throws Exception
    {
        return getActionsForType(Action.HOST_TYPE);
    }

    public static List getDomainActions()
        throws Exception
    {
        return getActionsForType(Action.DOMAIN_TYPE);
    }

    public static List getProjectActions()
        throws Exception
    {
        return getActionsForType(Action.PROJECT_TYPE);
    }

    private static List getActionsForType(String type)
        throws Exception
    {
        Criteria c = new Criteria().add(TYPE, type);
        return doSelect(c);
    }

    static
    {
        try
        {
            cache = new ActionCache();
        }
        catch (RemoteException e)
        {
            throw new RuntimeException("Unable to create action cache: " +
                                       e.getMessage());
        }
    }

    static class ActionCache extends RegisterableCache
    {
        /**
         * Registered name of this cache.
         */
        private static final String NAME = "Action cache";

        /**
         * Cache of actions keyed by ID.
         */
        Map actionsByID;

        /**
         * Cache of actions keyed by name.
         */
        Map actionsByName;

        public ActionCache()
            throws RemoteException
        {
            super(NAME, Action.class);
            actionsByID = new HashMap();
            actionsByName = new HashMap();
        }

        /**
         * Invalidates some portion of the cache.
         *
         */
        public final void invalidate()
            throws Exception
        {            
            super.invalidate();
            actionsByID.clear();
            actionsByName.clear();
        }

        /**
         * Describe the contents of the cache.
         */
        public String describeContents()
        {
            StringBuffer buf = new StringBuffer()
                .append("\n ")
                .append(actionsByID.keySet().size())
                .append(" actions cached by ID, ")
                .append(actionsByName.keySet().size())
                .append(" cached by name.");
            return buf.toString();
        }
    }
}
@


1.14
log
@Added ability for caches to keep track of number of invalidations.
@
text
@d52 4
a55 5
import org.apache.turbine.om.*;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
d61 1
d68 1
a68 1
 * @@version $Id: ActionPeer.java,v 1.13 2001/05/30 20:15:25 leonardr Exp $
@


1.13
log
@Big cleanup of cache self-descriptions. Also added an admin tool to do manual selective cache invalidation.
@
text
@d68 1
a68 1
 * @@version $Id: ActionPeer.java,v 1.12 2001/05/23 01:50:13 dlr Exp $
d165 5
d182 1
a182 1
            super("Action cache", Action.class);
d192 1
d194 1
@


1.12
log
@Ported Helm from WebMacro to Velocity.
@
text
@d68 1
a68 1
 * @@version $Id: ActionPeer.java,v 1.11 2001/05/23 00:35:00 leonardr Exp $
d198 1
@


1.11
log
@Cleanup of caching and cache invalidation.
@
text
@d55 2
d68 1
a68 1
 * @@version $Id: ActionPeer.java,v 1.10 2001/05/21 21:06:01 leonardr Exp $
@


1.10
log
@Moved clustering features out of RMI and into the database.
@
text
@d66 1
a66 1
 * @@version $Id: ActionPeer.java,v 1.9 2001/04/20 15:30:21 dlr Exp $
d175 1
a175 1
            super(Action.class);
d185 3
a187 3
        {
            invalidate(actionsByID);
            invalidate(actionsByName);
d190 4
a193 1
        private void invalidate(Map map)
d195 6
a200 9
            if (DEBUG)
            {
                Log.debug("Action peer invalidating " + map.keySet().size() 
                          + " entries.");
            }
            else
            {
                map.clear();
            }
a201 1

@


1.9
log
@Added semi-selective cache invalidation which invalidates particular caches on a write instead of all the caches.
@
text
@d66 1
a66 1
 * @@version $Id: ActionPeer.java,v 1.8 2001/04/12 04:41:05 leonardr Exp $
d175 1
a175 1
            super(ActionPeer.class);
a182 3
         * @@param invalidationDescriptor Description of the invalidation that 
         *                               should occur, or <code>null</code> for
         *                               complete invalidation.
d184 1
a184 1
        public final void invalidate(Object invalidationDescriptor)
d186 2
a187 2
            invalidate(invalidationDescriptor, actionsByID);
            invalidate(invalidationDescriptor, actionsByName);
d190 1
a190 5
        /**
         * This cache is invalidated whenever an Action is changed
         */
        protected final boolean affectedByInvalidation
            (Object invalidationDescriptor)
d192 1
a192 2
            boolean affects = false;
            if (invalidationDescriptor == null)
d194 2
a195 1
                affects = true;
d197 1
a197 1
            else if (invalidationDescriptor instanceof String)
d199 1
a199 5
                String objectClassName = (String)invalidationDescriptor;
                if (objectClassName.equals("Action"))
                {
                    affects = true;
                }
a200 1
            return affects;
a202 24
        private void invalidate(Object descriptor, Map map)
        {
            if (affectedByInvalidation(descriptor))
            {
                if (DEBUG)
                {
                    StringBuffer buf =
                        new StringBuffer("ActionPeer invalidating cache: ");
                    Object[] keys = map.keySet().toArray();
                    for (int i = 0; i < keys.length; i++)
                    {
                        String key = (String) keys[i];
                        if (i > 0) buf.append(", ");
                        buf.append(key);
                        map.remove(key);
                    }
                    Log.debug(buf.toString());
                }
                else
                {
                    map.clear();
                }
            }
        }
@


1.8
log
@Added debugging code and moved RARPeer and ProjectPeer to the new caching system.
@
text
@d66 1
a66 1
 * @@version $Id: ActionPeer.java,v 1.7 2001/04/12 02:27:10 dlr Exp $
d193 22
d217 1
a217 1
            if (descriptor == null)
a236 6
            }
            else
            {
                throw new UnsupportedOperationException
                    ("ActionCache.invalidate() does not " + 
                     "currently support a descriptor");
@


1.7
log
@Integrated JVM-registered cache implementation to support cross-JVM
cache invalidation.
@
text
@d66 1
a66 1
 * @@version $Id: ActionPeer.java,v 1.6 2001/03/16 01:13:00 leonardr Exp $
d219 1
a219 1
                    ("UserCache.invalidate() does not " + 
@


1.6
log
@Cache actions by ID as well as by name. Action objects are put in both tables simultaneously so there is only one set of Action objects in circulation.
@
text
@d50 1
d59 1
d66 1
a66 1
 * @@version $Id: ActionPeer.java,v 1.5 2001/03/13 03:04:41 dlr Exp $
d71 1
a71 1
     * Cache of actions keyed by name.
d73 1
a73 1
    private static Map actionsByName = new HashMap();
d76 1
a76 1
     * Cache of actions keyed by ID.
d78 1
a78 1
    private static Map actionsByID = new HashMap();
d83 1
a83 1
        Action action = (Action) actionsByID.get(id);
d86 1
a86 1
            synchronized (actionsByID)
d88 1
a88 1
                action = (Action) actionsByID.get(id);
d92 2
a93 2
                    actionsByID.put(action.getID(), action);
                    actionsByName.put(action.getName(), action);
d103 1
a103 1
        Action action = (Action) actionsByName.get(name);
d106 1
a106 1
            synchronized (actionsByName)
d108 1
a108 1
                action = (Action) actionsByName.get(name);
d114 2
a115 2
                    actionsByID.put(action.getID(), action);
                    actionsByName.put(action.getName(), action);
d147 77
@


1.5
log
@Corrected handling of critical section.
@
text
@d64 1
a64 1
 * @@version $Id: ActionPeer.java,v 1.4 2001/03/13 02:21:16 leonardr Exp $
d73 5
d81 15
a95 1
        return retrieveByPK(new NumberKey(id));
d112 1
@


1.4
log
@Added more caching.
@
text
@d64 1
a64 1
 * @@version $Id: ActionPeer.java,v 1.3 2001/03/13 01:14:37 leonardr Exp $
a67 1

d82 2
a83 6
        Action action = null;
        if (actionsByName.containsKey(name))
        {
            action = (Action)actionsByName.get(name);
        }
        else
d85 11
a95 4
            Criteria c = new Criteria().add(NAME, name);
            action = (Action)PeerTool.getFirstBO
                (doSelect(c), "Action named " + name);
            actionsByName.put(action.getName(), action);
@


1.3
log
@Cache actions by name. This speeds up permission checking greatly.
@
text
@d56 1
d58 1
a58 1
import org.tigris.helm.om.Action;
d64 1
a64 1
 * @@version $Id: ActionPeer.java,v 1.2 2001/03/07 01:53:21 lucas Exp $
d72 1
a72 1
    private static Hashtable actionsByName = new Hashtable();
@


1.2
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d49 1
a49 1
import java.util.List;
d53 1
d63 1
a63 1
 * @@version $Id: ActionPeer.java,v 1.1 2001/03/07 01:13:15 lucas Exp $
d67 6
d82 13
a94 2
        Criteria c = new Criteria().add(NAME, name);
        return (Action)PeerTool.getFirstBO(doSelect(c), "Action named " + name);
@


1.1
log
@Moved in from peer package to handle Torque changes. -dlr
@
text
@a56 1

d62 1
a62 1
 * @@version $Id: ActionPeer.java,v 1.4 2001/02/26 20:21:18 dlr Exp $
@

