1 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 14 public class NotNullExpression implements Criterion { 15 16 private final String propertyName; 17 18 private static final TypedValue[] NO_VALUES = new TypedValue[0]; 19 20 protected NotNullExpression(String propertyName) { 21 this.propertyName = propertyName; 22 } 23 24 public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) 25 throws HibernateException { 26 String [] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName); 27 String result = StringHelper.join( 28 " or ", 29 StringHelper.suffix( columns, " is not null" ) 30 ); 31 if (columns.length>1) result = '(' + result + ')'; 32 return result; 33 34 } 36 37 public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 38 throws HibernateException { 39 return NO_VALUES; 40 } 41 42 public String toString() { 43 return propertyName + " is not null"; 44 } 45 46 } 47 | Popular Tags |