00001
package com.quadcap.sql;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
import java.io.Externalizable;
00042
import java.io.IOException;
00043
import java.io.ObjectInput;
00044
import java.io.ObjectOutput;
00045
00046
import java.util.Enumeration;
00047
import java.util.Vector;
00048
00049
import java.sql.SQLException;
00050
00051
import com.quadcap.sql.types.Op;
00052
import com.quadcap.sql.types.Type;
00053
import com.quadcap.sql.types.Value;
00054
00055
import com.quadcap.util.Debug;
00056
00057
00058
00059
00060
00061
00062 public class BinaryExpression extends Expression implements
Externalizable {
00063 Expression e = null;
00064 Expression f = null;
00065 int op = -1;
00066 boolean not =
false;
00067
00068
00069
00070
00071 public BinaryExpression() {}
00072
00073
00074
00075
00076
00077 public BinaryExpression(
int op,
Expression e,
Expression f) {
00078
this.op = op;
00079
this.e = e;
00080
this.f = f;
00081 }
00082
00083 public int rank() {
return 0; }
00084
00085 public Type getType(
Session session,
Cursor cursor)
throws SQLException {
00086
return e.
getType(session, cursor);
00087 }
00088
00089 public Value getValue(
Session session,
Cursor cursor)
throws SQLException {
00090
Value eval =
e.
getValue(session, cursor);
00091
Value fval =
f.
getValue(session, cursor);
00092
Value ret =
Value.binop(
op, eval, fval);
00093
if (
not) {
00094 ret = ret.
unop(
Op.NOT);
00095 }
00096
return ret;
00097 }
00098
00099 public void invert() {
00100
not = !
not;
00101 }
00102
00103 public String
toString() {
00104 String n =
not ?
"not " :
"";
00105
return n +
e +
" " +
Op.
toString(
op) +
" " +
f;
00106 }
00107
00108 public void visitSubExpressions(
ExpressionVisitor ev) {
00109 ev.
visit(
e);
00110 ev.
visit(
f);
00111 }
00112
00113 public void readExternal(ObjectInput in)
00114
throws IOException, ClassNotFoundException
00115 {
00116
e = (
Expression)in.readObject();
00117
f = (
Expression)in.readObject();
00118
op = in.readInt();
00119
not = (in.read() == 1);
00120 }
00121
00122 public void writeExternal(ObjectOutput out)
throws IOException {
00123 out.writeObject(
e);
00124 out.writeObject(
f);
00125 out.writeInt(
op);
00126 out.write(
not ? 1 : 0);
00127 }
00128 }