List of usage examples for javax.persistence Query setMaxResults
Query setMaxResults(int maxResult);
From source file:com.tzquery.fsn.dao.impl.TzQueryDaoImpl.java
/** * ?id??/*from w w w . j ava 2 s. c om*/ * @param paramVO * @param fId * @return * @throws DaoException */ @Override public List<FacilityMaintenanceRecord> getFacilityMaintenanceRecordList(TzQueryRequestParamVO paramVO, Long fId) throws DaoException { try { List<FacilityMaintenanceRecord> list = new ArrayList<FacilityMaintenanceRecord>(); StringBuffer sql = new StringBuffer(); sql.append( "SELECT * FROM facility_maintenance_record WHERE facility_id=?1 ORDER BY maintenance_time desc"); Query query = entityManager.createNativeQuery(sql.toString(), FacilityMaintenanceRecord.class); query.setParameter(1, fId); if (paramVO.getPage() > 0 && paramVO.getPageSize() > 0) { query.setFirstResult((paramVO.getPage() - 1) * paramVO.getPageSize()); query.setMaxResults(paramVO.getPageSize()); } list = query.getResultList(); return list; } catch (Exception e) { throw new DaoException( "TzQueryDaoImpl-->getFacilityMaintenanceRecordList()?id???", e); } }
From source file:br.org.indt.ndg.server.survey.SurveyHandlerBean.java
public QueryInputOutputVO listSurveysByImeiDBWithoutResults(String imei, String status, QueryInputOutputVO queryIOVO) throws MSMApplicationException, MSMSystemException { if (queryIOVO == null) { queryIOVO = new QueryInputOutputVO(); }/*from w w w . j a va 2s . c o m*/ NdgUser user = businessDelegate.getUserByImei(imei); String sqlCommand = "from Transactionlog t where transactionType = " + "\'" + TransactionLogVO.TYPE_SEND_SURVEY + "\' " + "and imei.imei = :imei " + "and transactionStatus = :status "; if ((queryIOVO.getFilterText() != null) && (queryIOVO.getFilterFields() != null)) { sqlCommand += SqlUtil.getFilterCondition(queryIOVO.getFilterText(), queryIOVO.getFilterFields()); } sqlCommand += " group by t.survey.idSurvey "; if ((queryIOVO.getSortField() != null) && (queryIOVO.getIsDescending() != null)) { sqlCommand += SqlUtil.getSortCondition(queryIOVO.getSortField(), queryIOVO.getIsDescending()); } Query q = manager.createQuery(sqlCommand); q.setParameter("imei", imei); q.setParameter("status", status); queryIOVO.setRecordCount(q.getResultList().size()); if ((queryIOVO.getPageNumber() != null) && (queryIOVO.getRecordsPerPage() != null)) { q.setFirstResult((queryIOVO.getPageNumber() - 1) * queryIOVO.getRecordsPerPage()); q.setMaxResults(queryIOVO.getRecordsPerPage()); } ArrayList<Transactionlog> al = (ArrayList<Transactionlog>) q.getResultList(); Iterator<Transactionlog> it = al.iterator(); ArrayList<Object> surveyList = new ArrayList<Object>(); while (it.hasNext()) { SurveyXML survey = null; Transactionlog surveyTransactionLog = (Transactionlog) it.next(); SurveyVO vo = new SurveyVO(); vo.setIdSurvey(surveyTransactionLog.getSurvey().getIdSurvey()); survey = loadSurveyDB(user.getUserAdmin(), surveyTransactionLog.getSurvey().getIdSurvey()); CreateXml.xmlToString(survey.getXmldoc()); Survey surveyPojo = manager.find(Survey.class, surveyTransactionLog.getSurvey().getIdSurvey()); try { byte[] stringXMLByte = surveyPojo.getSurveyXml().getBytes("UTF-8"); vo.setSurvey(new String(stringXMLByte, "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } vo.setTitle(survey.getTitle()); vo.setResultsSent(survey.getResultsSize()); vo.setStatus(surveyTransactionLog.getTransactionStatus()); surveyList.add(vo); } queryIOVO.setQueryResult(surveyList); return queryIOVO; }
From source file:it.webappcommon.lib.jpa.ControllerStandard.java
public <T extends EntityBaseStandard> List<T> findList(Class<T> classObj, String query, Map<String, Object> map, int firstItem, int batchSize) throws Exception { List<T> returnValue = null; EntityManagerFactory emf = null;// ww w .j av a 2 s .c o m EntityManager em = null; Query q = null; Iterator i = null; Map.Entry entry = null; try { emf = getEntityManagerFactory(); em = emf.createEntityManager(); q = em.createNamedQuery(query); if (batchSize > 0) { q.setFirstResult(firstItem); q.setMaxResults(batchSize); } if (map != null) { for (i = map.entrySet().iterator(); i.hasNext();) { entry = (Map.Entry) i.next(); q.setParameter((String) entry.getKey(), entry.getValue()); } } returnValue = (List<T>) q.getResultList(); } catch (Exception e) { throw e; } finally { if (!passedEm) { PersistenceManagerUtil.close(em); } em = null; q = null; i = null; entry = null; } return returnValue; }
From source file:com.gettec.fsnip.fsn.dao.product.impl.ProductDAOImpl.java
/** * ??/*from w w w . jav a 2 s . c om*/ * @return * @author ZhaWanNeng 2015/04/17 */ @SuppressWarnings("unchecked") public List<Product> getproductList(int pageSize, int page) throws DaoException { try { String sql = " SELECT e FROM " + entityClass.getName() + " e "; Query query = entityManager.createQuery(sql); query.setFirstResult((page - 1) * pageSize); query.setMaxResults(pageSize); List<Product> result = query.getResultList(); return result; } catch (Exception e) { throw new DaoException("ProductDAOImpl.getproductList()-->> ?", e); } }
From source file:com.tzquery.fsn.dao.impl.TzQueryDaoImpl.java
/** * ??ID??/*w w w.ja v a 2s . c om*/ * @author ChenXiaolin 2015-12-02 * @param paramVO * @return * @throws DaoException */ @SuppressWarnings("unchecked") @Override public List<TzQueryResponseBusVO> getSaleBusiness(TzQueryRequestParamVO paramVO) throws DaoException { try { StringBuffer sb_qyery = new StringBuffer(" and bus.other_address LIKE '"); if (StringUtil.isNotEmpty(paramVO.getProvice())) { //? sb_qyery.append(paramVO.getProvice()).append("-"); } if (StringUtil.isNotEmpty(paramVO.getCity())) { // sb_qyery.append(paramVO.getCity()).append("-"); } if (StringUtil.isNotEmpty(paramVO.getArea())) { // sb_qyery.append(paramVO.getArea()); } sb_qyery.append("%'"); StringBuffer sb = new StringBuffer(); sb.append(" select * from ("); sb.append( " SELECT pro.name proName,pro.category cat,pro.barcode bar, bus.id busId,bus.other_address oadd,bus.name busName,"); sb.append( "bus.license_no lic,bus.type type,bus.address addr,IF(bus.id=pro.producer_id,'','??') relation,pro.id"); sb.append(" FROM tz_stock stock "); sb.append(" INNER JOIN business_unit bus ON bus.id = stock.business_id "); sb.append(" INNER JOIN product pro ON pro.id = stock.product_id"); sb.append(" WHERE stock.product_id = ?1"); sb.append(sb_qyery); sb.append(" GROUP BY bus.id ) test"); Query query = entityManager.createNativeQuery(sb.toString()); query.setParameter(1, Long.parseLong(paramVO.getProId())); if (paramVO.getPage() > 0 && paramVO.getPageSize() > 0) { query.setFirstResult((paramVO.getPage() - 1) * paramVO.getPageSize()); query.setMaxResults(paramVO.getPageSize()); } List<Object[]> objects = query.getResultList(); return setSaleBusiness(objects); } catch (Exception e) { throw new DaoException( "TzQueryDaoImpl-->getSaleBusiness()??ID?? ,?", e); } }
From source file:org.hoteia.qalingo.core.dao.RetailerDao.java
public List<GeolocatedStore> findB2CStoresByGeoloc(final String countryCode, final Long productBrandId, final List<String> types, final String latitude, final String longitude, final String distance, int maxResults, Object... params) { if (StringUtils.isNotEmpty(latitude) && StringUtils.isNotEmpty(longitude)) { Float latitudeFloat = new Float(latitude); Float longitudeFloat = new Float(longitude); StringBuilder queryString = buildSQLStoresByGeoloc(countryCode, productBrandId, types, latitude, longitude, distance, maxResults, params); queryString.append("AND is_b2c = :b2c "); if (distance != null) { queryString.append("HAVING distance <= :distanceValue "); } else {//from ww w . j a v a 2s. com queryString.append("HAVING distance IS NOT null "); } queryString.append("ORDER BY distance ASC"); Query query = createNativeQuery(queryString.toString()); query.setParameter("latitude", latitudeFloat); query.setParameter("longitude", longitudeFloat); if (distance != null) { query.setParameter("distanceValue", distance); } query.setParameter("b2c", true); if (StringUtils.isNotEmpty(countryCode)) { query.setParameter("countryCode", countryCode); } if (productBrandId != null) { query.setParameter("productBrandId", productBrandId); } if (types != null && !types.isEmpty()) { int count = 1; for (String type : types) { query.setParameter("type" + count, "%" + type + "%"); count++; } } query.setParameter("active", true); query.setMaxResults(maxResults); query.unwrap(SQLQuery.class).addScalar("id", LongType.INSTANCE).addScalar("code", StringType.INSTANCE) .addScalar("distance", DoubleType.INSTANCE); @SuppressWarnings("unchecked") List<Object[]> objects = query.getResultList(); List<GeolocatedStore> stores = new ArrayList<GeolocatedStore>(); for (Object[] object : objects) { GeolocatedStore geolocatedStore = new GeolocatedStore(); geolocatedStore.setId((Long) object[0]); geolocatedStore.setCode((String) object[1]); geolocatedStore.setDistance((Double) object[2]); stores.add(geolocatedStore); } return stores; } return null; }
From source file:com.tzquery.fsn.dao.impl.TzQueryDaoImpl.java
/** * ???//from w ww .j a v a 2 s. c om * @author ChenXiaolin 2015-12-04 * @param paramVO * @return * @throws DaoException */ @SuppressWarnings("unchecked") @Override public List<TzQueryResponseTansDetailVO> getBusQueryTransDetail(TzQueryRequestParamVO paramVO) throws DaoException { try { StringBuffer sb = new StringBuffer(); sb.append( " SELECT pro.barcode,pro.name,pro.format,acInfo.product_batch,acInfo.production_date,account.create_time,acInfo.product_num"); sb.append(" FROM tz_business_account account"); sb.append(" INNER JOIN tz_business_account_info acInfo ON account.id = acInfo.business_account_id"); sb.append(" INNER JOIN product pro ON pro.id = acInfo.product_id"); sb.append(" INNER JOIN business_unit inBus ON inBus.id = account.in_business_id"); sb.append(" INNER JOIN business_unit outBus ON outBus.id = account.out_business_id"); if (paramVO.getSalesType() == 0) {//????? sb.append(" WHERE account.out_business_id = ?1 AND inBus.id = ?2"); } else if (paramVO.getSalesType() == 1) {//????? sb.append(" WHERE account.in_business_id = ?1 AND outBus.id = ?2"); } /* ? */ if (StringUtil.isNotEmpty(paramVO.getProBarcode())) {//??? sb.append(" AND pro.barcode LIKE '%").append(paramVO.getProBarcode()).append("%'"); } if (StringUtil.isNotEmpty(paramVO.getProName())) {//??? sb.append(" AND pro.name LIKE '%").append(paramVO.getProName()).append("%'"); } if (StringUtil.isNotEmpty(paramVO.getTransSDate())) { sb.append(" AND account.create_time >= '").append(paramVO.getTransSDate()).append(" 00:00:00") .append("'"); } if (StringUtil.isNotEmpty(paramVO.getTransEDate())) { sb.append(" AND account.create_time <= '").append(paramVO.getTransEDate()).append(" 23:59:59") .append("'"); } sb.append(" ORDER BY account.create_time DESC"); /* sql */ Query query = entityManager.createNativeQuery(sb.toString()); query.setParameter(1, paramVO.getBusId()); query.setParameter(2, paramVO.getFirstBusId()); if (paramVO.getPage() > 0 && paramVO.getPageSize() > 0) { query.setFirstResult((paramVO.getPage() - 1) * paramVO.getPageSize()); query.setMaxResults(paramVO.getPageSize()); } List<Object[]> objects = query.getResultList(); return setBusQueryDetail(objects); } catch (Exception e) { throw new DaoException( "TzQueryDaoImpl-->getBusQueryTransDetail()???,?", e); } }
From source file:org.medici.bia.dao.document.DocumentDAOJpaImpl.java
/** * {@inheritDoc}/*from w w w . j av a2s .co m*/ */ @Override public Page searchDocumentsRelated(String personToSearch, PaginationFilter paginationFilter) throws PersistenceException { Page page = new Page(paginationFilter); Query query = null; String toSearch = new String( "FROM Document WHERE entryId IN (SELECT document.entryId FROM org.medici.bia.domain.EpLink WHERE person.personId=" + personToSearch + ") AND logicalDelete=false"); if (paginationFilter.getTotal() == null) { String countQuery = "SELECT COUNT(*) " + toSearch; query = getEntityManager().createQuery(countQuery); page.setTotal(new Long((Long) query.getSingleResult())); } paginationFilter = generatePaginationFilterMYSQL(paginationFilter); query = getEntityManager().createQuery(toSearch + getOrderByQuery(paginationFilter.getSortingCriterias())); query.setFirstResult(paginationFilter.getFirstRecord()); query.setMaxResults(paginationFilter.getLength()); page.setList(query.getResultList()); return page; }
From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java
License:asdf
@TransactionAttribute(TransactionAttributeType.SUPPORTS) @Override//from w w w . ja v a2s . c om public Certificate findMostRecentlyUpdatedActiveCertificate(byte[] subjectKeyId) { Certificate certificate = null; final String subjectKeyIdString = new String(Base64.encode(subjectKeyId, false)); log.debug("Searching for subjectKeyIdString " + subjectKeyIdString); final Query query = this.entityManager.createQuery( "SELECT a FROM CertificateData a WHERE a.subjectKeyId=:subjectKeyId AND a.status=:status ORDER BY a.updateTime DESC"); query.setParameter("subjectKeyId", subjectKeyIdString); query.setParameter("status", CertificateConstants.CERT_ACTIVE); query.setMaxResults(1); @SuppressWarnings("unchecked") final List<CertificateData> resultList = query.getResultList(); if (resultList.size() == 1) { certificate = resultList.get(0).getCertificate(this.entityManager); if (certificate == null && log.isDebugEnabled()) { log.debug("Reference to an issued certificate with subjectKeyId " + subjectKeyId + " found, but the certificate is not stored in the database."); } } return certificate; }
From source file:org.medici.bia.dao.document.DocumentDAOJpaImpl.java
/** * {@inheritDoc}//from w ww. jav a 2 s .c om */ @Override public Page searchReferringToDocumentsPerson(String personToSearch, PaginationFilter paginationFilter) throws PersistenceException { Page page = new Page(paginationFilter); Query query = null; String toSearch = new String( "FROM Document WHERE entryId IN (SELECT document.entryId FROM org.medici.bia.domain.EpLink WHERE person.personId=" + personToSearch + " AND docRole is null) AND logicalDelete=false "); if (paginationFilter.getTotal() == null) { String countQuery = "SELECT COUNT(*) " + toSearch; query = getEntityManager().createQuery(countQuery); page.setTotal(new Long((Long) query.getSingleResult())); } paginationFilter = generatePaginationFilterMYSQL(paginationFilter); query = getEntityManager().createQuery(toSearch + getOrderByQuery(paginationFilter.getSortingCriterias())); query.setFirstResult(paginationFilter.getFirstRecord()); query.setMaxResults(paginationFilter.getLength()); page.setList(query.getResultList()); return page; }