本文整理汇总了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();
}
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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());
}
示例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;
}
示例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());
}
示例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());
}
示例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;
}