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


1.14
date	2001.08.11.09.08.03;	author dlr;	state Exp;
branches;
next	1.13;

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

1.12
date	2001.05.30.19.57.25;	author leonardr;	state Exp;
branches;
next	1.11;

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

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

1.9
date	2001.04.20.21.19.40;	author leonardr;	state Exp;
branches;
next	1.8;

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

1.7
date	2001.03.16.15.58.50;	author leonardr;	state Exp;
branches;
next	1.6;

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

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

1.4
date	2001.03.13.03.33.42;	author dlr;	state Exp;
branches;
next	1.3;

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

1.2
date	2001.03.07.01.53.22;	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.14
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.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;
import org.apache.commons.util.exception.NestableException;
import org.apache.torque.util.Criteria;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.tool.PeerTool;
import org.tigris.helm.tool.cache.SimpleRegisterableCache;

/**
 * Extension of generated Peer BaseResourcePeer.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 */
public class ResourcePeer extends BaseResourcePeer
{

    /**
     * Cache of resources keyed by ID.
     */
    private static SimpleRegisterableCache resourcesByID;

    static
    {
        resourcesByID = new SimpleRegisterableCache
            ("Resource cache", Resource.class, new Hashtable());
    }

    /**
     * Overridden BasePeer method to do a delete and then to send out
     * an appropriate CacheInvalidationEvent.
     */
    public static void doDelete(Criteria c)
        throws Exception
    {
        BaseResourcePeer.doDelete(c);
        uncache(Resource.class);
    }

    /**
     * Factory method.
     */
    public static Resource getInstance(String resourceID)
        throws DoesNotExist, Exception
    {
        Map cache = resourcesByID.getCache();
        Resource r = (Resource)cache.get(resourceID);
        if (r == null)
        {
            synchronized (cache)
            {
                r = (Resource)cache.get(resourceID);
                Criteria c = new Criteria(1).add(RESOURCE_ID, resourceID);
                if (r == null)
                {
                    r = (Resource)PeerTool.getFirstBO
                        (doSelect(c), "Resource with ID " + resourceID);
                    cache.put(resourceID, r);
                }
            }
        }
        return r;
    }
}
@


1.13
log
@Use PeerTool to get DoesNotExist error message.
@
text
@d53 3
a55 4
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.om.NumberKey;
@


1.12
log
@You're interested in the object, not the peer.
@
text
@d58 2
d97 1
a97 1
        throws Exception
d100 1
a100 1
        Resource r = (Resource) cache.get(resourceID);
d105 2
a106 1
                r = (Resource) cache.get(resourceID);
d109 2
a110 1
                    r = ResourcePeer.retrieveByPK(new NumberKey(resourceID));
@


1.11
log
@Ported Helm from WebMacro to Velocity.
@
text
@d77 1
a77 1
            ("Resource cache", ResourcePeer.class, new Hashtable());
@


1.10
log
@Cleanup of caching and cache invalidation.
@
text
@d53 2
@


1.9
log
@Send CacheInvalidationEvents on deletes, and on saves of objects which are not themselves cached but which invalidate other caches when they are changed.
@
text
@d74 2
a75 11
        try
        {
            resourcesByID = new SimpleRegisterableCache(ResourcePeer.class, 
                                                        new Hashtable());
        } 
        catch (RemoteException e)
        {
            throw new RuntimeException("Unable to create resource cache: " +
                                       e.getMessage());
        }

d86 1
a86 1
        uncache(ResourcePeer.class);
@


1.8
log
@Added semi-selective cache invalidation which invalidates particular caches on a write instead of all the caches.
@
text
@d53 1
d85 11
@


1.7
log
@Disabled some more actions on project lock.
@
text
@d50 1
d52 1
a52 1
import org.apache.turbine.om.SimpleKey;
d54 2
a55 1
import org.apache.turbine.util.Log;
d69 1
a69 1
    private static Map resourcesByID = new HashMap();
d71 1
a71 4
    /**
     * Remove a resource's mapping.
     */
    public static void uncache(Resource toInvalidate)
d73 6
a78 1
        if (resourcesByID.containsKey(toInvalidate.getID()))
d80 2
a81 1
            resourcesByID.remove(toInvalidate);
d83 1
d92 2
a93 1
        Resource r = (Resource) resourcesByID.get(resourceID);
d96 1
a96 1
            synchronized (resourcesByID)
d98 1
a98 1
                r = (Resource) resourcesByID.get(resourceID);
d102 1
a102 1
                    resourcesByID.put(resourceID, r);
@


1.6
log
@More fixes for caching.
@
text
@d70 11
@


1.5
log
@No need to import class now in the same package.
@
text
@d53 1
@


1.4
log
@Corrected handling of critical section in getInstance().
@
text
@a53 1
import org.tigris.helm.om.Resource;
@


1.3
log
@Added caching of resources.
@
text
@d59 1
d75 2
a76 2
        Resource r = null;
        if (resourcesByID.containsKey(resourceID))
d78 9
a86 5
            r = (Resource)resourcesByID.get(resourceID);
        } 
        else 
        {
            r = ResourcePeer.retrieveByPK(new NumberKey(resourceID));
a89 1

@


1.2
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d49 2
d62 6
d74 10
a83 1
        return ResourcePeer.retrieveByPK(new NumberKey(resourceID));
@


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

@

