KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > collections > MyRangeCursor


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2000,2006 Oracle. All rights reserved.
5  *
6  * $Id: MyRangeCursor.java,v 1.5 2006/10/30 21:14:10 bostic Exp $
7  */

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     /**
37      * Returns true if a write cursor is requested by the user via the cursor
38      * config, or if this is a writable cursor and the user has not specified a
39      * cursor config. For CDB, a special cursor must be created for writing.
40      * See CurrentTransaction.openCursor.
41      */

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