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 PropertyExpression implements Criterion { 15 16 private final String propertyName; 17 private final String otherPropertyName; 18 private final String op; 19 20 private static final TypedValue[] NO_TYPED_VALUES = new TypedValue[0]; 21 22 protected PropertyExpression(String propertyName, String otherPropertyName, String op) { 23 this.propertyName = propertyName; 24 this.otherPropertyName = otherPropertyName; 25 this.op = op; 26 } 27 28 public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) 29 throws HibernateException { 30 String [] xcols = criteriaQuery.getColumnsUsingProjection(criteria, propertyName); 31 String [] ycols = criteriaQuery.getColumnsUsingProjection(criteria, otherPropertyName); 32 String result = StringHelper.join( 33 " and ", 34 StringHelper.add(xcols, getOp(), ycols) 35 ); 36 if (xcols.length>1) result = '(' + result + ')'; 37 return result; 38 } 40 41 public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 42 throws HibernateException { 43 return NO_TYPED_VALUES; 44 } 45 46 public String toString() { 47 return propertyName + getOp() + otherPropertyName; 48 } 49 50 public String getOp() { 51 return op; 52 } 53 54 } 55 | Popular Tags |