001: /**********************************************************************
002: Copyright (c) 2003 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.store.expression;
019:
020: import java.util.List;
021:
022: import org.jpox.store.mapping.JavaTypeMapping;
023:
024: /**
025: * Expression for binary object.
026: *
027: * @version $Revision: 1.6 $
028: **/
029: public class BinaryExpression extends ScalarExpression {
030: /**
031: * Constructor
032: * @param qs the QueryExpression
033: */
034: protected BinaryExpression(QueryExpression qs) {
035: super (qs);
036: }
037:
038: /**
039: *
040: * @param qs the QueryExpression
041: * @param mapping the mapping associated to this expression
042: * @param te the TableExpression where this expression refers to
043: */
044: public BinaryExpression(QueryExpression qs,
045: JavaTypeMapping mapping, LogicSetExpression te) {
046: super (qs, mapping, te);
047: }
048:
049: /**
050: * Generates statement as e.g. FUNCTION_NAME(arg[,argN])
051: * @param functionName
052: * @param args ScalarExpression list
053: */
054: public BinaryExpression(String functionName, List args) {
055: super (functionName, args);
056: }
057:
058: /**
059: * Performs a function on two binary expressions.
060: * op(operand1,operand2)
061: * operand1 op operand2
062: * @param operand1 the first expression
063: * @param op the operator between operands
064: * @param operand2 the second expression
065: */
066: public BinaryExpression(ScalarExpression operand1,
067: DyadicOperator op, ScalarExpression operand2) {
068: super (operand1, op, operand2);
069: }
070:
071: public BooleanExpression eq(ScalarExpression expr) {
072: if (expr instanceof NullLiteral) {
073: return expr.eq(this );
074: } else if (expr instanceof BinaryExpression) {
075: return new BooleanExpression(this , OP_EQ, expr);
076: } else {
077: return super .eq(expr);
078: }
079: }
080:
081: public BooleanExpression noteq(ScalarExpression expr) {
082: if (expr instanceof NullLiteral) {
083: return expr.noteq(this );
084: } else if (expr instanceof BinaryExpression) {
085: return new BooleanExpression(this , OP_NOTEQ, expr);
086: } else {
087: return super .noteq(expr);
088: }
089: }
090:
091: public BooleanExpression lt(ScalarExpression expr) {
092: if (expr instanceof BinaryExpression) {
093: return new BooleanExpression(this , OP_LT, expr);
094: } else {
095: return super .lt(expr);
096: }
097: }
098:
099: public BooleanExpression lteq(ScalarExpression expr) {
100: if (expr instanceof BinaryExpression) {
101: return new BooleanExpression(this , OP_LTEQ, expr);
102: } else {
103: return super .lteq(expr);
104: }
105: }
106:
107: public BooleanExpression gt(ScalarExpression expr) {
108: if (expr instanceof BinaryExpression) {
109: return new BooleanExpression(this , OP_GT, expr);
110: } else {
111: return super .gt(expr);
112: }
113: }
114:
115: public BooleanExpression gteq(ScalarExpression expr) {
116: if (expr instanceof BinaryExpression) {
117: return new BooleanExpression(this , OP_GTEQ, expr);
118: } else {
119: return super .gteq(expr);
120: }
121: }
122:
123: public ScalarExpression add(ScalarExpression expr) {
124: if (expr instanceof BinaryExpression) {
125: return new BinaryExpression(this , OP_CONCAT, expr);
126: } else {
127: return super .add(expr);
128: }
129: }
130:
131: public BooleanExpression in(ScalarExpression expr) {
132: return new BooleanExpression(this, OP_IN, expr);
133: }
134: }
|