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

package sample.scatterplot.ejb;

import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import sample.scatterplot.persistence.PlotSample;

/**
 *
 * Stateless EJB that only queries the samples of a magnitude.
 * It was created cos PlotApplication cannot be annotated with @Stateless.
 *
 * @author ricky
 */
@javax.inject.Named
@javax.ejb.Stateless
@javax.ejb.LocalBean
public class PlotQueryEjb {

    /**
     * Entity Manager to access DDBB
     */
    @PersistenceContext
    EntityManager em;

    /**
     * Simple method to list all the samples between two dates. The named query
     * must be passed.
     * @param queryName The named query to execute
     * @param startDate The start date
     * @param endDate The end date
     * @return All the samples between both dates
     */
    public List<PlotSample> getPlotSamples(String queryName, Date startDate, Date endDate) {
        return em.createNamedQuery(queryName).
                setParameter("begin", startDate).
                setParameter("end", endDate).getResultList();
    }
 
}
