List of usage examples for org.hibernate.criterion SimpleExpression ignoreCase
boolean ignoreCase
To view the source code for org.hibernate.criterion SimpleExpression ignoreCase.
Click Source Link
From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java
License:Open Source License
private void makeCaseInsensitive(Criterion criterion) { SimpleExpression simpleExpression; if (type == STRING && criterion instanceof SimpleExpression) { simpleExpression = (SimpleExpression) criterion; if (StringUtils.trimToNull((String) value) != null) { simpleExpression.ignoreCase(); }//from www . ja va 2s . c o m } }
From source file:grails.orm.HibernateCriteriaBuilder.java
License:Apache License
/** * Creates an "equals" Criterion based on the specified property name and value. * Supports case-insensitive search if the <code>params</code> map contains <code>true</code> * under the 'ignoreCase' key.// w ww . ja v a 2s .c om * @param propertyName The property name * @param propertyValue The property value * @param params optional map with customization parameters; currently only 'ignoreCase' is supported. * * @return A Criterion instance */ @SuppressWarnings("rawtypes") public org.grails.datastore.mapping.query.api.Criteria eq(String propertyName, Object propertyValue, Map params) { if (!validateSimpleExpression()) { throwRuntimeException(new IllegalArgumentException("Call to [eq] with propertyName [" + propertyName + "] and value [" + propertyValue + "] not allowed here.")); } propertyName = calculatePropertyName(propertyName); propertyValue = calculatePropertyValue(propertyValue); SimpleExpression eq = Restrictions.eq(propertyName, propertyValue); if (params != null) { Object ignoreCase = params.get("ignoreCase"); if (ignoreCase instanceof Boolean && (Boolean) ignoreCase) { eq = eq.ignoreCase(); } } addToCriteria(eq); return this; }
From source file:org.jtalks.jcommune.model.dao.hibernate.ValidatorHibernateDao.java
License:Open Source License
private List<?> getResultSet(Class<? extends Entity> entity, String field, String param, boolean ignoreCase) { SimpleExpression fieldRestriction = Restrictions.eq(field, param); if (ignoreCase) { fieldRestriction = fieldRestriction.ignoreCase(); }/*from w w w . ja v a 2 s. c o m*/ return sessionFactory.getCurrentSession().createCriteria(entity).add(fieldRestriction).setCacheable(true) .list(); }
From source file:org.jtalks.poulpe.model.dao.hibernate.UserHibernateDao.java
License:Open Source License
/** * {@inheritDoc}// www.j a v a 2 s . c o m */ @Override public List<PoulpeUser> findPoulpeUsersBySearchRequest(UserSearchRequest searchRequest) { String searchString = SqlLikeEscaper.escapeControlCharacters(searchRequest.getSearchString()); SimpleExpression expression = Restrictions.like("username", MessageFormat.format(FORMAT, searchString)) .ignoreCase(); Criteria criteria = session().createCriteria(PoulpeUser.class) .add((searchRequest.isCaseSensitise()) ? expression : expression.ignoreCase()) .addOrder(getOrder(searchRequest)); searchRequest.getPagination().addPagination(criteria); return criteria.list(); }
From source file:org.openmrs.api.db.hibernate.HibernateConceptDAO.java
License:Mozilla Public License
/** * @see org.openmrs.api.db.ConceptDAO#getDrugs(java.lang.String, org.openmrs.Concept, boolean) *//* w w w.j a va 2 s . c om*/ @SuppressWarnings("unchecked") public List<Drug> getDrugs(String drugName, Concept concept, boolean includeRetired) throws DAOException { Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(Drug.class, "drug"); if (!includeRetired) { searchCriteria.add(Restrictions.eq("drug.retired", false)); } if (concept != null) { searchCriteria.add(Restrictions.eq("drug.concept", concept)); } if (drugName != null) { SimpleExpression eq = Restrictions.eq("drug.name", drugName); if (Context.getAdministrationService().isDatabaseStringComparisonCaseSensitive()) { eq = eq.ignoreCase(); } searchCriteria.add(eq); } return (List<Drug>) searchCriteria.list(); }
From source file:org.openmrs.api.db.hibernate.PatientSearchCriteria.java
License:Mozilla Public License
/** * Utility method to add identifier expression to an existing criteria * * @param identifier//from w w w .ja v a 2s. c o m * @param identifierTypes * @param matchIdentifierExactly * @param includeVoided true/false whether or not to included voided patients */ private Criterion prepareCriterionForIdentifier(String identifier, List<PatientIdentifierType> identifierTypes, boolean matchIdentifierExactly, boolean includeVoided) { identifier = HibernateUtil.escapeSqlWildcards(identifier, sessionFactory); Conjunction conjunction = Restrictions.conjunction(); if (!includeVoided) { conjunction.add(Restrictions.eq("ids.voided", false)); } // do the identifier restriction if (identifier != null) { // if the user wants an exact search, match on that. if (matchIdentifierExactly) { SimpleExpression matchIdentifier = Restrictions.eq("ids.identifier", identifier); if (Context.getAdministrationService().isDatabaseStringComparisonCaseSensitive()) { matchIdentifier.ignoreCase(); } conjunction.add(matchIdentifier); } else { AdministrationService adminService = Context.getAdministrationService(); String regex = adminService .getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_REGEX, ""); String patternSearch = adminService .getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_PATTERN, ""); // remove padding from identifier search string if (Pattern.matches("^\\^.{1}\\*.*$", regex)) { identifier = removePadding(identifier, regex); } if (org.springframework.util.StringUtils.hasLength(patternSearch)) { conjunction.add(splitAndGetSearchPattern(identifier, patternSearch)); } // if the regex is empty, default to a simple "like" search or if // we're in hsql world, also only do the simple like search (because // hsql doesn't know how to deal with 'regexp' else if ("".equals(regex) || HibernateUtil.isHSQLDialect(sessionFactory)) { conjunction.add(getCriterionForSimpleSearch(identifier, adminService)); } // if the regex is present, search on that else { regex = replaceSearchString(regex, identifier); conjunction.add(Restrictions.sqlRestriction("identifier regexp ?", regex, StringType.INSTANCE)); } } } // TODO add a junit test for patientIdentifierType restrictions // do the type restriction if (!CollectionUtils.isEmpty(identifierTypes)) { criteria.add(Restrictions.in("ids.identifierType", identifierTypes)); } return conjunction; }