1 package com.daffodilwoods.daffodildb.server.sql99.dml.declarecursor; 2 3 import com.daffodilwoods.database.resource.*; 4 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.*; 5 import com.daffodilwoods.database.utility.P; 6 import com.daffodilwoods.daffodildb.server.datasystem.utility.*; 7 import com.daffodilwoods.database.general.QualifiedIdentifier; 8 import java.util.*; 9 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 10 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference; 11 import com.daffodilwoods.daffodildb.utils.comparator.CTbnfUzqfDpnqbsbups; 12 import com.daffodilwoods.daffodildb.utils.comparator.CPckfduDpnqbsbups; 13 import com.daffodilwoods.daffodildb.utils.comparator.CJoufhfsDpnqbsbups; 14 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 15 import com.daffodilwoods.daffodildb.utils.BufferRange; 16 import java.io.*; 17 import com.daffodilwoods.daffodildb.server.datasystem.btree.*; 18 19 27 public class MemoryTable implements _DataTable{ 28 29 33 34 private OrderedKeyList recordList; 35 36 41 42 private int counter = Integer.MIN_VALUE; 43 44 48 49 private _TableCharacteristics tableCharacteristics; 50 51 54 private QualifiedIdentifier tableName; 55 56 59 60 private double totalSize; 61 62 68 69 public MemoryTable(QualifiedIdentifier tableName0,_TableCharacteristics tableCharacteristics0) throws DException { 70 tableCharacteristics = tableCharacteristics0; 71 tableName = tableName0; 72 recordList = new OrderedKeyList(new CJoufhfsDpnqbsbups()); 73 74 } 75 76 84 85 public Object insert(Object values) throws DException{ 86 Object key = getKey(); 87 recordList.insert(key,values); 88 return key; 89 } 90 91 100 101 public Object update(Object key,Object values) throws DException{ 102 Object [] oldValues = (Object [])recordList.getObject(key); 103 if(oldValues == null) 104 throw StaticExceptions.RECORD_DELETED_EXCEPTION ; 105 recordList.insert(key,values); 106 107 return key; 108 } 109 110 111 118 119 public Object delete(Object key) throws DException{ 120 Object oldVal[] = (Object [])recordList.getObject(key); 121 if(oldVal == null) 122 throw new DataException("DSE2004",null ); 123 totalSize -= tableCharacteristics.getMemoryUsage(oldVal); 124 recordList.delete(key); 125 return key; 126 } 127 128 132 133 public _TableIterator getIterator() throws DException { 134 return new MemoryTableIterator(this); 135 } 136 137 public int getRowCount() throws DException { 138 return recordList.size(); 139 } 140 141 144 145 public Object getFirstKey() throws DException { 146 return recordList.getTopKey(); 147 } 148 149 152 153 public Object getLastKey() throws DException { 154 return recordList.getBottomKey(); 155 } 156 157 162 163 public void verifyValidity(Object key) throws DException{ 164 if(counter < key.hashCode()){ 165 throw DatabaseConstants.KEY_NOTFOUND_EXCEPTION; 166 } 167 if(!recordList.containsKey(key)){ 168 throw new DException("DSE2003",null); 169 } 170 } 171 172 179 180 public Object getObjectAtKey( Object key ) throws DException { 181 Object keyToReturn = recordList.getObject(key); 182 if(keyToReturn == null) 183 throw StaticExceptions.RECORD_DELETED_EXCEPTION ; 184 return keyToReturn; 185 } 186 187 public void clearRecords() { 188 recordList = null; 189 } 190 191 195 196 public double get_size() { 197 return totalSize; 198 } 199 200 public int getIndexType() { 201 return 0; 202 } 203 204 207 208 public _TableCharacteristics getTableCharacteristics() throws DException{ 209 return tableCharacteristics; 210 } 211 212 public _Record getBlankRecord() throws DException{ 213 return new Record(tableCharacteristics,new Object [tableCharacteristics.getColumnCount()]); 214 } 215 216 220 221 private synchronized Object getKey() { 222 return new Integer (counter++); 223 } 224 } 225 | Popular Tags |