001package com.identityworksllc.iiq.common.task.export;
002
003import org.apache.commons.logging.Log;
004import sailpoint.api.SailPointContext;
005import sailpoint.tools.GeneralException;
006
007import java.sql.Connection;
008import java.sql.PreparedStatement;
009import java.sql.SQLException;
010
011/**
012 * Finishes the export by removing the previous run record and adding the new one, with
013 * the latest export date
014 */
015public class ExportFinishPartition extends ExportPartition {
016    private String configHash;
017
018    @Override
019    protected void export(SailPointContext context, Connection connection, Log logger) throws GeneralException {
020        try (PreparedStatement delete = connection.prepareStatement("delete from de_runs"); PreparedStatement insert = connection.prepareStatement("insert into de_runs ( last_start_time, config_hash ) values ( ? )")) {
021            delete.executeUpdate();
022            insert.setLong(1, exportTimestamp);
023            insert.setString(2, configHash);
024            insert.executeUpdate();
025
026            connection.commit();
027        } catch(SQLException e) {
028            throw new GeneralException(e);
029        }
030    }
031
032    /**
033     * Sets the config hash
034     * @param configHash
035     */
036    public void setConfigHash(String configHash) {
037        this.configHash = configHash;
038    }
039}