head	1.7;
access;
symbols;
locks; strict;
comment	@# @;


1.7
date	2001.05.30.01.11.11;	author leonardr;	state dead;
branches;
next	1.6;

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

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

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

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

1.2
date	2001.05.17.00.57.06;	author lucas;	state Exp;
branches;
next	1.1;

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


desc
@@


1.7
log
@Got rid of denormalized project-project group mapping table in favor of per-JVM caching solution.
@
text
@package org.tigris.helm.om;

import java.util.*;

import com.workingdogs.village.*;

import org.apache.turbine.om.*;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.ObjectUtils;
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.db.pool.DBConnection;

import org.tigris.helm.om.*;
import org.tigris.helm.tool.*;

/** 
 * Sets up and controls the denormalized project group mapping table.
 */
public class DenormalizedProjectProjectgroupPeer
    extends BaseDenormalizedProjectProjectgroupPeer
{

    /**
     * Safely replace the current denormalized project group mappings
     * with new mappings.  
     */
    public static void replaceMappings(Map publicMappings, Map privateMappings)
        throws Exception
    {
        boolean[] publicValues = {true, false};
        Map[] mappingStructs = {publicMappings, privateMappings};

        StringBuffer insert = new StringBuffer
            ("insert into " + TABLE_NAME + " values ");

        boolean prependComma = false;
        for (int i = 0; i <= 1; i++)
        {
            Set parents = mappingStructs[i].keySet();
            for (Iterator j = parents.iterator(); j.hasNext();)
            {
                Project parent = (Project)j.next();
                List children = (List)mappingStructs[i].get(parent);
                for (Iterator k = children.iterator(); k.hasNext();)
                {
                    Project child = (Project)k.next();

                    if (prependComma)
                    {
                        insert.append(",");
                    }
                    else
                    {
                        prependComma = true;
                    }
                
                    insert.append('(').append(parent.getID()).append(',')
                        .append(child.getID()).append(',')
                        .append('"').append(DBFlag.flagValueOf
                                            (publicValues[i]))
                        .append('"').append(')');
                }
            }
        }

        String[] tablesToLockRead = {};
        String[] tablesToLockWrite = {TABLE_NAME};

        Log.debug("Final query: " + insert.toString());

        DBConnection conn = lockTables(tablesToLockRead, tablesToLockWrite);
        executeStatement("delete from " + TABLE_NAME, conn);
        if (mappingStructs[0].size() > 0 || mappingStructs[1].size() > 0)
        {
            executeStatement(insert.toString(), conn);
        }        
        unlockTables(conn);        
        uncache(DenormalizedProjectProjectgroupPeer.class);
    }


    /**
     * Returns the number of items in this table.
     */
    public static int itemsInTable()
        throws Exception
    {
        String query = "select count(*) from " + TABLE_NAME;
        Vector results = executeQuery(query);
        Record r = (Record)results.get(0);
        return r.getValue(1).asInt();
    }

}
@


1.6
log
@Rebuilding of denormalized table should generate cluster events, and the ACL cache should be interested in such events.
@
text
@@


1.5
log
@Ported Helm from WebMacro to Velocity.
@
text
@d80 3
a82 2
        }
        unlockTables(conn);
@


1.4
log
@Fixed bug which was causing denormalized table to look a lot like the undenormalized table.
@
text
@d13 2
@


1.3
log
@Bug fixes for clustering.
@
text
@d29 1
a29 1
    public static void replaceMappings(Map mappings)
d32 3
a37 2
        Set keys = mappings.keySet();

d39 1
a39 1
        for (Iterator i = keys.iterator(); i.hasNext();)
d41 2
a42 7
            List key = (List)i.next();
            Project parent = (Project)key.get(0);
            Project child = (Project)key.get(1);

            Boolean publicPath = (Boolean)mappings.get(key);

            if (prependComma)
d44 21
a64 1
                insert.append(",");
a65 10
            else
            {
                prependComma = true;
            }
                
            insert.append('(').append(parent.getID()).append(',')
                .append(child.getID()).append(',')
                .append('"').append(DBFlag.flagValueOf
                                     (publicPath.booleanValue()))
                .append('"').append(')');
d71 2
d75 1
a75 1
        if (keys.size() > 0)
@


1.2
log
@executeStatement only uses two parameters now
@
text
@d4 2
a5 1
import java.rmi.RemoteException;
d73 14
@


1.1
log
@A Heartbreaking Patch of Staggering Genius: adds capacity (but no interface) for deeply nested projects, categories, and project groups. As a side effect, gets rid of the hacky special 'all public projects in domain' group. There are probably bugs in this, and some of those bugs are probably security holes, so watch out.
@
text
@d65 1
a65 1
        executeStatement("delete from " + TABLE_NAME, DATABASE_NAME, conn);
d68 1
a68 1
            executeStatement(insert.toString(), DATABASE_NAME, conn);
@

