List of usage examples for javax.persistence TypedQuery getSingleResult
X getSingleResult();
From source file:org.kew.rmf.matchconf.Configuration.java
public static long countMatchConfigs() { TypedQuery<Long> q = entityManager().createQuery( "SELECT COUNT(o) FROM Configuration AS o WHERE o.authorityFileName != :authorityFileName", Long.class); q.setParameter("authorityFileName", ""); return q.getSingleResult(); }
From source file:net.triptech.metahive.model.Submission.java
/** * Count the submissions./*ww w . j a v a2 s . com*/ * * @param filter the filter * @return the long */ public static long countSubmissions(final SubmissionFilter filter) { StringBuilder sql = new StringBuilder("SELECT COUNT(s) FROM Submission s"); sql.append(buildWhere(filter)); TypedQuery<Long> q = entityManager().createQuery(sql.toString(), Long.class); HashMap<String, Long> variables = buildVariables(filter); for (String variable : variables.keySet()) { q.setParameter(variable, variables.get(variable)); } return q.getSingleResult(); }
From source file:mobile.service.core.ClientLogService.java
/** * ?ClientLog/*from w w w . ja v a 2 s. c o m*/ * * @param pageIndex ?1 * @param pageSize ?? * @param from ?? * @return */ public static MobilePage<ClientLog> getPage(int pageIndex, int pageSize, String from) { String contentHql = " from MobileClientLog where 1=1 "; if (StringUtils.isNotBlank(from)) { contentHql += " and device = :device "; } String countHql = " select count(id) " + contentHql; contentHql = contentHql + " order by id desc "; TypedQuery<Long> countTypedQuery = JPA.em().createQuery(countHql, Long.class); TypedQuery<MobileClientLog> contentTypedQuery = JPA.em().createQuery(contentHql, MobileClientLog.class) .setFirstResult((pageIndex - 1) * pageSize).setMaxResults(pageSize); if (StringUtils.isNotBlank(from)) { countTypedQuery.setParameter("device", from); contentTypedQuery.setParameter("device", from); } Long count = countTypedQuery.getSingleResult(); List<MobileClientLog> contentList = contentTypedQuery.getResultList(); List<ClientLog> voList = new ArrayList<ClientLog>(); if (CollectionUtils.isNotEmpty(contentList)) { for (MobileClientLog po : contentList) { voList.add(ClientLog.create(po)); } } MobilePage<ClientLog> page = new MobilePage<ClientLog>(count, voList); return page; }
From source file:models.GroupMember.java
/** * /* w w w .j a va 2 s . c om*/ * @param pageIndex 1 * @param pageSize ?? * @param groupId Id * @param excludeId GroupMember Id,null? * @return */ public static Page<GroupMember> queryPageByGroupId(int start, int pageSize, Long groupId, Long excludeId) { String hql = " from GroupMember where group.id = :groupId "; if (null != excludeId) { hql += " and id <> :excludeId"; } String countHql = "select count(id) " + hql; TypedQuery<Long> countTypedQuery = JPA.em().createQuery(countHql, Long.class).setParameter("groupId", groupId); TypedQuery<GroupMember> contentTypedQuery = JPA.em().createQuery(hql, GroupMember.class) .setParameter("groupId", groupId).setFirstResult((start - 1) * pageSize).setMaxResults(pageSize); if (null != excludeId) { countTypedQuery.setParameter("excludeId", excludeId); contentTypedQuery.setParameter("excludeId", excludeId); } Long count = countTypedQuery.getSingleResult(); List<GroupMember> resultList = contentTypedQuery.getResultList(); return new Page<GroupMember>(Constants.SUCESS, count, resultList); }
From source file:fr.univrouen.poste.domain.PosteCandidature.java
public static Long countFindPosteCandidaturesByPostesAndCandidatsAndRecevableAndAuditionnableAndModification( List<PosteAPourvoir> postes, List<User> candidats, List<ReviewStatusTypes> reviewStatus, Boolean recevable, Boolean auditionnable, Boolean modification) { EntityManager em = entityManager();//from ww w . j a v a 2s. c o m String jpaQuery = "SELECT COUNT(o) FROM PosteCandidature AS o WHERE"; if (postes != null) { jpaQuery = jpaQuery + " o.poste IN :postes AND"; } if (candidats != null) { jpaQuery = jpaQuery + " o.candidat IN :candidats AND"; } if (reviewStatus != null) { jpaQuery = jpaQuery + " o.managerReview.reviewStatus IN :reviewStatus AND"; } if (recevable != null) { jpaQuery = jpaQuery + " o.recevable = :recevable AND"; } if (auditionnable != null) { jpaQuery = jpaQuery + " o.auditionnable = :auditionnable AND"; } if (modification != null) { if (modification) { jpaQuery = jpaQuery + " o.modification IS NOT NULL AND"; } else { jpaQuery = jpaQuery + " o.modification IS NULL AND"; } } jpaQuery = jpaQuery + " 1=1"; TypedQuery q = em.createQuery(jpaQuery, Long.class); if (postes != null) { q.setParameter("postes", postes); } if (candidats != null) { q.setParameter("candidats", candidats); } if (reviewStatus != null) { q.setParameter("reviewStatus", reviewStatus); } if (recevable != null) { q.setParameter("recevable", recevable); } if (auditionnable != null) { q.setParameter("auditionnable", auditionnable); } return ((Long) q.getSingleResult()); }
From source file:models.Service.java
public static Page<Service> queryServiceByPage(int page, int pageSize, User user) { if (user == null) { throw new IllegalArgumentException("user?"); }// w ww . j a v a 2s . c o m StringBuffer queryHql = new StringBuffer(); StringBuffer countHql = new StringBuffer(); Map<String, Object> paramMap = new HashMap<String, Object>(); queryHql.append("from Service s where s.owner.id = :userId"); countHql.append("select count(s.id) from Service s where s.owner.id = :userId"); paramMap.put("userId", user.getId()); queryHql.append(" order by s.createDate desc"); TypedQuery<Service> listQuery = JPA.em().createQuery(queryHql.toString(), Service.class); TypedQuery<Long> countQuery = JPA.em().createQuery(countHql.toString(), Long.class); for (Entry<String, Object> e : paramMap.entrySet()) { listQuery.setParameter(e.getKey(), e.getValue()); countQuery.setParameter(e.getKey(), e.getValue()); } List<Service> data = listQuery.setFirstResult(page * pageSize).setMaxResults(pageSize).getResultList(); Long count = countQuery.getSingleResult(); return new Page<Service>(Constants.SUCESS, count, data); }
From source file:net.triptech.metahive.model.Definition.java
/** * Count the definitions./*from ww w . ja va 2 s . c o m*/ * * @param filter the filter * @return the long */ public static long countDefinitions(final DefinitionFilter filter) { StringBuilder sql = new StringBuilder("SELECT COUNT(d) FROM Definition d JOIN d.category c"); sql.append(buildWhere(filter)); TypedQuery<Long> q = entityManager().createQuery(sql.toString(), Long.class); HashMap<String, String> variables = buildVariables(filter); for (String variable : variables.keySet()) { q.setParameter(variable, variables.get(variable)); } return q.getSingleResult(); }
From source file:models.Service.java
public static Page<Service> queryServiceByPage(int page, int pageSize, Long userId, String searchText, Long industryId, String skillTag, boolean isFetchUser, boolean isFetchUserExpert) { StringBuffer queryHql = new StringBuffer(); StringBuffer countHql = new StringBuffer(); Map<String, Object> paramMap = new HashMap<String, Object>(); queryHql.append("from Service s "); countHql.append("select count(s.id) from Service s where 1=1 "); if (isFetchUser) { queryHql.append(" left join fetch s.owner o "); }// w ww . j av a2 s. co m if (isFetchUser && isFetchUserExpert) { queryHql.append(" left join fetch o.experts "); } queryHql.append(" where 1=1 "); if (null != userId) { queryHql.append(" and s.owner.id = :userId "); countHql.append(" and s.owner.id = :userId "); paramMap.put("userId", userId); } if (StringUtils.isNotBlank(searchText)) { queryHql.append( " and (s.industry.tagName like :searchTextLike or s.title like :searchTextLike or s.price like :searchTextLike)"); countHql.append( " and (s.industry.tagName like :searchTextLike or s.title like :searchTextLike or s.price like :searchTextLike)"); paramMap.put("searchTextLike", "%" + searchText.trim() + "%"); } if (null != industryId) { queryHql.append(" and s.industry.id = :industryId "); countHql.append(" and s.industry.id = :industryId "); paramMap.put("industryId", industryId); } if (StringUtils.isNotBlank(skillTag)) { queryHql.append(" and s.tags like :skillTag "); countHql.append(" and s.tags like :skillTag "); paramMap.put("skillTag", "%" + skillTag + "%"); } queryHql.append(" order by s.createDate desc"); TypedQuery<Service> listQuery = JPA.em().createQuery(queryHql.toString(), Service.class); TypedQuery<Long> countQuery = JPA.em().createQuery(countHql.toString(), Long.class); for (Entry<String, Object> e : paramMap.entrySet()) { listQuery.setParameter(e.getKey(), e.getValue()); countQuery.setParameter(e.getKey(), e.getValue()); } List<Service> data = listQuery.setFirstResult(page * pageSize).setMaxResults(pageSize).getResultList(); Long count = countQuery.getSingleResult(); return new Page<Service>(Constants.SUCESS, count, data); }
From source file:eu.domibus.common.dao.ConfigurationDAO.java
public boolean configurationExists() { TypedQuery<Long> query = this.em.createNamedQuery("Configuration.count", Long.class); return query.getSingleResult() != 0; }
From source file:fr.univrouen.poste.provider.AuthenticationSuccessEventListener.java
@Override @Transactional/*from w ww .j a va 2 s . c om*/ public void onApplicationEvent(AuthenticationSuccessEvent ev) { String username = ev.getAuthentication().getName(); TypedQuery<User> query = User.findUsersByEmailAddress(username, null, null); User targetUser = (User) query.getSingleResult(); if (targetUser != null) { // only for existing users targetUser.reportLoginOK(); targetUser.persist(); } }