00001
package com.quadcap.sql;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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.Enumeration;
00047
import java.util.Hashtable;
00048
import java.util.Vector;
00049
00050
import java.sql.SQLException;
00051
00052
import com.quadcap.util.Debug;
00053
00054
00055
00056
00057
00058
00059
00060 public class ViewCursor extends CursorImpl {
00061 Cursor cursor;
00062 View view;
00063
00064 public ViewCursor(
Session session,
View view,
00065
Cursor cursor, Vector names)
00066
throws SQLException
00067 {
00068 super(session,
view.
getName());
00069
this.view =
view;
00070
this.cursor =
cursor;
00071
if (names.size() >
cursor.
getColumnCount()) {
00072
throw new SQLException(
"Too many names in view column list",
00073
"42000");
00074 }
00075
if (names.size() <
cursor.
getColumnCount()) {
00076
00077
if (
Trace.bit(2)) {
00078
Debug.println(
"cursor = " +
cursor);
00079
for (
int i = 0; i < names.size(); i++) {
00080
Debug.println(
"name[" + i +
"] = " +
00081 names.elementAt(i).toString());
00082 }
00083 }
00084
00085
throw new SQLException(
"Not enough names in view column list",
00086
"42000");
00087 }
00088
for (
int i = 0; i < names.size(); i++) {
00089 String name = (String)names.elementAt(i);
00090 addColumn(
new Column(name,
00091
cursor.
getColumn(i+1).
getType()));
00092 }
00093
resolveColumns();
00094 }
00095
00096 public long size() throws SQLException {
return -1; }
00097
00098 public Row getRow() throws SQLException {
00099
return cursor.
getRow();
00100 }
00101
00102 public void updateRow(
Row row)
throws SQLException {
00103
view.
checkRow(session,
cursor, row);
00104
cursor.
updateRow(row);
00105 }
00106
00107 public void insertRow(
Row row)
throws SQLException {
00108
view.
checkRow(session,
cursor, row);
00109
cursor.
insertRow(row);
00110 }
00111
00112 public void deleteRow() throws SQLException {
00113
cursor.
deleteRow();
00114 }
00115
00116 public void beforeFirst() throws SQLException {
00117
cursor.
beforeFirst();
00118 }
00119
00120 public void afterLast() throws SQLException {
00121
cursor.
afterLast();
00122 }
00123
00124 public boolean absolute(
int row)
throws SQLException {
00125
return cursor.
absolute(row);
00126 }
00127
00128 public boolean next() throws SQLException {
00129
return cursor.
next();
00130 }
00131
00132 public boolean isWritable(
int column)
throws SQLException {
00133
return cursor.
isWritable(column);
00134 }
00135
00136 public int getColumnCount() throws SQLException {
00137
return cursor.
getColumnCount();
00138 }
00139 public void close() throws SQLException {
00140
cursor.
close();
00141 }
00142 }