/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sikd.ikonsol.ejb.dao;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import sikd.ikonsol.model.HeaderDataKonsolidasi;
import sikd.ikonsol.model.RawData;
import sikd.ikonsol.model.RawDataLak;
import sikd.ikonsol.model.RawDataLpe;
import sikd.ikonsol.model.RawDataLpsal;

/**
 *
 * @author Imam Bhoim
 */
public class HeaderDataKonsolidasiDao implements IDAO<HeaderDataKonsolidasi>, Serializable {

    private SqlSessionFactory sqlSessionFactory = null;
    private SqlSession session = null;

    public HeaderDataKonsolidasiDao(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public HeaderDataKonsolidasi createNew() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<HeaderDataKonsolidasi> findAll() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        List<HeaderDataKonsolidasi> list = new ArrayList<HeaderDataKonsolidasi>();

        session = sqlSessionFactory.openSession();
        try {
            list = session.selectList("HeaderDataKonsolidasiMapper.selectAll");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return list;
    }

    @Override
    public List<HeaderDataKonsolidasi> findByCriteria(String sql) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public HeaderDataKonsolidasi findByID(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        HeaderDataKonsolidasi obj = null;
        try {
            obj = session.selectOne("HeaderDataKonsolidasiMapper.selectId", id);

        } finally {
            session.close();
        }
        return obj;
    }

    @Override
    public HeaderDataKonsolidasi findByKode(String kode) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public HeaderDataKonsolidasi save(HeaderDataKonsolidasi obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.insertOne", obj);
        session.commit();
        session.close();
        return obj;
    }

    @Override
    public HeaderDataKonsolidasi update(HeaderDataKonsolidasi obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.updateOne", obj);
        session.commit();
        session.close();
        return obj;
    }

    @Override
    public void deleteByID(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteOne", id);
        session.commit();
        session.close();

    }

    @Override
    public void deleteByPK(String pk) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    // raw data function
    public RawData saveImportRawdata(RawData obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.insertImportRawdata", obj);
        session.commit();
        session.close();
        return obj;
    }

    public RawData saveImportRawdataUpdate(RawData obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.insertImportRawdataTemp", obj);
        session.commit();
        session.close();
        return obj;
    }

    public List<HeaderDataKonsolidasi> findAllByPemdaCount(int header) {
        Map<String, Object> map = new HashMap<>();
        map.put("header", header);
        List<HeaderDataKonsolidasi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("HeaderDataKonsolidasiMapper.selectCountPemda", map);

        } finally {
            session.close();
        }
        return list;
    }

    public RawDataLak saveImportRawdataLak(RawDataLak obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.insertImportRawdataLak", obj);
        session.commit();
        session.close();
        return obj;
    }

    public RawDataLpe saveImportRawdataLpe(RawDataLpe obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.insertImportRawdataLpe", obj);
        session.commit();
        session.close();
        return obj;
    }

    public RawDataLpsal saveImportRawdataLpsal(RawDataLpsal obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.insertImportRawdataLpsal", obj);
        session.commit();
        session.close();
        return obj;
    }

    public List<HeaderDataKonsolidasi> findAllByPemdaCountLak(int header) {
        Map<String, Object> map = new HashMap<>();
        map.put("header", header);
        List<HeaderDataKonsolidasi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("HeaderDataKonsolidasiMapper.selectCountPemdaLak", map);

        } finally {
            session.close();
        }
        return list;
    }

    public List<HeaderDataKonsolidasi> findAllByPemdaCountLpe(int header) {
        Map<String, Object> map = new HashMap<>();
        map.put("header", header);
        List<HeaderDataKonsolidasi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("HeaderDataKonsolidasiMapper.selectCountPemdaLpe", map);

        } finally {
            session.close();
        }
        return list;
    }

    public List<HeaderDataKonsolidasi> findAllByPemdaCountLpsal(int header) {
        Map<String, Object> map = new HashMap<>();
        map.put("header", header);
        List<HeaderDataKonsolidasi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("HeaderDataKonsolidasiMapper.selectCountPemdaLpsal", map);

        } finally {
            session.close();
        }
        return list;
    }

    public HeaderDataKonsolidasi copyData(HeaderDataKonsolidasi obj) {

        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.copyData", obj);
        session.commit();
        session.close();
        return obj;
    }

    public List<HeaderDataKonsolidasi> findKdpemda() {

        List<HeaderDataKonsolidasi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("HeaderDataKonsolidasiMapper.selectKdPemda");

        } finally {
            session.close();
        }
        return list;
    }

    public List<HeaderDataKonsolidasi> findKdpemdaLak() {

        List<HeaderDataKonsolidasi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("HeaderDataKonsolidasiMapper.selectKdPemdaLak");

        } finally {
            session.close();
        }
        return list;
    }

    public List<HeaderDataKonsolidasi> findKdpemdaLpe() {

        List<HeaderDataKonsolidasi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("HeaderDataKonsolidasiMapper.selectKdPemdaLpe");

        } finally {
            session.close();
        }
        return list;
    }

    public List<HeaderDataKonsolidasi> findKdpemdaLpsal() {

        List<HeaderDataKonsolidasi> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("HeaderDataKonsolidasiMapper.selectKdPemdaLpsal");

        } finally {
            session.close();
        }
        return list;
    }

    public void deleteData(String kdpemda, int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Map<String, Object> map = new HashMap<>();
        map.put("kdpemda", kdpemda);
        map.put("idheader", id);
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteOneData", map);
        session.commit();
        session.close();

    }

    public void deleteRawTemp() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteRawTemp");
        session.commit();
        session.close();

    }

    public RawDataLak saveImportRawdataLakUpdate(RawDataLak obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.insertImportRawdataLakUpdate", obj);
        session.commit();
        session.close();
        return obj;
    }

    public void deleteDataLak(String kdpemda, int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Map<String, Object> map = new HashMap<>();
        map.put("kdpemda", kdpemda);
        map.put("idheader", id);
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteOneDataLak", map);
        session.commit();
        session.close();

    }

    public void deleteRawLakTemp() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteRawLakTemp");
        session.commit();
        session.close();

    }

    public RawDataLpe saveImportRawdataLpeUpdate(RawDataLpe obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.insertImportRawdataLpeUpdate", obj);
        session.commit();
        session.close();
        return obj;
    }

    public void deleteDataLpe(String kdpemda, int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Map<String, Object> map = new HashMap<>();
        map.put("kdpemda", kdpemda);
        map.put("idheader", id);
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteOneDataLpe", map);
        session.commit();
        session.close();

    }

    public void deleteRawLpeTemp() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteRawLpeTemp");
        session.commit();
        session.close();

    }

    public RawDataLpsal saveImportRawdataLpsalUpdate(RawDataLpsal obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.insertImportRawdataLpsalUpdate", obj);
        session.commit();
        session.close();
        return obj;
    }

    public void deleteDataLpsal(String kdpemda, int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Map<String, Object> map = new HashMap<>();
        map.put("kdpemda", kdpemda);
        map.put("idheader", id);
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteOneDataLpsal", map);
        session.commit();
        session.close();

    }

    public void deleteRawLpsalTemp() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteRawLpsalTemp");
        session.commit();
        session.close();

    }


    public void deleteByIDRawDataLRANeracaLO(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteByIDRawDataLRANeracaLO", id);
        session.commit();
        session.close();

    }


    public void deleteByIDRawDataLak(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteByIDRawDataLak", id);
        session.commit();
        session.close();

    }

    public void deleteByIDRawDataLpe(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteByIDRawDataLpe", id);
        session.commit();
        session.close();

    }

    public void deleteByIDRawDataLpsal(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("HeaderDataKonsolidasiMapper.deleteByIDRawDataLpsal", id);
        session.commit();
        session.close();

    }

}
