/*
 * 
 * Created on Jun 9, 2005
 * 
 * György Süveges
 * Etixpert Kft.
 * Copyright(c) 2005
 * 
 */
package com.etixpert.evolution.workflow;

import org.hibernate.*;
import com.etixpert.evolution.*;
import com.etixpert.evolution.gui.servlets.*;
import java.sql.*;
import java.util.*;
/**
 * @author Suveges Gyorgy
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class DefaultWorkflow extends Workflow {

    /**
     * @param orders
     * @param statusFrom
     * @param statusTo
     */
    public DefaultWorkflow(int statusFrom, int statusTo) {
        super(statusFrom, statusTo);
        // TODO Auto-generated constructor stub
    }

    /* (non-Javadoc)
     * @see com.etixpert.evolution.workflow.Workflow#before()
     */
    protected void before(Connection conn, Set orders) throws Exception {
       return;

    }

    protected void changeStatus(Connection conn, Set orders) throws Exception {
        changeStatus(conn, orders, statusFrom, statusTo);
    
    }
    /* (non-Javadoc)
     * @see com.etixpert.evolution.workflow.Workflow#changeStatus()
     */
    
    
    protected void changeStatus(Connection conn, Set orders, int statusFrom, int statusTo) throws Exception {
        if (orders.size()==0) return;
        
        Statement stat = conn.createStatement();
        String sql = "update order_header set order_status_id = "+statusTo+
			" where order_status_id =" +statusFrom+" AND id in "+Tools.idsToSql(orders, false);
		logger.info("Changing status of orders from "+statusFrom+" to "+statusTo+ ": "+sql);
        int changed = stat.executeUpdate(sql);
        logger.info("Orders changed: "+changed);
        stat.close();
        
     
    }

    /* (non-Javadoc)
     * @see com.etixpert.evolution.workflow.Workflow#after()
     */
    protected void after(Connection conn, Set orders) throws Exception {
      return;

    }
    
    

}
