List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:com.websystique.springmvc.dao.AnswerOptionsDaoIml.java
public Collection<AnswerOptions> findAllAnswerOptions() { Criteria criteria = createEntityCriteria().addOrder(Order.asc("optId")); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. List<AnswerOptions> answerOptions = (List<AnswerOptions>) criteria.list(); return answerOptions; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.websystique.springmvc.dao.AnswersDaoIml.java
@SuppressWarnings("unchecked") public Collection<Answers> findAllAnswers() { Criteria criteria = createEntityCriteria().addOrder(Order.asc("answerId")); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. List<Answers> answers = (List<Answers>) criteria.list(); return answers; //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.websystique.springmvc.dao.CategoriesDaoIml.java
public Collection<Categories> findAllCategories() { Criteria criteria = createEntityCriteria().addOrder(Order.asc("catId")); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. List<Categories> categories = (List<Categories>) criteria.list(); return categories; //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.websystique.springmvc.dao.QuestionsDaoIml.java
public Collection<Questions> findAllQuestions() { Criteria criteria = createEntityCriteria().addOrder(Order.asc("questionId")); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. List<Questions> questions = (List<Questions>) criteria.list(); return questions; //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.websystique.springmvc.dao.SectionsDaoIml.java
@SuppressWarnings("unchecked") public Collection<Sections> findAllSections() { Criteria criteria = createEntityCriteria().addOrder(Order.asc("sectionId")); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. List<Sections> sections = (List<Sections>) criteria.list(); return sections; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.websystique.springmvc.dao.UsersDaoIml.java
@SuppressWarnings("unchecked") public Collection<Users> findAllUsers(Integer offset, Integer maxResults) { Criteria criteria = createEntityCriteria().addOrder(Order.asc("firstName")); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates. criteria.setFirstResult(offset != null ? offset : 0).setMaxResults(maxResults != null ? maxResults : 20); List<Users> users = (List<Users>) criteria.list(); return users; //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.wonders.bud.freshmommy.service.content.dao.impl.ContentDaoImpl.java
License:Open Source License
@Override public Page<ContentPO> findByPageCustom(Page<ContentPO> page, String orQuery) { Criteria c = createCriteria(); if (page.getParam() != null) { c = page.getParam().andCriteria(c); }/*from w w w. j av a 2 s . c o m*/ if (orQuery != null) { Criterion cTitle = Restrictions.like("title", "%" + orQuery + "%"); Criterion cShortTitle = Restrictions.like("shortTitle", "%" + orQuery + "%"); LogicalExpression orExp1 = Restrictions.or(cTitle, cShortTitle); Criterion cTxt = Restrictions.like("txt", "%" + orQuery + "%"); LogicalExpression orExp = Restrictions.or(orExp1, cTxt); c.add(orExp); } c.setProjection(null); // ?? int totalCount = ((Long) c.setProjection(Projections.rowCount()).uniqueResult()).intValue(); c.setProjection(null); c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); // page if (page.getStart() > -1) { c.setFirstResult(page.getStart()); } if (page.getPagesize() > -1) { c.setMaxResults(page.getPagesize()); } List<ContentPO> result = c.list(); getSession().clear(); page.setResult(result); page.setTotal(totalCount); return page; }
From source file:com.wooki.domain.dao.GenericDAOImpl.java
License:Apache License
@SuppressWarnings("unchecked") public List<T> list(QueryFilter... filters) { Criteria crit = session.createCriteria(getEntityType()); crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); applyFilters(crit, filters);/* ww w . j a v a 2 s.co m*/ return (List<T>) crit.list(); }
From source file:com.xbwl.common.orm.hibernate.HibernateDao.java
License:Apache License
/** * countCriteria./* w w w .j a v a 2s.co m*/ */ @SuppressWarnings("unchecked") protected int countCriteriaResult(final Criteria c) { CriteriaImpl impl = (CriteriaImpl) c; // ProjectionResultTransformerOrderBy,Count Projection projection = impl.getProjection(); ResultTransformer transformer = impl.getResultTransformer(); List<CriteriaImpl.OrderEntry> orderEntries = null; try { orderEntries = (List) ReflectionUtils.getFieldValue(impl, "orderEntries"); ReflectionUtils.setFieldValue(impl, "orderEntries", new ArrayList()); } catch (Exception e) { logger.error(":{}", e.getMessage()); } // Count int totalCount = (Integer) c.setProjection(Projections.rowCount()).uniqueResult(); // Projection,ResultTransformerOrderBy c.setProjection(projection); if (projection == null) { c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); } if (transformer != null) { c.setResultTransformer(transformer); } try { ReflectionUtils.setFieldValue(impl, "orderEntries", orderEntries); } catch (Exception e) { logger.error(":{}", e.getMessage()); } return totalCount; }
From source file:com.yahoo.elide.datastores.hibernate3.HibernateTransaction.java
License:Apache License
/** * Generates the Hibernate ScrollableIterator for Hibernate Query. * * @param loadClass The hibernate class to build the query off of. * @param criteria The criteria to use for filters * @param sortingRules The possibly empty sorting rules. * @param pagination The Optional pagination object. * @return The Iterable for Hibernate./*from ww w .j a v a 2 s .c o m*/ */ public Iterable loadObjects(final Class<?> loadClass, final Criteria criteria, final Optional<Set<Order>> sortingRules, final Optional<Pagination> pagination, RequestScope scope) { if (sortingRules.isPresent()) { sortingRules.get().forEach(criteria::addOrder); } if (pagination.isPresent()) { Pagination paginationData = pagination.get(); criteria.setFirstResult(paginationData.getOffset()); criteria.setMaxResults(paginationData.getLimit()); } else { Integer queryLimit = getQueryLimit(); if (queryLimit != null) { criteria.setMaxResults(queryLimit); } } if (isJoinQuery()) { joinCriteria(criteria, loadClass, scope); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (!isScrollEnabled || isJoinQuery()) { return criteria.list(); } return new ScrollableIterator(criteria.scroll(scrollMode)); }