/*
 * 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.BaganAkunStandarDao;
import sikd.ikonsol.ejb.dao.DataWarehouseDao;
import sikd.ikonsol.model.HeaderDataKonsolidasi;
import sikd.ikonsol.model.RawData;
import sikd.ikonsol.model.RawDataLak;
import sikd.ikonsol.model.RawDataLpe;
import sikd.ikonsol.model.RawDataLpsal;
import sikd.sikd5.sikd5ejb.session.util.MyBatisConnectionFactory;
/**
 *
 * @author Imam Bhoim
 */

@Stateless
public class DwEjbHomeImpl implements DwEjbHome{

     private SqlSessionFactory sqlSessionFactory;
    private SqlSession session = null;

    private DataWarehouseDao dao;

    @PostConstruct
    public void init() {
        try {
            System.out.println("-------- Load MyBatis Factory IKonsol ------- ");
            sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactoryIkonsolDw2();
            dao = new DataWarehouseDao(sqlSessionFactory);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    @Override
    public List<RawData> findAll() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        return dao.findAll();
    }

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

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

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

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

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

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

    @Override
    public List<RawData> findAllByParam(int tahun, String periode, int jenisLap,String namaTbl,String prov) {
     //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        return dao.findAllByParam(tahun, periode, jenisLap,namaTbl,prov);
    }

    @Override
    public RawData findCountByParam(int tahun, String periode, int jenisLap,String namaTbl,String prov) {
      //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        return dao.findCountByParam(tahun, periode, jenisLap,namaTbl,prov);
    }

    @Override
    public List<RawDataLpe> findAllByParamLpe(int tahun, String periode, int jenisLap,String namaTbl,String prov) {
   //     throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
           return dao.findAllByParamLpe(tahun, periode, jenisLap,namaTbl, prov);
    }

    @Override
    public List<RawDataLpsal> findAllByParamLpsal(int tahun, String periode, int jenisLap,String namaTbl,String prov) {
      //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
         return dao.findAllByParamLpsal(tahun, periode, jenisLap, namaTbl, prov);
   
    }

    @Override
    public List<RawDataLak> findAllByParamLak(int tahun, String periode, int jenisLap,String namaTbl,String prov) {
    //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        return dao.findAllByParamLak(tahun, periode, jenisLap,namaTbl,prov);
   
    }

    @Override
    public RawDataLpe findCountByParamLpe(int tahun, String periode, int jenisLap,String namaTbl,String prov) {
    //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
         return dao.findCountByParamLpe(tahun, periode, jenisLap,namaTbl,prov);
    }

    @Override
    public RawDataLpsal findCountByParamLpsal(int tahun, String periode, int jenisLap,String namaTbl,String prov) {
    //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
         return dao.findCountByParamLpsal(tahun, periode, jenisLap,namaTbl,prov);
    }

    @Override
    public RawDataLak findCountByParamLak(int tahun, String periode, int jenisLap,String namaTbl,String prov) {
       // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
       return dao.findCountByParamLak(tahun, periode, jenisLap,namaTbl,prov);
    }

    @Override
    public Boolean cekCon(HeaderDataKonsolidasi obj) {
       RawData obj2 =null;
       Boolean con = true;
        try {
            System.out.println("--------Loadmuluuu------- ");
            MyBatisConnectionFactory.setSqlSessionFactoryIkonsolDw2(obj.getServerDb(),obj.getNamaDb(),obj.getPortDb(),obj.getVendorDb(),obj.getUserName(),obj.getPassDb());
            sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactoryIkonsolDw2();
            sqlSessionFactory.openSession().getConnection();
            con = true;
           } catch (Exception ex) {
            ex.printStackTrace();
           con = false;
        }
    
    return con;
    
    }

    @Override
    public Boolean closesCon(HeaderDataKonsolidasi obj) {
       // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
           MyBatisConnectionFactory.setSqlSessionFactoryIkonsolDw2(obj.getServerDb(),obj.getNamaDb(),obj.getPortDb(),obj.getVendorDb(),obj.getUserName(),obj.getPassDb());
            sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactoryIkonsolDw2();
         
            session = (SqlSession) sqlSessionFactory;
            session.close();
       
            
      return   true;     
                    
    }

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

    @Override
    public List<RawData> findCountPemdaByParam(int tahun, String periode, int jenisLap,String namaTbl,String prov) {
      //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
      return dao.findCountPemdaByParam(tahun, periode, jenisLap,namaTbl,prov);
    }
    
}
