/*
 * 
 * Created on Jul 15, 2005
 * 
 * György Süveges
 * Etixpert Kft.
 * Copyright(c) 2005
 * 
 */
package com.etixpert.evolution.gui.servlets.pageactions;

import javax.servlet.http.*;
import org.hibernate.*;
import java.sql.*;
import com.etixpert.evolution.gui.servlets.*;
import com.etixpert.evolution.*;

/**
 * @author Suveges Gyorgy
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class del_abo extends PageActionHandler {

    /**
     * 
     */
    public del_abo() {
        super();
        // TODO Auto-generated constructor stub
    }

    /* (non-Javadoc)
     * @see com.etixpert.evolution.gui.servlets.pageactions.PageActionHandler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    protected void handle(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        String prefix = AboHelper.getPrefix(request);
        HttpSession session = request.getSession();
        session.removeAttribute(prefix+"detail_abo.jsp");
        //PageActionHandler.changeBooleanValues(request, (java.util.Map) session.getAttribute(details), "subscription");
        Transaction tx = null;
        try {
            Session hsession = HibernateUtil.currentSession();
            tx = hsession.beginTransaction();
            Connection conn = hsession.connection();
            String[] values = request.getParameterValues("del");
            logger.info("Deleting "+values.length+" abos");
            PreparedStatement ps = conn.prepareStatement("delete from subscription_header where id= ?");
            for (int i=0; i<values.length; i++) {
                ps.setInt(1, new Integer(values[i]).intValue());
                ps.executeUpdate();
            }
            ps.close();
            
            tx.commit();
        } catch (Exception e) {
            if (tx!=null)
                tx.rollback();
            throw e;
        }
    }

}
