List of usage examples for javax.persistence Query setFirstResult
Query setFirstResult(int startPosition);
From source file:org.medici.bia.dao.document.DocumentDAOJpaImpl.java
/** * {@inheritDoc}//w w w . ja v a 2 s.c o m */ @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; }
From source file:com.gettec.fsnip.fsn.dao.product.impl.ProductDAOImpl.java
/** * ??// www . j a v a2 s. c om * @return Long * @author ZhaWanNeng<br> * * 2015/4/10 */ @SuppressWarnings("unchecked") public List<ProductListVo> getProductList(Long type, int pageSize, int page) throws DaoException { try { String sql = ""; if (type == 3 || type == 5) { String nrv = "0.3"; if (type == 3) { nrv = "0.1"; } sql = " SELECT t.id,t.pname,t.pimg,t.nname,t.nvalue,t.nunit,t.nnrv,t.nper from (" + " SELECT DISTINCT pro.id as id,pro.name as pname,pro.imgUrl as pimg,nr.`name` as nname,nr.value as nvalue,nr.unit as nunit,nr.nrv as nnrv,nr.per as nper " + " FROM product pro LEFT JOIN nutri_rpt nr ON nr.product_id = pro.id " + " WHERE nr.nutri_id =?1 and nr.per='?100' and nr.nrv!='' and nr.nrv!='0' and nr.nrv!='0%' and nr.nrv > " + nrv + " ORDER BY cast(nr.nrv as decimal(10,2)) ASC ) t "; } else { sql = " SELECT t.id,t.pname,t.pimg,t.nname,t.nvalue,t.nunit,t.nnrv,t.nper from (" + " SELECT DISTINCT pro.id as id,pro.name as pname,pro.imgUrl as pimg,nr.`name` as nname,nr.value as nvalue,nr.unit as nunit,nr.nrv as nnrv,nr.per as nper " + " FROM product pro LEFT JOIN nutri_rpt nr ON nr.product_id = pro.id " + " WHERE nr.nutri_id =?1 and nr.per='?100' and nr.nrv!='' ORDER BY cast(nr.nrv as decimal(10,2)) DESC ) t "; } Query query = entityManager.createNativeQuery(sql); query.setParameter(1, type); query.setFirstResult((page - 1) * pageSize); query.setMaxResults(pageSize); List<Object[]> result = query.getResultList(); List<ProductListVo> productListVo = new ArrayList<ProductListVo>(); if (result.size() <= 0) { return null; } for (Object[] obj : result) { ProductNutritionVO vutrition = new ProductNutritionVO(); Long productid = Long.valueOf(obj[0].toString()); String productName = obj[1] != null ? obj[1].toString() : ""; String imgUrl = obj[2] != null ? obj[2].toString() : ""; String name = obj[3] != null ? obj[3].toString() : ""; String value = obj[4] != null ? obj[4].toString() : ""; String unit = obj[5] != null ? obj[5].toString() : ""; String nrv = obj[6] != null ? obj[6].toString() : ""; String per = obj[7] != null ? obj[7].toString() : ""; vutrition.setName(name); vutrition.setNrv(nrv); vutrition.setPer(per); vutrition.setUnit(unit); vutrition.setValue(value); ProductListVo listVo = new ProductListVo(productid, productName, imgUrl, vutrition); productListVo.add(listVo); } return productListVo; } catch (Exception e) { throw new DaoException("ProductDAOImpl.productCount() ", e); } }
From source file:com.gettec.fsnip.fsn.dao.product.impl.ProductDAOImpl.java
/** * ?/*www. java 2 s. c om*/ * @return Long * @author ZhaWanNeng<br> * * 2015/4/10 */ @SuppressWarnings("unchecked") public List<ProductRiskVo> riskBillboard(String type, int pageSize, int page) throws DaoException { try { String sql = ""; if ("14".equals(type) || "10".equals(type) || "01".equals(type)) { sql = " SELECT DISTINCT pro.id,pro.riskIndex,pro.name,pro.imgUrl,pro.test_property_name,pro.risk_succeed FROM product pro " + " WHERE pro.category LIKE '" + type + "_%' and pro.risk_succeed=1 ORDER BY pro.riskIndex ASC "; } else if ("00".equals(type)) { sql = " SELECT DISTINCT pro.id,pro.riskIndex,pro.name,pro.imgUrl,pro.test_property_name,pro.risk_succeed FROM product pro " + " WHERE pro.category not LIKE '14_%' and pro.category not LIKE '10_%' and pro.category not LIKE '01_%' and pro.risk_succeed=1 ORDER BY pro.riskIndex ASC "; } else { return null; } Query query = entityManager.createNativeQuery(sql); // query.setParameter(1, type); query.setFirstResult((page - 1) * pageSize); query.setMaxResults(pageSize); List<Object[]> result = query.getResultList(); List<ProductRiskVo> productList = new ArrayList<ProductRiskVo>(); if (result.size() <= 0) { return null; } for (Object[] obj : result) { Long id = Long.valueOf(obj[0].toString()); String riskIndex = obj[1] != null ? obj[1].toString() : ""; String name = obj[2] != null ? obj[2].toString() : ""; String imgUrl = obj[3] != null ? obj[3].toString() : ""; String testPropertyName = obj[4] != null ? obj[4].toString() : ""; String tes = obj[5] != null ? obj[5].toString() : ""; Boolean riskSucceed = false; if (tes.equals("true")) { riskSucceed = true; } ProductRiskVo productRisk = new ProductRiskVo(id, name, imgUrl, riskIndex, testPropertyName, riskSucceed); productList.add(productRisk); } return productList; } catch (Exception e) { throw new DaoException("ProductDAOImpl.riskBillboard() ", e); } }
From source file:com.tzquery.fsn.dao.impl.TzQueryDaoImpl.java
/** * ?sql/*from w w w. j a va 2 s. c o m*/ * @author ChenXiaolin 2015-12-03 * @param paramVO * @param sql * @return */ @SuppressWarnings("unchecked") private List<TzQueryResponseTansDetailVO> excuteSqlToTransDetail(String sql, TzQueryRequestParamVO paramVO) throws DaoException { try { Query query = entityManager.createNativeQuery(sql); query.setParameter(1, paramVO.getProId()); query.setParameter(2, paramVO.getBusId()); query.setParameter(3, paramVO.getProId()); query.setParameter(4, paramVO.getBusId()); if (paramVO.getPage() > 0 && paramVO.getPageSize() > 0) { query.setFirstResult((paramVO.getPage() - 1) * paramVO.getPageSize()); query.setMaxResults(paramVO.getPageSize()); } List<Object[]> objects = query.getResultList(); return setTransDetail(objects); } catch (Exception e) { throw new DaoException( "TzQueryDaoImpl-->excuteSqlToTransDetail()?sql,?", e); } }
From source file:com.sun.socialsite.userapi.UserManagerImpl.java
public List<User> getUsers(Boolean enabled, Date startDate, Date endDate, int offset, int length) throws UserManagementException { if (endDate == null) { endDate = new Date(); }/*from w w w . ja v a2 s . c o m*/ List<User> users = new ArrayList<User>(); Query query = null; if (enabled != null) { if (startDate != null) { query = getNamedQuery("User.findByEnabled&StartDate&EndDateOrderByCreationDateDESC"); query.setParameter("enabled", enabled); query.setParameter("startDate", startDate, TemporalType.DATE); query.setParameter("endDate", endDate, TemporalType.DATE); } else { query = getNamedQuery("User.findByEnabled&EndDateOrderByCreationDateDESC"); query.setParameter("enabled", enabled); query.setParameter("endDate", endDate, TemporalType.DATE); } } else { if (startDate != null) { query = getNamedQuery("User.findByStartDate&EndDateOrderByCreationDateDESC"); query.setParameter("startDate", startDate, TemporalType.DATE); query.setParameter("endDate", endDate, TemporalType.DATE); } else { query = getNamedQuery("User.findByEndDateOrderByCreationDateDESC"); query.setParameter("endDate", endDate, TemporalType.DATE); } } if (offset != 0) { query.setFirstResult(offset); } if (length != -1) { query.setMaxResults(length); } List results = query.getResultList(); if (results != null) { for (Object obj : results) { users.add((User) obj); } } return users; }
From source file:org.medici.bia.dao.document.DocumentDAOJpaImpl.java
/** * {@inheritDoc}/* w ww .j a va 2 s . c om*/ */ @Override public Page searchLinkedDocumentsTopic(Integer topicId, Integer placeAllId, PaginationFilter paginationFilter) throws PersistenceException { Page page = new Page(paginationFilter); Query query = null; String toSearch = "FROM Document WHERE entryId IN (SELECT document.entryId FROM org.medici.bia.domain.EplToLink WHERE place.geogKey IN (SELECT geogKey FROM Place WHERE placeAllId = " + placeAllId + ") AND topic.topicId = " + topicId + ") 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.apache.roller.weblogger.business.jpa.JPAWeblogEntryManagerImpl.java
/** * @inheritDoc//from w ww .j a v a 2 s . c o m */ public List getWeblogEntries(Weblog website, User user, Date startDate, Date endDate, String catName, List tags, String status, String text, String sortby, String sortOrder, String locale, int offset, int length) throws WebloggerException { WeblogCategory cat = null; if (StringUtils.isNotEmpty(catName) && website != null) { cat = getWeblogCategoryByPath(website, catName); if (cat == null) catName = null; } if (catName != null && catName.trim().equals("/")) { catName = null; } List params = new ArrayList(); int size = 0; StringBuffer queryString = new StringBuffer(); //queryString.append("SELECT e FROM WeblogEntry e WHERE "); if (tags == null || tags.size() == 0) { queryString.append("SELECT e FROM WeblogEntry e WHERE "); } else { queryString.append("SELECT e FROM WeblogEntry e JOIN e.tags t WHERE "); queryString.append("("); for (int i = 0; i < tags.size(); i++) { if (i != 0) queryString.append(" OR "); params.add(size++, tags.get(i)); queryString.append(" t.name = ?").append(size); } queryString.append(") AND "); } if (website != null) { params.add(size++, website.getId()); queryString.append("e.website.id = ?").append(size); } else { params.add(size++, Boolean.TRUE); queryString.append("e.website.enabled = ?").append(size); } /*if (tags != null && tags.size() > 0) { // A JOIN with WeblogEntryTag in parent quert will cause a DISTINCT in SELECT clause // WeblogEntry has a clob field and many databases do not link DISTINCT for CLOB fields // Hence as a workaround using corelated EXISTS query. queryString.append(" AND EXISTS (SELECT t FROM WeblogEntryTag t WHERE " + " t.weblogEntry = e AND t.name IN ("); final String PARAM_SEPERATOR = ", "; for(int i = 0; i < tags.size(); i++) { params.add(size++, tags.get(i)); queryString.append("?").append(size).append(PARAM_SEPERATOR); } // Remove the trailing PARAM_SEPERATOR queryString.delete(queryString.length() - PARAM_SEPERATOR.length(), queryString.length()); // Close the brace FOR IN clause and EXIST clause queryString.append(" ) )"); }*/ if (user != null) { params.add(size++, user.getUserName()); queryString.append(" AND e.creatorUserName = ?").append(size); } if (startDate != null) { Timestamp start = new Timestamp(startDate.getTime()); params.add(size++, start); queryString.append(" AND e.pubTime >= ?").append(size); } if (endDate != null) { Timestamp end = new Timestamp(endDate.getTime()); params.add(size++, end); queryString.append(" AND e.pubTime <= ?").append(size); } if (cat != null && website != null) { params.add(size++, cat.getId()); queryString.append(" AND e.category.id = ?").append(size); } if (status != null) { params.add(size++, status); queryString.append(" AND e.status = ?").append(size); } if (locale != null) { params.add(size++, locale + '%'); queryString.append(" AND e.locale like ?").append(size); } if (text != null) { params.add(size++, '%' + text + '%'); queryString.append(" AND ( e.text LIKE ?").append(size); queryString.append(" OR e.summary LIKE ? ").append(size); queryString.append(" OR e.title LIKE ?").append(size); queryString.append(") "); } if (sortby != null && sortby.equals("updateTime")) { queryString.append(" ORDER BY e.updateTime "); } else { queryString.append(" ORDER BY e.pubTime "); } if (sortOrder != null && sortOrder.equals(ASCENDING)) { queryString.append("ASC "); } else { queryString.append("DESC "); } Query query = strategy.getDynamicQuery(queryString.toString()); for (int i = 0; i < params.size(); i++) { query.setParameter(i + 1, params.get(i)); } if (offset != 0) { query.setFirstResult(offset); } if (length != -1) { query.setMaxResults(length); } return query.getResultList(); }
From source file:com.gettec.fsnip.fsn.dao.product.impl.ProductDAOImpl.java
/** * ???????/* w w w. ja v a 2s. c o m*/ * @param condition * @param page * @param pageSize * @return List<String> * @throws DaoException * @author LongXianZhen */ @SuppressWarnings("unchecked") @Override public List<String> getBarcodeListByCondition(String condition, int page, int pageSize) throws DaoException { try { List<String> barcodes = null; if (StringUtils.isNotBlank(condition)) { String sql = "select barcode from product where barcode like :barcode "; Query query = entityManager.createNativeQuery(sql).setParameter("barcode", "%" + condition + "%"); if (page > 0) { query.setFirstResult((page - 1) * pageSize); query.setMaxResults(pageSize); } barcodes = query.getResultList(); } return barcodes; } catch (Exception e) { throw new DaoException( "ProductDAOImpl.getBarcodeListByCondition()???????, ?", e); } }
From source file:com.tzquery.fsn.dao.impl.TzQueryDaoImpl.java
/** * ??????/* w w w . j a va 2 s. co m*/ * @param paramVO * @return * @throws DaoException */ @Override public List<FacilityInfo> getFacilityInfoList(TzQueryRequestParamVO paramVO) throws DaoException { try { List<FacilityInfo> list = new ArrayList<FacilityInfo>(); StringBuffer sql = new StringBuffer(); sql.append("SELECT f.* FROM facility_info f LEFT JOIN business_unit b ON f.business_id=b.id "); sql.append("WHERE b.`name`=?1 "); if (StringUtils.isNotBlank(paramVO.getProName())) { sql.append(" AND f.facility_name LIKE ?2 "); } sql.append(" ORDER BY f.buying_time desc "); Query query = entityManager.createNativeQuery(sql.toString(), FacilityInfo.class); query.setParameter(1, paramVO.getBusName()); if (StringUtils.isNotBlank(paramVO.getProName())) { query.setParameter(2, "%" + paramVO.getProName() + "%"); } 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-->getFacilityInfoList()???????", e); } }
From source file:com.gettec.fsnip.fsn.dao.product.impl.ProductDAOImpl.java
/** * ???/*from w ww . j av a 2 s . com*/ * @param page * @param size * @param organization * @return * @throws DaoException */ @SuppressWarnings("unchecked") @Override public List<Product> getAllNotLocalProduct(int page, int size, Long organization) throws DaoException { try { String sql = "SELECT p.* FROM product p " + "RIGHT JOIN t_meta_initialize_product t ON p.id=t.product_id " + "WHERE t.`local`=0 AND t.first_storage_id IS NULL AND t.organization=?1"; Query query = entityManager.createNativeQuery(sql.toString(), Product.class); query.setParameter(1, organization); if (page > 0) { query.setFirstResult((page - 1) * size); query.setMaxResults(size); } List<Product> result = query.getResultList(); return result; } catch (Exception e) { throw new DaoException( "ProductDAOImpl.getAllNotLocalProduct() ????", e); } }