List of usage examples for javax.persistence Query setMaxResults
Query setMaxResults(int maxResult);
From source file:com.gettec.fsnip.fsn.dao.member.impl.MemberDAOImpl.java
/** * ??/*from w w w. j a v a 2 s . c o m*/ * @param page * @param size * @param organization * @return * @throws DaoException */ @SuppressWarnings("unchecked") @Override public List<Member> getAllLocalMember(int page, int size, Long organization) throws DaoException { try { String sql = "SELECT DISTINCT p.* FROM member p " + "Inner JOIN business_unit b ON p.producer_id=b.id " + "LEFT JOIN t_meta_initialize_member t ON p.id=t.member_id AND t.organization=?1 " + "WHERE b.organization=?2 AND t.first_storage_id is NULL "; Query query = entityManager.createNativeQuery(sql.toString(), Member.class); query.setParameter(1, organization); query.setParameter(2, organization); if (page > 0) { query.setFirstResult((page - 1) * size); query.setMaxResults(size); } List<Member> result = query.getResultList(); return result; } catch (Exception e) { throw new DaoException( "MemberDAOImpl.getAllLocalMember() ??,?", e); } }
From source file:org.medici.bia.dao.user.UserDAOJpaImpl.java
/** * /*from w w w . j a v a 2 s .co m*/ */ public User findUser(User user) throws TooManyUsersException { try { StringBuilder conditionBuffer = new StringBuilder(""); if (user.getAccount() != null) { conditionBuffer.append("account=:account"); } if (user.getInitials() != null) { if (conditionBuffer.length() > 0) { conditionBuffer.append(" AND "); } conditionBuffer.append("initials=:initials"); } if (user.getFirstName() != null) { if (conditionBuffer.length() > 0) { conditionBuffer.append(" AND "); } conditionBuffer.append("firstName=:firstName"); } if (user.getLastName() != null) { if (conditionBuffer.length() > 0) { conditionBuffer.append(" AND "); } conditionBuffer.append("lastName=:lastName"); } if (user.getOrganization() != null) { if (conditionBuffer.length() > 0) { conditionBuffer.append(" AND "); } conditionBuffer.append("organization=:organization"); } if (user.getMail() != null) { if (conditionBuffer.length() > 0) { conditionBuffer.append(" AND "); } conditionBuffer.append("mail=:mail"); } Query query = getEntityManager().createQuery("FROM User WHERE " + conditionBuffer.toString()); if (user.getAccount() != null) { query.setParameter("account", user.getAccount()); } if (user.getInitials() != null) { query.setParameter("initials", user.getInitials()); } if (user.getFirstName() != null) { query.setParameter("firstName", user.getFirstName()); } if (user.getLastName() != null) { query.setParameter("lastName", user.getLastName()); } if (user.getOrganization() != null) { query.setParameter("organization", user.getOrganization()); } if (user.getMail() != null) { query.setParameter("mail", user.getMail()); } query.setMaxResults(1); return (User) query.getSingleResult(); } catch (PersistenceException persistenceException) { return null; } }
From source file:com.tzquery.fsn.dao.impl.TzQueryDaoImpl.java
/** * Sql?// w w w . j av a 2s . c o m * @author ChenXiaolin 2015-12-1 * @param paramVO * @param sql * @return */ @SuppressWarnings("unchecked") private List<TzQueryResponseProInfoVO> excuteSql(TzQueryRequestParamVO paramVO, String sql) throws DaoException { try { Query query = entityManager.createNativeQuery(sql); if (paramVO.getPage() > 0 && paramVO.getPageSize() > 0) { query.setFirstResult((paramVO.getPage() - 1) * paramVO.getPageSize()); query.setMaxResults(paramVO.getPageSize()); } List<Object[]> objects = query.getResultList(); return setproQuery(objects); } catch (Exception e) { throw new DaoException( "TzQueryDaoImpl-->excuteSql()sql??????", e); } }
From source file:br.org.indt.ndg.server.survey.SurveyHandlerBean.java
public QueryInputOutputVO getAllImeisBySurvey(String surveyId, QueryInputOutputVO queryIOVO) throws MSMApplicationException { if (queryIOVO == null) { queryIOVO = new QueryInputOutputVO(); }/*from ww w . j av a 2 s . com*/ String sQuery = "from Transactionlog where transactionType = "; sQuery += "\'"; sQuery += TransactionLogVO.TYPE_SEND_SURVEY; sQuery += "\'"; sQuery += " and survey.idSurvey = :surveyId"; if ((queryIOVO.getFilterText() != null) && (queryIOVO.getFilterFields() != null)) { sQuery += SqlUtil.getFilterCondition(queryIOVO.getFilterText(), queryIOVO.getFilterFields()); } if ((queryIOVO.getSortField() != null) && (queryIOVO.getIsDescending() != null)) { sQuery += SqlUtil.getSortCondition(queryIOVO.getSortField(), queryIOVO.getIsDescending()); } Query q = manager.createQuery(sQuery); q.setParameter("surveyId", surveyId); if ((queryIOVO.getPageNumber() != null) && (queryIOVO.getRecordsPerPage() != null)) { q.setFirstResult((queryIOVO.getPageNumber() - 1) * queryIOVO.getRecordsPerPage()); q.setMaxResults(queryIOVO.getRecordsPerPage()); } ArrayList<Object> ret = new ArrayList<Object>(); ArrayList<Transactionlog> al = (ArrayList<Transactionlog>) q.getResultList(); Iterator<Transactionlog> it = al.iterator(); ArrayList<String> imeiIdListAux = new ArrayList<String>(); while (it.hasNext()) { Transactionlog surveyTransactionLog = (Transactionlog) it.next(); if (imeiIdListAux.contains(surveyTransactionLog.getImei().getImei())) { continue; } imeiIdListAux.add(surveyTransactionLog.getImei().getImei()); Imei imei = null; if (surveyTransactionLog.getImei() != null) { imei = manager.find(Imei.class, surveyTransactionLog.getImei().getImei()); } if (imei != null) { ImeiVO vo = new ImeiVO(); vo.setImei(imei.getImei()); vo.setMsisdn(imei.getMsisdn()); vo.setUserName(imei.getUser().getUsername()); NdgDevice device = imei.getDevice(); DeviceVO devVO = new DeviceVO(); devVO.setIdDevice(device.getIdDevice()); devVO.setDeviceModel(device.getDeviceModel()); vo.setDevice(devVO); vo.setRealImei(imei.getRealImei()); if (!surveyTransactionLog.getTransactionStatus().equals(TransactionLogVO.STATUS_SUCCESS)) { vo.setStatus(TransactionLogVO.STATUS_PENDING); } else { vo.setStatus(surveyTransactionLog.getTransactionStatus()); } StringBuilder builder = new StringBuilder(); builder.append("from Result where idSurvey = '"); builder.append(surveyId); builder.append("' and imei = '"); builder.append(vo.getImei()); builder.append("'"); Query query = manager.createQuery(builder.toString()); vo.setQtdeResults(query.getResultList().size()); ret.add(vo); } } queryIOVO.setRecordCount(ret.size()); queryIOVO.setQueryResult(ret); return queryIOVO; }
From source file:org.medici.bia.dao.JpaDao.java
/** * /* w ww. j a v a 2 s .com*/ */ @Override public Page searchMYSQL(org.medici.bia.common.search.Search searchContainer, PaginationFilter paginationFilter) throws PersistenceException { // We prepare object of return method. Page page = new Page(paginationFilter); Query query = null; // We set size of result. if (paginationFilter.getTotal() == null) { String countQuery = "SELECT COUNT(*) " + searchContainer.toJPAQuery(); query = getEntityManager().createQuery(countQuery); page.setTotal(new Long((Long) query.getSingleResult())); } String objectsQuery = searchContainer.toJPAQuery(); // We manage sorting (this manages sorting on multiple fields) paginationFilter = generatePaginationFilterMYSQL(paginationFilter); String jpql = objectsQuery + getOrderByQuery(paginationFilter.getSortingCriterias()); logger.info("JPQL Query : " + jpql); query = getEntityManager().createQuery(jpql); // We set pagination query.setFirstResult(paginationFilter.getFirstRecord()); query.setMaxResults(paginationFilter.getLength()); // We set search result on return method page.setList(query.getResultList()); return page; }
From source file:com.tzquery.fsn.dao.impl.TzQueryDaoImpl.java
/** * ??ID??/*from w w w . ja v a 2 s . co m*/ * @author ChenXiaolin 2015-12-1 * @param paramVO * @return * @throws DaoException */ @SuppressWarnings("unchecked") @Override public List<TzQueryResponseReportInfoVO> lookReport(TzQueryRequestParamVO paramVO) throws DaoException { try { StringBuffer sb = new StringBuffer(); sb.append( " SELECT pro.name,pro.barcode,proInst.batch_serial_no,result.service_order,result.test_type,"); sb.append("result.test_orgnization,IF(result.pass=1,'?','??') pass,result.fullPdfPath"); sb.append(" FROM product_instance proInst"); sb.append(" LEFT JOIN test_result result ON proInst.id = result.sample_id"); sb.append(" LEFT JOIN product pro ON pro.id = proInst.product_id"); sb.append(" WHERE result.del = 0 AND proInst.product_id = ").append(Long.parseLong(paramVO.getProId())); Query query = entityManager.createNativeQuery(sb.toString()); if (paramVO.getPage() > 0 && paramVO.getPageSize() > 0) { query.setFirstResult((paramVO.getPage() - 1) * paramVO.getPageSize()); query.setMaxResults(paramVO.getPageSize()); } List<Object[]> objects = query.getResultList(); return setLookReport(objects); } catch (Exception e) { throw new DaoException( "TzQueryDaoImpl-->lookReport()??ID??,?", e); } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves a specified quantity of Annotations associated to a Resource specified by its URL * @param _url// www. java2 s . c o m * @param asc * @param first_indice * @param max_results * @return */ public List<Annotation> retrieveAnnotations(String _url, boolean asc, int first_indice, int max_results) { //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); URI _uri = (URI) em.createQuery("from URI where effectiveURI = ?").setParameter(1, _url) .getSingleResult(); if (_uri == null) { tx.commit(); // //em.close(); System.out.println("[RetrieveAnnotation.retrieveAnnotations] unable to retrieve Annotations" + " cause : there is no uri " + _url); return new ArrayList<Annotation>(); } //List annotations = em.createQuery("select distinct annotation from Annotation as annotation inner join annotation.annotated as annotated inner join annotated.representsResource as uri where uri=?").setParameter(1, _uri).getResultList(); String order_by_clause = " order by annotation.id desc"; if (asc) order_by_clause = " order by annotation.id asc"; Query _query = em.createQuery( "select distinct annotation from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=?" + order_by_clause) .setParameter(1, _uri); _query.setFirstResult(first_indice); _query.setMaxResults(max_results); List<Annotation> annotations = _query.getResultList(); tx.commit(); //em.close(); return annotations; } catch (Exception e) { //tx.commit(); tx.rollback(); //em.close(); System.out.println("[RetrieveAnnotation.retrieveAnnotations] unable to retrieve Annotations" + " cause : " + e.getMessage()); return new ArrayList<Annotation>(); } }
From source file:com.tzquery.fsn.dao.impl.TzQueryDaoImpl.java
/** * ???????//from w w w . j a v a2 s.c o m * @author ChenXiaolin 2015-12-14 * @param paramVO * @return * @throws DaoException */ @SuppressWarnings("unchecked") @Override public List<TzQueryResponseProListVO> getBusQueryProList(TzQueryRequestParamVO paramVO) throws DaoException { try { StringBuffer sb = new StringBuffer(); sb.append(" SELECT * FROM ( "); sb.append(" SELECT pro.id id,pro.name proN,pro.barcode pb,pro.format f,pro.category cet"); sb.append(" FROM tz_business_account account"); sb.append(" INNER JOIN business_unit bus ON bus.id = account.out_business_id"); sb.append(" INNER JOIN tz_business_account_info acInfo ON acInfo.business_account_id = account.id"); sb.append(" INNER JOIN product pro ON pro.id = acInfo.product_id"); sb.append(" WHERE bus.name = '").append(paramVO.getBusName()).append("'"); if (StringUtil.isNotEmpty(paramVO.getLicenseNo())) {//?? sb.append(" AND bus.license_no = '").append(paramVO.getLicenseNo()).append("'"); } /* ? */ if (StringUtil.isNotEmpty(paramVO.getProName())) {//??? sb.append(" AND pro.name LIKE '%").append(paramVO.getProName()).append("%'"); } if (StringUtil.isNotEmpty(paramVO.getFormat())) {//? sb.append(" AND pro.format LIKE '%").append(paramVO.getFormat()).append("%'"); } if (StringUtil.isNotEmpty(paramVO.getProBarcode())) {//??? sb.append(" AND pro.barcode LIKE '%").append(paramVO.getProBarcode()).append("%'"); } /* ?????? */ //FSN?? sb.append(" GROUP BY pro.id ) test"); /* sql */ Query query = entityManager.createNativeQuery(sb.toString()); if (paramVO.getPage() > 0 && paramVO.getPageSize() > 0) { query.setFirstResult((paramVO.getPage() - 1) * paramVO.getPageSize()); query.setMaxResults(paramVO.getPageSize()); } List<Object[]> objects = query.getResultList(); return setBusQueryProList(objects); } catch (Exception e) { throw new DaoException( "TzQueryDaoImpl-->getBusQueryProList()???????,?", e); } }
From source file:org.apache.roller.weblogger.business.jpa.JPAWeblogEntryManagerImpl.java
/** * @inheritDoc/*from w w w . j a v a 2 s. c o m*/ */ public List getWeblogEntriesPinnedToMain(Integer max) throws WebloggerException { Query query = strategy.getNamedQuery("WeblogEntry.getByPinnedToMain&statusOrderByPubTimeDesc"); query.setParameter(1, Boolean.TRUE); query.setParameter(2, WeblogEntry.PUBLISHED); if (max != null) { query.setMaxResults(max.intValue()); } return query.getResultList(); }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves a specified quantity of annotations associated to a Resource specified by its URL and ordered by AnnotationStatus * @param _url/*from w ww. ja v a2s . c o m*/ * @param asc * @param first_indice * @param max_results * @return */ public List<Annotation> retrieveAnnotationsGroupByStatus(String _url, boolean asc, int first_indice, int max_results) { //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); URI _uri = (URI) em.createQuery("from URI where effectiveURI = ?").setParameter(1, _url) .getSingleResult(); if (_uri == null) { tx.commit(); // //em.close(); System.out.println("[RetrieveAnnotation.retrieveAnnotations] unable to retrieve Annotations" + " cause : there is no uri " + _url); return new ArrayList<Annotation>(); } //List annotations = em.createQuery("select distinct annotation from Annotation as annotation inner join annotation.annotated as annotated inner join annotated.representsResource as uri where uri=?").setParameter(1, _uri).getResultList(); String order_by_clause = " annotation.id desc"; if (asc) order_by_clause = " annotation.id asc"; Query _query = em.createQuery( "select distinct annotation from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=? order by annotation.status," + order_by_clause) .setParameter(1, _uri); _query.setFirstResult(first_indice); _query.setMaxResults(max_results); List<Annotation> annotations = _query.getResultList(); //List annotations = em.createQuery("select distinct annotation from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=? group by annotation.status" ).setParameter(1, _uri).getResultList(); tx.commit(); //em.close(); return annotations; } catch (Exception e) { //tx.commit(); tx.rollback(); //em.close(); System.out.println("[RetrieveAnnotation.retrieveAnnotations] unable to retrieve Annotations" + " cause : " + e.getMessage()); return new ArrayList<Annotation>(); } }