Java Code Examples for org.hibernate.criterion.Order#asc()
The following examples show how to use
org.hibernate.criterion.Order#asc() .
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: 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 3
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 4
Source File: DomainDAOHibImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
/** * Load list domains by type. * * @param domainType * the domain type * * @return the list * * @throws EMFUserError * the EMF user error * * @see it.eng.spagobi.commons.dao.IDomainDAO#loadListDomainsByType(java.lang.String) */ @Override public List loadListDomainsByType(String domainType) throws EMFUserError { /* * <STATEMENT name="SELECT_LIST_DOMAINS" query="SELECT T.VALUE_NM AS VALUE_NAME, T.VALUE_ID AS VALUE_ID, T.VALUE_CD AS VALUE_CD FROM SBI_DOMAINS T WHERE * DOMAIN_CD = ? "/> */ Session aSession = null; Transaction tx = null; List realResult = new ArrayList(); try { aSession = getSession(); tx = aSession.beginTransaction(); Criterion domainCdCriterrion = Expression.eq("domainCd", domainType); Order valueIdOrder = Order.asc("valueId"); Criteria criteria = aSession.createCriteria(SbiDomains.class); criteria.add(domainCdCriterrion); criteria.addOrder(valueIdOrder); List hibList = criteria.list(); Iterator it = hibList.iterator(); while (it.hasNext()) { realResult.add(toDomain((SbiDomains) it.next())); } tx.commit(); } catch (HibernateException he) { logException(he); if (tx != null) tx.rollback(); throw new EMFUserError(EMFErrorSeverity.ERROR, 100); } finally { if (aSession != null) { if (aSession.isOpen()) aSession.close(); } } return realResult; }
Example 5
Source File: SubjectAreaDAO.java From unitime with Apache License 2.0 | 4 votes |
public Order getDefaultOrder() { return Order.asc(SubjectArea.PROP_SUBJECT_AREA_ABBREVIATION); }
Example 6
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; }