List of usage examples for org.hibernate.criterion ProjectionList add
public ProjectionList add(Projection projection)
From source file:org.wise.portal.dao.ideabasket.impl.HibernateIdeaBasketDao.java
License:Open Source License
/** * Get all the latest IdeaBaskets with the given run id * /*from w w w. jav a 2 s .co m*/ * we will basically be performing this query * select * from vle_database.ideaBasket i where id in(SELECT max(id) FROM vle_database.ideaBasket i where runid=<insert runId> and workgroupid in(<insert workgroup ids>) group by workgroupid) * * @param runId the id of the run * @param workgroupIds a list of workgroup ids * @return all the latest IdeaBaskets for a run id */ @SuppressWarnings("unchecked") @Transactional(readOnly = true) public List<IdeaBasket> getLatestIdeaBasketsForRunIdWorkgroupIds(long runId, List<Long> workgroupIds) { Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession(); /* * create a projection that will give us the latest idea basket id * for each workgroup id in the run. the projection will return * an array of array objects that will look like [id, workgroupId]. * each workgroup id will only appear once. */ ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.max("id")); projectionList.add(Projections.groupProperty("workgroupId")); //this first query will filter on the runId and workgroupids and the projection List latestIdeaBasketIdsProjection = session.createCriteria(IdeaBasket.class) .add(Restrictions.eq("runId", runId)).add(Restrictions.in("workgroupId", workgroupIds)) .setProjection(projectionList).list(); //the list that will contain all the idea basket ids we want List<Long> ideaBasketIds = new ArrayList<Long>(); //loop through all the results from our first query for (int x = 0; x < latestIdeaBasketIdsProjection.size(); x++) { //get the idea basket id Object[] projection = (Object[]) latestIdeaBasketIdsProjection.get(x); Long ideaBasketId = (Long) projection[0]; ideaBasketIds.add(ideaBasketId); } List<IdeaBasket> result = new ArrayList<IdeaBasket>(); if (ideaBasketIds.size() > 0) { //this second query will retrieve all the idea basket ids we retrieved from the first query result = session.createCriteria(IdeaBasket.class).add(createIdOrCriterion(ideaBasketIds, 0)).list(); } return result; }
From source file:uk.nhs.cfh.dsp.srth.expression.repository.impl.ExpressionMappingObjectDAOImpl.java
License:Apache License
/** * This method returns all contained {@link uk.nhs.cfh.dsp.srth.expression.repository.om.ExpressionMappingObject}s, * in the repository, but only returns their UUIDs and compositional grammar form of their NFE. * * @return the list// w ww.j av a2 s . c o m */ public List<ExpressionMappingObject> returnAllAsLiteObjects() { List list = this.hibernateTemplate.executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(ExpressionMappingObjectImpl.class); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property(NFE_UUID)); projectionList.add(Projections.property(NFE_CGF)); criteria.setProjection(projectionList); return criteria.list(); } }); return returnLiteObjects(list); }
From source file:uk.nhs.cfh.dsp.srth.expression.repository.impl.ExpressionMappingObjectDAOImpl.java
License:Apache License
/** * This method returns all distinct contained {@link uk.nhs.cfh.dsp.srth.expression.repository.om.ExpressionMappingObject}s, * in the repository, but only returns their UUIDs and compositional grammar form of their NFE. * * @return the list/* www .ja va2 s . c om*/ */ public List<ExpressionMappingObject> returnAllDistinctLiteObjects() { List list = this.hibernateTemplate.executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(ExpressionMappingObjectImpl.class); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.distinct(Projections.property(NFE_UUID))); projectionList.add(Projections.property(NFE_CGF)); criteria.setProjection(projectionList); return criteria.list(); } }); return returnLiteObjects(list); }
From source file:uk.nhs.cfh.dsp.srth.expression.repository.impl.ExpressionMappingObjectDAOImpl.java
License:Apache License
/** * This method returns all distinct {@link uk.nhs.cfh.dsp.srth.expression.repository.om.ExpressionMappingObject}s, * in the repository which match the given proximal primitive using SQL like operator, * but only returns their UUIDs and compositional grammar form of their NFE. * * @param proximalPrimitive the proximal primitive * @return the list/* ww w. j a v a 2 s . co m*/ */ public List<ExpressionMappingObject> returnAllMatchingDistinctLiteObjects(final String proximalPrimitive) { List list = this.hibernateTemplate.executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(ExpressionMappingObjectImpl.class); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.distinct(Projections.property(NFE_UUID))); projectionList.add(Projections.property(NFE_CGF)); criteria.setProjection(projectionList); criteria.add(Restrictions.like(NFE_CGF, proximalPrimitive + "%")); return criteria.list(); } }); return returnLiteObjects(list); }
From source file:uk.nhs.cfh.dsp.srth.expression.repository.impl.ExpressionMappingObjectDAOImpl.java
License:Apache License
public List<UUID> getCTUIdsUsingNFEFIds(final Collection<UUID> nfeUUIDs) { if (nfeUUIDs.size() < 1) { return Collections.emptyList(); } else {/*www .j a v a 2s.c om*/ List list = this.hibernateTemplate.executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(ExpressionMappingObjectImpl.class); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.distinct(Projections.property(CTU_UUID))); criteria.setProjection(projectionList); criteria.add(Restrictions.in(NFE_UUID, nfeUUIDs.toArray())); return criteria.list(); } }); return list; } }