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

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import sikd.ikonsol.model.SusunKonsolidasi;

/**
 *
 * @author Imam Bhoim
 */
public class SusunKonsolidasiDao implements IDAO<SusunKonsolidasi>, Serializable {

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

    public SusunKonsolidasiDao(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

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

    @Override
    public List<SusunKonsolidasi> findAll() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        List<SusunKonsolidasi> list = new ArrayList<SusunKonsolidasi>();

        session = sqlSessionFactory.openSession();
        try {
            list = session.selectList("SusunKonsolidasiMapper.selectAll");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return list;
    }

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

    @Override
    public SusunKonsolidasi findByID(int id) {
   session = sqlSessionFactory.openSession();
        SusunKonsolidasi obj = null;
        try {
            obj = session.selectOne("SusunKonsolidasiMapper.selectId", id);

        } finally {
            session.close();
        }
        return obj;
    }

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

    @Override
    public SusunKonsolidasi save(SusunKonsolidasi obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("SusunKonsolidasiMapper.insertOne", obj);
        session.commit();
        session.close();
        return obj;
    }

    @Override
    public SusunKonsolidasi update(SusunKonsolidasi obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("SusunKonsolidasiMapper.updateOne", obj);
        session.commit();
        session.close();
        return obj;
    }

    @Override
    public void deleteByID(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.delete("SusunKonsolidasiMapper.deleteOne", id);
        session.commit();
        session.close();
    }

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

    public List<SusunKonsolidasi> findAllByTahun(int tahun) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

        List<SusunKonsolidasi> list = new ArrayList<SusunKonsolidasi>();

        session = sqlSessionFactory.openSession();
        try {
            list = session.selectList("SusunKonsolidasiMapper.selectAllByTahun", tahun);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return list;
    }
    
     public SusunKonsolidasi updatePemda(SusunKonsolidasi obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("SusunKonsolidasiMapper.updateJmlPemda", obj);
        session.commit();
        session.close();
        return obj;
    }

       public SusunKonsolidasi updateStatus(SusunKonsolidasi obj) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        session.insert("SusunKonsolidasiMapper.updateStatus", obj);
        session.commit();
        session.close();
        return obj;
    }

}
