Quadcap Embeddable Database

com/quadcap/sql/NameExpression.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.ArrayList; 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 import com.quadcap.util.Util; 00057 00058 /** 00059 * Expression class for names (typically column or function names). 00060 * 00061 * @author Stan Bailes 00062 */ 00063 public class NameExpression extends Expression implements Externalizable { 00064 String name; 00065 boolean not = false; 00066 00067 /** 00068 * Default constructor 00069 */ 00070 public NameExpression() {} 00071 00072 public NameExpression(String name) { 00073 this.name = name; 00074 } 00075 00076 /** 00077 * I'm a scalar, basically 00078 */ 00079 public int rank() { return 0; } 00080 00081 public Type getType(Session session, Cursor cursor) throws SQLException { 00082 String rname = session.getConnection().resolveColname(name, cursor); 00083 Column c = cursor.getColumn(rname); 00084 return c.getType(); 00085 } 00086 00087 public Value getValue(Session session, Cursor cursor) throws SQLException { 00088 Cursor effectiveCursor = cursor; 00089 if (cursor == null) { 00090 throw new SQLException("No cursor for name expression: " + name, "42000"); 00091 } 00092 String rname = session.getConnection().resolveColname(name, cursor); 00093 Column c = cursor.getColumn(rname); 00094 if (c == null) { 00095 throw new SQLException("Bad column: " + name, "Q000S"); 00096 } 00097 Tuple tc = c.getRelation(); 00098 if (tc instanceof Cursor && !(cursor instanceof StaticCursor)) { 00099 effectiveCursor = (Cursor)tc; 00100 } 00101 00102 int col = c.getColumn(); 00103 Row row = effectiveCursor.getRow(); 00104 if (row == null) { 00105 throw new SQLException("no cursor", "Q000T"); 00106 } 00107 Value v = row.item(col); 00108 if (not) v = v.unop(Op.NOT); 00109 return v; 00110 } 00111 00112 public Row getValues(Session session, Cursor cursor) throws SQLException { 00113 ArrayList v = new ArrayList(); 00114 v.add(getValue(session, cursor)); 00115 return new Row(v); 00116 } 00117 00118 public String getName() { return name; } 00119 00120 public void invert() { 00121 not = !not; 00122 } 00123 00124 public void visitSubExpressions(ExpressionVisitor ev) { 00125 } 00126 00127 public void readExternal(ObjectInput in) 00128 throws IOException, ClassNotFoundException 00129 { 00130 name = (String)in.readObject(); 00131 } 00132 00133 public void writeExternal(ObjectOutput out) throws IOException { 00134 out.writeObject(name); 00135 } 00136 00137 public String toString() { 00138 return name; 00139 } 00140 }