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 IdentifierEqExpression implements Criterion { 15 16 private final Object value; 17 18 protected IdentifierEqExpression(Object value) { 19 this.value = value; 20 } 21 22 public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) 23 throws HibernateException { 24 25 String [] columns = criteriaQuery.getIdentifierColumns(criteria); 26 27 String result = StringHelper.join( 28 " and ", 29 StringHelper.suffix( columns, " = ?" ) 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 new TypedValue[] { criteriaQuery.getTypedIdentifierValue(criteria, value) }; 40 } 41 42 public String toString() { 43 return "id = " + value; 44 } 45 46 } 47 | Popular Tags |