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

/**
 *
 * @author Imam Bhoim
 */
public class JenisLaporanDao implements IDAO<JenisLaporan>, Serializable {

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

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

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

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

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

        return list;
    }

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

    @Override
    public JenisLaporan findByID(int id) {
        //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();
        JenisLaporan obj = null;
        try {
            obj = session.selectOne("JenisLaporanMapper.selectId", id);

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

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

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

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

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

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

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

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

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

        return list;
    }
    
}
