/** * Adds attribute value criteria to the given criteria query * * @param criteria the criteria * @param serializedAttributeValues the serialized attribute values * @param <AT> the attribute type */ public static <AT extends AttributeType> void addAttributeCriteria(Criteria criteria, Map<AT, String> serializedAttributeValues) { Conjunction conjunction = Restrictions.conjunction(); int a = 0; for (Map.Entry<AT, String> entry : serializedAttributeValues.entrySet()) { String alias = "attributes" + (a++); DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Location.class).setProjection(Projections.id()); detachedCriteria.createAlias("attributes", alias); detachedCriteria.add(Restrictions.eq(alias + ".attributeType", entry.getKey())); detachedCriteria.add(Restrictions.eq(alias + ".valueReference", entry.getValue())); detachedCriteria.add(Restrictions.eq(alias + ".voided", false)); conjunction.add(Property.forName("id").in(detachedCriteria)); } criteria.add(conjunction); }
public Projection toHibernateProjection(Query.Projection gormProjection) { return Projections.id(); } });
@Override public ProjectionList id() { projectionList.add(Projections.id()); return this; }
@Override public ProjectionList id() { projectionList.add(Projections.id()); return this; }
public org.grails.datastore.mapping.query.api.ProjectionList id() { final IdentifierProjection proj = Projections.id(); addProjectionToList(proj, null); return this; }
public org.grails.datastore.mapping.query.api.ProjectionList id() { final IdentifierProjection proj = Projections.id(); addProjectionToList(proj, null); return this; }
/** * @return list of all currency ids * @see org.jpos.gl.Currency */ public List<String> getCurrencyCodes() { return db.session() .createCriteria(Currency.class) .setProjection(Projections.id()) .list(); }
public HibernateRequest<T> projId(String pidProperty) { proj(Projections.id().as(pidProperty)); return this; }
public void deleteProcessDefinition(ProcessDefinition processDefinition) { try { // delete all instances of the given process List processInstances = session.createCriteria(ProcessInstance.class) .add(Restrictions.eq("processDefinition", processDefinition)) .setProjection(Projections.id()) .list(); for (Iterator iter = processInstances.iterator(); iter.hasNext();) { Long id = (Long) iter.next(); ProcessInstance processInstance = (ProcessInstance) session.get(ProcessInstance.class, id); if (processInstance != null) deleteProcessInstance(processInstance); } List referencingProcessStates = findReferencingProcessStates(processDefinition); for (Iterator i = referencingProcessStates.iterator(); i.hasNext();) { ProcessState processState = (ProcessState) i.next(); processState.setSubProcessDefinition(null); } // then delete the process definition session.delete(processDefinition); } catch (HibernateException e) { handle(e); throw new JbpmPersistenceException("could not delete " + processDefinition, e); } }
public void deleteProcessDefinition(ProcessDefinition processDefinition) { try { // delete all instances of the given process List processInstances = session.createCriteria(ProcessInstance.class) .add(Restrictions.eq("processDefinition", processDefinition)) .setProjection(Projections.id()) .list(); for (Iterator iter = processInstances.iterator(); iter.hasNext();) { Long id = (Long) iter.next(); ProcessInstance processInstance = (ProcessInstance) session.get(ProcessInstance.class, id); if (processInstance != null) deleteProcessInstance(processInstance); } List referencingProcessStates = findReferencingProcessStates(processDefinition); for (Iterator i = referencingProcessStates.iterator(); i.hasNext();) { ProcessState processState = (ProcessState) i.next(); processState.setSubProcessDefinition(null); } // then delete the process definition session.delete(processDefinition); } catch (HibernateException e) { handle(e); throw new JbpmPersistenceException("could not delete " + processDefinition, e); } }
/** * @param directories directories to search for memberships * @return all memberships across all directories (used for export). */ @SuppressWarnings("unchecked") public List<InternalMembership> findAllLocal(Collection<Directory> directories) { if (directories == null || directories.isEmpty()) { return Collections.emptyList(); } return session().createCriteria(getPersistentClass()) .add(Restrictions.in("directory", directories)) .add(Subqueries.propertyIn("parentId", DetachedCriteria.forClass(InternalGroup.class) .add(Restrictions.eq("local", true)) .setProjection(Projections.id()))) .list(); }
/** * Creates a projection onto a view, and also include the id in the projection. * * @param viewType The view to project onto. * * @return A projection onto a view plus the id. */ private ProjectionList projectToIdAndView(ComponentType viewType) { // Project the id property and the remaining properties that are required to project // the results onto the specified view type. ProjectionList properties = Projections.projectionList().add(Projections.id()); for (String fieldName : viewType.getAllPropertyTypes().keySet()) { properties.add(Property.forName(fieldName)); } return properties; }
public List<PROCESS_INSTANCE> retrieveProcessInstancesWith(PROCESS_DEF process, MUser creatingUser, Boolean active) { Objects.requireNonNull(process); Criteria c = getSession().createCriteria(getClassProcessInstance(), "PI"); c.createAlias("PI.processVersion", "DEF"); c.add(Restrictions.eq("DEF.processDefinition", process)); if (active != null) { DetachedCriteria sub = DetachedCriteria.forClass(getClassTaskInstance(), "T"); sub.createAlias("T.task", "TA"); sub.add(Restrictions.eqProperty("T.processInstance.cod", "PI.cod")); sub.add(Restrictions.isNull("T.endDate")); if (active) { sub.add(Restrictions.ne("TA.type", TaskType.END)); } else { sub.add(Restrictions.eq("TA.type", TaskType.END)); } sub.setProjection(Projections.id()); c.add(Subqueries.exists(sub)); } if (creatingUser != null) { c.add(Restrictions.eq("PI.userCreator", creatingUser)); } c.setCacheable(true).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return c.list(); }
public List<FLOW_INSTANCE> retrieveFlowInstancesWith(FLOW_DEFINITION flowDefinition, SUser creatingUser, Boolean active) { Objects.requireNonNull(flowDefinition); Criteria c = getSession().createCriteria(getClassFlowInstance(), "PI"); c.createAlias("PI.flowVersion", "DEF"); c.add(Restrictions.eq("DEF.flowDefinition", flowDefinition)); if (active != null) { DetachedCriteria sub = DetachedCriteria.forClass(getClassTaskInstance(), "T"); sub.createAlias("T.task", "TA"); sub.add(Restrictions.eqProperty("T.flowInstance.cod", "PI.cod")); sub.add(Restrictions.isNull("T.endDate")); if (active) { sub.add(Restrictions.ne("TA.type", TaskType.END)); } else { sub.add(Restrictions.eq("TA.type", TaskType.END)); } sub.setProjection(Projections.id()); c.add(Subqueries.exists(sub)); } if (creatingUser != null) { c.add(Restrictions.eq("PI.userCreator", creatingUser)); } c.setCacheable(true).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return c.list(); }
public List<PROCESS_INSTANCE> retrieveProcessInstancesWith(PROCESS_DEF process, MUser creatingUser, Boolean active) { Objects.requireNonNull(process); Criteria c = getSession().createCriteria(getClassProcessInstance(), "PI"); c.createAlias("PI.processVersion", "DEF"); c.add(Restrictions.eq("DEF.processDefinition", process)); if (active != null) { DetachedCriteria sub = DetachedCriteria.forClass(getClassTaskInstance(), "T"); sub.createAlias("T.task", "TA"); sub.add(Restrictions.eqProperty("T.processInstance.cod", "PI.cod")); sub.add(Restrictions.isNull("T.endDate")); if (active) { sub.add(Restrictions.ne("TA.type", TaskType.END)); } else { sub.add(Restrictions.eq("TA.type", TaskType.END)); } sub.setProjection(Projections.id()); c.add(Subqueries.exists(sub)); } if (creatingUser != null) { c.add(Restrictions.eq("PI.userCreator", creatingUser)); } c.setCacheable(true).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return c.list(); }
private DetachedCriteria buildCriteria( DetachedCriteria detachedCriteria, Query query ) { if ( query.isEmpty() ) { return detachedCriteria.setProjection( Projections.distinct( Projections.id() ) ); } org.hibernate.criterion.Junction junction = getHibernateJunction( query.getRootJunctionType() ); detachedCriteria.add( junction ); for ( org.hisp.dhis.query.Criterion criterion : query.getCriterions() ) { addCriterion( junction, criterion ); } query.getAliases().forEach( alias -> detachedCriteria.createAlias( alias, alias ) ); return detachedCriteria.setProjection( Projections.distinct( Projections.id() ) ); }
public DetachedCriteria getCriteria() { if (m_criteria == null) { throw new IllegalStateException("Unable to determine Class<?> of this criteria!"); } for (final Criterion criterion : m_criterions) { m_criteria.add(criterion); } /* * By implementing distinct() as a subquery, we lose the ability to sort the * results on any of the aliased columns. See bug NMS-7830 for more details. * * @see http://issues.opennms.org/browse/NMS-7830 */ if (m_distinct) { /* * This technique is documented in the comments at: * * @see http://floledermann.blogspot.com/2007/10/solving-hibernate-criterias-distinct.html?showComment=1262701416137#c529514229952853263 */ m_criteria.setProjection(Projections.distinct(Projections.id())); final DetachedCriteria newCriteria = DetachedCriteria.forClass(m_class); newCriteria.add(Subqueries.propertyIn("id", m_criteria)); m_criteria = newCriteria; } for (final org.hibernate.criterion.Order order : m_orders) { m_criteria.addOrder(order); } return m_criteria; }
@Override public Flowable<K> publishKeys(Predicate<? super K> filter) { return Flowable.using(() -> { EntityManager emStream = emf.createEntityManager(); Session session = emStream.unwrap(Session.class); Criteria criteria = session.createCriteria(configuration.entityClass()).setProjection(Projections.id()).setReadOnly(true); if (setFetchSizeMinInteger) { criteria.setFetchSize(Integer.MIN_VALUE); } ScrollableResults results = criteria.scroll(ScrollMode.FORWARD_ONLY); return new KeyValuePair<>(emStream, results); }, kvp -> { ScrollableResults results = kvp.getValue(); return Flowable.fromIterable(() -> new ScrollableResultsIterator(results, filter) ); }, kvp -> { try { kvp.getValue().close(); } finally { kvp.getKey().close(); } }); }
sub.add(Restrictions.in("TV.taskDefinition", states)); sub.add(Restrictions.isNull("T.endDate")); sub.setProjection(Projections.id());
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()+"'"); } proj.add(Projections.property(crit.getPropertyFullName())); } } criteria.setProjection(Projections.distinct(proj)); }