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

import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import sikd.sikd5.sikd5bean.fault.SIKDServiceException;
import sikd.sikd5.sikd5bean.query.PosisiKasAkunPerPemda;
import sikd.sikd5.sikd5bean.tabel.simpatik.Posisikasakun;
import sikd.sikd5.sikd5ejb.dao.PosisiKasDao;
import sikd.sikd5.sikd5ejb.dao.RefSimpatikDao;
import sikd.sikd5.sikd5ejb.session.util.MyBatisConnectionFactory;

@Stateless
@Remote({RefSimpatikSessionBeanRemote.class})
public class RefSimpatikSessionBean implements RefSimpatikSessionBeanRemote {

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

    @PostConstruct
    public void init() {
        try {
            sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
            dao = new RefSimpatikDao();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public List<PosisiKasAkunPerPemda> getRefsimpatiks(short tahun, String[] inAkun) throws Exception {
        List<PosisiKasAkunPerPemda> infos = new ArrayList<PosisiKasAkunPerPemda>();
        try {
            session = sqlSessionFactory.openSession();
            infos = dao.getRefsimpatiks(tahun, inAkun, session);
        } catch (Exception e) {
            e.printStackTrace();
            throw new SIKDServiceException(e.getMessage());
        } finally {
            session.close();
        }
        return infos;
    }

}
