本文整理汇总了Java中org.hibernate.Criteria.setResultTransformer方法的典型用法代码示例。如果您正苦于以下问题:Java Criteria.setResultTransformer方法的具体用法?Java Criteria.setResultTransformer怎么用?Java Criteria.setResultTransformer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Criteria
的用法示例。
在下文中一共展示了Criteria.setResultTransformer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listDistinctRoot
import org.hibernate.Criteria; //导入方法依赖的package包/类
public static List listDistinctRoot(Criteria criteria,Object dao,String... fields) throws Exception {
if (dao != null && criteria != null) {
criteria.setProjection(null);
criteria.setResultTransformer(Criteria.ROOT_ENTITY);
Method loadMethod = CoreUtil.getDaoLoadMethod(dao);
ProjectionList projectionList = Projections.projectionList().add(Projections.id());
boolean cast = false;
if (fields != null && fields.length > 0) {
for (int i = 0; i< fields.length; i++) {
projectionList.add(Projections.property(fields[i]));
}
cast = true;
}
List items = criteria.setProjection(Projections.distinct(projectionList)).list();
Iterator it = items.iterator();
ArrayList result = new ArrayList(items.size());
while (it.hasNext()) {
result.add(loadMethod.invoke(dao, cast ? ((Object[]) it.next())[0] : it.next()));
}
return result;
}
return null;
}
示例2: findAllUsers
import org.hibernate.Criteria; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<AdmUser> findAllUsers() {
Criteria criteria = createEntityCriteria().addOrder(Order.asc("firstName"));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates.
List<AdmUser> users = (List<AdmUser>) criteria.list();
// No need to fetch userProfiles since we are not showing them on list page. Let them lazy load.
// Uncomment below lines for eagerly fetching of userProfiles if you want.
/*
for(User user : users){
Hibernate.initialize(user.getUserProfiles());
}*/
return users;
}
示例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;
}
示例4: findAllUsers
import org.hibernate.Criteria; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<User> findAllUsers() {
Criteria criteria = createEntityCriteria().addOrder(Order.asc("firstName"));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates.
List<User> users = (List<User>) criteria.list();
return users;
}
示例5: handleFindTimelineSchedule
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
protected Collection<TimelineEvent> handleFindTimelineSchedule(Date today,
Long trialId, Long departmentId, Long teamMemberStaffId, Boolean notify, Boolean ignoreTimelineEvents, PSFVO psf)
throws Exception {
Criteria timelineEventCriteria = createTimelineEventCriteria();
SubCriteriaMap criteriaMap = new SubCriteriaMap(TimelineEvent.class, timelineEventCriteria);
if (trialId != null) {
timelineEventCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
}
if (departmentId != null) {
criteriaMap.createCriteria("trial").add(Restrictions.eq("department.id", departmentId.longValue()));
}
if (ignoreTimelineEvents != null) {
criteriaMap.createCriteria("trial.status").add(Restrictions.eq("ignoreTimelineEvents", ignoreTimelineEvents.booleanValue()));
}
if (teamMemberStaffId != null) {
criteriaMap.createCriteria("trial.members").add(Restrictions.eq("staff.id", teamMemberStaffId.longValue())); // unique staff!
if (notify != null) {
criteriaMap.createCriteria("trial.members").add(Restrictions.eq("notifyTimelineEvent", notify.booleanValue()));
}
}
timelineEventCriteria.add(Restrictions.eq("dismissed", false)); // performance only...
if (psf != null) {
PSFVO sorterFilter = new PSFVO();
sorterFilter.setFilters(psf.getFilters());
sorterFilter.setSortField(psf.getSortField());
sorterFilter.setSortOrder(psf.getSortOrder());
CriteriaUtil.applyPSFVO(criteriaMap, sorterFilter); // staff is not unique in team members
} else {
timelineEventCriteria.setResultTransformer(Criteria.ROOT_ENTITY);
}
ArrayList<TimelineEvent> resultSet = CriteriaUtil.listReminders(timelineEventCriteria, today, notify, null, null);
return (Collection<TimelineEvent>) CriteriaUtil.applyPVO(resultSet, psf, teamMemberStaffId != null); // no dupes here any more
}
示例6: loadAll
import org.hibernate.Criteria; //导入方法依赖的package包/类
public <T> List<T> loadAll(final Class<T> entityClass) {
Criteria criteria = getSession().createCriteria(entityClass);
criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
return criteria.list();
}
示例7: distinct
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Criteria distinct(Criteria criteria) {
criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
return criteria;
}
示例8: handleFindVisitScheduleItemSchedule
import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
protected Collection<VisitScheduleItem> handleFindVisitScheduleItemSchedule(
Date today, Long trialId, Long departmentId, Boolean notify, Boolean ignoreTimelineEvents, VariablePeriod reminderPeriod, Long reminderPeriodDays, PSFVO psf)
throws Exception {
Criteria visitScheduleItemCriteria = createVisitScheduleItemCriteria(null);
SubCriteriaMap criteriaMap = new SubCriteriaMap(VisitScheduleItem.class, visitScheduleItemCriteria);
if (trialId != null) {
visitScheduleItemCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
}
if (departmentId != null) {
criteriaMap.createCriteria("trial").add(Restrictions.eq("department.id", departmentId.longValue()));
}
if (ignoreTimelineEvents != null) {
criteriaMap.createCriteria("trial.status").add(Restrictions.eq("ignoreTimelineEvents", ignoreTimelineEvents.booleanValue()));
}
// if (teamMemberStaffId != null) {
// criteriaMap.createCriteria("trial.members").add(Restrictions.eq("staff.id", teamMemberStaffId.longValue())); // unique staff!
// if (notify != null) {
// criteriaMap.createCriteria("trial.members").add(Restrictions.eq("notifyTimelineEvent", notify.booleanValue()));
// }
// }
if (notify != null) {
visitScheduleItemCriteria.add(Restrictions.eq("notify", notify.booleanValue()));
}
visitScheduleItemCriteria.add(Restrictions.ge("stop", CommonUtil.dateToTimestamp(today)));
if (psf != null) {
PSFVO sorterFilter = new PSFVO();
sorterFilter.setFilters(psf.getFilters());
sorterFilter.setSortField(psf.getSortField());
sorterFilter.setSortOrder(psf.getSortOrder());
CriteriaUtil.applyPSFVO(criteriaMap, sorterFilter); // staff is not unique in team members
} else {
visitScheduleItemCriteria.setResultTransformer(Criteria.ROOT_ENTITY);
}
ArrayList<VisitScheduleItem> resultSet = CriteriaUtil.listReminders(visitScheduleItemCriteria, today, notify, reminderPeriod, reminderPeriodDays);
return (Collection<VisitScheduleItem>) CriteriaUtil.applyPVO(resultSet, psf, false); // no dupes here any more
}
示例9: distinct
import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
* distinct.
*
* @param criteria
* Criteria
* @return Criteria
*/
public static Criteria distinct(Criteria criteria) {
criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
return criteria;
}