head	1.15;
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.15
date	2001.06.18.22.12.20;	author leonardr;	state dead;
branches;
next	1.14;

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

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

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

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

1.10
date	2001.04.18.22.39.19;	author dlr;	state Exp;
branches;
next	1.9;

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

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

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

1.6
date	2001.03.26.17.27.07;	author dlr;	state Exp;
branches;
next	1.5;

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

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

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

1.2
date	2001.03.13.16.47.24;	author leonardr;	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
@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
@/* ================================================================
 * 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.turbine.om.SimpleKey;
import org.apache.turbine.om.NumberKey;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.BufferCache;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.Domain;
import org.tigris.helm.tool.*;
import org.tigris.helm.tool.cache.SimpleRegisterableCache;

/**
 * Extension of generated Peer BaseDomainPeer.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 */
public class DomainPeer extends BaseDomainPeer
{
    /**
     * The name of the special host domain.
     */
    public static final String HOST_DOMAIN_NAME = "**HOST";

    /**
     * Cache of domains keyed by name.
     */
    private static SimpleRegisterableCache domainsByName;

    static
    {
        domainsByName = new SimpleRegisterableCache
            ("Domain cache", Domain.class, new BufferCache(3));
    }

    //
    // Ways of retrieving Domain objects.
    //

    /**
     * Returns the domain with the specified ID.
     */
    public static Domain getInstance(String domainID)
        throws Exception
    {
        return DomainPeer.retrieveByPK(new NumberKey(domainID));
    }

    /**
     * Returns the domain with the specified name.
     */
    public static Domain getInstanceByName(String name)
        throws DoesNotExist, Exception
    {
        Map cache = domainsByName.getCache();
        Domain domain = (Domain) cache.get(name);
        if (domain == null)
        {
            synchronized (cache)
            {
                Criteria c = new Criteria().add(DomainPeer.NAME, name);
                domain = (Domain)PeerTool.getFirstBO
                    (DomainPeer.doSelect(c), "Domain with name " + name);
                cache.put(name, domain);
            }
        } 
        return domain;
    }

    //
    // Special domains.
    //

    /**
     * Gets the special host domain
     */
    public static Domain getHostDomain()
        throws Exception
    {
        Domain d = null;
        try 
        {
            d = getInstanceByName(HOST_DOMAIN_NAME);
        }
        catch (DoesNotExist e) 
        {
            throw new Error("Could not locate special host domain!");
        }
        return d;
    }
}
@


1.14
log
@Temp. workaround until Daniel fixes BufferCache to support size-2 caches.
@
text
@@


1.13
log
@Ported Helm from WebMacro to Velocity.
@
text
@d85 1
a85 1
            ("Domain cache", Domain.class, new BufferCache(2));
d116 1
a116 1
                cache.put(domain.getName(), domain);
@


1.12
log
@Cleanup of caching and cache invalidation.
@
text
@d56 2
@


1.11
log
@Daniel claims the buffercache problem never existed, so this can go back to being of size 2.
@
text
@a49 1
import java.rmi.RemoteException;
d82 2
a83 9
        try
        {
            domainsByName = new SimpleRegisterableCache(DomainPeer.class,
                                                        new BufferCache(2));
        }
        catch (RemoteException e)
        {
            throw new RuntimeException(e.getMessage());
        }
@


1.10
log
@SequencedHashtable, BufferCache, and BaseUnicastRemoteService have been moved into Turbine.  Changed references accordingly.
@
text
@d86 1
a86 1
                                                        new BufferCache(3));
@


1.9
log
@Increased size of cache.
@
text
@d55 1
@


1.8
log
@Integrated JVM-registered cache implementation to support cross-JVM
cache invalidation.
@
text
@d85 1
a85 1
                                                        new BufferCache(2));
@


1.7
log
@A BufferCache with a size of 2 is the right number for now, since we
populate the database with only two HELM_DOMAIN records.  The bug for
a SequencedHashtable of size 2 has been fixed (IZ #3303).
@
text
@d50 1
d60 1
d78 14
a91 1
    private static Map domainsByName = new BufferCache(2);
d112 2
a113 1
        Domain domain = (Domain)domainsByName.get(name);
d116 1
a116 1
            synchronized (domainsByName)
d121 1
a121 1
                domainsByName.put(domain.getName(), domain);
@


1.6
log
@Helm caches should currently be referred to by Map handles, allowing
easy changing of the underlying object that they point to.
@
text
@d76 1
a76 1
    private static Map domainsByName = new BufferCache(3);
@


1.5
log
@Increased the size of the cache a bit... size 2 seems to cause problems.
@
text
@d76 1
a76 1
    private static BufferCache domainsByName = new BufferCache(3);
@


1.4
log
@Use BufferCache instead of a HashMap.
@
text
@d76 1
a76 1
    private static BufferCache domainsByName = new BufferCache(2);
d103 2
a104 3
                domain = (Domain)PeerTool.getFirstBO(DomainPeer.doSelect(c),
                                                     "Domain with name " + name);

@


1.3
log
@Cache domain objects.
@
text
@d58 1
a58 1
import org.tigris.helm.tool.PeerTool;
d76 1
a76 1
    private static Map domainsByName = new HashMap();
@


1.2
log
@brace cleanup
@
text
@d49 1
a49 1
import java.util.List;
d54 1
d73 5
d97 13
a109 3
        Criteria c = new Criteria().add(DomainPeer.NAME, name);
        return (Domain)PeerTool.getFirstBO(DomainPeer.doSelect(c),
                                           "Domain with name " + name);
@


1.1
log
@Moved in from peer package to handle Torque changes. -dlr
@
text
@d107 2
a108 1
        try {
d111 2
a112 1
        catch (DoesNotExist e) {
@

