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.Enumeration ; 47 import java.util.Hashtable ; 48 import java.util.Vector ; 49 50 import java.sql.SQLException ; 51 52 import com.quadcap.util.Debug; 53 54 60 public class ViewCursor extends CursorImpl { 61 Cursor cursor; 62 View view; 63 64 public ViewCursor(Session session, View view, 65 Cursor cursor, Vector names) 66 throws SQLException 67 { 68 super(session, view.getName()); 69 this.view = view; 70 this.cursor = cursor; 71 if (names.size() > cursor.getColumnCount()) { 72 throw new SQLException ("Too many names in view column list", 73 "42000"); 74 } 75 if (names.size() < cursor.getColumnCount()) { 76 if (Trace.bit(2)) { 78 Debug.println("cursor = " + cursor); 79 for (int i = 0; i < names.size(); i++) { 80 Debug.println("name[" + i + "] = " + 81 names.elementAt(i).toString()); 82 } 83 } 84 throw new SQLException ("Not enough names in view column list", 86 "42000"); 87 } 88 for (int i = 0; i < names.size(); i++) { 89 String name = (String )names.elementAt(i); 90 addColumn(new Column(name, 91 cursor.getColumn(i+1).getType())); 92 } 93 resolveColumns(); 94 } 95 96 public long size() throws SQLException { return -1; } 97 98 public Row getRow() throws SQLException { 99 return cursor.getRow(); 100 } 101 102 public void updateRow(Row row) throws SQLException { 103 view.checkRow(session, cursor, row); 104 cursor.updateRow(row); 105 } 106 107 public void insertRow(Row row) throws SQLException { 108 view.checkRow(session, cursor, row); 109 cursor.insertRow(row); 110 } 111 112 public void deleteRow() throws SQLException { 113 cursor.deleteRow(); 114 } 115 116 public void beforeFirst() throws SQLException { 117 cursor.beforeFirst(); 118 } 119 120 public void afterLast() throws SQLException { 121 cursor.afterLast(); 122 } 123 124 public boolean absolute(int row) throws SQLException { 125 return cursor.absolute(row); 126 } 127 128 public boolean next() throws SQLException { 129 return cursor.next(); 130 } 131 132 public boolean isWritable(int column) throws SQLException { 133 return cursor.isWritable(column); 134 } 135 136 public int getColumnCount() throws SQLException { 137 return cursor.getColumnCount(); 138 } 139 public void close() throws SQLException { 140 cursor.close(); 141 } 142 } 143 | Popular Tags |