1 package com.daffodilwoods.daffodildb.server.sql99.dml.declarecursor; 2 3 import com.daffodilwoods.database.resource.*; 4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 5 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.TableCharacteristics; 6 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 7 import com.daffodilwoods.daffodildb.server.datasystem.utility.*; 8 import java.util.*; 9 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 10 import com.daffodilwoods.daffodildb.utils.BufferRange; 11 12 20 public class MemoryTableIterator implements _TableIterator,_TableOperations{ 21 22 26 private Object currentKey ; 27 28 32 33 private MemoryTable memoryTable; 34 35 40 41 private int status; 42 47 public MemoryTableIterator(MemoryTable memoryTable0) throws DException { 48 memoryTable = memoryTable0; 49 status = -1; 50 } 51 52 58 59 public boolean first() throws DException { 60 Object key = memoryTable.getFirstKey(); 61 boolean flag = (currentKey = key) != null; 62 status = flag ? 0 : -1; 63 return flag; 64 } 65 66 72 73 public boolean last() throws DException { 74 Object key = memoryTable.getLastKey(); 75 boolean flag = (currentKey = key) != null; 76 status = flag ? 0 : 1; 77 return flag; 78 } 79 80 87 public boolean next() throws DException { 88 if(status == 1) 89 return false; 90 if(status == -1) 91 return first(); 92 while(true){ 93 try{ 94 currentKey = new Integer (currentKey.hashCode()+1); 95 memoryTable.verifyValidity(currentKey); 96 status = 0; 97 return true; 98 }catch(DException e){ 99 if(e.getDseCode().equalsIgnoreCase("DSE2002")){ 100 status = 1; 101 return false; 102 } 103 else if(!e.getDseCode().equalsIgnoreCase("DSE2003")) 104 throw e; 105 } 106 } 107 } 108 109 116 117 public boolean previous() throws DException { 118 if(status == -1) 119 return false; 120 if(status == 1) 121 return last(); 122 while(true){ 123 try{ 124 currentKey = new Integer (currentKey.hashCode()-1); 125 memoryTable.verifyValidity(currentKey); 126 status = 0; 127 return true; 128 }catch(DException e){ 129 if(e.getDseCode().equalsIgnoreCase("DSE2002")){ 130 status = -1; 131 return false; 132 } 133 else if(!e.getDseCode().equalsIgnoreCase("DSE2003")) 134 throw e; 135 } 136 } 137 } 138 139 143 144 public Object getKey()throws DException{ 145 return currentKey; 146 } 147 148 153 154 public void insert(Object values)throws DException{ 155 currentKey = memoryTable.insert(values); 156 status = 0; 157 } 158 159 164 public void update(Object values)throws DException{ 165 currentKey = memoryTable.update(currentKey,values); 166 status = 0; 167 } 168 169 172 public void delete() throws DException{ 173 memoryTable.delete(currentKey); 174 } 175 176 177 183 public void update(int[] columns, Object [] values) throws DException { 184 if((columns.length != values.length)) 185 throw new DataException("DSE754",null); 186 Object oldVal[] = (Object [])getColumnValues(); 187 for (int j = 0; j < columns.length ; j++) 188 oldVal[columns[j]]=values[j]; 189 currentKey = memoryTable.update(currentKey,oldVal); 190 status =0; 191 } 192 193 197 198 public void move(Object key) throws DException { 199 currentKey = key; 200 status = 0; 201 } 202 203 204 205 public void show() throws DException { 206 if(first()){ 207 do{ 208 }while(next()); 209 } 210 } 211 212 216 217 public _Record getRecord() throws DException { 218 Record record = new Record((TableCharacteristics)memoryTable.getTableCharacteristics(),null); 219 record.setObject((Object [])getColumnValues()); 220 return record; 221 } 222 223 public String toString() { 224 return ""; 225 } 226 227 235 236 237 238 public Object getColumnValues(int parm1) throws com.daffodilwoods.database.resource.DException { 239 if(status != 0) 240 throw new DException("DSE2019",new Object [] {new Integer (status)}); 241 Object [] values = (Object [])memoryTable.getObjectAtKey(currentKey); 242 return values[parm1]; 243 } 244 245 251 252 253 254 public Object getColumnValues() throws com.daffodilwoods.database.resource.DException { 255 if(status != 0) 256 throw new DException("DSE2019",new Object [] {new Integer (status)}); 257 Object obj = memoryTable.getObjectAtKey(currentKey); 258 Object [] row = (Object []) obj; 259 Object [] clonedRow = new Object [row.length]; 260 System.arraycopy(row,0,clonedRow,0,row.length); 261 return clonedRow; 262 } 263 264 265 266 274 275 public Object getColumnValues(int[] columns) throws com.daffodilwoods.database.resource.DException { 276 if(status != 0) 277 throw new DException("DSE2019",new Object [] {new Integer (status)}); 278 Object [] oldVal = (Object [])memoryTable.getObjectAtKey(currentKey); 279 Object [] newVal = new Object [columns.length]; 280 for (int i = 0; i < columns.length; i++) 281 newVal[i] = oldVal[columns[i]]; 282 return newVal; 283 } 284 public byte[] getByteKey() throws DException{ 285 throw new java.lang.UnsupportedOperationException ( 286 "Method getByteKey() not yet implemented."); 287 } 288 public void moveByteKey(byte[] key) throws DException{ 289 throw new java.lang.UnsupportedOperationException ( 290 "Method moveByteKey() not yet implemented."); 291 } 292 293 public void deleteBlobClobRecord(_DatabaseUser user) throws DException { 294 throw new UnsupportedOperationException ( 295 "method deleteBlobClobRecord not supported "); 296 297 } 298 299 } 300 | Popular Tags |