当前位置: 首页>>代码示例>>Java>>正文


Java Criteria.setProjection方法代码示例

本文整理汇总了Java中org.hibernate.Criteria.setProjection方法的典型用法代码示例。如果您正苦于以下问题:Java Criteria.setProjection方法的具体用法?Java Criteria.setProjection怎么用?Java Criteria.setProjection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.Criteria的用法示例。


在下文中一共展示了Criteria.setProjection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: listMarketRank

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<Market> listMarketRank() {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("marketName"));
    proList.add(Projections.property("rank"));
    Criteria cri = getSession().createCriteria(Market.class);
    cri.setProjection(proList);
    List<Object[]> list = HibernateHelper.list(cri);
    List<Market> markets = null;
    if (list != null && !list.isEmpty()) {
        markets = new ArrayList<Market>(list.size());
        for (Object[] obj : list) {
            Market m = new Market();
            m.setMarketName((String) obj[0]);
            m.setRank((Integer) obj[1]);
            markets.add(m);
        }
    }
    return markets;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:21,代码来源:MarketDaoImpl.java

示例2: 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;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:19,代码来源:AppDaoImpl.java

示例3: pagedQuery

import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
 * 分页查询函数,使用已设好查询条件与排序的<code>Criteria</code>.
 * 
 * @param criteria
 *            条件
 * @param pageNo
 *            当前页号
 * @param pageSize
 *            每页最大记录数
 * @return 含总记录数和当前页数据的Page对象.
 */
@Transactional(readOnly = true)
public Page pagedQuery(Criteria criteria, int pageNo, int pageSize) {
    Assert.notNull(criteria);
    Assert.isTrue(pageNo >= 1, "pageNo should be eg 1");
    Assert.isTrue(criteria instanceof CriteriaImpl);

    // 先把Projection和OrderBy条件取出来,清空两者来执行Count操作
    Projection projection = HibernateUtils.findProjection(criteria);

    List orderEntries = HibernateUtils.findOrderEntries(criteria);
    HibernateUtils.setOrderEntries(criteria, Collections.EMPTY_LIST);

    // 执行查询
    Integer totalCount = this.getCount(criteria);
    // 将之前的Projection和OrderBy条件重新设回去
    criteria.setProjection(projection);

    if (projection == null) {
        criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
    }

    HibernateUtils.setOrderEntries(criteria, orderEntries);

    // 返回分页对象
    if (totalCount < 1) {
        return new Page();
    }

    int start = (pageNo - 1) * pageSize;
    List result = criteria.setFirstResult(start).setMaxResults(pageSize)
            .list();

    Page page = new Page(result, totalCount);
    page.setPageNo(pageNo);
    page.setPageSize(pageSize);

    return page;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:50,代码来源:HibernatePagingDao.java

示例4: listForDownloads

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public List<App> listForDownloads(Session session, int currentPage, int pageSize) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("id"));
    proList.add(Projections.property("pkname"));
    proList.add(Projections.property("marketName"));

    Criteria cri = session.createCriteria(App.class);
    cri.setProjection(proList);
    cri.setMaxResults(pageSize);
    cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
    // 先全部更新.
    // cri.add(Restrictions.or(Restrictions.ltProperty("realDownload",
    // "lastDayDownload"),
    // Restrictions.ne("deltaDownload", 0)));
    List<Object[]> list = HibernateHelper.list(cri);
    List<App> apps = null;
    if (list != null) {
        apps = new ArrayList<App>(list.size());
        for (Object[] obj : list) {
            App e = new App();
            e.setId((Integer) obj[0]);
            e.setPkname((String) obj[1]);
            e.setMarketName((String) obj[2]);
            apps.add(e);
        }
        list.clear();
    }
    return apps;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:31,代码来源:AppDaoImpl.java

示例5: showBookByStyle

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Pager<Book> showBookByStyle(String style, int pageNo, int pageSize) {
	
	Session session = sessionFactory.getCurrentSession();
	Criteria criteria = session.createCriteria(Book.class);
	criteria.add(Restrictions.eq("bookStyle", style));
	long recordTotal = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).longValue();
	criteria.setProjection(null);
	criteria.addOrder(Order.desc("clickTimes"));
	criteria.setFirstResult((pageNo - 1) * pageSize);
	criteria.setMaxResults(pageSize);
	List<Book> results = criteria.list();
	Pager<Book> page=new Pager<Book>(pageSize, pageNo, recordTotal, results);
	return page;
}
 
开发者ID:zhangjikai,项目名称:sdudoc,代码行数:16,代码来源:BookDaoImpl.java

示例6: handleFindTitles

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
protected Collection<String> handleFindTitles(Long trialDepartmentId,
		Long staffId, Long trialId, String titleInfix, Integer limit)
				throws Exception {
	Criteria dutyRosterCriteria = createDutyRosterTurnCriteria("dutyRosterTurn");
	Criteria trialCriteria = null;
	if (trialDepartmentId != null) {
		trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.LEFT_JOIN);
	} else if (trialId != null) {
		trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.INNER_JOIN);
	}
	if (trialDepartmentId != null || trialId != null) {
		if (trialDepartmentId != null) {
			trialCriteria.add(Restrictions.or(Restrictions.isNull("dutyRosterTurn.trial"), Restrictions.eq("department.id", trialDepartmentId.longValue())));
		}
		if (trialId != null) {
			trialCriteria.add(Restrictions.idEq(trialId.longValue()));
		}
	}
	if (staffId != null) {
		dutyRosterCriteria.add(Restrictions.eq("staff.id", staffId.longValue()));
	}
	CategoryCriterion.apply(dutyRosterCriteria, new CategoryCriterion(titleInfix, "title", MatchMode.ANYWHERE));
	dutyRosterCriteria.addOrder(Order.asc("title"));
	dutyRosterCriteria.setProjection(Projections.distinct(Projections.property("title")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.DUTY_ROSTER_TURN_TITLE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.DUTY_ROSTER_TURN_TITLE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), dutyRosterCriteria);
	return dutyRosterCriteria.list();
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:30,代码来源:DutyRosterTurnDaoImpl.java

示例7: listLogByUserPage

import org.hibernate.Criteria; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Pager<SysLog> listLogByUserPage(int userId, int pageNo, int pageSize) {
	Session session = sessionFactory.getCurrentSession();
	Criteria criteria = session.createCriteria(SysLog.class);
	criteria.add(Restrictions.eq("user.id", userId));
	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);
}
 
开发者ID:zhangjikai,项目名称:sdudoc,代码行数:15,代码来源:LogDaoImpl.java

示例8: 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);
}
 
开发者ID:zhangjikai,项目名称:sdudoc,代码行数:14,代码来源:LogDaoImpl.java

示例9: handleFindCalendars

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
protected Collection<String> handleFindCalendars(Long trialDepartmentId,
		Long staffId, Long trialId, String calendarPrefix, Integer limit)
				throws Exception {
	Criteria dutyRosterCriteria = createDutyRosterTurnCriteria("dutyRosterTurn");
	Criteria trialCriteria = null;
	if (trialDepartmentId != null) {
		trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.LEFT_JOIN);
	} else if (trialId != null) {
		trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.INNER_JOIN);
	}
	if (trialDepartmentId != null || trialId != null) {
		if (trialDepartmentId != null) {
			trialCriteria.add(Restrictions.or(Restrictions.isNull("dutyRosterTurn.trial"), Restrictions.eq("department.id", trialDepartmentId.longValue())));
		}
		if (trialId != null) {
			trialCriteria.add(Restrictions.idEq(trialId.longValue()));
		}
	}
	if (staffId != null) {
		dutyRosterCriteria.add(Restrictions.eq("staff.id", staffId.longValue()));
	}
	CategoryCriterion.apply(dutyRosterCriteria, new CategoryCriterion(calendarPrefix, "calendar", MatchMode.START));
	dutyRosterCriteria.addOrder(Order.asc("calendar"));
	dutyRosterCriteria.setProjection(Projections.distinct(Projections.property("calendar")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.DUTY_ROSTER_TURN_CALENDAR_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.DUTY_ROSTER_TURN_CALENDAR_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), dutyRosterCriteria);
	return dutyRosterCriteria.list();
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:30,代码来源:DutyRosterTurnDaoImpl.java

示例10: countForSearching

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public long countForSearching(Short pId, Short tagType, String keywords) {
    // 查询条件
    Criteria cri = searchByFilter(pId, keywords);
    cri.setProjection(Projections.count("id"));
    return ((Long) cri.uniqueResult()).longValue();
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:8,代码来源:MoTagDaoImpl.java

示例11: count

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public long count(short catalog, Integer subCatalog, Boolean noAds, Boolean noVirus, Boolean official) {
    Criteria cri = getSession().createCriteria(App.class);
    cri.setProjection(Projections.count("id"));
    cri.add(Restrictions.eq("catalog", catalog));
    cri.add(Restrictions.eq("hidden", false));
    if (subCatalog != null) {
        cri.add(Restrictions.eq("subCatalog", subCatalog));
    }
    filterAdVirusOfficial(noAds, noVirus, official, cri);
    Object o = cri.uniqueResult();
    return ((Long) o).longValue();
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:14,代码来源:AppDaoImpl.java

示例12: countForSearching

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public long countForSearching(Short catalog, Integer subCatalog, String keywords, Integer id, Date startDate,
        Date endDate, Boolean official, Integer audit) {
    Criteria cri = searchByFilter(catalog, subCatalog, keywords, id, startDate, endDate, official, audit);
    cri.setProjection(Projections.count("id"));
    return ((Long) cri.uniqueResult()).longValue();
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:8,代码来源:AppDaoImpl.java

示例13: pageRoleByConditions

import org.hibernate.Criteria; //导入方法依赖的package包/类
public Pagination<RoleDO> pageRoleByConditions(Long pageIndex, Long pageSize, Map params) {
    Criteria criteria = daoSupport.createCriteria(RoleDO.class);
    criteria.add(Restrictions.eq("editEnable",Boolean.TRUE));
    Long totalCount = (Long) criteria.setProjection(Projections.count("roleId")).uniqueResult();

    criteria.setProjection(null);
    criteria.setFirstResult((pageIndex.intValue() - 1) * pageSize.intValue());
    criteria.setMaxResults(pageIndex.intValue()* pageSize.intValue());
    List<RoleDO> items = criteria.list();
    Pagination<RoleDO> pagination = new Pagination<RoleDO>(pageIndex, pageSize, totalCount);
    pagination.setItems(items);
    return pagination;
}
 
开发者ID:wu05281,项目名称:admin-shiro,代码行数:14,代码来源:RoleService.java

示例14: getMaxId

import org.hibernate.Criteria; //导入方法依赖的package包/类
private long getMaxId(Class<?> entityClass) {
	Criteria criteria = dao.getSession().createCriteria(entityClass);
	criteria.setProjection(Projections.max("id"));
	Long maxId = (Long) criteria.uniqueResult();
	if (maxId == null)
		maxId = 0L;
	return maxId;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:9,代码来源:DefaultIdManager.java

示例15: getPkByIdOfMarketApp

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Integer getPkByIdOfMarketApp(int foreignKey) {
    Criteria cri = getSession().createCriteria(App.class);
    cri.add(Restrictions.eq("marketAppId", foreignKey));
    cri.setProjection(Projections.property("id"));
    try {
        Object o = cri.uniqueResult();
        if (o != null) {
            return (Integer) o;
        }
        return null;
    } catch (org.hibernate.AssertionFailure e) {
        return null;
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:16,代码来源:AppDaoImpl.java


注:本文中的org.hibernate.Criteria.setProjection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。