Skip to content

Commit

Permalink
HHH-8025 Implemented eqOrIsNull and neOrIsNotNull criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Meyer committed Feb 28, 2013
1 parent c4eff66 commit 04c38f1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Expand Up @@ -59,10 +59,18 @@ public SimpleExpression eq(Object value) {
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);
}
Expand Down
Expand Up @@ -59,20 +59,46 @@ public static Criterion idEq(Object value) {
* 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 a "not equal" constraint to the named property
* 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 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
Expand Down
Expand Up @@ -2064,7 +2064,7 @@ public void testNullCriteria() {
// 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() );
Expand Down

0 comments on commit 04c38f1

Please sign in to comment.