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

/**
 *
 * @author Imam Bhoim
 */
public class JenisBasDao implements IDAO<JenisBas>, Serializable {

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

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

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

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

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

        return list;
    }

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

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

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

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

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

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

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

        return list;
    }
}
