01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.sail.rdbms.algebra;
07:
08: import org.openrdf.query.algebra.Compare.CompareOp;
09: import org.openrdf.sail.rdbms.algebra.base.BinarySqlOperator;
10: import org.openrdf.sail.rdbms.algebra.base.RdbmsQueryModelVisitorBase;
11: import org.openrdf.sail.rdbms.algebra.base.SqlExpr;
12:
13: /**
14: * The SQL compare expressions (>, <, >=, <=).
15: *
16: * @author James Leigh
17: *
18: */
19: public class SqlCompare extends BinarySqlOperator {
20: public enum Operator {
21: GT, LT, GE, LE
22: }
23:
24: private Operator op;
25:
26: public SqlCompare(SqlExpr leftArg, CompareOp op, SqlExpr rightArg) {
27: super (leftArg, rightArg);
28: switch (op) {
29: case GT:
30: this .op = Operator.GT;
31: break;
32: case LT:
33: this .op = Operator.LT;
34: break;
35: case GE:
36: this .op = Operator.GE;
37: break;
38: case LE:
39: this .op = Operator.LE;
40: break;
41: default:
42: throw new AssertionError(op);
43: }
44: }
45:
46: public Operator getOperator() {
47: return op;
48: }
49:
50: @Override
51: public String getSignature() {
52: return super .getSignature() + " (" + op + ")";
53: }
54:
55: @Override
56: public <X extends Exception> void visit(
57: RdbmsQueryModelVisitorBase<X> visitor) throws X {
58: visitor.meet(this );
59: }
60:
61: @Override
62: public int hashCode() {
63: final int prime = 31;
64: int result = super .hashCode();
65: result = prime * result + ((op == null) ? 0 : op.hashCode());
66: return result;
67: }
68:
69: @Override
70: public boolean equals(Object obj) {
71: if (this == obj)
72: return true;
73: if (!super .equals(obj))
74: return false;
75: if (getClass() != obj.getClass())
76: return false;
77: final SqlCompare other = (SqlCompare) obj;
78: if (op == null) {
79: if (other.op != null)
80: return false;
81: } else if (!op.equals(other.op))
82: return false;
83: return true;
84: }
85: }
|