/*
 * 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.List;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import sikd.ikonsol.model.HeaderResiprokal;
import sikd.sikd5.sikd5ejb.dao.IDao;

/**
 *
 * @author Imam Bhoim
 */
public class HeaderResiprokalDao implements IDAO<HeaderResiprokal>, Serializable {

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

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

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

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

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

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

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

        return list;
    }

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

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

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

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

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

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

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

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

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

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

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

        return list;
    }

}
