HHH-8025 Implemented eqOrIsNull and neOrIsNotNull criteria

This commit is contained in:
Brett Meyer 2013-02-28 16:43:27 -05:00
parent c4eff66948
commit 04c38f189b
3 changed files with 37 additions and 3 deletions

View File

@ -59,10 +59,18 @@ public class Property extends PropertyProjection {
return Restrictions.eq(getPropertyName(), value);
}
public Criterion eqOrIsNull(Object value) {
return Restrictions.eqOrIsNull(getPropertyName(), value);
}
public SimpleExpression ne(Object value) {
return Restrictions.ne(getPropertyName(), value);
}
public Criterion neOrIsNotNull(Object value) {
return Restrictions.neOrIsNotNull(getPropertyName(), value);
}
public SimpleExpression gt(Object value) {
return Restrictions.gt(getPropertyName(), value);
}

View File

@ -59,20 +59,46 @@ public class Restrictions {
* Apply an "equal" constraint to the named property
* @param propertyName
* @param value
* @return Criterion
* @return SimpleExpression
*/
public static SimpleExpression eq(String propertyName, Object value) {
return new SimpleExpression(propertyName, value, "=");
}
/**
* Apply an "equal" constraint to the named property. If the value
* is null, instead apply "is null".
* @param propertyName
* @param value
* @return Criterion
*/
public static Criterion eqOrIsNull(String propertyName, Object value) {
if (value == null) {
return isNull(propertyName);
}
return new SimpleExpression(propertyName, value, "=");
}
/**
* Apply a "not equal" constraint to the named property
* @param propertyName
* @param value
* @return Criterion
* @return SimpleExpression
*/
public static SimpleExpression ne(String propertyName, Object value) {
return new SimpleExpression(propertyName, value, "<>");
}
/**
* Apply a "not equal" constraint to the named property. If the value
* is null, instead apply "is not null".
* @param propertyName
* @param value
* @return Criterion
*/
public static Criterion neOrIsNotNull(String propertyName, Object value) {
if (value == null) {
return isNotNull(propertyName);
}
return new SimpleExpression(propertyName, value, "<>");
}
/**
* Apply a "like" constraint to the named property
* @param propertyName

View File

@ -2064,7 +2064,7 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase {
// Ensure Restrictions creates "where foo is null", instead of
// "where foo = null"
List<Course> courses = s.createCriteria( Course.class ).add(
Restrictions.eq( "description", null) ).list();
Restrictions.eqOrIsNull( "description", null) ).list();
assertEquals( courses.size(), 1 );
assertEquals( courses.get( 0 ).getCourseCode(), course.getCourseCode() );