1 package com.quadcap.sql; 2 3 40 41 import java.io.Externalizable ; 42 import java.io.IOException ; 43 import java.io.ObjectInput ; 44 import java.io.ObjectOutput ; 45 46 import java.util.Vector ; 47 48 import java.sql.SQLException ; 49 50 import com.quadcap.sql.meta.MetaCursor; 51 52 import com.quadcap.util.Debug; 53 54 59 public class SelectFromTable extends TableExpression 60 implements Externalizable 61 { 62 String tableName; 63 Relation table = null; 64 65 68 public SelectFromTable() {} 69 70 73 public SelectFromTable(String tableName) { 74 this.tableName = tableName; 75 } 76 77 80 public int rank() { return 2; } 81 82 85 public Cursor getCursor(Session session, Cursor cursor) 86 throws SQLException 87 { 88 if (table == null) { 89 try { 90 Database db = session.getDatabase(); 91 table = db.getRelation(tableName); 92 } catch (IOException e) { 93 throw DbException.wrapThrowable(e); 94 } 95 if (table == null) { 96 Cursor c = MetaCursor.find(session, tableName); 97 if (c != null) return c; 98 99 throw new SQLException ("No such table: " + tableName, "42000"); 100 } 101 } 102 return table.getCursor(session, where, null, cursor); 103 } 104 105 108 public boolean isUpdatable() { 109 return true; 110 } 111 112 115 public void getBaseTables(Vector v) { 116 v.addElement(tableName); 117 } 118 119 122 public void readExternal(ObjectInput in) 123 throws IOException , ClassNotFoundException 124 { 125 this.tableName = (String )in.readObject(); 126 this.table = null; 127 } 128 129 132 public void writeExternal(ObjectOutput out) throws IOException { 133 out.writeObject(tableName); 134 } 135 136 public String toString() { 137 return tableName; 138 } 139 140 143 public String getTableName() { 144 return tableName; 145 } 146 147 150 public void setTableName(String t) { 151 tableName = t; 152 } 153 154 public String name() { return tableName; } 156 } 158 | Popular Tags |