List of usage examples for javax.persistence Query getSingleResult
Object getSingleResult();
From source file:com.gymadmin.persistence.dao.impl.UserDaoImpl.java
public UserEntity findByNick(String nick) { Query namedQuery = em.createNamedQuery("UserEntity.findByNick"); namedQuery.setParameter("nick", nick); try {/*from w w w. j ava2 s . co m*/ return (UserEntity) namedQuery.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:com.thingtrack.konekti.dao.impl.internal.ClientDaoImpl.java
@Override public Client getByUser(User user) throws Exception { String queryString = "SELECT p"; queryString += " FROM " + getEntityName() + " p"; queryString += " WHERE p.user = :user"; Query query = (Query) getEntityManager().createQuery(queryString).setParameter("user", user); return (Client) query.getSingleResult(); }
From source file:co.sip.dmesmobile.bs.ScUsersDao.java
public ScUsers findByLogin(String login) throws Exception { entityManager = Factory.getEntityManagerFactory().createEntityManager(); ScUsers result = null;//from w ww .j a v a 2 s. c o m try { Query query = entityManager.createNamedQuery("ScUsers.findByLogin"); query.setParameter("login", login); result = (ScUsers) query.getSingleResult(); } catch (Exception e) { log.error("Error intentando consultar el usuario", e.getCause()); } return result; }
From source file:cz.fi.muni.pa036.airticketbooking.dao.impl.UserRoleDaoImpl.java
@Override public UserRole findByUser(User user) { final Query query = em.createQuery("from UserRole where user = :user"); query.setParameter("user", user); return (UserRole) query.getSingleResult(); }
From source file:fr.univrouen.poste.web.ForgotChangePasswordValidator.java
@Override public void validate(Object target, Errors errors) { ForgotChangePasswordForm form = (ForgotChangePasswordForm) target; try {/*from w ww. j a va2s .com*/ Query query = User.findUsersByActivationKey(form.getActivationKey()); if (null != query) { query.getSingleResult(); // result not used but assert that there is one (and only) result for the query String newPassword = form.getNewPassword(); String newPasswordAgain = form.getNewPasswordAgain(); if (!newPassword.equals(newPasswordAgain)) { errors.reject("changepassword.passwordsnomatch"); } } } catch (EntityNotFoundException e) { errors.rejectValue("emailAddress", "changepassword.invalidemailaddress"); } catch (NonUniqueResultException e) { errors.rejectValue("emailAddress", "changepassword.duplicateemailaddress"); } }
From source file:ApplicationDao.CustomerDao.java
public String getCustomerPassword(String email) { em.getTransaction().begin();/*from w w w .j a va 2 s .c o m*/ Query q = em.createNamedQuery("GetPasswordForEmail").setParameter("email", email); Customer cusObj = (Customer) q.getSingleResult(); em.getTransaction().commit(); return cusObj.getPassword(); }
From source file:localdomain.localhost.service.SampleDataCreatorInitializer.java
@Override public void afterPropertiesSet() throws Exception { TransactionStatus status = transactionManager .getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED)); try {/*from ww w. j a v a 2 s.c om*/ Query query = em.createQuery("select count(p) from Product p"); long count = (Long) query.getSingleResult(); if (count == 0) { logger.info("Database is empty, insert demo products"); em.persist(new Product("Long Island Iced Tea", "Type of alcoholic mixed drink made with, among other ingredients, vodka, gin, tequila, and rum")); em.persist(new Product("Sex on the beach", "Made from vodka, peach schnapps, orange juice, and cranberry juice")); logger.info("Demo products inserted in the database"); } else { logger.info("Products found in the database, don't insert new ones"); } transactionManager.commit(status); } catch (RuntimeException e) { try { transactionManager.rollback(status); } catch (Exception rollbackException) { logger.warn("Silently ignore", rollbackException); } throw e; } }
From source file:com.mycompany.testeproject.ColaboradorDAO.java
public Tcolaborador getColaboradorByNrColaborador(long nrColaborador) { Query q = em.createNamedQuery("Tcolaborador.findByNrColaborador"); q.setParameter("nrColaborador", nrColaborador); return (Tcolaborador) q.getSingleResult(); }
From source file:de.crowdcode.bitemporal.example.AddressRepository.java
public Integer getAmount() { Query query = em.createQuery("select count(c.id) from AddressImpl c"); Number amount = (Number) query.getSingleResult(); return amount.intValue(); }
From source file:com.gymadmin.persistence.dao.impl.PlanDaoImpl.java
public PlanEntity findByName(String name) { Query namedQuery = em.createNamedQuery("PlanEntity.findByName"); namedQuery.setParameter("name", name); try {//from www.j ava2s. c om return (PlanEntity) namedQuery.getSingleResult(); } catch (NoResultException e) { return null; } }