/*
 * 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 com.cosmodas.FacadeCosmos;

import com.cosmodas.EntCosmos.Documentos;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * @author obper
 */
@Stateless
public class DocumentosFacade extends AbstractFacade<Documentos> implements DocumentosFacadeLocal {

    @PersistenceContext(unitName = "wcosmodasPersistent")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public DocumentosFacade() {
        super(Documentos.class);
    }

    @Override
    public List<Documentos> buscar_documentos() {
        Query consulta = em.createNamedQuery("Documentos.findByDocIn");
        //consulta.setParameter("documentoCodigo", documentoCodigo);

        try {
            return consulta.getResultList();
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public Documentos busquedaDocumento(String codigoDoc) {

        Query consulta = em.createNamedQuery("Documentos.findByDocumentoCodigo");
        consulta.setParameter("documentoCodigo", codigoDoc);

        try {
            return (Documentos) consulta.getResultList().get(0);
        } catch (Exception e) {
            return null;
        }
    }

}
