Example usage for javax.persistence NoResultException getClass

List of usage examples for javax.persistence NoResultException getClass

Introduction

In this page you can find the example usage for javax.persistence NoResultException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:edu.csueb.cs6320.utils.UserService.java

/**
 * If the email/password combination is valid, returns the user that belongs to it; otherwise returns null
 * @param email      The user's email/*from   www  .j ava2s . com*/
 * @param password   The user's password
 * @return         The user, if authentic; otherwise null
 */
public User getAuthenticatedUser(String email, String password) {
    EntityManager em = Persistence.createEntityManagerFactory("TestPU").createEntityManager();

    User u = null;
    try {
        u = (User) em.createQuery("SELECT u FROM User u WHERE u.email = :inEmail")
                .setParameter("inEmail", email).setMaxResults(1).getSingleResult();
    } catch (javax.persistence.NoResultException e) {
        System.out.println("No user found with that email");
        return null;
    } catch (Exception e) {
        System.out.println("Exception occurred while trying to find user " + "by email address, of class: "
                + e.getClass().toGenericString());
        e.printStackTrace();
    }

    if (u == null) {
        return null;
    }

    try {
        if (Auth.isCorrectPassword(password, u.getSalt(), u.getSaltedHashedPassword())) {
            return u;
        }
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}