org.hibernate.criterion.MatchMode Java Examples

The following examples show how to use org.hibernate.criterion.MatchMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchGlossaryStructureWithWordLike.java    From Knowage-Server with GNU Affero General Public License v3.0 7 votes vote down vote up
@Override
public Criteria evaluate(Session session) {

	if (glossaryId == null) {
		logger.debug("SearchGlossaryStructureWithWordLike, glossaryId =null");
		return null;
	}

	Criteria c = session.createCriteria(SbiGlWlist.class, "wlist");
	c.createAlias("wlist.content", "contentWl");
	c.createAlias("contentWl.glossary", "glossaryWl");
	c.createAlias("word", "wordWl");
	// c.createAlias("contentWl.parent", "parent"); // get parent info
	c.add(Restrictions.eq("glossaryWl.glossaryId", Integer.parseInt(glossaryId)));
	if (word != null) {
		c.add(Restrictions.like("wordWl.word", word, MatchMode.ANYWHERE).ignoreCase());
	}

	return c;
}
 
Example #2
Source File: JpaRestrictions.java    From sctalk with Apache License 2.0 6 votes vote down vote up
/**
 * 模糊匹配
 * 
 * @param fieldName 字段名
 * @param value 字段值
 * @param matchMode 匹配类型
 * @param ignoreNull 是否忽然空值
 * @return 条件表达式
 * @return
 */
public static SimpleExpression like(String fieldName, String value, MatchMode matchMode, boolean ignoreNull) {
    if (StringUtils.isEmpty(value))
        return null;
    SimpleExpression expression;
    switch (matchMode) {
        case START:
            expression = new SimpleExpression(fieldName, value, Operator.LLIKE);
            break;
        case END:
            expression = new SimpleExpression(fieldName, value, Operator.RLIKE);
            break;
        case ANYWHERE:
            expression = new SimpleExpression(fieldName, value, Operator.LIKE);
            break;
        default:
            expression = new SimpleExpression(fieldName, value, Operator.LIKE);
            break;
    }
    
    return expression;
}
 
Example #3
Source File: InventoryBookingDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @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();
}
 
Example #4
Source File: AspSubstanceDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
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));
}
 
Example #5
Source File: ChannelFactory.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find a vendor content source (org is null) for a given repo URL.
 * @param repoUrl url to match against
 * @return vendor content source if it exists
 */
public static ContentSource findVendorContentSourceByRepo(String repoUrl) {
    Criteria criteria = getSession().createCriteria(ContentSource.class);
    criteria.add(Restrictions.isNull("org"));
    if (repoUrl.contains("mirrorlist.centos.org")) {
        criteria.add(Restrictions.eq("sourceUrl", repoUrl));
    }
    else {
        String [] parts = repoUrl.split("\\?");
        String repoUrlPrefix = parts[0];
        if (parts.length > 1) {
            criteria.add(Restrictions.like("sourceUrl", repoUrlPrefix + '?',
                    MatchMode.START));
        }
        else {
            criteria.add(Restrictions.eq("sourceUrl", repoUrlPrefix));
        }
    }
    return (ContentSource) criteria.uniqueResult();
}
 
Example #6
Source File: DrugsDAOImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Mpp> getMedecinePackagesFromIngredients(String searchString, String lang, List<String> types, int first, int count) {
    log.debug("Getting medecine packages from ingredients for " + searchString + " from " + first + ", count=" + count);
    Session sess = this.getSessionFactory().getCurrentSession();
    Criteria c = sess.createCriteria(Mpp.class);
    addLangRestriction(c, lang);
    addTypesRestriction(c, types);

    c.createAlias("compositions", "comp").createAlias("comp.ingredient", "ingrd");
    c.add(Restrictions.or(Restrictions.ilike("name", searchString, MatchMode.START),
            Restrictions.ilike("ingrd.name", searchString, MatchMode.START)));

    c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    c.setFirstResult(first);
    c.setMaxResults(count);
    c.addOrder(Order.asc("name"));
    List<Mpp> result = c.list();
    return result;
}
 
Example #7
Source File: MoneyTransferDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected long handleGetCount(Long trialId, Long probandId, Long bankAccountId, PaymentMethod method, String costType, Boolean paid) throws Exception {
	org.hibernate.Criteria moneyTransferCriteria = createMoneyTransferCriteria("moneyTransfer");
	if (trialId != null) {
		moneyTransferCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	}
	if (probandId != null) {
		moneyTransferCriteria.add(Restrictions.eq("proband.id", probandId.longValue()));
	}
	if (bankAccountId != null) {
		moneyTransferCriteria.add(Restrictions.eq("bankAccount.id", bankAccountId.longValue()));
	}
	if (method != null) {
		moneyTransferCriteria.add(Restrictions.eq("method", method));
	}
	if (paid != null) {
		moneyTransferCriteria.add(Restrictions.eq("paid", paid.booleanValue()));
	}
	CategoryCriterion.apply(moneyTransferCriteria, new CategoryCriterion(costType, "costType", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS));
	return (Long) moneyTransferCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
 
Example #8
Source File: InquiryDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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);
		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();
}
 
Example #9
Source File: ECRFFieldDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected Collection<String> handleFindSections(Long trialId, Long ecrfId, String sectionPrefix, Integer limit) throws Exception {
	org.hibernate.Criteria ecrfFieldCriteria = createEcrfFieldCriteria();
	if (trialId != null) {
		ecrfFieldCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	}
	if (ecrfId != null) {
		ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
	}
	CategoryCriterion.apply(ecrfFieldCriteria, new CategoryCriterion(sectionPrefix, "section", MatchMode.START));
	ecrfFieldCriteria.addOrder(Order.asc("section"));
	ecrfFieldCriteria.setProjection(Projections.distinct(Projections.property("section")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.ECRF_FIELD_SECTION_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.ECRF_FIELD_SECTION_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), ecrfFieldCriteria);
	return ecrfFieldCriteria.list();
}
 
Example #10
Source File: ECRFFieldDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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);
		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();
}
 
Example #11
Source File: DefaultIssueManager.java    From onedev with MIT License 6 votes vote down vote up
@Sessional
@Override
public List<Issue> query(Project project, String term, int count) {
	EntityCriteria<Issue> criteria = newCriteria();
	
	Set<Project> projects = Sets.newHashSet(project);
	projects.addAll(project.getForkParents().stream().filter(it->SecurityUtils.canAccess(it)).collect(Collectors.toSet()));
	criteria.add(Restrictions.in(Issue.PROP_PROJECT, projects));
	
	if (term.startsWith("#"))
		term = term.substring(1);
	if (term.length() != 0) {
		try {
			long buildNumber = Long.parseLong(term);
			criteria.add(Restrictions.eq(Issue.PROP_NUMBER, buildNumber));
		} catch (NumberFormatException e) {
			criteria.add(Restrictions.or(
					Restrictions.ilike(Issue.PROP_TITLE, term, MatchMode.ANYWHERE),
					Restrictions.ilike(Issue.PROP_NO_SPACE_TITLE, term, MatchMode.ANYWHERE)));
		}
	}

	criteria.addOrder(Order.desc(Issue.PROP_PROJECT));
	criteria.addOrder(Order.desc(Issue.PROP_NUMBER));
	return query(criteria, 0, count);
}
 
Example #12
Source File: ProbandListEntryTagDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected Collection<ProbandListEntryTag> handleFindListEntryTags(Long trialId, String nameInfix, Integer limit) throws Exception {
	org.hibernate.Criteria listEntryTagCriteria = createListEntryTagCriteria();
	if (trialId != null) {
		listEntryTagCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	}
	if (!CommonUtil.isEmptyString(nameInfix)) {
		org.hibernate.Criteria trialCriteria = listEntryTagCriteria.createCriteria("trial", "trial0", CriteriaSpecification.INNER_JOIN);
		org.hibernate.Criteria fieldCriteria = listEntryTagCriteria.createCriteria("field", "inputField", CriteriaSpecification.INNER_JOIN);
		listEntryTagCriteria.add(Restrictions.or(
				(new CategoryCriterion(nameInfix, "inputField.nameL10nKey", MatchMode.ANYWHERE)).getRestriction(),
				(new CategoryCriterion(nameInfix, "trial0.name", MatchMode.ANYWHERE)).getRestriction()));
	}
	applySortOrders(listEntryTagCriteria);
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.PROBAND_LIST_ENTRY_TAG_FIELD_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.PROBAND_LIST_ENTRY_TAG_FIELD_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), listEntryTagCriteria);
	return listEntryTagCriteria.list();
}
 
Example #13
Source File: CriteriaParameter.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public Criterion toHibernateCriterion() {
	Criterion restriction = null;
	switch (getMatch()) {
	case LIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE);
		break;
	case ILIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE).ignoreCase();
		break;
	case NOT_EQ:
		restriction = Restrictions.ne(getName(), getValue());
		break;
	case IN:
		restriction = Restrictions.in(getName(), (Object[]) getValue());
		break;
	case NOT_IN:
		restriction = Restrictions.not(Restrictions.in(getName(), (Object[]) getValue()));
		break;
	default:
		restriction = Restrictions.eq(getName(), getValue());
		break;
	}
	return restriction;
}
 
Example #14
Source File: InquiryDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected Collection<String> handleFindCategories(Long trialId,
		String categoryPrefix, Boolean active, Boolean activeSignup, Integer limit) 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()));
	}
	CategoryCriterion.apply(inquiryCriteria, new CategoryCriterion(categoryPrefix, "category", MatchMode.START));
	inquiryCriteria.addOrder(Order.asc("category"));
	inquiryCriteria.setProjection(Projections.distinct(Projections.property("category")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.INQUIRY_CATEGORY_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.INQUIRY_CATEGORY_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), inquiryCriteria);
	return inquiryCriteria.list();
}
 
Example #15
Source File: JpaRestrictions.java    From sctalk with Apache License 2.0 6 votes vote down vote up
/**
 * 模糊匹配
 * 
 * @param fieldName 字段名
 * @param value 字段值
 * @param matchMode 匹配类型
 * @param ignoreNull 是否忽然空值
 * @return 条件表达式
 * @return
 */
public static SimpleExpression like(String fieldName, String value, MatchMode matchMode, boolean ignoreNull) {
    if (StringUtils.isEmpty(value))
        return null;
    SimpleExpression expression;
    switch (matchMode) {
        case START:
            expression = new SimpleExpression(fieldName, value, Operator.LLIKE);
            break;
        case END:
            expression = new SimpleExpression(fieldName, value, Operator.RLIKE);
            break;
        case ANYWHERE:
            expression = new SimpleExpression(fieldName, value, Operator.LIKE);
            break;
        default:
            expression = new SimpleExpression(fieldName, value, Operator.LIKE);
            break;
    }
    
    return expression;
}
 
Example #16
Source File: SearchGlossaryByName.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Criteria evaluate(Session session) {
	Criteria criteria = session.createCriteria(SbiGlGlossary.class);
	criteria.setProjection(
			Projections.projectionList().add(Projections.property("glossaryId"), "glossaryId").add(Projections.property("glossaryNm"), "glossaryNm"))
			.setResultTransformer(Transformers.aliasToBean(SbiGlGlossary.class));
	if (glossary != null && !glossary.isEmpty()) {
		criteria.add(Restrictions.like("glossaryNm", glossary, MatchMode.ANYWHERE).ignoreCase());
	}

	if (page != null && itemsPerPage != null) {
		criteria.setFirstResult((page - 1) * itemsPerPage);
		criteria.setMaxResults(itemsPerPage);
	}

	return criteria;
}
 
Example #17
Source File: StreetDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
protected Collection<String> handleFindZipCodes(String countryName, String zipCodePrefix, String cityName, String streetName, Integer limit) {
	org.hibernate.Criteria streetCriteria = createStreetCriteria();
	if (!CommonUtil.isEmptyString(countryName)) {
		streetCriteria.add(Restrictions.eq("countryName", countryName));
	}
	CategoryCriterion.apply(streetCriteria, new CategoryCriterion(zipCodePrefix, "zipCode", MatchMode.START));
	if (!CommonUtil.isEmptyString(cityName)) {
		streetCriteria.add(Restrictions.eq("cityName", cityName));
	}
	if (!CommonUtil.isEmptyString(streetName)) {
		streetCriteria.add(Restrictions.eq("streetName", streetName));
	}
	streetCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("zipCode", ""), Restrictions.isNull("zipCode"))));
	streetCriteria.addOrder(Order.asc("zipCode"));
	streetCriteria.setProjection(Projections.distinct(Projections.property("zipCode")));
	CriteriaUtil.applyLimit(limit,
			Settings.getIntNullable(SettingCodes.ZIP_CODE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.ZIP_CODE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT),
			streetCriteria);
	return streetCriteria.list();
}
 
Example #18
Source File: AspDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
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));
}
 
Example #19
Source File: InventoryBookingDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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();
}
 
Example #20
Source File: TrialDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected Collection<Trial> handleFindByReimbursementProbandSorted(
		Long probandId, PaymentMethod method, String costType, Boolean paid) throws Exception {
	org.hibernate.Criteria trialCriteria = createTrialCriteria(null);
	Criteria payoffCriteria = trialCriteria.createCriteria("payoffs", CriteriaSpecification.INNER_JOIN);
	payoffCriteria.add(Restrictions.eq("proband.id", probandId.longValue()));
	if (method != null) {
		payoffCriteria.add(Restrictions.eq("method", method));
	}
	if (paid != null) {
		payoffCriteria.add(Restrictions.eq("paid", paid.booleanValue()));
	}
	CategoryCriterion.apply(payoffCriteria, new CategoryCriterion(costType, "costType", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS));
	trialCriteria.addOrder(Order.asc("name"));
	return CriteriaUtil.listDistinctRoot(trialCriteria, this, "name");
}
 
Example #21
Source File: DutyRosterTurnDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
protected Collection<DutyRosterTurn> handleFindByDepartmentCategoryCalendarInterval(Long staffDepartmentId, Long staffCategoryId, Boolean allocatable, String calendar,
		Timestamp from, Timestamp to) {
	Criteria dutyRosterCriteria = createDutyRosterTurnCriteria("dutyRosterTurn");
	CriteriaUtil.applyClosedIntervalCriterion(dutyRosterCriteria, from, to, null);
	Criteria staffCriteria = null;
	if (staffDepartmentId != null) {
		staffCriteria = dutyRosterCriteria.createCriteria("staff", CriteriaSpecification.LEFT_JOIN);
	} else if (staffCategoryId != null || allocatable != null) {
		staffCriteria = dutyRosterCriteria.createCriteria("staff", CriteriaSpecification.INNER_JOIN);
	}
	if (staffDepartmentId != null || staffCategoryId != null || allocatable != null) {
		if (staffDepartmentId != null) {
			staffCriteria.add(Restrictions.or(Restrictions.isNull("dutyRosterTurn.staff"), Restrictions.eq("department.id", staffDepartmentId.longValue())));
		}
		if (staffCategoryId != null) {
			staffCriteria.add(Restrictions.eq("category.id", staffCategoryId.longValue()));
		}
		if (allocatable != null) {
			staffCriteria.add(Restrictions.eq("allocatable", allocatable.booleanValue()));
		}
	}
	CategoryCriterion.apply(dutyRosterCriteria, new CategoryCriterion(calendar, "calendar", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS));
	return dutyRosterCriteria.list();
}
 
Example #22
Source File: SearchImages.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Criteria evaluate(Session session) {
	Criteria c = session.createCriteria(SbiImages.class);
	if (name != null && !name.isEmpty()) {
		c.add(Restrictions.like("name", name, MatchMode.ANYWHERE).ignoreCase());
	}
	if (description != null && !description.isEmpty()) {
		c.add(Restrictions.like("description", description, MatchMode.ANYWHERE).ignoreCase());
	}
	if (sort != null) {
		for (Entry<OrderBy, Direction> entry : sort.entrySet()) {
			String orderField = "";
			switch (entry.getKey()) {
			case name:
				orderField = "name";
				break;
			case timeIn:
				orderField = "commonInfo.timeIn";
				break;
			}
			c.addOrder(Direction.asc.equals(entry.getValue()) ? Order.asc(orderField) : Order.desc(orderField));
		}
	}
	return c;
}
 
Example #23
Source File: DrugsDAOImpl.java    From icure-backend with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Mpp> getMedecinePackagesFromIngredients(String searchString, String lang, List<String> types, int first, int count) {
	log.debug("Getting medecine packages from ingredients for " + searchString + " from " + first + ", count=" + count);
	Session sess = getSessionFactory().getCurrentSession();
	Criteria c = sess.createCriteria(Mpp.class);
	addLangRestriction(c, lang);
	addTypesRestriction(c, types);

	c.createAlias("compositions", "comp").createAlias("comp.ingredient", "ingrd");
	c.add(Restrictions.or(Restrictions.ilike("name", searchString, MatchMode.START),
			Restrictions.ilike("ingrd.name", searchString, MatchMode.START)));

	c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
	c.setFirstResult(first);
	c.setMaxResults(count);
	c.addOrder(Order.asc("name"));
	List<Mpp> result = c.list();
	return result;
}
 
Example #24
Source File: CriteriaDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<String> handleFindCategories(DBModule module, String categoryPrefix, Integer limit)
		throws Exception {
	org.hibernate.Criteria criteriaCriteria = createCriteriaCriteria();
	if (module != null) {
		criteriaCriteria.add(Restrictions.eq("module", module));
	}
	CategoryCriterion.apply(criteriaCriteria, new CategoryCriterion(categoryPrefix, "category", MatchMode.START));
	criteriaCriteria.addOrder(Order.asc("category"));
	criteriaCriteria.setProjection(Projections.distinct(Projections.property("category")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.CRITERIA_CATEGORY_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.CRITERIA_CATEGORY_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), criteriaCriteria);
	return criteriaCriteria.list();
}
 
Example #25
Source File: InventoryBookingDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<String> handleFindCalendars(
		Long inventoryDepartmentId, Long inventoryId, Long probandId, Long courseId,
		Long trialId, String calendarPrefix, Integer limit)
		throws Exception {
	Criteria bookingCriteria = createBookingCriteria();
	if (inventoryId != null) {
		bookingCriteria.add(Restrictions.eq("inventory.id", inventoryId.longValue()));
	}
	if (inventoryDepartmentId != null) {
		Criteria inventoryCriteria = bookingCriteria.createCriteria("inventory", CriteriaSpecification.INNER_JOIN);
		inventoryCriteria.add(Restrictions.eq("department.id", inventoryDepartmentId.longValue()));
	}
	if (probandId != null) {
		bookingCriteria.add(Restrictions.eq("proband.id", probandId.longValue()));
	}
	if (courseId != null) {
		bookingCriteria.add(Restrictions.eq("course.id", courseId.longValue()));
	}
	if (trialId != null) {
		bookingCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	}
	CategoryCriterion.apply(bookingCriteria, new CategoryCriterion(calendarPrefix, "calendar", MatchMode.START));
	bookingCriteria.addOrder(Order.asc("calendar"));
	bookingCriteria.setProjection(Projections.distinct(Projections.property("calendar")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.INVENTORY_BOOKING_CALENDAR_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.INVENTORY_BOOKING_CALENDAR_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), bookingCriteria);
	return bookingCriteria.list();
}
 
Example #26
Source File: AspAtcCodeDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<String> handleFindAspAtcCodeCodes(String codePrefix, Integer limit) throws Exception {
	org.hibernate.Criteria aspAtcCodeCriteria = this.getSession().createCriteria(AspAtcCode.class);
	aspAtcCodeCriteria.setCacheable(true);
	CategoryCriterion.apply(aspAtcCodeCriteria, new CategoryCriterion(codePrefix, "code", MatchMode.START));
	aspAtcCodeCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("code", ""), Restrictions.isNull("code"))));
	aspAtcCodeCriteria.add(Restrictions.eq("revision",
			Settings.getString(SettingCodes.ASP_REVISION, Bundle.SETTINGS, DefaultSettings.ASP_REVISION)));
	aspAtcCodeCriteria.addOrder(Order.asc("code"));
	aspAtcCodeCriteria.setProjection(Projections.distinct(Projections.property("code")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.ASP_ATC_CODE_CODE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.ASP_ATC_CODE_CODE_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), aspAtcCodeCriteria);
	return aspAtcCodeCriteria.list();
}
 
Example #27
Source File: CountryDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<String> handleFindCountryNames(String countryNameInfix, Integer limit)
		throws Exception {
	org.hibernate.Criteria countryCriteria = createCountryCriteria();
	CategoryCriterion.apply(countryCriteria, new CategoryCriterion(countryNameInfix, "countryName", MatchMode.ANYWHERE));
	countryCriteria.add(Restrictions.not(Restrictions.or(Restrictions.eq("countryName", ""), Restrictions.isNull("countryName"))));
	countryCriteria.addOrder(Order.asc("countryName"));
	countryCriteria.setProjection(Projections.distinct(Projections.property("countryName")));
	CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.COUNTRY_NAME_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
			DefaultSettings.COUNTRY_NAME_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), countryCriteria);
	return countryCriteria.list();
}
 
Example #28
Source File: CountryDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<CountryVO> handleFindCountries(String countryNameInfix,
		String countryCodeInfix, Integer limit) throws Exception {
	org.hibernate.Criteria countryCriteria = createCountryCriteria();
	CategoryCriterion.applyAnd(countryCriteria,
			new CategoryCriterion(countryNameInfix, "countryName", MatchMode.ANYWHERE),
			new CategoryCriterion(countryCodeInfix, "countryCode", MatchMode.ANYWHERE));
	countryCriteria.addOrder(Order.asc("countryName"));
	CriteriaUtil.applyLimit(limit,
			Settings.getIntNullable(SettingCodes.COUNTRY_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.COUNTRY_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT),
			countryCriteria);
	return countryCriteria.list();
}
 
Example #29
Source File: AlphaIdDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void applyAlphaIdTextCriterions(org.hibernate.Criteria alphaIdCriteria, String textInfix) {
	ArrayList<CategoryCriterion> criterions = new ArrayList<CategoryCriterion>();
	criterions.add(new CategoryCriterion(textInfix, "text", MatchMode.ANYWHERE));
	if (MATCH_PRIMARY_CODE) {
		criterions.add(new CategoryCriterion(textInfix, "primaryCode", MatchMode.EXACT));
	}
	CategoryCriterion.applyOr(alphaIdCriteria, criterions);
	applyAlphaIdCriterions(alphaIdCriteria);
}
 
Example #30
Source File: DutyRosterTurnDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<DutyRosterTurn> handleFindByDepartmentStatusStaffTrialCalendarInterval(
		Long trialDepartmentId, Long statusId, Long staffId, boolean unassigned, Long trialId, String calendar, Timestamp from, Timestamp to)
		throws Exception {
	Criteria dutyRosterCriteria = createDutyRosterTurnCriteria("dutyRosterTurn");
	CriteriaUtil.applyClosedIntervalCriterion(dutyRosterCriteria, from, to, null);
	Criteria trialCriteria = null;
	if (trialDepartmentId != null) {
		trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.LEFT_JOIN);
	} else if (statusId != null || trialId != null) {
		trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.INNER_JOIN);
	}
	if (trialDepartmentId != null || statusId != null || trialId != null) {
		if (trialDepartmentId != null) {
			trialCriteria.add(Restrictions.or(Restrictions.isNull("dutyRosterTurn.trial"), Restrictions.eq("department.id", trialDepartmentId.longValue())));
		}
		if (statusId != null) {
			trialCriteria.add(Restrictions.eq("status.id", statusId.longValue()));
		}
		if (trialId != null) {
			trialCriteria.add(Restrictions.idEq(trialId.longValue()));
		}
	}
	if (staffId != null) {
		if (unassigned) {
			dutyRosterCriteria.add(Restrictions.or(Restrictions.eq("staff.id", staffId.longValue()), Restrictions.isNull("staff")));
		} else {
			dutyRosterCriteria.add(Restrictions.eq("staff.id", staffId.longValue()));
		}
	}
	CategoryCriterion.apply(dutyRosterCriteria, new CategoryCriterion(calendar, "calendar", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS));
	return dutyRosterCriteria.list();
}