@Override protected Collection<ECRFField> handleFindAllSorted(String nameInfix, Integer limit) throws Exception { org.hibernate.Criteria ecrfFieldCriteria = createEcrfFieldCriteria(); if (!CommonUtil.isEmptyString(nameInfix)) { org.hibernate.Criteria trialCriteria = ecrfFieldCriteria.createCriteria("trial", "trial0", CriteriaSpecification.INNER_JOIN); org.hibernate.Criteria ecrfCriteria = ecrfFieldCriteria.createCriteria("ecrf", "ecrf0", CriteriaSpecification.INNER_JOIN); org.hibernate.Criteria fieldCriteria = ecrfFieldCriteria.createCriteria("field", "inputField", CriteriaSpecification.INNER_JOIN); //fieldCriteria.add(Restrictions.eq("localized", false)); ecrfFieldCriteria.add(Restrictions.or( (new CategoryCriterion(nameInfix, "section", MatchMode.ANYWHERE)).getRestriction(), Restrictions.or( (new CategoryCriterion(nameInfix, "inputField.nameL10nKey", MatchMode.ANYWHERE)).getRestriction(), Restrictions.or( (new CategoryCriterion(nameInfix, "ecrf0.name", MatchMode.ANYWHERE)).getRestriction(), (new CategoryCriterion(nameInfix, "trial0.name", MatchMode.ANYWHERE)).getRestriction() )))); } applySortOrders(ecrfFieldCriteria); CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.ECRF_FIELD_FIELD_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.ECRF_FIELD_FIELD_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), ecrfFieldCriteria); return ecrfFieldCriteria.list(); }
private static void applyUsedByCriterions(org.hibernate.Criteria selectionSetValueCriteria, String nameInfix, String inputFieldProperty) { if (selectionSetValueCriteria != null) { org.hibernate.Criteria fieldCriteria = selectionSetValueCriteria.createCriteria("field","inputField", CriteriaSpecification.INNER_JOIN); if (!CommonUtil.isEmptyString(inputFieldProperty)) { fieldCriteria.add(Restrictions.not(Restrictions.isEmpty(inputFieldProperty))); } //fieldCriteria.add(Restrictions.eq("localized", false)); if (!CommonUtil.isEmptyString(nameInfix)) { selectionSetValueCriteria.add(Restrictions.or( (new CategoryCriterion(nameInfix, "inputField.nameL10nKey", MatchMode.ANYWHERE)).getRestriction(), (new CategoryCriterion(nameInfix, "nameL10nKey", MatchMode.ANYWHERE)).getRestriction() )); } } }
@Override protected Collection<Inquiry> handleFindAllSorted(String nameInfix, Integer limit) throws Exception { org.hibernate.Criteria inquiryCriteria = createInquiryCriteria(); if (!CommonUtil.isEmptyString(nameInfix)) { org.hibernate.Criteria trialCriteria = inquiryCriteria.createCriteria("trial", "trial0", CriteriaSpecification.INNER_JOIN); org.hibernate.Criteria fieldCriteria = inquiryCriteria.createCriteria("field", "inputField", CriteriaSpecification.INNER_JOIN); //fieldCriteria.add(Restrictions.eq("localized", false)); inquiryCriteria.add(Restrictions.or( (new CategoryCriterion(nameInfix, "category", MatchMode.ANYWHERE)).getRestriction(), Restrictions.or( (new CategoryCriterion(nameInfix, "inputField.nameL10nKey", MatchMode.ANYWHERE)).getRestriction(), (new CategoryCriterion(nameInfix, "trial0.name", MatchMode.ANYWHERE)).getRestriction() ))); } applySortOrders(inquiryCriteria); CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.INQUIRY_FIELD_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.INQUIRY_FIELD_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), inquiryCriteria); return inquiryCriteria.list(); }
@Override protected Collection<Inquiry> handleFindByParticipantsActiveSorted(Long trialId, Boolean active, Boolean activeSignup) throws Exception { org.hibernate.Criteria inquiryCriteria = createInquiryCriteria(); if (active != null) { inquiryCriteria.add(Restrictions.eq("active", active.booleanValue())); } if (activeSignup != null) { inquiryCriteria.add(Restrictions.eq("activeSignup", activeSignup.booleanValue())); } if (trialId != null) { inquiryCriteria.createCriteria("inquiryValues", CriteriaSpecification.INNER_JOIN).createCriteria("proband", CriteriaSpecification.INNER_JOIN) .createCriteria("trialParticipations", CriteriaSpecification.INNER_JOIN).add(Restrictions.eq("trial.id", trialId.longValue())); } applySortOrders(inquiryCriteria); // inquiryCriteria.setResultTransformer(org.hibernate.Criteria.DISTINCT_ROOT_ENTITY); // return inquiryCriteria.list(); return CriteriaUtil.listDistinctRoot(inquiryCriteria, this, "trial.id", "category", "position"); }
@Override protected Collection<Inquiry> handleFindByTrialActiveExcelProbandSorted(Long trialId, Boolean active, Boolean activeSignup, Boolean excel, Long probandId) throws Exception { org.hibernate.Criteria inquiryCriteria = createInquiryCriteria(); if (trialId != null) { inquiryCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (active != null) { inquiryCriteria.add(Restrictions.eq("active", active.booleanValue())); } if (activeSignup != null) { inquiryCriteria.add(Restrictions.eq("activeSignup", activeSignup.booleanValue())); } if (excel != null) { inquiryCriteria.add(Restrictions.or(Restrictions.eq("excelValue", excel.booleanValue()), Restrictions.eq("excelDate", excel.booleanValue()))); } if (probandId != null) { inquiryCriteria.createCriteria("inquiryValues", CriteriaSpecification.INNER_JOIN).add(Restrictions.eq("proband.id", probandId.longValue())); } applySortOrders(inquiryCriteria); // inquiryCriteria.setResultTransformer(org.hibernate.Criteria.DISTINCT_ROOT_ENTITY); // return inquiryCriteria.list(); return CriteriaUtil.listDistinctRoot(inquiryCriteria, this, "trial.id", "category", "position"); }
@Override protected long handleGetTrialGroupProbandCount( Long trialId, Long probandGroupId, Long probandId, boolean total) throws Exception { org.hibernate.Criteria listEntryCriteria = createListEntryCriteria(); if (trialId != null) { listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (probandGroupId != null) { listEntryCriteria.add(Restrictions.eq("group.id", probandGroupId.longValue())); } if (probandId != null) { listEntryCriteria.add(Restrictions.eq("proband.id", probandId.longValue())); } if (!total) { listEntryCriteria.createCriteria("lastStatus", CriteriaSpecification.INNER_JOIN).createCriteria("status", CriteriaSpecification.INNER_JOIN) .add(Restrictions.eq("count", true)); // istEntryCriteria.add(Restrictions.eq("proband.id", probandId.longValue())); } return (Long) listEntryCriteria.setProjection(Projections.rowCount()).uniqueResult(); }
@Override protected Collection<Map> handleFindByListEntryJs(Long probandListEntryId, boolean sort, Boolean js, PSFVO psf) throws Exception { org.hibernate.Criteria listEntryTagCriteria = createProbandListEntryTagCriteria(probandListEntryId); // if (active != null) { // ecrfFieldCriteria.add(Restrictions.eq("active", active.booleanValue())); // } if (js != null) { if (js) { listEntryTagCriteria.add(Restrictions.and(Restrictions.ne("jsVariableName", ""), Restrictions.isNotNull("jsVariableName"))); } else { listEntryTagCriteria.add(Restrictions.or(Restrictions.eq("jsVariableName", ""), Restrictions.isNull("jsVariableName"))); } } if (psf != null) { SubCriteriaMap criteriaMap = new SubCriteriaMap(ProbandListEntryTag.class, listEntryTagCriteria); // clear sort and filters? CriteriaUtil.applyPSFVO(criteriaMap, psf); } if (sort) { applySortOrders(listEntryTagCriteria); } listEntryTagCriteria.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); return listEntryTagCriteria.list(); }
private static void applyAspSubstanceNameCriterions(org.hibernate.Criteria aspSubstanceCriteria, String nameInfix) { String revision = Settings.getString(SettingCodes.ASP_REVISION, Bundle.SETTINGS, DefaultSettings.ASP_REVISION); ArrayList<CategoryCriterion> criterions = new ArrayList<CategoryCriterion>(); criterions.add(new CategoryCriterion(nameInfix, "name", MatchMode.ANYWHERE)); if (MATCH_ASP_NAME || MATCH_ASP_REGISTRATION_NUMBER || MATCH_ATC_CODE_CODE) { org.hibernate.Criteria aspsCriteria = aspSubstanceCriteria.createCriteria("asps", "asps0", CriteriaSpecification.LEFT_JOIN); if (MATCH_ASP_NAME) { criterions.add(new CategoryCriterion(nameInfix, "asps0.name", MatchMode.ANYWHERE)); } if (MATCH_ASP_REGISTRATION_NUMBER) { criterions.add(new CategoryCriterion(nameInfix, "asps0.registrationNumber", MatchMode.EXACT)); } aspsCriteria.add(Restrictions.eq("revision", revision)); if (MATCH_ATC_CODE_CODE) { org.hibernate.Criteria atcCodesCriteria = aspsCriteria.createCriteria("atcCodes", "atcCodes0", CriteriaSpecification.LEFT_JOIN); atcCodesCriteria.add(Restrictions.eq("revision", revision)); criterions.add(new CategoryCriterion(nameInfix, "atcCodes0.code", MatchMode.EXACT)); } } CategoryCriterion.applyOr(aspSubstanceCriteria, criterions); aspSubstanceCriteria.add(Restrictions.eq("revision", revision)); }
@Override protected Collection<JournalEntry> handleFindEcrfJournal(Long trailId) throws Exception { org.hibernate.Criteria journalCriteria = createJournalEntryCriteria(null); journalCriteria.add(Restrictions.or( Restrictions.eq("systemMessage", false), Restrictions.or(Restrictions.and(Restrictions.eq("systemMessage", true), Restrictions.eq("systemMessageModule", JournalModule.TRIAL_JOURNAL)), Restrictions.and(Restrictions.eq("systemMessage", true), Restrictions.eq("systemMessageModule", JournalModule.INPUT_FIELD_JOURNAL))) ) ); journalCriteria.createCriteria("category", CriteriaSpecification.LEFT_JOIN).add(Restrictions.or( Restrictions.or(Restrictions.eq("module", JournalModule.TRIAL_JOURNAL),Restrictions.eq("module", JournalModule.INPUT_FIELD_JOURNAL)), Restrictions.isNull("module"))); journalCriteria.createCriteria("inputField", CriteriaSpecification.LEFT_JOIN).createCriteria("ecrfFields", "trialEcrfField", CriteriaSpecification.LEFT_JOIN); journalCriteria.add(Restrictions.or(Restrictions.eq("trial.id", trailId.longValue()), Restrictions.eq("trialEcrfField.trial.id", trailId.longValue()))); journalCriteria.addOrder(Order.asc("id")); return CriteriaUtil.listDistinctRoot(journalCriteria, this); //journalCriteria.setResultTransformer(org.hibernate.Criteria.DISTINCT_ROOT_ENTITY); //loaded in memory anyway. //return journalCriteria.list(); }
@Override protected Collection<MaintenanceScheduleItem> handleFindMaintenanceInterval( Long inventoryId, Long departmentId, Long inventoryCategoryId, Long responsiblePersonId, Boolean reminder, Timestamp from, Timestamp to) throws Exception { Criteria maintenanceItemCriteria = createMaintenanceItemCriteria(); if (inventoryId != null || departmentId != null || inventoryCategoryId != null) { Criteria inventoryCriteria = maintenanceItemCriteria.createCriteria("inventory", CriteriaSpecification.INNER_JOIN); if (inventoryId != null) { inventoryCriteria.add(Restrictions.idEq(inventoryId.longValue())); } if (departmentId != null) { inventoryCriteria.add(Restrictions.eq("department.id", departmentId.longValue())); } if (inventoryCategoryId != null) { inventoryCriteria.add(Restrictions.eq("category.id", inventoryCategoryId.longValue())); } } if (responsiblePersonId != null) { maintenanceItemCriteria.add(Restrictions.eq("responsiblePerson.id", responsiblePersonId.longValue())); } maintenanceItemCriteria.add(Restrictions.eq("active", true)); // performance only... return CriteriaUtil.listEvents(maintenanceItemCriteria, from, to, reminder); }
@Override protected Collection<CourseParticipationStatusEntry> handleFindByStaffCourseRelevantForCourseAppointments(Long staffId, Long courseId, Boolean isRelevantForCourseAppointments) throws Exception { org.hibernate.Criteria courseParticipationStatusEntryCriteria = createCourseParticipationStatusEntryCriteria(); if (staffId != null) { courseParticipationStatusEntryCriteria.add(Restrictions.eq("staff.id", staffId.longValue())); } if (courseId != null) { courseParticipationStatusEntryCriteria.add(Restrictions.eq("course.id", courseId.longValue())); } if (isRelevantForCourseAppointments != null) { courseParticipationStatusEntryCriteria.createCriteria("status", CriteriaSpecification.INNER_JOIN).add( Restrictions.eq("relevantForCourseAppointments", isRelevantForCourseAppointments.booleanValue())); } return courseParticipationStatusEntryCriteria.list(); }
private static void applyAspNameCriterions(org.hibernate.Criteria aspCriteria, String nameInfix) { String revision = Settings.getString(SettingCodes.ASP_REVISION, Bundle.SETTINGS, DefaultSettings.ASP_REVISION); ArrayList<CategoryCriterion> criterions = new ArrayList<CategoryCriterion>(); criterions.add(new CategoryCriterion(nameInfix, "name", MatchMode.ANYWHERE)); if (MATCH_REGISTRATION_NUMBER) { criterions.add(new CategoryCriterion(nameInfix, "registrationNumber", MatchMode.EXACT)); } if (MATCH_SUBSTANCE_NAME) { org.hibernate.Criteria substancesCriteria = aspCriteria.createCriteria("substances", "substances0", CriteriaSpecification.LEFT_JOIN); substancesCriteria.add(Restrictions.eq("revision", revision)); criterions.add(new CategoryCriterion(nameInfix, "substances0.name", MatchMode.ANYWHERE)); } if (MATCH_ATC_CODE_CODE) { org.hibernate.Criteria atcCodesCriteria = aspCriteria.createCriteria("atcCodes", "atcCodes0", CriteriaSpecification.LEFT_JOIN); atcCodesCriteria.add(Restrictions.eq("revision", revision)); criterions.add(new CategoryCriterion(nameInfix, "atcCodes0.code", MatchMode.EXACT)); } CategoryCriterion.applyOr(aspCriteria, criterions); aspCriteria.add(Restrictions.eq("revision", revision)); }
@Override protected long handleGetEcrfFieldMaxSelectionSetValueCount(Long trialId) throws Exception { org.hibernate.Criteria inputFieldCriteria = createInputFieldCriteria(); inputFieldCriteria.add( Restrictions.in("fieldType", SELECT_FIELD_TYPES)); // no AUTOCOMPLETE! org.hibernate.Criteria ecrfFieldCriteria = inputFieldCriteria.createCriteria("ecrfFields", "ecrfFields0", CriteriaSpecification.INNER_JOIN); ecrfFieldCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); org.hibernate.Criteria selectionSetValueCriteria = inputFieldCriteria.createCriteria("selectionSetValues","inputFieldSelectionSetValues", CriteriaSpecification.INNER_JOIN); inputFieldCriteria.setProjection(Projections.projectionList() .add(Projections.groupProperty("ecrfFields0.id")) .add(Projections.alias(Projections.count("inputFieldSelectionSetValues.id"),"selectionSetValuesCount"))); inputFieldCriteria.addOrder(Order.desc("selectionSetValuesCount")); inputFieldCriteria.setMaxResults(1); long maxSelectionSetValues = 0l; try { maxSelectionSetValues = (Long) ((Object[]) inputFieldCriteria.list().iterator().next())[1]; } catch (Exception e) { } return maxSelectionSetValues; }
@Override protected Collection<ProbandListEntryTag> handleFindByTrialExcelEcrfProbandSorted(Long trialId, Boolean excel, Boolean ecrf, Long probandId) throws Exception { org.hibernate.Criteria listEntryTagCriteria = createListEntryTagCriteria(); if (trialId != null) { listEntryTagCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (excel != null) { listEntryTagCriteria.add(Restrictions.or(Restrictions.eq("excelValue", excel.booleanValue()), Restrictions.eq("excelDate", excel.booleanValue()))); } if (ecrf != null) { listEntryTagCriteria.add(Restrictions.eq("ecrfValue", ecrf.booleanValue())); } if (probandId != null) { listEntryTagCriteria.createCriteria("tagValues", CriteriaSpecification.INNER_JOIN).createCriteria("listEntry", CriteriaSpecification.INNER_JOIN) .add(Restrictions.eq("proband.id", probandId.longValue())); } applySortOrders(listEntryTagCriteria); // listEntryTagCriteria.setResultTransformer(org.hibernate.Criteria.DISTINCT_ROOT_ENTITY); // return listEntryTagCriteria.list(); return CriteriaUtil.listDistinctRoot(listEntryTagCriteria, this, "trial.id", "position"); }
@Override protected Collection<InquiryValue> handleFindByTrialActiveProbandField( Long trialId, Boolean active, Boolean activeSignup, Long probandId, Long inputFieldId) throws Exception { org.hibernate.Criteria inquiryValueCriteria = createInquiryValueCriteria(); if (probandId != null) { inquiryValueCriteria.add(Restrictions.eq("proband.id", probandId.longValue())); } if (trialId != null || active != null || inputFieldId != null) { Criteria inquiryCriteria = inquiryValueCriteria.createCriteria("inquiry", CriteriaSpecification.INNER_JOIN); if (trialId != null) { inquiryCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (active != null) { inquiryCriteria.add(Restrictions.eq("active", active.booleanValue())); } if (activeSignup != null) { inquiryCriteria.add(Restrictions.eq("activeSignup", activeSignup.booleanValue())); } if (inputFieldId != null) { inquiryCriteria.add(Restrictions.eq("field.id", inputFieldId.longValue())); } } return inquiryValueCriteria.list(); }
@Override protected long handleGetCount(Long trialId, Boolean active, Boolean activeSignup, Long probandId) throws Exception { org.hibernate.Criteria inquiryValueCriteria = createInquiryValueCriteria(); if (probandId != null) { inquiryValueCriteria.add(Restrictions.eq("proband.id", probandId.longValue())); } if (trialId != null || active != null) { org.hibernate.Criteria inquiryCriteria = inquiryValueCriteria.createCriteria("inquiry", CriteriaSpecification.INNER_JOIN); if (trialId != null) { inquiryCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (active != null) { inquiryCriteria.add(Restrictions.eq("active", active.booleanValue())); } if (activeSignup != null) { inquiryCriteria.add(Restrictions.eq("activeSignup", activeSignup.booleanValue())); } } return (Long) inquiryValueCriteria.setProjection(Projections.rowCount()).uniqueResult(); }
@Override protected long handleGetCount(Long trialId, String category, Boolean active, Boolean activeSignup, Long probandId) throws Exception { org.hibernate.Criteria inquiryValueCriteria = createInquiryValueCriteria(); if (probandId != null) { inquiryValueCriteria.add(Restrictions.eq("proband.id", probandId.longValue())); } org.hibernate.Criteria inquiryCriteria = inquiryValueCriteria.createCriteria("inquiry", CriteriaSpecification.INNER_JOIN); if (trialId != null) { inquiryCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (active != null) { inquiryCriteria.add(Restrictions.eq("active", active.booleanValue())); } if (activeSignup != null) { inquiryCriteria.add(Restrictions.eq("activeSignup", activeSignup.booleanValue())); } if (category != null && category.length() > 0) { inquiryCriteria.add(Restrictions.eq("category", category)); } else { inquiryCriteria.add(Restrictions.or(Restrictions.eq("category", ""), Restrictions.isNull("category"))); } return (Long) inquiryValueCriteria.setProjection(Projections.rowCount()).uniqueResult(); }
@Override protected Collection<InventoryBooking> handleFindByCourseSorted(Long courseId, Boolean isRelevantForCourseAppointments, boolean sort) throws Exception { Criteria bookingCriteria = createBookingCriteria(); if (courseId != null) { bookingCriteria.add(Restrictions.eq("course.id", courseId.longValue())); } if (isRelevantForCourseAppointments != null) { bookingCriteria.createCriteria("inventory", CriteriaSpecification.INNER_JOIN).createCriteria("category", CriteriaSpecification.INNER_JOIN) .add(Restrictions.eq("relevantForCourseAppointments", isRelevantForCourseAppointments.booleanValue())); } if (sort) { bookingCriteria.addOrder(Order.asc("start")); } return bookingCriteria.list(); }
/** * @inheritDoc */ @Override protected Collection<InventoryBooking> handleFindByProbandCalendarInterval(Long probandId, String calendar, Timestamp from, Timestamp to, Boolean isRelevantForProbandAppointments) throws Exception { Criteria bookingCriteria = createBookingCriteria(); CriteriaUtil.applyClosedIntervalCriterion(bookingCriteria, from, to, null); if (probandId != null) { bookingCriteria.add(Restrictions.eq("proband.id", probandId.longValue())); } if (isRelevantForProbandAppointments != null) { bookingCriteria.createCriteria("inventory", CriteriaSpecification.INNER_JOIN).createCriteria("category", CriteriaSpecification.INNER_JOIN) .add(Restrictions.eq("relevantForProbandAppointments", isRelevantForProbandAppointments.booleanValue())); } CategoryCriterion.apply(bookingCriteria, new CategoryCriterion(calendar, "calendar", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS)); return bookingCriteria.list(); }
@Override protected Collection<InventoryBooking> handleFindByTrialCalendarInterval( Long trialId, String calendar, Timestamp from, Timestamp to, Boolean isRelevantForTrialAppointments) throws Exception { Criteria bookingCriteria = createBookingCriteria(); CriteriaUtil.applyClosedIntervalCriterion(bookingCriteria, from, to, null); if (trialId != null) { bookingCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (isRelevantForTrialAppointments != null) { bookingCriteria.createCriteria("inventory", CriteriaSpecification.INNER_JOIN).createCriteria("category", CriteriaSpecification.INNER_JOIN) .add(Restrictions.eq("relevantForTrialAppointments", isRelevantForTrialAppointments.booleanValue())); } CategoryCriterion.apply(bookingCriteria, new CategoryCriterion(calendar, "calendar", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS)); return bookingCriteria.list(); }
@Override protected Collection<TrialTagValue> handleFindByTrialExcelPayoffsSorted(Long trialId, Boolean payoffs, Boolean excel) throws Exception { org.hibernate.Criteria tagValueCriteria = createTagValueCriteria(); tagValueCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); Criteria tagCriteria = tagValueCriteria.createCriteria("tag", CriteriaSpecification.INNER_JOIN); if (excel != null) { tagCriteria.add(Restrictions.eq("excel", excel.booleanValue())); } if (payoffs != null) { tagCriteria.add(Restrictions.eq("payoffs", payoffs.booleanValue())); } tagCriteria.addOrder(Order.asc("nameL10nKey")); return tagValueCriteria.list(); }
@Override protected Collection<TimelineEvent> handleFindByTrialDepartmentStatusTypeShowInterval( Long trialId, Long departmentId, Long statusId, Long typeId, Boolean show, Timestamp from, Timestamp to) throws Exception { Criteria timelineEventCriteria = createTimelineEventCriteria(); CriteriaUtil.applyStopOptionalIntervalCriterion(timelineEventCriteria, from, to, null, true); if (trialId != null || departmentId != null || statusId != null) { Criteria trialCriteria = timelineEventCriteria.createCriteria("trial", CriteriaSpecification.INNER_JOIN); if (trialId != null) { trialCriteria.add(Restrictions.idEq(trialId.longValue())); } if (departmentId != null) { trialCriteria.add(Restrictions.eq("department.id", departmentId.longValue())); } if (statusId != null) { trialCriteria.add(Restrictions.eq("status.id", statusId.longValue())); } } if (typeId != null) { timelineEventCriteria.add(Restrictions.eq("type.id", typeId.longValue())); } if (show != null) { timelineEventCriteria.add(Restrictions.eq("show", show.booleanValue())); } return timelineEventCriteria.list(); }
/** * 分页查询函数,使用已设好查询条件与排序的<code>Criteria</code>. * * @param criteria * 条件 * @param pageNo * 当前页号 * @param pageSize * 每页最大记录数 * @return 含总记录数和当前页数据的Page对象. */ @Transactional(readOnly = true) public Page pagedQuery(Criteria criteria, int pageNo, int pageSize) { Assert.notNull(criteria); Assert.isTrue(pageNo >= 1, "pageNo should be eg 1"); Assert.isTrue(criteria instanceof CriteriaImpl); // 先把Projection和OrderBy条件取出来,清空两者来执行Count操作 Projection projection = HibernateUtils.findProjection(criteria); List orderEntries = HibernateUtils.findOrderEntries(criteria); HibernateUtils.setOrderEntries(criteria, Collections.EMPTY_LIST); // 执行查询 Integer totalCount = this.getCount(criteria); // 将之前的Projection和OrderBy条件重新设回去 criteria.setProjection(projection); if (projection == null) { criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); } HibernateUtils.setOrderEntries(criteria, orderEntries); // 返回分页对象 if (totalCount < 1) { return new Page(); } int start = (pageNo - 1) * pageSize; List result = criteria.setFirstResult(start).setMaxResults(pageSize) .list(); Page page = new Page(result, totalCount); page.setPageNo(pageNo); page.setPageSize(pageSize); return page; }
public ItemSerializerState(Set<String> categories, boolean export) { this.categories = categories; this.export = export; if( categories.contains(ItemSerializerService.CATEGORY_ALL) ) { allCategories = true; } itemProjection = Projections.projectionList().add(Projections.id().as(ID_ALIAS)); itemQuery = DetachedCriteria.forClass(Item.class, "i").setProjection(itemProjection) .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP) .add(Restrictions.eq("institution", CurrentInstitution.get())); }
@Override protected Collection<Trial> handleFindByParticipatingProbandSorted( Long probandId) throws Exception { org.hibernate.Criteria trialCriteria = createTrialCriteria(null); trialCriteria.createCriteria("probandListEntries", CriteriaSpecification.INNER_JOIN).add(Restrictions.eq("proband.id", probandId.longValue())); trialCriteria.addOrder(Order.asc("name")); return trialCriteria.list(); }
@SuppressWarnings("unchecked") public List<Map<String, Object>> querySqlObjects(String sql, Object params, Integer currentPage,Integer rowsInPage){ Query qry = em.createNativeQuery(sql); SQLQuery s = qry.unwrap(SQLQuery.class); //设置参数 if(params != null){ if(params instanceof List){ List<Object> paramList = (List<Object>) params; for(int i = 0, size = paramList.size(); i < size; i++){ qry.setParameter(i+1, paramList.get(i)); } }else if(params instanceof Map){ Map<String, Object> paramMap = (Map<String, Object>) params; for(String key : paramMap.keySet()){ qry.setParameter(key, paramMap.get(key)); } } } if (currentPage != null && rowsInPage != null) {//判断是否有分页 // 起始对象位置 qry.setFirstResult(rowsInPage * (currentPage - 1)); // 查询对象个数 qry.setMaxResults(rowsInPage); } s.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); List<Map<String, Object>> resultList=new ArrayList<Map<String, Object>>(); try { resultList=s.list(); } catch (Exception e) { }finally{ em.close(); } return resultList; }
/** * 根据SQL语句查询分页 * @param sql * @param currentPage * @param pageSize * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public PageModel queryForPageBySql(String sql,Integer currentPage,Integer pageSize){ PageModel page = new PageModel(); Integer totalCount = 0; Integer totalPage = 0; //EntityManager em = this.emf.createEntityManager(); Query qry = em.createNativeQuery(sql); Query qry2 = em.createNativeQuery(sql); SQLQuery s = qry.unwrap(SQLQuery.class); if (currentPage != null && pageSize != null) {//判断是否有分页 // 起始对象位置 qry.setFirstResult(pageSize * (currentPage - 1)); // 查询对象个数 qry.setMaxResults(pageSize); } s.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); List<Map> resultList=new ArrayList<Map>(); List list = qry2.getResultList(); totalCount = (list == null ? 0 : list.size()); if(totalCount % pageSize == 0){ totalPage = totalCount/pageSize; }else{ totalPage = totalCount/pageSize + 1; } try { resultList=s.list(); page.setCurrentPage(currentPage); page.setPageSize(pageSize); page.setList(resultList); page.setTotalCount(totalCount); page.setTotalPage(totalPage); } catch (Exception e) { e.printStackTrace(); }finally{ em.close(); } return page; }
@Override protected LinkedList<QService> load() { return new LinkedList<>( Spring.getInstance().getHt().findByCriteria(DetachedCriteria.forClass(QService.class). setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY). add(Property.forName("deleted").isNull()). addOrder(Property.forName("seqId").asc()). addOrder(Property.forName("id").asc()))); }
@Override protected LinkedList<QRespItem> load() { return new LinkedList<>( Spring.getInstance().getHt().findByCriteria(DetachedCriteria.forClass(QRespItem.class). setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY). add(Property.forName("deleted").isNull()). addOrder(Property.forName("id").asc()))); }
@SuppressWarnings("unchecked") public Collection<ComponentConfig> loadComponentConfigsByName(String profileKey) { DetachedCriteria dc = DetachedCriteria.forClass(ComponentConfig.class); dc.add(Restrictions.eq("name", profileKey)); dc.createAlias("componentConfigMembers", "m", CriteriaSpecification.LEFT_JOIN); dc.addOrder(Order.asc("m.order")); return (List<ComponentConfig>) this.query(dc); }
@SuppressWarnings("unchecked") public ComponentConfig loadComponentConfig(String controlId, String name) { DetachedCriteria dc = DetachedCriteria.forClass(ComponentConfig.class); dc.add(Restrictions.eq("name", name)); dc.add(Restrictions.eq("controlId", controlId)); dc.createAlias("componentConfigMembers", "m", CriteriaSpecification.LEFT_JOIN); dc.addOrder(Order.asc("m.order")); List<ComponentConfig> componentConfigs = (List<ComponentConfig>) this.query(dc); return componentConfigs.isEmpty() ? null : componentConfigs.get(0); }
@SuppressWarnings("unchecked") public Collection<ComponentConfig> loadComponentConfigsByViewName(String viewName) { DetachedCriteria dc = DetachedCriteria.forClass(ComponentConfig.class); dc.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); dc.add(Restrictions.like("controlId", viewName + ".%")); dc.createAlias("componentConfigMembers", "m", CriteriaSpecification.LEFT_JOIN); dc.addOrder(Order.asc("m.order")); return (List<ComponentConfig>) this.query(dc); }
@SuppressWarnings("unchecked") public Collection<ComponentConfig> loadComponentConfigs() { DetachedCriteria dc = DetachedCriteria.forClass(ComponentConfig.class); dc.createAlias("componentConfigMembers", "m", CriteriaSpecification.LEFT_JOIN); dc.addOrder(Order.asc("m.order")); return (List<ComponentConfig>) this.query(dc); }
@Override protected Collection<Staff> handleFindByDepartmentNotificationType( Long departmentId, NotificationType notificationType) throws Exception { org.hibernate.Criteria staffCriteria = createStaffCriteria(); if (departmentId != null) { staffCriteria.add(Restrictions.eq("department.id", departmentId.longValue())); } if (notificationType != null) { staffCriteria.createCriteria("category", CriteriaSpecification.INNER_JOIN).createCriteria("sendDepartmentNotificationTypes", CriteriaSpecification.INNER_JOIN) .add(Restrictions.eq("type", notificationType)); } return staffCriteria.list(); }
@Override protected long handleGetCount(Long selectionSetValueId) { org.hibernate.Criteria inputFieldValueCriteria = createInputFieldValueCriteria(); if (selectionSetValueId != null) { org.hibernate.Criteria selectionSetValueCriteria = inputFieldValueCriteria.createCriteria("selectionValues", CriteriaSpecification.INNER_JOIN); selectionSetValueCriteria.add(Restrictions.idEq(selectionSetValueId)); } else { inputFieldValueCriteria.add(Restrictions.not(Restrictions.isEmpty("selectionValues"))); } return (Long) inputFieldValueCriteria.setProjection(Projections.rowCount()).uniqueResult(); }
@Override protected Collection<ProbandListEntry> handleFindByTrialGroupProbandCountPerson( Long trialId, Long probandGroupId, Long probandId, boolean total, Boolean person, PSFVO psf) throws Exception { org.hibernate.Criteria listEntryCriteria = createListEntryCriteria(); SubCriteriaMap criteriaMap = new SubCriteriaMap(ProbandListEntry.class, listEntryCriteria); if (trialId != null) { listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (probandGroupId != null) { listEntryCriteria.add(Restrictions.eq("group.id", probandGroupId.longValue())); } if (probandId != null || person != null) { Criteria probandCriteria = criteriaMap.createCriteria("proband", CriteriaSpecification.INNER_JOIN); // Criteria probandCriteria = listEntryCriteria.createCriteria("proband", CriteriaSpecification.INNER_JOIN); //org.hibernate.QueryException: duplicate association path: // proband if (probandId != null) { probandCriteria.add(Restrictions.idEq(probandId.longValue())); } if (person != null) { probandCriteria.add(Restrictions.eq("person", person.booleanValue())); } // listEntryCriteria.add(Restrictions.eq("proband.id", probandId.longValue())); } if (!total) { criteriaMap.createCriteria("lastStatus.status", CriteriaSpecification.INNER_JOIN).add(Restrictions.eq("count", true)); // listEntryCriteria.createCriteria("lastStatus", CriteriaSpecification.INNER_JOIN).createCriteria("status", CriteriaSpecification.INNER_JOIN) // .add(Restrictions.eq("count", true)); // istEntryCriteria.add(Restrictions.eq("proband.id", probandId.longValue())); } CriteriaUtil.applyPSFVO(criteriaMap, psf); return listEntryCriteria.list(); }
@Override protected Collection<ProbandListEntry> handleGetProbandList( Long trialId, org.phoenixctms.ctsms.enumeration.ProbandListStatusLogLevel logLevel, boolean last) throws Exception { // http://stackoverflow.com/questions/1648426/hibernate-detached-queries-as-a-part-of-the-criteria-query // https://forum.hibernate.org/viewtopic.php?p=2317841#2317841 org.hibernate.Criteria listEntryCriteria = createListEntryCriteria(); boolean distinctRoot = false; if (trialId != null) { listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); } if (logLevel != null) { org.hibernate.Criteria statusEntryCriteria; if (last) { statusEntryCriteria = listEntryCriteria.createCriteria("statusEntries", "probandListStatusEntry0", CriteriaSpecification.INNER_JOIN); } else { statusEntryCriteria = listEntryCriteria.createCriteria("statusEntries", CriteriaSpecification.INNER_JOIN); } org.hibernate.Criteria statusTypeCriteria = statusEntryCriteria.createCriteria("status", CriteriaSpecification.INNER_JOIN); org.hibernate.Criteria logLevelCriteria = statusTypeCriteria.createCriteria("logLevels", CriteriaSpecification.INNER_JOIN); logLevelCriteria.add(Restrictions.eq("logLevel", logLevel)); if (last) { DetachedCriteria subQuery = DetachedCriteria.forClass(ProbandListStatusEntryImpl.class, "probandListStatusEntry1"); // IMPL!!!! subQuery.add(Restrictions.eqProperty("probandListStatusEntry1.listEntry", "probandListStatusEntry0.listEntry")); subQuery.setProjection(Projections.max("id")); statusEntryCriteria.add(Subqueries.propertyEq("id", subQuery)); } else { // listEntryCriteria.setResultTransformer(org.hibernate.Criteria.DISTINCT_ROOT_ENTITY); distinctRoot = true; } } listEntryCriteria.addOrder(Order.asc("trial")); listEntryCriteria.addOrder(Order.asc("position")); if (distinctRoot) { return CriteriaUtil.listDistinctRoot(listEntryCriteria, this, "trial.id", "position"); } else { return listEntryCriteria.list(); } }
private org.hibernate.Criteria createProbandListEntryTagCriteria(Long probandListEntryId) { ProbandListEntry listEntry = this.getProbandListEntryDao().load(probandListEntryId); org.hibernate.Criteria listEntryTagCriteria = this.getSession().createCriteria(ProbandListEntryTag.class, ServiceUtil.PROBAND_LIST_ENTRY_TAG_VALUE_DAO_PROBAND_LIST_ENTRY_TAG_ALIAS); listEntryTagCriteria.add(Restrictions.eq("trial.id", listEntry.getTrial().getId().longValue())); org.hibernate.Criteria listEntryTagValueCriteria = listEntryTagCriteria.createCriteria("tagValues", ServiceUtil.PROBAND_LIST_ENTRY_TAG_VALUE_DAO_PROBAND_LIST_ENTRY_TAG_VALUE_ALIAS, CriteriaSpecification.LEFT_JOIN, Restrictions.eq(ServiceUtil.PROBAND_LIST_ENTRY_TAG_VALUE_DAO_PROBAND_LIST_ENTRY_TAG_VALUE_ALIAS + ".listEntry.id", probandListEntryId.longValue())); // criteriaMap.createCriteria("ecrfField", CriteriaSpecification.LEFT_JOIN); // listEntryTagValueCriteria.add(Restrictions.or(Restrictions.eq("listEntry.id", probandListEntryId.longValue()), // Restrictions.isNull("listEntry"))); // correlated - slow: // DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteria(ecrfFieldValueCriteria, ecrfFieldCriteria, null, probandListEntryId, null); // // DetachedCriteria subQuery = DetachedCriteria.forClass(ECRFFieldValueImpl.class, "ecrfFieldValue1"); // IMPL!!!! // // subQuery.setProjection(Projections.max("id")); // // subQuery.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue())); // // subQuery.add(Restrictions.eqProperty("ecrfField.id", "ecrfField0.id")); // subQuery.add(Restrictions.or(Restrictions.isNull("index"), // Restrictions.eqProperty("index", ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS + ".index"))); // ecrfFieldValueCriteria.add(Restrictions.or( // Restrictions.isNull("listEntry"), // Restrictions.and( // Restrictions.eq("listEntry.id", probandListEntryId.longValue()), // Subqueries.propertyIn("id", subQuery) // ) // )); // System.out.println(CriteriaUtil.criteriaToSql(listEntryTagCriteria)); return listEntryTagCriteria; }
@Override protected Collection<ProbandListEntryTagValue> handleFindByListEntryField( Long probandListEntryId, Long inputFieldId) throws Exception { org.hibernate.Criteria listEntryTagValueCriteria = createListEntryTagValueCriteria(); if (probandListEntryId != null) { listEntryTagValueCriteria.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue())); } if (inputFieldId != null) { listEntryTagValueCriteria.createCriteria("tag", CriteriaSpecification.INNER_JOIN).add(Restrictions.eq("field.id", inputFieldId.longValue())); } return listEntryTagValueCriteria.list(); }
@Override protected long handleGetCountByField(Long inputFieldId) throws Exception { org.hibernate.Criteria listEntryTagValueCriteria = createListEntryTagValueCriteria(); if (inputFieldId != null) { org.hibernate.Criteria tagCriteria = listEntryTagValueCriteria.createCriteria("tag", CriteriaSpecification.INNER_JOIN); tagCriteria.add(Restrictions.eq("field.id", inputFieldId.longValue())); } return (Long) listEntryTagValueCriteria.setProjection(Projections.rowCount()).uniqueResult(); }