當前位置: 首頁>>代碼示例>>Java>>正文


Java Query.setMaxResults方法代碼示例

本文整理匯總了Java中javax.persistence.Query.setMaxResults方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.setMaxResults方法的具體用法?Java Query.setMaxResults怎麽用?Java Query.setMaxResults使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.persistence.Query的用法示例。


在下文中一共展示了Query.setMaxResults方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNotifications

import javax.persistence.Query; //導入方法依賴的package包/類
public List<Notificaciones> getNotifications(boolean all, int maxResults, int firstResult, String _id) {
    EntityManager em = getEntityManager();
    List<Notificaciones> result = new ArrayList<>();
    try {
        Query q = em.createNativeQuery(String.format(SQL_NOTIFICATION, _id), Notificaciones.class);

        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        result = q.getResultList();
        return result;
    } finally {
        em.close();
    }
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:17,代碼來源:NotificacionesJpaController.java

示例2: findRecent

import javax.persistence.Query; //導入方法依賴的package包/類
@GET
@Path("/recent/")
@Produces({"application/xml", "application/json"})
public List<TransitCumulativeSales> findRecent() {     
    Query baseRangeQuery = em.createQuery(BASE_RANGE_QUERY); 
    //Query baseRangeQuery = getEntityManager().createQuery(BASE_RANGE_QUERY);
    baseRangeQuery.setMaxResults(200);
    List<TransitCumulativeSales> result = new ArrayList<TransitCumulativeSales>();
    List<Object[]> resultList = baseRangeQuery.getResultList();
    System.out.print("hello world");
    for (int i=0; i < resultList.size(); i++){
        Object o[] = resultList.get(i);
        TransitCumulativeSales t = new TransitCumulativeSales();
        t.setStartDailySalesId((Integer)o[0]);
        t.setEndDailySalesId((Integer)o[1]);
        t.setCost((Double)o[2]);
        t.setSales((Double) o[3]);
        t.setDate((Date)o[4]);
        result.add(t);
    }
    return result;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:23,代碼來源:CumulativeLiveSalesFacadeREST.java

示例3: findPersonaEntities

import javax.persistence.Query; //導入方法依賴的package包/類
private List<Usuario> findPersonaEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Usuario.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:16,代碼來源:UsuarioJpaController.java

示例4: findRecentProductTypeFrom

import javax.persistence.Query; //導入方法依賴的package包/類
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/producttype/{id}/{orderLineId}")
public List<LiveSalesList> findRecentProductTypeFrom(@PathParam("id") Integer productTypeId, @PathParam("orderLineId") Integer orderLineId) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
    Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
    cq.select(liveSalesList);
    cq.where(cb.and(
        cb.equal(liveSalesList.get(LiveSalesList_.productTypeId), productTypeId),
        cb.gt(liveSalesList.get(LiveSalesList_.orderLineId), orderLineId)
    ));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:17,代碼來源:LiveSalesListFacadeREST.java

示例5: loadOperatorRevenueSharePercentage

import javax.persistence.Query; //導入方法依賴的package包/類
@Override
public BigDecimal loadOperatorRevenueSharePercentage(long serviceKey,
        long endPeriod) {
    Query query = dm
            .createNamedQuery("RevenueShareModelHistory.findOperatorRevenueSharePercentage");
    query.setParameter("productObjKey", Long.valueOf(serviceKey));
    query.setParameter("modDate", new Date(endPeriod));
    query.setMaxResults(1);

    BigDecimal percentage;
    try {
        RevenueShareModelHistory revenueShareModelHistory = (RevenueShareModelHistory) query
                .getSingleResult();
        percentage = revenueShareModelHistory.getDataContainer()
                .getRevenueShare();
    } catch (NoResultException e) {
        logger.logError(
                Log4jLogger.SYSTEM_LOG,
                e,
                LogMessageIdentifier.ERROR_OPERATOR_REVENUE_SHARE_OF_SERVICE_NOT_FOUND,
                Long.toString(serviceKey));
        throw e;
    }
    return percentage;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:26,代碼來源:SharesDataRetrievalServiceBean.java

示例6: findLastRelevantJobHistory

import javax.persistence.Query; //導入方法依賴的package包/類
/**
 * Finds the most recently started job history record matching the given jobName/env1/env2 which is no older
 * than maxAge.  Null if none found.
 */
public JobHistory findLastRelevantJobHistory(String jobName, String env1, String env2, long maxAge)
{
  String queryString = "SELECT jh FROM " + JobHistory.class.getSimpleName() + " jh WHERE "
      + "jh.jobName = '" + jobName + "' "
      + "AND jh.env1 = '" + env1 + "' "
      + "AND " + makeNullableCondition("jh.env2", env2) + " "
      + "AND jh.startTime > :oldestAllowedStartTime "
      + "ORDER BY jh.startTime DESC ";
  Query query = entityManager.createQuery(queryString);
  query.setParameter("oldestAllowedStartTime", makeTimestampBeforeNow(maxAge));
  query.setMaxResults(1);
  List<JobHistory> results = query.getResultList();
  if (results != null && results.size() > 0)
  {
    return results.get(0);
  }
  else
  {
    return null;
  }
}
 
開發者ID:Nike-Inc,項目名稱:bluegreen-manager,代碼行數:26,代碼來源:JobHistoryDAO.java

示例7: pagingQuery

import javax.persistence.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void pagingQuery(String jpql,String countJpql,Page<?> page,Map<String,Object> parameter,String dataSourceName){
	EntityManager em=this.getEntityManager(dataSourceName);
	Query query=em.createQuery(jpql);
	if(parameter!=null){
		this.setParameter(query, parameter);				
	}
	query.setFirstResult((page.getPageNo()-1)*page.getPageSize());
	query.setMaxResults(page.getPageSize());
	page.setEntities(query.getResultList());
	Query countQuery=em.createQuery(countJpql);
	if(parameter!=null){
		this.setParameter(countQuery, parameter);				
	}
	int count=0;
	Object obj=countQuery.getSingleResult();
	if(obj instanceof Integer){
		count=(Integer)obj;
	}else if(obj instanceof Long){
		count=((Long)obj).intValue();
	}else{
		throw new IllegalArgumentException("The ql["+countJpql+"] fetch result is "+obj+",can not convert to int value");
	}
	page.setEntityCount(count);
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:26,代碼來源:JpaDao.java

示例8: queryByMapParams

import javax.persistence.Query; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
public List queryByMapParams(String hql, Map<String, Object> params, Integer currentPage,Integer pageSize){
	//EntityManager em = this.emf.createEntityManager();
	Query query = em.createQuery(hql);
	List list = null;
	try {
		if(params != null && !params.isEmpty()){
			for(Map.Entry<String,Object> entry: params.entrySet()){
				query.setParameter(entry.getKey(), entry.getValue());
			}
		}
		
		if(currentPage != null && pageSize != null){
			query.setFirstResult((currentPage-1)*pageSize);
			query.setMaxResults(pageSize);
		}
		list = query.getResultList();
	} catch (Exception e) {
		e.printStackTrace();
	}finally{
		em.close();
	}
	
	return list;
}
 
開發者ID:xujeff,項目名稱:tianti,代碼行數:26,代碼來源:CustomBaseSqlDaoImpl.java

示例9: getPrevious

import javax.persistence.Query; //導入方法依賴的package包/類
public Menu getPrevious(@NotNull LocalDate current) {
    Query query = em.createQuery("select m from Menu m where (m.date < :current) order by m.date DESC ");
    query.setParameter("current", current);
    query.setMaxResults(1);

    List list = query.getResultList();
    if (list.isEmpty()) {
        return null;
    } else {
        return (Menu) list.get(0);
    }
}
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:13,代碼來源:MenuEJB.java

示例10: canBeDeleted

import javax.persistence.Query; //導入方法依賴的package包/類
public boolean canBeDeleted(long id){

        Dish dish = getDish(id);
        if(dish == null){
            return false;
        }

        Query query = em.createQuery("select m from Menu m where :dish member of m.dishes");
        query.setParameter("dish", dish);
        query.setMaxResults(1);
        List results = query.getResultList();

        return results==null || results.isEmpty();
    }
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:15,代碼來源:DishEJB.java

示例11: findRecent

import javax.persistence.Query; //導入方法依賴的package包/類
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/")
public List<LiveSalesList> findRecent() {
    javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
    cq.select(cq.from(LiveSalesList.class));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:11,代碼來源:LiveSalesListFacadeREST.java

示例12: getNext

import javax.persistence.Query; //導入方法依賴的package包/類
public Menu getNext(@NotNull LocalDate current) {
    Query query = em.createQuery("select m from Menu m where (m.date > :current) order by m.date ASC ");
    query.setParameter("current", current);
    query.setMaxResults(1);

    List list = query.getResultList();
    if (list.isEmpty()) {
        return null;
    } else {
        return (Menu) list.get(0);
    }
}
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:13,代碼來源:MenuEJB.java

示例13: setPaginationParameters

import javax.persistence.Query; //導入方法依賴的package包/類
private void setPaginationParameters(PaginationInt pagination,
        Query query) {
    setSortingParameter(query, pagination);
    setFilterParameters(query, pagination);

    query.setFirstResult(pagination.getOffset());
    query.setMaxResults(pagination.getLimit());
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:9,代碼來源:UserSubscriptionDao.java

示例14: loadVendorHistoryOfProduct

import javax.persistence.Query; //導入方法依賴的package包/類
private OrganizationHistory loadVendorHistoryOfProduct(long serviceKey) {
    Query query = dm
            .createNamedQuery("OrganizationHistory.findVendorOfProduct");
    query.setParameter("productKey", Long.valueOf(serviceKey));
    query.setMaxResults(1);
    try {
        return (OrganizationHistory) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:12,代碼來源:SharesDataRetrievalServiceBean.java

示例15: queryForPageBySql

import javax.persistence.Query; //導入方法依賴的package包/類
/**
 * 根據SQL語句查詢分頁
 * @param sql
 * @param currentPage
 * @param pageSize
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public PageModel queryForPageBySql(String sql,Integer currentPage,Integer pageSize){
	PageModel page = new PageModel();
	Integer totalCount = 0;
	Integer totalPage = 0;
	
	//EntityManager em = this.emf.createEntityManager();
	Query qry = em.createNativeQuery(sql);
	Query qry2 = em.createNativeQuery(sql);
	SQLQuery s = qry.unwrap(SQLQuery.class);
	if (currentPage != null && pageSize != null) {//判斷是否有分頁
		// 起始對象位置
		qry.setFirstResult(pageSize * (currentPage - 1));
		// 查詢對象個數
		qry.setMaxResults(pageSize);
	}
	s.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
	List<Map> resultList=new ArrayList<Map>();
	List list = qry2.getResultList();
	totalCount = (list == null ? 0 : list.size());
	if(totalCount % pageSize == 0){
		totalPage = totalCount/pageSize;
	}else{
		totalPage = totalCount/pageSize + 1;
	}
	try {
		resultList=s.list();
		page.setCurrentPage(currentPage);
		page.setPageSize(pageSize);
		page.setList(resultList);
		page.setTotalCount(totalCount);
		page.setTotalPage(totalPage);
	} catch (Exception e) {
		e.printStackTrace();
	}finally{
		em.close();
	}		
	return page;
}
 
開發者ID:xujeff,項目名稱:tianti,代碼行數:47,代碼來源:CustomBaseSqlDaoImpl.java


注:本文中的javax.persistence.Query.setMaxResults方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。