@Test public void testIgnoreCaseCriteria() { User user1 = new User(1, "Chris"); User user2 = new User(2, "Steve"); doInHibernate( this::sessionFactory, session -> { session.save(user1); session.save(user2); } ); doInHibernate( this::sessionFactory, session -> { Criteria criteria = session.createCriteria(User.class); criteria.add(Restrictions.eq("name", user1.getName().toLowerCase()).ignoreCase()); assertEquals(1, criteria.list().size()); } ); }
/** * Apply an "equal" constraint to the named property * * @param propertyName The name of the property * @param value The value to use in comparison * * @return SimpleExpression * * @see SimpleExpression */ public static SimpleExpression eq(String propertyName, Object value) { return new SimpleExpression( propertyName, value, "=" ); }
/** * Get a map of set of the natural identifier values set on this criterion (for composite natural identifiers * this need not be the full set of properties). * * @return The value map. */ public Map<String, Object> getNaturalIdValues() { final Map<String, Object> naturalIdValueMap = new ConcurrentHashMap<String, Object>(); for ( Criterion condition : conjunction.conditions() ) { if ( !SimpleExpression.class.isInstance( condition ) ) { continue; } final SimpleExpression equalsCondition = SimpleExpression.class.cast( condition ); if ( !"=".equals( equalsCondition.getOp() ) ) { continue; } naturalIdValueMap.put( equalsCondition.getPropertyName(), equalsCondition.getValue() ); } return naturalIdValueMap; }
@Override public String toString() { return propertyName + getOp() + value; }
@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final String[] columns = criteriaQuery.findColumns( propertyName, criteria ); final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName ); final StringBuilder fragment = new StringBuilder(); if ( columns.length > 1 ) { fragment.append( '(' ); } final SessionFactoryImplementor factory = criteriaQuery.getFactory(); final int[] sqlTypes = type.sqlTypes( factory ); for ( int i = 0; i < columns.length; i++ ) { final boolean lower = ignoreCase && (sqlTypes[i] == Types.VARCHAR || sqlTypes[i] == Types.CHAR || sqlTypes[i] == Types.NVARCHAR || sqlTypes[i] == Types.NCHAR); if ( lower ) { fragment.append( factory.getDialect().getLowercaseFunction() ).append( '(' ); } fragment.append( columns[i] ); if ( lower ) { fragment.append( ')' ); } fragment.append( getOp() ).append( "?" ); if ( i < columns.length - 1 ) { fragment.append( " and " ); } } if ( columns.length > 1 ) { fragment.append( ')' ); } return fragment.toString(); }
Restrictions.like( "text", pattern ).ignoreCase() ).list();
/** * Apply a "not equal" constraint to the named property * * @param propertyName The name of the property * @param value The value to use in comparison * * @return The Criterion * @see SimpleExpression */ public static SimpleExpression ne(String propertyName, Object value) { return new SimpleExpression( propertyName, value, "<>" ); }
public Map<String, Object> getNaturalIdValues() { final Map<String, Object> naturalIdValueMap = new ConcurrentHashMap<String, Object>(); for ( Criterion condition : conjunction.conditions() ) { if ( !SimpleExpression.class.isInstance( condition ) ) { continue; } final SimpleExpression equalsCondition = SimpleExpression.class.cast( condition ); if ( !"=".equals( equalsCondition.getOp() ) ) { continue; } naturalIdValueMap.put( equalsCondition.getPropertyName(), equalsCondition.getValue() ); } return naturalIdValueMap; }
public String toString() { return propertyName + getOp() + value; }
.add( Restrictions.eq( "integer", f.getInteger() ) ) .add( Restrictions.eqProperty("integer", "integer") ) .add( Restrictions.like( "string", f.getString().toUpperCase(Locale.ROOT) ).ignoreCase() ) .add( Restrictions.in( "boolean", f.getBoolean(), f.getBoolean() ) ) .setFetchMode("foo", FetchMode.JOIN)
/** * Apply a "greater than or equal" constraint to the named property * * @param propertyName The name of the property * @param value The value to use in comparison * * @return The Criterion * * @see SimpleExpression */ public static SimpleExpression ge(String propertyName, Object value) { return new SimpleExpression( propertyName, value, ">=" ); }
public Map<String, Object> getNaturalIdValues() { final Map<String, Object> naturalIdValueMap = new ConcurrentHashMap<String, Object>(); for ( Criterion condition : conjunction.conditions() ) { if ( !SimpleExpression.class.isInstance( condition ) ) { continue; } final SimpleExpression equalsCondition = SimpleExpression.class.cast( condition ); if ( !"=".equals( equalsCondition.getOp() ) ) { continue; } naturalIdValueMap.put( equalsCondition.getPropertyName(), equalsCondition.getValue() ); } return naturalIdValueMap; }
public String toString() { return propertyName + getOp() + value; }
/** * @see org.openmrs.api.UserService#getUserByEmail(java.lang.String) */ @Override @SuppressWarnings("unchecked") public User getUserByEmail(String email) { return (User) sessionFactory.getCurrentSession().createCriteria(User.class).add(Restrictions.eq("email", email).ignoreCase()).uniqueResult(); }
/** * Apply a "greater than" constraint to the named property * * @param propertyName The name of the property * @param value The value to use in comparison * * @return The Criterion * * @see SimpleExpression */ public static SimpleExpression gt(String propertyName, Object value) { return new SimpleExpression( propertyName, value, ">" ); }
public String toString() { return propertyName + getOp() + value; }
/** * @see org.openmrs.api.db.AdministrationDAO#getGlobalPropertyObject(java.lang.String) */ @Override public GlobalProperty getGlobalPropertyObject(String propertyName) { if (isDatabaseStringComparisonCaseSensitive()) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(GlobalProperty.class); return (GlobalProperty) criteria.add(Restrictions.eq(PROPERTY, propertyName).ignoreCase()) .uniqueResult(); } else { return (GlobalProperty) sessionFactory.getCurrentSession().get(GlobalProperty.class, propertyName); } }
/** * Apply a "less than" constraint to the named property * * @param propertyName The name of the property * @param value The value to use in comparison * * @return The Criterion * * @see SimpleExpression */ public static SimpleExpression lt(String propertyName, Object value) { return new SimpleExpression( propertyName, value, "<" ); }
public String toString() { return propertyName + getOp() + value; }
/** * @see org.openmrs.api.db.ConceptDAO#getDrugs(java.lang.String, org.openmrs.Concept, boolean) */ @Override @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(); }