List of usage examples for org.hibernate.criterion Projections id
public static IdentifierProjection id()
From source file:org.encuestame.persistence.dao.imp.TweetPollDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<TweetPoll> getTweetpollByHashTagName(final String tagName, final Integer startResults, final Integer limitResults, final TypeSearchResult filterby, final SearchPeriods periods) { final DetachedCriteria detached = DetachedCriteria.forClass(TweetPoll.class) .createAlias("hashTags", "hashTags").setProjection(Projections.id()) .add(Subqueries.propertyIn("hashTags.hashTagId", DetachedCriteria.forClass(HashTag.class, "hash").setProjection(Projections.id()) .add(Restrictions.in("hash.hashTag", new String[] { tagName })))); final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class, "tweetPoll"); criteria.add(Subqueries.propertyIn("tweetPoll.tweetPollId", detached)); //if filters are defined. if (filterby != null) { if (filterby.equals(TypeSearchResult.HASHTAG)) { criteria.addOrder(Order.desc("tweetPoll.createDate")); } else if (filterby.equals(TypeSearchResult.HASHTAGRATED)) { criteria.addOrder(Order.desc("numbervotes")); }/* w ww . j av a 2 s . c om*/ } criteria.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE)); calculateSearchPeriodsDates(periods, detached, "createDate"); return (List<TweetPoll>) filterByMaxorStart(criteria, limitResults, startResults); }
From source file:org.encuestame.persistence.dao.imp.TweetPollDao.java
License:Apache License
public TweetPoll checkIfTweetPollHasHashTag(final String tagName, final SearchPeriods periods, final Long tpoll) { final DetachedCriteria detached = DetachedCriteria.forClass(TweetPoll.class) .createAlias("hashTags", "hashTags").setProjection(Projections.id()) .add(Restrictions.eq("tweetPoll.tweetPollId", tpoll)) .add(Subqueries.propertyIn("hashTags.hashTagId", DetachedCriteria.forClass(HashTag.class, "hash").setProjection(Projections.id()) .add(Restrictions.in("hash.hashTag", new String[] { tagName })))); final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class, "tweetPoll"); criteria.add(Subqueries.propertyIn("tweetPoll.tweetPollId", detached)); criteria.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE)); calculateSearchPeriodsDates(periods, detached, "createDate"); return (TweetPoll) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria)); }
From source file:org.encuestame.persistence.dao.imp.TweetPollDao.java
License:Apache License
@SuppressWarnings("unchecked") //FUTURE: this method return a List<Object[]> instead List<TweetPoll> public List<TweetPoll> getTweetPollsbyHashTagNameAndDateRange(final String tagName, final SearchPeriods period) { final DetachedCriteria detached = DetachedCriteria.forClass(TweetPoll.class) .createAlias("hashTags", "hashTags").setProjection(Projections.id()) .add(Subqueries.propertyIn("hashTags.hashTagId", DetachedCriteria.forClass(HashTag.class, "hash").setProjection(Projections.id()) .add(Restrictions.in("hash.hashTag", new String[] { tagName })))); final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class, "tweetPoll"); criteria.add(Subqueries.propertyIn("tweetPoll.tweetPollId", detached)); criteria.addOrder(Order.desc("tweetPoll.createDate")); criteria.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE)); ProjectionList projList = Projections.projectionList(); projList.add(Projections.groupProperty("createDate")); projList.add(Projections.rowCount()); criteria.setProjection(projList);/* w w w. j a v a 2 s . c o m*/ // calculateSearchPeriodsDates(period, criteria, "createDate"); return (List<TweetPoll>) getHibernateTemplate().findByCriteria(criteria); }
From source file:org.encuestame.persistence.dao.imp.TweetPollDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<Object[]> getTweetPollsRangeStats(final String tagName, final SearchPeriods period) { final DetachedCriteria detached = DetachedCriteria.forClass(TweetPoll.class) .createAlias("hashTags", "hashTags").setProjection(Projections.id()) .add(Subqueries.propertyIn("hashTags.hashTagId", DetachedCriteria.forClass(HashTag.class, "hash").setProjection(Projections.id()) .add(Restrictions.in("hash.hashTag", new String[] { tagName })))); final DetachedCriteria criteria = DetachedCriteria.forClass(TweetPoll.class, "tweetPoll"); criteria.add(Subqueries.propertyIn("tweetPoll.tweetPollId", detached)); criteria.addOrder(Order.desc("tweetPoll.createDate")); criteria.add(Restrictions.eq("publishTweetPoll", Boolean.TRUE)); ProjectionList projList = Projections.projectionList(); projList.add(Projections.groupProperty("createDate")); projList.add(Projections.rowCount()); criteria.setProjection(projList);/*from ww w.j ava 2 s.co m*/ calculateSearchPeriodsDates(period, criteria, "createDate"); return (List<Object[]>) getHibernateTemplate().findByCriteria(criteria); }
From source file:org.faster.orm.service.hibernate.with.option.HibernateProjectWithOptionService.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from ww w.java 2s . co m*/ public List<ID> projectIdByCriteria(DetachedCriteria dc, QueryOption queryOption) { dc.setProjection(Projections.id()); return fetchAll(dc, queryOption); }
From source file:org.fornax.cartridges.sculptor.framework.accessimpl.jpahibernate.JpaHibFindByConditionAccessImpl.java
License:Apache License
private void addProjection(Criteria criteria) throws PersistenceException { // Prepare projection // All orderBy fields has to be in result - SQL limitation ProjectionList proj = Projections.projectionList().add(Projections.id()); for (ConditionalCriteria crit : cndCriterias) { if (Operator.OrderAsc.equals(crit.getOperator()) || Operator.OrderDesc.equals(crit.getOperator())) { if (crit.getPropertyPath() != null && crit.getPropertyPath().length > 0) { throw new PersistenceException("Can't create distinct condition order by foreign field '" + crit.getPropertyFullName() + "'"); }//from w ww. j a v a 2 s. c om proj.add(Projections.property(crit.getPropertyFullName())); } } criteria.setProjection(Projections.distinct(proj)); }
From source file:org.goobi.production.flow.statistics.hibernate.FilterHelper.java
License:Open Source License
private static void limitToUserAssignedSteps(Conjunction con, Boolean stepOpenOnly, Boolean userAssignedStepsOnly) { /* show only open Steps or those in use by current user */ Session session = Helper.getHibernateSession(); /* identify current user */ LoginForm login = (LoginForm) Helper.getManagedBeanValue("#{LoginForm}"); if (login == null || login.getMyBenutzer() == null) { return;//from w w w.j a v a2s . c o m } /* init id-list, preset with item 0 */ List<Integer> idList = new ArrayList<Integer>(); idList.add(Integer.valueOf(0)); /* * hits by user groups */ Criteria critGroups = session.createCriteria(Task.class); if (stepOpenOnly) { critGroups.add(Restrictions.eq("processingStatus", Integer.valueOf(1))); } else if (userAssignedStepsOnly) { critGroups.add(Restrictions.eq("processingStatus", Integer.valueOf(2))); critGroups.add(Restrictions.eq("processingUser.id", login.getMyBenutzer().getId())); } else { critGroups.add(Restrictions.or(Restrictions.eq("processingStatus", Integer.valueOf(1)), Restrictions.like("processingStatus", Integer.valueOf(2)))); } /* only processes which are not templates */ Criteria temp = critGroups.createCriteria("process", "process"); critGroups.add(Restrictions.eq("process.template", Boolean.FALSE)); /* only assigned projects */ temp.createCriteria("project", "project").createCriteria("users", "projectUsers"); critGroups.add(Restrictions.eq("projectUsers.id", login.getMyBenutzer().getId())); /* * only steps assigned to the user groups the current user is member of */ critGroups.createCriteria("userGroups", "userGroups").createCriteria("users", "users"); critGroups.add(Restrictions.eq("users.id", login.getMyBenutzer().getId())); /* collecting the hits */ critGroups.setProjection(Projections.id()); for (Object o : critGroups.setFirstResult(0).setMaxResults(Integer.MAX_VALUE).list()) { idList.add((Integer) o); } /* * Users only */ Criteria critUser = session.createCriteria(Task.class); if (stepOpenOnly) { critUser.add(Restrictions.eq("processingStatus", Integer.valueOf(1))); } else if (userAssignedStepsOnly) { critUser.add(Restrictions.eq("processingStatus", Integer.valueOf(2))); critUser.add(Restrictions.eq("processingUser.id", login.getMyBenutzer().getId())); } else { critUser.add(Restrictions.or(Restrictions.eq("processingStatus", Integer.valueOf(1)), Restrictions.like("processingStatus", Integer.valueOf(2)))); } /* exclude templates */ Criteria temp2 = critUser.createCriteria("process", "process"); critUser.add(Restrictions.eq("process.template", Boolean.FALSE)); /* check project assignment */ temp2.createCriteria("project", "project").createCriteria("users", "projectUsers"); critUser.add(Restrictions.eq("projectUsers.id", login.getMyBenutzer().getId())); /* only steps where the user is assigned to */ critUser.createCriteria("processingUser", "processingUser"); critUser.add(Restrictions.eq("processingUser.id", login.getMyBenutzer().getId())); /* collecting the hits */ critUser.setProjection(Projections.id()); for (Object o : critUser.setFirstResult(0).setMaxResults(Integer.MAX_VALUE).list()) { idList.add((Integer) o); } /* * only taking the hits by restricting to the ids */ con.add(Restrictions.in("id", idList)); }
From source file:org.jdal.dao.hibernate.HibernateDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<Serializable> getKeys(Page<T> page) { Criteria criteria = getCriteria(page); return criteria.setProjection(Projections.id()).list(); }
From source file:org.jpos.gl.GLSession.java
License:Open Source License
/** * @param journal the journal.//from w w w . j av a 2s . c o m * @param start date (inclusive). * @param end date (inclusive). * @param searchString optional search string * @param findByPostDate true to find by postDate, false to find by timestamp * @return list of transactions' ids * @throws GLException if user doesn't have READ permission on this journal. */ public List findTransactionsIds(Journal journal, Date start, Date end, String searchString, boolean findByPostDate, int pageNumber, int pageSize) throws HibernateException, GLException { checkPermission(GLPermission.READ, journal); String dateField = findByPostDate ? "postDate" : "timestamp"; if (findByPostDate) { if (start != null) start = Util.floor(start); if (end != null) end = Util.ceil(end); } Criteria crit = session.createCriteria(GLTransaction.class).add(Restrictions.eq("journal", journal)); crit.setProjection(Projections.id()); if (start != null && start.equals(end)) crit.add(Restrictions.eq(dateField, start)); else { if (start != null) crit.add(Restrictions.ge(dateField, start)); if (end != null) crit.add(Restrictions.le(dateField, end)); } if (searchString != null) crit.add(Restrictions.like("detail", "%" + searchString + "%")); if (pageSize > 0 && pageNumber > 0) { crit.setMaxResults(pageSize); crit.setFirstResult(pageSize * (pageNumber - 1)); } return crit.list(); }
From source file:org.jpos.qi.EntityContainer.java
License:Open Source License
public Collection<?> getItemIds() { try {//from w w w . j a v a2s .c o m return (Collection<?>) DB.exec((db) -> { Criteria crit = getCriteria(db); crit.setProjection(Projections.id()); return crit.list(); }); } catch (Exception e) { QI.getQI().getLog().error(e); return null; } }