KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > criterion > NullExpression


1 //$Id: NullExpression.java,v 1.10 2005/02/12 07:19:14 steveebersole Exp $
2
package org.hibernate.criterion;
3
4
5 import org.hibernate.Criteria;
6 import org.hibernate.HibernateException;
7 import org.hibernate.engine.TypedValue;
8 import org.hibernate.util.StringHelper;
9
10 /**
11  * Constrains a property to be null
12  * @author Gavin King
13  */

14 public class NullExpression implements Criterion {
15
16     private final String JavaDoc propertyName;
17
18     private static final TypedValue[] NO_VALUES = new TypedValue[0];
19
20     protected NullExpression(String JavaDoc propertyName) {
21         this.propertyName = propertyName;
22     }
23
24     public String JavaDoc toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
25     throws HibernateException {
26         String JavaDoc[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);
27         String JavaDoc result = StringHelper.join(
28             " and ",
29             StringHelper.suffix( columns, " is null" )
30         );
31         if (columns.length>1) result = '(' + result + ')';
32         return result;
33
34         //TODO: get SQL rendering out of this package!
35
}
36
37     public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
38     throws HibernateException {
39         return NO_VALUES;
40     }
41
42     public String JavaDoc toString() {
43         return propertyName + " is null";
44     }
45
46 }
47
Popular Tags