public void build(Criteria criteria) { SortParam sort = sortState.getSort(); String property; if (sort != null && sort.getProperty() != null) { property = sort.getProperty(); asc = sort.isAscending(); } else { property = defaultProperty; } if (property != null) { if (property.contains(".")) { // for 'dot' properties we need to add aliases // e.g. for the property 'orderbook.order.item.name' we need to add an aliases for 'order' // and 'order.item' String path[] = property.split("\\."); for (int ii = 0; ii < path.length - 1; ii++) { StringBuffer sb = new StringBuffer(); for (int jj = 0; jj <= ii; jj++) { if (sb.length() > 0) sb.append("."); sb.append(path[jj]); } criteria.createAlias(sb.toString(), path[ii], CriteriaSpecification.LEFT_JOIN); } // when we have a 'dot' property we want to sort by the sub tables field // e.g. for the property 'orderbook.order.item.name' we need to sort by 'item.name' if (path.length > 1) property = String.format("%s.%s", path[path.length - 2], path[path.length - 1]); else property = path[path.length - 1]; } Order order = asc ? Order.asc(property) : Order.desc(property); order = cased ? order : order.ignoreCase(); criteria.addOrder(order); } }
/* (non-Javadoc) * @see com.mg.framework.api.orm.DetachedCriteria#addOrder(com.mg.framework.api.orm.Order) */ @Override public DetachedCriteria addOrder(Order order) { org.hibernate.criterion.Order orderHibernate; if (order.isAscending()) orderHibernate = org.hibernate.criterion.Order.asc(order.getPropertyName()); else orderHibernate = org.hibernate.criterion.Order.desc(order.getPropertyName()); if (order.isIgnoreCase()) orderHibernate.ignoreCase(); delegate.addOrder(orderHibernate); return this; }