| 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.sql.SQLException ; 47 48 import com.quadcap.sql.io.ObjectInputStream; 49 import com.quadcap.sql.io.ObjectOutputStream; 50 51 import com.quadcap.sql.file.SubPageManager; 52 import com.quadcap.sql.index.BCursor; 53 54 import com.quadcap.util.Debug; 55 56 62 public abstract class BC_Cursor extends CursorImpl { 63 protected BCursor bc = null; 64 protected LazyRow row = null; 65 protected boolean rowValid = false; 66 protected long rowId = 0; 67 68 71 public BC_Cursor(Session session, String name, Cursor outer) 72 throws SQLException  73 { 74 super(session, name, outer); 75 } 76 77 81 public Row getRow() throws SQLException { 82 Row ret = null; 83 if (rowId != 0) { 84 if (!rowValid) { 85 try { 86 fetchCurrentRow(); 87 } catch (IOException ex) { 88 throw DbException.wrapThrowable(ex); 89 } 90 } 91 if (rowValid) { 92 ret = row; 93 } 94 } 95 return row; 96 } 97 98 101 public abstract void checkCursor() throws IOException , SQLException ; 102 103 public abstract long getCurrentRowId() throws IOException , SQLException ; 104 105 public abstract void fetchCurrentRow() throws IOException , SQLException ; 106 107 public boolean isWritable(int column) { return false; } 108 109 public boolean absolute(int x) throws SQLException { 110 try { 111 rowValid = false; 112 rowId = 0; 113 checkCursor(); 114 boolean ret = bc.absolute(x); 115 if (ret) { 116 rowId = getCurrentRowId(); 117 } 118 return ret; 119 } catch (IOException e) { 120 throw DbException.wrapThrowable(e); 121 } 122 } 123 124 public void beforeFirst() throws SQLException { 125 try { 126 rowValid = false; 127 rowId = 0; 128 checkCursor(); 129 bc.beforeFirst(); 130 } catch (IOException e) { 131 throw DbException.wrapThrowable(e); 132 } 133 } 134 135 public void afterLast() throws SQLException { 136 try { 137 rowValid = false; 138 rowId = 0; 139 checkCursor(); 140 bc.afterLast(); 141 } catch (IOException e) { 142 throw DbException.wrapThrowable(e); 143 } 144 } 145 146 public boolean next() throws SQLException { 147 try { 148 rowValid = false; 149 rowId = 0; 150 checkCursor(); 151 boolean ret = bc.next(); 152 if (ret) { 153 rowId = getCurrentRowId(); 154 } 155 return ret; 156 } catch (IOException e) { 157 throw DbException.wrapThrowable(e); 158 } 159 } 160 161 public boolean prev() throws SQLException { 162 try { 163 rowValid = false; 164 rowId = 0; 165 checkCursor(); 166 boolean ret = bc.prev(); 167 if (ret) rowId = getCurrentRowId(); 168 return ret; 169 } catch (IOException e) { 170 throw DbException.wrapThrowable(e); 171 } 172 } 173 174 177 public void close() throws SQLException { 178 try { 179 if (bc != null) bc.release(); 180 } finally { 181 bc = null; 182 row = null; 183 } 184 } 185 186 189 public long getRowId() { 190 return rowId; 191 } 192 193 196 public long size() throws SQLException { 197 try { 198 return bc.size(); 199 } catch (IOException e) { 200 throw DbException.wrapThrowable(e); 201 } 202 } 203 204 public void updateRow(Row row) throws SQLException { 205 throw new SQLException ("Cursor not updateable"); 206 } 207 208 public void deleteRow() throws SQLException { 209 throw new SQLException ("Cursor not updateable"); 210 } 211 } 212 | Popular Tags |