head	1.9;
access;
symbols
	TIGRIS_0_9_2_4:1.4
	TIGRIS_0_9_2_3:1.4
	HELM_PEER_PORT_BRANCH:1.8.0.2
	TURBINE_PEER:1.8
	TIGRIS_0_9_2_1:1.8
	TIGRIS_0_9_2:1.4.0.4
	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.9
date	2001.02.21.03.23.56;	author edk;	state dead;
branches;
next	1.8;

1.8
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.8.2.1;
next	1.7;

1.7
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.6;

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

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

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

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

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

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

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

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


desc
@@


1.9
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 resource table.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: ResourceManager.java,v 1.8 2001/01/26 18:29:00 edk Exp $
 *
 * Copyright (c) 2000 CollabNet, Inc.
 */

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

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

    /**
     * The name field.
     */
    public static final String RESOURCE_PATTERN = "PATTERN";   

    /**
     * The name field.
     */
    public static final String RESOURCE_DESCRIPTION = "DESCRIPTION";   

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

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

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

    /**
     *  Retrieves the name of a resource, given its ID.
     *
     * @@param	connection    A JDBC database connection
     * @@param	resourceID       The resourceID to obtain 
     * @@return	 a String
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public String getResourceName (Connection connection, String resourceID)
	throws SQLException, DataSetException, JoistDatabaseException
    {
        return getResource(connection, resourceID).getValue(RESOURCE_PATTERN)
            .asString();
    }

    /**
     * Retrieves the record for a specified project.
     *
     * @@param	connection    A JDBC database connection
     * @@param	resourceID       The resourceID to obtain 
     * @@return	 a String
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public Record getResource (Connection connection, String resourceID)
	throws SQLException, DataSetException, JoistDatabaseException
    {
        DataSet resources = getResources(connection, resourceID, null);
        if (resources != null && resources.containsRecord(0))
        {
            return resources.getRecord(0);
        }
        else
        {
            throw new JoistDatabaseException("No such resource " + resourceID);
        }
    }

    /**
     * Retrieves the ID for a resource with known name
     *
     * @@param	connection    A JDBC database connection
     * @@param	resourceName     The resource name to identify
     * @@return	 a String
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public String getResourceID (Connection connection, String resourceName)
	throws SQLException, DataSetException, JoistDatabaseException
    {
        TableDataSet resources = getResources(connection,null,resourceName);
        if (resources != null && resources.containsRecord(0))
        {
            return resources.getRecord(0).getValue(RESOURCE_ID).asString();
        }
        else
        {
            throw new JoistDatabaseException("Invalid resource " + 
                                             resourceName);
        }
    }

    /**
     *  Retrieves a list of all the resources from the database.
     *
     * @@param	connection    A JDBC database connection
     * @@return	 a DataSet
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public DataSet listResources (Connection connection)
	throws SQLException, DataSetException
    {
        return getResources(connection, null, null);
    }

    /**
     *  Retrieves resources by resource ID or name.
     *
     * @@param	connection    A JDBC database connection
     * @@param   resourceID       A resource ID (can be null)
     * @@ param  name          A resource name (can be null)
     * @@return	 a DataSet
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    private TableDataSet getResources(Connection connection,
                                      String resourceID,
                                      String name)
        throws SQLException, DataSetException
    {
        TableDataSet resources = null;
        try
        {
            KeyDef kd = new KeyDef().addAttrib(RESOURCE_ID);
            resources = new TableDataSet(connection, TABLE_NAME, kd);
            resources.where(buildWhereClause(resourceID, name));
            resources.fetchRecords();
	}
	catch (DataSetException e)
	{
	    log.exception(e);
	    if (debug) log.debug("Getting Resource: " + e.getMessage());
	    throw e;
	}
	catch (SQLException e)
	{
	    log.exception(e);
	    if (debug) log.debug("Getting Resource: " + e.getMessage());
	    throw e;
	}
	finally
	{
	    registerToClose(resources);
	}
        return resources;
    }

    /**
     * Adds a new resource to the database
     *
     * @@param connection The JDBC database connection to use.
     * @@param name       A regular expression indicating the resource.
     * @@return	         The system-assigned resource ID for the newly added 
     *                   resource.
     *
     * @@exception	SQLException
     * @@exception	DataSetException
     */
    public Record addResource (Connection connection, String pattern,
                               String description)
	throws SQLException, DataSetException
    {
        Record r = null;
        try {
            r = updateResource(connection, null, pattern, description);
        } catch (JoistDatabaseException ignore) {
            //JDE can only be thrown when changing an existing resource.
        }
        return r;
    }

    /**
     * Updates an existing resource or adds a new resource to the database 
     * (depending on whether given a <code>resourceID</code> or not).
     *
     * @@param connection     The JDBC database connection to use.
     * @@param resourceID    The database key of the resource to update, or 
     *                      <code>null</code> if the resource is new.
     * @@param pattern       A regular expression indicating the resource.
     * @@param description   A description of the resource.
     *
     * @@return              The record for the resource.
     *
     * @@exception	SQLException
     * @@exception DataSetException 
     */
    public Record updateResource (Connection connection, String resourceID, 
                                   String pattern, String description)
	throws SQLException, DataSetException, JoistDatabaseException
    {
	Record resource = null;       
        TableDataSet resources = null;
	try
	{
            if (resourceID != null)
            {
                resource = getResource(connection, resourceID);
                if (pattern != null)
                {
                    resource.setValue(RESOURCE_PATTERN, pattern);
                }
                if (description != null)
                {
                    resource.setValue(RESOURCE_DESCRIPTION, description);
                }
                resource.save();
	    } else {
                KeyDef kd = new KeyDef().addAttrib(RESOURCE_ID);
                resources = new TableDataSet(connection, TABLE_NAME, kd);
                resource = resources.addRecord();
                resource.setValue(RESOURCE_PATTERN, pattern);
                resource.setValue(RESOURCE_DESCRIPTION, description);
                resource.save();
                resourceID = getLastInsertedID(connection).toString();
                resource.setValue(RESOURCE_ID, resourceID);
	    }
        }
	catch (DataSetException e)
	{
	    log.exception(e);
	    String message = "Adding Resource: " + e.getMessage();
	    if (debug) log.debug(message);
	    throw e;
	}
	catch (SQLException e)
	{
	    log.exception(e);
	    String message = "Adding Resource: " + e.getMessage();
	    if (debug) log.debug(message);
	    throw e;
	}
	catch (JoistDatabaseException e)
	{
	    log.exception(e);
	    String message = "Adding Resource: " + e.getMessage();
	    if (debug) log.debug(message);
	    throw e;
	}
	finally
	{
	    registerToClose(resources);
	}

	return resource;
    }

    /**
     * Deletes an existing resource from the database
     *
     * @@param	  connection    the JDBC database connection
     * @@param	  resourceID       the ID of the resource to delete
     * @@exception SQLException
     */
    public void  deleteResource (Connection connection, String resourceID)
	throws SQLException, DataSetException
    {
	TableDataSet resources = null;
	try
	{            
            Record r = getResource(connection, resourceID);
            r.markToBeDeleted();
            r.save();           
        } catch (JoistDatabaseException ignore) {
            //If it didn't exist in the first place, don't complain
            //about not being able to delete it.
        } catch (DataSetException e) {
	    log.exception(e);
	    if (debug) log.debug("Deleting Resource: " + e.getMessage());
	    throw e;
	} catch (SQLException e) {
	    log.exception(e);
	    if (debug) log.debug("Deleting Resource: " + e.getMessage());
	    throw e;
	} finally {
	    registerToClose(resources);
	}
    }

    /**
     * Creates a SQL <code>where</code> clause.
     */
    protected static String buildWhereClause (String resourceID, 
                                              String name)
    {
        StringBuffer whereClause = new StringBuffer();
        boolean firstClause = true;

        if (resourceID != null)
        {
            whereClause.append(RESOURCE_ID).append('=').append(resourceID);
            firstClause = false;
        }
        if (name != null)
        {
            if (!firstClause)
            {
                whereClause.append(" AND ");
            }
            name = escapeAndQuoteSQL(name);
            whereClause.append(RESOURCE_PATTERN).append('=').append(name);
            firstClause = false;
        }

        return whereClause.toString();
    }
}
@


1.8
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: ResourceManager.java,v 1.4 2000/12/11 19:46:10 leonardr Exp $
@


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


1.7
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: ResourceManager.java,v 1.6 2001/01/25 02:19:25 leonardr Exp $
d109 1
a109 1
        super(dataMgr, new KeyDef().addAttrib(RESOURCE_ID));
d113 1
a113 1
     * Retrieves the name of a resource.
d115 5
a119 2
     * @@param resourceID The database key of the resource name to obtain.
     * @@return	         The name of the requested resource.
d121 2
a122 2
    public String getResourceName (String resourceID)
	throws DBException
d124 2
a125 1
        return getResource(resourceID).getValue(RESOURCE_PATTERN).asString();
d129 1
a129 1
     * Retrieves the record for a specified resource.
d131 5
a135 4
     * @@param resourceID The database key of the resource to obtain.
     * @@return	         The requested resource.
     *
     * @@exception DBException
d137 2
a138 2
    public Record getResource (String resourceID)
	throws DoesNotExist, DBException
d140 1
a140 1
        DataSet resources = getResources(resourceID, null);
d147 1
a147 1
            throw new DoesNotExist("No such resource " + resourceID);
d152 1
a152 4
     * Retrieves the database key of the resource with the specified name.
     *
     * @@param resourceName The resource name to identify.
     * @@return	           The database key.
d154 5
a158 1
     * @@exception DBException
d160 2
a161 2
    public String getResourceID (String resourceName)
	throws DoesNotExist, DBException
d163 1
a163 1
        DataSet resources = getResources(null, resourceName);
d170 2
a171 1
            throw new DoesNotExist("Resource " + resourceName);
d176 1
a176 1
     * Retrieves a list of all resources.
d178 4
a181 3
     * @@return The resource list.
     *
     * @@exception DBException
d183 2
a184 2
    public DataSet listResources ()
	throws DBException
d186 1
a186 1
        return getResources(null, null);
d190 1
a190 5
     * Retrieves resources by resource ID or name.
     *
     * @@param resourceID A resource ID (can be <code>null</code>).
     * @@param  name      A resource name (can be <code>null</code>).
     * @@return	         The list of matching resources.
d192 11
a202 4
     * @@exception DBException
     */
    private TableDataSet getResources(String resourceID, String name)
        throws DBException
d204 1
a204 2
        Criterion c = new Criterion(RESOURCE_ID, resourceID);
        c.and(NAME, name);
d207 22
a228 6
            return runSelect(TABLE_NAME, c);
        }
        catch (Exception e)
        {
            throw new DBException(e);
        }
d232 1
a232 5
     * Adds a new resource to the database.
     *
     * @@param pattern A regular expression indicating the resource.
     * @@param descrip A description of the resource.
     * @@return	      The database key of the newly added resource.
d234 11
a244 4
     * @@exception DBException
     */
    public Record addResource (String pattern, String descrip)
	throws DBException
d248 1
a248 1
            r = updateResource(null, pattern, descrip);
d250 1
a250 1
            //JDE is only be thrown when changing an existing resource.
d259 14
a272 12
     * @@param resourceID The database key of the resource to update, or 
     *                   <code>null</code> if the resource is new.
     * @@param pattern    A regular expression indicating the resource.
     * @@param descrip    A description of the resource.
     *
     * @@return           The resource record.
     *
     * @@exception DBException 
     */
    public Record updateResource (String resourceID, String pattern,
                                  String descrip)
	throws DBException
d280 1
a280 1
                resource = getResource(resourceID);
d301 1
a301 1
	catch (JoistDatabaseException e)
d303 4
a306 1
	    throw new DBException(e);
d308 1
a308 1
	catch (DataSetException e)
d310 4
a313 1
	    throw new DBException(e);
d315 1
a315 1
	catch (SQLException e)
d317 4
a320 1
	    throw new DBException(e);
d338 1
a338 1
	throws DBException
d350 3
a352 1
	    throw new DBException(e);
d354 3
a356 1
	    throw new DBException(e);
@


1.6
log
@partially converted
-dlr@@collab.net
@
text
@d64 1
a64 1
 * @@version $Id: ResourceManager.java,v 1.5 2001/01/24 20:42:46 dlr Exp $
@


1.5
log
@Making use of DBException.
@
text
@d64 1
a64 1
 * @@version $Id: ResourceManager.java,v 1.4 2000/12/11 19:46:10 leonardr Exp $
d109 1
a109 1
        super(dataMgr);
d113 1
a113 1
     *  Retrieves the name of a resource, given its ID.
d115 2
a116 3
     * @@param	connection    A JDBC database connection
     * @@param	resourceID       The resourceID to obtain 
     * @@return	 a String
d118 1
a118 1
    public String getResourceName (Connection connection, String resourceID)
d121 1
a121 2
        return getResource(connection, resourceID).getValue(RESOURCE_PATTERN)
            .asString();
d125 1
a125 1
     * Retrieves the record for a specified project.
d127 4
a130 5
     * @@param	connection    A JDBC database connection
     * @@param	resourceID       The resourceID to obtain 
     * @@return	 a String
     * @@exception	SQLException
     * @@exception	DataSetException
d132 2
a133 2
    public Record getResource (Connection connection, String resourceID)
	throws DBException
d135 1
a135 1
        DataSet resources = getResources(connection, resourceID, null);
d142 1
a142 1
            throw new DBException("No such resource: " + resourceID);
d147 1
a147 1
     * Retrieves the ID for a resource with known name
d149 4
a152 5
     * @@param	connection    A JDBC database connection
     * @@param	resourceName     The resource name to identify
     * @@return	 a String
     * @@exception	SQLException
     * @@exception	DataSetException
d154 2
a155 2
    public String getResourceID (Connection connection, String resourceName)
	throws DBException
d157 1
a157 1
        TableDataSet resources = getResources(connection,null,resourceName);
d164 1
a164 1
            throw new DBException("Invalid resource: " + resourceName);
d169 3
a171 1
     *  Retrieves a list of all the resources from the database.
d173 1
a173 4
     * @@param	connection    A JDBC database connection
     * @@return	 a DataSet
     * @@exception	SQLException
     * @@exception	DataSetException
d175 1
a175 1
    public DataSet listResources (Connection connection)
d178 1
a178 1
        return getResources(connection, null, null);
d182 5
a186 1
     *  Retrieves resources by resource ID or name.
d188 1
a188 6
     * @@param	connection    A JDBC database connection
     * @@param   resourceID       A resource ID (can be null)
     * @@ param  name          A resource name (can be null)
     * @@return	 a DataSet
     * @@exception	SQLException
     * @@exception	DataSetException
d190 1
a190 3
    private TableDataSet getResources(Connection connection,
                                      String resourceID,
                                      String name)
d193 2
a194 1
        TableDataSet resources = null;
d197 6
a202 18
            KeyDef kd = new KeyDef().addAttrib(RESOURCE_ID);
            resources = new TableDataSet(connection, TABLE_NAME, kd);
            resources.where(buildWhereClause(resourceID, name));
            resources.fetchRecords();
	}
	catch (DataSetException e)
	{
	    throw new DBException(e);
	}
	catch (SQLException e)
	{
	    throw new DBException(e);
	}
	finally
	{
	    registerToClose(resources);
	}
        return resources;
d206 1
a206 1
     * Adds a new resource to the database
d208 3
a210 4
     * @@param connection The JDBC database connection to use.
     * @@param name       A regular expression indicating the resource.
     * @@return	         The system-assigned resource ID for the newly added 
     *                   resource.
d214 1
a214 2
    public Record addResource (Connection connection, String pattern,
                               String description)
d219 1
a219 1
            r = updateResource(connection, null, pattern, description);
d230 4
a233 5
     * @@param connection     The JDBC database connection to use.
     * @@param resourceID    The database key of the resource to update, or 
     *                      <code>null</code> if the resource is new.
     * @@param pattern       A regular expression indicating the resource.
     * @@param description   A description of the resource.
d235 1
a235 1
     * @@return              The record for the resource.
d239 2
a240 2
    public Record updateResource (Connection connection, String resourceID, 
                                  String pattern, String description)
d249 1
a249 1
                resource = getResource(connection, resourceID);
@


1.4
log
@Support for updating resources.
@
text
@d64 1
a64 1
 * @@version $Id: ResourceManager.java,v 1.3 2000/12/07 18:26:08 leonardr Exp $
a117 2
     * @@exception	SQLException
     * @@exception	DataSetException
d120 1
a120 1
	throws SQLException, DataSetException, JoistDatabaseException
d136 1
a136 1
	throws SQLException, DataSetException, JoistDatabaseException
d145 1
a145 1
            throw new JoistDatabaseException("No such resource " + resourceID);
d159 1
a159 1
	throws SQLException, DataSetException, JoistDatabaseException
d168 1
a168 2
            throw new JoistDatabaseException("Invalid resource " + 
                                             resourceName);
d181 1
a181 1
	throws SQLException, DataSetException
d199 1
a199 1
        throws SQLException, DataSetException
d211 1
a211 3
	    log.exception(e);
	    if (debug) log.debug("Getting Resource: " + e.getMessage());
	    throw e;
d215 1
a215 3
	    log.exception(e);
	    if (debug) log.debug("Getting Resource: " + e.getMessage());
	    throw e;
d232 1
a232 2
     * @@exception	SQLException
     * @@exception	DataSetException
d236 1
a236 1
	throws SQLException, DataSetException
d242 1
a242 1
            //JDE can only be thrown when changing an existing resource.
d259 1
a259 2
     * @@exception	SQLException
     * @@exception DataSetException 
d262 2
a263 2
                                   String pattern, String description)
	throws SQLException, DataSetException, JoistDatabaseException
d292 4
d298 1
a298 4
	    log.exception(e);
	    String message = "Adding Resource: " + e.getMessage();
	    if (debug) log.debug(message);
	    throw e;
d302 1
a302 11
	    log.exception(e);
	    String message = "Adding Resource: " + e.getMessage();
	    if (debug) log.debug(message);
	    throw e;
	}
	catch (JoistDatabaseException e)
	{
	    log.exception(e);
	    String message = "Adding Resource: " + e.getMessage();
	    if (debug) log.debug(message);
	    throw e;
d320 1
a320 1
	throws SQLException, DataSetException
d332 1
a332 3
	    log.exception(e);
	    if (debug) log.debug("Deleting Resource: " + e.getMessage());
	    throw e;
d334 1
a334 3
	    log.exception(e);
	    if (debug) log.debug("Deleting Resource: " + e.getMessage());
	    throw e;
@


1.3
log
@New servlet - Resource Add
@
text
@d64 1
a64 1
 * @@version $Id: ResourceManager.java,v 1.2 2000/12/05 23:28:58 leonardr Exp $
d207 2
a208 1
            resources = new TableDataSet(connection, TABLE_NAME);
@


1.2
log
@Added a check so that business objects cannot be created with records from the wrong table. Also added some new business objects.
@
text
@d64 1
a64 1
 * @@version $Id: ResourceManager.java,v 1.1.1.1 2000/11/12 21:15:11 dlr Exp $
d241 2
a242 1
    public Integer addResource (Connection connection, String name)
d245 7
a251 1
        return updateResource(connection, null, name);
d258 1
a258 1
     * @@param connection The JDBC database connection to use.
d260 5
a264 3
     *                   <code>null</code> if the resource is new.
     * @@param name       A regular expression indicating the resource.
     * @@return	         The system-assigned resource ID for the resource updated.
d267 1
a267 1
     * @@exception	DataSetException
d269 3
a271 3
    public Integer updateResource (Connection connection, String resourceID, 
                                String name)
	throws SQLException, DataSetException
d273 1
a273 2
	Record resource = null;

d277 8
a284 10
            KeyDef kd = new KeyDef().addAttrib(RESOURCE_ID);
            resources = new TableDataSet(connection, TABLE_NAME, kd);
            resources.where(buildWhereClause(resourceID, name));

            // Do update.
            resources.fetchRecords();
	    if (resources.containsRecord(0)) 
	    {
                resource = resources.getRecord(0);
                if (name != null)
d286 1
a286 2
                    resource.setValue(RESOURCE_PATTERN, name);
                    resource.save();
d288 4
a291 3
	    }
            else
            {
d293 2
a294 1
                resource.setValue(RESOURCE_PATTERN, name);
d296 2
d314 7
d326 1
a326 1
	return new Integer(resource.getValue(RESOURCE_ID).asInt());
d341 8
a348 13
	{
	    resources = new TableDataSet(connection, TABLE_NAME);
	    resources.where(buildWhereClause(resourceID,null));
	    resources.fetchRecords();
	    if (resources.containsRecord(0)) 
	    {
                Record r = resources.getRecord(0);
                r.markToBeDeleted();
                r.save();
	    }
	}
	catch (DataSetException e)
	{
d352 1
a352 3
	}
	catch (SQLException e)
	{
d356 1
a356 3
	}
	finally
	{
@


1.1
log
@Initial revision
@
text
@d64 1
a64 1
 * @@version $Id: ResourceManager.java,v 1.9 2000/11/11 08:35:01 dlr Exp $
d113 1
a113 1
     *  Retrieves a named resource from the database.
d124 16
d143 1
a143 1
            return resources.getRecord(0).getValue(RESOURCE_PATTERN).asString();
@


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
@@
