package br.mp.mprj.portal.portlet.gestaomensagens.service.service.persistence;

import java.util.List;

import br.mp.mprj.portal.portlet.gestaomensagens.service.model.Agendamento;
import br.mp.mprj.portal.portlet.gestaomensagens.service.model.impl.AgendamentoImpl;

import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import com.liferay.util.dao.orm.CustomSQLUtil;

public class AgendamentoFinderImpl extends BasePersistenceImpl<Agendamento>  implements AgendamentoFinder {
	
	private static final Log _log = LogFactoryUtil.getLog(AgendamentoFinderImpl.class);
	
	private static final String FIND_BY_MSG_PEND_ENVIO = AgendamentoFinder.class.getName().concat(".findByMensagensPendetesDeEnvio");

	public List<Agendamento> findByMensagensPendetesDeEnvio() {
	
		  Session session = null;
		  
		    try {
		        session = openSession();
		        CustomSQLUtil.reloadCustomSQL();
		        String sql = CustomSQLUtil.get(FIND_BY_MSG_PEND_ENVIO);

		        SQLQuery q = session.createSQLQuery(sql);
		        q.setCacheable(true);
		        q.addEntity("ag", AgendamentoImpl.class);
		        
		        QueryPos qPos = QueryPos.getInstance(q);
		    

		        List<Agendamento> list = (List<Agendamento>) QueryUtil.list(q, getDialect(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);
		        
		        return list;
		        
		    } catch (Exception e) {
		    	_log.error("Problemas ao listar atributos ativos:", e);
		    } finally {
		        closeSession(session);
		    }

		    return null;
	}

}
