1 package org.hibernate.criterion; 3 4 5 import org.hibernate.Criteria; 6 import org.hibernate.EntityMode; 7 import org.hibernate.HibernateException; 8 import org.hibernate.engine.TypedValue; 9 import org.hibernate.type.Type; 10 import org.hibernate.util.StringHelper; 11 12 16 public class SQLCriterion implements Criterion { 17 18 private final String sql; 19 private final TypedValue[] typedValues; 20 21 public String toSqlString( 22 Criteria criteria, 23 CriteriaQuery criteriaQuery) 24 throws HibernateException { 25 return StringHelper.replace( sql, "{alias}", criteriaQuery.getSQLAlias(criteria) ); 26 } 27 28 public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 29 throws HibernateException { 30 return typedValues; 31 } 32 33 public String toString() { 34 return sql; 35 } 36 37 protected SQLCriterion(String sql, Object [] values, Type[] types) { 38 this.sql = sql; 39 typedValues = new TypedValue[values.length]; 40 for ( int i=0; i<typedValues.length; i++ ) { 41 typedValues[i] = new TypedValue( types[i], values[i], EntityMode.POJO ); 42 } 43 } 44 45 } 46 | Popular Tags |