List of usage examples for javax.persistence Query setFirstResult
Query setFirstResult(int startPosition);
From source file:org.sakaiproject.kernel.rest.friends.RestFriendsProvider.java
/** * @param params//from w ww. j a v a2 s .c om * @param request * @param response * @return * @throws IOException * @throws RepositoryException * @throws UnsupportedEncodingException */ private Map<String, Object> doStatus(FriendsParams params, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, RepositoryException, IOException { FriendsBean myFriends = friendsResolverService.resolve(params.uuid); Query query = null; StringBuilder sb = new StringBuilder(); sb.append(FriendsIndexBean.FINDBY_UUID_WITH_SORT); if (params.filterStatus != null) { sb.append(" and ").append(FriendsIndexBean.FRIENDS_STATUS_FIELD).append(" = :") .append(FriendsIndexBean.PARAM_FRIENDSTATUS); } if (params.sort != null && params.sort.length > 0) { sb.append(" order by "); for (int i = 0; i < params.sort.length; i++) { if (i != 0) { sb.append(","); } sb.append(" s.").append(params.sort[i]); if (params.sortOrder != null && params.sortOrder.length == params.sort.length) { sb.append(" ").append(params.sortOrder[i]); } } } query = entityManager.createQuery(sb.toString()); query.setFirstResult(params.start); query.setMaxResults(params.end); query.setParameter(FriendsIndexBean.PARAM_UUID, params.uuid); if (params.filterStatus != null) { query.setParameter(FriendsIndexBean.PARAM_FRIENDSTATUS, params.filterStatus.toString()); } List<?> results = query.getResultList(); System.err.println(" Results: " + results.size()); Map<String, FriendBean> myFriendMap = myFriends.friendsMap(); Map<String, FriendBean> sortedFriendMap = Maps.newLinkedHashMap(); for (Object fio : results) { FriendsIndexBean fi = (FriendsIndexBean) fio; FriendBean fb = myFriendMap.get(fi.getFriendUuid()); if (fb != null) { sortedFriendMap.put(fb.getFriendUuid(), fb); UserProfile profile = profileResolverService.resolve(fb.getFriendUuid()); fb.setProfile(profile.getProperties()); Map<String, String> properties = fb.getProperties(); properties.put("userStoragePrefix", userFactoryService.getUserPathPrefix(fb.getFriendUuid())); fb.setProperties(properties); } } myFriends.setFriends(Lists.newArrayList(sortedFriendMap.values())); return ImmutableMap.of("response", "OK", "status", myFriends); }
From source file:com.gettec.fsnip.fsn.dao.business.impl.BusinessUnitDAOImpl.java
/** * ???/*from w w w . ja v a2 s . c o m*/ * @author HuangYog * Create date 2015/04/13 */ @SuppressWarnings("unchecked") @Override public Object getAllBusUnitName(Integer page, Integer pageSize, String keyword, String buType) throws DaoException { try { if (page - 1 < 0) { return null; } String sql = "SELECT DISTINCT name,id FROM business_unit WHERE name IS NOT NULL AND name LIKE '%" + keyword + "%' ";//LIMIT ?3,?4 "; Query query = entityManager.createNativeQuery(sql); if (page > 0 && pageSize > 0) { query.setFirstResult((page - 1) * pageSize); query.setMaxResults(pageSize); } List<Object[]> result = query.getResultList(); List<BusinessNameVO> lists = null; if (result != null && result.size() > 0) { lists = new ArrayList<BusinessNameVO>(); for (Object[] obj : result) { BusinessNameVO vo = new BusinessNameVO(); vo.setId(obj[1] != null ? Long.valueOf(obj[1].toString()) : -1); vo.setName(obj[0] != null ? obj[0].toString() : ""); lists.add(vo); } } return lists; } catch (Exception e) { throw new DaoException("BusinessUnitDAOImpl.getAllBusUnitName()-->" + e.getMessage(), e); } }
From source file:org.medici.bia.dao.user.UserDAOJpaImpl.java
/** * {@inheritDoc}/* w w w.j ava 2 s.c o m*/ */ @SuppressWarnings("unchecked") @Override public Page findForumMembersByText(String text, PaginationFilter paginationFilter) { String queryString = "FROM User WHERE forumJoinedDate IS NOT NULL AND account LIKE '%" + text + "%' ORDER BY account"; // We prepare object of return method. Page page = new Page(paginationFilter); Query query = null; // We set size of result. if (paginationFilter.getPageTotal() == null) { String countQuery = "SELECT COUNT(*) " + queryString; query = getEntityManager().createQuery(countQuery); page.setTotal(new Long((Long) query.getSingleResult())); page.setTotalPages(PageUtils.calculeTotalPages(page.getTotal(), page.getElementsForPage())); } else { page.setTotal(paginationFilter.getTotal()); page.setTotalPages(paginationFilter.getPageTotal()); } query = getEntityManager().createQuery(queryString); // We set pagination query.setFirstResult(PageUtils.calculeStart(page.getThisPage(), page.getElementsForPage())); query.setMaxResults(page.getElementsForPage()); // We manage sorting (this manages sorting on multiple fields) List<User> list = (List<User>) query.getResultList(); // We set search result on return method page.setList(list); return page; }
From source file:org.medici.bia.dao.user.UserDAOJpaImpl.java
/** * {@inheritDoc}/*from w w w. j ava2 s.co m*/ */ @Override public Page findUsers(User user, PaginationFilter paginationFilter) { Page page = new Page(paginationFilter); Query query = null; String jpql = "FROM User "; String condition = getConditionOnUser(user); if (!StringUtils.equals(condition, "")) { jpql = jpql + "WHERE " + condition; } if (paginationFilter.getTotal() == null) { String countQuery = "SELECT COUNT(*) " + jpql; query = getEntityManager().createQuery(countQuery); page.setTotal(new Long((Long) query.getSingleResult())); } paginationFilter = generatePaginationFilterMYSQL(paginationFilter); query = getEntityManager().createQuery(jpql + getOrderByQuery(paginationFilter.getSortingCriterias())); query.setFirstResult(paginationFilter.getFirstRecord()); query.setMaxResults(paginationFilter.getLength()); page.setList(query.getResultList()); return page; }
From source file:org.medici.bia.dao.user.UserDAOJpaImpl.java
/** * {@inheritDoc}// w w w . j a v a 2s . com */ @SuppressWarnings("unchecked") @Override public Page findForumMembers(String letter, PaginationFilter paginationFilter) { String queryString; if (letter.equals("All")) { queryString = "FROM User WHERE forumJoinedDate IS NOT NULL ORDER BY account"; } else { queryString = "FROM User WHERE forumJoinedDate IS NOT NULL AND account LIKE '" + letter + "%' ORDER BY account"; } // We prepare object of return method. Page page = new Page(paginationFilter); Query query = null; // We set size of result. if (paginationFilter.getPageTotal() == null) { String countQuery = "SELECT COUNT(*) " + queryString; query = getEntityManager().createQuery(countQuery); page.setTotal(new Long((Long) query.getSingleResult())); page.setTotalPages(PageUtils.calculeTotalPages(page.getTotal(), page.getElementsForPage())); } else { page.setTotal(paginationFilter.getTotal()); page.setTotalPages(paginationFilter.getPageTotal()); } query = getEntityManager().createQuery(queryString); // We set pagination query.setFirstResult(PageUtils.calculeStart(page.getThisPage(), page.getElementsForPage())); query.setMaxResults(page.getElementsForPage()); // We manage sorting (this manages sorting on multiple fields) List<User> list = (List<User>) query.getResultList(); // We set search result on return method page.setList(list); return page; }
From source file:com.gettec.fsnip.fsn.dao.member.impl.MemberDAOImpl.java
/** * ?//from w w w. j a v a2 s.c o m * @return * @author ZhaWanNeng 2015/04/17 */ @SuppressWarnings("unchecked") public List<Member> getmemberList(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<Member> result = query.getResultList(); return result; } catch (Exception e) { throw new DaoException("MemberDAOImpl.getmemberList()-->> ?", e); } }
From source file:com.gettec.fsnip.fsn.dao.business.impl.BusinessUnitDAOImpl.java
/** * ??????????// ww w .j ava 2s .c o m * @param page * @param pageSize ?? * @param businessName ??? * @param businessType ? * @param startDate ? * @param endDate ?? * @return List<BusinessStaVO> * @throws DaoException * @author LongXianZhen */ @SuppressWarnings("unchecked") @Override public List<BusinessStaVO> findBusinessIdByNameType(int page, int pageSize, String businessName, String businessType, String startDate, String endDate) throws DaoException { try { String new_configure = " WHERE organization IS NOT NULL AND organization!=0 "; //???????? if (!businessName.equals("") && businessName != null) { new_configure = new_configure + " AND e.name like " + "'%" + businessName + "%' "; } //???? if (!businessType.equals("") && businessType != null) { new_configure = new_configure + " AND e.type like " + "'%" + businessType + "%' "; } ////???? if (!startDate.equals("") && !endDate.equals("")) { endDate = DateUtil.addDays(endDate, 1); new_configure = new_configure + " AND e.enterpriteDate BETWEEN '" + startDate + "' AND '" + endDate + "' "; } String jpql = "SELECT e.id,e.name,e.type,e.organization,enterpriteDate FROM business_unit e "; if (new_configure != null && !new_configure.equals("")) { jpql = jpql + " " + new_configure; } Query query = entityManager.createNativeQuery(jpql); if (page != 0 && pageSize != 0) { query.setFirstResult((page - 1) * pageSize); query.setMaxResults(pageSize); } List<Object[]> objs = query.getResultList(); List<BusinessStaVO> businessSta = new ArrayList<BusinessStaVO>(); for (Object[] obj : objs) { BusinessStaVO buSta = new BusinessStaVO(); buSta.setBusinessId(Long.valueOf(obj[0].toString())); buSta.setBusinessName(obj[1] == null ? null : obj[1].toString()); buSta.setBusinessType(obj[2] == null ? null : obj[2].toString()); buSta.setOrganization(obj[3] == null ? null : Long.valueOf(obj[3].toString())); buSta.setEnterpriteDate(obj[4] == null ? null : (Date) obj[4]); businessSta.add(buSta); } return businessSta; } catch (Exception e) { throw new DaoException( "BusinessUnitDAOImpl.findBusinessIdByNameType()-->??????????", e); } }
From source file:org.fracturedatlas.athena.apa.impl.jpa.JpaApaAdapter.java
private Set<JpaRecord> getRecordsByType(AthenaSearch athenaSearch, EntityManager em) { Set<JpaRecord> finishedTicketsSet = null; Query query = em.createQuery("from JpaRecord as ticket where type=:ticketType").setParameter("ticketType", athenaSearch.getType());/*from ww w. j a va 2 s . com*/ if (athenaSearch.getLimit() != null) { query.setMaxResults(athenaSearch.getLimit()); } if (athenaSearch.getStart() != null) { query.setFirstResult(athenaSearch.getStart()); } finishedTicketsSet = new HashSet<JpaRecord>(query.getResultList()); return finishedTicketsSet; }
From source file:com.gettec.fsnip.fsn.dao.business.impl.BusinessUnitDAOImpl.java
/********************************************???*****************************************************/ @Override//from www . j a va 2 s . co m public List<AccountBusinessVO> getAccountEnRegisteList(int page, int pageSize, String province, String city, String area, String nameOrLicNo, String btype) throws DaoException { try { Map<String, Map<String, String>> map = setParam(province, city, area, nameOrLicNo, btype); Object condition = ""; Map<String, String> param = null; if (map != null && map.size() > 0) { condition = map.keySet().iterator().next(); param = map.get(condition); } String sql = "SELECT e.id,e.name,e.license_no,e.person_in_charge,e.type,e.enterpriteDate, " + "e.address,e.contact,e.telephone FROM business_unit e WHERE e.`name` IS NOT NULL " + "AND e.`name` <> '' AND e.organization IS NOT NULL AND e.organization <> '' " + condition.toString() + " ORDER BY e.id "; Query query = entityManager.createNativeQuery(sql.toString()); getParam(param, query); if (page > 0) { query.setFirstResult((page - 1) * pageSize).setMaxResults(pageSize); } List<Object[]> result = query.getResultList(); return result != null && result.size() > 0 ? setListAccountBusinessVO(result) : null; } catch (Exception e) { throw new DaoException("BusinessUnitDAOImpl.getAccountEnRegisteList()", e); } }
From source file:com.lhfs.fsn.dao.testReport.impl.TestReportDaoImpl.java
@SuppressWarnings("unchecked") @Override//from w w w.j a va 2s .com public List<ProductInfoVO> getByLicenseNoProduct(String licenseNo, Integer page, Integer pageSize) { String sql = "SELECT p.id,p.name,p.barcode FROM product p "; sql += " LEFT JOIN business_unit bu ON bu.id=p.producer_id "; sql += " WHERE bu.license_no = ?1"; Query query = entityManager.createNativeQuery(sql); query.setParameter(1, licenseNo); // ? if (page > 0) { query.setFirstResult((page - 1) * pageSize); query.setMaxResults(pageSize); } List<Object[]> objs = query.getResultList(); List<ProductInfoVO> proList = new ArrayList<ProductInfoVO>(); for (Object[] obj : objs) { ProductInfoVO vo = new ProductInfoVO(); vo.setProductId(obj[0] == null ? null : Long.parseLong(obj[0].toString())); vo.setProductName(obj[1] == null ? null : obj[1].toString()); vo.setBarcode(obj[2] == null ? null : obj[2].toString()); proList.add(vo); } return proList; }