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.sql.SQLException;
00047
00048
import com.quadcap.sql.io.ObjectInputStream;
00049
import com.quadcap.sql.io.ObjectOutputStream;
00050
00051
import com.quadcap.sql.file.SubPageManager;
00052
import com.quadcap.sql.index.BCursor;
00053
00054
import com.quadcap.util.Debug;
00055
00056
00057
00058
00059
00060
00061
00062 public abstract class BC_Cursor extends CursorImpl {
00063 protected BCursor
bc = null;
00064 protected LazyRow row = null;
00065 protected boolean rowValid =
false;
00066 protected long rowId = 0;
00067
00068
00069
00070
00071 public BC_Cursor(
Session session, String name,
Cursor outer)
00072
throws SQLException
00073 {
00074 super(session, name, outer);
00075 }
00076
00077
00078
00079
00080
00081 public Row getRow() throws SQLException {
00082
Row ret = null;
00083
if (
rowId != 0) {
00084
if (!
rowValid) {
00085
try {
00086
fetchCurrentRow();
00087 }
catch (IOException ex) {
00088
throw DbException.wrapThrowable(ex);
00089 }
00090 }
00091
if (
rowValid) {
00092 ret =
row;
00093 }
00094 }
00095
return row;
00096 }
00097
00098
00099
00100
00101
public abstract void checkCursor() throws IOException, SQLException;
00102
00103 public abstract
long getCurrentRowId() throws IOException, SQLException;
00104
00105 public abstract
void fetchCurrentRow() throws IOException, SQLException;
00106
00107 public
boolean isWritable(
int column) {
return false; }
00108
00109 public boolean absolute(
int x)
throws SQLException {
00110
try {
00111
rowValid =
false;
00112
rowId = 0;
00113
checkCursor();
00114
boolean ret =
bc.absolute(x);
00115
if (ret) {
00116
rowId =
getCurrentRowId();
00117 }
00118
return ret;
00119 }
catch (IOException e) {
00120
throw DbException.wrapThrowable(e);
00121 }
00122 }
00123
00124 public void beforeFirst() throws SQLException {
00125
try {
00126
rowValid =
false;
00127
rowId = 0;
00128
checkCursor();
00129
bc.beforeFirst();
00130 }
catch (IOException e) {
00131
throw DbException.wrapThrowable(e);
00132 }
00133 }
00134
00135 public void afterLast() throws SQLException {
00136
try {
00137
rowValid =
false;
00138
rowId = 0;
00139
checkCursor();
00140
bc.afterLast();
00141 }
catch (IOException e) {
00142
throw DbException.wrapThrowable(e);
00143 }
00144 }
00145
00146 public boolean next() throws SQLException {
00147
try {
00148
rowValid =
false;
00149
rowId = 0;
00150
checkCursor();
00151
boolean ret =
bc.next();
00152
if (ret) {
00153
rowId =
getCurrentRowId();
00154 }
00155
return ret;
00156 }
catch (IOException e) {
00157
throw DbException.wrapThrowable(e);
00158 }
00159 }
00160
00161 public boolean prev() throws SQLException {
00162
try {
00163
rowValid =
false;
00164
rowId = 0;
00165
checkCursor();
00166
boolean ret =
bc.prev();
00167
if (ret)
rowId =
getCurrentRowId();
00168
return ret;
00169 }
catch (IOException e) {
00170
throw DbException.wrapThrowable(e);
00171 }
00172 }
00173
00174
00175
00176
00177 public void close() throws SQLException {
00178
try {
00179
if (
bc != null)
bc.release();
00180 } finally {
00181
bc = null;
00182
row = null;
00183 }
00184 }
00185
00186
00187
00188
00189 public long getRowId() {
00190
return rowId;
00191 }
00192
00193
00194
00195
00196 public long size() throws SQLException {
00197
try {
00198
return bc.size();
00199 }
catch (IOException e) {
00200
throw DbException.wrapThrowable(e);
00201 }
00202 }
00203
00204 public void updateRow(
Row row)
throws SQLException {
00205
throw new SQLException(
"Cursor not updateable");
00206 }
00207
00208 public void deleteRow() throws SQLException {
00209
throw new SQLException(
"Cursor not updateable");
00210 }
00211 }