1 23 24 28 50 package com.sun.jts.CosTransactions; 51 52 54 import java.util.*; 55 56 64 71 class LogCursor { 72 74 final static int ASCENDING = 0; 75 final static int DESCENDING = 1; 76 77 79 LogCursor blockValid; 80 LogControl logControl; 81 LogHandle logHandle; 82 LogLSN startLSN; 83 LogLSN endLSN; 84 LogLSN currentLSN; 85 int direction; 86 boolean symbolicsChecked; 87 88 99 LogCursor( LogControl control, 100 LogHandle handle, 101 LogLSN startLSN, 102 LogLSN endLSN ) { 103 104 logHandle = handle; 105 logControl = control; 106 107 119 this.startLSN = new LogLSN(startLSN); 120 currentLSN = new LogLSN(startLSN); 121 this.endLSN = new LogLSN(endLSN); 122 if( startLSN.lessThan(endLSN) ) 123 direction = ASCENDING; 124 else 125 direction = DESCENDING; 126 127 blockValid = this; 128 symbolicsChecked = false; 129 130 } 131 132 133 141 public void finalize() { 142 blockValid = null; 143 144 } 145 146 157 synchronized byte[] readCursor( int[] type, 158 LogLSN LSNread ) 159 throws LogException { 160 161 166 if( blockValid != this ) 167 throw new LogException(null,LogException.LOG_INVALID_CURSOR,1); 168 169 172 if( logHandle == null || logHandle.blockValid != logHandle ) 173 throw new LogException(null,LogException.LOG_INVALID_CURSOR,2); 174 175 177 if( !logControl.logInitialised ) 178 throw new LogException(null,LogException.LOG_NOT_INITIALISED,3); 179 180 184 185 if( logHandle.logControlDescriptor.headLSN.isNULL() ) 186 throw new LogException(null,LogException.LOG_END_OF_CURSOR,5); 187 188 196 if( !symbolicsChecked ) { 197 if( currentLSN.equals(LogLSN.HEAD_LSN) ) 198 currentLSN.copy(logHandle.logControlDescriptor.headLSN); 199 else if( currentLSN.equals(LogLSN.TAIL_LSN) ) 200 currentLSN.copy(logHandle.logControlDescriptor.tailLSN); 201 202 symbolicsChecked = true; 203 } 204 205 215 if( currentLSN.greaterThan(logHandle.logControlDescriptor.headLSN) || 216 currentLSN.lessThan(logHandle.logControlDescriptor.tailLSN) ) 217 throw new LogException(null,LogException.LOG_END_OF_CURSOR,6); 218 219 223 boolean recordRetrieved = false; 224 LogExtent logEDP = null; 225 LogRecordHeader logRH = null; 226 LogRecordEnding logRE = null; 227 228 while( !recordRetrieved ) { 229 230 237 logEDP = logHandle.positionFilePointer(currentLSN,0,LogExtent.ACCESSTYPE_READ); 238 239 246 byte[] headerBytes = new byte[LogRecordHeader.SIZEOF]; 247 int bytesRead = 0; 248 try { 249 bytesRead = logEDP.fileHandle.fileRead(headerBytes); 250 } catch( LogException le ) { 251 logEDP.lastAccess = LogExtent.ACCESSTYPE_UNKNOWN; 252 throw new LogException(null,LogException.LOG_READ_FAILURE,8); 253 } 254 255 logRH = new LogRecordHeader(headerBytes,0); 256 logEDP.cursorPosition += bytesRead; 257 258 263 if( !logRH.currentLSN.equals(currentLSN) ) 264 throw new LogException(null,LogException.LOG_CORRUPTED,9); 265 266 274 if( logRH.recordType == LogHandle.LINK ) 275 if( direction == ASCENDING ) 276 currentLSN.copy(logRH.nextLSN); 277 else 278 currentLSN.copy(logRH.previousLSN); 279 else 280 recordRetrieved = true; 281 } 282 283 286 byte[][] readVect = new byte[2][]; 287 readVect[0] = new byte[logRH.recordLength]; 288 readVect[1] = new byte[LogRecordEnding.SIZEOF]; 289 290 295 int bytesRead = 0; 296 try { 297 bytesRead = logEDP.fileHandle.readVector(readVect); 298 } catch( LogException le ) { 299 logEDP.lastAccess = LogExtent.ACCESSTYPE_UNKNOWN; 300 throw new LogException(null,le.errorCode,11); 301 } 302 logEDP.cursorPosition += bytesRead; 303 304 logRE = new LogRecordEnding(readVect[1],0); 305 306 311 if( !logRE.currentLSN.equals(currentLSN) ) 312 throw new LogException(null,LogException.LOG_CORRUPTED,12); 313 314 320 if( direction == ASCENDING ) 321 currentLSN.copy(logRH.nextLSN); 322 else 323 currentLSN.copy(logRH.previousLSN); 324 325 329 type[0] = logRH.recordType; 330 LSNread.copy(logRH.currentLSN); 331 332 334 return readVect[0]; 335 } 336 } 337 | Popular Tags |