下面列出了怎么用org.hibernate.criterion.MatchMode的API类实例代码及写法,或者点击链接到github查看源代码。
@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;
}
/**
* 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();
}
/**
* @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();
}
@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);
}
@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;
}
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;
}
@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;
}
@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
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;
}
@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;
}
/**
* 模糊匹配
*
* @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;
}
/**
* 模糊匹配
*
* @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;
}
/**
* @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();
}
@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();
}
@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();
}
@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();
}
@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();
}
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));
}
/**
* @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();
}
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 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");
}
@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();
}
@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();
}
@SuppressWarnings("unchecked")
public List<Mpp> getMedecinePackages(String searchString, String lang, List<String> types, int first, int count) {
log.debug("Getting medecine packages for " + searchString + " from " + first + ", count=" + count);
Session sess = this.getSessionFactory().getCurrentSession();
Criteria c = sess.createCriteria(Mpp.class);
addLangRestriction(c, lang);
addTypesRestriction(c, types);
c.add(Restrictions.ilike("name", searchString, MatchMode.START));
c.setFirstResult(first);
c.setMaxResults(count);
c.addOrder(Order.asc("name"));
List<Mpp> result = c.list();
return result;
}
@After
public void tearDown() throws Exception {
for (Article art : this.articleService
.find(Restrictions.like("title", "测试缓存", MatchMode.START))) {
this.articleService.delete(art.getId());
}
}
private EntityCriteria<Role> getCriteria() {
EntityCriteria<Role> criteria = EntityCriteria.of(Role.class);
if (query != null)
criteria.add(Restrictions.ilike("name", query, MatchMode.ANYWHERE));
else
criteria.setCacheable(true);
return criteria;
}
private EntityCriteria<Group> getCriteria() {
EntityCriteria<Group> criteria = EntityCriteria.of(Group.class);
if (query != null)
criteria.add(Restrictions.ilike("name", query, MatchMode.ANYWHERE));
else
criteria.setCacheable(true);
return criteria;
}
private EntityCriteria<Membership> getCriteria() {
EntityCriteria<Membership> criteria = EntityCriteria.of(Membership.class);
if (query != null)
criteria.createCriteria("user").add(Restrictions.ilike("name", query, MatchMode.ANYWHERE));
else
criteria.setCacheable(true);
criteria.add(Restrictions.eq("group", getGroup()));
return criteria;
}
private EntityCriteria<User> getCriteria() {
EntityCriteria<User> criteria = EntityCriteria.of(User.class);
criteria.add(Restrictions.not(Restrictions.eq("id", User.SYSTEM_ID)));
if (query != null) {
criteria.add(Restrictions.or(
Restrictions.ilike("name", query, MatchMode.ANYWHERE),
Restrictions.ilike("fullName", query, MatchMode.ANYWHERE)));
} else {
criteria.setCacheable(true);
}
return criteria;
}
private EntityCriteria<Membership> getCriteria() {
EntityCriteria<Membership> criteria = EntityCriteria.of(Membership.class);
if (query != null)
criteria.createCriteria("group").add(Restrictions.ilike("name", query, MatchMode.ANYWHERE));
else
criteria.setCacheable(true);
criteria.add(Restrictions.eq("user", getUser()));
return criteria;
}