/*
 * 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();

    }
    
      public HeaderDataKonsolidasi findCountData(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.selectCountRawData", id);

        } finally {
            session.close();
        }
        return obj;
    }
      
       public HeaderDataKonsolidasi findCountDataLak(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.selectCountRawDataLak", id);

        } finally {
            session.close();
        }
        return obj;
    }
      
       
        public HeaderDataKonsolidasi findCountDataLpe(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.selectCountRawDataLpe", id);

        } finally {
            session.close();
        }
        return obj;
    }
      
        
         public HeaderDataKonsolidasi findCountDataLpsal(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.selectCountRawDataLpsal", id);

        } finally {
            session.close();
        }
        return obj;
    }
      
      
      
    public HeaderDataKonsolidasi findAllByPemdaCount() { 
     //   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.selectCountByPemdaCount");

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

    public HeaderDataKonsolidasi updateDW(HeaderDataKonsolidasi obj) {
    
        session = sqlSessionFactory.openSession();
        session.update("HeaderDataKonsolidasiMapper.updateOneDw", obj);
        session.commit();
        session.close();
        return obj;
    }
     
  public HeaderDataKonsolidasi findByThnIdlapKdper(int thn, int idlap, String kdper) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
         Map<String, Object> map = new HashMap<>();
        map.put("tahun", thn);
        map.put("idlap", idlap);
        map.put("kdPeriode", kdper);
        session = sqlSessionFactory.openSession();
        HeaderDataKonsolidasi obj = null;
        try {
            obj = session.selectOne("HeaderDataKonsolidasiMapper.selectFindByThnIdlapKdper", map);

        } finally {
            session.close();
        }
        return obj;
    }
  
  public HeaderDataKonsolidasi findByAllKriteria(int thn, int idlap, String kdper, int sumber, int bas, int level, int status) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
         Map<String, Object> map = new HashMap<>();
        map.put("tahun", thn);
        map.put("idlap", idlap);
        map.put("kdPeriode", kdper);
        map.put("sumber", sumber);
        map.put("bas", bas);
        map.put("level", level);
        map.put("status", status);
        session = sqlSessionFactory.openSession();
        HeaderDataKonsolidasi obj = null;
        try {
            obj = session.selectOne("HeaderDataKonsolidasiMapper.selectFindByAllKriteria", map);

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

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

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

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

        } finally {
            session.close();
        }
        return list;
    }
    
    
    public HeaderDataKonsolidasi updateLingkup(HeaderDataKonsolidasi obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("HeaderDataKonsolidasiMapper.updateOneLingkup", obj);
        session.commit();
        session.close();
        return obj;
    }
    
      public List<HeaderDataKonsolidasi> findProvLak(int header) {
        Map<String, Object> map = new HashMap<>();
        map.put("header", header);
        List<HeaderDataKonsolidasi> list = null;
        session = sqlSessionFactory.openSession();
        try {

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

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

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

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

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

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

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

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

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

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

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

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