List of usage examples for javax.persistence Query getSingleResult
Object getSingleResult();
From source file:es.ucm.fdi.dalgs.degree.repository.DegreeRepository.java
public String getNextCode() { Query query = em.createQuery("Select MAX(e.id ) from Degree e"); try {//from w ww. ja v a 2s .co m Long aux = (Long) query.getSingleResult() + 1; return "DEG" + aux; } catch (Exception e) { logger.error(e.getMessage()); return null; } }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAUser.java
@Override @Transactional// w w w .j av a 2 s . co m public boolean existUsers() { Query query = entityManager.createQuery("SELECT COUNT(sid) FROM MDOUser"); Long usersCount = (Long) query.getSingleResult(); if (usersCount != null && usersCount.equals(0L)) { return false; } else { return true; } }
From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.test.NewsITCase.java
/** * Count news./*w w w .j a v a 2 s . com*/ * * @return the long * @throws Exception the exception */ private long countNews() throws Exception { EntityManager em = emf.createEntityManager(); Query query = em.createQuery("SELECT COUNT(p.fs_id) FROM news p"); Long countResult = (Long) query.getSingleResult(); em.close(); return countResult; }
From source file:ApplicationDao.CustomerDao.java
public Customer getCustomerByEmailandPassword(String email, String password) { em.getTransaction().begin();/*w w w. j a va2 s . co m*/ Customer cusObj = null; Query q = em.createNamedQuery("findCustomerByEmailandPassword").setParameter("email", email) .setParameter("password", (DigestUtils.sha256Hex(password))); try { cusObj = (Customer) q.getSingleResult(); } catch (NoResultException nre) { return null; } em.getTransaction().commit(); return cusObj; }
From source file:com.jd.survey.dao.security.UserDAOImpl.java
@Transactional public Long getCount() throws DataAccessException { try {// www . ja va2 s.c o m Query query = createNamedQuery("User.getCount", -1, -1); return (Long) query.getSingleResult(); } catch (NoResultException nre) { return null; } }
From source file:com.jd.survey.dao.security.UserDAOImpl.java
@Transactional public User findById(Long id) throws DataAccessException { try {// w w w .j a v a 2 s. c o m Query query = createNamedQuery("User.findById", -1, -1, id); return (User) query.getSingleResult(); } catch (NoResultException nre) { return null; } }
From source file:nc.noumea.mairie.organigramme.dao.impl.EntiteFavorisDaoImpl.java
@Override public EntiteFavoris findByIdAgentAndIdEntite(Integer idAgent, Integer idEntite) { String jpaQuery = "SELECT entiteFavoris FROM EntiteFavoris entiteFavoris WHERE entiteFavoris.idAgent = :idAgent AND entiteFavoris.idEntite = :idEntite"; Query query = persistentManager.getEntityManager().createQuery(jpaQuery); OrganigrammeUtil.setParameter(query, "idAgent", idAgent); OrganigrammeUtil.setParameter(query, "idEntite", idEntite); return (EntiteFavoris) query.getSingleResult(); }
From source file:me.ronghai.sa.dao.impl.AbstractModelDAOWithEMImpl.java
@Override public long count(String configure) { String jpql = "SELECT count(*) FROM " + entityClass.getName(); if (configure != null) { jpql = jpql + configure;/*from w w w .j a va 2 s .c om*/ } Query query = entityManager.createQuery(jpql); Object rtn = query.getSingleResult(); return rtn == null ? 0 : Long.parseLong(rtn.toString()); }
From source file:com.jd.survey.dao.security.UserDAOImpl.java
@Transactional public Long getCountInternal() throws DataAccessException { try {//from w ww . j ava 2 s. co m Query query = createNamedQuery("User.getCountInternal", -1, -1); return (Long) query.getSingleResult(); } catch (NoResultException nre) { return null; } }
From source file:com.jd.survey.dao.security.UserDAOImpl.java
@Transactional public Long getCountExternal() throws DataAccessException { try {/*from w ww.j a va 2 s . c o m*/ Query query = createNamedQuery("User.getCountExternal", -1, -1); return (Long) query.getSingleResult(); } catch (NoResultException nre) { return null; } }