本文整理汇总了Java中org.hibernate.Criteria.addOrder方法的典型用法代码示例。如果您正苦于以下问题:Java Criteria.addOrder方法的具体用法?Java Criteria.addOrder怎么用?Java Criteria.addOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Criteria
的用法示例。
在下文中一共展示了Criteria.addOrder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNewsInfoByConditionAndPage
import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
* 根据条件查询指定新闻
*/
@Override
public List<?> getNewsInfoByConditionAndPage(NewsInfo condition, int page, int pageSize) {
Session session = SessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(NewsInfo.class);
if (condition != null) {
if (condition.getTopic() != null && condition.getTopic().getId() != null ) {
criteria.add(Restrictions.eq("topic.id", condition.getTopic().getId()));
}
if (condition.getTitle() != null && !"".equals(condition.getTitle())) {
criteria.add(Restrictions.like("title", condition.getTitle(), MatchMode.ANYWHERE));
}
}
criteria.setFirstResult(pageSize * (page - 1));
criteria.setMaxResults(pageSize);
criteria.addOrder(Order.desc("createDate"));
return criteria.list();
}
示例2: buildCriteria
import org.hibernate.Criteria; //导入方法依赖的package包/类
private void buildCriteria(Criteria criteria,boolean queryCount){
if(!queryCount && firstResult>0){
criteria.setFirstResult(firstResult);
}
if(!queryCount && maxResults>0){
criteria.setMaxResults(maxResults);
}
if(processInstanceId>0){
criteria.add(Restrictions.eq("processInstanceId", processInstanceId));
}
if(rootProcessInstanceId>0){
criteria.add(Restrictions.eq("rootProcessInstanceId", rootProcessInstanceId));
}
if(StringUtils.isNotEmpty(key)){
criteria.add(Restrictions.eq("key", key));
}
if(!queryCount){
for(String ascProperty:ascOrders){
criteria.addOrder(Order.asc(ascProperty));
}
for(String descProperty:descOrders){
criteria.addOrder(Order.desc(descProperty));
}
}
}
示例3: getLatest
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<App> getLatest(short catalog, Integer subCatalog, Long date, int currentPage, int pageSize,
Boolean noAds, Boolean noVirus, Boolean official) {
Criteria cri = getSession().createCriteria(App.class);
getLastestByFilter(catalog, subCatalog, date, cri);
cri.add(Restrictions.eq("hidden", false));
filterAdVirusOfficial(noAds, noVirus, official, cri);
if (date != null) {
cri.addOrder(Order.desc("viewCount"));
} else {
// 不查询日期,按日期先排序.
cri.addOrder(Order.desc("lastUpdateTime"));
}
cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
cri.setMaxResults(pageSize);
List<App> list = HibernateHelper.list(cri);
return list;
}
示例4: search
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<MoViewTagApps> search(Integer tagId, Integer catalog, Short tagType, int page, int rows,
String keywords, String sort, String order) {
Criteria cri = searchByFilter(tagId, catalog, tagType, keywords);
if (sort != null && !sort.isEmpty()) {
HibernateHelper.addOrder(cri, sort, order);
} else {
if (order != null && "asc".equals(order)) {
cri.addOrder(Order.asc("id"));
} else {
cri.addOrder(Order.desc("id"));
}
}
cri.setMaxResults(rows);
cri.setFirstResult(HibernateHelper.firstResult(page, rows));
List<MoViewTagApps> list = HibernateHelper.list(cri);
return list;
}
示例5: getName
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<String> getName(Session session, short catalog, Integer subCatalog, Integer currentPage,
Integer pageSize) {
Criteria cri = session.createCriteria(App.class);
cri.setProjection(Projections.distinct(Projections.property("name")));
cri.add(Restrictions.eq("catalog", catalog));
cri.add(Restrictions.eq("hidden", false));
if (subCatalog != null) {
cri.add(Restrictions.eq("subCatalog", subCatalog));
}
cri.addOrder(Order.asc("name"));
if (currentPage != null && pageSize != null) {
cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
cri.setMaxResults(pageSize);
}
List<String> list = HibernateHelper.list(cri);
return list;
}
示例6: search
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<MarketApp> search(EnumMarket enumMarket, Short catalog, Integer subCatalog, int page, int rows,
String keywords, String sort, String order) {
Criteria cri = searchByFilter(enumMarket, catalog, subCatalog, keywords);
if (sort != null && !sort.isEmpty()) {
HibernateHelper.addOrder(cri, sort, order);
} else {
if (order != null && "asc".equals(order)) {
cri.addOrder(Order.asc("id"));
} else {
cri.addOrder(Order.desc("id"));
}
}
cri.setMaxResults(rows);
cri.setFirstResult(HibernateHelper.firstResult(page, rows));
List<MarketApp> list = HibernateHelper.list(cri);
return list;
}
示例7: listUserByPage
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Pager<User> listUserByPage(int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(User.class);
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
criteria.addOrder(Order.desc("registerDate"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<User> results = criteria.list();
return new Pager<User>(pageSize, pageNo, recordTotal, results);
}
示例8: findMarketAppList
import org.hibernate.Criteria; //导入方法依赖的package包/类
private List<MarketApp> findMarketAppList(EnumMarket enumMarket, Short catalog, Integer subCatalog, int page,
int rows, String keywords, Integer id, String sort, String order, Date startDate, Date endDate) {
List<MarketApp> list;
Criteria cri = searchByFilter(enumMarket, catalog, subCatalog, keywords, id, startDate, endDate);
if (sort != null && !sort.isEmpty()) {
HibernateHelper.addOrder(cri, sort, order);
} else {
if (order != null && "asc".equals(order)) {
cri.addOrder(Order.asc("id"));
} else {
cri.addOrder(Order.desc("id"));
}
}
cri.setMaxResults(rows);
cri.setFirstResult(HibernateHelper.firstResult(page, rows));
list = HibernateHelper.list(cri);
return list;
}
示例9: handleFindByCourseSorted
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
protected Collection<InventoryBooking> handleFindByCourseSorted(Long courseId, Boolean isRelevantForCourseAppointments, boolean sort) throws Exception
{
Criteria bookingCriteria = createBookingCriteria();
if (courseId != null) {
bookingCriteria.add(Restrictions.eq("course.id", courseId.longValue()));
}
if (isRelevantForCourseAppointments != null) {
bookingCriteria.createCriteria("inventory", CriteriaSpecification.INNER_JOIN).createCriteria("category", CriteriaSpecification.INNER_JOIN)
.add(Restrictions.eq("relevantForCourseAppointments", isRelevantForCourseAppointments.booleanValue()));
}
if (sort) {
bookingCriteria.addOrder(Order.asc("start"));
}
return bookingCriteria.list();
}
示例10: searchSort
import org.hibernate.Criteria; //导入方法依赖的package包/类
private void searchSort(String sort, String order, Criteria cri) {
if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
HibernateHelper.addOrder(cri, sort, order);
} else {
if (StringUtils.isNotBlank(order) && "desc".equals(order.toLowerCase())) {
cri.addOrder(Order.desc("id"));
} else {
cri.addOrder(Order.asc("id"));
}
}
}
示例11: list
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<Tag> list(TagType tagType) {
Criteria cri = getSession().createCriteria(Tag.class);
if (null != tagType) {
// 注释原因: tagType是枚举类型(int) Tag实体tagType属性是Short类型 不能直接把int 转化成
// short 类型
cri.add(Restrictions.eq("tagType", Short.valueOf(tagType.getVal())));
}
cri.addOrder(Order.desc("rank"));
return HibernateHelper.list(cri);
}
示例12: listLogAllByPage
import org.hibernate.Criteria; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Pager<SysLog> listLogAllByPage(int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(SysLog.class);
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
criteria.addOrder(Order.desc("time"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<SysLog> results = criteria.list();
return new Pager<SysLog>(pageSize, pageNo, recordTotal, results);
}
示例13: listCollectsByUser
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Pager<Collect> listCollectsByUser(int userId, int pageNo, int pageSize) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Collect.class);
criteria.add(Restrictions.eq("userId", userId));
long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
criteria.setProjection(null);
criteria.addOrder(Order.desc("collectDate"));
criteria.setFirstResult((pageNo - 1) * pageSize);
criteria.setMaxResults(pageSize);
List<Collect> results = criteria.list();
return new Pager<Collect>(pageSize, pageNo, recordTotal, results);
}
示例14: getSortedList
import org.hibernate.Criteria; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<E> getSortedList(String sortOrder, String sortProperty) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try
{
session.beginTransaction();
Criteria crit = session.createCriteria(entityClass);
if (!sortProperty.equals("")){
if (sortOrder.equals("asc")){
crit.addOrder(Order.asc(sortProperty));
}
else if (sortOrder.equals("desc")){
crit.addOrder(Order.desc(sortProperty));
}
}
List<E> resultList = crit.list();
session.getTransaction().commit();
return resultList;
}
catch (HibernateException e)
{
//log.error("Hibernate Exception" + e.getMessage());
session.getTransaction().rollback();
throw new RuntimeException(e);
}
}
示例15: findAll
import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
* Return all objects related to the implementation of this DAO with no filter.
* Use the session given.
*/
@SuppressWarnings("unchecked")
public List<T> findAll (Session s, Order... orders) {
Criteria crit = s.createCriteria(getReferenceClass());
if (orders != null) {
for (Order order: orders) {
if (order != null)
crit.addOrder(order);
}
}
crit.setCacheable(true);
return (List<T>)crit.list();
}