head	1.13;
access;
symbols
	TIGRIS_0_9_2_4:1.6
	TIGRIS_0_9_2_3:1.6
	HELM_PEER_PORT_BRANCH:1.12.0.2
	TURBINE_PEER:1.12
	TIGRIS_0_9_2_1:1.12
	TIGRIS_0_9_2:1.6.0.8
	TIGRIS_0_9_0:1.6.0.6
	TIGRIS_0_8_4:1.6.0.4
	TIGRIS_NOV_12_2000:1.6
	OLDHELM:1.6.0.2
	TIGRIS_NOV_11_2000:1.6;
locks; strict;
comment	@# @;


1.13
date	2001.02.21.03.23.56;	author edk;	state dead;
branches;
next	1.12;

1.12
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.12.2.1;
next	1.11;

1.11
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.10;

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

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

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

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

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

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

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

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

1.2
date	2000.09.29.18.09.59;	author leonardr;	state Exp;
branches;
next	1.1;

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

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


desc
@@


1.13
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.util.*;
import java.sql.*;

import org.webmacro.util.*;
import org.webmacro.servlet.*;

import com.workingdogs.village.*;

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

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

public class ScopeManager extends TableManager
{
    /**
     * The name of the database table that this <code>TableManager</code> 
     * manages.
     */
    public static final String TABLE_NAME = "HELM_SCOPE";

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

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

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

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

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

    /**
     *  Retrieves a named scope from the database.
     *
     * @@param	connection    A JDBC database connection
     * @@param	scopeID       The scopeID to obtain 
     * @@return	 a String
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public String getScopeForID (Connection connection, String scopeID)
	throws DBException
    {
        TableDataSet scopes = null;
        try
        {
            scopes = new TableDataSet(connection, TABLE_NAME);
            scopes.where(SCOPE_ID + '=' + scopeID);
            scopes.fetchRecords();
            if (scopes.containsRecord(0))
            {
                return scopes.getRecord(0).getValue(SCOPE_ID).asString();
            } else {
                throw new DBException ("No such scope: " + scopeID);
            }
	}
	catch (DataSetException e)
	{
            throw new DBException(e);
	}
	catch (SQLException e)
	{
            throw new DBException(e);
	}
	finally
	{
	    registerToClose(scopes);
	}
    }

    /**
     * Adds a new scope to the database
     *
     * @@param connection The JDBC database connection to use.
     * @@param name       A regular expression indicating the scope.
     * @@return	         The system-assigned scope ID for the newly added 
     *                   scope.
     *
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public Integer addScope (Connection connection, String name)
	throws DBException
    {
        return updateScope(connection, null, name);
    }

    /**
     * Updates an existing scope or adds a new scope to the database 
     * (depending on whether given a <code>scopeID</code> or not).
     *
     * @@param connection The JDBC database connection to use.
     * @@param scopeID    The database key of the scope to update, or 
     *                   <code>null</code> if the scope is new.
     * @@param name       A regular expression indicating the scope.
     * @@return	         The system-assigned scope ID for the scope updated.
     *
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public Integer updateScope (Connection connection, String scopeID, 
                                String name)
	throws DBException
    {
        Integer sid = null;

	Record scope = null;
        TableDataSet scopes = null;
	try
	{
            // Prep for update.
	    scopes = new TableDataSet(connection, TABLE_NAME);
            StringBuffer whereClause = new StringBuffer();
            if (scopeID == null)
            {
                // Adding new scope.  First check for scope with existing name.
                whereClause.append(SCOPE_NAME).append('=').append(name);
            }
            else
            {
                // Updating existing scope.
                whereClause.append(" and ");
                whereClause.append(SCOPE_ID).append('=').append(scopeID);
            }
            scopes.where(whereClause.toString());

            // Do update.
            scopes.fetchRecords();
	    if (scopes.containsRecord(0)) 
	    {
                scope = scopes.getRecord(0);
                if (scopeID != null)
                {
                    scope.setValue(SCOPE_NAME, name);
                    scope.save();
                }
	    }
            else
            {
                scope = scopes.addRecord();
                scope.setValue(SCOPE_NAME, name);
                scope.save();
	    }
            sid = new Integer(scope.getValue(SCOPE_ID).asInt());
        }
	catch (DataSetException e)
	{
            throw new DBException(e);
	}
	catch (SQLException e)
	{
            throw new DBException(e);
	}
	finally
	{
	    registerToClose(scopes);
	}

	return sid;
    }

    /**
     * Deletes an existing scope from the database
     *
     * @@param	  connection    the JDBC database connection
     * @@param	  scopeID       the ID of the scope to delete
     * @@exception SQLException
     */
    public void  deleteScope (Connection connection, String scopeID)
	throws DBException
    {
	TableDataSet scopes = null;
	try
	{
	    scopes = new TableDataSet(connection, TABLE_NAME);
	    scopes.where(SCOPE_ID + '=' + scopeID);
	    scopes.fetchRecords();
	    if (scopes.containsRecord(0)) 
	    {
                Record r = scopes.getRecord(0);
                r.markToBeDeleted();
                r.save();
	    }
	}
	catch (DataSetException e)
	{
	    throw new DBException(e);
	}
	catch (SQLException e)
	{
	    throw new DBException(e);
	}
	finally
	{
	    registerToClose(scopes);
	}
    }
}
@


1.12
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.8 2001/01/24 01:24:50 dlr Exp $
@


1.12.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.12 2001/01/26 18:29:00 edk Exp $
@


1.11
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
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.10 2001/01/24 22:24:36 leonardr Exp $
d104 1
a104 1
        super(dataMgr, new KeyDef().addAttrib(SCOPE_ID));
d113 2
a114 2
     *
     * @@exception DBException
d154 2
a155 1
     * @@exception DBException
d173 2
a174 1
     * @@exception DBException
d242 1
a242 2
     *
     * @@exception DBException
@


1.10
log
@Moved TableManagers to new keydef constructor and keydef-less runSelect.
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.9 2001/01/24 20:42:46 dlr Exp $
@


1.9
log
@Making use of DBException.
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.8 2001/01/24 01:24:50 dlr Exp $
d104 1
a104 1
        super(dataMgr);
@


1.8
log
@Corrected compiler errors I just introduced using Leonard's sandbox.
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.7 2001/01/24 01:20:52 leonardr Exp $
d113 2
a114 2
     * @@exception	SQLException
     * @@exception	DataSetException
d154 1
a154 2
     * @@exception	SQLException
     * @@exception	DataSetException
d172 1
a172 2
     * @@exception	SQLException
     * @@exception	DataSetException
d240 2
a241 1
     * @@exception SQLException
@


1.7
log
@Switching to DBException.
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.6 2000/09/29 20:13:49 dlr Exp $
d129 1
a129 1
                throw new JoistDatabaseException ("No such scope " + scopeID);
d180 2
a182 1

d219 1
d234 1
a234 1
	return new Integer(scope.getValue(SCOPE_ID).asInt());
@


1.6
log
@Corrected JavaDoc.
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.5 2000/09/29 19:55:46 dlr Exp $
d117 1
a117 1
	throws SQLException, DataSetException, JoistDatabaseException
d134 1
a134 3
	    log.exception(e);
	    if (debug) log.debug("Getting Scope: " + e.getMessage());
	    throw e;
d138 1
a138 3
	    log.exception(e);
	    if (debug) log.debug("Getting Scope: " + e.getMessage());
	    throw e;
d142 1
a142 1
	    if (scopes != null) registerToClose(scopes);
d158 1
a158 1
	throws SQLException, DataSetException
d178 1
a178 1
	throws SQLException, DataSetException
d221 1
a221 4
	    log.exception(e);
	    String message = "Adding  " + e.getMessage();
	    if (debug) log.debug(message);
	    throw e;
d225 1
a225 4
	    log.exception(e);
	    String message = "Adding Scope: " + e.getMessage();
	    if (debug) log.debug(message);
	    throw e;
d229 1
a229 1
	    if (scopes != null) registerToClose(scopes);
d243 1
a243 1
	throws SQLException, DataSetException
d260 1
a260 3
	    log.exception(e);
	    if (debug) log.debug("Deleting Scope: " + e.getMessage());
	    throw e;
d264 1
a264 3
	    log.exception(e);
	    if (debug) log.debug("Deleting Scope: " + e.getMessage());
	    throw e;
d268 1
a268 1
	    if (scopes != null) registerToClose(scopes);
a271 2


@


1.5
log
@Collab.Net --> CollabNet in copyright.
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.4 2000/09/29 19:51:58 dlr Exp $
d98 1
a98 1
     * Instantiates a new instance.
d100 1
a100 1
     * @@param	dataMgr  A variable of type DataManager
d168 2
a169 1
     * Adds a new scope to the database
@


1.4
log
@Corrected method mis-call.
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.3 2000/09/29 19:40:05 dlr Exp $
d66 1
a66 1
 * Copyright (c) 2000 Collab.Net, Inc.
@


1.3
log
@- Added JavaDoc to field members.
- Added updateScope() method, which addScope() now wrappers.
- Thorough code review.
@
text
@d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.2 2000/09/29 18:09:59 leonardr Exp $
d211 1
a211 1
                    scope.setValue(SCOPE_NAME.name);
d218 1
a218 1
                scope.setValue(SCOPE_NAME.name);
@


1.2
log
@Filled in basic functionality.
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d60 1
a60 1
 * Manages one or more database tables.
d64 1
a64 1
 * @@version $Id: ScopeManager.java,v 1.1 2000/09/29 01:42:45 dlr Exp $
d71 19
d91 4
a96 4
    static final String scopeTable = "HELM_SCOPE";
    static final String scopeIDField = "SCOPE_ID";
    static final String scopeNameField = "NAME";   

d119 1
a119 1
        TableDataSet scopes=null;
d122 2
a123 2
            scopes = new TableDataSet(connection, scopeTable);
            scopes.where(scopeIDField + " = " + scopeID);
d127 1
a127 1
                return scopes.getRecord(0).getValue(scopeIDField).asString();
d135 1
a135 2
	    String message = "Getting Scope: " + e.getMessage();
	    if (debug) log.debug(message);
d141 1
a141 2
	    String message = "Getting Scope: " + e.getMessage();
	    if (debug) log.debug(message);
d151 6
a156 1
     *  Adds a new scope to the database
a157 3
     * @@param	connection    the JDBC database connection
     * @@param	regexp    the regexp of the scope
     * @@return	 the system-assigned scope ID for the newly added scope.
d164 2
d167 19
a185 2
	Record r;
    TableDataSet scopes = null;
d188 19
a206 4
	    scopes = new TableDataSet(connection, scopeTable);
	    scopes.where(scopeIDField + "=" + name);
	    scopes.fetchRecords();
	    if (!scopes.containsRecord(0)) 
d208 12
a219 5
            r = scopes.addRecord();
            r.setValue(scopeNameField,name);
            r.save();
	    } else {
            r = scopes.getRecord(0);
d221 1
a221 1
    }
d241 1
a241 1
	return new Integer(r.getValue(scopeIDField).asInt());
a244 4
     * Is an update method neccessary?
     */

    /**
a254 1
    Record r = null;
d257 2
a258 2
	    scopes = new TableDataSet(connection, scopeTable);
	    scopes.where(scopeIDField + "=" + scopeID);
d262 3
a264 3
            r = scopes.getRecord(0);
            r.markToBeDeleted();
            r.save();
d270 1
a270 2
	    String message = "Deleting Scope: " + e.getMessage();
	    if (debug) log.debug(message);
d275 2
a276 2
	    String message = "Deleting Scope: " + e.getMessage();
	    if (debug) log.debug(message);
@


1.1
log
@Table manager stubs for the new Helm permission system.
@
text
@d2 1
a2 1
 * Copyright (c) 2000 Collab.Net.  All rights reserved.
d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d27 1
a27 1
 * permission of Collab.Net.
d44 1
a44 1
 * individuals on behalf of Collab.Net.
a45 1

d60 1
a60 1
 * Manages one or more database table.
d63 2
a64 1
 * @@version $Id: $
d71 1
a71 1
    private static Log log = new Log("rpsmMgr", "ScopeManager");
d74 4
d87 143
d231 2
@

