/*
 * Struts ActionのベースとなるDB入出力を伴うクラス。
 * ※このクラスはblancoStrutsの自動生成の対象ではありません。
 * @since 2005/03/21
 */
package blanco.struts.action;

import java.sql.Connection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * blancoStruts <br>
 * Struts ActionのベースとなるDB入出力を伴うクラス。 <br>
 * ※このクラスはblancoStrutsの自動生成の対象ではありません。
 * 
 * @since 2005/03/21
 * @author HiromuUchibayashi
 */
public abstract class AbstractDbAction extends AbstractBaseAction {

    public abstract ActionForward executeDbAction(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response, Connection conn) throws Exception;

    public final ActionForward executeAction(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        ActionForward forward = null;
        // BlancoActionForm actionForm = (BlancoActionForm) form;
        ActionForm actionForm = form;
        Connection conn = null;

        try {
            // TODO: ここでConnectionを取得する
            conn = null; // 本来はここでConnectionを渡す。
            forward = executeDbAction(mapping, actionForm, request, response,
                    conn);
        } finally {
            if (conn != null) {
                try {
                    conn.rollback();
                } finally {
                    conn.close();
                    conn = null;
                }
            }
        }

        return forward;
    }
}