/*
 * 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 beans;

import entities.Cliente;
import entities.Usuario;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author ryuuji
 */
@Stateless
public class ClienteFacade extends AbstractFacade<Cliente> implements ClienteFacadeLocal {

  @PersistenceContext(unitName = "bank-ejbPU")
  private EntityManager em;

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

  public ClienteFacade() {
    super(Cliente.class);
  }

  @Override
  public Cliente findByRut(String rut) {
    TypedQuery<Cliente> query = em.createQuery("SELECT c FROM Cliente c WHERE c.rut = :rut ", Cliente.class);
    query.setParameter("rut", rut);
    try {
      return query.getSingleResult();
    } catch (NoResultException | NonUniqueResultException ex) {
      return null;
    }
  }

}
