KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: LogicalExpression.java,v 1.8 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
9 /**
10  * Superclass of binary logical expressions
11  * @author Gavin King
12  */

13 public class LogicalExpression implements Criterion {
14
15     private final Criterion lhs;
16     private final Criterion rhs;
17     private final String JavaDoc op;
18
19     protected LogicalExpression(Criterion lhs, Criterion rhs, String JavaDoc op) {
20         this.lhs = lhs;
21         this.rhs = rhs;
22         this.op = op;
23     }
24
25     public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
26     throws HibernateException {
27
28         TypedValue[] lhstv = lhs.getTypedValues(criteria, criteriaQuery);
29         TypedValue[] rhstv = rhs.getTypedValues(criteria, criteriaQuery);
30         TypedValue[] result = new TypedValue[ lhstv.length + rhstv.length ];
31         System.arraycopy(lhstv, 0, result, 0, lhstv.length);
32         System.arraycopy(rhstv, 0, result, lhstv.length, rhstv.length);
33         return result;
34     }
35
36     public String JavaDoc toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
37     throws HibernateException {
38
39         return '(' +
40             lhs.toSqlString(criteria, criteriaQuery) +
41             ' ' +
42             getOp() +
43             ' ' +
44             rhs.toSqlString(criteria, criteriaQuery) +
45             ')';
46     }
47
48     public String JavaDoc getOp() {
49         return op;
50     }
51
52     public String JavaDoc toString() {
53         return lhs.toString() + ' ' + getOp() + ' ' + rhs.toString();
54     }
55 }
56
Popular Tags