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

import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import sikd.ikonsol.ejb.dao.PeriodeDao;
import sikd.ikonsol.model.Periode;
import sikd.sikd5.sikd5ejb.session.util.MyBatisConnectionFactory;
import sikd.sikd5.sikd5ejb.session.util.MyBatisConnectionFactoryIKonsol;

/**
 *
 * @author User
 */
@Stateless
public class PeriodeEjbHomeImpl implements PeriodeEjbHome {

    private SqlSessionFactory sqlSessionFactory;
    private SqlSession session = null;

    private PeriodeDao dao;

    @PostConstruct
    public void init() {
        try {
            System.out.println("-------- Load MyBatis Factory IKonsol ------- ");
            sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactoryIkonsol();
            dao = new PeriodeDao(sqlSessionFactory);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public List<Periode> findAll() {
        return dao.findAll();
    }

    @Override
    public Periode createNew() {
        return new Periode();
    }

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

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

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

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

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

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

    @Override
    public List<Periode> findAllAktif() {
        return dao.findAllAktif();
    }

}
