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.sql.SQLException;
00042
00043
import com.quadcap.util.Debug;
00044
00045
00046
00047
00048
00049
00050 abstract public class CursorImpl extends TupleImpl implements
Cursor {
00051 protected Session session = null;
00052 protected Cursor outer;
00053
00054
00055
00056
00057 private CursorImpl() {}
00058
00059
00060
00061
00062 public CursorImpl(
Session session, String name) {
00063 super(name);
00064
this.session = session;
00065 }
00066
00067
00068
00069
00070 public CursorImpl(
Session session, String name,
Cursor outer) {
00071 super(name);
00072
this.session = session;
00073
this.outer = outer;
00074 }
00075
00076
00077
00078
00079 public Session getSession() {
return session; }
00080
00081
00082
00083
00084
00085
abstract public Row getRow() throws SQLException;
00086
00087
00088
00089
00090 public
void insertRow(
Row row) throws SQLException {
00091
throw new SQLException(
"Insert not allowed for this cursor type");
00092 }
00093
abstract public void updateRow(
Row row)
throws SQLException;
00094
abstract public void deleteRow() throws SQLException;
00095
00096 abstract public
void beforeFirst() throws SQLException;
00097 abstract public
void afterLast() throws SQLException;
00098 abstract public
boolean next() throws SQLException;
00099
00100 public
boolean prev() throws SQLException {
00101
throw new SQLException(
"prev() not supported for this cursor type");
00102 }
00103
00104
abstract public boolean isWritable(
int column)
throws SQLException;
00105
abstract public void close() throws SQLException;
00106
00107 public
void finalize() throws Throwable {
00108
try {
00109
close();
00110 }
catch (Throwable t) {
00111 }
00112 super.finalize();
00113 }
00114
00115 public Column getColumn(String columnName)
throws SQLException {
00116
Column c = super.getColumn(columnName);
00117
if (c == null &&
outer != null) {
00118 c =
outer.
getColumn(columnName);
00119 }
00120
return c;
00121 }
00122
00123 public void setOuterCursor(
Cursor c) {
00124
outer = c;
00125 }
00126
00127 public Cursor getOuterCursor() {
00128
return outer;
00129 }
00130
00131
00132
00133
00134
00135 public boolean absolute(
int row)
throws SQLException {
00136
if (row > 0) {
00137
beforeFirst();
00138
while (row-- > 0)
if (!
next())
return false;
00139 }
else {
00140
afterLast();
00141
while (row++ < 0)
if (!
prev())
return false;
00142 }
00143
return true;
00144 }
00145
00146 public void reset(
Expression expr,
Cursor outer)
throws SQLException {}
00147
00148 public Table getTable() {
return null; }
00149 public long getRowId() {
return 0; }
00150
00151
00152 public String
toString() {
00153
try {
00154 StringBuffer sb =
00155
new StringBuffer(
Table.strip(getClass().
getName()));
00156 sb.append(
": ");
00157 sb.append(
getName());
00158
if (
outer != null) {
00159 sb.append(
" (outer ");
00160 sb.append(
outer.toString());
00161 sb.append(
")");
00162 }
00163 sb.append(
" {");
00164
for (
int i = 1; i <=
getColumnCount(); i++) {
00165
Column c = getColumn(i);
00166
if (i > 1) sb.append(
',');
00167 sb.append(c.
getName());
00168 }
00169 sb.append(
'}');
00170
return sb.toString();
00171 }
catch (Exception e) {
00172
Debug.print(e);
00173
return this.getClass().getName();
00174 }
00175 }
00176
00177 static void dumpCursor(String label,
Cursor c)
throws SQLException {
00178
if (label.length() > 0) label = label +
" ";
00179
int count = 0;
00180 c.beforeFirst();
00181
while (c.next()) {
00182
Debug.println(label +
"Row " + (++count) +
": " + c.getRow());
00183 }
00184 c.beforeFirst();
00185 }
00186
00187 }