package dao.entities; import java.util.List; import java.util.UUID; import javax.persistence.NoResultException; import javax.persistence.TypedQuery; import dao.JpaDao; import entities.UserInfo; import entities.security.UserAuth; public class UserInfoDaoImpl extends JpaDao implements UserInfoDao { public UserInfo loadDetails(UserInfo t) { // TODO Auto-generated method stub return null; } @Override public UserInfo getByIdAndMail(String identification, String email) { String queryString = "FROM UserInfo userInfo where userInfo.identification = :userInfoID and userInfo.email = :userInfoEmail"; TypedQuery typedQuery = entityManager.createQuery(queryString, UserInfo.class); typedQuery.setParameter("userInfoID", identification); typedQuery.setParameter("userInfoEmail", email); try { return typedQuery.getSingleResult(); } catch(NoResultException ex) { return null; } } @Override public UserInfo getByAuthenticationId(String authenticationID) { UserAuth userauth = new UserAuth(); userauth.setId(UUID.fromString(authenticationID)); String queryString = "FROM UserInfo userInfo where userInfo.authentication = :auth"; TypedQuery typedQuery = entityManager.createQuery(queryString, UserInfo.class); typedQuery.setParameter("auth", userauth); try { return typedQuery.getSingleResult(); } catch(NoResultException ex) { return null; } } @Override public UserInfo getByMail(String email) { String queryString = "FROM UserInfo userInfo where userInfo.email = :email"; TypedQuery typedQuery = entityManager.createQuery(queryString, UserInfo.class); typedQuery.setParameter("email", email); try { return typedQuery.getSingleResult(); } catch(Exception ex) { //no need to distinguish between exceptions for the moment return null; } } @Override public UserInfo getByUsername(String username) { String queryString = "select ui from UserInfo ui join UserAuth ui.authentication ua where ua.username=:username"; TypedQuery typedQuery = entityManager.createQuery(queryString, UserInfo.class); typedQuery.setParameter("username", username); try { return typedQuery.getSingleResult(); } catch(Exception ex) { //no need to distinguish between exceptions for the moment return null; } } }