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

/**
 *
 * @author Imam Bhoim
 */
public class BaganAkunStandarDao implements IDAO<BaganAkunStandar>, Serializable {

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

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

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

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

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

        return list;
    }

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

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

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

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

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

    public BaganAkunStandar saveLevel5(BaganAkunStandar obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("BaganAkunStandarMapper.insertOneLevel5", obj);
        session.commit();
        session.close();
        return obj;
    }
    
      public BaganAkunStandar saveImport(BaganAkunStandar obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("BaganAkunStandarMapper.insertImport", obj);
        session.commit();
        session.close();
        return obj;
    }

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

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

    public List<BaganAkunStandar> findAllLevel1(int idbas) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        List<BaganAkunStandar> listlvl1 = new ArrayList<BaganAkunStandar>();

        session = sqlSessionFactory.openSession();
        try {
            listlvl1 = session.selectList("BaganAkunStandarMapper.selectAllLevel1", idbas);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return listlvl1;
    }

    public List<BaganAkunStandar> findAllLevel2() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        List<BaganAkunStandar> listlvl2 = new ArrayList<BaganAkunStandar>();

        session = sqlSessionFactory.openSession();
        try {
            listlvl2 = session.selectList("BaganAkunStandarMapper.selectAllLevel2");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return listlvl2;
    }

    public List<BaganAkunStandar> findAllLevel2ByLevel1(int lvl1, int idbas) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Map<String, Object> map = new HashMap<>();
        map.put("kodeLevel1", lvl1);
        map.put("idbas", idbas);
        List<BaganAkunStandar> listlvl2 = new ArrayList<BaganAkunStandar>();

        session = sqlSessionFactory.openSession();
        try {
            listlvl2 = session.selectList("BaganAkunStandarMapper.selectAllLevel2ByLevel1", map);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return listlvl2;
    }

    public List<BaganAkunStandar> findAllLevel3ByLevel2(int lvl2, int idbas) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Map<String, Object> map = new HashMap<>();
        map.put("kodeLevel2", lvl2);
        map.put("idbas", idbas);
        List<BaganAkunStandar> listlvl3 = new ArrayList<BaganAkunStandar>();

        session = sqlSessionFactory.openSession();
        try {
            listlvl3 = session.selectList("BaganAkunStandarMapper.selectAllLevel3ByLevel2", map);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return listlvl3;
    }

    public List<BaganAkunStandar> findAllLevel4ByLevel3(int lvl3, int idbas) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Map<String, Object> map = new HashMap<>();
        map.put("kodeLevel3", lvl3);
        map.put("idbas", idbas);
        List<BaganAkunStandar> listlvl4 = new ArrayList<BaganAkunStandar>();

        session = sqlSessionFactory.openSession();
        try {
            listlvl4 = session.selectList("BaganAkunStandarMapper.selectAllLevel4ByLevel3", map);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return listlvl4;
    }

    public BaganAkunStandar findKodelvl12(int lvl1, int lvl2, int lvl3, int idbas) {
        Map<String, Object> map = new HashMap<>();
        map.put("kodeLevel1", lvl1);
        map.put("kodeLevel2", lvl2);
        map.put("kodeLevel3", lvl3);
        map.put("idbas", idbas);
        session = sqlSessionFactory.openSession();
        BaganAkunStandar obj = null;
        try {
            obj = session.selectOne("BaganAkunStandarMapper.selectLevel123", map);

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

    public BaganAkunStandar findKodelvl123(int lvl1, int lvl2, int lvl3, String lvl4, int idbas) {
        Map<String, Object> map = new HashMap<>();
        map.put("kodeLevel1", lvl1);
        map.put("kodeLevel2", lvl2);
        map.put("kodeLevel3", lvl3);
        map.put("kodeLevel4", lvl4);
        map.put("idbas", idbas);
        session = sqlSessionFactory.openSession();
        BaganAkunStandar obj = null;
        try {
            obj = session.selectOne("BaganAkunStandarMapper.selectLevel1234", map);

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

    public BaganAkunStandar findKodelvl1234(int lvl1, int lvl2, int lvl3, String lvl4, String lvl5, int idbas) {
        Map<String, Object> map = new HashMap<>();
        map.put("kodeLevel1", lvl1);
        map.put("kodeLevel2", lvl2);
        map.put("kodeLevel3", lvl3);
        map.put("kodeLevel4", lvl4);
        map.put("kodeLevel5", lvl5);
        map.put("idbas", idbas);
        session = sqlSessionFactory.openSession();
        BaganAkunStandar obj = null;
        try {
            obj = session.selectOne("BaganAkunStandarMapper.selectLevel12345", map);

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

    public List<BaganAkunStandar> findByLevel1(int lvl1, int idbas) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Map<String, Object> map = new HashMap<>();
        map.put("kodeLevel1", lvl1);
        map.put("idbas", idbas);
        List<BaganAkunStandar> listlvl1 = new ArrayList<BaganAkunStandar>();

        session = sqlSessionFactory.openSession();
        try {
            listlvl1 = session.selectList("BaganAkunStandarMapper.selectByLevel1", map);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return listlvl1;
    }

    public List<BaganAkunStandar> findByLevel2(int lvl1, int lvl2, int idbas) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Map<String, Object> map = new HashMap<>();
        map.put("kodeLevel1", lvl1);
        map.put("kodeLevel2", lvl2);
        map.put("idbas", idbas);
        List<BaganAkunStandar> listlvl2 = new ArrayList<BaganAkunStandar>();

        session = sqlSessionFactory.openSession();
        try {
            listlvl2 = session.selectList("BaganAkunStandarMapper.selectByLevel2", map);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return listlvl2;
    }

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

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

        return list;
    }

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

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

        return list;
    }

    public List<BaganAkunStandar> findAllByJenisBas(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        List<BaganAkunStandar> list = new ArrayList<BaganAkunStandar>();

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

        return list;
    }

    public void deleteKode(int lvl1, int lvl2, int lvl3, String lvl4, String lvl5, int idbas) {
        Map<String, Object> map = new HashMap<>();
        map.put("kodeLevel1", lvl1);
        map.put("kodeLevel2", lvl2);
        map.put("kodeLevel3", lvl3);
        map.put("kodeLevel4", lvl4);
        map.put("kodeLevel5", lvl5);
        map.put("idbas", idbas);
        session = sqlSessionFactory.openSession();
        session.delete("BaganAkunStandarMapper.deleteOne", map);
        session.commit();
        session.close();

    }
}
