FileDocCategorySizeDatePackage
LikeExpression.javaAPI DocHibernate 3.2.52146Wed Jun 28 00:20:52 BST 2006org.hibernate.criterion

LikeExpression

public class LikeExpression extends Object implements Criterion
A criterion representing a "like" expression
author
Scott Marlow
author
Steve Ebersole

Fields Summary
private final String
propertyName
private final Object
value
private final Character
escapeChar
private final boolean
ignoreCase
Constructors Summary
protected LikeExpression(String propertyName, String value, Character escapeChar, boolean ignoreCase)

		this.propertyName = propertyName;
		this.value = value;
		this.escapeChar = escapeChar;
		this.ignoreCase = ignoreCase;
	
protected LikeExpression(String propertyName, String value)

		this( propertyName, value, null, false );
	
protected LikeExpression(String propertyName, String value, MatchMode matchMode)

		this( propertyName, matchMode.toMatchString( value ) );
	
protected LikeExpression(String propertyName, String value, MatchMode matchMode, Character escapeChar, boolean ignoreCase)

		this( propertyName, matchMode.toMatchString( value ), escapeChar, ignoreCase );
	
Methods Summary
public org.hibernate.engine.TypedValue[]getTypedValues(org.hibernate.Criteria criteria, CriteriaQuery criteriaQuery)

		return new TypedValue[] {
				criteriaQuery.getTypedValue( criteria, propertyName, value.toString().toLowerCase() )
		};
	
public java.lang.StringtoSqlString(org.hibernate.Criteria criteria, CriteriaQuery criteriaQuery)

		Dialect dialect = criteriaQuery.getFactory().getDialect();
		String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, propertyName );
		if ( columns.length != 1 ) {
			throw new HibernateException( "Like may only be used with single-column properties" );
		}
		String lhs = ignoreCase
				? dialect.getLowercaseFunction() + '(" + columns[0] + ')"
	            : columns[0];
		return lhs + " like ?" + ( escapeChar == null ? "" : " escape \'" + escapeChar + "\'" );