/*
 * 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.UserDao;
import sikd.ikonsol.model.User;
import sikd.sikd5.sikd5ejb.session.util.MyBatisConnectionFactory;

/**
 *
 * @author Imam Bhoim
 */
@Stateless
public class UserEjbHomeImpl implements UserEjbHome {

    private SqlSessionFactory sqlSessionFactory;
    private SqlSession session = null;

    private UserDao dao;

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

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

    @Override
    public User findByID(int id) {
        return dao.findByID(id);
    }

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

    @Override
    public User save(User obj) {
        return dao.save(obj);
    }

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

    @Override
    public User update(User obj) {
        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.
    }

    @Override
    public void deleteId(int id) {
  dao.deleteByID(id);
    }

}
