@Override public List<ThesaurusConcept> getPaginatedAvailableConceptsOfGroup( Integer startIndex, Integer limit, String groupId, String thesaurusId, Boolean onlyValidatedConcepts, String like) { DetachedCriteria dc = DetachedCriteria.forClass(ThesaurusConceptGroup.class, "gr"); dc.createCriteria("concepts", "tc", JoinType.RIGHT_OUTER_JOIN); dc.setProjection(Projections.projectionList().add(Projections.property("tc.identifier"))); dc.add(Restrictions.eq("gr.identifier", groupId)); Criteria criteria = selectPaginatedConceptsByAlphabeticalOrder(startIndex, limit); criteria.add(Subqueries.propertyNotIn("tc.identifier", dc)); selectThesaurus(criteria, thesaurusId); criteria.add( Restrictions.not( Restrictions.and( Restrictions.eq("topConcept", false), Restrictions.or( Restrictions.isNull("tc.parentConcepts"), Restrictions.isEmpty("tc.parentConcepts"))))); if (null != like) { conceptNameIsLike(criteria, like); } onlyValidatedConcepts(criteria, onlyValidatedConcepts); return criteria.list(); }
/** {@inheritDoc} */ public long totalLeafStoryPoints(Iteration iteration) { Criteria iterationCrit = getCurrentSession().createCriteria(Story.class); iterationCrit.add(Restrictions.isEmpty("children")); iterationCrit.add(Restrictions.ne("state", StoryState.DEFERRED)); iterationCrit.setProjection(Projections.projectionList().add(Projections.sum("storyPoints"))); return sum(0L, (Long) iterationCrit.uniqueResult()); }
/** {@inheritDoc} */ public long totalLeafDoneStoryPoints(Iteration iteration) { Criteria iterationCrit = getCurrentSession().createCriteria(Story.class); iterationCrit.add(Restrictions.isEmpty("children")); iterationCrit.setProjection(Projections.projectionList().add(Projections.sum("storyPoints"))); iterationCrit.add(Restrictions.eq("state", StoryState.DONE)); iterationCrit.add(Restrictions.isNotNull("storyPoints")); iterationCrit.add(Restrictions.eq("iteration", iteration)); Long result = (Long) iterationCrit.uniqueResult(); return result == null ? 0 : result; }
@Override public void buildUnordered(Criteria criteria) { // Type check if (showEventTypesM.getObject().size() < numberOfEventTypes) criteria.add(Restrictions.in("type", showEventTypesM.getObject())); else log.debug("Not filtering by event type"); criteria.createAlias("user", "user"); // Site Check List<Site> siteList = showSitesM.getObject(); if (siteList.size() < numberOfSites || inAPeriod.getObject()) { criteria.createAlias("user.periods", "period", JoinType.LEFT_OUTER_JOIN); Disjunction siteRestriction = Restrictions.disjunction(); if (!inAPeriod.getObject()) siteRestriction.add(Restrictions.isEmpty("user.periods")); // Show users with no periods if (!siteList.isEmpty()) siteRestriction.add( Restrictions.in("period.site", siteList)); // Show users with matching periods if (inAPeriod.getObject() && siteList.isEmpty()) { siteRestriction.add(Restrictions.idEq(-1L)); // Halt query early; don't show anyone. criteria.setMaxResults(0); } criteria.add(siteRestriction); } else { log.debug("Not filtering by period/site"); } if (fromDateM.getObject() != null && toDateM.getObject() != null) { Date startDate = midnightStart(fromDateM.getObject()); Date endDate = midnightEnd(toDateM.getObject()); log.debug("Considering events between {} and {}", startDate, endDate); criteria.add(Restrictions.between("insertTime", startDate, endDate)); } // set permission check if (showPermissionUsers.getObject()) { criteria.add(Restrictions.eq("user.permission", true)); } // Also load ResponseData elements in the same query, to avoid thousands of subsequent // queries. criteria.setFetchMode("responseData", FetchMode.JOIN); // The join with periods results in multiple rows for multi-period users. // Unfortunately, this confuses the dataprovider, which still counts the duplicates // and therefore doesn't return a full page full of items each time. criteria.setResultTransformer( CriteriaSpecification .DISTINCT_ROOT_ENTITY); // Remove duplicate rows as a result of the INNER JOIN }
private Criteria criteria(FullTextSession session) { final Class<?> cls = values.onlyTypes.get(0); Criteria criteria = session.createCriteria(cls); AnnotationCriteria ann = new AnnotationCriteria(criteria, values.fetchAnnotations); ids(criteria); ownerOrGroup(cls, criteria); createdOrModified(cls, criteria); annotatedBy(ann); annotatedBetween(ann); // annotatedWith if (values.onlyAnnotatedWith != null) { if (values.onlyAnnotatedWith.size() > 1) { throw new ApiUsageException( "HHH-879: " + "At the moment Hibernate cannot fulfill this request.\n" + "Please use only a single onlyAnnotatedWith " + "parameter when performing full text searches."); } else if (values.onlyAnnotatedWith.size() > 0) { if (!IAnnotated.class.isAssignableFrom(cls)) { // A non-IAnnotated object cannot have any // Annotations, and so our results are null return null; // EARLY EXIT ! } else { for (Class<?> annCls : values.onlyAnnotatedWith) { SimpleExpression ofType = new TypeEqualityExpression("class", annCls); ann.getChild().add(ofType); } } } else { criteria.add(Restrictions.isEmpty("annotationLinks")); } } // orderBy if (values.orderBy.size() > 0) { for (int i = 0; i < values.orderBy.size(); i++) { String orderBy = values.orderBy.get(i); String orderWithoutMode = orderByPath(orderBy); boolean ascending = orderByAscending(orderBy); if (ascending) { criteria.addOrder(Order.asc(orderWithoutMode)); } else { criteria.addOrder(Order.desc(orderWithoutMode)); } } } return criteria; }
private void attachLeafFilters(Criteria projectCrit, Criteria iterationCrit, Project project) { projectCrit.add(Restrictions.eq("backlog", project)); projectCrit.add(Restrictions.isEmpty("children")); iterationCrit.createCriteria("backlog").add(Restrictions.eq("parent", project)); iterationCrit.add(Restrictions.isEmpty("children")); }
private void selectNoParents(Criteria criteria) { criteria.add( Restrictions.or( Restrictions.isNull("tc.parentConcepts"), Restrictions.isEmpty("tc.parentConcepts"))); }
private Criterion orderStateIn(List<String> values, Criteria criteria) { FilterUtils.addAlias(criteria, "orders", "o", JoinType.LEFT_OUTER_JOIN); return Restrictions.or( Restrictions.isEmpty("orders"), Restrictions.in("o.currentOrderStateName", values)); }