List of usage examples for javax.persistence TypedQuery getSingleResult
X getSingleResult();
From source file:eu.domibus.common.dao.MessageLogDao.java
public MessageLogEntry findByMessageId(String messageId, MSHRole mshRole) { final TypedQuery<MessageLogEntry> query = this.em.createNamedQuery("MessageLogEntry.findByMessageId", MessageLogEntry.class); query.setParameter("MESSAGE_ID", messageId); query.setParameter("MSH_ROLE", mshRole); try {/*from w w w .j ava 2s.c o m*/ return query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.openmeetings.app.data.calendar.daos.AppointmentCategoryDaoImpl.java
public AppointmentCategory getAppointmentCategoryById(Long categoryId) { try {//w ww . ja v a 2 s . c o m log.debug("getAppointmentCategoryById: " + categoryId); String hql = "select app from AppointmentCategory app " + "WHERE app.deleted <> :deleted " + "AND app.categoryId = :categoryId"; TypedQuery<AppointmentCategory> query = em.createQuery(hql, AppointmentCategory.class); query.setParameter("deleted", "true"); query.setParameter("categoryId", categoryId); AppointmentCategory appointCategory = null; try { appointCategory = query.getSingleResult(); } catch (NoResultException ex) { } return appointCategory; } catch (Exception ex2) { log.error("[getAppointmentCategoryById]: " + ex2); } return null; }
From source file:net.awired.generic.jpa.dao.impl.GenericDaoImpl.java
@Transactional(propagation = Propagation.SUPPORTS) protected ENTITY findSingleResult(TypedQuery<ENTITY> query) throws NotFoundException { try {/*from ww w . ja va 2s .c o m*/ return query.getSingleResult(); } catch (NoResultException e) { throw new NotFoundException("Object '" + entityClass + "' with parameters '" + Arrays.toString(query.getParameters().toArray()) + "' not found in database", e); } }
From source file:com.softwarecorporativo.monitoriaifpe.servico.AtividadeService.java
@PermitAll @Override//from w w w. j a v a 2s . com public Atividade verificarExistencia(Atividade entidadeNegocio) { StringBuilder jpql = new StringBuilder(); jpql.append("select a from "); jpql.append(getClasseEntidade().getSimpleName()); jpql.append(" as a where a.monitoria = ?1 "); jpql.append(" and a.dataInicio = ?2 "); TypedQuery<Atividade> query = super.entityManager.createQuery(jpql.toString(), getClasseEntidade()); query.setParameter(1, entidadeNegocio.getMonitoria()); query.setParameter(2, entidadeNegocio.getDataInicio(), TemporalType.DATE); return query.getSingleResult(); }
From source file:eu.europa.ec.fisheries.uvms.exchange.dao.bean.ExchangeLogDaoBean.java
@Override public Long getExchangeLogListSearchCount(String countSql, List<SearchValue> searchKeyValues) throws ExchangeDaoException { LOG.debug("SQL QUERY IN LIST COUNT: " + countSql); TypedQuery<Long> query = em.createQuery(countSql, Long.class); HashMap<ExchangeSearchField, List<SearchValue>> orderedValues = SearchFieldMapper .combineSearchFields(searchKeyValues); setQueryParameters(query, orderedValues); return query.getSingleResult(); }
From source file:eu.domibus.ebms3.common.dao.PModeDao.java
protected String findActionName(final String action) throws EbMS3Exception { if (action == null || action.isEmpty()) { throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0004, "Action parameter must not be null or empty", null, null, null); }//from www . ja v a 2 s . c om final TypedQuery<String> query = this.entityManager.createNamedQuery("Action.findByAction", String.class); query.setParameter("ACTION", action); try { final String actionName = query.getSingleResult(); return actionName; } catch (final NoResultException e) { PModeDao.LOG.info("No matching action found", e); throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0001, "No matching action found", null, null, null); } }
From source file:com.epam.ipodromproject.repository.jpa.JPAUserRepository.java
@Override public long getTotalUsers(String partOfName, boolean enabled, boolean unblocked) { TypedQuery<Long> query = entityManager.createNamedQuery("User.getTotalUsersByPartOfNameAndEnabled", Long.class); query.setParameter("code", "%" + partOfName + "%"); query.setParameter("enabled", enabled); query.setParameter("blocked", !unblocked); long totalUsers = 0; try {//from ww w. j a v a 2s . co m totalUsers = query.getSingleResult(); } catch (Exception e) { } return totalUsers; }
From source file:eu.domibus.ebms3.common.dao.PModeDao.java
@Override public Agreement getAgreement(final String pModeKey) { final TypedQuery<Agreement> query = this.entityManager.createNamedQuery("Agreement.findByName", Agreement.class); query.setParameter("NAME", this.getAgreementRefNameFromPModeKey(pModeKey)); return query.getSingleResult(); }
From source file:org.openmeetings.app.data.calendar.daos.AppointmentReminderTypDaoImpl.java
public AppointmentReminderTyps getAppointmentReminderTypById(Long typId) { try {/*from ww w. j a v a 2s . com*/ log.debug("AppointmentReminderTypById: " + typId); String hql = "select app from AppointmentReminderTyps app " + "WHERE app.deleted <> :deleted " + "AND app.typId = :typId"; TypedQuery<AppointmentReminderTyps> query = em.createQuery(hql, AppointmentReminderTyps.class); query.setParameter("deleted", "true"); query.setParameter("typId", typId); AppointmentReminderTyps appointmentReminderTyps = null; try { appointmentReminderTyps = query.getSingleResult(); } catch (NoResultException ex) { } return appointmentReminderTyps; } catch (Exception ex2) { log.error("[getAppointmentReminderTypsById]: " + ex2); } return null; }
From source file:com.creditcloud.common.entities.dao.AbstractReadDAO.java
/** * count entity by ParamInfo// ww w.j a va2 s .c o m * * @param paramInfo * @return */ public int count(ParamInfo paramInfo) { EntityManager em = getEntityManager(); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(entityClass); Root<T> userRoot = cq.from(entityClass); cq.select(cb.count(userRoot)); //build query for paramInfo if (paramInfo != null) { Set<Predicate> andCriteria = new HashSet(); Set<Predicate> orCriteria = new HashSet(); for (ParamItem item : paramInfo.getParamItems()) { Predicate predicate; if (item.getValue() instanceof String) { //fuzy search for string String regExp = "%" + item.getValue() + "%"; predicate = cb.like((Expression) (userRoot.get(item.getFieldName())), regExp); } else { predicate = cb.equal((userRoot.get(item.getFieldName())), item.getValue()); } switch (item.getOperator()) { case AND: andCriteria.add(predicate); break; case OR: orCriteria.add(predicate); break; } } if (orCriteria.size() > 0) { Predicate or = cb.or(orCriteria.toArray(new Predicate[orCriteria.size()])); andCriteria.add(or); } if (andCriteria.size() > 0) { Predicate and = cb.and(andCriteria.toArray(new Predicate[andCriteria.size()])); cq.where(and); } } TypedQuery<Long> query = em.createQuery(cq); Long result = query.getSingleResult(); return result == null ? 0 : result.intValue(); }