head	1.8;
access;
symbols
	TIGRIS_0_8_4:1.7.0.4
	TIGRIS_NOV_12_2000:1.7
	OLDHELM:1.7.0.2
	TIGRIS_NOV_11_2000:1.7
	TIGRIS_BASELINE:1.7;
locks; strict;
comment	@# @;


1.8
date	2000.12.06.19.52.22;	author leonardr;	state dead;
branches;
next	1.7;

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

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

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

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

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

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

1.1
date	2000.09.26.00.20.00;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.8
log
@Begone unused classes that exist elsewhere
@
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 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.security;

import java.sql.*;

import com.workingdogs.village.*;

import org.joist.database.TableManager;
import org.joist.database.DataManager;

/**
 * This class performs associations between "base" versions of
 * database records and "composite" versions of those same records (a
 * boolean field in the table schema distringuishes between base and
 * composites). To use this class for a particular table, subclass it
 * and override its String properties.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: CompositeManager.java,v 1.7 2000/09/26 02:29:30 dlr Exp $
 */

abstract public class CompositeManager extends TableManager {

    protected String joinBaseField;
    protected String joinCompositeField;
    protected String unitTable;
    protected String joinTable;
    protected String isCompositeField;
    protected String idField;

    /** 
     * Constructor 
     */
    protected CompositeManager(DataManager dataMgr, String joinBaseField, 
                               String joinCompositeField, String unitTable, 
                               String joinTable, String isCompositeField, 
                               String idField) {
        super(dataMgr);

        this.joinBaseField = joinBaseField;
        this.joinCompositeField = joinCompositeField;
        this.unitTable = unitTable;
        this.joinTable = joinTable;
        this.isCompositeField = isCompositeField;
        this.idField = idField;
    }
    
    /**
     * Retrieve a list of composites.
     *
     * @@param connection A database connection
     * @@return a Dataset containing all the composite members of the unitTable.
     */
    public DataSet getComposites(Connection connection)
        throws SQLException, DataSetException {
    
        TableDataSet tds = new TableDataSet(connection, unitTable);
        tds.where(isCompositeField + " = 'Y'");
        return tds.fetchRecords();
    }

    /**
     * Retrieve a list of bases.
     *
     * @@param connection A database connection
     * @@return a Dataset containing all the base members of the unitTable.
     */
    public DataSet getBases(Connection connection)
        throws SQLException, DataSetException {
    
        TableDataSet tds = new TableDataSet(connection, unitTable);
        tds.where(isCompositeField + " = 'N'");
        return tds.fetchRecords();
    }

    /**
     * Associate a base with a composite. Does not yet check to make
     * sure the composite is indeed composite. Should there be a
     * special exception for this?
     *
     * @@param connection A database connection
     * @@param baseID The base ID to add to the composite
     * @@param compositeID The composite ID to add to.
     *
     * @@exception SQLException if there is a database error
     * @@exception DataSetException if something goes wrong with the DataSet.
     */
    public void addBaseToComposite(Connection connection, String baseID, 
                                   String compositeID)
        throws SQLException, DataSetException {
    
        TableDataSet tds = new TableDataSet(connection, joinTable);
        tds.where(joinBaseField + " = " + baseID + " AND " + 
                  joinCompositeField + " = " + compositeID);
        if (!tds.fetchRecords().containsRecord(0)) {
            Record r = tds.addRecord();
            r.setValue(joinBaseField,baseID);
            r.setValue(joinCompositeField,compositeID);
            r.save();
        }
    }

    /**
     * Disassociate a base from a composite.
     *
     * @@param connection A database connection
     * @@param baseID The base ID to remove from the composite
     * @@param compositeID The composite ID from which to remove the base
     *
     * @@exception SQLException if there is a database error
     * @@exception DataSetException if something goes wrong with the DataSet.
     */
    public void removeBaseFromComposite(Connection connection, String baseID, 
                                        String compositeID)
        throws SQLException, DataSetException {
    
        TableDataSet tds = new TableDataSet(connection, joinTable);
        tds.where(joinBaseField + " = " + baseID + " AND " + 
                  joinCompositeField + " = " + compositeID);
        DataSet d = tds.fetchRecords();
        if (d.containsRecord(0)) {
            Record r = d.getRecord(0);
            r.markToBeDeleted();
            r.save();
        }
    }
}
@


1.7
log
@Obliterated evil tab characters.  No other change.
@
text
@d66 1
a66 1
 * @@version $Id: CompositeManager.java,v 1.6 2000/09/26 02:24:34 dlr Exp $
@


1.6
log
@Renamed xxxset to xxxSet.  Going to move the files in the repository to preserve history.
@
text
@d66 1
a66 1
 * @@version $Id: CompositeManager.java,v 1.5 2000/09/26 01:28:41 dlr Exp $
d85 1
a85 1
	super(dataMgr);
d102 5
a106 5
	throws SQLException, DataSetException {
	
	TableDataSet tds = new TableDataSet(connection, unitTable);
	tds.where(isCompositeField + " = 'Y'");
	return tds.fetchRecords();
d116 5
a120 5
	throws SQLException, DataSetException {
	
	TableDataSet tds = new TableDataSet(connection, unitTable);
	tds.where(isCompositeField + " = 'N'");
	return tds.fetchRecords();
d137 11
a147 11
	throws SQLException, DataSetException {
	
	TableDataSet tds = new TableDataSet(connection, joinTable);
	tds.where(joinBaseField + " = " + baseID + " AND " + 
		  joinCompositeField + " = " + compositeID);
	if (!tds.fetchRecords().containsRecord(0)) {
	    Record r = tds.addRecord();
	    r.setValue(joinBaseField,baseID);
	    r.setValue(joinCompositeField,compositeID);
	    r.save();
	}
d162 11
a172 11
	throws SQLException, DataSetException {
	
	TableDataSet tds = new TableDataSet(connection, joinTable);
	tds.where(joinBaseField + " = " + baseID + " AND " + 
		  joinCompositeField + " = " + compositeID);
	DataSet d = tds.fetchRecords();
	if (d.containsRecord(0)) {
	    Record r = d.getRecord(0);
	    r.markToBeDeleted();
	    r.save();
	}
@


1.5
log
@Added myself and Leonard to headers.
@
text
@d66 1
a66 1
 * @@version $Id: CompositeManager.java,v 1.4 2000/09/26 01:20:02 dlr Exp $
d174 1
a174 3
    
} /* end class ModuleManager */

@


1.4
log
@Updated class members.
@
text
@d65 2
a66 1
 * @@version $Id: $
@


1.3
log
@Made CompositeManager abstract and added its subclasses. Defanged
UsersetTest until the database is brought into line with CompositeManager.
@
text
@d63 3
d70 6
a75 8
    private static final String unitTable = "";
    private static final String joinTable = "";

    private static final String joinBaseField = "base";
    private static final String joinCompositeField = "composite";

    private static final String isCompositeField = "isComposite";
    private static final String idField = "id";
d80 4
a83 1
    public CompositeManager(DataManager dataMgr) {
d85 7
d100 1
a100 1
    public static DataSet getComposites(Connection connection)
d104 1
a104 1
	tds.where(isCompositeField + " = true");
d114 1
a114 1
    public static DataSet getBases(Connection connection)
d118 1
a118 1
	tds.where(isCompositeField + " = false");
d132 4
a135 3
     * @@exception DataSetException if something goes wrong with the DataSet.  */
    public static void addBaseToComposite(Connection connection, String baseID, 
					  String compositeID)			
d159 2
a160 2
    public static void removeBaseFromComposite(Connection connection, String baseID, 
					       String compositeID)			
@


1.2
log
@Actually compiles now. :)
@
text
@d65 1
a65 1
public class CompositeManager extends TableManager {
d67 2
a68 1
    private static String unitTable;
a69 1
    private static String joinTable;
d73 2
a74 2
    private static String isCompositeField;
    private static String idField;
@


1.1
log
@New file to manage via a join table the associations between another
table and itself, when that table contains both base elements and
composite elemensts associated many-to-many with base elements, and a
base element is distinguished from a composite by a boolean
field. Examples: the proposed user table and the proposed project table.
@
text
@d48 1
a48 1
package org.tigris.helm.database;
a49 6
import org.webmacro.servlet.*;
import org.webmacro.engine.*;
import org.webmacro.broker.*;

import javax.servlet.*;
import javax.servlet.http.*;
a53 1
import org.joist.util.*;
d73 1
a73 1
    private static String compositeIndicatorField;
d79 1
a79 1
    public SetManager(DataManager dataMgr) {
d93 1
a93 1
	tds.where(compositeField + " = true");
d107 1
a107 1
	tds.where(compositeField + " = false");
d127 1
a127 1
	tds.where(joinBaseField + " = " baseID + " AND " + 
d152 1
a152 1
	tds.where(joinBaseField + " = " baseID + " AND " + 
d154 1
a154 1
	Dataset d = tds.fetchRecords();
@

