KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: IdentifierEqExpression.java,v 1.2 2005/02/12 07:19:13 steveebersole Exp $
2
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 /**
11  * An identifier constraint
12  * @author Gavin King
13  */

14 public class IdentifierEqExpression implements Criterion {
15
16     private final Object JavaDoc value;
17
18     protected IdentifierEqExpression(Object JavaDoc value) {
19         this.value = value;
20     }
21
22     public String JavaDoc toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
23     throws HibernateException {
24
25         String JavaDoc[] columns = criteriaQuery.getIdentifierColumns(criteria);
26
27         String JavaDoc result = StringHelper.join(
28             " and ",
29             StringHelper.suffix( columns, " = ?" )
30         );
31         if (columns.length>1) result = '(' + result + ')';
32         return result;
33
34         //TODO: get SQL rendering out of this package!
35
}
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 JavaDoc toString() {
43         return "id = " + value;
44     }
45
46 }
47
Popular Tags