01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2000,2008 Oracle. All rights reserved.
05: *
06: * $Id: MyRangeCursor.java,v 1.5.2.2 2008/01/07 15:14:06 cwl Exp $
07: */
08:
09: 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, CursorConfig config, DataView view,
25: boolean writeAllowed) throws DatabaseException {
26:
27: super (range, view.dupsRange, openCursor(view, config,
28: writeAllowed));
29: this .view = view;
30: isRecnoOrQueue = view.recNumAllowed && !view.btreeRecNumDb;
31: writeCursor = isWriteCursor(config, writeAllowed);
32: }
33:
34: /**
35: * Returns true if a write cursor is requested by the user via the cursor
36: * config, or if this is a writable cursor and the user has not specified a
37: * cursor config. For CDB, a special cursor must be created for writing.
38: * See CurrentTransaction.openCursor.
39: */
40: private static boolean isWriteCursor(CursorConfig config,
41: boolean writeAllowed) {
42: return DbCompat.getWriteCursor(config)
43: || (config == CursorConfig.DEFAULT && writeAllowed);
44: }
45:
46: private static Cursor openCursor(DataView view,
47: CursorConfig config, boolean writeAllowed)
48: throws DatabaseException {
49:
50: return view.currentTxn.openCursor(view.db, config,
51: isWriteCursor(config, writeAllowed), view
52: .useTransaction());
53: }
54:
55: protected Cursor dupCursor(Cursor cursor, boolean samePosition)
56: throws DatabaseException {
57:
58: return view.currentTxn.dupCursor(cursor, writeCursor,
59: samePosition);
60: }
61:
62: protected void closeCursor(Cursor cursor) throws DatabaseException {
63:
64: view.currentTxn.closeCursor(cursor);
65: }
66:
67: protected boolean checkRecordNumber() {
68: return isRecnoOrQueue;
69: }
70: }
|