List of usage examples for javax.persistence Query getSingleResult
Object getSingleResult();
From source file:br.com.blackhouse.internet.controller.LoginController.java
/** * Returns true if user exist else false * // ww w .j ava 2 s . c o m * @param userName * user name * @param password * user password * @return true if user exist else false */ @Transactional public Usuario checkLogin(String userName, String password) { if (GenericValidator.isBlankOrNull(userName) || GenericValidator.isBlankOrNull(password)) { logger.log(Level.WARNING, "UserName and Password is null"); return null; } Query query = entityManager.createQuery( "select p from Usuario p where " + "p.userName=:userName and " + "p.password=:password"); query.setParameter("userName", userName); query.setParameter("password", password); Usuario value = null; try { value = (Usuario) query.getSingleResult(); value.setLastLoginDate(GregorianCalendar.getInstance().getTime()); } catch (Exception e) { return null; } return value; }
From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java
public SoftwareLicenseDTO getGNUv3SoftwareLicenseDTO() { Query query = createEntityManager().createNamedQuery("SoftwareLicenseDTO.findByName"); query.setParameter("name", GNUv3SoftwareLicenseName); return (SoftwareLicenseDTO) query.getSingleResult(); }
From source file:gwap.rest.User.java
private GameType getGameType() { Query query = entityManager.createNamedQuery("gameType.select"); query.setParameter("name", "inspectorXApp"); GameType gameType = (GameType) query.getSingleResult(); return gameType; }
From source file:com.eu.evaluation.server.dao.AbstractDAO.java
/** * /*from www .ja v a2 s .co m*/ * * @param jpql * @param params * @param pageNo * @param pageSize * @return */ public PageData<T> query(String jpql, MapSqlParameterSource params, int pageNo, int pageSize) { // Count String countQueryString = " select count (*) " + removeSelect(removeOrders(jpql)); Query countQuery = createQuery(countQueryString, params); Long totalCount = (Long) countQuery.getSingleResult(); if (totalCount < 1) { return new PageData<T>(); } // int startIndex = PageData.getStartOfPage(pageNo, pageSize); Query query = createQuery(jpql, params); query.setFirstResult(startIndex); query.setMaxResults(pageSize); List<T> rows = query.getResultList(); return new PageData<T>(startIndex, totalCount, pageSize, rows); }
From source file:com.bizintelapps.bugtracker.dao.impl.GenericDaoImpl.java
private Integer executeQueryReturnInt(final String jpql, final Object... params) throws DataAccessException { Query query = entityManager.createQuery(jpql); int i = 1;/*from www . j a va2 s . c o m*/ for (Object param : params) { query.setParameter(i++, param); } Long result = (Long) query.getSingleResult(); try { return result.intValue(); } catch (RuntimeException re) { log.debug(re); return null; } }
From source file:com.healthcit.cacure.dao.BaseQuestionDao.java
public BaseQuestion getById(Long id) { Query query = em.createQuery("from BaseQuestion q where id = :Id"); query.setParameter("Id", id); return (BaseQuestion) query.getSingleResult(); }
From source file:org.kuali.mobility.push.dao.PreferenceDaoImpl.java
@Override public Preference findPreference(String username, Long senderId) { try {/*from ww w .j av a 2s. c om*/ Query query = getEntityManager().createNamedQuery("Preference.findPreferenceWithUsernameAndSenderId"); query.setParameter("username", username); query.setParameter("pushSenderID", senderId); return (Preference) query.getSingleResult(); } catch (NoResultException nre) { // If there is no result we return nothing return null; } }
From source file:co.sip.dmesmobile.bs.ScPersonDao.java
@Override @Transactional/* w w w. j a va 2s . c o m*/ public ScPerson getScPersonById(long id) { entityManager = Factory.getEntityManagerFactory().createEntityManager(); ScPerson result = null; try { Query query = entityManager.createNamedQuery("ScPerson.findByIdPerson"); query.setParameter("idPerson", id); result = (ScPerson) query.getSingleResult(); } catch (Exception e) { log.error("Error al intentar consultar un tercero por ID", e); throw e; } return result; }
From source file:org.kuali.mobility.push.dao.SenderDaoImpl.java
public Sender findSenderBySenderKey(String senderKey) { Query query = entityManager.createQuery("select s from Sender s where s.senderKey = :senderKey"); query.setParameter("senderKey", senderKey); Sender s;/*from w w w . ja v a 2s . co m*/ try { s = (Sender) query.getSingleResult(); } catch (NoResultException e) { LOG.info("Sender with senderKey " + senderKey + " was not found or was invalid."); return null; } return s; }
From source file:org.kuali.mobility.push.dao.SenderDaoImpl.java
public Sender findSenderByShortName(String shortName) { Query query = entityManager.createQuery("select s from Sender s where s.shortName = :shortName"); query.setParameter("shortName", shortName); Sender s;/* w w w .ja va 2 s . co m*/ try { s = (Sender) query.getSingleResult(); } catch (NoResultException e) { LOG.info("Sender with Shortname " + shortName + " was not found or was invalid."); return null; } return s; }