Java Code Examples for org.hibernate.criterion.Order#desc()
The following examples show how to use
org.hibernate.criterion.Order#desc() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLVisitor.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
@Override public Object visitOrder(OrderExpression order_expression, Object filter_result, SortOrder sort_order) { Order order; String property = ((Member) filter_result).getName(); switch (sort_order) { case asc: { order = Order.asc(property); break; } case desc: { order = Order.desc(property); break; } default: { throw new UnsupportedOperationException("Unsupported order: " + sort_order); } } return order; }
Example 2
Source File: QuestionDAO.java From mamute with Apache License 2.0 | 6 votes |
public List<Question> top(String section, int count, DateTime since) { Order order; if (section.equals("viewed")) { order = Order.desc("q.views"); } else if (section.equals("answered")) { order = Order.desc("q.answerCount"); } else /*if (section.equals("voted"))*/ { order = Order.desc("q.voteCount"); } return session.createCriteria(Question.class, "q") .add(and(Restrictions.eq("q.moderationOptions.invisible", false))) .add(gt("q.createdAt", since)) .addOrder(order) .setMaxResults(count) .list(); }
Example 3
Source File: HibernateSupportDao.java From base-framework with Apache License 2.0 | 6 votes |
/** * 设置分页参数到Criteria对象,辅助函数. * * @param c Hibernate Criteria * @param pageRequest 分页请求参数 * * @return {@link Criteria} */ protected Criteria setPageRequestToCriteria( Criteria c, PageRequest pageRequest) { Assert.isTrue(pageRequest.getPageSize() > 0, "分页大小必须大于0"); c.setFirstResult(pageRequest.getOffset()); c.setMaxResults(pageRequest.getPageSize()); if (pageRequest.isOrderBySetted()) { for (Sort sort : pageRequest.getSort()) { Order order = null; if (sort.getDir().equals(Sort.ASC)) { order = Order.asc(sort.getProperty()); } else { order = Order.desc(sort.getProperty()); } c.addOrder(order); } } return c; }
Example 4
Source File: TagAction.java From csustRepo with MIT License | 5 votes |
@SuppressWarnings("unchecked") public String list() { int pageNum=1; int pageSize=20; String name=getRequest().getParameter("name"); String queryOrderBy=getRequest().getParameter("queryOrderBy"); String pageSizeStr=getRequest().getParameter("pageSize"); String pageNumStr=getRequest().getParameter("pageNo"); Set<Criterion> criterions=new HashSet<Criterion>(2); Set<Order> orders=new HashSet<Order>(1); Order orderByIdDesc=Order.desc("id"); orders.add(orderByIdDesc); if(!StringUtil.isNullOrEmpty(name)){ criterions.add(Restrictions.like("name", "%"+name.trim()+"%")); } if(!StringUtil.isNullOrEmpty(queryOrderBy)&&queryOrderBy.equals("asc")){ orders.remove(orderByIdDesc); orders.add(Order.asc("id")); } if(!StringUtil.isNullOrEmpty(pageSizeStr)){ pageSize=Integer.parseInt(pageSizeStr); } if (!StringUtil.isNullOrEmpty(pageNumStr)) { pageNum=Integer.parseInt(pageNumStr); } Page page=tagService.pageCQuery(pageNum, pageSize, criterions,orders,"id"); getContextMap().put("page", page); getContextMap().put("params", getParameters()); return "list"; }
Example 5
Source File: CollectionRepositoryImpl.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
private void searchCollectionsAddOrder(String sortColumn, String sortDirection, Criteria criteria) { if (StringUtils.hasText(sortColumn)) { if ("owner".equals(sortColumn)){ sortColumn = "owner.userName"; criteria.createAlias("owner", "owner"); } Order order; if ("ASC".equals(sortDirection)){ order = Order.asc(sortColumn); } else { order = Order.desc(sortColumn); } criteria.addOrder(order); } }
Example 6
Source File: SessionDAO.java From unitime with Apache License 2.0 | 4 votes |
public Order getDefaultOrder() { return Order.desc(Session.PROP_SESSION_BEGIN_DATE_TIME); }
Example 7
Source File: WithUserPaginatedDAO.java From mamute with Apache License 2.0 | 4 votes |
@Override public Order getOrder() { return Order.desc("p.createdAt"); }
Example 8
Source File: WithUserPaginatedDAO.java From mamute with Apache License 2.0 | 4 votes |
@Override public Order getOrder() { return Order.desc("p.voteCount"); }
Example 9
Source File: TopicAction.java From csustRepo with MIT License | 4 votes |
@SuppressWarnings("unchecked") public String list() { int pageNum=1; int pageSize=20; String title=getRequest().getParameter("title"); String gscatalogidStr=getRequest().getParameter("gscatalogid"); String zycatalogidStr=getRequest().getParameter("zycatalogid"); String queryOrderBy=getRequest().getParameter("queryOrderBy"); String pageSizeStr=getRequest().getParameter("pageSize"); String pageNumStr=getRequest().getParameter("pageNo"); Set<Criterion> criterions=new HashSet<Criterion>(2); Set<Order> orders=new HashSet<Order>(1); Order orderByIdDesc=Order.desc("id"); orders.add(orderByIdDesc); if(!StringUtil.isNullOrEmpty(title)){ criterions.add(Restrictions.like("title", "%"+title.trim()+"%")); } if(!StringUtil.isNullOrEmpty(gscatalogidStr)){ criterions.add(Restrictions.eq("repGscatalog.id", Integer.parseInt(gscatalogidStr))); } if(!StringUtil.isNullOrEmpty(zycatalogidStr)){ criterions.add(Restrictions.eq("repZycatalog.id", Integer.parseInt(zycatalogidStr))); } if(!StringUtil.isNullOrEmpty(queryOrderBy)&&queryOrderBy.equals("asc")){ orders.remove(orderByIdDesc); orders.add(Order.asc("id")); } if(!StringUtil.isNullOrEmpty(pageSizeStr)){ pageSize=Integer.parseInt(pageSizeStr); } if (!StringUtil.isNullOrEmpty(pageNumStr)) { pageNum=Integer.parseInt(pageNumStr); } List<RepGscatalog> gscatalogs=gsCatalogService.loadAll(); List<RepZycatalog> zycatalogs=zyCatalogService.loadAll(); Page page=topicService.pageCQuery(pageNum, pageSize, criterions,orders,"id"); getContextMap().put("page", page); getContextMap().put("params", getParameters()); getContextMap().put("gscatalogs", gscatalogs); getContextMap().put("zycatalogs", zycatalogs); return "list"; }
Example 10
Source File: NoticeAction.java From csustRepo with MIT License | 4 votes |
/** * 显示公告列表,加上分页 * * @return */ public String list() { int pageNum = 1; int pageSize = 20; List<String> likenNames = Arrays.asList("title", "adduser"); List<String> eqNames = Arrays.asList("ispassed"); Set<Criterion> criterions = new HashSet<Criterion>(); Set<Order> orders = new HashSet<Order>(); Order order = Order.desc("id"); orders.add(order); for (Map.Entry<String, Object> param : getParameters().entrySet()) { String name = param.getKey(); String value = ((String[]) param.getValue())[0]; if (value != null && !value.isEmpty()) { if (eqNames.contains(name)) { if(!value.equals("-1")){ criterions.add(Restrictions.eq(name, Integer.parseInt(value))); } } else if (likenNames.contains(name)) { if (name.equals("adduser")) { criterions.add( // Restrictions.sqlRestriction("(select u.username from rep_admin u where u.id={alias}.adminid) like '%"+value+"%'")); Restrictions.like("author", "%"+value.trim()+"%")); } else { criterions.add(Restrictions.like(name, "%"+value.trim()+"%")); } } else if (name.equals(Page.PAGENO)) { pageNum = Integer.parseInt(value); } else if (name.equals(Page.QUERYORDERBY)) { if (value.equals("asc")) { orders.remove(order); orders.add(Order.asc("id")); }else if (value.equals("addtime_desc")) { orders.remove(order); orders.add(Order.desc("addtime")); }else if (value.equals("addtime_asc")) { orders.remove(order); orders.add(Order.asc("addtime")); } } else if (name.equals(Page.PAGESIZE)) { pageSize = Integer.parseInt(value); if (pageSize <= 0) { pageSize = 20; } } } } Page page = noticeService.pageCQuery(pageNum, pageSize, criterions,orders, "id"); getContextMap().put("page", page); getContextMap().put("params", getParameters()); return "list"; }
Example 11
Source File: AdminAction.java From csustRepo with MIT License | 4 votes |
public String list() { int pageNum=1; int pageSize=20; /*Cookie[] cookies=request.getCookies(); boolean cookieExistFlag=false; for (Cookie cookie : cookies) { if(cookie.getName().equals(Page._COOKIE_PAGE_SIZE)){ pageSize=Integer.parseInt(cookie.getValue()); cookieExistFlag=true; } } if(!cookieExistFlag){ Cookie cookie=new Cookie(Page._COOKIE_PAGE_SIZE, "20"); response.addCookie(cookie); } */ List<String> likenNames=Arrays.asList("username","school","major"); List<String> eqNames=Arrays.asList("islock","ispassed","teacherorstu","roleid"); Set<Criterion> criterions=new HashSet<Criterion>(); Set<Order> orders=new HashSet<Order>(); Order order=Order.desc("id"); orders.add(order); for (Map.Entry<String, Object> param : getParameters().entrySet()) { String name=param.getKey(); String value=((String[])param.getValue())[0]; if(value!=null&&!value.isEmpty()){ if(eqNames.contains(name)){ if(!value.equals("-1")){ if(name.equals("roleid")){ criterions.add(Restrictions.eq("repRole.id", Integer.parseInt(value))); }else { criterions.add(Restrictions.eq(name, Integer.parseInt(value))); } } }else if(likenNames.contains(name)){ criterions.add(Restrictions.like(name, "%"+value.trim()+"%")); }else if(name.equals(Page.PAGENO)){ pageNum=Integer.parseInt(value); }else if(name.equals(Page.QUERYORDERBY)){ if(value.equals("asc")){ orders.remove(order); orders.add(Order.asc("id")); } }else if (name.equals(Page.PAGESIZE)) { pageSize=Integer.parseInt(value); if(pageSize<=0){ pageSize=20; } } } } Page page=adminService.pageCQuery(pageNum, pageSize, criterions, orders,"id"); getContextMap().put("page", page); getContextMap().put("params", getParameters()); List<RepRole> roles=roleService.loadAll(); getContextMap().put("roles", roles); return "list"; }
Example 12
Source File: UserAction.java From csustRepo with MIT License | 4 votes |
public String list() { int pageNum=1; int pageSize=20; /*Cookie[] cookies=request.getCookies(); boolean cookieExistFlag=false; for (Cookie cookie : cookies) { if(cookie.getName().equals(Page._COOKIE_PAGE_SIZE)){ pageSize=Integer.parseInt(cookie.getValue()); cookieExistFlag=true; } } if(!cookieExistFlag){ Cookie cookie=new Cookie(Page._COOKIE_PAGE_SIZE, "20"); response.addCookie(cookie); } */ List<String> likenNames=Arrays.asList("username","school","major"); List<String> eqNames=Arrays.asList("islock","ispassed","teacherorstu"); Set<Criterion> criterions=new HashSet<Criterion>(); Set<Order> orders=new HashSet<Order>(); Order order=Order.desc("id"); orders.add(order); /* * 注:此方法下方的注释部分是pageQuery方法拼接hql语句的分页实现方案 * * @author 杨真 8-16 9:41 */ // StringBuilder hql=new StringBuilder("from RepUser u "); // String orderBy="desc"; // ArrayList<Object> hqlParams=new ArrayList<Object>(); // int paramIndex=0; for (Map.Entry<String, Object> param : getParameters().entrySet()) { String name=param.getKey(); String value=((String[])param.getValue())[0]; if(value!=null&&!value.isEmpty()){ // if(eqNames.contains(name)&&!value.equals("-1")){ if(eqNames.contains(name)){ criterions.add(Restrictions.eq(name, Integer.parseInt(value))); /*if(paramIndex==0){ hql.append("where "); hql.append("u."+name+" =? "); }else { hql.append("and u."+name+" =? "); } hqlParams.add(paramIndex,Integer.parseInt(value)); paramIndex++;*/ }else if(likenNames.contains(name)){ criterions.add(Restrictions.like(name, "%"+value.trim()+"%")); /*if(paramIndex==0){ hql.append("where "); hql.append("u."+name+" like ? "); }else{ hql.append("and u."+name+" like ? "); } hqlParams.add(paramIndex,"%"+value+"%"); paramIndex++;*/ }else if(name.equals(Page.PAGENO)){ pageNum=Integer.parseInt(value); }else if(name.equals(Page.QUERYORDERBY)){ if(value.equals("asc")){ // orderBy="asc"; orders.remove(order); orders.add(Order.asc("id")); } }else if (name.equals(Page.PAGESIZE)) { pageSize=Integer.parseInt(value); if(pageSize<=0){ pageSize=20; } } } } // hql.append("order by u.id "+orderBy); // // System.out.println(hql); // // Page page=userService.pageQuery(hql.toString(), pageNum, pageSize, hqlParams.toArray()); Page page=userService.pageCQuery(pageNum, pageSize, criterions, orders,"id"); getContextMap().put("page", page); getContextMap().put("params", getParameters()); return "list"; }
Example 13
Source File: LogAction.java From csustRepo with MIT License | 4 votes |
public String list() { int pageNum=1; int pageSize=20; List<String> likenNames=Arrays.asList("operationtype","description","operationip"); // List<String> eqNames=Arrays.asList("islock","ispassed","teacherorstu","roleid"); Set<Criterion> criterions=new HashSet<Criterion>(); Set<Order> orders=new HashSet<Order>(); Order order=Order.desc("id"); orders.add(order); for (Map.Entry<String, Object> param : getParameters().entrySet()) { String name=param.getKey(); String value=((String[])param.getValue())[0]; if(value!=null&&!value.isEmpty()){ if(likenNames.contains(name)){ criterions.add(Restrictions.like(name, "%"+value+"%")); }else if(name.equals("adminid")){ criterions.add(Restrictions.eq("repAdmin.id", Integer.parseInt(value))); }else if(name.equals(Page.PAGENO)){ pageNum=Integer.parseInt(value); }else if(name.equals(Page.QUERYORDERBY)){ if(value.equals("asc")){ orders.remove(order); orders.add(Order.asc("id")); } }else if (name.equals(Page.PAGESIZE)) { pageSize=Integer.parseInt(value); if(pageSize<=0){ pageSize=20; } } } } String starttimeStr=getRequest().getParameter("starttime"); String endtimeStr=getRequest().getParameter("endtime"); if(starttimeStr!=null&&!starttimeStr.isEmpty()&&endtimeStr!=null&&!endtimeStr.isEmpty()){ try { SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date startTime = dateFormat.parse(starttimeStr); Date endTime = dateFormat.parse(endtimeStr); criterions.add(Restrictions.between("operationtime", startTime, endTime)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Page page=logService.pageCQuery(pageNum, pageSize, criterions, orders,"id"); getContextMap().put("page", page); getContextMap().put("params", getParameters()); List<RepAdmin> admins=adminService.loadAll(); getContextMap().put("admins", admins); return "list"; }
Example 14
Source File: AsksAction.java From csustRepo with MIT License | 4 votes |
public String list(){ int pageNum = 1; int pageSize = 20; List<String> likenNames = Arrays.asList("title", "adduser"); List<String> eqNames = Arrays.asList("ispassed","isreplied"); Set<Criterion> criterions = new HashSet<Criterion>(); Set<Order> orders = new HashSet<Order>(); Order order = Order.desc("id"); orders.add(order); for (Map.Entry<String, Object> param : getParameters().entrySet()) { String name = param.getKey(); String value = ((String[]) param.getValue())[0]; if (value != null && !value.isEmpty()) { if (eqNames.contains(name)) { criterions.add(Restrictions.eq(name, Integer.parseInt(value))); } else if (likenNames.contains(name)) { if (name.equals("adduser")) { // criterions.add(Restrictions.like("repUser.username", "%"+value+"%")); criterions.add( Restrictions.sqlRestriction( "(select u.username from rep_user u where u.id={alias}.userid) like '%"+value+"%'")); }else { criterions.add(Restrictions.like(name, "%"+value.trim()+"%")); } } else if (name.equals(Page.PAGENO)) { pageNum = Integer.parseInt(value); } else if (name.equals(Page.QUERYORDERBY)) { if (value.equals("asc")) { orders.remove(order); orders.add(Order.asc("id")); }else if (value.equals("addtime_desc")) { orders.remove(order); orders.add(Order.desc("addtime")); }else if (value.equals("addtime_asc")) { orders.remove(order); orders.add(Order.asc("addtime")); } } else if (name.equals(Page.PAGESIZE)) { pageSize = Integer.parseInt(value); if (pageSize <= 0) { pageSize = 20; } } } } Page page = messageService.pageCQuery(pageNum, pageSize, criterions,orders, "id"); getContextMap().put("page", page); getContextMap().put("params", getParameters()); return "list"; }
Example 15
Source File: HibernateDao.java From jdal with Apache License 2.0 | 4 votes |
/** * Create Order from criteria and property path * @param criteria the hibernate criteria to apply order on * @param propertyPath the property path * @return Order */ protected Order createOrder(Criteria criteria, String propertyPath, boolean ascending) { Order order = null; if (propertyPath != null) { String sortProperty = PropertyUtils.getPropertyName(propertyPath); try { if (PropertyUtils.isNested(propertyPath)) { String alias = PropertyUtils.getPropertyName(PropertyUtils.getPath(propertyPath)); // Need to create alias? // String alias = HibernateUtils.findAliasForPropertyPath(criteria, propertyPath); HibernateUtils.createAlias(criteria, PropertyUtils.getPath(propertyPath)); sortProperty = alias + PropertyUtils.PROPERTY_SEPARATOR + sortProperty; } else { // test if property is an entity class Type sortType = getClassMetadata().getPropertyType(propertyPath); if (sortType.isEntityType()) { // is entity, look for 'name' property String[] propertyNames = getClassMetadata(sortType.getReturnedClass()).getPropertyNames(); for (String name : propertyNames) { if ("name".equals(name)) { log.info("Found property name on persistent class: " + sortType.getName()); String newPath = propertyPath + PropertyAccessor.NESTED_PROPERTY_SEPARATOR + "name"; return createOrder(criteria, newPath, ascending); } } } } if (log.isDebugEnabled()) log.debug("Setting order as: " + sortProperty); order = ascending ? Order.asc(sortProperty) : Order.desc(sortProperty); } catch(HibernateException he) { log.error("Cannot to create Order for property: " + sortProperty + " for " + getEntityClass().getSimpleName(), he); } } else { // add default order by id ClassMetadata metadata = getClassMetadata(); if (metadata != null) order = Order.asc(metadata.getIdentifierPropertyName()); } return order; }