01: //$Id: NotExpression.java 5685 2005-02-12 07:19:50Z steveebersole $
02: package org.hibernate.criterion;
03:
04: import org.hibernate.Criteria;
05: import org.hibernate.HibernateException;
06: import org.hibernate.dialect.MySQLDialect;
07: import org.hibernate.engine.TypedValue;
08:
09: /**
10: * Negates another criterion
11: * @author Gavin King
12: */
13: public class NotExpression implements Criterion {
14:
15: private Criterion criterion;
16:
17: protected NotExpression(Criterion criterion) {
18: this .criterion = criterion;
19: }
20:
21: public String toSqlString(Criteria criteria,
22: CriteriaQuery criteriaQuery) throws HibernateException {
23: if (criteriaQuery.getFactory().getDialect() instanceof MySQLDialect) {
24: return "not ("
25: + criterion.toSqlString(criteria, criteriaQuery)
26: + ')';
27: } else {
28: return "not "
29: + criterion.toSqlString(criteria, criteriaQuery);
30: }
31: }
32:
33: public TypedValue[] getTypedValues(Criteria criteria,
34: CriteriaQuery criteriaQuery) throws HibernateException {
35: return criterion.getTypedValues(criteria, criteriaQuery);
36: }
37:
38: public String toString() {
39: return "not " + criterion.toString();
40: }
41:
42: }
|