当前位置: 首页>>代码示例>>Java>>正文


Java Query.setFirstResult方法代码示例

本文整理汇总了Java中javax.persistence.Query.setFirstResult方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setFirstResult方法的具体用法?Java Query.setFirstResult怎么用?Java Query.setFirstResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.Query的用法示例。


在下文中一共展示了Query.setFirstResult方法的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: 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

示例3: executeObjectQuery

import javax.persistence.Query; //导入方法依赖的package包/类
/**
 * Searches for products
 * 
 * @return found VO services
 */
@SuppressWarnings("unchecked")
private List<Product> executeObjectQuery() {
    Query query = dm.createNativeQuery(sql, Product.class);
    setParameters(query);

    if (listCriteria.getOffset() > 0) {
        query.setFirstResult(listCriteria.getOffset());
        doCountQuery = true;
    }

    if (listCriteria.getLimit() >= 0) {
        query.setMaxResults(listCriteria.getLimit());
        doCountQuery = true;
    }

    List<Product> result = query.getResultList();
    return result;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:ProductSearch.java

示例4: findByNative

import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public <X> List<X> findByNative(String sql, List<?> params, Pageable pageable, Class<X> clazz) {
    Assert.hasText(sql, "native sql can not been null or blank");
    Query query = entityManager.createNativeQuery(sql);
    if (query != null) {
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.aliasToBean(clazz));
        query.setFirstResult(pageable.getOffset());
        query.setMaxResults(pageable.getPageSize());
        if (CollectionUtils.isNotEmpty(params)) {
            for (int i = 0; i < params.size(); i++) {
                query.setParameter(i + 1, params.get(i));
            }
        }
        return query.getResultList();
    }
    return Lists.newArrayList();
}
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:18,代码来源:BaseRepositoryImpl.java

示例5: setupQuery

import javax.persistence.Query; //导入方法依赖的package包/类
protected Query setupQuery(Query typedQuery) {
	// apply graph control
	if (!fetchPaths.isEmpty()) {
		applyFetchPaths(typedQuery);
	}

	// control Hibernate query caching
	if (cached) {
		typedQuery.setHint("org.hibernate.cacheable", Boolean.TRUE);
	}

	if (limit > 0) {
		typedQuery.setMaxResults(limit);
	}
	typedQuery.setFirstResult(offset);
	return typedQuery;
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:18,代码来源:AbstractQueryExecutorImpl.java

示例6: querySqlObjects

import javax.persistence.Query; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<Map<String, Object>> querySqlObjects(String sql, Object params, Integer currentPage,Integer rowsInPage){
	Query qry = em.createNativeQuery(sql);
	SQLQuery s = qry.unwrap(SQLQuery.class);
	
	//设置参数
	if(params != null){
		if(params instanceof List){
			List<Object> paramList = (List<Object>) params;
			for(int i = 0, size = paramList.size(); i < size; i++){
				qry.setParameter(i+1, paramList.get(i));
			}
		}else if(params instanceof Map){
			Map<String, Object> paramMap = (Map<String, Object>) params;
			for(String key : paramMap.keySet()){
				qry.setParameter(key, paramMap.get(key));
			}
		}
	}
	
	if (currentPage != null && rowsInPage != null) {//判断是否有分页
		// 起始对象位置
		qry.setFirstResult(rowsInPage * (currentPage - 1));
		// 查询对象个数
		qry.setMaxResults(rowsInPage);
	}
	s.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
	List<Map<String, Object>> resultList=new ArrayList<Map<String, Object>>();
	try {
		resultList=s.list();
	} catch (Exception e) {
	}finally{
		em.close();
	}
	return resultList;
}
 
开发者ID:xujeff,项目名称:tianti,代码行数:37,代码来源:CustomBaseSqlDaoImpl.java

示例7: 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

示例8: 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

示例9: findTelefonoEntities

import javax.persistence.Query; //导入方法依赖的package包/类
private List<Telefono> findTelefonoEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Telefono.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:16,代码来源:TelefonoJpaController.java

示例10: find

import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public <X> List<X> find(String hql, Map<String, ?> params, Pageable pageable, Class<X> clazz) {
    Assert.hasText(hql, "hql can not been null or blank");
    Query query = entityManager.createQuery(hql);
    if (query != null) {
        query.unwrap(QueryImpl.class).setResultTransformer(Transformers.aliasToBean(clazz));
        query.setFirstResult(pageable.getOffset());
        query.setMaxResults(pageable.getPageSize());
        if (params != null) {
            params.entrySet().forEach(param -> query.setParameter(param.getKey(), param.getValue()));
        }
        return query.getResultList();
    }
    return Lists.newArrayList();
}
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:16,代码来源:BaseRepositoryImpl.java

示例11: setPaginationParameters

import javax.persistence.Query; //导入方法依赖的package包/类
private void setPaginationParameters(PaginationUsersInUnit pagination,
        Query query) {
    setSortingParameter(query, pagination);
    setFilterParameters(query, pagination);

    query.setFirstResult(pagination.getOffset());
    query.setMaxResults(pagination.getLimit());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:9,代码来源:UserGroupUsersDao.java

示例12: getVisibleServices

import javax.persistence.Query; //导入方法依赖的package包/类
public List<Product> getVisibleServices(String unitId,
        Pagination pagination, String marketplaceId) {
    Query query = dm.createNamedQuery("UserGroup.findVisibleServices");
    query.setParameter("userGroupKey", Long.valueOf(unitId));
    query.setParameter("marketplaceKey", Long.valueOf(marketplaceId));
    query.setFirstResult(pagination.getOffset());
    query.setMaxResults(pagination.getLimit());
    List<Product> visibleProducts = ParameterizedTypes.list(
            query.getResultList(), Product.class);
    return visibleProducts;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:UserGroupDao.java

示例13: setPaginationParameters

import javax.persistence.Query; //导入方法依赖的package包/类
private void setPaginationParameters(Pagination pagination, Query query) {
    setSortingParameter(query, pagination);
    setFilterParameters(query, pagination);

    query.setFirstResult(pagination.getOffset());
    query.setMaxResults(pagination.getLimit());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:8,代码来源:SubscriptionDao.java

示例14: 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

示例15: queryForPage

import javax.persistence.Query; //导入方法依赖的package包/类
/**
 * 根据hql语句和分页条件查找分页数据
 * @param hql
 * @param currentPage
 * @param pageSize
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public PageModel queryForPage(String hql,int currentPage,int pageSize){
	PageModel page = new PageModel();
	List list = null;
	Integer totalCount = 0;
	Integer totalPage = 0; //总页数
	try {
		int firstResult = (currentPage-1)*pageSize;
		Query query = em.createQuery(hql);
		query.setMaxResults(pageSize);
		query.setFirstResult(firstResult);
		list = query.getResultList();
		
		Query query2 = em.createQuery(hql);
		List list2 = query2.getResultList();
		totalCount = (list2 == null) ? 0 : list2.size();
		if(totalCount % pageSize == 0){
			totalPage = totalCount/pageSize;
		}else{
			totalPage = totalCount/pageSize + 1;
		}
		
		page.setCurrentPage(currentPage);
		page.setList(list);
		page.setPageSize(pageSize);
		page.setTotalCount(totalCount);
		page.setTotalPage(totalPage);
	} catch (Exception e) {
		e.printStackTrace();
	}finally{
		em.close();
	}		
	return page;
}
 
开发者ID:xujeff,项目名称:tianti,代码行数:42,代码来源:CustomBaseSqlDaoImpl.java


注:本文中的javax.persistence.Query.setFirstResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。