HHH-8025 Implemented eqOrIsNull and neOrIsNotNull criteria
This commit is contained in:
parent
c4eff66948
commit
04c38f189b
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() );
|
||||
|
|
Loading…
Reference in New Issue