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.util.Debug; 51 52 64 public class SelectFromItem extends TableExpression implements Externalizable { 65 TableExpression e; 66 String asName = null; 67 Vector columns = null; 68 69 public SelectFromItem() {} 70 71 public SelectFromItem(TableExpression e, String asName, Vector columns) { 72 this.e = e; 73 this.asName = asName; 74 this.columns = columns; 75 } 76 77 public void readExternal(ObjectInput in) 78 throws IOException , ClassNotFoundException 79 { 80 this.e = (TableExpression)in.readObject(); 81 this.asName = (String )in.readObject(); 82 this.columns = (Vector )in.readObject(); 83 } 84 85 public void writeExternal(ObjectOutput out) throws IOException { 86 out.writeObject(e); 87 out.writeObject(asName); 88 out.writeObject(columns); 89 } 90 91 public int rank() { return e.rank(); } 92 93 public boolean isUpdatable() { return e.isUpdatable(); } 94 95 public void getBaseTables(Vector v) { 96 e.getBaseTables(v); 97 } 98 99 public void setWhere(Expression where) { 100 this.where = where; 101 e.setWhere(where); 102 } 103 104 public Cursor getCursor(Session session, Cursor outer) 105 throws SQLException 106 { 107 Cursor c = e.getCursor(session, outer); 108 return new RenameCursor(session, c, asName, columns); 109 } 110 111 public String toString() { 112 StringBuffer sb = new StringBuffer (e.toString()); 113 if (asName != null && asName.length() > 0) { 114 sb.append(" AS "); 115 sb.append(asName); 116 if (columns != null) { 117 sb.append('('); 118 for (int i = 0; i < columns.size(); i++) { 119 if (i > 0) sb.append(','); 120 sb.append(columns.get(i)); 121 } 122 sb.append(')'); 123 } 124 } 125 return sb.toString(); 126 } 127 128 public String name() { 130 StringBuffer sb = new StringBuffer (e.name()); 131 if (asName != null) { 132 sb.append(" AS "); 133 sb.append(asName); 134 } 135 return sb.toString(); 136 } 137 } 139 140 | Popular Tags |