List of usage examples for javax.persistence TypedQuery getSingleResult
X getSingleResult();
From source file:cz.muni.fi.anatomytutor.backend.dao.impl.AuthUserDaoImplJPA.java
@Override public boolean isEmailAlreadyUsed(String email) { TypedQuery<Long> query; AuthUser returnedUser;/* www . j av a2 s . co m*/ query = em.createQuery("SELECT COUNT(tbl.email) FROM AuthUser tbl " + " WHERE tbl.email = :uemail", Long.class); query.setParameter("uemail", email); Long result = query.getSingleResult(); if (result == 0) { return false; } else if (result == 1) { return true; } throw new RuntimeException("There are more than one identical email in the database."); }
From source file:br.ufba.dcc.mestrado.computacao.repository.impl.ProjectRepositoryImpl.java
@Override public OpenHubProjectEntity findByName(String name) { CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<OpenHubProjectEntity> criteriaQuery = criteriaBuilder.createQuery(getEntityClass()); Root<OpenHubProjectEntity> root = criteriaQuery.from(getEntityClass()); criteriaQuery.select(root);/*from w w w . j av a 2s .c o m*/ Predicate predicate = criteriaBuilder.equal(root.get("name"), name); criteriaQuery.where(predicate); TypedQuery<OpenHubProjectEntity> query = getEntityManager().createQuery(criteriaQuery); OpenHubProjectEntity projectEntity = query.getSingleResult(); return projectEntity; }
From source file:com.simplecrud.dao.UserInfoDao.java
/** * * @param username/*ww w . ja va 2 s. com*/ * @return SIGNING DATE */ public Object getUserSigningDate(String username) { TypedQuery<NewMember> q = em .createQuery("SELECT n.signingDate FROM NewMember n WHERE n.username = :username", NewMember.class); q.setParameter("username", username); return q.getSingleResult(); }
From source file:fr.univrouen.poste.web.SignUpController.java
private String activateUser(String activationKey, String emailAddress, Model model) { String textePremierePageAnonyme = AppliConfig.getCacheTextePremierePageAnonyme(); model.addAttribute("textePremierePageAnonyme", textePremierePageAnonyme); TypedQuery<User> query = User.findUsersByActivationKeyAndEmailAddress(activationKey, emailAddress, null, null);/*from ww w .j a v a 2 s . c o m*/ if (!query.getResultList().isEmpty()) { User user = query.getSingleResult(); if (user.getPassword() != null) { user.setActivationDate(new Date()); user.setEnabled(true); user.merge(); return "login"; } else { UserRegistrationForm form = new UserRegistrationForm(); form.setEmailAddress(emailAddress); form.setActivationKey(activationKey); model.addAttribute("User", form); return "signup/initpassword"; } } else { return "signup/errorlink"; } }
From source file:org.jasig.portlet.notice.service.jpa.JpaNotificationDao.java
@Transactional(readOnly = true) public JpaEntry getFullEntry(long entryId) { Validate.isTrue(entryId > 0, "Invalid entryId: " + entryId); TypedQuery<JpaEntry> query = entityManager.createNamedQuery("JpaEntry.getFullById", JpaEntry.class); query.setParameter("entryId", entryId); return query.getSingleResult(); }
From source file:com.epam.training.taranovski.web.project.repository.implementation.CheckDocumentRepositoryImplementation.java
@Override public CheckDocument findByVacancy(Vacancy vacancy) { EntityManager em = entityManagerFactory.createEntityManager(); CheckDocument checkDocument = null;/*from ww w. j a v a 2 s. c o m*/ try { em.getTransaction().begin(); TypedQuery<CheckDocument> query = em.createNamedQuery("CheckDocument.findByVacancy", CheckDocument.class); query.setParameter("vacancy", vacancy); checkDocument = query.getSingleResult(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(BasicSkillRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return checkDocument; }
From source file:com.epam.training.taranovski.web.project.repository.implementation.CheckDocumentRepositoryImplementation.java
@Override public CheckDocument findByEmployee(Employee employee) { EntityManager em = entityManagerFactory.createEntityManager(); CheckDocument checkDocument = null;/*from w w w .j a v a 2 s . co m*/ try { em.getTransaction().begin(); TypedQuery<CheckDocument> query = em.createNamedQuery("CheckDocument.findByEmployee", CheckDocument.class); query.setParameter("employee", employee); checkDocument = query.getSingleResult(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(BasicSkillRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return checkDocument; }
From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java
@Override public long getCountAllWinsForPlayerInLeague(Player p, League l) { TypedQuery<Long> query = entityManager.createNamedQuery("countAllWinsForPlayerInLeague", Long.class); query.setParameter("player", p); query.setParameter("league", l); return query.getSingleResult(); }
From source file:org.businessmanager.dao.GenericDaoImpl.java
@Override public Long getCount(Map<SingularAttribute<T, ?>, Object> filterAttributes, boolean enableLikeSearch) { CriteriaBuilder queryBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> criteriaQuery = queryBuilder.createQuery(Long.class); Root<T> rootQuery = criteriaQuery.from(getPersistenceClass()); CriteriaQuery<Long> select = criteriaQuery.select(queryBuilder.count(rootQuery)); List<Predicate> predicateList = createFilterList(filterAttributes, enableLikeSearch, queryBuilder, rootQuery);/*from ww w . j a va 2 s. c o m*/ criteriaQuery.where(predicateList.toArray(new Predicate[0])); TypedQuery<Long> typedQuery = entityManager.createQuery(select); return typedQuery.getSingleResult(); }
From source file:de.lava.marvin.whaosleaguepersistence.dao.impl.PlayerDaoImpl.java
@Override public long getCountAllLosesForPlayerInLeague(Player p, League l) { TypedQuery<Long> query = entityManager.createNamedQuery("countAllLosesForPlayerInLeague", Long.class); query.setParameter("player", p); query.setParameter("league", l); return query.getSingleResult(); }