KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: SQLCriterion.java,v 1.10 2005/02/18 03:47:27 oneovthafew Exp $
2
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 /**
13  * A SQL fragment. The string {alias} will be replaced by the
14  * alias of the root entity.
15  */

16 public class SQLCriterion implements Criterion {
17
18     private final String JavaDoc sql;
19     private final TypedValue[] typedValues;
20
21     public String JavaDoc 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 JavaDoc toString() {
34         return sql;
35     }
36
37     protected SQLCriterion(String JavaDoc sql, Object JavaDoc[] 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