head	1.12;
access;
symbols
	TIGRIS_1_1_0RC2:1.9.2.1
	TIGRIS_1_1_0RC1:1.9.2.1
	TIGRIS_1_1:1.9.2.1.0.2
	TIGRIS_1_0_8:1.9.2.1
	TIGRIS_1_0_8RC3:1.9.2.1
	TIGRIS_1_0_8RC2:1.9.2.1
	TIGRIS_1_0_8RC1:1.9.2.1
	TIGRIS_1_0_7:1.9.2.1
	TIGRIS_1_0_7RC3:1.9.2.1
	TIGRIS_1_0_7RC2:1.9.2.1
	TIGRIS_1_0_7RC1:1.9.2.1
	TIGRIS_1_0_6:1.9.2.1
	TIGRIS_1_0_6RC5:1.9.2.1
	TIGRIS_1_0_6RC4:1.9.2.1
	TIGRIS_1_0_6RC3:1.9.2.1
	TIGRIS_1_0_6RC2:1.9.2.1
	TIGRIS_1_0_6RC1:1.9.2.1
	TIGRIS_1_0:1.9.0.2;
locks; strict;
comment	@# @;


1.12
date	2001.08.03.02.40.12;	author dlr;	state dead;
branches;
next	1.11;

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

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

1.9
date	2001.06.01.17.35.57;	author leonardr;	state Exp;
branches
	1.9.2.1;
next	1.8;

1.8
date	2001.06.01.17.00.41;	author leonardr;	state Exp;
branches;
next	1.7;

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

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

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

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

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

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

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

1.9.2.1
date	2001.06.01.19.18.07;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.12
log
@Deprecated by Spread.
@
text
@/* ================================================================
 * Copyright (c) 2001 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.om;

import java.util.*;

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.db.pool.DBConnection;

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

/** 
 * 
 */
public class ClusterEventPeer extends BaseClusterEventPeer
{

    public static ClusterEvent retrieveInstance(String type, String descriptor,
                                                DBConnection conn)
        throws Exception
    {
        ClusterEvent event = null;
        Criteria c = new Criteria().add(TYPE, type).add(DESCRIPTOR, descriptor);
        List events = null;
        if (conn == null)
        {
            events = doSelect(c);
        }
        else
        {
            events = doSelect(c, conn);
        }
        if (events.size() > 0)
        {
            event = (ClusterEvent)events.get(0);
        }
        else
        {
            event = new ClusterEvent();
            event.setType(type);
            event.setDescriptor(descriptor);
        }
        return event;
    }

    /**
     * Gets all events pertaining to the specified type, in ascending order
     * of timestamp.
     */
    public static List getInstances(String type)
        throws Exception
    {
        Criteria c = new Criteria(1).add(TYPE, type)
            .addAscendingOrderByColumn(STAMP)
            .addAscendingOrderByColumn(DESCRIPTOR);
        return doSelect(c);
    }

    /**
     * Deletes an event.
     */    
    public static void deleteInstance(String type, String descriptor)
        throws Exception
    {
        Criteria c = new Criteria(2)
            .add(TYPE, type).add(DESCRIPTOR, descriptor);
        doDelete(c);
    }

    /**
     * Adds a series of events of the same type. Will not overwrite
     * existing entries.
     */
    public static void addEvents(String type, String[] descriptors)
        throws Exception
    {
        StringBuffer q = new StringBuffer();
        
        String[] readTables = {};
        String[] writeTables = {TABLE_NAME};
        DBConnection conn = lockTables(readTables, writeTables);

        try
        {
            Criteria c = new Criteria(2).addIn(DESCRIPTOR, descriptors)
                .add(TYPE, type);
            List existingEvents = doSelect(c, conn);
            List existingDescriptors = new ArrayList(existingEvents.size());
            for (Iterator i = existingEvents.iterator(); i.hasNext();)
            {
                ClusterEvent e = (ClusterEvent)i.next();
                existingDescriptors.add(e.getDescriptor().toString());
            }
            
            for (int i = 0; i < descriptors.length; i++)
            {
                String descriptor = descriptors[i];
                if (!existingDescriptors.contains(descriptor))
                {
                    ClusterEvent e = new ClusterEvent();
                    e.setType(type);
                    e.setDescriptor(descriptor);
                    e.save(conn);
                }
            }
        }
        finally
        {
            unlockTables(conn);
        }
    }
}
@


1.11
log
@Made generated SQL database-independant, for 'database-independant' == 'works on both MySQL and Oracle'
@
text
@@


1.10
log
@More action cleanup, and reinstated Domain - View action because it turns out to have been in use after all.
@
text
@a49 1
import java.rmi.RemoteException;
d121 2
a122 1
     * Adds a series of events of the same type.
a127 6

        q.append("insert ");
        if (!isOracle())
        {
            q.append("ignore ");
        }
d129 11
a139 8
        q.append("into HELM_CLUSTER_EVENT select '")
            .append(type).append("', PROJECT_ID, ").append(getNowFunction())
            .append("from HELM_PROJECT where PROJECT_ID in (");

        boolean executable = false;
        for (int i = 0; i < descriptors.length; i++)
        {
            if (executable)
d141 2
a142 1
                q.append(',');
d144 2
a145 1
            else
d147 8
a154 1
                executable = true;
d156 2
a157 5
            q.append(descriptors[i]);
        }            
        q.append(')');

        if (executable)
d159 1
a159 2
            Log.debug("About to execute " + q);
            executeStatement(q.toString());
@


1.9
log
@Got rid of compile error.
@
text
@d127 12
a138 3
        StringBuffer q = new StringBuffer()
            .append("insert ignore into ").append(TABLE_NAME)
            .append(" values ");
d150 4
a153 4
            q.append("(\"").append(type).append("\",\"")
                .append(descriptors[i])
                .append("\",NOW()").append(')');
        }
@


1.9.2.1
log
@Ported minimal cluster functionality so that I could also port IssueTrackingRebuildService, which builds on it.
@
text
@d105 2
a106 2
            .addOrderByColumn(STAMP)
            .addOrderByColumn(DESCRIPTOR);
d147 1
@


1.8
log
@Order by descriptor if two items have the same stamp.
@
text
@d105 1
a105 1
            .addAscendingOrderByColumn(STAMP);
@


1.7
log
@Reformatting.
@
text
@d106 1
@


1.6
log
@Filtering out the singleton is unneccessary.
@
text
@d104 1
a104 2
        Criteria c = new Criteria(1)
            .add(TYPE, type)
@


1.5
log
@"insert ignore" allows us to avoid race conditions and extra DB hits here
@
text
@d101 1
a101 1
    public static List getNonSingletonInstances(String type)
d104 1
a104 1
        Criteria c = new Criteria(2)
a105 3
            .add(DESCRIPTOR, 
                 (Object)ClusteredSingletonService.SINGLETON_EVENT_TYPE,
                 Criteria.NOT_EQUAL)
@


1.4
log
@Factored out script running code to support new IssueTrackingRebuildService.
@
text
@a129 14
        //First filter out any projects with pending requests, so as not
        //to zero out their age and thus ensure that they get processed
        //later.
        Criteria c = new Criteria(2)
            .add(TYPE, type).addIn(DESCRIPTOR, descriptors);
        List matches = doSelect(c);
        List matchingDescriptors = new ArrayList(matches.size());
        for (Iterator i = matches.iterator(); i.hasNext();)
        {
            ClusterEvent e = (ClusterEvent)i.next();
            String descriptor = e.getDescriptor().toString();
            matchingDescriptors.add(descriptor);
        }

d131 2
a132 2
            .append("insert into ").append(TABLE_NAME).append(" values ");
        boolean comma = false;
d136 5
a140 1
            if (!matchingDescriptors.contains(descriptors[i]))
a142 11
                if (comma)
                {
                    q.append(',');
                }
                else
                {
                    comma = true;
                }
                q.append("(\"").append(type).append("\",\"")
                    .append(descriptors[i])
                    .append("\",NOW()").append(')');
d144 3
@


1.3
log
@Fixed up cluster singleton interface and made the task runner into a cluster singleton.
@
text
@d61 1
a61 1
import org.tigris.helm.tool.*;
d97 19
d119 2
a120 1
        Criteria c = new Criteria().add(TYPE, type).add(DESCRIPTOR, descriptor);
d124 48
@


1.2
log
@Changed field name to avoid using reserved word.
@
text
@d69 2
a70 1
    public static ClusterEvent retrieveInstance(String type, String descriptor)
d75 9
a83 1
        List events = doSelect(c);
@


1.1
log
@Changed timestamp table to cluster event table.
@
text
@d69 1
a69 1
    public static ClusterEvent retrieveInstance(String type, String key)
d73 1
a73 1
        Criteria c = new Criteria().add(TYPE, type).add(KEY, key);
d83 1
a83 1
            event.setKey(key);
d88 1
a88 1
    public static void deleteInstance(String type, String key)
d91 1
a91 1
        Criteria c = new Criteria().add(TYPE, type).add(KEY, key);
@

