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

package hu.nir.nmail.ejb.stateless;

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

/**
 *
 * @author attila
 */
@Stateless
public class SmtpSettingsManagerBean implements SmtpSettingsManagerRemote, SmtpSettingsManagerLocal {
    @PersistenceContext(unitName="nmailPU")
    private EntityManager em;
    
    public SmtpSettings getSmtpSettings() {
        Query query = em.createNamedQuery("SmtpSettings.findAvailableSmtps");
        List queryResult = query.getResultList();
        
        if (queryResult == null || queryResult.size() < 1) {
            return null;
        }
        
        return (SmtpSettings) queryResult.get(0);
    }

    public void persist(SmtpSettings smtpSettings) {
        em.persist(smtpSettings);
    }
}
