1 8 9 package com.sleepycat.collections; 10 11 import com.sleepycat.compat.DbCompat; 12 import com.sleepycat.je.Cursor; 13 import com.sleepycat.je.CursorConfig; 14 import com.sleepycat.je.DatabaseException; 15 import com.sleepycat.util.keyrange.KeyRange; 16 import com.sleepycat.util.keyrange.RangeCursor; 17 18 class MyRangeCursor extends RangeCursor { 19 20 private DataView view; 21 private boolean isRecnoOrQueue; 22 private boolean writeCursor; 23 24 MyRangeCursor(KeyRange range, 25 CursorConfig config, 26 DataView view, 27 boolean writeAllowed) 28 throws DatabaseException { 29 30 super(range, view.dupsRange, openCursor(view, config, writeAllowed)); 31 this.view = view; 32 isRecnoOrQueue = view.recNumAllowed && !view.btreeRecNumDb; 33 writeCursor = isWriteCursor(config, writeAllowed); 34 } 35 36 42 private static boolean isWriteCursor(CursorConfig config, 43 boolean writeAllowed) { 44 return DbCompat.getWriteCursor(config) || 45 (config == CursorConfig.DEFAULT && writeAllowed); 46 } 47 48 private static Cursor openCursor(DataView view, 49 CursorConfig config, 50 boolean writeAllowed) 51 throws DatabaseException { 52 53 return view.currentTxn.openCursor 54 (view.db, config, isWriteCursor(config, writeAllowed), 55 view.useTransaction()); 56 } 57 58 protected Cursor dupCursor(Cursor cursor, boolean samePosition) 59 throws DatabaseException { 60 61 return view.currentTxn.dupCursor(cursor, writeCursor, samePosition); 62 } 63 64 protected void closeCursor(Cursor cursor) 65 throws DatabaseException { 66 67 view.currentTxn.closeCursor(cursor); 68 } 69 70 protected boolean checkRecordNumber() { 71 return isRecnoOrQueue; 72 } 73 } 74 | Popular Tags |