/*
 * 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.RefPemdaDao;
import sikd.ikonsol.model.ReferensiPemda;
import sikd.ikonsol.model.ReferensiWilayah;
import sikd.sikd5.sikd5bean.tabel.Pemda;
import sikd.sikd5.sikd5ejb.session.util.MyBatisConnectionFactory;
import sikd.sikd5.sikd5ejb.session.util.MyBatisConnectionFactoryIKonsol;

/**
 *
 * @author Imam Bhoim
 */
@Stateless
public class RefPemdaEjbHomeImpl implements RefPemdaEjbHome {

    private SqlSessionFactory sqlSessionFactory;
    private SqlSession session = null;

    private RefPemdaDao dao;

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

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

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

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

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

    @Override
    public ReferensiPemda update(ReferensiPemda 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.deleteByPK(kode);
    }

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

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

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

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

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