1 package org.hibernate.criterion; 3 4 5 import org.hibernate.Criteria; 6 import org.hibernate.HibernateException; 7 import org.hibernate.engine.TypedValue; 8 9 13 public class LogicalExpression implements Criterion { 14 15 private final Criterion lhs; 16 private final Criterion rhs; 17 private final String op; 18 19 protected LogicalExpression(Criterion lhs, Criterion rhs, String 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 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 getOp() { 49 return op; 50 } 51 52 public String toString() { 53 return lhs.toString() + ' ' + getOp() + ' ' + rhs.toString(); 54 } 55 } 56 | Popular Tags |