package br.com.caelum.livraria.dao;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import javax.swing.JOptionPane;
import br.com.caelum.livraria.modelo.Usuario;
public class UsuarioDao {
public boolean existe (Usuario usuario) {
System.out.println("aquiii - UsuarioDao");
EntityManager em = new JPAUtil().getEntityManager();
System.out.println("aquiii - UsuarioDao1111");
TypedQuery<Usuario> query = em.createQuery(
" select u from Usuario u "
+ " where u.email = :pEmail and u.senha = :pSenha", Usuario.class);
query.setParameter("pEmail", usuario.getEmail());
query.setParameter("pSenha", usuario.getSenha());
try{
Usuario resultado = query.getSingleResult();
}catch(NoResultException ex){
System.out.println("Email ou senha incorreto! ");
//JOptionPane.showMessageDialog(null,"Email ou senha incorreto! ","",JOptionPane.INFORMATION_MESSAGE);
JOptionPane i = new JOptionPane();
i.showMessageDialog(null, "Email ou senha incorreto! ");
i.setFocusable(true);
return false;
}
em.close();
return true;
}
}