head	1.7;
access;
symbols;
locks; strict;
comment	@# @;


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

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

1.5
date	2001.06.18.22.12.20;	author leonardr;	state Exp;
branches;
next	1.4;

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

1.3
date	2001.05.03.00.32.29;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2001.05.02.06.57.45;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.05.02.06.49.25;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.7
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 org.apache.torque.util.Criteria;
import org.apache.turbine.util.Log;

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

/**
 * Extension of generated Peer BaseAttributeValuePeer
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 */
public class AttributeValuePeer extends BaseAttributeValuePeer
{
    /**
     * Cache of attribute values keyed by entity type/entity id/name.
     */
    private static SimpleRegisterableCache valuesByAttribute
        = new SimpleRegisterableCache
        ("Attribute value cache", AttributeValuePeer.class, new Hashtable());

    /**
     * Gets an entity's attribute value.
     *
     * @@param entityType The type of entity to get an attribute's value for.
     * @@param entityID   The database key of the specific entry with which
     *                   the attribute value is associated.
     * @@param name       The name of the attribute.
     * @@return           The value.
     */
    public static AttributeValue getInstanceByName(String entityType,
                                                   String entityID,
                                                   String name)
        throws Exception
    {
        List key = new ArrayList(3);
        key.add(entityType);
        key.add(entityID);
        key.add(name);
        Map cache = valuesByAttribute.getCache();
        AttributeValue value = (AttributeValue)cache.get(key);
        if (value == null)
        {
            synchronized (cache)
            {
                value = (AttributeValue)cache.get(key);
                if (value == null)
                {
                    Criteria c = new Criteria(4)
                        .add(AttributePeer.ENTITY_TYPE, entityType)
                        .add(BOKeyFieldName.resolve(entityType), entityID)
                        .addJoin(AttributeValuePeer.ENTITY_ID, BOKeyFieldName.resolve(entityType))
                        .addJoin(AttributeValuePeer.ATTRIBUTE_ID,
                                 AttributePeer.ATTRIBUTE_ID)
                        .add(AttributePeer.NAME, name);
                    try
                    {
                        value = (AttributeValue) PeerTool.getFirstBO
                            (doSelect(c), entityType + " attribute named " 
                             + name + " for " + entityID);
                        cache.put(key, value);
                    }
                    catch (DoesNotExist ignore)
                    {
                    }
                }
            }
        }
        return value;
    }   
}
@


1.6
log
@A cache for attribute values, and code to use it when getting role attribute values.
@
text
@d51 1
a51 3
import org.apache.turbine.om.SimpleKey;
import org.apache.turbine.om.NumberKey;
import org.apache.turbine.util.db.Criteria;
@


1.5
log
@Huge patch of the day: Got rid of redundant HELM_DOMAIN table. The project representation of the domain and the host is now the canonical one. Host and Domain now subclass ProjectGroup. The canonical representation of a project's membership in a domain group is now the corresponding mapping in HELM_PROJECT_PROJECTGROUP. Schema changes: No more HELM_DOMAIN table (obviously); no more DOMAIN_ID in HELM_PROJECT; HELM_USER and HELM_VC_VIEW now have foreign keys in HELM_PROJECT instead of HELM_DOMAIN.
@
text
@d49 2
d56 1
d58 1
d69 7
d89 35
a123 9
        Criteria c = new Criteria(4)
            .add(AttributePeer.ENTITY_TYPE, entityType)
            .add(BOKeyFieldName.resolve(entityType), entityID)
            .addJoin(AttributeValuePeer.ATTRIBUTE_ID,
                     AttributePeer.ATTRIBUTE_ID)
            .add(AttributePeer.NAME, name);
        return (AttributeValue) PeerTool.getFirstBO
            (doSelect(c), entityType + " attribute named " + name);
    }
@


1.4
log
@Added entityID to getInstanceByName() decl.  It's necessary to return
one and only one row.
@
text
@d52 1
@


1.3
log
@Added getInstanceByName() class method.
@
text
@d67 2
d72 3
a74 1
    public static AttributeValue getInstanceByName(String entityType, String name)
d77 1
a77 1
        Criteria c = new Criteria(3)
d79 1
@


1.2
log
@Replaced Role-specific tables w/ more general purpose versions.  Did a little clean up in light of that.
@
text
@d51 3
d63 18
@


1.1
log
@Replaced Role-specific tables w/ more general purpose versions.
@
text
@a51 1
import org.tigris.helm.om.*;
d53 1
a53 1
 * Extension of generated Peer BaseRoleAttributeValuePeer
d56 1
d58 1
a58 1
public class RoleAttributeValuePeer extends BaseRoleAttributeValuePeer
a59 1

@

