Quadcap Embeddable Database

com/quadcap/sql/Expression.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.IOException; 00042 00043 import java.util.Enumeration; 00044 import java.util.Vector; 00045 00046 import java.sql.SQLException; 00047 00048 import com.quadcap.sql.types.Op; 00049 import com.quadcap.sql.types.Type; 00050 import com.quadcap.sql.types.Value; 00051 00052 import com.quadcap.util.Debug; 00053 00054 /** 00055 * Base class for all expression types. 00056 * 00057 * @author Stan Bailes 00058 */ 00059 00060 public abstract class Expression { 00061 /** 00062 * Returns zero if this is a scalar expression, one if it's a vector 00063 * type and 2 if it's a table/cursor type. 00064 */ 00065 public abstract int rank(); 00066 00067 /** 00068 * Return the expression's type if known 00069 */ 00070 public abstract Type getType(Session session, Cursor cursor) 00071 throws SQLException; 00072 00073 /** 00074 * If this is a scalar, return its value 00075 */ 00076 public Value getValue(Session session, Cursor cursor) 00077 throws SQLException 00078 { 00079 return null; 00080 } 00081 00082 /** 00083 * If this is a vector, return the value 00084 */ 00085 public Row getValues(Session session, Cursor cursor) throws SQLException { 00086 if (rank() == 0) { 00087 Value v = getValue(session, cursor); 00088 Row row = new Row(1); 00089 row.set(1, v); 00090 return row; 00091 } else { 00092 throw new SQLException("getValues, rank = " + rank(), "Q0000"); 00093 } 00094 } 00095 00096 /** 00097 * If this is a cursor, return the value 00098 */ 00099 public Cursor getCursor(Session session, Cursor cursor) 00100 throws SQLException 00101 { 00102 return null; 00103 } 00104 00105 /** 00106 * Negate the logical value of the expression 00107 */ 00108 public void invert() throws antlr.RecognitionException { 00109 throw new antlr.RecognitionException("Error, not a boolean expression"); 00110 } 00111 00112 /** 00113 * Give a visitor access to the parse tree. 00114 */ 00115 public void visitSubExpressions(ExpressionVisitor v) {} 00116 00117 00118 public String getName() { return null; } 00119 00120 abstract public String toString(); 00121 00122 }