/*
 * Copyright
 *  2010 axYus - http://www.axyus.com
 *  2010 C.Marchand - christophe.marchand@axyus.com
 *
 * This file is part of XEMELIOS_NB.
 *
 * XEMELIOS_NB is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * XEMELIOS_NB is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with XEMELIOS_NB; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 */


package fr.gouv.finances.dgfip.xemelios.batch.exports;

import fr.gouv.finances.dgfip.xemelios.batch.Batch;
import fr.gouv.finances.dgfip.xemelios.data.impl.pool.PoolManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Types;
import org.apache.log4j.Logger;

/**
 * Initialise les exports qui étaient en cours lors de l'arrêt des batchs
 * @author cmarchand
 */
public class ExportInitiator extends Batch {
    private static final Logger logger = Logger.getLogger(ExportInitiator.class);

    public ExportInitiator(String args[]) {
        super(args);
    }

    @Override
    protected void initialize() throws Exception {
        super.initialize();
    }

    @Override
    protected void doProcess() throws Exception {
        logger.info("Running ExportInitiator");
        Connection con = null;
        try {
            con = PoolManager.getInstance().getConnection();
            PreparedStatement ps = con.prepareStatement("UPDATE EXPORT_JOBS SET STATUS=1, RUN_DATE=? WHERE STATUS=2");
            ps.setNull(1, Types.DATE);
            ps.executeUpdate();
        } catch(Exception ex) {
            logger.error(ex);
        } finally {
            if(con!=null) PoolManager.getInstance().releaseConnection(con);
        }
    }

    @Override
    public String getResumeTraitement() {
        return null;
    }

    @Override
    public String typeTraitementRefCode() {
        return "Export initiator";
    }

    @Override
    public String getInformations() {
        return null;
    }

    @Override
    protected String getBatchVersion() {
        return "1";
    }



}
