/*
 * 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.AkunResiprokal;

/**
 *
 * @author Imam Bhoim
 */
public class AkunResiprokalDao implements IDAO<AkunResiprokal>, Serializable {

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

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

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

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

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

        return list;
    }

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

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

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

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

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

    @Override
    public AkunResiprokal update(AkunResiprokal obj) {
        // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("AkunResiprokalMapper.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("AkunResiprokalMapper.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.
    }
    
     public List<AkunResiprokal> findByIdHeader(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        List<AkunResiprokal> list = new ArrayList<AkunResiprokal>();

        session = sqlSessionFactory.openSession();
        try {
            list = session.selectList("AkunResiprokalMapper.selectIdHeader", id);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return list;
    }
     
      public AkunResiprokal findKodeAkunHeader(int lvl1, int lvl2, int lvl3, String lvl4, String lvl5, int idbas, int headerres) {
        Map<String, Object> map = new HashMap<>();
        map.put("kdlevel1", lvl1);
        map.put("kdlevel2", lvl2);
        map.put("kdlevel3", lvl3);
        map.put("kdlevel4", lvl4);
        map.put("kdlevel5", lvl5);
        map.put("idbas", idbas);
        map.put("header_id_resipro", headerres);
        session = sqlSessionFactory.openSession();
        AkunResiprokal obj = null;
        try {
            obj = session.selectOne("AkunResiprokalMapper.selectKodeAkunHeader", map);

        } finally {
            session.close();
        }
        return obj;
    }
      
       public AkunResiprokal findKodeAkunHeaderLengkap(int lvl1, int lvl2, int lvl3, String lvl4, String lvl5, int idbas, int headerres, 
               String dk, int kategoripemdaid, String flag) {
        Map<String, Object> map = new HashMap<>();
        map.put("kdlevel1", lvl1);
        map.put("kdlevel2", lvl2);
        map.put("kdlevel3", lvl3);
        map.put("kdlevel4", lvl4);
        map.put("kdlevel5", lvl5);
        map.put("idbas", idbas);
        map.put("header_id_resipro", headerres);
        map.put("dk", dk);
        map.put("id_kategori_pemda", kategoripemdaid);
         map.put("flag", flag);
        session = sqlSessionFactory.openSession();
        AkunResiprokal obj = null;
        try {
            obj = session.selectOne("AkunResiprokalMapper.selectKodeAkunHeaderLengkap", map);

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

}
