/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hu.nir.nmail.ejb.stateless;

import hu.nir.nmail.ejb.entity.NmailSetting;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author attila
 */
@Stateless
public class NmailSettingManagerBean implements NmailSettingManagerLocal, NmailSettingManagerRemote {
    @PersistenceContext(unitName="nmailPU")
    private EntityManager em;
    
    public NmailSetting getAvailableNmailSetting() {
        Query query = em.createNamedQuery("NmailSetting.findNmailSettings");
        try {
            List resultList = query.getResultList();
            if (resultList.size() < 1) {
                return null;
            }
            
            return (NmailSetting) resultList.get(0);
        } catch (NoResultException e) {
            return null;
        }
    }
}
