head	1.17;
access;
symbols
	TIGRIS_0_9_2_4:1.9
	TIGRIS_0_9_2_3:1.9
	HELM_PEER_PORT_BRANCH:1.16.0.2
	TURBINE_PEER:1.16
	TIGRIS_0_9_2_1:1.16
	TIGRIS_0_9_2:1.9.0.2
	TIGRIS_0_9_0:1.4.0.2
	TIGRIS_0_8_4:1.1.1.1.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.17
date	2001.02.21.03.23.56;	author edk;	state dead;
branches;
next	1.16;

1.16
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.16.2.1;
next	1.15;

1.15
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.14;

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

1.13
date	2001.01.25.01.32.10;	author lucas;	state Exp;
branches;
next	1.12;

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

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

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

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

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

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

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

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

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

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

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

1.1
date	2000.11.12.21.14.55;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.11.12.21.14.55;	author dlr;	state Exp;
branches;
next	;

1.16.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	;


desc
@@


1.17
log
@delete stuff from the head which is obsolete in the branch (more changes
are still needed for a clean compile)
@
text
@/* ================================================================
 * Copyright (c) 2000 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 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 CollabNet.
 */
package org.tigris.helm.database;

import java.sql.*;
import java.util.*;

import org.webmacro.util.Log;
import org.webmacro.servlet.WebContext;

import org.apache.turbine.services.resources.TurbineResourceService;
import org.apache.turbine.services.db.*;
import org.apache.turbine.util.db.pool.*;

import com.workingdogs.village.*;

import org.joist.database.*;
import org.joist.util.EscapedString;
import org.joist.util.QuotedString;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.domain.Domain;


/**
 * Manages the domain table.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: DomainManager.java,v 1.16 2001/01/26 18:29:00 edk Exp $
 *
 * Copyright (c) 2000 CollabNet, Inc.  
 */

public class DomainManager extends TableManager
{
    /**
     * SQL statement used to lock the tables used in the initializer.
     */
    private static final String LOCK_TABLES = "lock tables " + 
        "HELM_DOMAIN read";
    
    /**
     * SQL statement used to unlock the tables used in the initializer.
     */
    private static final String UNLOCK_TABLES = "unlock tables";

    /**
     * A static mapping of domain names to Records. Used for
     * speed reasons.  
     */
    private static HashMap domainNameMap = new HashMap();

    /**
     * A static mapping of domain IDs to Records. Used for
     * speed reasons.  
     */
    private static HashMap domainIDMap = new HashMap();

    /**
     * The name of the database table that this <code>TableManager</code> 
     * manages. Doesn't actually exist yet.
     */
    public static final String TABLE_NAME = "HELM_DOMAIN";

    /**
     * The primary database key field.
     */
    public static final String DOMAIN_ID = "DOMAIN_ID";

    /**
     * The foreign database key field from Joist's User table.
     * <p>
     * HELP: This does not belong here, but no Helm UserManager exists.
     */
    public static final String USER_DOMAIN_ID = "domainID";

    /**
     * The name field.
     */
    public static final String DOMAIN_NAME = "NAME";   

    /**
     * The logger instance for all instances of this class.
     */
    private static Log log = new Log("domMgr", "DomainManager");

    /**
     * Whether we want debugging information.
     */
    private static boolean debug = true;    

    /**
     * The special domain name for the host.
     */
    public static final String hostDomainName = "**HOST";

    /**
     * Creates a new instance.
     *
     * @@param dataMgr The manager of this instance.
     */
    public DomainManager(DataManager dataMgr)
    {
        super(dataMgr);
    }

    // method addUserToDmain movedto Domain#addNewUser

    // method getUsersForDomain has been moved to Domain#getUsers

    /**
     * Static initializer--build the map of domain names to Domain
     * objects.  
     */
    static
    {
        DBConnection dbConn = null;
        try
        {
            // Get a connection from the Turbine ConnectionPool.
            dbConn = TurbineDB.getConnection();
            Connection connection = dbConn.getConnection();
            DataManager dMgr = new DataManager();

            Statement stmt = null;        
            try
            {
                // Grab a light weight database lock.
                stmt = connection.createStatement();
                stmt.executeUpdate(LOCK_TABLES);
            }
            catch (Exception e)
            {
                log.info("Table locking/unlocking error in static " +
                          "initializer: " + e.getMessage());
                throw new RuntimeException(e.getMessage());
            }

            try
            {
                buildDomainMaps(connection, dMgr);
            }
            catch (DataSetException e)
            {
                log.exception(e);
                throw new RuntimeException(e.getMessage());
            }
            catch (SQLException e)
            {
                log.exception(e);
                throw new RuntimeException(e.getMessage());
            }

            if (stmt != null)
            {
                // Unlock the database tables.
                stmt.executeUpdate(UNLOCK_TABLES);
                stmt.close();
            }
        }
        catch (Exception e)
        {
            log.exception(e);
            throw new RuntimeException(e.getMessage());
        }
        finally
        {
            // Return the connection to the pool.
            if (dbConn != null)
            {
                try
                {
                    TurbineDB.releaseConnection(dbConn);
                }
                catch (Exception e)
                {
                    throw new RuntimeException(e.getMessage());
                }
            }
        }
    }

    /**
     * Builds the static Maps of domain records.
     */
    private static void buildDomainMaps (Connection connection,
                                         DataManager dMgr)
        throws SQLException, DataSetException
    {
        DataSet domains = null;
        try
        {
            domains = new TableDataSet(connection, TABLE_NAME);
            domains.fetchRecords();
            for (int i = 0; i < domains.size(); i++)
            {
                Record domain = domains.getRecord(i);
                String domainID = domain.getValue(DOMAIN_ID).toString();
                String domainName = domain.getValue(DOMAIN_NAME).toString();
                domainIDMap.put(domainID, domain);
                domainNameMap.put(domainName, domain);
            }
        }
        finally
        {
            if (domains != null) domains.close();
        }
    }

    public Record getHostDomain()
        throws JoistDatabaseException
    {
        return getDomainRecordByName(hostDomainName);
    }

    public String getHostDomainID()
        throws JoistDatabaseException, DataSetException
    {
        return getHostDomain().getValue(DOMAIN_ID).asString();
    }

    public Record getDomainRecordByID(String domainID) 
        throws JoistDatabaseException
    {        
        if (domainIDMap.containsKey(domainID))
        {
            return (Record)domainIDMap.get(domainID);
        } else {
            throw new JoistDatabaseException("No such domainID: " + domainID);
        }
    }

    public Record getDomainRecordByName(String domainName) 
        throws JoistDatabaseException
    {
        if (domainNameMap.containsKey(domainName))
        {
            return (Record)domainNameMap.get(domainName);
        } else {
            throw new JoistDatabaseException("No such domain: " + 
                                             domainName);
        }
    }

    /**
     * Maps a domain ID to a domain name.
     *
     * @@param domainID The domain ID to get a name for.
     * @@return         The domain name.
     *
     * @@exception JoistDatabaseException
     */
    public String getDomainName (String domainID)
        throws DataSetException, JoistDatabaseException
    {        
        return getDomainRecordByID(domainID).getValue(DOMAIN_NAME).asString();
    }

    /**
     * Maps a domain name to a domain ID.
     *
     * @@param domainName The domain name to get an ID for.
     * @@return           The domain ID.
     *
     * @@exception JoistDatabaseException
     */
    public Integer getDomainID (String domainName)
        throws DataSetException, JoistDatabaseException
    {        
        return new Integer(getDomainRecordByName(domainName)
                           .getValue(DOMAIN_ID).asInt());
    }

    /**
     * Gets a DataSet containing all the domains.
     *
     * @@param connection A JDBC connection
     * @@return           A DataSet representing all domains.
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    public DataSet listDomains (Connection connection)
        throws DataSetException, SQLException
    {
        return getDomains(connection, null, null);
    }

    /**
     * General method for getting domains from the database.
     *
     * @@param connection A JDBC connection
     * @@return           A DataSet representing the specified domain(s).
     *
     * @@exception SQLException
     * @@exception DataSetException
     */
    private DataSet getDomains (Connection conn, String domainID,
                                String domainName)
        throws DataSetException, SQLException
    {
        String action = "Getting domains for domainID=" + domainID + 
            ", domainName=" + domainName;
        TableDataSet domains = null;
        try
        {
            domains = new TableDataSet(conn, TABLE_NAME);
            domains.where(buildWhereClause(domainID, domainName));
            domains.fetchRecords();
        }
        catch (DataSetException e)
        {
            log.exception(e);
            if (debug) log.debug(action + ": " + e.getMessage());
            throw e;
        }
        catch (SQLException e)
        {
            log.exception(e);
            if (debug) log.debug(action + ": " + e.getMessage());
            throw e;
        }
        finally
        {
            registerToClose(domains);
        }        

        return domains;
    }

    /**
     * Retrieves a user for the given domain and loginID.
     */
    public Record getUserForLoginID(Connection c, String domainID, 
                                    String loginID)
        throws SQLException, DataSetException
    {
        return getUserForField(c, domainID, UserManager.LOGIN_ID, loginID);
    }

    /**
     * Retrieves a user for the given domain and loginID.
     */
    public Record getUserForEmail(Connection c, String domainID, String email)
        throws SQLException, DataSetException
    {
        return getUserForField(c, domainID, UserManager.EMAIL, email);
    }

    /**
     * Retrieves a user for the given domain and other database text field.
     */
    private Record getUserForField(Connection c, String domainID, String key,
                                   String value)
        throws SQLException, DataSetException
    {
        TableDataSet users = null;
        try
        {
            KeyDef kd = new KeyDef().addAttrib(UserManager.USER_ID);
            users = new TableDataSet(c, UserManager.TABLE_NAME, kd);
            StringBuffer buf = new StringBuffer();
            Domain dom = new Domain(c, getDataManager(), domainID);
            // Use Domain's getHostDomain() instance method.
            users.where(key + '=' + escapeAndQuoteSQL(value) + " AND (" +
                        USER_DOMAIN_ID + '=' + domainID + " OR " +
                        USER_DOMAIN_ID + '=' + dom.getHostDomain().getID() +
                        ')');
            users.fetchRecords(1);
        }
        catch (JoistDatabaseException e)
        {
            throw new SQLException(e.getMessage());
        }
        catch (DoesNotExist e)
        {
            throw new SQLException(e.getMessage());
        }
        finally
        {
            registerToClose(users);
        }
        return users.getRecord(0);
    }

    /**
     * Builds the SQL <code>where</code> clause for the managed table.
     *
     * @@param domainID The database key of the domain.
     * @@param name     The domain name.
     * @@return         The generated SQL.
     */
    private String buildWhereClause (Object domainID, String name)
    {
        StringBuffer buf = new StringBuffer();

        if (domainID != null)
        {
            buf.append(DOMAIN_ID).append('=').append(domainID);
        }
        if (name != null)
        {
            if (domainID != null)
            {
                buf.append(" AND ");
            }
            buf.append(DOMAIN_NAME).append('=');
            buf.append(escapeAndQuoteSQL(name));
        }

        return buf.toString();
    }
}
@


1.16
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d73 1
a73 1
 * @@version $Id: DomainManager.java,v 1.9 2001/01/15 17:17:38 leonardr Exp $
@


1.16.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d73 1
a73 1
 * @@version $Id: DomainManager.java,v 1.16 2001/01/26 18:29:00 edk Exp $
@


1.15
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d60 1
a60 3
import org.joist.database.TableManager;
import org.joist.database.DataManager;
import org.joist.database.Criterion;
d73 1
a73 1
 * @@version $Id: DomainManager.java,v 1.14 2001/01/25 01:38:06 leonardr Exp $
d75 1
a75 1
 * Copyright (c) 2000-2001 CollabNet, Inc.  
d115 3
a117 1
     * The name field.
d119 1
a119 1
    public static final String DOMAIN_NAME = "NAME";   
d122 1
a122 1
     * The default way of ordering items from this table.
d124 1
a124 2
    private static final String DEFAULT_ORDER_CLAUSE = TABLE_NAME + '.' +
        DOMAIN_NAME;
d148 1
a148 1
        super(dataMgr, new KeyDef().addAttrib(DOMAIN_ID));
d151 1
a151 1
    // method addUserToDomain moved to Domain#addNewUser
d187 6
a192 1
            catch (DBException e)
d204 3
a206 1
        } catch (Exception e) {
d209 3
a211 1
        } finally {
d218 3
a220 1
                } catch (Exception e) {
d232 1
a232 1
        throws DBException
a246 4
        } catch (DataSetException e) {
            throw new DBException(e);
        } catch (SQLException e) {
            throw new DBException(e);
d250 1
a250 7
            try {
                if (domains != null) domains.close();
            } catch (DataSetException e) {
                throw new DBException(e);
            } catch (SQLException e) {
                throw new DBException(e);
            }
d255 1
a255 1
        throws DBException
d257 1
a257 7
        Record r = null;
        try {
            r = getDomainRecordByName(hostDomainName);
        } catch (DoesNotExist e) {
            throw new DBException("Host domain does not exist!");
        }
        return r;
d261 1
a261 1
        throws DBException
d263 1
a263 7
        String id = null;
        try {
            id = getHostDomain().getValue(DOMAIN_ID).asString();
        } catch (DataSetException e) {
            throw new DBException(e);
        }
        return id;
d267 1
a267 1
        throws DoesNotExist
d273 1
a273 1
            throw new DoesNotExist("Domain with ID " + domainID);
d278 1
a278 1
        throws DoesNotExist
d284 2
a285 1
            throw new DoesNotExist("Domain with name " + domainName);
d295 1
a295 2
     * @@exception DoesNotExist if the domain ID is invalid.
     * @@exception DBexception if an error with the database occurs.
d298 1
a298 1
        throws DBException, DoesNotExist
d300 1
a300 8
        String name = null;
        try {
            name = getDomainRecordByID(domainID)
                .getValue(DOMAIN_NAME).asString();
        } catch (DataSetException e) {
            throw new DBException(e);
        }
        return name;
d309 1
a309 2
     * @@exception DoesNotExist if the domain name is invalid.
     * @@exception DBexception if a problem with the database occurs.
d311 2
a312 2
    public String getDomainID (String domainName)
        throws DBException, DoesNotExist
d314 2
a315 8
        String id = null;
        try {
            id = getDomainRecordByName(domainName).getValue(DOMAIN_ID)
                .asString();
        } catch (DataSetException e) {
            throw new DBException(e);
        }
        return id;
d321 1
d324 2
a325 1
     * @@exception DBexception if a problem with the database occurs.
d327 2
a328 2
    public DataSet listDomains()
        throws DBException
d330 1
a330 1
        return getDomains(null);
d334 1
a334 1
     * Get domains from the database which match a given Criterion.
a337 1
     * @@exception DBexception if a problem with the database occurs.
d339 97
d437 1
a437 2
    private DataSet getDomains(Criterion criterion)
        throws DBException
d439 5
a443 5
        DataSet s = null;
        try {
            s = runSelect(TABLE_NAME, criterion, DEFAULT_ORDER_CLAUSE);
        } catch (Exception e) {
            throw new DBException(e);
d445 11
a455 1
        return s;
@


1.14
log
@More TableManagers de-connectionified.
@
text
@d75 1
a75 1
 * @@version $Id: DomainManager.java,v 1.13 2001/01/25 01:32:10 lucas Exp $
@


1.13
log
@Lopsided brace
@
text
@d75 1
a75 1
 * @@version $Id: DomainManager.java,v 1.12 2001/01/24 22:24:36 leonardr Exp $
d124 2
a125 1
    private static final String DEFAULT_ORDER_CLAUSE = TABLE_NAME + "." + DOMAIN_NAME;
d152 1
a152 1
    // method addUserToDmain movedto Domain#addNewUser
@


1.12
log
@Moved TableManagers to new keydef constructor and keydef-less runSelect.
@
text
@d75 1
a75 1
 * @@version $Id: DomainManager.java,v 1.11 2001/01/24 21:41:48 leonardr Exp $
d285 1
@


1.11
log
@Ported UserManager and RoleManager to Helm. Started moving other TableManagers toward a grab-connection-on-demand model. Massive breakage ensues. dlr and I are working on it.
@
text
@d75 1
a75 1
 * @@version $Id: DomainManager.java,v 1.10 2001/01/24 20:42:46 dlr Exp $
a121 8
     * Returns a KeyDef object appropriate for this table.
     */
    private KeyDef keydef()
    {
        return new KeyDef().addAttrib(DOMAIN_ID);
    }

    /**
d148 1
a148 1
        super(dataMgr);
d368 1
a368 2
            s = runSelect(TABLE_NAME, keydef(), criterion, 
                          DEFAULT_ORDER_CLAUSE);
@


1.10
log
@Making use of DBException.
@
text
@d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d60 3
a62 1
import org.joist.database.*;
d75 1
a75 1
 * @@version $Id: DomainManager.java,v 1.9 2001/01/15 17:17:38 leonardr Exp $
d77 1
a77 1
 * Copyright (c) 2000 CollabNet, Inc.  
d117 6
a122 3
     * The foreign database key field from Joist's User table.
     * <p>
     * HELP: This does not belong here, but no Helm UserManager exists.
d124 4
a127 1
    public static final String USER_DOMAIN_ID = "domainID";
d130 1
a130 1
     * The name field.
d132 1
a132 1
    public static final String DOMAIN_NAME = "NAME";   
d195 1
a195 6
            catch (DataSetException e)
            {
                log.exception(e);
                throw new RuntimeException(e.getMessage());
            }
            catch (SQLException e)
d207 1
a207 3
        }
        catch (Exception e)
        {
d210 1
a210 3
        }
        finally
        {
d217 1
a217 3
                }
                catch (Exception e)
                {
d244 3
a246 3
        }
        catch (DataSetException e)
        {
d251 7
a257 1
            if (domains != null) domains.close();
d264 7
a270 1
        return getDomainRecordByName(hostDomainName);
d276 7
a282 1
        return getHostDomain().getValue(DOMAIN_ID).asString();
d286 1
a286 1
        throws DBException
d291 2
a292 5
        }
        else
        {
            throw new DBException("No such domainID: " + domainID);
        }
d296 1
a296 1
        throws DBException
d301 2
a302 4
        }
        else
        {
            throw new DBException("No such domain: " + domainName);
d312 2
a313 1
     * @@exception DBException
d316 1
a316 1
        throws DBException
d318 8
a325 1
        return getDomainRecordByID(domainID).getValue(DOMAIN_NAME).asString();
d334 2
a335 1
     * @@exception DBException
d337 2
a338 2
    public Integer getDomainID (String domainName)
        throws DBException
d340 8
a347 2
        return new Integer(getDomainRecordByName(domainName)
                           .getValue(DOMAIN_ID).asInt());
a352 1
     * @@param connection A JDBC connection
d355 1
a355 1
     * @@exception DBException
d357 1
a357 1
    public DataSet listDomains (Connection connection)
d360 1
a360 1
        return getDomains(connection, null, null);
d364 1
a364 1
     * General method for getting domains from the database.
d368 1
a369 34
     * @@exception SQLException
     * @@exception DataSetException
     */
    private DataSet getDomains (Connection conn, String domainID,
                                String domainName)
        throws DBException
    {
        String action = "Getting domains for domainID=" + domainID + 
            ", domainName=" + domainName;
        TableDataSet domains = null;
        try
        {
            domains = new TableDataSet(conn, TABLE_NAME);
            domains.where(buildWhereClause(domainID, domainName));
            domains.fetchRecords();
        }
        catch (DataSetException e)
        {
            throw new DBException (e);
        }
        catch (SQLException e)
        {
            throw new DBException (e);
        }
        finally
        {
            registerToClose(domains);
        }        

        return domains;
    }

    /**
     * Retrieves a user for the given domain and loginID.
d371 1
a371 2
    public Record getUserForLoginID(Connection c, String domainID, 
                                    String loginID)
d374 5
a378 35
        return getUserForField(c, domainID, UserManager.LOGIN_ID, loginID);
    }

    /**
     * Retrieves a user for the given domain and loginID.
     */
    public Record getUserForEmail(Connection c, String domainID, String email)
        throws DBException
    {
        return getUserForField(c, domainID, UserManager.EMAIL, email);
    }

    /**
     * Retrieves a user for the given domain and other database text field.
     */
    private Record getUserForField(Connection c, String domainID, String key,
                                   String value)
        throws DoesNotExist, DBException
    {
        TableDataSet users = null;
        try
        {
            KeyDef kd = new KeyDef().addAttrib(UserManager.USER_ID);
            users = new TableDataSet(c, UserManager.TABLE_NAME, kd);
            StringBuffer buf = new StringBuffer();
            Domain dom = new Domain(c, getDataManager(), domainID);
            // Use Domain's getHostDomain() instance method.
            users.where(key + '=' + escapeAndQuoteSQL(value) + " AND (" +
                        USER_DOMAIN_ID + '=' + domainID + " OR " +
                        USER_DOMAIN_ID + '=' + dom.getHostDomain().getID() +
                        ')');
            users.fetchRecords(1);
        }
        catch (JoistDatabaseException e)
        {
d381 1
a381 33
        finally
        {
            registerToClose(users);
        }
        return users.getRecord(0);
    }

    /**
     * Builds the SQL <code>where</code> clause for the managed table.
     *
     * @@param domainID The database key of the domain.
     * @@param name     The domain name.
     * @@return         The generated SQL.
     */
    private String buildWhereClause (Object domainID, String name)
    {
        StringBuffer buf = new StringBuffer();

        if (domainID != null)
        {
            buf.append(DOMAIN_ID).append('=').append(domainID);
        }
        if (name != null)
        {
            if (domainID != null)
            {
                buf.append(" AND ");
            }
            buf.append(DOMAIN_NAME).append('=');
            buf.append(escapeAndQuoteSQL(name));
        }

        return buf.toString();
@


1.9
log
@Got rid of no-longer-needed debugging.
@
text
@d73 1
a73 1
 * @@version $Id: DomainManager.java,v 1.8 2001/01/05 01:10:55 dlr Exp $
d232 1
a232 1
        throws SQLException, DataSetException
d248 4
d259 1
a259 1
        throws JoistDatabaseException
d265 1
a265 1
        throws JoistDatabaseException, DataSetException
d271 1
a271 1
        throws JoistDatabaseException
d276 4
a279 2
        } else {
            throw new JoistDatabaseException("No such domainID: " + domainID);
d284 1
a284 1
        throws JoistDatabaseException
d289 4
a292 3
        } else {
            throw new JoistDatabaseException("No such domain: " + 
                                             domainName);
d302 1
a302 1
     * @@exception JoistDatabaseException
d305 1
a305 1
        throws DataSetException, JoistDatabaseException
d316 1
a316 1
     * @@exception JoistDatabaseException
d319 1
a319 1
        throws DataSetException, JoistDatabaseException
d331 1
a331 2
     * @@exception SQLException
     * @@exception DataSetException
d334 1
a334 1
        throws DataSetException, SQLException
d350 1
a350 1
        throws DataSetException, SQLException
d363 1
a363 3
            log.exception(e);
            if (debug) log.debug(action + ": " + e.getMessage());
            throw e;
d367 1
a367 3
            log.exception(e);
            if (debug) log.debug(action + ": " + e.getMessage());
            throw e;
d382 1
a382 1
        throws SQLException, DataSetException
d391 1
a391 1
        throws SQLException, DataSetException
d401 1
a401 1
        throws SQLException, DataSetException
d419 1
a419 5
            throw new SQLException(e.getMessage());
        }
        catch (DoesNotExist e)
        {
            throw new SQLException(e.getMessage());
@


1.8
log
@Migrated to latest Turbine CVS to avoid connection release bug (fixed long ago in Turbine CVS--we just had a bunk version).
@
text
@d73 1
a73 1
 * @@version $Id: DomainManager.java,v 1.7 2000/12/29 02:33:37 dlr Exp $
a412 1
            if (debug) log.info("sql=" + users.getSelectString());
@


1.7
log
@Updated to support move of root user to Host's domain.
@
text
@d73 1
a73 1
 * @@version $Id: DomainManager.java,v 1.6 2000/12/28 19:48:36 dlr Exp $
d165 1
a165 1
            dbConn = PoolBrokerService.getInstance().getConnection();
d217 1
a217 1
                    PoolBrokerService.getInstance().releaseConnection(dbConn);
@


1.6
log
@Less lines, same bytecodes.
@
text
@d64 3
d73 1
a73 1
 * @@version $Id: DomainManager.java,v 1.5 2000/12/27 23:12:34 leonardr Exp $
d406 8
a413 2
            users.where(USER_DOMAIN_ID + '=' + domainID + " AND " + key + '=' +
                        escapeAndQuoteSQL(value));
d415 8
@


1.5
log
@Support for users in the host domain.
@
text
@d70 1
a70 1
 * @@version $Id: DomainManager.java,v 1.4 2000/12/15 18:58:39 leonardr Exp $
d403 2
a404 5
            StringBuffer buf = new StringBuffer(USER_DOMAIN_ID);
            buf.append('=').append(domainID).append(" AND ")
                .append(key).append('=')
                .append(escapeAndQuoteSQL(value));
            users.where(buf.toString());
@


1.4
log
@Wide-ranging patch containing code which will eventually cause fewer MemberAdd and MemberDelete scripts to be run.
@
text
@d70 1
a70 1
 * @@version $Id: DomainManager.java,v 1.3 2000/12/06 19:36:57 dlr Exp $
d255 6
@


1.3
log
@This should be private, as it allows a broader interface than is
necessary (or desired).
@
text
@d70 1
a70 1
 * @@version $Id: DomainManager.java,v 1.2 2000/12/06 19:36:23 dlr Exp $
d249 6
@


1.2
log
@Added a method to retrieve user by email address.
@
text
@d70 1
a70 1
 * @@version $Id: DomainManager.java,v 1.1.1.1 2000/11/12 21:14:55 dlr Exp $
d382 2
a383 2
    public Record getUserForField(Connection c, String domainID, String key,
                                  String value)
@


1.1
log
@Initial revision
@
text
@d70 1
a70 1
 * @@version $Id: DomainManager.java,v 1.25 2000/11/11 04:33:44 dlr Exp $
d367 19
d393 2
a394 2
                .append(UserManager.LOGIN_ID).append('=')
                .append(escapeAndQuoteSQL(loginID));
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@@
