Quadcap Embeddable Database

com/quadcap/sql/BinaryExpression.java

Go to the documentation of this file.
00001 package com.quadcap.sql; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 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 * Expression class for all binary ops. 00059 * 00060 * @author Stan Bailes 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 * Default constructor 00070 */ 00071 public BinaryExpression() {} 00072 00073 /** 00074 * Parser's constructor: A binary expression node consists of an opcode and two 00075 * "child" expressions. 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); // XXX not quite... 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 }